src/mess/machine/pokemini.c
| r9669 | r9670 | |
| 13 | 13 | #include "cpu/minx/minx.h" |
| 14 | 14 | |
| 15 | 15 | |
| 16 | | struct PRC |
| 17 | | { |
| 18 | | UINT8 colors_inverted; |
| 19 | | UINT8 background_enabled; |
| 20 | | UINT8 sprites_enabled; |
| 21 | | UINT8 copy_enabled; |
| 22 | | UINT8 map_size; |
| 23 | | UINT8 map_size_x; |
| 24 | | UINT8 frame_count; |
| 25 | | UINT8 max_frame_count; |
| 26 | | UINT32 bg_tiles; |
| 27 | | UINT32 spr_tiles; |
| 28 | | UINT8 count; |
| 29 | | emu_timer *count_timer; |
| 30 | | }; |
| 31 | | |
| 32 | | |
| 33 | | struct TIMERS |
| 34 | | { |
| 35 | | emu_timer *seconds_timer; |
| 36 | | emu_timer *hz256_timer; |
| 37 | | emu_timer *timer1; /* Timer 1 low or 16bit */ |
| 38 | | emu_timer *timer1_hi; /* Timer 1 hi */ |
| 39 | | emu_timer *timer2; /* Timer 2 low or 16bit */ |
| 40 | | emu_timer *timer2_hi; /* Timer 2 high */ |
| 41 | | emu_timer *timer3; /* Timer 3 low or 16bit */ |
| 42 | | emu_timer *timer3_hi; /* Timer 3 high */ |
| 43 | | }; |
| 44 | | |
| 45 | | |
| 46 | | UINT8 *pokemini_ram; |
| 47 | | static UINT8 pm_reg[0x100]; |
| 48 | | static struct PRC prc; |
| 49 | | static struct TIMERS timers; |
| 50 | | |
| 51 | | |
| 52 | 16 | static void pokemini_check_irqs( running_machine *machine ) |
| 53 | 17 | { |
| 18 | pokemini_state *state = machine->driver_data<pokemini_state>(); |
| 54 | 19 | int irq_set[4] = { 1, 0, 0, 0 }; |
| 55 | 20 | int prio, vector; |
| 56 | 21 | |
| 57 | 22 | /* Check IRQ $03-$04 */ |
| 58 | | prio = ( pm_reg[0x20] >> 6 ) & 0x03; |
| 23 | prio = ( state->pm_reg[0x20] >> 6 ) & 0x03; |
| 59 | 24 | if ( ! irq_set[prio] ) |
| 60 | 25 | { |
| 61 | | if ( pm_reg[0x23] & pm_reg[0x27] & 0x40 ) |
| 26 | if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x40 ) |
| 62 | 27 | irq_set[prio] = 0x04; |
| 63 | 28 | |
| 64 | | if ( pm_reg[0x23] & pm_reg[0x27] & 0x80 ) |
| 29 | if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x80 ) |
| 65 | 30 | irq_set[prio] = 0x03; |
| 66 | 31 | } |
| 67 | 32 | |
| 68 | 33 | /* Check IRQ $05-$06 */ |
| 69 | | prio = ( pm_reg[0x20] >> 4 ) & 0x03; |
| 34 | prio = ( state->pm_reg[0x20] >> 4 ) & 0x03; |
| 70 | 35 | if ( ! irq_set[prio] ) |
| 71 | 36 | { |
| 72 | | if ( pm_reg[0x23] & pm_reg[0x27] & 0x10 ) |
| 37 | if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x10 ) |
| 73 | 38 | irq_set[prio] = 0x06; |
| 74 | 39 | |
| 75 | | if ( pm_reg[0x23] & pm_reg[0x27] & 0x20 ) |
| 40 | if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x20 ) |
| 76 | 41 | irq_set[prio] = 0x05; |
| 77 | 42 | } |
| 78 | 43 | |
| 79 | 44 | /* Check IRQ $07-$08 */ |
| 80 | | prio = ( pm_reg[0x20] >> 2 ) & 0x03; |
| 45 | prio = ( state->pm_reg[0x20] >> 2 ) & 0x03; |
| 81 | 46 | if ( ! irq_set[prio] ) |
| 82 | 47 | { |
| 83 | | if ( pm_reg[0x23] & pm_reg[0x27] & 0x04 ) |
| 48 | if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x04 ) |
| 84 | 49 | irq_set[prio] = 0x08; |
| 85 | 50 | |
| 86 | | if ( pm_reg[0x23] & pm_reg[0x27] & 0x08 ) |
| 51 | if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x08 ) |
| 87 | 52 | irq_set[prio] = 0x07; |
| 88 | 53 | } |
| 89 | 54 | |
| 90 | 55 | /* Check IRQ $09-$0A */ |
| 91 | | prio = ( pm_reg[0x20] >> 0 ) & 0x03; |
| 56 | prio = ( state->pm_reg[0x20] >> 0 ) & 0x03; |
| 92 | 57 | if ( ! irq_set[prio] ) |
| 93 | 58 | { |
| 94 | | if ( pm_reg[0x23] & pm_reg[0x27] & 0x01 ) |
| 59 | if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x01 ) |
| 95 | 60 | irq_set[prio] = 0x0A; |
| 96 | 61 | |
| 97 | | if ( pm_reg[0x23] & pm_reg[0x27] & 0x02 ) |
| 62 | if ( state->pm_reg[0x23] & state->pm_reg[0x27] & 0x02 ) |
| 98 | 63 | irq_set[prio] = 0x09; |
| 99 | 64 | } |
| 100 | 65 | |
| 101 | 66 | /* Check IRQ $0B-$0E */ |
| 102 | | prio = ( pm_reg[0x21] >> 6 ) & 0x03; |
| 67 | prio = ( state->pm_reg[0x21] >> 6 ) & 0x03; |
| 103 | 68 | if ( ! irq_set[prio] ) |
| 104 | 69 | { |
| 105 | | if ( pm_reg[0x24] & pm_reg[0x28] & 0x04 ) |
| 70 | if ( state->pm_reg[0x24] & state->pm_reg[0x28] & 0x04 ) |
| 106 | 71 | irq_set[prio] = 0x0E; |
| 107 | 72 | |
| 108 | | if ( pm_reg[0x24] & pm_reg[0x28] & 0x08 ) |
| 73 | if ( state->pm_reg[0x24] & state->pm_reg[0x28] & 0x08 ) |
| 109 | 74 | irq_set[prio] = 0x0D; |
| 110 | 75 | |
| 111 | | if ( pm_reg[0x24] & pm_reg[0x28] & 0x10 ) |
| 76 | if ( state->pm_reg[0x24] & state->pm_reg[0x28] & 0x10 ) |
| 112 | 77 | irq_set[prio] = 0x0C; |
| 113 | 78 | |
| 114 | | if ( pm_reg[0x24] & pm_reg[0x28] & 0x20 ) |
| 79 | if ( state->pm_reg[0x24] & state->pm_reg[0x28] & 0x20 ) |
| 115 | 80 | irq_set[prio] = 0x0B; |
| 116 | 81 | } |
| 117 | 82 | |
| 118 | 83 | /* Check IRQ $0F-$10 */ |
| 119 | | prio = ( pm_reg[0x22] >> 0 ) & 0x03; |
| 84 | prio = ( state->pm_reg[0x22] >> 0 ) & 0x03; |
| 120 | 85 | if ( ! irq_set[prio] ) |
| 121 | 86 | { |
| 122 | | if ( pm_reg[0x26] & pm_reg[0x2A] & 0x40 ) |
| 87 | if ( state->pm_reg[0x26] & state->pm_reg[0x2A] & 0x40 ) |
| 123 | 88 | irq_set[prio] = 0x10; |
| 124 | 89 | |
| 125 | | if ( pm_reg[0x26] & pm_reg[0x2A] & 0x80 ) |
| 90 | if ( state->pm_reg[0x26] & state->pm_reg[0x2A] & 0x80 ) |
| 126 | 91 | irq_set[prio] = 0x0F; |
| 127 | 92 | } |
| 128 | 93 | |
| 129 | 94 | /* Check IRQ $13-$14 */ |
| 130 | | prio = ( pm_reg[0x21] >> 4 ) & 0x03; |
| 95 | prio = ( state->pm_reg[0x21] >> 4 ) & 0x03; |
| 131 | 96 | if ( ! irq_set[prio] ) |
| 132 | 97 | { |
| 133 | | if ( pm_reg[0x24] & pm_reg[0x28] & 0x01 ) |
| 98 | if ( state->pm_reg[0x24] & state->pm_reg[0x28] & 0x01 ) |
| 134 | 99 | irq_set[prio] = 0x14; |
| 135 | 100 | |
| 136 | | if ( pm_reg[0x24] & pm_reg[0x28] & 0x02 ) |
| 101 | if ( state->pm_reg[0x24] & state->pm_reg[0x28] & 0x02 ) |
| 137 | 102 | irq_set[prio] = 0x13; |
| 138 | 103 | } |
| 139 | 104 | |
| 140 | 105 | /* Check IRQ $15-$1C */ |
| 141 | | prio = ( pm_reg[0x21] >> 2 ) & 0x03; |
| 106 | prio = ( state->pm_reg[0x21] >> 2 ) & 0x03; |
| 142 | 107 | if ( ! irq_set[prio] ) |
| 143 | 108 | { |
| 144 | | if ( pm_reg[0x25] & pm_reg[0x29] & 0x01 ) |
| 109 | if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x01 ) |
| 145 | 110 | irq_set[prio] = 0x1C; |
| 146 | 111 | |
| 147 | | if ( pm_reg[0x25] & pm_reg[0x29] & 0x02 ) |
| 112 | if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x02 ) |
| 148 | 113 | irq_set[prio] = 0x1B; |
| 149 | 114 | |
| 150 | | if ( pm_reg[0x25] & pm_reg[0x29] & 0x04 ) |
| 115 | if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x04 ) |
| 151 | 116 | irq_set[prio] = 0x1A; |
| 152 | 117 | |
| 153 | | if ( pm_reg[0x25] & pm_reg[0x29] & 0x08 ) |
| 118 | if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x08 ) |
| 154 | 119 | irq_set[prio] = 0x19; |
| 155 | 120 | |
| 156 | | if ( pm_reg[0x25] & pm_reg[0x29] & 0x10 ) |
| 121 | if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x10 ) |
| 157 | 122 | irq_set[prio] = 0x18; |
| 158 | 123 | |
| 159 | | if ( pm_reg[0x25] & pm_reg[0x29] & 0x20 ) |
| 124 | if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x20 ) |
| 160 | 125 | irq_set[prio] = 0x17; |
| 161 | 126 | |
| 162 | | if ( pm_reg[0x25] & pm_reg[0x29] & 0x40 ) |
| 127 | if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x40 ) |
| 163 | 128 | irq_set[prio] = 0x16; |
| 164 | 129 | |
| 165 | | if ( pm_reg[0x25] & pm_reg[0x29] & 0x80 ) |
| 130 | if ( state->pm_reg[0x25] & state->pm_reg[0x29] & 0x80 ) |
| 166 | 131 | irq_set[prio] = 0x15; |
| 167 | 132 | } |
| 168 | 133 | |
| 169 | 134 | /* Check IRQ $1D-$1F */ |
| 170 | | prio = ( pm_reg[0x21] >> 0 ) & 0x03; |
| 171 | | if ( ! irq_set[prio] && ( pm_reg[0x26] & pm_reg[0x2A] & 0x07 ) ) |
| 135 | prio = ( state->pm_reg[0x21] >> 0 ) & 0x03; |
| 136 | if ( ! irq_set[prio] && ( state->pm_reg[0x26] & state->pm_reg[0x2A] & 0x07 ) ) |
| 172 | 137 | { |
| 173 | | if ( pm_reg[0x26] & pm_reg[0x2A] & 0x01 ) |
| 138 | if ( state->pm_reg[0x26] & state->pm_reg[0x2A] & 0x01 ) |
| 174 | 139 | irq_set[prio] = 0x1F; |
| 175 | 140 | |
| 176 | | if ( pm_reg[0x26] & pm_reg[0x2A] & 0x02 ) |
| 141 | if ( state->pm_reg[0x26] & state->pm_reg[0x2A] & 0x02 ) |
| 177 | 142 | irq_set[prio] = 0x1E; |
| 178 | 143 | |
| 179 | | if ( pm_reg[0x26] & pm_reg[0x2A] & 0x04 ) |
| 144 | if ( state->pm_reg[0x26] & state->pm_reg[0x2A] & 0x04 ) |
| 180 | 145 | irq_set[prio] = 0x1D; |
| 181 | 146 | } |
| 182 | 147 | |
| r9669 | r9670 | |
| 204 | 169 | |
| 205 | 170 | static void pokemini_update_sound( running_machine *machine ) |
| 206 | 171 | { |
| 172 | pokemini_state *state = machine->driver_data<pokemini_state>(); |
| 207 | 173 | running_device *speaker = machine->device("speaker"); |
| 208 | 174 | /* Check if sound should be muted */ |
| 209 | | if ( pm_reg[0x70] & 0x03 ) |
| 175 | if ( state->pm_reg[0x70] & 0x03 ) |
| 210 | 176 | { |
| 211 | 177 | speaker_level_w( speaker, 0 ); |
| 212 | 178 | } |
| 213 | 179 | else |
| 214 | 180 | { |
| 215 | 181 | static const int levels[4] = { 0, 1, 1, 2 }; |
| 216 | | int level = levels[ pm_reg[0x71] & 0x03 ]; |
| 182 | int level = levels[ state->pm_reg[0x71] & 0x03 ]; |
| 217 | 183 | |
| 218 | | // if ( ( ( pm_reg[0x48] & 0x80 ) && ( pm_reg[0x4E] | ( pm_reg[0x4F] << 8 ) ) > ( pm_reg[0x4C] | ( pm_reg[0x4D] << 8 ) ) ) |
| 219 | | // || ( ( pm_reg[0x48] & 0x80 ) && pm_reg[0x4F] > pm_reg[0x4D] ) ) |
| 184 | // if ( ( ( state->pm_reg[0x48] & 0x80 ) && ( state->pm_reg[0x4E] | ( state->pm_reg[0x4F] << 8 ) ) > ( state->pm_reg[0x4C] | ( state->pm_reg[0x4D] << 8 ) ) ) |
| 185 | // || ( ( state->pm_reg[0x48] & 0x80 ) && state->pm_reg[0x4F] > state->pm_reg[0x4D] ) ) |
| 220 | 186 | // { |
| 221 | 187 | level = 0; |
| 222 | 188 | // } |
| r9669 | r9670 | |
| 228 | 194 | |
| 229 | 195 | static TIMER_CALLBACK(pokemini_seconds_timer_callback) |
| 230 | 196 | { |
| 231 | | if ( pm_reg[0x08] & 0x01 ) |
| 197 | pokemini_state *state = machine->driver_data<pokemini_state>(); |
| 198 | if ( state->pm_reg[0x08] & 0x01 ) |
| 232 | 199 | { |
| 233 | | pm_reg[0x09] += 1; |
| 234 | | if ( ! pm_reg[0x09] ) |
| 200 | state->pm_reg[0x09] += 1; |
| 201 | if ( ! state->pm_reg[0x09] ) |
| 235 | 202 | { |
| 236 | | pm_reg[0x0A] += 1; |
| 237 | | if ( ! pm_reg[0x0A] ) |
| 203 | state->pm_reg[0x0A] += 1; |
| 204 | if ( ! state->pm_reg[0x0A] ) |
| 238 | 205 | { |
| 239 | | pm_reg[0x0B] += 1; |
| 206 | state->pm_reg[0x0B] += 1; |
| 240 | 207 | } |
| 241 | 208 | } |
| 242 | 209 | } |
| r9669 | r9670 | |
| 245 | 212 | |
| 246 | 213 | static TIMER_CALLBACK(pokemini_256hz_timer_callback) |
| 247 | 214 | { |
| 248 | | if ( pm_reg[0x40] & 0x01 ) |
| 215 | pokemini_state *state = machine->driver_data<pokemini_state>(); |
| 216 | if ( state->pm_reg[0x40] & 0x01 ) |
| 249 | 217 | { |
| 250 | | pm_reg[0x41] += 1; |
| 218 | state->pm_reg[0x41] += 1; |
| 251 | 219 | /* Check if the 32Hz IRQ should be triggered */ |
| 252 | | if ( ! ( pm_reg[0x41] & 0x07 ) ) |
| 220 | if ( ! ( state->pm_reg[0x41] & 0x07 ) ) |
| 253 | 221 | { |
| 254 | | pm_reg[0x28] |= 0x20; |
| 222 | state->pm_reg[0x28] |= 0x20; |
| 255 | 223 | |
| 256 | 224 | /* Check if the 8Hz IRQ should be triggered */ |
| 257 | | if ( ! ( pm_reg[0x41] & 0x1F ) ) |
| 225 | if ( ! ( state->pm_reg[0x41] & 0x1F ) ) |
| 258 | 226 | { |
| 259 | | pm_reg[0x28] |= 0x10; |
| 227 | state->pm_reg[0x28] |= 0x10; |
| 260 | 228 | |
| 261 | 229 | /* Check if the 2Hz IRQ should be triggered */ |
| 262 | | if ( ! ( pm_reg[0x41] & 0x7F ) ) |
| 230 | if ( ! ( state->pm_reg[0x41] & 0x7F ) ) |
| 263 | 231 | { |
| 264 | | pm_reg[0x28] |= 0x08; |
| 232 | state->pm_reg[0x28] |= 0x08; |
| 265 | 233 | |
| 266 | 234 | /* Check if the 1Hz IRQ should be triggered */ |
| 267 | | if ( ! pm_reg[0x41] ) |
| 235 | if ( ! state->pm_reg[0x41] ) |
| 268 | 236 | { |
| 269 | | pm_reg[0x28] |= 0x04; |
| 237 | state->pm_reg[0x28] |= 0x04; |
| 270 | 238 | } |
| 271 | 239 | } |
| 272 | 240 | } |
| r9669 | r9670 | |
| 279 | 247 | |
| 280 | 248 | static TIMER_CALLBACK(pokemini_timer1_callback) |
| 281 | 249 | { |
| 282 | | pm_reg[0x36] -= 1; |
| 250 | pokemini_state *state = machine->driver_data<pokemini_state>(); |
| 251 | state->pm_reg[0x36] -= 1; |
| 283 | 252 | /* Check for underflow of timer */ |
| 284 | | if ( pm_reg[0x36] == 0xFF ) |
| 253 | if ( state->pm_reg[0x36] == 0xFF ) |
| 285 | 254 | { |
| 286 | 255 | /* Check if timer1 is running in 16bit mode */ |
| 287 | | if ( pm_reg[0x30] & 0x80 ) |
| 256 | if ( state->pm_reg[0x30] & 0x80 ) |
| 288 | 257 | { |
| 289 | | pm_reg[0x37] -= 1; |
| 290 | | if ( pm_reg[0x37] == 0xFF ) |
| 258 | state->pm_reg[0x37] -= 1; |
| 259 | if ( state->pm_reg[0x37] == 0xFF ) |
| 291 | 260 | { |
| 292 | | pm_reg[0x27] |= 0x08; |
| 261 | state->pm_reg[0x27] |= 0x08; |
| 293 | 262 | pokemini_check_irqs( machine ); |
| 294 | | pm_reg[0x36] = pm_reg[0x32]; |
| 295 | | pm_reg[0x37] = pm_reg[0x33]; |
| 263 | state->pm_reg[0x36] = state->pm_reg[0x32]; |
| 264 | state->pm_reg[0x37] = state->pm_reg[0x33]; |
| 296 | 265 | } |
| 297 | 266 | } |
| 298 | 267 | else |
| 299 | 268 | { |
| 300 | | pm_reg[0x27] |= 0x04; |
| 269 | state->pm_reg[0x27] |= 0x04; |
| 301 | 270 | pokemini_check_irqs( machine ); |
| 302 | | pm_reg[0x36] = pm_reg[0x32]; |
| 271 | state->pm_reg[0x36] = state->pm_reg[0x32]; |
| 303 | 272 | } |
| 304 | 273 | } |
| 305 | 274 | } |
| r9669 | r9670 | |
| 307 | 276 | |
| 308 | 277 | static TIMER_CALLBACK(pokemini_timer1_hi_callback) |
| 309 | 278 | { |
| 310 | | pm_reg[0x37] -= 1; |
| 279 | pokemini_state *state = machine->driver_data<pokemini_state>(); |
| 280 | state->pm_reg[0x37] -= 1; |
| 311 | 281 | /* Check for underflow of timer */ |
| 312 | | if ( pm_reg[0x37] == 0xFF ) |
| 282 | if ( state->pm_reg[0x37] == 0xFF ) |
| 313 | 283 | { |
| 314 | | pm_reg[0x27] |= 0x08; |
| 284 | state->pm_reg[0x27] |= 0x08; |
| 315 | 285 | pokemini_check_irqs( machine ); |
| 316 | | pm_reg[0x37] = pm_reg[0x33]; |
| 286 | state->pm_reg[0x37] = state->pm_reg[0x33]; |
| 317 | 287 | } |
| 318 | 288 | } |
| 319 | 289 | |
| 320 | 290 | |
| 321 | 291 | static TIMER_CALLBACK(pokemini_timer2_callback) |
| 322 | 292 | { |
| 323 | | pm_reg[0x3E] -= 1; |
| 293 | pokemini_state *state = machine->driver_data<pokemini_state>(); |
| 294 | state->pm_reg[0x3E] -= 1; |
| 324 | 295 | /* Check for underflow of timer */ |
| 325 | | if ( pm_reg[0x3E] == 0xFF ) |
| 296 | if ( state->pm_reg[0x3E] == 0xFF ) |
| 326 | 297 | { |
| 327 | 298 | /* Check if timer2 is running in 16bit mode */ |
| 328 | | if ( pm_reg[0x38] & 0x80 ) |
| 299 | if ( state->pm_reg[0x38] & 0x80 ) |
| 329 | 300 | { |
| 330 | | pm_reg[0x3F] -= 1; |
| 331 | | if ( pm_reg[0x3F] == 0xFF ) |
| 301 | state->pm_reg[0x3F] -= 1; |
| 302 | if ( state->pm_reg[0x3F] == 0xFF ) |
| 332 | 303 | { |
| 333 | | pm_reg[0x27] |= 0x20; |
| 304 | state->pm_reg[0x27] |= 0x20; |
| 334 | 305 | pokemini_check_irqs( machine ); |
| 335 | | pm_reg[0x3E] = pm_reg[0x3A]; |
| 336 | | pm_reg[0x3F] = pm_reg[0x3B]; |
| 306 | state->pm_reg[0x3E] = state->pm_reg[0x3A]; |
| 307 | state->pm_reg[0x3F] = state->pm_reg[0x3B]; |
| 337 | 308 | } |
| 338 | 309 | } |
| 339 | 310 | else |
| 340 | 311 | { |
| 341 | | pm_reg[0x27] |= 0x10; |
| 312 | state->pm_reg[0x27] |= 0x10; |
| 342 | 313 | pokemini_check_irqs( machine ); |
| 343 | | pm_reg[0x3E] = pm_reg[0x3A]; |
| 314 | state->pm_reg[0x3E] = state->pm_reg[0x3A]; |
| 344 | 315 | } |
| 345 | 316 | } |
| 346 | 317 | } |
| r9669 | r9670 | |
| 348 | 319 | |
| 349 | 320 | static TIMER_CALLBACK(pokemini_timer2_hi_callback) |
| 350 | 321 | { |
| 351 | | pm_reg[0x3F] -= 1; |
| 322 | pokemini_state *state = machine->driver_data<pokemini_state>(); |
| 323 | state->pm_reg[0x3F] -= 1; |
| 352 | 324 | /* Check for underfow of timer */ |
| 353 | | if ( pm_reg[0x3F] == 0xFF ) |
| 325 | if ( state->pm_reg[0x3F] == 0xFF ) |
| 354 | 326 | { |
| 355 | | pm_reg[0x27] |= 0x20; |
| 327 | state->pm_reg[0x27] |= 0x20; |
| 356 | 328 | pokemini_check_irqs( machine ); |
| 357 | | pm_reg[0x3F] = pm_reg[0x3B]; |
| 329 | state->pm_reg[0x3F] = state->pm_reg[0x3B]; |
| 358 | 330 | } |
| 359 | 331 | } |
| 360 | 332 | |
| 361 | 333 | |
| 362 | 334 | static TIMER_CALLBACK(pokemini_timer3_callback) |
| 363 | 335 | { |
| 364 | | pm_reg[0x4E] -= 1; |
| 336 | pokemini_state *state = machine->driver_data<pokemini_state>(); |
| 337 | state->pm_reg[0x4E] -= 1; |
| 365 | 338 | /* Check for underflow of timer */ |
| 366 | | if ( pm_reg[0x4E] == 0xFF ) |
| 339 | if ( state->pm_reg[0x4E] == 0xFF ) |
| 367 | 340 | { |
| 368 | 341 | /* Check if timer3 is running in 16bit mode */ |
| 369 | | if ( pm_reg[0x48] & 0x80 ) |
| 342 | if ( state->pm_reg[0x48] & 0x80 ) |
| 370 | 343 | { |
| 371 | | pm_reg[0x4F] -= 1; |
| 372 | | if ( pm_reg[0x4F] == 0xFF ) |
| 344 | state->pm_reg[0x4F] -= 1; |
| 345 | if ( state->pm_reg[0x4F] == 0xFF ) |
| 373 | 346 | { |
| 374 | | pm_reg[0x27] |= 0x02; |
| 347 | state->pm_reg[0x27] |= 0x02; |
| 375 | 348 | pokemini_check_irqs( machine ); |
| 376 | | pm_reg[0x4E] = pm_reg[0x4A]; |
| 377 | | pm_reg[0x4F] = pm_reg[0x4B]; |
| 349 | state->pm_reg[0x4E] = state->pm_reg[0x4A]; |
| 350 | state->pm_reg[0x4F] = state->pm_reg[0x4B]; |
| 378 | 351 | } |
| 379 | 352 | } |
| 380 | 353 | else |
| 381 | 354 | { |
| 382 | | pm_reg[0x4E] = pm_reg[0x4A]; |
| 355 | state->pm_reg[0x4E] = state->pm_reg[0x4A]; |
| 383 | 356 | } |
| 384 | 357 | } |
| 385 | 358 | |
| 386 | | if ( pm_reg[0x48] & 0x80 ) |
| 359 | if ( state->pm_reg[0x48] & 0x80 ) |
| 387 | 360 | { |
| 388 | | if ( ( pm_reg[0x4E] == pm_reg[0x4C] ) && ( pm_reg[0x4F] == pm_reg[0x4D] ) ) |
| 361 | if ( ( state->pm_reg[0x4E] == state->pm_reg[0x4C] ) && ( state->pm_reg[0x4F] == state->pm_reg[0x4D] ) ) |
| 389 | 362 | { |
| 390 | | pm_reg[0x27] |= 0x01; |
| 363 | state->pm_reg[0x27] |= 0x01; |
| 391 | 364 | pokemini_check_irqs( machine ); |
| 392 | 365 | } |
| 393 | 366 | pokemini_update_sound( machine ); |
| r9669 | r9670 | |
| 397 | 370 | |
| 398 | 371 | static TIMER_CALLBACK(pokemini_timer3_hi_callback) |
| 399 | 372 | { |
| 400 | | pm_reg[0x4F] -= 1; |
| 373 | pokemini_state *state = machine->driver_data<pokemini_state>(); |
| 374 | state->pm_reg[0x4F] -= 1; |
| 401 | 375 | /* Check for underflow of timer */ |
| 402 | | if ( pm_reg[0x4F] == 0xFF ) |
| 376 | if ( state->pm_reg[0x4F] == 0xFF ) |
| 403 | 377 | { |
| 404 | | pm_reg[0x27] |= 0x02; |
| 378 | state->pm_reg[0x27] |= 0x02; |
| 405 | 379 | pokemini_check_irqs( machine ); |
| 406 | | pm_reg[0x4F] = pm_reg[0x4B]; |
| 380 | state->pm_reg[0x4F] = state->pm_reg[0x4B]; |
| 407 | 381 | } |
| 408 | 382 | |
| 409 | | if ( ! ( pm_reg[0x48] & 0x80 ) ) |
| 383 | if ( ! ( state->pm_reg[0x48] & 0x80 ) ) |
| 410 | 384 | { |
| 411 | | if( pm_reg[0x4F] == pm_reg[0x4D] ) |
| 385 | if( state->pm_reg[0x4F] == state->pm_reg[0x4D] ) |
| 412 | 386 | { |
| 413 | | pm_reg[0x27] |= 0x01; |
| 387 | state->pm_reg[0x27] |= 0x01; |
| 414 | 388 | pokemini_check_irqs( machine ); |
| 415 | 389 | } |
| 416 | 390 | pokemini_update_sound( machine ); |
| r9669 | r9670 | |
| 420 | 394 | |
| 421 | 395 | WRITE8_DEVICE_HANDLER( pokemini_hwreg_w ) |
| 422 | 396 | { |
| 397 | pokemini_state *state = device->machine->driver_data<pokemini_state>(); |
| 423 | 398 | static const int timer_to_cycles_fast[8] = { 2, 8, 32, 64, 128, 256, 1024, 4096 }; |
| 424 | 399 | static const int timer_to_cycles_slow[8] = { 128, 256, 512, 1024, 2048, 4096, 8192, 16384 }; |
| 425 | 400 | |
| r9669 | r9670 | |
| 446 | 421 | */ |
| 447 | 422 | if ( data & 0x02 ) |
| 448 | 423 | { |
| 449 | | pm_reg[0x09] = 0x00; |
| 450 | | pm_reg[0x0A] = 0x00; |
| 451 | | pm_reg[0x0B] = 0x00; |
| 424 | state->pm_reg[0x09] = 0x00; |
| 425 | state->pm_reg[0x0A] = 0x00; |
| 426 | state->pm_reg[0x0B] = 0x00; |
| 452 | 427 | data &= ~0x02; |
| 453 | 428 | } |
| 454 | 429 | break; |
| r9669 | r9670 | |
| 486 | 461 | Bit 7 R/W Enable high counting |
| 487 | 462 | */ |
| 488 | 463 | /* Check for prescaler change for the low counter */ |
| 489 | | if ( ( data & 0x07 ) != ( pm_reg[0x18] & 0x07 ) ) |
| 464 | if ( ( data & 0x07 ) != ( state->pm_reg[0x18] & 0x07 ) ) |
| 490 | 465 | { |
| 491 | 466 | int index = data & 0x07; |
| 492 | | int cycles = ( pm_reg[0x19] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 467 | int cycles = ( state->pm_reg[0x19] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 493 | 468 | |
| 494 | | timer_adjust_periodic(timers.timer1, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 469 | timer_adjust_periodic(state->timers.timer1, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 495 | 470 | } |
| 496 | 471 | |
| 497 | 472 | /* Check for prescaler change for the high counter */ |
| 498 | | if ( ( data & 0x70 ) != ( pm_reg[0x18] & 0x70 ) ) |
| 473 | if ( ( data & 0x70 ) != ( state->pm_reg[0x18] & 0x70 ) ) |
| 499 | 474 | { |
| 500 | 475 | int index = ( data >> 4 ) & 0x07; |
| 501 | | int cycles = ( pm_reg[0x19] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 476 | int cycles = ( state->pm_reg[0x19] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 502 | 477 | |
| 503 | | timer_adjust_periodic(timers.timer1_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 478 | timer_adjust_periodic(state->timers.timer1_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 504 | 479 | } |
| 505 | 480 | |
| 506 | 481 | /* Check if timer1 low should be enabled */ |
| 507 | | if ( ( data & 0x08 ) && ( pm_reg[0x30] & 0x04 ) && |
| 508 | | ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x01 ) ) || |
| 509 | | ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x01 ) ) ) ) |
| 482 | if ( ( data & 0x08 ) && ( state->pm_reg[0x30] & 0x04 ) && |
| 483 | ( ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x19] & 0x01 ) ) || |
| 484 | ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x19] & 0x01 ) ) ) ) |
| 510 | 485 | { |
| 511 | | timer_enable( timers.timer1, 1 ); |
| 486 | timer_enable( state->timers.timer1, 1 ); |
| 512 | 487 | } |
| 513 | 488 | else |
| 514 | 489 | { |
| 515 | | timer_enable( timers.timer1, 0 ); |
| 490 | timer_enable( state->timers.timer1, 0 ); |
| 516 | 491 | } |
| 517 | 492 | |
| 518 | 493 | /* Check if timer1 high should be enabled */ |
| 519 | | if ( ( data & 0x80 ) && ( pm_reg[0x31] & 0x04 ) && ! ( pm_reg[0x30] & 0x80 ) && |
| 520 | | ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x02 ) ) || |
| 521 | | ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x02 ) ) ) ) |
| 494 | if ( ( data & 0x80 ) && ( state->pm_reg[0x31] & 0x04 ) && ! ( state->pm_reg[0x30] & 0x80 ) && |
| 495 | ( ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x19] & 0x02 ) ) || |
| 496 | ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x19] & 0x02 ) ) ) ) |
| 522 | 497 | { |
| 523 | | timer_enable( timers.timer1_hi, 1 ); |
| 498 | timer_enable( state->timers.timer1_hi, 1 ); |
| 524 | 499 | } |
| 525 | 500 | else |
| 526 | 501 | { |
| 527 | | timer_enable( timers.timer1_hi, 0 ); |
| 502 | timer_enable( state->timers.timer1_hi, 0 ); |
| 528 | 503 | } |
| 529 | 504 | break; |
| 530 | 505 | case 0x19: /* Timers 1 speed |
| r9669 | r9670 | |
| 536 | 511 | Bit 6-7 Unused |
| 537 | 512 | */ |
| 538 | 513 | /* Check for prescaler change for the high counter */ |
| 539 | | if ( ( data & 0x01 ) != ( pm_reg[0x19] & 0x01 ) ) |
| 514 | if ( ( data & 0x01 ) != ( state->pm_reg[0x19] & 0x01 ) ) |
| 540 | 515 | { |
| 541 | | int index = pm_reg[0x18] & 0x07; |
| 516 | int index = state->pm_reg[0x18] & 0x07; |
| 542 | 517 | int cycles = ( data & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 543 | 518 | |
| 544 | | timer_adjust_periodic(timers.timer1, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 519 | timer_adjust_periodic(state->timers.timer1, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 545 | 520 | } |
| 546 | 521 | |
| 547 | 522 | /* Check for prescaler change for the low counter */ |
| 548 | | if ( ( data & 0x02 ) != ( pm_reg[0x19] & 0x02 ) ) |
| 523 | if ( ( data & 0x02 ) != ( state->pm_reg[0x19] & 0x02 ) ) |
| 549 | 524 | { |
| 550 | | int index = ( pm_reg[0x18] >> 4 ) & 0x07; |
| 525 | int index = ( state->pm_reg[0x18] >> 4 ) & 0x07; |
| 551 | 526 | int cycles = ( data & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 552 | 527 | |
| 553 | | timer_adjust_periodic(timers.timer1_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 528 | timer_adjust_periodic(state->timers.timer1_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 554 | 529 | } |
| 555 | 530 | |
| 556 | 531 | { |
| r9669 | r9670 | |
| 561 | 536 | /* Check which fast timers should be enabled */ |
| 562 | 537 | if ( data & 0x20 ) |
| 563 | 538 | { |
| 564 | | if ( ( pm_reg[0x18] & 0x08 ) && ( pm_reg[0x30] & 0x04 ) && ! ( data & 0x01 ) ) |
| 539 | if ( ( state->pm_reg[0x18] & 0x08 ) && ( state->pm_reg[0x30] & 0x04 ) && ! ( data & 0x01 ) ) |
| 565 | 540 | timer1_enable = 1; |
| 566 | 541 | |
| 567 | | if ( ( pm_reg[0x18] & 0x80 ) && ( pm_reg[0x31] & 0x04 ) && ! ( pm_reg[0x30] & 0x80 ) && ! ( data & 0x02 ) ) |
| 542 | if ( ( state->pm_reg[0x18] & 0x80 ) && ( state->pm_reg[0x31] & 0x04 ) && ! ( state->pm_reg[0x30] & 0x80 ) && ! ( data & 0x02 ) ) |
| 568 | 543 | timer1_hi_enable = 1; |
| 569 | 544 | |
| 570 | | if ( ( pm_reg[0x1A] & 0x08 ) && ( pm_reg[0x38] & 0x04 ) && ! ( pm_reg[0x1B] & 0x01 ) ) |
| 545 | if ( ( state->pm_reg[0x1A] & 0x08 ) && ( state->pm_reg[0x38] & 0x04 ) && ! ( state->pm_reg[0x1B] & 0x01 ) ) |
| 571 | 546 | timer2_enable = 1; |
| 572 | 547 | |
| 573 | | if ( ( pm_reg[0x1A] & 0x80 ) && ( pm_reg[0x39] & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) && ! ( pm_reg[0x1B] & 0x02 ) ) |
| 548 | if ( ( state->pm_reg[0x1A] & 0x80 ) && ( state->pm_reg[0x39] & 0x04 ) && ! ( state->pm_reg[0x38] & 0x80 ) && ! ( state->pm_reg[0x1B] & 0x02 ) ) |
| 574 | 549 | timer2_hi_enable = 1; |
| 575 | 550 | |
| 576 | | if ( ( pm_reg[0x1C] & 0x08 ) && ( pm_reg[0x48] & 0x04 ) && ! ( pm_reg[0x1D] & 0x01 ) ) |
| 551 | if ( ( state->pm_reg[0x1C] & 0x08 ) && ( state->pm_reg[0x48] & 0x04 ) && ! ( state->pm_reg[0x1D] & 0x01 ) ) |
| 577 | 552 | timer3_enable = 1; |
| 578 | 553 | |
| 579 | | if ( ( pm_reg[0x1C] & 0x80 ) && ( pm_reg[0x49] & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) && ! ( pm_reg[0x1D] & 0x02 ) ) |
| 554 | if ( ( state->pm_reg[0x1C] & 0x80 ) && ( state->pm_reg[0x49] & 0x04 ) && ! ( state->pm_reg[0x48] & 0x80 ) && ! ( state->pm_reg[0x1D] & 0x02 ) ) |
| 580 | 555 | timer3_hi_enable = 1; |
| 581 | 556 | } |
| 582 | 557 | |
| 583 | 558 | /* Check which slow timers should be enabled */ |
| 584 | 559 | if ( data & 0x10 ) |
| 585 | 560 | { |
| 586 | | if ( ( pm_reg[0x18] & 0x08 ) && ( data & 0x01 ) ) |
| 561 | if ( ( state->pm_reg[0x18] & 0x08 ) && ( data & 0x01 ) ) |
| 587 | 562 | timer1_enable = 1; |
| 588 | 563 | |
| 589 | | if ( ( pm_reg[0x1A] & 0x08 ) && ( pm_reg[0x1B] & 0x01 ) ) |
| 564 | if ( ( state->pm_reg[0x1A] & 0x08 ) && ( state->pm_reg[0x1B] & 0x01 ) ) |
| 590 | 565 | timer2_enable = 1; |
| 591 | 566 | |
| 592 | | if ( ( pm_reg[0x1C] & 0x08 ) && ( pm_reg[0x1D] & 0x01 ) ) |
| 567 | if ( ( state->pm_reg[0x1C] & 0x08 ) && ( state->pm_reg[0x1D] & 0x01 ) ) |
| 593 | 568 | timer3_enable = 1; |
| 594 | 569 | } |
| 595 | | timer_enable( timers.timer1, timer1_enable ); |
| 596 | | timer_enable( timers.timer1_hi, timer1_hi_enable ); |
| 597 | | timer_enable( timers.timer2, timer2_enable ); |
| 598 | | timer_enable( timers.timer2_hi, timer2_hi_enable ); |
| 599 | | timer_enable( timers.timer3, timer3_enable ); |
| 600 | | timer_enable( timers.timer3_hi, timer3_hi_enable ); |
| 570 | timer_enable( state->timers.timer1, timer1_enable ); |
| 571 | timer_enable( state->timers.timer1_hi, timer1_hi_enable ); |
| 572 | timer_enable( state->timers.timer2, timer2_enable ); |
| 573 | timer_enable( state->timers.timer2_hi, timer2_hi_enable ); |
| 574 | timer_enable( state->timers.timer3, timer3_enable ); |
| 575 | timer_enable( state->timers.timer3_hi, timer3_hi_enable ); |
| 601 | 576 | } |
| 602 | 577 | break; |
| 603 | 578 | case 0x1A: /* Timer 2 pre-scale + enable |
| r9669 | r9670 | |
| 615 | 590 | Bit 7 R/W Enable high counting |
| 616 | 591 | */ |
| 617 | 592 | /* Check for prescaler change for the low counter */ |
| 618 | | if ( ( data & 0x07 ) != ( pm_reg[0x1A] & 0x07 ) ) |
| 593 | if ( ( data & 0x07 ) != ( state->pm_reg[0x1A] & 0x07 ) ) |
| 619 | 594 | { |
| 620 | 595 | int index = data & 0x07; |
| 621 | | int cycles = ( pm_reg[0x1B] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 596 | int cycles = ( state->pm_reg[0x1B] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 622 | 597 | |
| 623 | | timer_adjust_periodic(timers.timer2, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 598 | timer_adjust_periodic(state->timers.timer2, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 624 | 599 | } |
| 625 | 600 | |
| 626 | 601 | /* Check for prescaler change for the high counter */ |
| 627 | | if ( ( data & 0x70 ) != ( pm_reg[0x1A] & 0x70 ) ) |
| 602 | if ( ( data & 0x70 ) != ( state->pm_reg[0x1A] & 0x70 ) ) |
| 628 | 603 | { |
| 629 | 604 | int index = ( data >> 4 ) & 0x07; |
| 630 | | int cycles = ( pm_reg[0x1B] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 605 | int cycles = ( state->pm_reg[0x1B] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 631 | 606 | |
| 632 | | timer_adjust_periodic(timers.timer2_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 607 | timer_adjust_periodic(state->timers.timer2_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 633 | 608 | } |
| 634 | 609 | |
| 635 | 610 | /* Check if timer2 low should be enabled */ |
| 636 | | if ( ( data & 0x08 ) && ( pm_reg[0x38] & 0x04 ) && |
| 637 | | ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x01 ) ) || |
| 638 | | ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x01 ) ) ) ) |
| 611 | if ( ( data & 0x08 ) && ( state->pm_reg[0x38] & 0x04 ) && |
| 612 | ( ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1B] & 0x01 ) ) || |
| 613 | ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1B] & 0x01 ) ) ) ) |
| 639 | 614 | { |
| 640 | | timer_enable( timers.timer2, 1 ); |
| 615 | timer_enable( state->timers.timer2, 1 ); |
| 641 | 616 | } |
| 642 | 617 | else |
| 643 | 618 | { |
| 644 | | timer_enable( timers.timer2, 0 ); |
| 619 | timer_enable( state->timers.timer2, 0 ); |
| 645 | 620 | } |
| 646 | 621 | |
| 647 | 622 | /* Check if timer2 high should be enabled */ |
| 648 | | if ( ( data & 0x80 ) && ( pm_reg[0x39] & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) && |
| 649 | | ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x02 ) ) || |
| 650 | | ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x02 ) ) ) ) |
| 623 | if ( ( data & 0x80 ) && ( state->pm_reg[0x39] & 0x04 ) && ! ( state->pm_reg[0x38] & 0x80 ) && |
| 624 | ( ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1B] & 0x02 ) ) || |
| 625 | ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1B] & 0x02 ) ) ) ) |
| 651 | 626 | { |
| 652 | | timer_enable( timers.timer2_hi, 1 ); |
| 627 | timer_enable( state->timers.timer2_hi, 1 ); |
| 653 | 628 | } |
| 654 | 629 | else |
| 655 | 630 | { |
| 656 | | timer_enable( timers.timer2_hi, 0 ); |
| 631 | timer_enable( state->timers.timer2_hi, 0 ); |
| 657 | 632 | } |
| 658 | 633 | break; |
| 659 | 634 | case 0x1B: /* Timer 2 speeds |
| r9669 | r9670 | |
| 661 | 636 | Bit 1 R/W Select slow timer for timer 2 hi |
| 662 | 637 | */ |
| 663 | 638 | /* Check for prescaler change for the high counter */ |
| 664 | | if ( ( data & 0x01 ) != ( pm_reg[0x1B] & 0x01 ) ) |
| 639 | if ( ( data & 0x01 ) != ( state->pm_reg[0x1B] & 0x01 ) ) |
| 665 | 640 | { |
| 666 | | int index = pm_reg[0x1A] & 0x07; |
| 641 | int index = state->pm_reg[0x1A] & 0x07; |
| 667 | 642 | int cycles = ( data & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 668 | 643 | |
| 669 | | timer_adjust_periodic(timers.timer2, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 644 | timer_adjust_periodic(state->timers.timer2, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 670 | 645 | |
| 671 | | if ( ( pm_reg[0x1A] & 0x08 ) && ( pm_reg[0x38] & 0x04 ) && |
| 672 | | ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x01 ) ) || |
| 673 | | ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x01 ) ) ) ) |
| 646 | if ( ( state->pm_reg[0x1A] & 0x08 ) && ( state->pm_reg[0x38] & 0x04 ) && |
| 647 | ( ( ( state->pm_reg[0x19] & 0x10 ) && ( data & 0x01 ) ) || |
| 648 | ( ( state->pm_reg[0x19] & 0x20 ) && ! ( data & 0x01 ) ) ) ) |
| 674 | 649 | { |
| 675 | | timer_enable( timers.timer2, 1 ); |
| 650 | timer_enable( state->timers.timer2, 1 ); |
| 676 | 651 | } |
| 677 | 652 | else |
| 678 | 653 | { |
| 679 | | timer_enable( timers.timer2, 0 ); |
| 654 | timer_enable( state->timers.timer2, 0 ); |
| 680 | 655 | } |
| 681 | 656 | } |
| 682 | 657 | |
| 683 | 658 | /* Check for prescaler change for the low counter */ |
| 684 | | if ( ( data & 0x02 ) != ( pm_reg[0x1B] & 0x02 ) ) |
| 659 | if ( ( data & 0x02 ) != ( state->pm_reg[0x1B] & 0x02 ) ) |
| 685 | 660 | { |
| 686 | | int index = ( pm_reg[0x1A] >> 4 ) & 0x07; |
| 661 | int index = ( state->pm_reg[0x1A] >> 4 ) & 0x07; |
| 687 | 662 | int cycles = ( data & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 688 | 663 | |
| 689 | | timer_adjust_periodic(timers.timer2_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 664 | timer_adjust_periodic(state->timers.timer2_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 690 | 665 | |
| 691 | | if ( ( pm_reg[0x1A] & 0x80 ) && ( pm_reg[0x39] & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) && |
| 692 | | ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x02 ) ) || |
| 693 | | ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x02 ) ) ) ) |
| 666 | if ( ( state->pm_reg[0x1A] & 0x80 ) && ( state->pm_reg[0x39] & 0x04 ) && ! ( state->pm_reg[0x38] & 0x80 ) && |
| 667 | ( ( ( state->pm_reg[0x19] & 0x10 ) && ( data & 0x02 ) ) || |
| 668 | ( ( state->pm_reg[0x19] & 0x20 ) && ! ( data & 0x02 ) ) ) ) |
| 694 | 669 | { |
| 695 | | timer_enable( timers.timer2_hi, 1 ); |
| 670 | timer_enable( state->timers.timer2_hi, 1 ); |
| 696 | 671 | } |
| 697 | 672 | else |
| 698 | 673 | { |
| 699 | | timer_enable( timers.timer2_hi, 0 ); |
| 674 | timer_enable( state->timers.timer2_hi, 0 ); |
| 700 | 675 | } |
| 701 | 676 | } |
| 702 | 677 | break; |
| r9669 | r9670 | |
| 715 | 690 | Bit 7 R/W Enable high counting |
| 716 | 691 | */ |
| 717 | 692 | /* Check for prescaler change for the low counter */ |
| 718 | | if ( ( data & 0x07 ) != ( pm_reg[0x1C] & 0x07 ) ) |
| 693 | if ( ( data & 0x07 ) != ( state->pm_reg[0x1C] & 0x07 ) ) |
| 719 | 694 | { |
| 720 | 695 | int index = data & 0x07; |
| 721 | | int cycles = ( pm_reg[0x1D] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 696 | int cycles = ( state->pm_reg[0x1D] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 722 | 697 | |
| 723 | | timer_adjust_periodic(timers.timer3, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 698 | timer_adjust_periodic(state->timers.timer3, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 724 | 699 | } |
| 725 | 700 | |
| 726 | 701 | /* Check for prescaler change for the high counter */ |
| 727 | | if ( ( data & 0x70 ) != ( pm_reg[0x1C] & 0x70 ) ) |
| 702 | if ( ( data & 0x70 ) != ( state->pm_reg[0x1C] & 0x70 ) ) |
| 728 | 703 | { |
| 729 | 704 | int index = ( data >> 4 ) & 0x07; |
| 730 | | int cycles = ( pm_reg[0x1D] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 705 | int cycles = ( state->pm_reg[0x1D] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 731 | 706 | |
| 732 | | timer_adjust_periodic(timers.timer3_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 707 | timer_adjust_periodic(state->timers.timer3_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 733 | 708 | } |
| 734 | 709 | |
| 735 | 710 | /* Check if timer2 low should be enabled */ |
| 736 | | if ( ( data & 0x08 ) && ( pm_reg[0x48] & 0x04 ) && |
| 737 | | ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x01 ) ) || |
| 738 | | ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x01 ) ) ) ) |
| 711 | if ( ( data & 0x08 ) && ( state->pm_reg[0x48] & 0x04 ) && |
| 712 | ( ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1D] & 0x01 ) ) || |
| 713 | ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1D] & 0x01 ) ) ) ) |
| 739 | 714 | { |
| 740 | | timer_enable( timers.timer3, 1 ); |
| 715 | timer_enable( state->timers.timer3, 1 ); |
| 741 | 716 | } |
| 742 | 717 | else |
| 743 | 718 | { |
| 744 | | timer_enable( timers.timer3, 0 ); |
| 719 | timer_enable( state->timers.timer3, 0 ); |
| 745 | 720 | } |
| 746 | 721 | |
| 747 | 722 | /* Check if timer2 high should be enabled */ |
| 748 | | if ( ( data & 0x80 ) && ( pm_reg[0x49] & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) && |
| 749 | | ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x02 ) ) || |
| 750 | | ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x02 ) ) ) ) |
| 723 | if ( ( data & 0x80 ) && ( state->pm_reg[0x49] & 0x04 ) && ! ( state->pm_reg[0x48] & 0x80 ) && |
| 724 | ( ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1D] & 0x02 ) ) || |
| 725 | ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1D] & 0x02 ) ) ) ) |
| 751 | 726 | { |
| 752 | | timer_enable( timers.timer3_hi, 1 ); |
| 727 | timer_enable( state->timers.timer3_hi, 1 ); |
| 753 | 728 | } |
| 754 | 729 | else |
| 755 | 730 | { |
| 756 | | timer_enable( timers.timer3_hi, 0 ); |
| 731 | timer_enable( state->timers.timer3_hi, 0 ); |
| 757 | 732 | } |
| 758 | 733 | break; |
| 759 | 734 | case 0x1D: /* Timer 3 speeds |
| r9669 | r9670 | |
| 761 | 736 | Bit 1 R/W Select slow timer for timer 3 hi |
| 762 | 737 | */ |
| 763 | 738 | /* Check for prescaler change for the high counter */ |
| 764 | | if ( ( data & 0x01 ) != ( pm_reg[0x1D] & 0x01 ) ) |
| 739 | if ( ( data & 0x01 ) != ( state->pm_reg[0x1D] & 0x01 ) ) |
| 765 | 740 | { |
| 766 | | int index = pm_reg[0x1C] & 0x07; |
| 741 | int index = state->pm_reg[0x1C] & 0x07; |
| 767 | 742 | int cycles = ( data & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 768 | 743 | |
| 769 | | timer_adjust_periodic(timers.timer3, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 744 | timer_adjust_periodic(state->timers.timer3, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 770 | 745 | |
| 771 | | if ( ( pm_reg[0x1C] & 0x08 ) && ( pm_reg[0x48] & 0x04 ) && |
| 772 | | ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x01 ) ) || |
| 773 | | ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x01 ) ) ) ) |
| 746 | if ( ( state->pm_reg[0x1C] & 0x08 ) && ( state->pm_reg[0x48] & 0x04 ) && |
| 747 | ( ( ( state->pm_reg[0x19] & 0x10 ) && ( data & 0x01 ) ) || |
| 748 | ( ( state->pm_reg[0x19] & 0x20 ) && ! ( data & 0x01 ) ) ) ) |
| 774 | 749 | { |
| 775 | | timer_enable( timers.timer3, 1 ); |
| 750 | timer_enable( state->timers.timer3, 1 ); |
| 776 | 751 | } |
| 777 | 752 | else |
| 778 | 753 | { |
| 779 | | timer_enable( timers.timer3, 0 ); |
| 754 | timer_enable( state->timers.timer3, 0 ); |
| 780 | 755 | } |
| 781 | 756 | } |
| 782 | 757 | |
| 783 | 758 | /* Check for prescaler change for the low counter */ |
| 784 | | if ( ( data & 0x02 ) != ( pm_reg[0x1D] & 0x02 ) ) |
| 759 | if ( ( data & 0x02 ) != ( state->pm_reg[0x1D] & 0x02 ) ) |
| 785 | 760 | { |
| 786 | | int index = ( pm_reg[0x1C] >> 4 ) & 0x07; |
| 761 | int index = ( state->pm_reg[0x1C] >> 4 ) & 0x07; |
| 787 | 762 | int cycles = ( data & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 788 | 763 | |
| 789 | | timer_adjust_periodic(timers.timer3_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 764 | timer_adjust_periodic(state->timers.timer3_hi, attotime_zero, 0, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(cycles)); |
| 790 | 765 | |
| 791 | | if ( ( pm_reg[0x1C] & 0x80 ) && ( pm_reg[0x49] & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) && |
| 792 | | ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x02 ) ) || |
| 793 | | ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x02 ) ) ) ) |
| 766 | if ( ( state->pm_reg[0x1C] & 0x80 ) && ( state->pm_reg[0x49] & 0x04 ) && ! ( state->pm_reg[0x48] & 0x80 ) && |
| 767 | ( ( ( state->pm_reg[0x19] & 0x10 ) && ( data & 0x02 ) ) || |
| 768 | ( ( state->pm_reg[0x19] & 0x20 ) && ! ( data & 0x02 ) ) ) ) |
| 794 | 769 | { |
| 795 | | timer_enable( timers.timer3_hi, 1 ); |
| 770 | timer_enable( state->timers.timer3_hi, 1 ); |
| 796 | 771 | } |
| 797 | 772 | else |
| 798 | 773 | { |
| 799 | | timer_enable( timers.timer3_hi, 0 ); |
| 774 | timer_enable( state->timers.timer3_hi, 0 ); |
| 800 | 775 | } |
| 801 | 776 | } |
| 802 | 777 | break; |
| r9669 | r9670 | |
| 806 | 781 | Bit 4-5 R/W Timer 2 overflow Interrupt #3-#4 |
| 807 | 782 | Bit 6-7 R/W VDraw/VBlank trigger Interrupt #1-#2 |
| 808 | 783 | */ |
| 809 | | pm_reg[0x20] = data; |
| 784 | state->pm_reg[0x20] = data; |
| 810 | 785 | pokemini_check_irqs( device->machine ); |
| 811 | 786 | break; |
| 812 | 787 | case 0x21: /* Event #15-#22 priority |
| r9669 | r9670 | |
| 814 | 789 | Bit 2-3 R/W All keypad interrupts - Interrupt #15-#22 |
| 815 | 790 | Bit 4-7 R/W Unknown |
| 816 | 791 | */ |
| 817 | | pm_reg[0x21] = data; |
| 792 | state->pm_reg[0x21] = data; |
| 818 | 793 | pokemini_check_irqs( device->machine ); |
| 819 | 794 | break; |
| 820 | 795 | case 0x22: /* Event #9-#14 priority |
| 821 | 796 | Bit 0-1 R/W All #9 - #14 events - Interrupt #9-#14 |
| 822 | 797 | Bit 2-7 Unused |
| 823 | 798 | */ |
| 824 | | pm_reg[0x22] = data; |
| 799 | state->pm_reg[0x22] = data; |
| 825 | 800 | pokemini_check_irqs( device->machine ); |
| 826 | 801 | break; |
| 827 | 802 | case 0x23: /* Event #1-#8 enable |
| r9669 | r9670 | |
| 834 | 809 | Bit 6 R/W V-Draw trigger - Enable Interrupt #2 |
| 835 | 810 | Bit 7 R/W V-Blank trigger - Enable Interrupt #1 |
| 836 | 811 | */ |
| 837 | | pm_reg[0x23] = data; |
| 812 | state->pm_reg[0x23] = data; |
| 838 | 813 | pokemini_check_irqs( device->machine ); |
| 839 | 814 | break; |
| 840 | 815 | case 0x24: /* Event #9-#12 enable |
| 841 | 816 | Bit 0-5 R/W Unknown |
| 842 | 817 | Bit 6-7 Unused |
| 843 | 818 | */ |
| 844 | | pm_reg[0x24] = data; |
| 819 | state->pm_reg[0x24] = data; |
| 845 | 820 | pokemini_check_irqs( device->machine ); |
| 846 | 821 | break; |
| 847 | 822 | case 0x25: /* Event #15-#22 enable |
| r9669 | r9670 | |
| 854 | 829 | Bit 6 R/W Press D-pad right key event - Enable interrupt #16 |
| 855 | 830 | Bit 7 R/W Press power button event - Enable interrupt #15 |
| 856 | 831 | */ |
| 857 | | pm_reg[0x25] = data; |
| 832 | state->pm_reg[0x25] = data; |
| 858 | 833 | pokemini_check_irqs( device->machine ); |
| 859 | 834 | break; |
| 860 | 835 | case 0x26: /* Event #13-#14 enable |
| r9669 | r9670 | |
| 864 | 839 | Bit 6 R/W Shock detector trigger - Enable interrupt #14 |
| 865 | 840 | Bit 7 R/W IR receiver - low to high trigger - Enable interrupt #13 |
| 866 | 841 | */ |
| 867 | | pm_reg[0x26] = data; |
| 842 | state->pm_reg[0x26] = data; |
| 868 | 843 | pokemini_check_irqs( device->machine ); |
| 869 | 844 | break; |
| 870 | 845 | case 0x27: /* Interrupt active flag #1-#8 |
| r9669 | r9670 | |
| 877 | 852 | Bit 6 VDraw trigger / Clear interrupt #2 |
| 878 | 853 | Bit 7 VBlank trigger / Clear interrupt #1 |
| 879 | 854 | */ |
| 880 | | pm_reg[0x27] &= ~data; |
| 855 | state->pm_reg[0x27] &= ~data; |
| 881 | 856 | pokemini_check_irqs( device->machine ); |
| 882 | 857 | return; |
| 883 | 858 | case 0x28: /* Interrupt active flag #9-#12 |
| r9669 | r9670 | |
| 888 | 863 | Bit 5 Unknown / Clear interrupt #9 |
| 889 | 864 | Bit 6-7 Unknown |
| 890 | 865 | */ |
| 891 | | pm_reg[0x28] &= ~data; |
| 866 | state->pm_reg[0x28] &= ~data; |
| 892 | 867 | pokemini_check_irqs( device->machine ); |
| 893 | 868 | return; |
| 894 | 869 | case 0x29: /* Interrupt active flag #15-#22 |
| r9669 | r9670 | |
| 901 | 876 | Bit 6 Press D-pad right key event / Clear interrupt #16 |
| 902 | 877 | Bit 7 Press power button event / Clear interrupt #15 |
| 903 | 878 | */ |
| 904 | | pm_reg[0x29] &= ~data; |
| 879 | state->pm_reg[0x29] &= ~data; |
| 905 | 880 | pokemini_check_irqs( device->machine ); |
| 906 | 881 | return; |
| 907 | 882 | case 0x2A: /* Interrupt active flag #13-#14 |
| r9669 | r9670 | |
| 909 | 884 | Bit 6 Shock detector trigger / Clear interrupt #14 |
| 910 | 885 | Bit 7 Unknown / Clear interrupt #13 |
| 911 | 886 | */ |
| 912 | | pm_reg[0x2A] &= ~data; |
| 887 | state->pm_reg[0x2A] &= ~data; |
| 913 | 888 | pokemini_check_irqs( device->machine ); |
| 914 | 889 | return; |
| 915 | 890 | case 0x30: /* Timer 1 control 1 |
| r9669 | r9670 | |
| 922 | 897 | */ |
| 923 | 898 | if ( data & 0x02 ) |
| 924 | 899 | { |
| 925 | | pm_reg[0x36] = pm_reg[0x32]; |
| 900 | state->pm_reg[0x36] = state->pm_reg[0x32]; |
| 926 | 901 | data &= ~0x02; |
| 927 | 902 | } |
| 928 | 903 | |
| 929 | | if ( ( data & 0x04 ) && ( pm_reg[0x18] & 0x08 ) && |
| 930 | | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x01 ) ) || |
| 931 | | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x01 ) ) ) ) |
| 904 | if ( ( data & 0x04 ) && ( state->pm_reg[0x18] & 0x08 ) && |
| 905 | ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x19] & 0x01 ) ) || |
| 906 | ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x19] & 0x01 ) ) ) ) |
| 932 | 907 | { |
| 933 | | timer_enable( timers.timer1, 1 ); |
| 908 | timer_enable( state->timers.timer1, 1 ); |
| 934 | 909 | } |
| 935 | 910 | else |
| 936 | 911 | { |
| 937 | | timer_enable( timers.timer1, 0 ); |
| 912 | timer_enable( state->timers.timer1, 0 ); |
| 938 | 913 | } |
| 939 | 914 | |
| 940 | | if ( ( pm_reg[0x31] & 0x04 ) && ! ( data & 0x80 ) && ( pm_reg[0x18] & 0x80 ) && |
| 941 | | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x02 ) ) || |
| 942 | | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x02 ) ) ) ) |
| 915 | if ( ( state->pm_reg[0x31] & 0x04 ) && ! ( data & 0x80 ) && ( state->pm_reg[0x18] & 0x80 ) && |
| 916 | ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x19] & 0x02 ) ) || |
| 917 | ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x19] & 0x02 ) ) ) ) |
| 943 | 918 | { |
| 944 | | timer_enable( timers.timer1_hi, 1 ); |
| 919 | timer_enable( state->timers.timer1_hi, 1 ); |
| 945 | 920 | } |
| 946 | 921 | else |
| 947 | 922 | { |
| 948 | | timer_enable( timers.timer1_hi, 0 ); |
| 923 | timer_enable( state->timers.timer1_hi, 0 ); |
| 949 | 924 | } |
| 950 | 925 | break; |
| 951 | 926 | case 0x31: /* Timer 1 control 2 |
| r9669 | r9670 | |
| 957 | 932 | */ |
| 958 | 933 | if ( data & 0x02 ) |
| 959 | 934 | { |
| 960 | | pm_reg[0x37] = pm_reg[0x33]; |
| 935 | state->pm_reg[0x37] = state->pm_reg[0x33]; |
| 961 | 936 | data &= ~0x02; |
| 962 | 937 | } |
| 963 | 938 | |
| 964 | | if ( ( data & 0x04 ) && ! ( pm_reg[0x30] & 0x80 ) && ( pm_reg[0x18] & 0x80 ) && |
| 965 | | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x02 ) ) || |
| 966 | | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x02 ) ) ) ) |
| 939 | if ( ( data & 0x04 ) && ! ( state->pm_reg[0x30] & 0x80 ) && ( state->pm_reg[0x18] & 0x80 ) && |
| 940 | ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x19] & 0x02 ) ) || |
| 941 | ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x19] & 0x02 ) ) ) ) |
| 967 | 942 | { |
| 968 | | timer_enable( timers.timer1_hi, 1 ); |
| 943 | timer_enable( state->timers.timer1_hi, 1 ); |
| 969 | 944 | } |
| 970 | 945 | else |
| 971 | 946 | { |
| 972 | | timer_enable( timers.timer1_hi, 0 ); |
| 947 | timer_enable( state->timers.timer1_hi, 0 ); |
| 973 | 948 | } |
| 974 | 949 | break; |
| 975 | 950 | case 0x32: /* Timer 1 preset value (low) |
| r9669 | r9670 | |
| 1002 | 977 | */ |
| 1003 | 978 | if ( data & 0x02 ) |
| 1004 | 979 | { |
| 1005 | | pm_reg[0x3E] = pm_reg[0x3A]; |
| 980 | state->pm_reg[0x3E] = state->pm_reg[0x3A]; |
| 1006 | 981 | data &= ~0x02; |
| 1007 | 982 | } |
| 1008 | 983 | |
| 1009 | | if ( ( data & 0x04 ) && ( pm_reg[0x1A] & 0x08 ) && |
| 1010 | | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1A] & 0x01 ) ) || |
| 1011 | | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1A] & 0x01 ) ) ) ) |
| 984 | if ( ( data & 0x04 ) && ( state->pm_reg[0x1A] & 0x08 ) && |
| 985 | ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1A] & 0x01 ) ) || |
| 986 | ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1A] & 0x01 ) ) ) ) |
| 1012 | 987 | { |
| 1013 | | timer_enable( timers.timer2, 1 ); |
| 988 | timer_enable( state->timers.timer2, 1 ); |
| 1014 | 989 | } |
| 1015 | 990 | else |
| 1016 | 991 | { |
| 1017 | | timer_enable( timers.timer2, 0 ); |
| 992 | timer_enable( state->timers.timer2, 0 ); |
| 1018 | 993 | } |
| 1019 | | if ( ( pm_reg[0x39] & 0x04 ) && ! ( data & 0x80 ) && ( pm_reg[0x1A] & 0x80 ) && |
| 1020 | | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x02 ) ) || |
| 1021 | | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x02 ) ) ) ) |
| 994 | if ( ( state->pm_reg[0x39] & 0x04 ) && ! ( data & 0x80 ) && ( state->pm_reg[0x1A] & 0x80 ) && |
| 995 | ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1B] & 0x02 ) ) || |
| 996 | ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1B] & 0x02 ) ) ) ) |
| 1022 | 997 | { |
| 1023 | | timer_enable( timers.timer2_hi, 1 ); |
| 998 | timer_enable( state->timers.timer2_hi, 1 ); |
| 1024 | 999 | } |
| 1025 | 1000 | else |
| 1026 | 1001 | { |
| 1027 | | timer_enable( timers.timer2_hi, 0 ); |
| 1002 | timer_enable( state->timers.timer2_hi, 0 ); |
| 1028 | 1003 | } |
| 1029 | 1004 | break; |
| 1030 | 1005 | case 0x39: /* Timer 2 control 2 |
| r9669 | r9670 | |
| 1036 | 1011 | */ |
| 1037 | 1012 | if ( data & 0x02 ) |
| 1038 | 1013 | { |
| 1039 | | pm_reg[0x3F] = pm_reg[0x3A]; |
| 1014 | state->pm_reg[0x3F] = state->pm_reg[0x3A]; |
| 1040 | 1015 | data &= ~0x02; |
| 1041 | 1016 | } |
| 1042 | 1017 | |
| 1043 | | if ( ( data & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) && ( pm_reg[0x1A] & 0x80 ) && |
| 1044 | | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x02 ) ) || |
| 1045 | | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x02 ) ) ) ) |
| 1018 | if ( ( data & 0x04 ) && ! ( state->pm_reg[0x38] & 0x80 ) && ( state->pm_reg[0x1A] & 0x80 ) && |
| 1019 | ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1B] & 0x02 ) ) || |
| 1020 | ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1B] & 0x02 ) ) ) ) |
| 1046 | 1021 | { |
| 1047 | | timer_enable( timers.timer2_hi, 1 ); |
| 1022 | timer_enable( state->timers.timer2_hi, 1 ); |
| 1048 | 1023 | } |
| 1049 | 1024 | else |
| 1050 | 1025 | { |
| 1051 | | timer_enable( timers.timer2_hi, 0 ); |
| 1026 | timer_enable( state->timers.timer2_hi, 0 ); |
| 1052 | 1027 | } |
| 1053 | 1028 | break; |
| 1054 | 1029 | case 0x3A: /* Timer 2 preset value (low) |
| r9669 | r9670 | |
| 1080 | 1055 | */ |
| 1081 | 1056 | if ( data & 0x02 ) |
| 1082 | 1057 | { |
| 1083 | | pm_reg[0x41] = 0; |
| 1058 | state->pm_reg[0x41] = 0; |
| 1084 | 1059 | data &= ~0x02; |
| 1085 | 1060 | } |
| 1086 | 1061 | break; |
| r9669 | r9670 | |
| 1098 | 1073 | */ |
| 1099 | 1074 | if ( data & 0x02 ) |
| 1100 | 1075 | { |
| 1101 | | pm_reg[0x4E] = pm_reg[0x4A]; |
| 1076 | state->pm_reg[0x4E] = state->pm_reg[0x4A]; |
| 1102 | 1077 | data &= ~0x02; |
| 1103 | 1078 | } |
| 1104 | 1079 | |
| 1105 | | if ( ( data & 0x04 ) && ( pm_reg[0x1C] & 0x08 ) && |
| 1106 | | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x01 ) ) || |
| 1107 | | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x01 ) ) ) ) |
| 1080 | if ( ( data & 0x04 ) && ( state->pm_reg[0x1C] & 0x08 ) && |
| 1081 | ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1D] & 0x01 ) ) || |
| 1082 | ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1D] & 0x01 ) ) ) ) |
| 1108 | 1083 | { |
| 1109 | | timer_enable( timers.timer3, 1 ); |
| 1084 | timer_enable( state->timers.timer3, 1 ); |
| 1110 | 1085 | } |
| 1111 | 1086 | else |
| 1112 | 1087 | { |
| 1113 | | timer_enable( timers.timer3, 0 ); |
| 1088 | timer_enable( state->timers.timer3, 0 ); |
| 1114 | 1089 | } |
| 1115 | | if ( ( pm_reg[0x49] & 0x04 ) && ! ( data & 0x80 ) && ( pm_reg[0x1C] & 0x80 ) && |
| 1116 | | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x02 ) ) || |
| 1117 | | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x02 ) ) ) ) |
| 1090 | if ( ( state->pm_reg[0x49] & 0x04 ) && ! ( data & 0x80 ) && ( state->pm_reg[0x1C] & 0x80 ) && |
| 1091 | ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1D] & 0x02 ) ) || |
| 1092 | ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1D] & 0x02 ) ) ) ) |
| 1118 | 1093 | { |
| 1119 | | timer_enable( timers.timer3_hi, 1 ); |
| 1094 | timer_enable( state->timers.timer3_hi, 1 ); |
| 1120 | 1095 | } |
| 1121 | 1096 | else |
| 1122 | 1097 | { |
| 1123 | | timer_enable( timers.timer3_hi, 0 ); |
| 1098 | timer_enable( state->timers.timer3_hi, 0 ); |
| 1124 | 1099 | } |
| 1125 | | pm_reg[0x48] = data; |
| 1100 | state->pm_reg[0x48] = data; |
| 1126 | 1101 | pokemini_update_sound( device->machine ); |
| 1127 | 1102 | break; |
| 1128 | 1103 | case 0x49: /* Timer 3 control 2 |
| r9669 | r9670 | |
| 1134 | 1109 | */ |
| 1135 | 1110 | if ( data & 0x02 ) |
| 1136 | 1111 | { |
| 1137 | | pm_reg[0x4F] = pm_reg[0x4B]; |
| 1112 | state->pm_reg[0x4F] = state->pm_reg[0x4B]; |
| 1138 | 1113 | data &= ~0x02; |
| 1139 | 1114 | } |
| 1140 | 1115 | |
| 1141 | | if ( ( data & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) && ( pm_reg[0x1C] & 0x80 ) && |
| 1142 | | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x02 ) ) || |
| 1143 | | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x02 ) ) ) ) |
| 1116 | if ( ( data & 0x04 ) && ! ( state->pm_reg[0x48] & 0x80 ) && ( state->pm_reg[0x1C] & 0x80 ) && |
| 1117 | ( ( ( state->pm_reg[0x19] & 0x20 ) && ! ( state->pm_reg[0x1D] & 0x02 ) ) || |
| 1118 | ( ( state->pm_reg[0x19] & 0x10 ) && ( state->pm_reg[0x1D] & 0x02 ) ) ) ) |
| 1144 | 1119 | { |
| 1145 | | timer_enable( timers.timer3_hi, 1 ); |
| 1120 | timer_enable( state->timers.timer3_hi, 1 ); |
| 1146 | 1121 | } |
| 1147 | 1122 | else |
| 1148 | 1123 | { |
| 1149 | | timer_enable( timers.timer3_hi, 0 ); |
| 1124 | timer_enable( state->timers.timer3_hi, 0 ); |
| 1150 | 1125 | } |
| 1151 | | pm_reg[0x49] = data; |
| 1126 | state->pm_reg[0x49] = data; |
| 1152 | 1127 | pokemini_update_sound( device->machine ); |
| 1153 | 1128 | break; |
| 1154 | 1129 | case 0x4A: /* Timer 3 preset value (low) |
| 1155 | 1130 | Bit 0-7 R/W Timer 3 preset value bit 0-7 |
| 1156 | 1131 | */ |
| 1157 | | pm_reg[0x4A] = data; |
| 1132 | state->pm_reg[0x4A] = data; |
| 1158 | 1133 | pokemini_update_sound( device->machine ); |
| 1159 | 1134 | break; |
| 1160 | 1135 | case 0x4B: /* Timer 3 preset value (high) |
| 1161 | 1136 | Bit 0-7 R/W Timer 3 preset value bit 8-15 |
| 1162 | 1137 | */ |
| 1163 | | pm_reg[0x4B] = data; |
| 1138 | state->pm_reg[0x4B] = data; |
| 1164 | 1139 | pokemini_update_sound( device->machine ); |
| 1165 | 1140 | break; |
| 1166 | 1141 | case 0x4C: /* Timer 3 sound-pivot (low) |
| 1167 | 1142 | Bit 0-7 R/W Timer 3 sound-pivot value bit 0-7 |
| 1168 | 1143 | */ |
| 1169 | | pm_reg[0x4C] = data; |
| 1144 | state->pm_reg[0x4C] = data; |
| 1170 | 1145 | pokemini_update_sound( device->machine ); |
| 1171 | 1146 | break; |
| 1172 | 1147 | case 0x4D: /* Timer 3 sound-pivot (high) |
| r9669 | r9670 | |
| 1177 | 1152 | Pulse-Width of 50% = Half of preset-value |
| 1178 | 1153 | Pulse-Width of 100% = Same as preset-value |
| 1179 | 1154 | */ |
| 1180 | | pm_reg[0x4D] = data; |
| 1155 | state->pm_reg[0x4D] = data; |
| 1181 | 1156 | pokemini_update_sound( device->machine ); |
| 1182 | 1157 | break; |
| 1183 | 1158 | case 0x4E: /* Timer 3 counter (low), read only |
| r9669 | r9670 | |
| 1220 | 1195 | Bit 6 Always 1 |
| 1221 | 1196 | Bit 7 R/W IR received bit (mirror, if device not selected: 0) |
| 1222 | 1197 | */ |
| 1223 | | if ( pm_reg[0x60] & 0x04 ) |
| 1198 | if ( state->pm_reg[0x60] & 0x04 ) |
| 1224 | 1199 | i2cmem_sda_write(device, ( data & 0x04 ) ? 1 : 0 ); |
| 1225 | 1200 | |
| 1226 | | if ( pm_reg[0x60] & 0x08 ) |
| 1201 | if ( state->pm_reg[0x60] & 0x08 ) |
| 1227 | 1202 | i2cmem_scl_write(device, ( data & 0x08 ) ? 1 : 0 ); |
| 1228 | 1203 | break; |
| 1229 | 1204 | case 0x70: /* Sound related */ |
| 1230 | | pm_reg[0x70] = data; |
| 1205 | state->pm_reg[0x70] = data; |
| 1231 | 1206 | pokemini_update_sound( device->machine ); |
| 1232 | 1207 | break; |
| 1233 | 1208 | case 0x71: /* Sound volume |
| r9669 | r9670 | |
| 1239 | 1214 | Bit 2 R/W Always set to 0 |
| 1240 | 1215 | Bit 3-7 Unused |
| 1241 | 1216 | */ |
| 1242 | | pm_reg[0x71] = data; |
| 1217 | state->pm_reg[0x71] = data; |
| 1243 | 1218 | pokemini_update_sound( device->machine ); |
| 1244 | 1219 | break; |
| 1245 | 1220 | case 0x80: /* LCD control |
| r9669 | r9670 | |
| 1254 | 1229 | 11 - 24x8 (prohibited code) |
| 1255 | 1230 | Bit 6-7 Unused |
| 1256 | 1231 | */ |
| 1257 | | prc.colors_inverted = ( data & 0x01 ) ? 1 : 0; |
| 1258 | | prc.background_enabled = ( data & 0x02 ) ? 1 : 0; |
| 1259 | | prc.sprites_enabled = ( data & 0x04 ) ? 1 : 0; |
| 1260 | | prc.copy_enabled = ( data & 0x08 ) ? 1 : 0; |
| 1261 | | prc.map_size = ( data >> 4 ) & 0x03; |
| 1262 | | switch( prc.map_size ) |
| 1232 | state->prc.colors_inverted = ( data & 0x01 ) ? 1 : 0; |
| 1233 | state->prc.background_enabled = ( data & 0x02 ) ? 1 : 0; |
| 1234 | state->prc.sprites_enabled = ( data & 0x04 ) ? 1 : 0; |
| 1235 | state->prc.copy_enabled = ( data & 0x08 ) ? 1 : 0; |
| 1236 | state->prc.map_size = ( data >> 4 ) & 0x03; |
| 1237 | switch( state->prc.map_size ) |
| 1263 | 1238 | { |
| 1264 | 1239 | case 0: |
| 1265 | | prc.map_size_x = 12; break; |
| 1240 | state->prc.map_size_x = 12; break; |
| 1266 | 1241 | case 1: |
| 1267 | | prc.map_size_x = 16; break; |
| 1242 | state->prc.map_size_x = 16; break; |
| 1268 | 1243 | case 2: |
| 1269 | 1244 | case 3: |
| 1270 | | prc.map_size_x = 24; break; |
| 1245 | state->prc.map_size_x = 24; break; |
| 1271 | 1246 | } |
| 1272 | 1247 | break; |
| 1273 | 1248 | case 0x81: /* LCD render refresh rate |
| r9669 | r9670 | |
| 1285 | 1260 | */ |
| 1286 | 1261 | switch ( data & 0x0E ) |
| 1287 | 1262 | { |
| 1288 | | case 0x00: prc.max_frame_count = 3; break; |
| 1289 | | case 0x02: prc.max_frame_count = 6; break; |
| 1290 | | case 0x04: prc.max_frame_count = 9; break; |
| 1291 | | case 0x06: prc.max_frame_count = 12; break; |
| 1292 | | case 0x08: prc.max_frame_count = 2; break; |
| 1293 | | case 0x0A: prc.max_frame_count = 4; break; |
| 1294 | | case 0x0C: prc.max_frame_count = 6; break; |
| 1295 | | case 0x0E: prc.max_frame_count = 8; break; |
| 1263 | case 0x00: state->prc.max_frame_count = 3; break; |
| 1264 | case 0x02: state->prc.max_frame_count = 6; break; |
| 1265 | case 0x04: state->prc.max_frame_count = 9; break; |
| 1266 | case 0x06: state->prc.max_frame_count = 12; break; |
| 1267 | case 0x08: state->prc.max_frame_count = 2; break; |
| 1268 | case 0x0A: state->prc.max_frame_count = 4; break; |
| 1269 | case 0x0C: state->prc.max_frame_count = 6; break; |
| 1270 | case 0x0E: state->prc.max_frame_count = 8; break; |
| 1296 | 1271 | } |
| 1297 | 1272 | break; |
| 1298 | 1273 | case 0x82: /* BG tile data memory offset (low) |
| r9669 | r9670 | |
| 1300 | 1275 | Bit 3-7 R/W BG tile data memory offset bit 3-7 |
| 1301 | 1276 | */ |
| 1302 | 1277 | data &= 0xF8; |
| 1303 | | prc.bg_tiles = ( prc.bg_tiles & 0xFFFF00 ) | data; |
| 1278 | state->prc.bg_tiles = ( state->prc.bg_tiles & 0xFFFF00 ) | data; |
| 1304 | 1279 | break; |
| 1305 | 1280 | case 0x83: /* BG tile data memory offset (mid) |
| 1306 | 1281 | Bit 0-7 R/W BG tile data memory offset bit 8-15 |
| 1307 | 1282 | */ |
| 1308 | | prc.bg_tiles = ( prc.bg_tiles & 0xFF00FF ) | ( data << 8 ); |
| 1283 | state->prc.bg_tiles = ( state->prc.bg_tiles & 0xFF00FF ) | ( data << 8 ); |
| 1309 | 1284 | break; |
| 1310 | 1285 | case 0x84: /* BG tile data memory offset (high) |
| 1311 | 1286 | Bit 0-4 R/W BG tile data memory offset bit 16-20 |
| 1312 | 1287 | Bit 5-7 Unused |
| 1313 | 1288 | */ |
| 1314 | 1289 | data &= 0x1F; |
| 1315 | | prc.bg_tiles = ( prc.bg_tiles & 0x00FFFF ) | ( data << 16 ); |
| 1290 | state->prc.bg_tiles = ( state->prc.bg_tiles & 0x00FFFF ) | ( data << 16 ); |
| 1316 | 1291 | break; |
| 1317 | 1292 | case 0x85: /* BG vertical move |
| 1318 | 1293 | Bit 0-6 R/W Move the background up, move range: |
| r9669 | r9670 | |
| 1335 | 1310 | Bit 6-7 R/W Sprite tile data memory offset bit 6-7 |
| 1336 | 1311 | */ |
| 1337 | 1312 | data &= 0xC0; |
| 1338 | | prc.spr_tiles = ( prc.spr_tiles & 0xFFFF00 ) | data; |
| 1313 | state->prc.spr_tiles = ( state->prc.spr_tiles & 0xFFFF00 ) | data; |
| 1339 | 1314 | break; |
| 1340 | 1315 | case 0x88: /* Sprite tile data memory offset (med) |
| 1341 | 1316 | Bit 0-7 R/W Sprite tile data memory offset bit 8-15 |
| 1342 | 1317 | */ |
| 1343 | | prc.spr_tiles = ( prc.spr_tiles & 0xFF00FF ) | ( data << 8 ); |
| 1318 | state->prc.spr_tiles = ( state->prc.spr_tiles & 0xFF00FF ) | ( data << 8 ); |
| 1344 | 1319 | break; |
| 1345 | 1320 | case 0x89: /* Sprite tile data memory offset (high) |
| 1346 | 1321 | Bit 0-4 R/W Sprite tile data memory offset bit 16-20 |
| 1347 | 1322 | Bit 5-7 Unused |
| 1348 | 1323 | */ |
| 1349 | 1324 | data &= 0x1F; |
| 1350 | | prc.spr_tiles = ( prc.spr_tiles & 0x00FFFF ) | ( data << 16 ); |
| 1325 | state->prc.spr_tiles = ( state->prc.spr_tiles & 0x00FFFF ) | ( data << 16 ); |
| 1351 | 1326 | break; |
| 1352 | 1327 | case 0x8A: /* LCD status |
| 1353 | 1328 | Bit 0 R Unknown |
| r9669 | r9670 | |
| 1372 | 1347 | logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", cpu_get_pc( device->machine->firstcpu ), offset, data ); |
| 1373 | 1348 | break; |
| 1374 | 1349 | } |
| 1375 | | pm_reg[offset] = data; |
| 1350 | state->pm_reg[offset] = data; |
| 1376 | 1351 | } |
| 1377 | 1352 | |
| 1378 | 1353 | READ8_DEVICE_HANDLER( pokemini_hwreg_r ) |
| 1379 | 1354 | { |
| 1380 | | UINT8 data = pm_reg[offset]; |
| 1355 | pokemini_state *state = device->machine->driver_data<pokemini_state>(); |
| 1356 | UINT8 data = state->pm_reg[offset]; |
| 1381 | 1357 | |
| 1382 | 1358 | switch( offset ) |
| 1383 | 1359 | { |
| 1384 | 1360 | case 0x52: return input_port_read(device->machine, "INPUTS"); |
| 1385 | 1361 | case 0x61: |
| 1386 | | if ( ! ( pm_reg[0x60] & 0x04 ) ) |
| 1362 | if ( ! ( state->pm_reg[0x60] & 0x04 ) ) |
| 1387 | 1363 | { |
| 1388 | 1364 | data = ( data & ~ 0x04 ) | ( i2cmem_sda_read( device) ? 0x04 : 0x00 ); |
| 1389 | 1365 | } |
| 1390 | 1366 | |
| 1391 | | if ( ! ( pm_reg[0x60] & 0x08 ) ) |
| 1367 | if ( ! ( state->pm_reg[0x60] & 0x08 ) ) |
| 1392 | 1368 | { |
| 1393 | 1369 | data &= ~0x08; |
| 1394 | 1370 | } |
| 1395 | 1371 | break; |
| 1396 | | case 0x81: return ( pm_reg[offset] & 0x0F ) | ( prc.frame_count << 4 ); |
| 1397 | | case 0x8A: return prc.count; |
| 1372 | case 0x81: return ( state->pm_reg[offset] & 0x0F ) | ( state->prc.frame_count << 4 ); |
| 1373 | case 0x8A: return state->prc.count; |
| 1398 | 1374 | } |
| 1399 | 1375 | return data; |
| 1400 | 1376 | } |
| r9669 | r9670 | |
| 1442 | 1418 | |
| 1443 | 1419 | static TIMER_CALLBACK( pokemini_prc_counter_callback ) |
| 1444 | 1420 | { |
| 1421 | pokemini_state *state = machine->driver_data<pokemini_state>(); |
| 1445 | 1422 | address_space *space = cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ); |
| 1446 | | prc.count++; |
| 1423 | state->prc.count++; |
| 1447 | 1424 | |
| 1448 | 1425 | /* Check for overflow */ |
| 1449 | | if ( prc.count >= 0x42 ) |
| 1426 | if ( state->prc.count >= 0x42 ) |
| 1450 | 1427 | { |
| 1451 | | prc.count = 0; |
| 1452 | | prc.frame_count++; |
| 1428 | state->prc.count = 0; |
| 1429 | state->prc.frame_count++; |
| 1453 | 1430 | } |
| 1454 | 1431 | else |
| 1455 | 1432 | { |
| 1456 | | if ( prc.count == 0x18 && prc.frame_count >= prc.max_frame_count ) |
| 1433 | if ( state->prc.count == 0x18 && state->prc.frame_count >= state->prc.max_frame_count ) |
| 1457 | 1434 | { |
| 1458 | | prc.frame_count = 0; |
| 1435 | state->prc.frame_count = 0; |
| 1459 | 1436 | |
| 1460 | 1437 | /* Check if the background should be drawn */ |
| 1461 | | if ( prc.background_enabled ) |
| 1438 | if ( state->prc.background_enabled ) |
| 1462 | 1439 | { |
| 1463 | 1440 | int x, y; |
| 1464 | 1441 | for ( y = 0; y < 8; y++ ) { |
| 1465 | 1442 | for ( x = 0; x < 12; x++ ) { |
| 1466 | | UINT8 tile = pokemini_ram[ 0x360 + ( y * prc.map_size_x ) + x ]; |
| 1443 | UINT8 tile = state->ram[ 0x360 + ( y * state->prc.map_size_x ) + x ]; |
| 1467 | 1444 | int i; |
| 1468 | 1445 | for( i = 0; i < 8; i++ ) { |
| 1469 | | pokemini_ram[ ( y * 96 ) + ( x * 8 ) + i ] = space->read_byte( prc.bg_tiles + ( tile * 8 ) + i ); |
| 1446 | state->ram[ ( y * 96 ) + ( x * 8 ) + i ] = space->read_byte( state->prc.bg_tiles + ( tile * 8 ) + i ); |
| 1470 | 1447 | } |
| 1471 | 1448 | } |
| 1472 | 1449 | } |
| 1473 | 1450 | } |
| 1474 | 1451 | |
| 1475 | 1452 | /* Check if the sprites should be drawn */ |
| 1476 | | if ( prc.sprites_enabled ) |
| 1453 | if ( state->prc.sprites_enabled ) |
| 1477 | 1454 | { |
| 1478 | 1455 | UINT16 spr; |
| 1479 | 1456 | |
| 1480 | 1457 | for ( spr = 0x35C; spr >= 0x300; spr -= 4 ) |
| 1481 | 1458 | { |
| 1482 | | int spr_x = ( pokemini_ram[ spr + 0 ] & 0x7F ) - 16; |
| 1483 | | int spr_y = ( pokemini_ram[ spr + 1 ] & 0x7F ) - 16; |
| 1484 | | UINT8 spr_tile = pokemini_ram[ spr + 2 ]; |
| 1485 | | UINT8 spr_flag = pokemini_ram[ spr + 3 ]; |
| 1459 | int spr_x = ( state->ram[ spr + 0 ] & 0x7F ) - 16; |
| 1460 | int spr_y = ( state->ram[ spr + 1 ] & 0x7F ) - 16; |
| 1461 | UINT8 spr_tile = state->ram[ spr + 2 ]; |
| 1462 | UINT8 spr_flag = state->ram[ spr + 3 ]; |
| 1486 | 1463 | |
| 1487 | 1464 | if ( spr_flag & 0x08 ) |
| 1488 | 1465 | { |
| 1489 | 1466 | UINT16 gfx, mask; |
| 1490 | | UINT32 spr_base = prc.spr_tiles + spr_tile * 64; |
| 1467 | UINT32 spr_base = state->prc.spr_tiles + spr_tile * 64; |
| 1491 | 1468 | int i, j; |
| 1492 | 1469 | |
| 1493 | 1470 | for ( i = 0; i < 16; i++ ) |
| r9669 | r9670 | |
| 1516 | 1493 | { |
| 1517 | 1494 | if ( mask & 0x8000 ) |
| 1518 | 1495 | { |
| 1519 | | pokemini_ram[ ram_addr ] &= ~ ( 1 << ( ( spr_y + j ) & 0x07 ) ); |
| 1496 | state->ram[ ram_addr ] &= ~ ( 1 << ( ( spr_y + j ) & 0x07 ) ); |
| 1520 | 1497 | if ( gfx & 0x8000 ) |
| 1521 | 1498 | { |
| 1522 | | pokemini_ram[ ram_addr ] |= ( 1 << ( ( spr_y + j ) & 0x07 ) ); |
| 1499 | state->ram[ ram_addr ] |= ( 1 << ( ( spr_y + j ) & 0x07 ) ); |
| 1523 | 1500 | } |
| 1524 | 1501 | } |
| 1525 | 1502 | mask <<= 1; |
| r9669 | r9670 | |
| 1529 | 1506 | { |
| 1530 | 1507 | if ( mask & 0x0001 ) |
| 1531 | 1508 | { |
| 1532 | | pokemini_ram[ ram_addr ] &= ~ ( 1 << ( ( spr_y + j ) & 0x07 ) ); |
| 1509 | state->ram[ ram_addr ] &= ~ ( 1 << ( ( spr_y + j ) & 0x07 ) ); |
| 1533 | 1510 | if ( gfx & 0x0001 ) |
| 1534 | 1511 | { |
| 1535 | | pokemini_ram[ ram_addr ] |= ( 1 << ( ( spr_y + j ) & 0x07 ) ); |
| 1512 | state->ram[ ram_addr ] |= ( 1 << ( ( spr_y + j ) & 0x07 ) ); |
| 1536 | 1513 | } |
| 1537 | 1514 | } |
| 1538 | 1515 | mask >>= 1; |
| r9669 | r9670 | |
| 1547 | 1524 | } |
| 1548 | 1525 | |
| 1549 | 1526 | /* Set PRC Render interrupt */ |
| 1550 | | pm_reg[0x27] |= 0x40; |
| 1527 | state->pm_reg[0x27] |= 0x40; |
| 1551 | 1528 | pokemini_check_irqs( machine ); |
| 1552 | 1529 | |
| 1553 | 1530 | /* Check if the rendered data should be copied to the LCD */ |
| 1554 | | if ( prc.copy_enabled ) |
| 1531 | if ( state->prc.copy_enabled ) |
| 1555 | 1532 | { |
| 1556 | 1533 | int x, y; |
| 1557 | 1534 | |
| 1558 | 1535 | for( y = 0; y < 64; y += 8 ) { |
| 1559 | 1536 | for( x = 0; x < 96; x++ ) { |
| 1560 | | UINT8 data = pokemini_ram[ ( y * 12 ) + x ]; |
| 1537 | UINT8 data = state->ram[ ( y * 12 ) + x ]; |
| 1561 | 1538 | |
| 1562 | 1539 | *BITMAP_ADDR16(machine->generic.tmpbitmap, y + 0, x) = ( data & 0x01 ) ? 3 : 0; |
| 1563 | 1540 | *BITMAP_ADDR16(machine->generic.tmpbitmap, y + 1, x) = ( data & 0x02 ) ? 3 : 0; |
| r9669 | r9670 | |
| 1571 | 1548 | } |
| 1572 | 1549 | |
| 1573 | 1550 | /* Set PRC Copy interrupt */ |
| 1574 | | pm_reg[0x27] |= 0x80; |
| 1551 | state->pm_reg[0x27] |= 0x80; |
| 1575 | 1552 | pokemini_check_irqs( machine ); |
| 1576 | 1553 | } |
| 1577 | 1554 | } |
| 1578 | 1555 | |
| 1579 | 1556 | /* Set possible input irqs */ |
| 1580 | | pm_reg[0x29] |= ~ input_port_read( machine, "INPUTS" ); |
| 1557 | state->pm_reg[0x29] |= ~ input_port_read( machine, "INPUTS" ); |
| 1581 | 1558 | } |
| 1582 | 1559 | } |
| 1583 | 1560 | |
| 1584 | 1561 | |
| 1585 | 1562 | MACHINE_START( pokemini ) |
| 1586 | 1563 | { |
| 1564 | pokemini_state *state = machine->driver_data<pokemini_state>(); |
| 1587 | 1565 | /* Clear internal structures */ |
| 1588 | | memset( &prc, 0, sizeof(prc) ); |
| 1589 | | memset( &timers, 0, sizeof(timers) ); |
| 1590 | | memset( pm_reg, 0, sizeof(pm_reg) ); |
| 1566 | memset( &state->prc, 0, sizeof(state->prc) ); |
| 1567 | memset( &state->timers, 0, sizeof(state->timers) ); |
| 1568 | memset( state->pm_reg, 0, sizeof(state->pm_reg) ); |
| 1591 | 1569 | |
| 1592 | 1570 | /* Set up timers */ |
| 1593 | | timers.seconds_timer = timer_alloc(machine, pokemini_seconds_timer_callback , NULL ); |
| 1594 | | timer_adjust_periodic( timers.seconds_timer, attotime_zero, 0, ATTOTIME_IN_SEC( 1 ) ); |
| 1571 | state->timers.seconds_timer = timer_alloc(machine, pokemini_seconds_timer_callback , NULL ); |
| 1572 | timer_adjust_periodic( state->timers.seconds_timer, attotime_zero, 0, ATTOTIME_IN_SEC( 1 ) ); |
| 1595 | 1573 | |
| 1596 | | timers.hz256_timer = timer_alloc(machine, pokemini_256hz_timer_callback , NULL ); |
| 1597 | | timer_adjust_periodic( timers.hz256_timer, attotime_zero, 0, ATTOTIME_IN_HZ( 256 ) ); |
| 1574 | state->timers.hz256_timer = timer_alloc(machine, pokemini_256hz_timer_callback , NULL ); |
| 1575 | timer_adjust_periodic( state->timers.hz256_timer, attotime_zero, 0, ATTOTIME_IN_HZ( 256 ) ); |
| 1598 | 1576 | |
| 1599 | | timers.timer1 = timer_alloc(machine, pokemini_timer1_callback , NULL ); |
| 1600 | | timers.timer1_hi = timer_alloc(machine, pokemini_timer1_hi_callback, NULL ); |
| 1601 | | timers.timer2 = timer_alloc(machine, pokemini_timer2_callback , NULL ); |
| 1602 | | timers.timer2_hi = timer_alloc(machine, pokemini_timer2_hi_callback, NULL ); |
| 1603 | | timers.timer3 = timer_alloc(machine, pokemini_timer3_callback , NULL ); |
| 1604 | | timers.timer3_hi = timer_alloc(machine, pokemini_timer3_hi_callback, NULL ); |
| 1577 | state->timers.timer1 = timer_alloc(machine, pokemini_timer1_callback , NULL ); |
| 1578 | state->timers.timer1_hi = timer_alloc(machine, pokemini_timer1_hi_callback, NULL ); |
| 1579 | state->timers.timer2 = timer_alloc(machine, pokemini_timer2_callback , NULL ); |
| 1580 | state->timers.timer2_hi = timer_alloc(machine, pokemini_timer2_hi_callback, NULL ); |
| 1581 | state->timers.timer3 = timer_alloc(machine, pokemini_timer3_callback , NULL ); |
| 1582 | state->timers.timer3_hi = timer_alloc(machine, pokemini_timer3_hi_callback, NULL ); |
| 1605 | 1583 | |
| 1606 | 1584 | /* Set up the PRC */ |
| 1607 | | prc.max_frame_count = 2; |
| 1608 | | prc.count_timer = timer_alloc(machine, pokemini_prc_counter_callback, NULL ); |
| 1609 | | timer_adjust_periodic( prc.count_timer, attotime_zero, 0, machine->device<cpu_device>("maincpu")->cycles_to_attotime(55640 / 65) ); |
| 1585 | state->prc.max_frame_count = 2; |
| 1586 | state->prc.count_timer = timer_alloc(machine, pokemini_prc_counter_callback, NULL ); |
| 1587 | timer_adjust_periodic( state->prc.count_timer, attotime_zero, 0, machine->device<cpu_device>("maincpu")->cycles_to_attotime(55640 / 65) ); |
| 1610 | 1588 | } |
| 1611 | 1589 | |
src/mess/machine/pet.c
| r9669 | r9670 | |
| 29 | 29 | } \ |
| 30 | 30 | } while (0) |
| 31 | 31 | |
| 32 | | int pet_font; |
| 33 | | UINT8 *pet_memory; |
| 34 | | UINT8 *superpet_memory; |
| 35 | | static UINT8 *pet80_bank1_base; |
| 36 | | static int pet_keyline_select; |
| 37 | 32 | |
| 38 | | static emu_timer *datasette1_timer; |
| 39 | | static emu_timer *datasette2_timer; |
| 40 | 33 | |
| 41 | 34 | /* pia at 0xe810 |
| 42 | 35 | port a |
| r9669 | r9670 | |
| 54 | 47 | */ |
| 55 | 48 | static READ8_DEVICE_HANDLER( pia0_pa_r ) |
| 56 | 49 | { |
| 50 | pet_state *state = device->machine->driver_data<pet_state>(); |
| 57 | 51 | /* |
| 58 | 52 | |
| 59 | 53 | bit description |
| r9669 | r9670 | |
| 73 | 67 | UINT8 data = 0; |
| 74 | 68 | |
| 75 | 69 | /* key */ |
| 76 | | data |= pet_keyline_select; |
| 70 | data |= state->keyline_select; |
| 77 | 71 | |
| 78 | 72 | /* #1 cassette switch */ |
| 79 | 73 | data |= ((cassette_get_state(device->machine->device("cassette1")) & CASSETTE_MASK_UISTATE) == CASSETTE_STOPPED) << 4; |
| r9669 | r9670 | |
| 92 | 86 | |
| 93 | 87 | static WRITE8_DEVICE_HANDLER( pia0_pa_w ) |
| 94 | 88 | { |
| 89 | pet_state *state = device->machine->driver_data<pet_state>(); |
| 95 | 90 | /* |
| 96 | 91 | |
| 97 | 92 | bit description |
| r9669 | r9670 | |
| 108 | 103 | */ |
| 109 | 104 | |
| 110 | 105 | /* key */ |
| 111 | | pet_keyline_select = data & 0x0f; |
| 106 | state->keyline_select = data & 0x0f; |
| 112 | 107 | } |
| 113 | 108 | |
| 114 | 109 | /* Keyboard reading/handling for regular keyboard */ |
| 115 | 110 | static READ8_DEVICE_HANDLER( kin_r ) |
| 116 | 111 | { |
| 112 | pet_state *state = device->machine->driver_data<pet_state>(); |
| 117 | 113 | /* |
| 118 | 114 | |
| 119 | 115 | bit description |
| r9669 | r9670 | |
| 135 | 131 | "ROW5", "ROW6", "ROW7", "ROW8", "ROW9" |
| 136 | 132 | }; |
| 137 | 133 | |
| 138 | | if (pet_keyline_select < 10) |
| 134 | if (state->keyline_select < 10) |
| 139 | 135 | { |
| 140 | | data = input_port_read(device->machine, keynames[pet_keyline_select]); |
| 136 | data = input_port_read(device->machine, keynames[state->keyline_select]); |
| 141 | 137 | /* Check for left-shift lock */ |
| 142 | | if ((pet_keyline_select == 8) && (input_port_read(device->machine, "SPECIAL") & 0x80)) |
| 138 | if ((state->keyline_select == 8) && (input_port_read(device->machine, "SPECIAL") & 0x80)) |
| 143 | 139 | data &= 0xfe; |
| 144 | 140 | } |
| 145 | 141 | return data; |
| r9669 | r9670 | |
| 155 | 151 | "ROW5", "ROW6", "ROW7", "ROW8", "ROW9" |
| 156 | 152 | }; |
| 157 | 153 | |
| 158 | | if (pet_keyline_select < 10) |
| 154 | if (state->keyline_select < 10) |
| 159 | 155 | { |
| 160 | | data = input_port_read(device->machine, keynames[pet_keyline_select]); |
| 156 | data = input_port_read(device->machine, keynames[state->keyline_select]); |
| 161 | 157 | /* Check for left-shift lock */ |
| 162 | 158 | /* 2008-05 FP: For some reason, superpet read it in the opposite way!! */ |
| 163 | 159 | /* While waiting for confirmation from docs, we add a workaround here. */ |
| 164 | 160 | if (state->superpet) |
| 165 | 161 | { |
| 166 | | if ((pet_keyline_select == 6) && !(input_port_read(device->machine, "SPECIAL") & 0x80)) |
| 162 | if ((state->keyline_select == 6) && !(input_port_read(device->machine, "SPECIAL") & 0x80)) |
| 167 | 163 | data &= 0xfe; |
| 168 | 164 | } |
| 169 | 165 | else |
| 170 | 166 | { |
| 171 | | if ((pet_keyline_select == 6) && (input_port_read(device->machine, "SPECIAL") & 0x80)) |
| 167 | if ((state->keyline_select == 6) && (input_port_read(device->machine, "SPECIAL") & 0x80)) |
| 172 | 168 | data &= 0xfe; |
| 173 | 169 | } |
| 174 | 170 | } |
| r9669 | r9670 | |
| 190 | 186 | |
| 191 | 187 | static WRITE8_DEVICE_HANDLER( cass1_motor_w ) |
| 192 | 188 | { |
| 189 | pet_state *state = device->machine->driver_data<pet_state>(); |
| 193 | 190 | if (!data) |
| 194 | 191 | { |
| 195 | 192 | cassette_change_state(device->machine->device("cassette1"),CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR); |
| 196 | | timer_adjust_periodic(datasette1_timer, attotime_zero, 0, ATTOTIME_IN_HZ(48000)); // I put 48000 because I was given some .wav with this freq |
| 193 | timer_adjust_periodic(state->datasette1_timer, attotime_zero, 0, ATTOTIME_IN_HZ(48000)); // I put 48000 because I was given some .wav with this freq |
| 197 | 194 | } |
| 198 | 195 | else |
| 199 | 196 | { |
| 200 | 197 | cassette_change_state(device->machine->device("cassette1"),CASSETTE_MOTOR_DISABLED ,CASSETTE_MASK_MOTOR); |
| 201 | | timer_reset(datasette1_timer, attotime_never); |
| 198 | timer_reset(state->datasette1_timer, attotime_never); |
| 202 | 199 | } |
| 203 | 200 | } |
| 204 | 201 | |
| r9669 | r9670 | |
| 374 | 371 | |
| 375 | 372 | static WRITE8_DEVICE_HANDLER( via_pb_w ) |
| 376 | 373 | { |
| 374 | pet_state *state = device->machine->driver_data<pet_state>(); |
| 377 | 375 | /* |
| 378 | 376 | |
| 379 | 377 | bit description |
| r9669 | r9670 | |
| 405 | 403 | if (BIT(data, 4)) |
| 406 | 404 | { |
| 407 | 405 | cassette_change_state(device->machine->device("cassette2"), CASSETTE_MOTOR_ENABLED, CASSETTE_MASK_MOTOR); |
| 408 | | timer_adjust_periodic(datasette2_timer, attotime_zero, 0, ATTOTIME_IN_HZ(48000)); // I put 48000 because I was given some .wav with this freq |
| 406 | timer_adjust_periodic(state->datasette2_timer, attotime_zero, 0, ATTOTIME_IN_HZ(48000)); // I put 48000 because I was given some .wav with this freq |
| 409 | 407 | } |
| 410 | 408 | else |
| 411 | 409 | { |
| 412 | 410 | cassette_change_state(device->machine->device("cassette2"), CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR); |
| 413 | | timer_reset(datasette2_timer, attotime_never); |
| 411 | timer_reset(state->datasette2_timer, attotime_never); |
| 414 | 412 | } |
| 415 | 413 | } |
| 416 | 414 | |
| 417 | 415 | static WRITE_LINE_DEVICE_HANDLER( gb_w ) |
| 418 | 416 | { |
| 417 | pet_state *drvstate = device->machine->driver_data<pet_state>(); |
| 419 | 418 | DBG_LOG(device->machine, 1, "address line", ("%d\n", state)); |
| 420 | | if (state) pet_font |= 1; |
| 421 | | else pet_font &= ~1; |
| 419 | if (state) drvstate->font |= 1; |
| 420 | else drvstate->font &= ~1; |
| 422 | 421 | } |
| 423 | 422 | |
| 424 | 423 | static WRITE_LINE_DEVICE_HANDLER( via_irq_w ) |
| r9669 | r9670 | |
| 448 | 447 | DEVCB_LINE(via_irq_w) /* out_irq_func */ |
| 449 | 448 | }; |
| 450 | 449 | |
| 451 | | static struct { |
| 452 | | int bank; /* rambank to be switched in 0x9000 */ |
| 453 | | int rom; /* rom socket 6502? at 0x9000 */ |
| 454 | | } spet= { 0 }; |
| 455 | 450 | |
| 456 | 451 | static WRITE8_HANDLER( cbm8096_io_w ) |
| 457 | 452 | { |
| r9669 | r9670 | |
| 492 | 487 | |
| 493 | 488 | static WRITE8_HANDLER( pet80_bank1_w ) |
| 494 | 489 | { |
| 495 | | pet80_bank1_base[offset] = data; |
| 490 | pet_state *state = space->machine->driver_data<pet_state>(); |
| 491 | state->pet80_bank1_base[offset] = data; |
| 496 | 492 | } |
| 497 | 493 | |
| 498 | 494 | /* |
| r9669 | r9670 | |
| 508 | 504 | */ |
| 509 | 505 | WRITE8_HANDLER( cbm8096_w ) |
| 510 | 506 | { |
| 507 | pet_state *state = space->machine->driver_data<pet_state>(); |
| 511 | 508 | if (data & 0x80) |
| 512 | 509 | { |
| 513 | 510 | if (data & 0x40) |
| r9669 | r9670 | |
| 537 | 534 | |
| 538 | 535 | if (data & 0x20) |
| 539 | 536 | { |
| 540 | | pet80_bank1_base = pet_memory + 0x8000; |
| 541 | | memory_set_bankptr(space->machine, "bank1", pet80_bank1_base); |
| 537 | state->pet80_bank1_base = state->memory + 0x8000; |
| 538 | memory_set_bankptr(space->machine, "bank1", state->pet80_bank1_base); |
| 542 | 539 | memory_install_write8_handler(space, 0x8000, 0x8fff, 0, 0, pet80_bank1_w); |
| 543 | 540 | } |
| 544 | 541 | else |
| r9669 | r9670 | |
| 563 | 560 | { |
| 564 | 561 | if (!(data & 0x20)) |
| 565 | 562 | { |
| 566 | | pet80_bank1_base = pet_memory + 0x14000; |
| 567 | | memory_set_bankptr(space->machine, "bank1", pet80_bank1_base); |
| 563 | state->pet80_bank1_base = state->memory + 0x14000; |
| 564 | memory_set_bankptr(space->machine, "bank1", state->pet80_bank1_base); |
| 568 | 565 | } |
| 569 | | memory_set_bankptr(space->machine, "bank2", pet_memory + 0x15000); |
| 570 | | memory_set_bankptr(space->machine, "bank3", pet_memory + 0x16000); |
| 571 | | memory_set_bankptr(space->machine, "bank4", pet_memory + 0x17000); |
| 566 | memory_set_bankptr(space->machine, "bank2", state->memory + 0x15000); |
| 567 | memory_set_bankptr(space->machine, "bank3", state->memory + 0x16000); |
| 568 | memory_set_bankptr(space->machine, "bank4", state->memory + 0x17000); |
| 572 | 569 | } |
| 573 | 570 | else |
| 574 | 571 | { |
| 575 | 572 | if (!(data & 0x20)) |
| 576 | 573 | { |
| 577 | | pet80_bank1_base = pet_memory + 0x10000; |
| 578 | | memory_set_bankptr(space->machine, "bank1", pet80_bank1_base); |
| 574 | state->pet80_bank1_base = state->memory + 0x10000; |
| 575 | memory_set_bankptr(space->machine, "bank1", state->pet80_bank1_base); |
| 579 | 576 | } |
| 580 | | memory_set_bankptr(space->machine, "bank2", pet_memory + 0x11000); |
| 581 | | memory_set_bankptr(space->machine, "bank3", pet_memory + 0x12000); |
| 582 | | memory_set_bankptr(space->machine, "bank4", pet_memory + 0x13000); |
| 577 | memory_set_bankptr(space->machine, "bank2", state->memory + 0x11000); |
| 578 | memory_set_bankptr(space->machine, "bank3", state->memory + 0x12000); |
| 579 | memory_set_bankptr(space->machine, "bank4", state->memory + 0x13000); |
| 583 | 580 | } |
| 584 | 581 | |
| 585 | 582 | if (data & 8) |
| 586 | 583 | { |
| 587 | 584 | if (!(data & 0x40)) |
| 588 | 585 | { |
| 589 | | memory_set_bankptr(space->machine, "bank7", pet_memory + 0x1e800); |
| 586 | memory_set_bankptr(space->machine, "bank7", state->memory + 0x1e800); |
| 590 | 587 | } |
| 591 | | memory_set_bankptr(space->machine, "bank6", pet_memory + 0x1c000); |
| 592 | | memory_set_bankptr(space->machine, "bank8", pet_memory + 0x1f000); |
| 593 | | memory_set_bankptr(space->machine, "bank9", pet_memory + 0x1fff1); |
| 588 | memory_set_bankptr(space->machine, "bank6", state->memory + 0x1c000); |
| 589 | memory_set_bankptr(space->machine, "bank8", state->memory + 0x1f000); |
| 590 | memory_set_bankptr(space->machine, "bank9", state->memory + 0x1fff1); |
| 594 | 591 | } |
| 595 | 592 | else |
| 596 | 593 | { |
| 597 | 594 | if (!(data & 0x40)) |
| 598 | 595 | { |
| 599 | | memory_set_bankptr(space->machine, "bank7", pet_memory+ 0x1a800); |
| 596 | memory_set_bankptr(space->machine, "bank7", state->memory+ 0x1a800); |
| 600 | 597 | } |
| 601 | | memory_set_bankptr(space->machine, "bank6", pet_memory + 0x18000); |
| 602 | | memory_set_bankptr(space->machine, "bank8", pet_memory + 0x1b000); |
| 603 | | memory_set_bankptr(space->machine, "bank9", pet_memory + 0x1bff1); |
| 598 | memory_set_bankptr(space->machine, "bank6", state->memory + 0x18000); |
| 599 | memory_set_bankptr(space->machine, "bank8", state->memory + 0x1b000); |
| 600 | memory_set_bankptr(space->machine, "bank9", state->memory + 0x1bff1); |
| 604 | 601 | } |
| 605 | 602 | } |
| 606 | 603 | else |
| 607 | 604 | { |
| 608 | | pet80_bank1_base = pet_memory + 0x8000; |
| 609 | | memory_set_bankptr(space->machine, "bank1", pet80_bank1_base ); |
| 605 | state->pet80_bank1_base = state->memory + 0x8000; |
| 606 | memory_set_bankptr(space->machine, "bank1", state->pet80_bank1_base ); |
| 610 | 607 | memory_install_write8_handler(space, 0x8000, 0x8fff, 0, 0, pet80_bank1_w); |
| 611 | 608 | |
| 612 | | memory_set_bankptr(space->machine, "bank2", pet_memory + 0x9000); |
| 609 | memory_set_bankptr(space->machine, "bank2", state->memory + 0x9000); |
| 613 | 610 | memory_unmap_write(space, 0x9000, 0x9fff, 0, 0); |
| 614 | 611 | |
| 615 | | memory_set_bankptr(space->machine, "bank3", pet_memory + 0xa000); |
| 612 | memory_set_bankptr(space->machine, "bank3", state->memory + 0xa000); |
| 616 | 613 | memory_unmap_write(space, 0xa000, 0xafff, 0, 0); |
| 617 | 614 | |
| 618 | | memory_set_bankptr(space->machine, "bank4", pet_memory + 0xb000); |
| 615 | memory_set_bankptr(space->machine, "bank4", state->memory + 0xb000); |
| 619 | 616 | memory_unmap_write(space, 0xb000, 0xbfff, 0, 0); |
| 620 | 617 | |
| 621 | | memory_set_bankptr(space->machine, "bank6", pet_memory + 0xc000); |
| 618 | memory_set_bankptr(space->machine, "bank6", state->memory + 0xc000); |
| 622 | 619 | memory_unmap_write(space, 0xc000, 0xe7ff, 0, 0); |
| 623 | 620 | |
| 624 | 621 | memory_install_read8_handler(space, 0xe800, 0xefff, 0, 0, cbm8096_io_r); |
| 625 | 622 | memory_install_write8_handler(space, 0xe800, 0xefff, 0, 0, cbm8096_io_w); |
| 626 | 623 | |
| 627 | | memory_set_bankptr(space->machine, "bank8", pet_memory + 0xf000); |
| 624 | memory_set_bankptr(space->machine, "bank8", state->memory + 0xf000); |
| 628 | 625 | memory_unmap_write(space, 0xf000, 0xffef, 0, 0); |
| 629 | 626 | |
| 630 | | memory_set_bankptr(space->machine, "bank9", pet_memory + 0xfff1); |
| 627 | memory_set_bankptr(space->machine, "bank9", state->memory + 0xfff1); |
| 631 | 628 | memory_unmap_write(space, 0xfff1, 0xffff, 0, 0); |
| 632 | 629 | } |
| 633 | 630 | } |
| r9669 | r9670 | |
| 639 | 636 | |
| 640 | 637 | WRITE8_HANDLER( superpet_w ) |
| 641 | 638 | { |
| 639 | pet_state *state = space->machine->driver_data<pet_state>(); |
| 642 | 640 | switch (offset) |
| 643 | 641 | { |
| 644 | 642 | case 0: |
| r9669 | r9670 | |
| 652 | 650 | |
| 653 | 651 | case 4: |
| 654 | 652 | case 5: |
| 655 | | spet.bank = data & 0xf; |
| 656 | | memory_configure_bank(space->machine, "bank1", 0, 16, superpet_memory, 0x1000); |
| 657 | | memory_set_bank(space->machine, "bank1", spet.bank); |
| 653 | state->spet.bank = data & 0xf; |
| 654 | memory_configure_bank(space->machine, "bank1", 0, 16, state->supermemory, 0x1000); |
| 655 | memory_set_bank(space->machine, "bank1", state->spet.bank); |
| 658 | 656 | /* 7 low writeprotects systemlatch */ |
| 659 | 657 | break; |
| 660 | 658 | |
| 661 | 659 | case 6: |
| 662 | 660 | case 7: |
| 663 | | spet.rom = data & 1; |
| 661 | state->spet.rom = data & 1; |
| 664 | 662 | break; |
| 665 | 663 | } |
| 666 | 664 | } |
| 667 | 665 | |
| 668 | 666 | static TIMER_CALLBACK( pet_interrupt ) |
| 669 | 667 | { |
| 668 | pet_state *state = machine->driver_data<pet_state>(); |
| 670 | 669 | running_device *pia_0 = machine->device("pia_0"); |
| 671 | | static int level = 0; |
| 672 | 670 | |
| 673 | | pia6821_cb1_w(pia_0, level); |
| 674 | | level = !level; |
| 671 | pia6821_cb1_w(pia_0, state->pia_level); |
| 672 | state->pia_level = !state->pia_level; |
| 675 | 673 | } |
| 676 | 674 | |
| 677 | 675 | |
| r9669 | r9670 | |
| 697 | 695 | int i; |
| 698 | 696 | pet_state *state = machine->driver_data<pet_state>(); |
| 699 | 697 | |
| 700 | | pet_font = 0; |
| 698 | state->font = 0; |
| 701 | 699 | |
| 702 | 700 | state->pet_basic1 = 0; |
| 703 | 701 | state->superpet = 0; |
| 704 | 702 | state->cbm8096 = 0; |
| 705 | 703 | |
| 706 | 704 | memory_install_readwrite_bank(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0000, messram_get_size(machine->device("messram")) - 1, 0, 0, "bank10"); |
| 707 | | memory_set_bankptr(machine, "bank10", pet_memory); |
| 705 | memory_set_bankptr(machine, "bank10", state->memory); |
| 708 | 706 | |
| 709 | 707 | if (messram_get_size(machine->device("messram")) < 0x8000) |
| 710 | 708 | { |
| r9669 | r9670 | |
| 714 | 712 | /* 2114 poweron ? 64 x 0xff, 64x 0, and so on */ |
| 715 | 713 | for (i = 0; i < messram_get_size(machine->device("messram")); i += 0x40) |
| 716 | 714 | { |
| 717 | | memset (pet_memory + i, i & 0x40 ? 0 : 0xff, 0x40); |
| 715 | memset (state->memory + i, i & 0x40 ? 0 : 0xff, 0x40); |
| 718 | 716 | } |
| 719 | 717 | |
| 720 | 718 | /* pet clock */ |
| 721 | 719 | timer_pulse(machine, ATTOTIME_IN_MSEC(10), NULL, 0, pet_interrupt); |
| 722 | 720 | |
| 723 | 721 | /* datasette */ |
| 724 | | datasette1_timer = timer_alloc(machine, pet_tape1_timer, NULL); |
| 725 | | datasette2_timer = timer_alloc(machine, pet_tape2_timer, NULL); |
| 722 | state->datasette1_timer = timer_alloc(machine, pet_tape1_timer, NULL); |
| 723 | state->datasette2_timer = timer_alloc(machine, pet_tape2_timer, NULL); |
| 726 | 724 | } |
| 727 | 725 | |
| 728 | 726 | |
| 729 | 727 | DRIVER_INIT( pet2001 ) |
| 730 | 728 | { |
| 731 | 729 | pet_state *state = machine->driver_data<pet_state>(); |
| 732 | | pet_memory = messram_get_ptr(machine->device("messram")); |
| 730 | state->memory = messram_get_ptr(machine->device("messram")); |
| 733 | 731 | pet_common_driver_init(machine); |
| 734 | 732 | state->pet_basic1 = 1; |
| 735 | 733 | pet_vh_init(machine); |
| r9669 | r9670 | |
| 737 | 735 | |
| 738 | 736 | DRIVER_INIT( pet ) |
| 739 | 737 | { |
| 740 | | pet_memory = messram_get_ptr(machine->device("messram")); |
| 738 | pet_state *state = machine->driver_data<pet_state>(); |
| 739 | state->memory = messram_get_ptr(machine->device("messram")); |
| 741 | 740 | pet_common_driver_init(machine); |
| 742 | 741 | pet_vh_init(machine); |
| 743 | 742 | } |
| r9669 | r9670 | |
| 745 | 744 | DRIVER_INIT( pet80 ) |
| 746 | 745 | { |
| 747 | 746 | pet_state *state = machine->driver_data<pet_state>(); |
| 748 | | pet_memory = memory_region(machine, "maincpu"); |
| 747 | state->memory = memory_region(machine, "maincpu"); |
| 749 | 748 | |
| 750 | 749 | pet_common_driver_init(machine); |
| 751 | 750 | state->cbm8096 = 1; |
| 752 | | state->videoram = &pet_memory[0x8000]; |
| 751 | state->videoram = &state->memory[0x8000]; |
| 753 | 752 | pet80_vh_init(machine); |
| 754 | 753 | |
| 755 | 754 | } |
| r9669 | r9670 | |
| 757 | 756 | DRIVER_INIT( superpet ) |
| 758 | 757 | { |
| 759 | 758 | pet_state *state = machine->driver_data<pet_state>(); |
| 760 | | pet_memory = messram_get_ptr(machine->device("messram")); |
| 759 | state->memory = messram_get_ptr(machine->device("messram")); |
| 761 | 760 | pet_common_driver_init(machine); |
| 762 | 761 | state->superpet = 1; |
| 763 | 762 | |
| 764 | | superpet_memory = auto_alloc_array(machine, UINT8, 0x10000); |
| 763 | state->supermemory = auto_alloc_array(machine, UINT8, 0x10000); |
| 765 | 764 | |
| 766 | | memory_configure_bank(machine, "bank1", 0, 16, superpet_memory, 0x1000); |
| 765 | memory_configure_bank(machine, "bank1", 0, 16, state->supermemory, 0x1000); |
| 767 | 766 | memory_set_bank(machine, "bank1", 0); |
| 768 | 767 | |
| 769 | 768 | superpet_vh_init(machine); |
| r9669 | r9670 | |
| 777 | 776 | |
| 778 | 777 | if (state->superpet) |
| 779 | 778 | { |
| 780 | | spet.rom = 0; |
| 779 | state->spet.rom = 0; |
| 781 | 780 | if (input_port_read(machine, "CFG") & 0x04) |
| 782 | 781 | { |
| 783 | 782 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, 1); |
| 784 | 783 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, 0); |
| 785 | | pet_font = 2; |
| 784 | state->font = 2; |
| 786 | 785 | } |
| 787 | 786 | else |
| 788 | 787 | { |
| 789 | 788 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, 0); |
| 790 | 789 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, 1); |
| 791 | | pet_font = 0; |
| 790 | state->font = 0; |
| 792 | 791 | } |
| 793 | 792 | } |
| 794 | 793 | |
| r9669 | r9670 | |
| 824 | 823 | { |
| 825 | 824 | cpu_set_input_line(device, INPUT_LINE_HALT, 1); |
| 826 | 825 | cpu_set_input_line(device, INPUT_LINE_HALT, 0); |
| 827 | | pet_font |= 2; |
| 826 | state->font |= 2; |
| 828 | 827 | } |
| 829 | 828 | else |
| 830 | 829 | { |
| 831 | 830 | cpu_set_input_line(device, INPUT_LINE_HALT, 0); |
| 832 | 831 | cpu_set_input_line(device, INPUT_LINE_HALT, 1); |
| 833 | | pet_font &= ~2; |
| 832 | state->font &= ~2; |
| 834 | 833 | } |
| 835 | 834 | } |
| 836 | 835 | |
| r9669 | r9670 | |
| 846 | 845 | |
| 847 | 846 | static DEVICE_IMAGE_LOAD(pet_cart) |
| 848 | 847 | { |
| 848 | pet_state *state = image.device().machine->driver_data<pet_state>(); |
| 849 | 849 | UINT32 size = image.length(); |
| 850 | 850 | const char *filetype = image.filetype(); |
| 851 | 851 | int address = 0; |
| r9669 | r9670 | |
| 860 | 860 | |
| 861 | 861 | logerror("Loading cart %s at %.4x size:%.4x\n", image.filename(), address, size); |
| 862 | 862 | |
| 863 | | image.fread(pet_memory + address, size); |
| 863 | image.fread(state->memory + address, size); |
| 864 | 864 | |
| 865 | 865 | return IMAGE_INIT_PASS; |
| 866 | 866 | } |
src/mess/machine/oric.c
| r9669 | r9670 | |
| 30 | 30 | #include "devices/flopdrv.h" |
| 31 | 31 | |
| 32 | 32 | |
| 33 | | UINT8 *oric_ram; |
| 34 | 33 | |
| 35 | 34 | static const int enable_logging = 1; |
| 36 | | /* static int save_done = 0; */ |
| 37 | 35 | |
| 38 | 36 | |
| 39 | 37 | /* ==0 if oric1 or oric atmos, !=0 if telestrat */ |
| 40 | | static int oric_is_telestrat = 0; |
| 41 | 38 | |
| 42 | 39 | /* This does not exist in the real hardware. I have used it to |
| 43 | 40 | know which sources are interrupting */ |
| 44 | 41 | /* bit 2 = telestrat 2nd via interrupt, 1 = microdisc interface, |
| 45 | 42 | 0 = oric 1st via interrupt */ |
| 46 | | static unsigned char oric_irqs; |
| 47 | 43 | |
| 48 | 44 | enum |
| 49 | 45 | { |
| r9669 | r9670 | |
| 66 | 62 | /* called when ints are changed - cleared/set */ |
| 67 | 63 | static void oric_refresh_ints(running_machine *machine) |
| 68 | 64 | { |
| 65 | oric_state *state = machine->driver_data<oric_state>(); |
| 69 | 66 | /* telestrat has floppy hardware built-in! */ |
| 70 | | if (oric_is_telestrat==0) |
| 67 | if (state->is_telestrat==0) |
| 71 | 68 | { |
| 72 | 69 | /* oric 1 or oric atmos */ |
| 73 | 70 | |
| 74 | 71 | /* if floppy disc hardware is disabled, do not allow interrupts from it */ |
| 75 | 72 | if ((input_port_read(machine, "FLOPPY") & 0x07) == ORIC_FLOPPY_INTERFACE_NONE) |
| 76 | 73 | { |
| 77 | | oric_irqs &=~(1<<1); |
| 74 | state->irqs &=~(1<<1); |
| 78 | 75 | } |
| 79 | 76 | } |
| 80 | 77 | |
| 81 | 78 | /* any irq set? */ |
| 82 | | if ((oric_irqs & 0x0f)!=0) |
| 79 | if ((state->irqs & 0x0f)!=0) |
| 83 | 80 | { |
| 84 | 81 | cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE); |
| 85 | 82 | } |
| r9669 | r9670 | |
| 89 | 86 | } |
| 90 | 87 | } |
| 91 | 88 | |
| 92 | | static char *oric_ram_0x0c000 = NULL; |
| 93 | 89 | |
| 94 | 90 | |
| 95 | 91 | /* index of keyboard line to scan */ |
| 96 | | static int oric_keyboard_line; |
| 97 | 92 | /* sense result */ |
| 98 | | static char oric_key_sense_bit; |
| 99 | 93 | /* mask to read keys */ |
| 100 | | static char oric_keyboard_mask; |
| 101 | 94 | |
| 102 | 95 | |
| 103 | | static unsigned char oric_via_port_a_data; |
| 104 | 96 | |
| 105 | 97 | |
| 106 | 98 | |
| 107 | 99 | /* refresh keyboard sense */ |
| 108 | 100 | static void oric_keyboard_sense_refresh(running_machine *machine) |
| 109 | 101 | { |
| 102 | oric_state *state = machine->driver_data<oric_state>(); |
| 110 | 103 | /* The following assumes that if a 0 is written, it can be used to detect if any key |
| 111 | 104 | has been pressed.. */ |
| 112 | 105 | /* for each bit that is 0, it combines it's pressed state with the pressed state so far */ |
| r9669 | r9670 | |
| 118 | 111 | int input_port_data; |
| 119 | 112 | static const char *const keynames[] = { "ROW0", "ROW1", "ROW2", "ROW3", "ROW4", "ROW5", "ROW6", "ROW7" }; |
| 120 | 113 | |
| 121 | | input_port_data = input_port_read(machine, keynames[oric_keyboard_line]); |
| 114 | input_port_data = input_port_read(machine, keynames[state->keyboard_line]); |
| 122 | 115 | |
| 123 | 116 | /* go through all bits in line */ |
| 124 | 117 | for (i=0; i<8; i++) |
| 125 | 118 | { |
| 126 | 119 | /* sense this bit? */ |
| 127 | | if (((~oric_keyboard_mask) & (1<<i)) != 0) |
| 120 | if (((~state->keyboard_mask) & (1<<i)) != 0) |
| 128 | 121 | { |
| 129 | 122 | /* is key pressed? */ |
| 130 | 123 | if (input_port_data & (1<<i)) |
| r9669 | r9670 | |
| 136 | 129 | } |
| 137 | 130 | |
| 138 | 131 | /* clear sense result */ |
| 139 | | oric_key_sense_bit = 0; |
| 132 | state->key_sense_bit = 0; |
| 140 | 133 | /* any keys pressed on this line? */ |
| 141 | 134 | if (key_bit!=0) |
| 142 | 135 | { |
| 143 | 136 | /* set sense result */ |
| 144 | | oric_key_sense_bit = (1<<3); |
| 137 | state->key_sense_bit = (1<<3); |
| 145 | 138 | } |
| 146 | 139 | } |
| 147 | 140 | |
| r9669 | r9670 | |
| 149 | 142 | /* this is executed when a write to psg port a is done */ |
| 150 | 143 | WRITE8_HANDLER (oric_psg_porta_write) |
| 151 | 144 | { |
| 152 | | oric_keyboard_mask = data; |
| 145 | oric_state *state = space->machine->driver_data<oric_state>(); |
| 146 | state->keyboard_mask = data; |
| 153 | 147 | } |
| 154 | 148 | |
| 155 | 149 | |
| 156 | 150 | /* PSG control pins */ |
| 157 | 151 | /* bit 1 = BDIR state */ |
| 158 | 152 | /* bit 0 = BC1 state */ |
| 159 | | static char oric_psg_control; |
| 160 | 153 | |
| 161 | 154 | /* this port is also used to read printer data */ |
| 162 | 155 | static READ8_DEVICE_HANDLER ( oric_via_in_a_func ) |
| 163 | 156 | { |
| 157 | oric_state *state = device->machine->driver_data<oric_state>(); |
| 164 | 158 | address_space *space = cputag_get_address_space( device->machine, "maincpu", ADDRESS_SPACE_PROGRAM ); |
| 165 | 159 | |
| 166 | 160 | /*logerror("port a read\r\n"); */ |
| 167 | 161 | |
| 168 | 162 | /* access psg? */ |
| 169 | | if (oric_psg_control!=0) |
| 163 | if (state->psg_control!=0) |
| 170 | 164 | { |
| 171 | 165 | /* if psg is in read register state return reg data */ |
| 172 | | if (oric_psg_control==0x01) |
| 166 | if (state->psg_control==0x01) |
| 173 | 167 | { |
| 174 | 168 | return ay8910_r(space->machine->device("ay8912"), 0); |
| 175 | 169 | } |
| r9669 | r9670 | |
| 179 | 173 | } |
| 180 | 174 | |
| 181 | 175 | /* correct?? */ |
| 182 | | return oric_via_port_a_data; |
| 176 | return state->via_port_a_data; |
| 183 | 177 | } |
| 184 | 178 | |
| 185 | 179 | static READ8_DEVICE_HANDLER ( oric_via_in_b_func ) |
| 186 | 180 | { |
| 181 | oric_state *state = device->machine->driver_data<oric_state>(); |
| 187 | 182 | int data; |
| 188 | 183 | |
| 189 | 184 | oric_keyboard_sense_refresh(device->machine); |
| 190 | 185 | |
| 191 | | data = oric_key_sense_bit; |
| 192 | | data |= oric_keyboard_line & 0x07; |
| 186 | data = state->key_sense_bit; |
| 187 | data |= state->keyboard_line & 0x07; |
| 193 | 188 | |
| 194 | 189 | return data; |
| 195 | 190 | } |
| r9669 | r9670 | |
| 198 | 193 | /* read/write data depending on state of bdir, bc1 pins and data output to psg */ |
| 199 | 194 | static void oric_psg_connection_refresh(running_machine *machine) |
| 200 | 195 | { |
| 201 | | if (oric_psg_control!=0) |
| 196 | oric_state *state = machine->driver_data<oric_state>(); |
| 197 | if (state->psg_control!=0) |
| 202 | 198 | { |
| 203 | | switch (oric_psg_control) |
| 199 | switch (state->psg_control) |
| 204 | 200 | { |
| 205 | 201 | /* PSG inactive */ |
| 206 | 202 | case 0: |
| r9669 | r9670 | |
| 208 | 204 | /* read register data */ |
| 209 | 205 | case 1: |
| 210 | 206 | { |
| 211 | | //oric_via_port_a_data = ay8910_read_port_0_r(space, 0); |
| 207 | //state->via_port_a_data = ay8910_read_port_0_r(space, 0); |
| 212 | 208 | } |
| 213 | 209 | break; |
| 214 | 210 | /* write register data */ |
| 215 | 211 | case 2: |
| 216 | 212 | { |
| 217 | 213 | running_device *ay8912 = machine->device("ay8912"); |
| 218 | | ay8910_data_w(ay8912, 0, oric_via_port_a_data); |
| 214 | ay8910_data_w(ay8912, 0, state->via_port_a_data); |
| 219 | 215 | } |
| 220 | 216 | break; |
| 221 | 217 | /* write register index */ |
| 222 | 218 | case 3: |
| 223 | 219 | { |
| 224 | 220 | running_device *ay8912 = machine->device("ay8912"); |
| 225 | | ay8910_address_w(ay8912, 0, oric_via_port_a_data); |
| 221 | ay8910_address_w(ay8912, 0, state->via_port_a_data); |
| 226 | 222 | } |
| 227 | 223 | break; |
| 228 | 224 | |
| r9669 | r9670 | |
| 236 | 232 | |
| 237 | 233 | static WRITE8_DEVICE_HANDLER ( oric_via_out_a_func ) |
| 238 | 234 | { |
| 239 | | oric_via_port_a_data = data; |
| 235 | oric_state *state = device->machine->driver_data<oric_state>(); |
| 236 | state->via_port_a_data = data; |
| 240 | 237 | |
| 241 | 238 | oric_psg_connection_refresh(device->machine); |
| 242 | 239 | |
| 243 | 240 | |
| 244 | | if (oric_psg_control==0) |
| 241 | if (state->psg_control==0) |
| 245 | 242 | { |
| 246 | 243 | /* if psg not selected, write to printer */ |
| 247 | 244 | running_device *printer = device->machine->device("centronics"); |
| r9669 | r9670 | |
| 305 | 302 | via_0->write_cb1(data); |
| 306 | 303 | } |
| 307 | 304 | |
| 308 | | static unsigned char previous_portb_data = 0; |
| 309 | 305 | static WRITE8_DEVICE_HANDLER ( oric_via_out_b_func ) |
| 310 | 306 | { |
| 307 | oric_state *state = device->machine->driver_data<oric_state>(); |
| 311 | 308 | running_device *printer = device->machine->device("centronics"); |
| 312 | 309 | |
| 313 | 310 | /* KEYBOARD */ |
| 314 | | oric_keyboard_line = data & 0x07; |
| 311 | state->keyboard_line = data & 0x07; |
| 315 | 312 | |
| 316 | 313 | /* CASSETTE */ |
| 317 | 314 | /* cassette motor control */ |
| 318 | | if ((previous_portb_data^data) & (1<<6)) |
| 315 | if ((state->previous_portb_data^data) & (1<<6)) |
| 319 | 316 | { |
| 320 | 317 | if (data & (1<<6)) |
| 321 | 318 | { |
| r9669 | r9670 | |
| 335 | 332 | centronics_strobe_w(printer, BIT(data, 4)); |
| 336 | 333 | |
| 337 | 334 | oric_psg_connection_refresh(device->machine); |
| 338 | | previous_portb_data = data; |
| 335 | state->previous_portb_data = data; |
| 339 | 336 | } |
| 340 | 337 | |
| 341 | 338 | |
| 342 | 339 | static READ8_DEVICE_HANDLER ( oric_via_in_ca2_func ) |
| 343 | 340 | { |
| 344 | | return oric_psg_control & 1; |
| 341 | oric_state *state = device->machine->driver_data<oric_state>(); |
| 342 | return state->psg_control & 1; |
| 345 | 343 | } |
| 346 | 344 | |
| 347 | 345 | static READ8_DEVICE_HANDLER ( oric_via_in_cb2_func ) |
| 348 | 346 | { |
| 349 | | return (oric_psg_control>>1) & 1; |
| 347 | oric_state *state = device->machine->driver_data<oric_state>(); |
| 348 | return (state->psg_control>>1) & 1; |
| 350 | 349 | } |
| 351 | 350 | |
| 352 | 351 | static WRITE8_DEVICE_HANDLER ( oric_via_out_ca2_func ) |
| 353 | 352 | { |
| 354 | | oric_psg_control &=~1; |
| 353 | oric_state *state = device->machine->driver_data<oric_state>(); |
| 354 | state->psg_control &=~1; |
| 355 | 355 | |
| 356 | 356 | if (data) |
| 357 | 357 | { |
| 358 | | oric_psg_control |=1; |
| 358 | state->psg_control |=1; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | oric_psg_connection_refresh(device->machine); |
| r9669 | r9670 | |
| 363 | 363 | |
| 364 | 364 | static WRITE8_DEVICE_HANDLER ( oric_via_out_cb2_func ) |
| 365 | 365 | { |
| 366 | | oric_psg_control &=~2; |
| 366 | oric_state *state = device->machine->driver_data<oric_state>(); |
| 367 | state->psg_control &=~2; |
| 367 | 368 | |
| 368 | 369 | if (data) |
| 369 | 370 | { |
| 370 | | oric_psg_control |=2; |
| 371 | state->psg_control |=2; |
| 371 | 372 | } |
| 372 | 373 | |
| 373 | 374 | oric_psg_connection_refresh(device->machine); |
| r9669 | r9670 | |
| 376 | 377 | |
| 377 | 378 | static void oric_via_irq_func(running_device *device, int state) |
| 378 | 379 | { |
| 379 | | oric_irqs &= ~(1<<0); |
| 380 | oric_state *drvstate = device->machine->driver_data<oric_state>(); |
| 381 | drvstate->irqs &= ~(1<<0); |
| 380 | 382 | |
| 381 | 383 | if (state) |
| 382 | 384 | { |
| r9669 | r9670 | |
| 385 | 387 | //logerror("oric via1 interrupt\r\n"); |
| 386 | 388 | } |
| 387 | 389 | |
| 388 | | oric_irqs |=(1<<0); |
| 390 | drvstate->irqs |=(1<<0); |
| 389 | 391 | } |
| 390 | 392 | |
| 391 | 393 | oric_refresh_ints(device->machine); |
| r9669 | r9670 | |
| 464 | 466 | |
| 465 | 467 | static void oric_install_apple2_interface(running_machine *machine) |
| 466 | 468 | { |
| 469 | oric_state *state = machine->driver_data<oric_state>(); |
| 467 | 470 | running_device *fdc = machine->device("fdc"); |
| 468 | 471 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 469 | 472 | |
| 470 | | if (oric_is_telestrat) |
| 473 | if (state->is_telestrat) |
| 471 | 474 | return; |
| 472 | 475 | |
| 473 | 476 | memory_install_read8_handler(space, 0x0300, 0x030f, 0, 0, oric_IO_r); |
| r9669 | r9670 | |
| 482 | 485 | |
| 483 | 486 | static void oric_enable_memory(running_machine *machine, int low, int high, int rd, int wr) |
| 484 | 487 | { |
| 488 | oric_state *state = machine->driver_data<oric_state>(); |
| 485 | 489 | int i; |
| 486 | 490 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 487 | 491 | |
| 488 | | if (oric_is_telestrat) |
| 492 | if (state->is_telestrat) |
| 489 | 493 | return; |
| 490 | 494 | for (i = low; i <= high; i++) |
| 491 | 495 | { |
| r9669 | r9670 | |
| 541 | 545 | |
| 542 | 546 | static WRITE8_HANDLER(apple2_v2_interface_w) |
| 543 | 547 | { |
| 548 | oric_state *state = space->machine->driver_data<oric_state>(); |
| 544 | 549 | /* data is ignored, address is used to decode operation */ |
| 545 | | if (oric_is_telestrat) |
| 550 | if (state->is_telestrat) |
| 546 | 551 | return; |
| 547 | 552 | |
| 548 | 553 | /* logerror("apple 2 interface v2 rom page: %01x\n",(offset & 0x02)>>1); */ |
| r9669 | r9670 | |
| 564 | 569 | memory_set_bankptr(space->machine, "bank1", rom_ptr); |
| 565 | 570 | memory_set_bankptr(space->machine, "bank2", rom_ptr+0x02000); |
| 566 | 571 | memory_set_bankptr(space->machine, "bank3", rom_ptr+0x03800); |
| 567 | | memory_set_bankptr(space->machine, "bank5", oric_ram_0x0c000); |
| 568 | | memory_set_bankptr(space->machine, "bank6", oric_ram_0x0c000+0x02000); |
| 569 | | memory_set_bankptr(space->machine, "bank7", oric_ram_0x0c000+0x03800); |
| 572 | memory_set_bankptr(space->machine, "bank5", state->ram_0x0c000); |
| 573 | memory_set_bankptr(space->machine, "bank6", state->ram_0x0c000+0x02000); |
| 574 | memory_set_bankptr(space->machine, "bank7", state->ram_0x0c000+0x03800); |
| 570 | 575 | } |
| 571 | 576 | else |
| 572 | 577 | { |
| 573 | 578 | /*logerror("apple 2 interface v2: ram enabled\n"); */ |
| 574 | 579 | |
| 575 | 580 | /* enable ram */ |
| 576 | | memory_set_bankptr(space->machine, "bank1", oric_ram_0x0c000); |
| 577 | | memory_set_bankptr(space->machine, "bank2", oric_ram_0x0c000+0x02000); |
| 578 | | memory_set_bankptr(space->machine, "bank3", oric_ram_0x0c000+0x03800); |
| 579 | | memory_set_bankptr(space->machine, "bank5", oric_ram_0x0c000); |
| 580 | | memory_set_bankptr(space->machine, "bank6", oric_ram_0x0c000+0x02000); |
| 581 | | memory_set_bankptr(space->machine, "bank7", oric_ram_0x0c000+0x03800); |
| 581 | memory_set_bankptr(space->machine, "bank1", state->ram_0x0c000); |
| 582 | memory_set_bankptr(space->machine, "bank2", state->ram_0x0c000+0x02000); |
| 583 | memory_set_bankptr(space->machine, "bank3", state->ram_0x0c000+0x03800); |
| 584 | memory_set_bankptr(space->machine, "bank5", state->ram_0x0c000); |
| 585 | memory_set_bankptr(space->machine, "bank6", state->ram_0x0c000+0x02000); |
| 586 | memory_set_bankptr(space->machine, "bank7", state->ram_0x0c000+0x03800); |
| 582 | 587 | } |
| 583 | 588 | } |
| 584 | 589 | |
| r9669 | r9670 | |
| 605 | 610 | |
| 606 | 611 | |
| 607 | 612 | /* bit 0: overlay ram access (1 means overlay ram enabled) */ |
| 608 | | static unsigned char port_3fa_w; |
| 609 | 613 | |
| 610 | 614 | /* bit 0: ROMDIS (1 means internal Basic rom disabled) */ |
| 611 | | static unsigned char port_3fb_w; |
| 612 | 615 | |
| 613 | 616 | |
| 614 | 617 | static void oric_jasmin_set_mem_0x0c000(running_machine *machine) |
| 615 | 618 | { |
| 619 | oric_state *state = machine->driver_data<oric_state>(); |
| 616 | 620 | /* assumption: |
| 617 | 621 | 1. It is possible to access all 16k overlay ram. |
| 618 | 622 | 2. If os is enabled, and overlay ram is enabled, all 16k can be accessed. |
| 619 | 623 | 3. if os is disabled, and overlay ram is enabled, jasmin rom takes priority. |
| 620 | 624 | */ |
| 621 | | if (oric_is_telestrat) |
| 625 | if (state->is_telestrat) |
| 622 | 626 | return; |
| 623 | 627 | |
| 624 | 628 | /* the ram is disabled in the jasmin rom which indicates that jasmin takes |
| 625 | 629 | priority over the ram */ |
| 626 | 630 | |
| 627 | 631 | /* basic rom disabled? */ |
| 628 | | if ((port_3fb_w & 0x01)==0) |
| 632 | if ((state->port_3fb_w & 0x01)==0) |
| 629 | 633 | { |
| 630 | 634 | /* no, it is enabled! */ |
| 631 | 635 | |
| 632 | 636 | /* overlay ram enabled? */ |
| 633 | | if ((port_3fa_w & 0x01)==0) |
| 637 | if ((state->port_3fa_w & 0x01)==0) |
| 634 | 638 | { |
| 635 | 639 | unsigned char *rom_ptr; |
| 636 | 640 | |
| r9669 | r9670 | |
| 650 | 654 | |
| 651 | 655 | oric_enable_memory(machine, 1, 3, TRUE, TRUE); |
| 652 | 656 | |
| 653 | | memory_set_bankptr(machine, "bank1", oric_ram_0x0c000); |
| 654 | | memory_set_bankptr(machine, "bank2", oric_ram_0x0c000+0x02000); |
| 655 | | memory_set_bankptr(machine, "bank3", oric_ram_0x0c000+0x03800); |
| 656 | | memory_set_bankptr(machine, "bank5", oric_ram_0x0c000); |
| 657 | | memory_set_bankptr(machine, "bank6", oric_ram_0x0c000+0x02000); |
| 658 | | memory_set_bankptr(machine, "bank7", oric_ram_0x0c000+0x03800); |
| 657 | memory_set_bankptr(machine, "bank1", state->ram_0x0c000); |
| 658 | memory_set_bankptr(machine, "bank2", state->ram_0x0c000+0x02000); |
| 659 | memory_set_bankptr(machine, "bank3", state->ram_0x0c000+0x03800); |
| 660 | memory_set_bankptr(machine, "bank5", state->ram_0x0c000); |
| 661 | memory_set_bankptr(machine, "bank6", state->ram_0x0c000+0x02000); |
| 662 | memory_set_bankptr(machine, "bank7", state->ram_0x0c000+0x03800); |
| 659 | 663 | } |
| 660 | 664 | } |
| 661 | 665 | else |
| 662 | 666 | { |
| 663 | 667 | /* yes, basic rom is disabled */ |
| 664 | 668 | |
| 665 | | if ((port_3fa_w & 0x01)==0) |
| 669 | if ((state->port_3fa_w & 0x01)==0) |
| 666 | 670 | { |
| 667 | 671 | /* overlay ram disabled */ |
| 668 | 672 | |
| r9669 | r9670 | |
| 674 | 678 | /*logerror("&c000-&f8ff is ram!\n"); */ |
| 675 | 679 | oric_enable_memory(machine, 1, 2, TRUE, TRUE); |
| 676 | 680 | |
| 677 | | memory_set_bankptr(machine, "bank1", oric_ram_0x0c000); |
| 678 | | memory_set_bankptr(machine, "bank2", oric_ram_0x0c000+0x02000); |
| 679 | | memory_set_bankptr(machine, "bank5", oric_ram_0x0c000); |
| 680 | | memory_set_bankptr(machine, "bank6", oric_ram_0x0c000+0x02000); |
| 681 | memory_set_bankptr(machine, "bank1", state->ram_0x0c000); |
| 682 | memory_set_bankptr(machine, "bank2", state->ram_0x0c000+0x02000); |
| 683 | memory_set_bankptr(machine, "bank5", state->ram_0x0c000); |
| 684 | memory_set_bankptr(machine, "bank6", state->ram_0x0c000+0x02000); |
| 681 | 685 | } |
| 682 | 686 | |
| 683 | 687 | { |
| r9669 | r9670 | |
| 697 | 701 | /* DRQ is connected to interrupt */ |
| 698 | 702 | static WRITE_LINE_DEVICE_HANDLER( oric_jasmin_wd179x_drq_w ) |
| 699 | 703 | { |
| 704 | oric_state *drvstate = device->machine->driver_data<oric_state>(); |
| 700 | 705 | if (state) |
| 701 | | oric_irqs |= (1<<1); |
| 706 | drvstate->irqs |= (1<<1); |
| 702 | 707 | else |
| 703 | | oric_irqs &=~(1<<1); |
| 708 | drvstate->irqs &=~(1<<1); |
| 704 | 709 | |
| 705 | 710 | oric_refresh_ints(device->machine); |
| 706 | 711 | } |
| r9669 | r9670 | |
| 738 | 743 | |
| 739 | 744 | static WRITE8_HANDLER(oric_jasmin_w) |
| 740 | 745 | { |
| 746 | oric_state *state = space->machine->driver_data<oric_state>(); |
| 741 | 747 | via6522_device *via_0 = space->machine->device<via6522_device>("via6522_0");; |
| 742 | 748 | running_device *fdc = space->machine->device("wd179x"); |
| 743 | 749 | switch (offset & 0x0f) |
| r9669 | r9670 | |
| 765 | 771 | break; |
| 766 | 772 | case 0x0a: |
| 767 | 773 | //logerror("jasmin overlay ram w: %02x PC: %04x\n", data, cpu_get_pc(space->machine->device("maincpu"))); |
| 768 | | port_3fa_w = data; |
| 774 | state->port_3fa_w = data; |
| 769 | 775 | oric_jasmin_set_mem_0x0c000(space->machine); |
| 770 | 776 | break; |
| 771 | 777 | case 0x0b: |
| 772 | 778 | //logerror("jasmin romdis w: %02x PC: %04x\n", data, cpu_get_pc(space->machine->device("maincpu"))); |
| 773 | | port_3fb_w = data; |
| 779 | state->port_3fb_w = data; |
| 774 | 780 | oric_jasmin_set_mem_0x0c000(space->machine); |
| 775 | 781 | break; |
| 776 | 782 | /* bit 0,1 of addr is the drive */ |
| r9669 | r9670 | |
| 790 | 796 | |
| 791 | 797 | static void oric_install_jasmin_interface(running_machine *machine) |
| 792 | 798 | { |
| 799 | oric_state *state = machine->driver_data<oric_state>(); |
| 793 | 800 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 794 | 801 | /* romdis */ |
| 795 | | port_3fb_w = 1; |
| 802 | state->port_3fb_w = 1; |
| 796 | 803 | oric_jasmin_set_mem_0x0c000(machine); |
| 797 | 804 | |
| 798 | 805 | memory_install_read8_handler(space, 0x0300, 0x03ef, 0, 0, oric_IO_r); |
| r9669 | r9670 | |
| 806 | 813 | /* MICRODISC INTERFACE variables */ |
| 807 | 814 | |
| 808 | 815 | /* used by Microdisc interfaces */ |
| 809 | | static unsigned char oric_wd179x_int_state = 0; |
| 810 | 816 | |
| 811 | 817 | /* bit 7 is intrq state */ |
| 812 | | static unsigned char port_314_r; |
| 813 | 818 | /* bit 7 is drq state (active low) */ |
| 814 | | static unsigned char port_318_r; |
| 815 | 819 | /* bit 6,5: drive */ |
| 816 | 820 | /* bit 4: side */ |
| 817 | 821 | /* bit 3: double density enable */ |
| 818 | 822 | /* bit 0: enable FDC IRQ to trigger IRQ on CPU */ |
| 819 | | static unsigned char port_314_w; |
| 820 | 823 | |
| 821 | 824 | |
| 822 | 825 | static void oric_microdisc_refresh_wd179x_ints(running_machine *machine) |
| 823 | 826 | { |
| 824 | | oric_irqs &=~(1<<1); |
| 827 | oric_state *state = machine->driver_data<oric_state>(); |
| 828 | state->irqs &=~(1<<1); |
| 825 | 829 | |
| 826 | | if ((oric_wd179x_int_state) && (port_314_w & (1<<0))) |
| 830 | if ((state->wd179x_int_state) && (state->port_314_w & (1<<0))) |
| 827 | 831 | { |
| 828 | 832 | /*logerror("oric microdisc interrupt\n"); */ |
| 829 | 833 | |
| 830 | | oric_irqs |=(1<<1); |
| 834 | state->irqs |=(1<<1); |
| 831 | 835 | } |
| 832 | 836 | |
| 833 | 837 | oric_refresh_ints(machine); |
| r9669 | r9670 | |
| 835 | 839 | |
| 836 | 840 | static WRITE_LINE_DEVICE_HANDLER( oric_microdisc_wd179x_intrq_w ) |
| 837 | 841 | { |
| 838 | | oric_wd179x_int_state = state; |
| 842 | oric_state *drvstate = device->machine->driver_data<oric_state>(); |
| 843 | drvstate->wd179x_int_state = state; |
| 839 | 844 | |
| 840 | 845 | if (state) |
| 841 | | port_314_r &= ~(1<<7); |
| 846 | drvstate->port_314_r &= ~(1<<7); |
| 842 | 847 | else |
| 843 | | port_314_r |=(1<<7); |
| 848 | drvstate->port_314_r |=(1<<7); |
| 844 | 849 | |
| 845 | 850 | oric_microdisc_refresh_wd179x_ints(device->machine); |
| 846 | 851 | } |
| 847 | 852 | |
| 848 | 853 | static WRITE_LINE_DEVICE_HANDLER( oric_microdisc_wd179x_drq_w ) |
| 849 | 854 | { |
| 855 | oric_state *drvstate = device->machine->driver_data<oric_state>(); |
| 850 | 856 | if (state) |
| 851 | | port_318_r &=~(1<<7); |
| 857 | drvstate->port_318_r &=~(1<<7); |
| 852 | 858 | else |
| 853 | | port_318_r |= (1<<7); |
| 859 | drvstate->port_318_r |= (1<<7); |
| 854 | 860 | } |
| 855 | 861 | |
| 856 | 862 | static void oric_microdisc_set_mem_0x0c000(running_machine *machine) |
| 857 | 863 | { |
| 858 | | if (oric_is_telestrat) |
| 864 | oric_state *state = machine->driver_data<oric_state>(); |
| 865 | if (state->is_telestrat) |
| 859 | 866 | return; |
| 860 | 867 | |
| 861 | 868 | /* for 0x0c000-0x0dfff: */ |
| 862 | 869 | /* if os disabled, ram takes priority */ |
| 863 | 870 | /* /ROMDIS */ |
| 864 | | if ((port_314_w & (1<<1))==0) |
| 871 | if ((state->port_314_w & (1<<1))==0) |
| 865 | 872 | { |
| 866 | 873 | /*logerror("&c000-&dfff is ram\n"); */ |
| 867 | 874 | /* rom disabled enable ram */ |
| 868 | 875 | oric_enable_memory(machine, 1, 1, TRUE, TRUE); |
| 869 | | memory_set_bankptr(machine, "bank1", oric_ram_0x0c000); |
| 870 | | memory_set_bankptr(machine, "bank5", oric_ram_0x0c000); |
| 876 | memory_set_bankptr(machine, "bank1", state->ram_0x0c000); |
| 877 | memory_set_bankptr(machine, "bank5", state->ram_0x0c000); |
| 871 | 878 | } |
| 872 | 879 | else |
| 873 | 880 | { |
| r9669 | r9670 | |
| 882 | 889 | |
| 883 | 890 | /* for 0x0e000-0x0ffff */ |
| 884 | 891 | /* if not disabled, os takes priority */ |
| 885 | | if ((port_314_w & (1<<1))!=0) |
| 892 | if ((state->port_314_w & (1<<1))!=0) |
| 886 | 893 | { |
| 887 | 894 | unsigned char *rom_ptr; |
| 888 | 895 | /*logerror("&e000-&ffff is os rom\n"); */ |
| r9669 | r9670 | |
| 898 | 905 | else |
| 899 | 906 | { |
| 900 | 907 | /* if eprom is enabled, it takes priority over ram */ |
| 901 | | if ((port_314_w & (1<<7))==0) |
| 908 | if ((state->port_314_w & (1<<7))==0) |
| 902 | 909 | { |
| 903 | 910 | unsigned char *rom_ptr; |
| 904 | 911 | /*logerror("&e000-&ffff is disk rom\n"); */ |
| r9669 | r9670 | |
| 913 | 920 | /*logerror("&e000-&ffff is ram\n"); */ |
| 914 | 921 | /* rom disabled enable ram */ |
| 915 | 922 | oric_enable_memory(machine, 2, 3, TRUE, TRUE); |
| 916 | | memory_set_bankptr(machine, "bank2", oric_ram_0x0c000+0x02000); |
| 917 | | memory_set_bankptr(machine, "bank3", oric_ram_0x0c000+0x03800); |
| 918 | | memory_set_bankptr(machine, "bank6", oric_ram_0x0c000+0x02000); |
| 919 | | memory_set_bankptr(machine, "bank7", oric_ram_0x0c000+0x03800); |
| 923 | memory_set_bankptr(machine, "bank2", state->ram_0x0c000+0x02000); |
| 924 | memory_set_bankptr(machine, "bank3", state->ram_0x0c000+0x03800); |
| 925 | memory_set_bankptr(machine, "bank6", state->ram_0x0c000+0x02000); |
| 926 | memory_set_bankptr(machine, "bank7", state->ram_0x0c000+0x03800); |
| 920 | 927 | } |
| 921 | 928 | } |
| 922 | 929 | } |
| r9669 | r9670 | |
| 925 | 932 | |
| 926 | 933 | READ8_HANDLER (oric_microdisc_r) |
| 927 | 934 | { |
| 935 | oric_state *state = space->machine->driver_data<oric_state>(); |
| 928 | 936 | unsigned char data = 0x0ff; |
| 929 | 937 | running_device *fdc = space->machine->device("wd179x"); |
| 930 | 938 | |
| r9669 | r9670 | |
| 944 | 952 | data = wd17xx_data_r(fdc, 0); |
| 945 | 953 | break; |
| 946 | 954 | case 0x04: |
| 947 | | data = port_314_r | 0x07f; |
| 955 | data = state->port_314_r | 0x07f; |
| 948 | 956 | /* logerror("port_314_r: %02x\n",data); */ |
| 949 | 957 | break; |
| 950 | 958 | case 0x08: |
| 951 | | data = port_318_r | 0x07f; |
| 959 | data = state->port_318_r | 0x07f; |
| 952 | 960 | /* logerror("port_318_r: %02x\n",data); */ |
| 953 | 961 | break; |
| 954 | 962 | |
| r9669 | r9670 | |
| 966 | 974 | |
| 967 | 975 | WRITE8_HANDLER(oric_microdisc_w) |
| 968 | 976 | { |
| 977 | oric_state *state = space->machine->driver_data<oric_state>(); |
| 969 | 978 | running_device *fdc = space->machine->device("wd179x"); |
| 970 | 979 | switch (offset & 0x0ff) |
| 971 | 980 | { |
| r9669 | r9670 | |
| 984 | 993 | break; |
| 985 | 994 | case 0x04: |
| 986 | 995 | { |
| 987 | | port_314_w = data; |
| 996 | state->port_314_w = data; |
| 988 | 997 | |
| 989 | 998 | //logerror("port_314_w: %02x\n",data); |
| 990 | 999 | |
| r9669 | r9670 | |
| 1012 | 1021 | |
| 1013 | 1022 | static void oric_install_microdisc_interface(running_machine *machine) |
| 1014 | 1023 | { |
| 1024 | oric_state *state = machine->driver_data<oric_state>(); |
| 1015 | 1025 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 1016 | 1026 | |
| 1017 | 1027 | memory_install_read8_handler(space, 0x0300, 0x030f, 0, 0, oric_IO_r); |
| r9669 | r9670 | |
| 1024 | 1034 | |
| 1025 | 1035 | /* disable os rom, enable microdisc rom */ |
| 1026 | 1036 | /* 0x0c000-0x0dfff will be ram, 0x0e000-0x0ffff will be microdisc rom */ |
| 1027 | | port_314_w = 0x0ff^((1<<7) | (1<<1)); |
| 1037 | state->port_314_w = 0x0ff^((1<<7) | (1<<1)); |
| 1028 | 1038 | |
| 1029 | 1039 | oric_microdisc_set_mem_0x0c000(machine); |
| 1030 | 1040 | } |
| r9669 | r9670 | |
| 1066 | 1076 | |
| 1067 | 1077 | static void oric_common_init_machine(running_machine *machine) |
| 1068 | 1078 | { |
| 1079 | oric_state *state = machine->driver_data<oric_state>(); |
| 1069 | 1080 | /* clear all irqs */ |
| 1070 | | oric_irqs = 0; |
| 1071 | | oric_ram_0x0c000 = NULL; |
| 1081 | state->irqs = 0; |
| 1082 | state->ram_0x0c000 = NULL; |
| 1072 | 1083 | |
| 1073 | 1084 | timer_pulse(machine, ATTOTIME_IN_HZ(4800), NULL, 0, oric_refresh_tape); |
| 1074 | 1085 | } |
| 1075 | 1086 | |
| 1076 | 1087 | MACHINE_START( oric ) |
| 1077 | 1088 | { |
| 1089 | oric_state *state = machine->driver_data<oric_state>(); |
| 1078 | 1090 | oric_common_init_machine(machine); |
| 1079 | 1091 | |
| 1080 | | oric_is_telestrat = 0; |
| 1092 | state->is_telestrat = 0; |
| 1081 | 1093 | |
| 1082 | | oric_ram_0x0c000 = auto_alloc_array(machine, char, 16384); |
| 1094 | state->ram_0x0c000 = auto_alloc_array(machine, char, 16384); |
| 1083 | 1095 | } |
| 1084 | 1096 | |
| 1085 | 1097 | |
| 1086 | 1098 | MACHINE_RESET( oric ) |
| 1087 | 1099 | { |
| 1100 | oric_state *state = machine->driver_data<oric_state>(); |
| 1088 | 1101 | int disc_interface_id = input_port_read(machine, "FLOPPY") & 0x07; |
| 1089 | 1102 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 1090 | | if (oric_is_telestrat) |
| 1103 | if (state->is_telestrat) |
| 1091 | 1104 | return; |
| 1092 | 1105 | |
| 1093 | 1106 | switch (disc_interface_id) |
| r9669 | r9670 | |
| 1274 | 1287 | |
| 1275 | 1288 | */ |
| 1276 | 1289 | |
| 1277 | | static unsigned char telestrat_bank_selection; |
| 1278 | | static unsigned char telestrat_via2_port_a_data; |
| 1279 | | static unsigned char telestrat_via2_port_b_data; |
| 1280 | 1290 | |
| 1281 | | enum |
| 1282 | | { |
| 1283 | | TELESTRAT_MEM_BLOCK_UNDEFINED, |
| 1284 | | TELESTRAT_MEM_BLOCK_RAM, |
| 1285 | | TELESTRAT_MEM_BLOCK_ROM |
| 1286 | | }; |
| 1287 | | |
| 1288 | | struct telestrat_mem_block |
| 1289 | | { |
| 1290 | | int MemType; |
| 1291 | | unsigned char *ptr; |
| 1292 | | }; |
| 1293 | | |
| 1294 | | |
| 1295 | | static struct telestrat_mem_block telestrat_blocks[8]; |
| 1296 | | |
| 1297 | 1291 | static void telestrat_refresh_mem(running_machine *machine) |
| 1298 | 1292 | { |
| 1293 | oric_state *state = machine->driver_data<oric_state>(); |
| 1299 | 1294 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 1300 | 1295 | |
| 1301 | | struct telestrat_mem_block *mem_block = &telestrat_blocks[telestrat_bank_selection]; |
| 1296 | telestrat_mem_block *mem_block = &state->telestrat_blocks[state->telestrat_bank_selection]; |
| 1302 | 1297 | |
| 1303 | 1298 | switch (mem_block->MemType) |
| 1304 | 1299 | { |
| r9669 | r9670 | |
| 1330 | 1325 | |
| 1331 | 1326 | static READ8_DEVICE_HANDLER(telestrat_via2_in_a_func) |
| 1332 | 1327 | { |
| 1333 | | //logerror("via 2 - port a %02x\n",telestrat_via2_port_a_data); |
| 1334 | | return telestrat_via2_port_a_data; |
| 1328 | oric_state *state = device->machine->driver_data<oric_state>(); |
| 1329 | //logerror("via 2 - port a %02x\n",state->telestrat_via2_port_a_data); |
| 1330 | return state->telestrat_via2_port_a_data; |
| 1335 | 1331 | } |
| 1336 | 1332 | |
| 1337 | 1333 | |
| 1338 | 1334 | static WRITE8_DEVICE_HANDLER(telestrat_via2_out_a_func) |
| 1339 | 1335 | { |
| 1336 | oric_state *state = device->machine->driver_data<oric_state>(); |
| 1340 | 1337 | //logerror("via 2 - port a w: %02x\n",data); |
| 1341 | 1338 | |
| 1342 | | telestrat_via2_port_a_data = data; |
| 1339 | state->telestrat_via2_port_a_data = data; |
| 1343 | 1340 | |
| 1344 | | if (((data^telestrat_bank_selection) & 0x07)!=0) |
| 1341 | if (((data^state->telestrat_bank_selection) & 0x07)!=0) |
| 1345 | 1342 | { |
| 1346 | | telestrat_bank_selection = data & 0x07; |
| 1343 | state->telestrat_bank_selection = data & 0x07; |
| 1347 | 1344 | |
| 1348 | 1345 | telestrat_refresh_mem(device->machine); |
| 1349 | 1346 | } |
| r9669 | r9670 | |
| 1351 | 1348 | |
| 1352 | 1349 | static READ8_DEVICE_HANDLER(telestrat_via2_in_b_func) |
| 1353 | 1350 | { |
| 1351 | oric_state *state = device->machine->driver_data<oric_state>(); |
| 1354 | 1352 | unsigned char data = 0x01f; |
| 1355 | 1353 | |
| 1356 | 1354 | /* left joystick selected? */ |
| 1357 | | if (telestrat_via2_port_b_data & (1<<6)) |
| 1355 | if (state->telestrat_via2_port_b_data & (1<<6)) |
| 1358 | 1356 | { |
| 1359 | 1357 | data &= input_port_read(device->machine, "JOY0"); |
| 1360 | 1358 | } |
| 1361 | 1359 | |
| 1362 | 1360 | /* right joystick selected? */ |
| 1363 | | if (telestrat_via2_port_b_data & (1<<7)) |
| 1361 | if (state->telestrat_via2_port_b_data & (1<<7)) |
| 1364 | 1362 | { |
| 1365 | 1363 | data &= input_port_read(device->machine, "JOY1"); |
| 1366 | 1364 | } |
| 1367 | 1365 | |
| 1368 | | data |= telestrat_via2_port_b_data & ((1<<7) | (1<<6) | (1<<5)); |
| 1366 | data |= state->telestrat_via2_port_b_data & ((1<<7) | (1<<6) | (1<<5)); |
| 1369 | 1367 | |
| 1370 | 1368 | return data; |
| 1371 | 1369 | } |
| 1372 | 1370 | |
| 1373 | 1371 | static WRITE8_DEVICE_HANDLER(telestrat_via2_out_b_func) |
| 1374 | 1372 | { |
| 1375 | | telestrat_via2_port_b_data = data; |
| 1373 | oric_state *state = device->machine->driver_data<oric_state>(); |
| 1374 | state->telestrat_via2_port_b_data = data; |
| 1376 | 1375 | } |
| 1377 | 1376 | |
| 1378 | 1377 | |
| 1379 | 1378 | static void telestrat_via2_irq_func(running_device *device, int state) |
| 1380 | 1379 | { |
| 1381 | | oric_irqs &=~(1<<2); |
| 1380 | oric_state *drvstate = device->machine->driver_data<oric_state>(); |
| 1381 | drvstate->irqs &=~(1<<2); |
| 1382 | 1382 | |
| 1383 | 1383 | if (state) |
| 1384 | 1384 | { |
| 1385 | 1385 | //logerror("telestrat via2 interrupt\n"); |
| 1386 | 1386 | |
| 1387 | | oric_irqs |=(1<<2); |
| 1387 | drvstate->irqs |=(1<<2); |
| 1388 | 1388 | } |
| 1389 | 1389 | |
| 1390 | 1390 | oric_refresh_ints(device->machine); |
| r9669 | r9670 | |
| 1410 | 1410 | /* interrupt state from acia6551 */ |
| 1411 | 1411 | static void telestrat_acia_callback(running_machine *machine, int irq_state) |
| 1412 | 1412 | { |
| 1413 | | oric_irqs&=~(1<<3); |
| 1413 | oric_state *state = machine->driver_data<oric_state>(); |
| 1414 | state->irqs&=~(1<<3); |
| 1414 | 1415 | |
| 1415 | 1416 | if (irq_state) |
| 1416 | 1417 | { |
| 1417 | | oric_irqs |= (1<<3); |
| 1418 | state->irqs |= (1<<3); |
| 1418 | 1419 | } |
| 1419 | 1420 | |
| 1420 | 1421 | oric_refresh_ints(machine); |
| r9669 | r9670 | |
| 1423 | 1424 | |
| 1424 | 1425 | MACHINE_START( telestrat ) |
| 1425 | 1426 | { |
| 1427 | oric_state *state = machine->driver_data<oric_state>(); |
| 1426 | 1428 | oric_common_init_machine(machine); |
| 1427 | 1429 | |
| 1428 | | oric_is_telestrat = 1; |
| 1430 | state->is_telestrat = 1; |
| 1429 | 1431 | |
| 1430 | 1432 | /* initialise overlay ram */ |
| 1431 | | telestrat_blocks[0].MemType = TELESTRAT_MEM_BLOCK_RAM; |
| 1432 | | telestrat_blocks[0].ptr = auto_alloc_array(machine, UINT8, 16384); |
| 1433 | state->telestrat_blocks[0].MemType = TELESTRAT_MEM_BLOCK_RAM; |
| 1434 | state->telestrat_blocks[0].ptr = auto_alloc_array(machine, UINT8, 16384); |
| 1433 | 1435 | |
| 1434 | | telestrat_blocks[1].MemType = TELESTRAT_MEM_BLOCK_RAM; |
| 1435 | | telestrat_blocks[1].ptr = auto_alloc_array(machine, UINT8, 16384); |
| 1436 | | telestrat_blocks[2].MemType = TELESTRAT_MEM_BLOCK_RAM; |
| 1437 | | telestrat_blocks[2].ptr = auto_alloc_array(machine, UINT8, 16384); |
| 1436 | state->telestrat_blocks[1].MemType = TELESTRAT_MEM_BLOCK_RAM; |
| 1437 | state->telestrat_blocks[1].ptr = auto_alloc_array(machine, UINT8, 16384); |
| 1438 | state->telestrat_blocks[2].MemType = TELESTRAT_MEM_BLOCK_RAM; |
| 1439 | state->telestrat_blocks[2].ptr = auto_alloc_array(machine, UINT8, 16384); |
| 1438 | 1440 | |
| 1439 | 1441 | /* initialise default cartridge */ |
| 1440 | | telestrat_blocks[3].MemType = TELESTRAT_MEM_BLOCK_ROM; |
| 1441 | | telestrat_blocks[3].ptr = memory_region(machine, "maincpu")+0x010000; |
| 1442 | state->telestrat_blocks[3].MemType = TELESTRAT_MEM_BLOCK_ROM; |
| 1443 | state->telestrat_blocks[3].ptr = memory_region(machine, "maincpu")+0x010000; |
| 1442 | 1444 | |
| 1443 | | telestrat_blocks[4].MemType = TELESTRAT_MEM_BLOCK_RAM; |
| 1444 | | telestrat_blocks[4].ptr = auto_alloc_array(machine, UINT8, 16384); |
| 1445 | state->telestrat_blocks[4].MemType = TELESTRAT_MEM_BLOCK_RAM; |
| 1446 | state->telestrat_blocks[4].ptr = auto_alloc_array(machine, UINT8, 16384); |
| 1445 | 1447 | |
| 1446 | 1448 | /* initialise default cartridge */ |
| 1447 | | telestrat_blocks[5].MemType = TELESTRAT_MEM_BLOCK_ROM; |
| 1448 | | telestrat_blocks[5].ptr = memory_region(machine, "maincpu")+0x014000; |
| 1449 | state->telestrat_blocks[5].MemType = TELESTRAT_MEM_BLOCK_ROM; |
| 1450 | state->telestrat_blocks[5].ptr = memory_region(machine, "maincpu")+0x014000; |
| 1449 | 1451 | |
| 1450 | 1452 | /* initialise default cartridge */ |
| 1451 | | telestrat_blocks[6].MemType = TELESTRAT_MEM_BLOCK_ROM; |
| 1452 | | telestrat_blocks[6].ptr = memory_region(machine, "maincpu")+0x018000; |
| 1453 | state->telestrat_blocks[6].MemType = TELESTRAT_MEM_BLOCK_ROM; |
| 1454 | state->telestrat_blocks[6].ptr = memory_region(machine, "maincpu")+0x018000; |
| 1453 | 1455 | |
| 1454 | 1456 | /* initialise default cartridge */ |
| 1455 | | telestrat_blocks[7].MemType = TELESTRAT_MEM_BLOCK_ROM; |
| 1456 | | telestrat_blocks[7].ptr = memory_region(machine, "maincpu")+0x01c000; |
| 1457 | state->telestrat_blocks[7].MemType = TELESTRAT_MEM_BLOCK_ROM; |
| 1458 | state->telestrat_blocks[7].ptr = memory_region(machine, "maincpu")+0x01c000; |
| 1457 | 1459 | |
| 1458 | | telestrat_bank_selection = 7; |
| 1460 | state->telestrat_bank_selection = 7; |
| 1459 | 1461 | telestrat_refresh_mem(machine); |
| 1460 | 1462 | |
| 1461 | 1463 | /* disable os rom, enable microdisc rom */ |
| 1462 | 1464 | /* 0x0c000-0x0dfff will be ram, 0x0e000-0x0ffff will be microdisc rom */ |
| 1463 | | port_314_w = 0x0ff^((1<<7) | (1<<1)); |
| 1465 | state->port_314_w = 0x0ff^((1<<7) | (1<<1)); |
| 1464 | 1466 | } |
src/mess/machine/vtech2.c
| r9669 | r9670 | |
| 20 | 20 | #include "sound/speaker.h" |
| 21 | 21 | |
| 22 | 22 | /* public */ |
| 23 | | int laser_latch; |
| 24 | 23 | |
| 25 | 24 | /* static */ |
| 26 | | static UINT8 *mem; |
| 27 | | static int laser_bank_mask; /* up to 16 4K banks supported */ |
| 28 | | static int laser_bank[4]; |
| 29 | | static int laser_video_bank; |
| 30 | 25 | |
| 31 | 26 | #define TRKSIZE_VZ 0x9a0 /* arbitrary (actually from analyzing format) */ |
| 32 | | #define TRKSIZE_FM 3172 /* size of a standard FM mode track */ |
| 33 | 27 | |
| 34 | | static UINT8 laser_track_x2[2]; |
| 35 | 28 | static const UINT8 laser_fdc_wrprot[2] = {0x80, 0x80}; |
| 36 | | static UINT8 laser_fdc_status = 0; |
| 37 | | static UINT8 laser_fdc_data[TRKSIZE_FM]; |
| 38 | | static int laser_data; |
| 39 | | static int laser_fdc_edge = 0; |
| 40 | | static int laser_fdc_bits; |
| 41 | | static int laser_drive; |
| 42 | | static int laser_fdc_start = 0; |
| 43 | | static int laser_fdc_write = 0; |
| 44 | | static int laser_fdc_offs = 0; |
| 45 | | static int laser_fdc_latch = 0; |
| 46 | 29 | |
| 47 | 30 | /* write to banked memory (handle memory mapped i/o and videoram) */ |
| 48 | 31 | static void mwa_bank(running_machine *machine, int bank, int offs, int data); |
| r9669 | r9670 | |
| 100 | 83 | |
| 101 | 84 | DRIVER_INIT(laser) |
| 102 | 85 | { |
| 86 | vtech2_state *state = machine->driver_data<vtech2_state>(); |
| 103 | 87 | UINT8 *gfx = memory_region(machine, "gfx2"); |
| 104 | 88 | int i; |
| 105 | 89 | |
| 106 | | laser_track_x2[0] = laser_track_x2[1] = 80; |
| 107 | | laser_fdc_bits = 8; |
| 108 | | laser_drive = -1; |
| 90 | state->laser_track_x2[0] = state->laser_track_x2[1] = 80; |
| 91 | state->laser_fdc_bits = 8; |
| 92 | state->laser_drive = -1; |
| 109 | 93 | |
| 110 | 94 | for (i = 0; i < 256; i++) |
| 111 | 95 | gfx[i] = i; |
| 112 | 96 | |
| 113 | | laser_latch = -1; |
| 114 | | mem = memory_region(machine, "maincpu"); |
| 97 | state->laser_latch = -1; |
| 98 | state->mem = memory_region(machine, "maincpu"); |
| 115 | 99 | |
| 116 | | for (i = 0; i < ARRAY_LENGTH(laser_bank); i++) |
| 117 | | laser_bank[i] = -1; |
| 100 | for (i = 0; i < ARRAY_LENGTH(state->laser_bank); i++) |
| 101 | state->laser_bank[i] = -1; |
| 118 | 102 | } |
| 119 | 103 | |
| 120 | 104 | |
| r9669 | r9670 | |
| 124 | 108 | vtech2_state *state = machine->driver_data<vtech2_state>(); |
| 125 | 109 | int i; |
| 126 | 110 | |
| 127 | | laser_bank_mask = bank_mask; |
| 128 | | laser_video_bank = video_mask; |
| 129 | | state->videoram = mem + laser_video_bank * 0x04000; |
| 130 | | logerror("laser_machine_init(): bank mask $%04X, video %d [$%05X]\n", laser_bank_mask, laser_video_bank, laser_video_bank * 0x04000); |
| 111 | state->laser_bank_mask = bank_mask; |
| 112 | state->laser_video_bank = video_mask; |
| 113 | state->videoram = state->mem + state->laser_video_bank * 0x04000; |
| 114 | logerror("laser_machine_init(): bank mask $%04X, video %d [$%05X]\n", state->laser_bank_mask, state->laser_video_bank, state->laser_video_bank * 0x04000); |
| 131 | 115 | |
| 132 | | for (i = 0; i < ARRAY_LENGTH(laser_bank); i++) |
| 116 | for (i = 0; i < ARRAY_LENGTH(state->laser_bank); i++) |
| 133 | 117 | laser_bank_select_w(cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), i, 0); |
| 134 | 118 | } |
| 135 | 119 | |
| r9669 | r9670 | |
| 154 | 138 | |
| 155 | 139 | WRITE8_HANDLER( laser_bank_select_w ) |
| 156 | 140 | { |
| 141 | vtech2_state *state = space->machine->driver_data<vtech2_state>(); |
| 157 | 142 | static const char *const bank_name[16] = { |
| 158 | 143 | "ROM lo","ROM hi","MM I/O","Video RAM lo", |
| 159 | 144 | "RAM #0","RAM #1","RAM #2","RAM #3", |
| r9669 | r9670 | |
| 164 | 149 | offset %= 4; |
| 165 | 150 | data &= 15; |
| 166 | 151 | |
| 167 | | if( data != laser_bank[offset] ) |
| 152 | if( data != state->laser_bank[offset] ) |
| 168 | 153 | { |
| 169 | | laser_bank[offset] = data; |
| 154 | state->laser_bank[offset] = data; |
| 170 | 155 | logerror("select bank #%d $%02X [$%05X] %s\n", offset+1, data, 0x4000 * (data & 15), bank_name[data]); |
| 171 | 156 | |
| 172 | 157 | /* memory mapped I/O bank selected? */ |
| r9669 | r9670 | |
| 178 | 163 | else |
| 179 | 164 | { |
| 180 | 165 | sprintf(bank,"bank%d",offset+1); |
| 181 | | memory_set_bankptr(space->machine, bank, &mem[0x4000*laser_bank[offset]]); |
| 182 | | if( laser_bank_mask & (1 << data) ) |
| 166 | memory_set_bankptr(space->machine, bank, &state->mem[0x4000*state->laser_bank[offset]]); |
| 167 | if( state->laser_bank_mask & (1 << data) ) |
| 183 | 168 | { |
| 184 | 169 | /* video RAM bank selected? */ |
| 185 | | if( data == laser_video_bank ) |
| 170 | if( data == state->laser_video_bank ) |
| 186 | 171 | { |
| 187 | 172 | logerror("select bank #%d VIDEO!\n", offset+1); |
| 188 | 173 | } |
| r9669 | r9670 | |
| 219 | 204 | ************************************************/ |
| 220 | 205 | static int mra_bank(running_machine *machine, int bank, int offs) |
| 221 | 206 | { |
| 222 | | static int level_old = 0, cassette_bit = 0; |
| 207 | vtech2_state *state = machine->driver_data<vtech2_state>(); |
| 223 | 208 | int level, data = 0xff; |
| 224 | 209 | |
| 225 | 210 | /* Laser 500/700 only: keyboard rows A through D */ |
| 226 | 211 | if( (offs & 0x00ff) == 0x00ff ) |
| 227 | 212 | { |
| 228 | | static int row_a,row_b,row_c,row_d; |
| 229 | 213 | if( (offs & 0x0300) == 0x0000 ) /* keyboard row A */ |
| 230 | 214 | { |
| 231 | | if( input_port_read(machine, "ROWA") != row_a ) |
| 215 | if( input_port_read(machine, "ROWA") != state->row_a ) |
| 232 | 216 | { |
| 233 | | row_a = input_port_read(machine, "ROWA"); |
| 234 | | data &= row_a; |
| 217 | state->row_a = input_port_read(machine, "ROWA"); |
| 218 | data &= state->row_a; |
| 235 | 219 | } |
| 236 | 220 | } |
| 237 | 221 | if( (offs & 0x0300) == 0x0100 ) /* keyboard row B */ |
| 238 | 222 | { |
| 239 | | if( input_port_read(machine, "ROWB") != row_b ) |
| 223 | if( input_port_read(machine, "ROWB") != state->row_b ) |
| 240 | 224 | { |
| 241 | | row_b = input_port_read(machine, "ROWB"); |
| 242 | | data &= row_b; |
| 225 | state->row_b = input_port_read(machine, "ROWB"); |
| 226 | data &= state->row_b; |
| 243 | 227 | } |
| 244 | 228 | } |
| 245 | 229 | if( (offs & 0x0300) == 0x0200 ) /* keyboard row C */ |
| 246 | 230 | { |
| 247 | | if( input_port_read(machine, "ROWC") != row_c ) |
| 231 | if( input_port_read(machine, "ROWC") != state->row_c ) |
| 248 | 232 | { |
| 249 | | row_c = input_port_read(machine, "ROWC"); |
| 250 | | data &= row_c; |
| 233 | state->row_c = input_port_read(machine, "ROWC"); |
| 234 | data &= state->row_c; |
| 251 | 235 | } |
| 252 | 236 | } |
| 253 | 237 | if( (offs & 0x0300) == 0x0300 ) /* keyboard row D */ |
| 254 | 238 | { |
| 255 | | if( input_port_read(machine, "ROWD") != row_d ) |
| 239 | if( input_port_read(machine, "ROWD") != state->row_d ) |
| 256 | 240 | { |
| 257 | | row_d = input_port_read(machine, "ROWD"); |
| 258 | | data &= row_d; |
| 241 | state->row_d = input_port_read(machine, "ROWD"); |
| 242 | data &= state->row_d; |
| 259 | 243 | } |
| 260 | 244 | } |
| 261 | 245 | } |
| r9669 | r9670 | |
| 282 | 266 | |
| 283 | 267 | /* what's bit 7 good for? tape input maybe? */ |
| 284 | 268 | level = cassette_input(vtech2_cassette_image(machine)) * 65536.0; |
| 285 | | if( level < level_old - 511 ) |
| 286 | | cassette_bit = 0x00; |
| 287 | | if( level > level_old + 511 ) |
| 288 | | cassette_bit = 0x80; |
| 289 | | level_old = level; |
| 269 | if( level < state->level_old - 511 ) |
| 270 | state->cassette_bit = 0x00; |
| 271 | if( level > state->level_old + 511 ) |
| 272 | state->cassette_bit = 0x80; |
| 273 | state->level_old = level; |
| 290 | 274 | |
| 291 | | data &= ~cassette_bit; |
| 275 | data &= ~state->cassette_bit; |
| 292 | 276 | // logerror("bank #%d keyboard_r [$%04X] $%02X\n", bank, offs, data); |
| 293 | 277 | |
| 294 | 278 | return data; |
| r9669 | r9670 | |
| 307 | 291 | ************************************************/ |
| 308 | 292 | static void mwa_bank(running_machine *machine, int bank, int offs, int data) |
| 309 | 293 | { |
| 294 | vtech2_state *state = machine->driver_data<vtech2_state>(); |
| 310 | 295 | running_device *speaker = machine->device("speaker"); |
| 311 | | offs += 0x4000 * laser_bank[bank]; |
| 312 | | switch (laser_bank[bank]) |
| 296 | offs += 0x4000 * state->laser_bank[bank]; |
| 297 | switch (state->laser_bank[bank]) |
| 313 | 298 | { |
| 314 | 299 | case 0: /* ROM lower 16K */ |
| 315 | 300 | case 1: /* ROM upper 16K */ |
| 316 | 301 | logerror("bank #%d write to ROM [$%05X] $%02X\n", bank+1, offs, data); |
| 317 | 302 | break; |
| 318 | 303 | case 2: /* memory mapped output */ |
| 319 | | if (data != laser_latch) |
| 304 | if (data != state->laser_latch) |
| 320 | 305 | { |
| 321 | 306 | logerror("bank #%d write to I/O [$%05X] $%02X\n", bank+1, offs, data); |
| 322 | 307 | /* Toggle between graphics and text modes? */ |
| 323 | | if ((data ^ laser_latch) & 0x01) |
| 308 | if ((data ^ state->laser_latch) & 0x01) |
| 324 | 309 | speaker_level_w(speaker, data & 1); |
| 325 | | laser_latch = data; |
| 310 | state->laser_latch = data; |
| 326 | 311 | } |
| 327 | 312 | break; |
| 328 | 313 | case 12: /* ext. ROM #1 */ |
| r9669 | r9670 | |
| 332 | 317 | logerror("bank #%d write to ROM [$%05X] $%02X\n", bank+1, offs, data); |
| 333 | 318 | break; |
| 334 | 319 | default: /* RAM */ |
| 335 | | if( laser_bank[bank] == laser_video_bank && mem[offs] != data ) |
| 320 | if( state->laser_bank[bank] == state->laser_video_bank && state->mem[offs] != data ) |
| 336 | 321 | { |
| 337 | 322 | logerror("bank #%d write to videoram [$%05X] $%02X\n", bank+1, offs, data); |
| 338 | 323 | } |
| 339 | | mem[offs] = data; |
| 324 | state->mem[offs] = data; |
| 340 | 325 | break; |
| 341 | 326 | } |
| 342 | 327 | } |
| 343 | 328 | |
| 344 | 329 | DEVICE_IMAGE_LOAD( laser_cart ) |
| 345 | 330 | { |
| 331 | vtech2_state *state = image.device().machine->driver_data<vtech2_state>(); |
| 346 | 332 | int size = 0; |
| 347 | 333 | |
| 348 | | size = image.fread(&mem[0x30000], 0x10000); |
| 349 | | laser_bank_mask &= ~0xf000; |
| 334 | size = image.fread(&state->mem[0x30000], 0x10000); |
| 335 | state->laser_bank_mask &= ~0xf000; |
| 350 | 336 | if( size > 0 ) |
| 351 | | laser_bank_mask |= 0x1000; |
| 337 | state->laser_bank_mask |= 0x1000; |
| 352 | 338 | if( size > 0x4000 ) |
| 353 | | laser_bank_mask |= 0x2000; |
| 339 | state->laser_bank_mask |= 0x2000; |
| 354 | 340 | if( size > 0x8000 ) |
| 355 | | laser_bank_mask |= 0x4000; |
| 341 | state->laser_bank_mask |= 0x4000; |
| 356 | 342 | if( size > 0xc000 ) |
| 357 | | laser_bank_mask |= 0x8000; |
| 343 | state->laser_bank_mask |= 0x8000; |
| 358 | 344 | |
| 359 | 345 | return size > 0 ? IMAGE_INIT_PASS : IMAGE_INIT_FAIL; |
| 360 | 346 | } |
| 361 | 347 | |
| 362 | 348 | DEVICE_IMAGE_UNLOAD( laser_cart ) |
| 363 | 349 | { |
| 364 | | laser_bank_mask &= ~0xf000; |
| 350 | vtech2_state *state = image.device().machine->driver_data<vtech2_state>(); |
| 351 | state->laser_bank_mask &= ~0xf000; |
| 365 | 352 | /* wipe out the memory contents to be 100% sure */ |
| 366 | | memset(&mem[0x30000], 0xff, 0x10000); |
| 353 | memset(&state->mem[0x30000], 0xff, 0x10000); |
| 367 | 354 | } |
| 368 | 355 | |
| 369 | 356 | static running_device *laser_file(running_machine *machine) |
| 370 | 357 | { |
| 371 | | return machine->device( laser_drive ? FLOPPY_1 : FLOPPY_0 ); |
| 358 | vtech2_state *state = machine->driver_data<vtech2_state>(); |
| 359 | return machine->device( state->laser_drive ? FLOPPY_1 : FLOPPY_0 ); |
| 372 | 360 | } |
| 373 | 361 | |
| 374 | 362 | static void laser_get_track(running_machine *machine) |
| 375 | 363 | { |
| 376 | | sprintf(laser_frame_message, "#%d get track %02d", laser_drive, laser_track_x2[laser_drive]/2); |
| 377 | | laser_frame_time = 30; |
| 364 | vtech2_state *state = machine->driver_data<vtech2_state>(); |
| 365 | sprintf(state->laser_frame_message, "#%d get track %02d", state->laser_drive, state->laser_track_x2[state->laser_drive]/2); |
| 366 | state->laser_frame_time = 30; |
| 378 | 367 | /* drive selected or and image file ok? */ |
| 379 | | if( laser_drive >= 0 && laser_file(machine) != NULL ) |
| 368 | if( state->laser_drive >= 0 && laser_file(machine) != NULL ) |
| 380 | 369 | { |
| 381 | 370 | int size, offs; |
| 382 | 371 | device_image_interface *image = dynamic_cast<device_image_interface *>(laser_file(machine)); |
| 383 | 372 | size = TRKSIZE_VZ; |
| 384 | | offs = TRKSIZE_VZ * laser_track_x2[laser_drive]/2; |
| 373 | offs = TRKSIZE_VZ * state->laser_track_x2[state->laser_drive]/2; |
| 385 | 374 | image->fseek(offs, SEEK_SET); |
| 386 | | size = image->fread(laser_fdc_data, size); |
| 375 | size = image->fread(state->laser_fdc_data, size); |
| 387 | 376 | logerror("get track @$%05x $%04x bytes\n", offs, size); |
| 388 | 377 | } |
| 389 | | laser_fdc_offs = 0; |
| 390 | | laser_fdc_write = 0; |
| 378 | state->laser_fdc_offs = 0; |
| 379 | state->laser_fdc_write = 0; |
| 391 | 380 | } |
| 392 | 381 | |
| 393 | 382 | static void laser_put_track(running_machine *machine) |
| 394 | 383 | { |
| 384 | vtech2_state *state = machine->driver_data<vtech2_state>(); |
| 395 | 385 | device_image_interface *image = dynamic_cast<device_image_interface *>(laser_file(machine)); |
| 396 | 386 | /* drive selected and image file ok? */ |
| 397 | | if( laser_drive >= 0 && laser_file(machine) != NULL ) |
| 387 | if( state->laser_drive >= 0 && laser_file(machine) != NULL ) |
| 398 | 388 | { |
| 399 | 389 | int size, offs; |
| 400 | | offs = TRKSIZE_VZ * laser_track_x2[laser_drive]/2; |
| 401 | | image->fseek(offs + laser_fdc_start, SEEK_SET); |
| 402 | | size = image->fwrite(&laser_fdc_data[laser_fdc_start], laser_fdc_write); |
| 403 | | logerror("put track @$%05X+$%X $%04X/$%04X bytes\n", offs, laser_fdc_start, size, laser_fdc_write); |
| 390 | offs = TRKSIZE_VZ * state->laser_track_x2[state->laser_drive]/2; |
| 391 | image->fseek(offs + state->laser_fdc_start, SEEK_SET); |
| 392 | size = image->fwrite(&state->laser_fdc_data[state->laser_fdc_start], state->laser_fdc_write); |
| 393 | logerror("put track @$%05X+$%X $%04X/$%04X bytes\n", offs, state->laser_fdc_start, size, state->laser_fdc_write); |
| 404 | 394 | } |
| 405 | 395 | } |
| 406 | 396 | |
| r9669 | r9670 | |
| 411 | 401 | |
| 412 | 402 | READ8_HANDLER( laser_fdc_r ) |
| 413 | 403 | { |
| 404 | vtech2_state *state = space->machine->driver_data<vtech2_state>(); |
| 414 | 405 | int data = 0xff; |
| 415 | 406 | switch( offset ) |
| 416 | 407 | { |
| 417 | 408 | case 1: /* data (read-only) */ |
| 418 | | if( laser_fdc_bits > 0 ) |
| 409 | if( state->laser_fdc_bits > 0 ) |
| 419 | 410 | { |
| 420 | | if( laser_fdc_status & 0x80 ) |
| 421 | | laser_fdc_bits--; |
| 422 | | data = (laser_data >> laser_fdc_bits) & 0xff; |
| 411 | if( state->laser_fdc_status & 0x80 ) |
| 412 | state->laser_fdc_bits--; |
| 413 | data = (state->laser_data >> state->laser_fdc_bits) & 0xff; |
| 423 | 414 | #if 0 |
| 424 | 415 | logerror("laser_fdc_r bits %d%d%d%d%d%d%d%d\n", |
| 425 | 416 | (data>>7)&1,(data>>6)&1,(data>>5)&1,(data>>4)&1, |
| 426 | 417 | (data>>3)&1,(data>>2)&1,(data>>1)&1,(data>>0)&1 ); |
| 427 | 418 | #endif |
| 428 | 419 | } |
| 429 | | if( laser_fdc_bits == 0 ) |
| 420 | if( state->laser_fdc_bits == 0 ) |
| 430 | 421 | { |
| 431 | | laser_data = laser_fdc_data[laser_fdc_offs]; |
| 432 | | logerror("laser_fdc_r %d : data ($%04X) $%02X\n", offset, laser_fdc_offs, laser_data); |
| 433 | | if( laser_fdc_status & 0x80 ) |
| 422 | state->laser_data = state->laser_fdc_data[state->laser_fdc_offs]; |
| 423 | logerror("laser_fdc_r %d : data ($%04X) $%02X\n", offset, state->laser_fdc_offs, state->laser_data); |
| 424 | if( state->laser_fdc_status & 0x80 ) |
| 434 | 425 | { |
| 435 | | laser_fdc_bits = 8; |
| 436 | | laser_fdc_offs = (laser_fdc_offs + 1) % TRKSIZE_FM; |
| 426 | state->laser_fdc_bits = 8; |
| 427 | state->laser_fdc_offs = (state->laser_fdc_offs + 1) % TRKSIZE_FM; |
| 437 | 428 | } |
| 438 | | laser_fdc_status &= ~0x80; |
| 429 | state->laser_fdc_status &= ~0x80; |
| 439 | 430 | } |
| 440 | 431 | break; |
| 441 | 432 | case 2: /* polling (read-only) */ |
| 442 | 433 | /* fake */ |
| 443 | | if( laser_drive >= 0 ) |
| 444 | | laser_fdc_status |= 0x80; |
| 445 | | data = laser_fdc_status; |
| 434 | if( state->laser_drive >= 0 ) |
| 435 | state->laser_fdc_status |= 0x80; |
| 436 | data = state->laser_fdc_status; |
| 446 | 437 | break; |
| 447 | 438 | case 3: /* write protect status (read-only) */ |
| 448 | | if( laser_drive >= 0 ) |
| 449 | | data = laser_fdc_wrprot[laser_drive]; |
| 439 | if( state->laser_drive >= 0 ) |
| 440 | data = laser_fdc_wrprot[state->laser_drive]; |
| 450 | 441 | logerror("laser_fdc_r %d : write_protect $%02X\n", offset, data); |
| 451 | 442 | break; |
| 452 | 443 | } |
| r9669 | r9670 | |
| 455 | 446 | |
| 456 | 447 | WRITE8_HANDLER( laser_fdc_w ) |
| 457 | 448 | { |
| 449 | vtech2_state *state = space->machine->driver_data<vtech2_state>(); |
| 458 | 450 | int drive; |
| 459 | 451 | |
| 460 | 452 | switch( offset ) |
| 461 | 453 | { |
| 462 | 454 | case 0: /* latch (write-only) */ |
| 463 | 455 | drive = (data & 0x10) ? 0 : (data & 0x80) ? 1 : -1; |
| 464 | | if( drive != laser_drive ) |
| 456 | if( drive != state->laser_drive ) |
| 465 | 457 | { |
| 466 | | laser_drive = drive; |
| 467 | | if( laser_drive >= 0 ) |
| 458 | state->laser_drive = drive; |
| 459 | if( state->laser_drive >= 0 ) |
| 468 | 460 | laser_get_track(space->machine); |
| 469 | 461 | } |
| 470 | | if( laser_drive >= 0 ) |
| 462 | if( state->laser_drive >= 0 ) |
| 471 | 463 | { |
| 472 | | if( (PHI0(data) && !(PHI1(data) || PHI2(data) || PHI3(data)) && PHI1(laser_fdc_latch)) || |
| 473 | | (PHI1(data) && !(PHI0(data) || PHI2(data) || PHI3(data)) && PHI2(laser_fdc_latch)) || |
| 474 | | (PHI2(data) && !(PHI0(data) || PHI1(data) || PHI3(data)) && PHI3(laser_fdc_latch)) || |
| 475 | | (PHI3(data) && !(PHI0(data) || PHI1(data) || PHI2(data)) && PHI0(laser_fdc_latch)) ) |
| 464 | if( (PHI0(data) && !(PHI1(data) || PHI2(data) || PHI3(data)) && PHI1(state->laser_fdc_latch)) || |
| 465 | (PHI1(data) && !(PHI0(data) || PHI2(data) || PHI3(data)) && PHI2(state->laser_fdc_latch)) || |
| 466 | (PHI2(data) && !(PHI0(data) || PHI1(data) || PHI3(data)) && PHI3(state->laser_fdc_latch)) || |
| 467 | (PHI3(data) && !(PHI0(data) || PHI1(data) || PHI2(data)) && PHI0(state->laser_fdc_latch)) ) |
| 476 | 468 | { |
| 477 | | if( laser_track_x2[laser_drive] > 0 ) |
| 478 | | laser_track_x2[laser_drive]--; |
| 479 | | logerror("laser_fdc_w(%d) $%02X drive %d: stepout track #%2d.%d\n", offset, data, laser_drive, laser_track_x2[laser_drive]/2,5*(laser_track_x2[laser_drive]&1)); |
| 480 | | if( (laser_track_x2[laser_drive] & 1) == 0 ) |
| 469 | if( state->laser_track_x2[state->laser_drive] > 0 ) |
| 470 | state->laser_track_x2[state->laser_drive]--; |
| 471 | logerror("laser_fdc_w(%d) $%02X drive %d: stepout track #%2d.%d\n", offset, data, state->laser_drive, state->laser_track_x2[state->laser_drive]/2,5*(state->laser_track_x2[state->laser_drive]&1)); |
| 472 | if( (state->laser_track_x2[state->laser_drive] & 1) == 0 ) |
| 481 | 473 | laser_get_track(space->machine); |
| 482 | 474 | } |
| 483 | 475 | else |
| 484 | | if( (PHI0(data) && !(PHI1(data) || PHI2(data) || PHI3(data)) && PHI3(laser_fdc_latch)) || |
| 485 | | (PHI1(data) && !(PHI0(data) || PHI2(data) || PHI3(data)) && PHI0(laser_fdc_latch)) || |
| 486 | | (PHI2(data) && !(PHI0(data) || PHI1(data) || PHI3(data)) && PHI1(laser_fdc_latch)) || |
| 487 | | (PHI3(data) && !(PHI0(data) || PHI1(data) || PHI2(data)) && PHI2(laser_fdc_latch)) ) |
| 476 | if( (PHI0(data) && !(PHI1(data) || PHI2(data) || PHI3(data)) && PHI3(state->laser_fdc_latch)) || |
| 477 | (PHI1(data) && !(PHI0(data) || PHI2(data) || PHI3(data)) && PHI0(state->laser_fdc_latch)) || |
| 478 | (PHI2(data) && !(PHI0(data) || PHI1(data) || PHI3(data)) && PHI1(state->laser_fdc_latch)) || |
| 479 | (PHI3(data) && !(PHI0(data) || PHI1(data) || PHI2(data)) && PHI2(state->laser_fdc_latch)) ) |
| 488 | 480 | { |
| 489 | | if( laser_track_x2[laser_drive] < 2*40 ) |
| 490 | | laser_track_x2[laser_drive]++; |
| 491 | | logerror("laser_fdc_w(%d) $%02X drive %d: stepin track #%2d.%d\n", offset, data, laser_drive, laser_track_x2[laser_drive]/2,5*(laser_track_x2[laser_drive]&1)); |
| 492 | | if( (laser_track_x2[laser_drive] & 1) == 0 ) |
| 481 | if( state->laser_track_x2[state->laser_drive] < 2*40 ) |
| 482 | state->laser_track_x2[state->laser_drive]++; |
| 483 | logerror("laser_fdc_w(%d) $%02X drive %d: stepin track #%2d.%d\n", offset, data, state->laser_drive, state->laser_track_x2[state->laser_drive]/2,5*(state->laser_track_x2[state->laser_drive]&1)); |
| 484 | if( (state->laser_track_x2[state->laser_drive] & 1) == 0 ) |
| 493 | 485 | laser_get_track(space->machine); |
| 494 | 486 | } |
| 495 | 487 | if( (data & 0x40) == 0 ) |
| 496 | 488 | { |
| 497 | | laser_data <<= 1; |
| 498 | | if( (laser_fdc_latch ^ data) & 0x20 ) |
| 499 | | laser_data |= 1; |
| 500 | | if( (laser_fdc_edge ^= 1) == 0 ) |
| 489 | state->laser_data <<= 1; |
| 490 | if( (state->laser_fdc_latch ^ data) & 0x20 ) |
| 491 | state->laser_data |= 1; |
| 492 | if( (state->laser_fdc_edge ^= 1) == 0 ) |
| 501 | 493 | { |
| 502 | | if( --laser_fdc_bits == 0 ) |
| 494 | if( --state->laser_fdc_bits == 0 ) |
| 503 | 495 | { |
| 504 | 496 | UINT8 value = 0; |
| 505 | | laser_data &= 0xffff; |
| 506 | | if( laser_data & 0x4000 ) value |= 0x80; |
| 507 | | if( laser_data & 0x1000 ) value |= 0x40; |
| 508 | | if( laser_data & 0x0400 ) value |= 0x20; |
| 509 | | if( laser_data & 0x0100 ) value |= 0x10; |
| 510 | | if( laser_data & 0x0040 ) value |= 0x08; |
| 511 | | if( laser_data & 0x0010 ) value |= 0x04; |
| 512 | | if( laser_data & 0x0004 ) value |= 0x02; |
| 513 | | if( laser_data & 0x0001 ) value |= 0x01; |
| 514 | | logerror("laser_fdc_w(%d) data($%04X) $%02X <- $%02X ($%04X)\n", offset, laser_fdc_offs, laser_fdc_data[laser_fdc_offs], value, laser_data); |
| 515 | | laser_fdc_data[laser_fdc_offs] = value; |
| 516 | | laser_fdc_offs = (laser_fdc_offs + 1) % TRKSIZE_FM; |
| 517 | | laser_fdc_write++; |
| 518 | | laser_fdc_bits = 8; |
| 497 | state->laser_data &= 0xffff; |
| 498 | if( state->laser_data & 0x4000 ) value |= 0x80; |
| 499 | if( state->laser_data & 0x1000 ) value |= 0x40; |
| 500 | if( state->laser_data & 0x0400 ) value |= 0x20; |
| 501 | if( state->laser_data & 0x0100 ) value |= 0x10; |
| 502 | if( state->laser_data & 0x0040 ) value |= 0x08; |
| 503 | if( state->laser_data & 0x0010 ) value |= 0x04; |
| 504 | if( state->laser_data & 0x0004 ) value |= 0x02; |
| 505 | if( state->laser_data & 0x0001 ) value |= 0x01; |
| 506 | logerror("laser_fdc_w(%d) data($%04X) $%02X <- $%02X ($%04X)\n", offset, state->laser_fdc_offs, state->laser_fdc_data[state->laser_fdc_offs], value, state->laser_data); |
| 507 | state->laser_fdc_data[state->laser_fdc_offs] = value; |
| 508 | state->laser_fdc_offs = (state->laser_fdc_offs + 1) % TRKSIZE_FM; |
| 509 | state->laser_fdc_write++; |
| 510 | state->laser_fdc_bits = 8; |
| 519 | 511 | } |
| 520 | 512 | } |
| 521 | 513 | } |
| 522 | 514 | /* change of write signal? */ |
| 523 | | if( (laser_fdc_latch ^ data) & 0x40 ) |
| 515 | if( (state->laser_fdc_latch ^ data) & 0x40 ) |
| 524 | 516 | { |
| 525 | 517 | /* falling edge? */ |
| 526 | | if ( laser_fdc_latch & 0x40 ) |
| 518 | if ( state->laser_fdc_latch & 0x40 ) |
| 527 | 519 | { |
| 528 | | sprintf(laser_frame_message, "#%d put track %02d", laser_drive, laser_track_x2[laser_drive]/2); |
| 529 | | laser_frame_time = 30; |
| 530 | | laser_fdc_start = laser_fdc_offs; |
| 531 | | laser_fdc_edge = 0; |
| 520 | sprintf(state->laser_frame_message, "#%d put track %02d", state->laser_drive, state->laser_track_x2[state->laser_drive]/2); |
| 521 | state->laser_frame_time = 30; |
| 522 | state->laser_fdc_start = state->laser_fdc_offs; |
| 523 | state->laser_fdc_edge = 0; |
| 532 | 524 | } |
| 533 | 525 | else |
| 534 | 526 | { |
| 535 | 527 | /* data written to track before? */ |
| 536 | | if( laser_fdc_write ) |
| 528 | if( state->laser_fdc_write ) |
| 537 | 529 | laser_put_track(space->machine); |
| 538 | 530 | } |
| 539 | | laser_fdc_bits = 8; |
| 540 | | laser_fdc_write = 0; |
| 531 | state->laser_fdc_bits = 8; |
| 532 | state->laser_fdc_write = 0; |
| 541 | 533 | } |
| 542 | 534 | } |
| 543 | | laser_fdc_latch = data; |
| 535 | state->laser_fdc_latch = data; |
| 544 | 536 | break; |
| 545 | 537 | } |
| 546 | 538 | } |
src/mess/machine/wswan.c
| r9669 | r9670 | |
| 27 | 27 | static const char *const wswan_sram_str[] = { "none", "64Kbit SRAM", "256Kbit SRAM", "512Kbit SRAM", "1Mbit SRAM", "2Mbit SRAM", "1Kbit EEPROM", "16Kbit EEPROM", "8Kbit EEPROM", "Unknown" }; |
| 28 | 28 | static const int wswan_sram_size[] = { 0, 64*1024/8, 256*1024/8, 512*1024/8, 1024*1024/8, 2*1024*1024/8, 1024/8, 16*1024/8, 8*1024/8, 0 }; |
| 29 | 29 | |
| 30 | | typedef struct { |
| 31 | | UINT8 mode; /* eeprom mode */ |
| 32 | | UINT16 address; /* Read/write address */ |
| 33 | | UINT8 command; /* Commands: 00, 01, 02, 03, 04, 08, 0C */ |
| 34 | | UINT8 start; /* start bit */ |
| 35 | | UINT8 write_enabled; /* write enabled yes/no */ |
| 36 | | int size; /* size of eeprom/sram area */ |
| 37 | | UINT8 *data; /* pointer to start of sram/eeprom data */ |
| 38 | | UINT8 *page; /* pointer to current sram/eeprom page */ |
| 39 | | } EEPROM; |
| 40 | | |
| 41 | | typedef struct { |
| 42 | | UINT8 present; /* Is an RTC present */ |
| 43 | | UINT8 setting; /* Timer setting byte */ |
| 44 | | UINT8 year; /* Year */ |
| 45 | | UINT8 month; /* Month */ |
| 46 | | UINT8 day; /* Day */ |
| 47 | | UINT8 day_of_week; /* Day of the week */ |
| 48 | | UINT8 hour; /* Hour, high bit = 0 => AM, high bit = 1 => PM */ |
| 49 | | UINT8 minute; /* Minute */ |
| 50 | | UINT8 second; /* Second */ |
| 51 | | UINT8 index; /* index for reading/writing of current of alarm time */ |
| 52 | | } RTC; |
| 53 | | |
| 54 | | typedef struct { |
| 55 | | UINT32 source; /* Source address */ |
| 56 | | UINT16 size; /* Size */ |
| 57 | | UINT8 enable; /* Enabled */ |
| 58 | | } SoundDMA; |
| 59 | | |
| 60 | 30 | static TIMER_CALLBACK(wswan_scanline_interrupt); |
| 61 | 31 | |
| 62 | 32 | |
| 63 | | static UINT8 *ROMMap[256]; |
| 64 | | static UINT32 ROMBanks; |
| 65 | | static UINT8 internal_eeprom[INTERNAL_EEPROM_SIZE]; |
| 66 | | static UINT8 system_type; |
| 67 | | VDP wswan_vdp; |
| 68 | | static EEPROM eeprom; |
| 69 | | static RTC rtc; |
| 70 | | static SoundDMA sound_dma; |
| 71 | | static UINT8 *ws_ram; |
| 72 | | static UINT8 *ws_bios_bank; |
| 73 | | static UINT8 wswan_bios_disabled; |
| 74 | | UINT8 ws_portram[256]; |
| 75 | 33 | static const UINT8 ws_portram_init[256] = |
| 76 | 34 | { |
| 77 | 35 | 0x00, 0x00, 0x00/*?*/, 0xbb, 0x00, 0x00, 0x00, 0x26, 0xfe, 0xde, 0xf9, 0xfb, 0xdb, 0xd7, 0x7f, 0xf5, |
| r9669 | r9670 | |
| 130 | 88 | |
| 131 | 89 | static void wswan_handle_irqs( running_machine *machine ) |
| 132 | 90 | { |
| 133 | | if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_HBLTMR ) { |
| 134 | | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_HBLTMR ); |
| 135 | | } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_VBL ) { |
| 136 | | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_VBL ); |
| 137 | | } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_VBLTMR ) { |
| 138 | | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_VBLTMR ); |
| 139 | | } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_LCMP ) { |
| 140 | | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_LCMP ); |
| 141 | | } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_SRX ) { |
| 142 | | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_SRX ); |
| 143 | | } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_RTC ) { |
| 144 | | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_RTC ); |
| 145 | | } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_KEY ) { |
| 146 | | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_KEY ); |
| 147 | | } else if ( ws_portram[0xb2] & ws_portram[0xb6] & WSWAN_IFLAG_STX ) { |
| 148 | | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, ws_portram[0xb0] + WSWAN_INT_STX ); |
| 91 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 92 | if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_HBLTMR ) { |
| 93 | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_HBLTMR ); |
| 94 | } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_VBL ) { |
| 95 | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_VBL ); |
| 96 | } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_VBLTMR ) { |
| 97 | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_VBLTMR ); |
| 98 | } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_LCMP ) { |
| 99 | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_LCMP ); |
| 100 | } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_SRX ) { |
| 101 | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_SRX ); |
| 102 | } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_RTC ) { |
| 103 | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_RTC ); |
| 104 | } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_KEY ) { |
| 105 | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_KEY ); |
| 106 | } else if ( state->ws_portram[0xb2] & state->ws_portram[0xb6] & WSWAN_IFLAG_STX ) { |
| 107 | cputag_set_input_line_and_vector( machine, "maincpu", 0, HOLD_LINE, state->ws_portram[0xb0] + WSWAN_INT_STX ); |
| 149 | 108 | } else { |
| 150 | 109 | cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE ); |
| 151 | 110 | } |
| r9669 | r9670 | |
| 153 | 112 | |
| 154 | 113 | static void wswan_set_irq_line( running_machine *machine, int irq) |
| 155 | 114 | { |
| 156 | | if ( ws_portram[0xb2] & irq ) |
| 115 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 116 | if ( state->ws_portram[0xb2] & irq ) |
| 157 | 117 | { |
| 158 | | ws_portram[0xb6] |= irq; |
| 118 | state->ws_portram[0xb6] |= irq; |
| 159 | 119 | wswan_handle_irqs( machine ); |
| 160 | 120 | } |
| 161 | 121 | } |
| 162 | 122 | |
| 163 | 123 | static void wswan_clear_irq_line( running_machine *machine, int irq) |
| 164 | 124 | { |
| 165 | | ws_portram[0xb6] &= ~irq; |
| 125 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 126 | state->ws_portram[0xb6] &= ~irq; |
| 166 | 127 | wswan_handle_irqs( machine ); |
| 167 | 128 | } |
| 168 | 129 | |
| 169 | 130 | static TIMER_CALLBACK(wswan_rtc_callback) |
| 170 | 131 | { |
| 132 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 171 | 133 | /* A second passed */ |
| 172 | | rtc.second = rtc.second + 1; |
| 173 | | if ( ( rtc.second & 0x0F ) > 9 ) |
| 134 | state->rtc.second = state->rtc.second + 1; |
| 135 | if ( ( state->rtc.second & 0x0F ) > 9 ) |
| 174 | 136 | { |
| 175 | | rtc.second = ( rtc.second & 0xF0 ) + 0x10; |
| 137 | state->rtc.second = ( state->rtc.second & 0xF0 ) + 0x10; |
| 176 | 138 | } |
| 177 | 139 | |
| 178 | 140 | /* Check for minute passed */ |
| 179 | | if ( rtc.second >= 0x60 ) |
| 141 | if ( state->rtc.second >= 0x60 ) |
| 180 | 142 | { |
| 181 | | rtc.second = 0; |
| 182 | | rtc.minute = rtc.minute + 1; |
| 183 | | if ( ( rtc.minute & 0x0F ) > 9 ) |
| 143 | state->rtc.second = 0; |
| 144 | state->rtc.minute = state->rtc.minute + 1; |
| 145 | if ( ( state->rtc.minute & 0x0F ) > 9 ) |
| 184 | 146 | { |
| 185 | | rtc.minute = ( rtc.minute & 0xF0 ) + 0x10; |
| 147 | state->rtc.minute = ( state->rtc.minute & 0xF0 ) + 0x10; |
| 186 | 148 | } |
| 187 | 149 | } |
| 188 | 150 | |
| 189 | 151 | /* Check for hour passed */ |
| 190 | | if ( rtc.minute >= 0x60 ) |
| 152 | if ( state->rtc.minute >= 0x60 ) |
| 191 | 153 | { |
| 192 | | rtc.minute = 0; |
| 193 | | rtc.hour = rtc.hour + 1; |
| 194 | | if ( ( rtc.hour & 0x0F ) > 9 ) |
| 154 | state->rtc.minute = 0; |
| 155 | state->rtc.hour = state->rtc.hour + 1; |
| 156 | if ( ( state->rtc.hour & 0x0F ) > 9 ) |
| 195 | 157 | { |
| 196 | | rtc.hour = ( rtc.hour & 0xF0 ) + 0x10; |
| 158 | state->rtc.hour = ( state->rtc.hour & 0xF0 ) + 0x10; |
| 197 | 159 | } |
| 198 | | if ( rtc.hour == 0x12 ) |
| 160 | if ( state->rtc.hour == 0x12 ) |
| 199 | 161 | { |
| 200 | | rtc.hour |= 0x80; |
| 162 | state->rtc.hour |= 0x80; |
| 201 | 163 | } |
| 202 | 164 | } |
| 203 | 165 | |
| 204 | 166 | /* Check for day passed */ |
| 205 | | if ( rtc.hour >= 0x24 ) |
| 167 | if ( state->rtc.hour >= 0x24 ) |
| 206 | 168 | { |
| 207 | | rtc.hour = 0; |
| 208 | | rtc.day = rtc.day + 1; |
| 169 | state->rtc.hour = 0; |
| 170 | state->rtc.day = state->rtc.day + 1; |
| 209 | 171 | } |
| 210 | 172 | } |
| 211 | 173 | |
| 212 | 174 | static void wswan_machine_stop( running_machine &machine ) |
| 213 | 175 | { |
| 176 | wswan_state *state = machine.driver_data<wswan_state>(); |
| 214 | 177 | device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart")); |
| 215 | | if ( eeprom.size ) |
| 178 | if ( state->eeprom.size ) |
| 216 | 179 | { |
| 217 | | image->battery_save(eeprom.data, eeprom.size ); |
| 180 | image->battery_save(state->eeprom.data, state->eeprom.size ); |
| 218 | 181 | } |
| 219 | 182 | } |
| 220 | 183 | |
| 221 | 184 | static void wswan_setup_bios( running_machine *machine ) |
| 222 | 185 | { |
| 223 | | if ( ws_bios_bank == NULL ) |
| 186 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 187 | if ( state->ws_bios_bank == NULL ) |
| 224 | 188 | { |
| 225 | | ws_bios_bank = auto_alloc_array(machine, UINT8, 0x10000 ); |
| 226 | | memcpy( ws_bios_bank + 0xffc0, ws_fake_bios_code, 0x40 ); |
| 189 | state->ws_bios_bank = auto_alloc_array(machine, UINT8, 0x10000 ); |
| 190 | memcpy( state->ws_bios_bank + 0xffc0, ws_fake_bios_code, 0x40 ); |
| 227 | 191 | } |
| 228 | 192 | } |
| 229 | 193 | |
| 230 | 194 | MACHINE_START( wswan ) |
| 231 | 195 | { |
| 232 | | ws_bios_bank = NULL; |
| 233 | | system_type = TYPE_WSWAN; |
| 196 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 197 | state->ws_bios_bank = NULL; |
| 198 | state->system_type = TYPE_WSWAN; |
| 234 | 199 | machine->add_notifier(MACHINE_NOTIFY_EXIT, wswan_machine_stop ); |
| 235 | | wswan_vdp.timer = timer_alloc( machine, wswan_scanline_interrupt, &wswan_vdp ); |
| 236 | | timer_adjust_periodic( wswan_vdp.timer, ticks_to_attotime( 256, 3072000 ), 0, ticks_to_attotime( 256, 3072000 ) ); |
| 200 | state->vdp.timer = timer_alloc( machine, wswan_scanline_interrupt, &state->vdp ); |
| 201 | timer_adjust_periodic( state->vdp.timer, ticks_to_attotime( 256, 3072000 ), 0, ticks_to_attotime( 256, 3072000 ) ); |
| 237 | 202 | |
| 238 | 203 | wswan_setup_bios(machine); |
| 239 | 204 | |
| 240 | 205 | /* Set up RTC timer */ |
| 241 | | if ( rtc.present ) |
| 206 | if ( state->rtc.present ) |
| 242 | 207 | timer_pulse(machine, ATTOTIME_IN_SEC(1), NULL, 0, wswan_rtc_callback ); |
| 243 | 208 | } |
| 244 | 209 | |
| 245 | 210 | MACHINE_START( wscolor ) |
| 246 | 211 | { |
| 247 | | ws_bios_bank = NULL; |
| 248 | | system_type = TYPE_WSC; |
| 212 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 213 | state->ws_bios_bank = NULL; |
| 214 | state->system_type = TYPE_WSC; |
| 249 | 215 | machine->add_notifier(MACHINE_NOTIFY_EXIT, wswan_machine_stop ); |
| 250 | | wswan_vdp.timer = timer_alloc( machine, wswan_scanline_interrupt, &wswan_vdp ); |
| 251 | | timer_adjust_periodic( wswan_vdp.timer, ticks_to_attotime( 256, 3072000 ), 0, ticks_to_attotime( 256, 3072000 ) ); |
| 216 | state->vdp.timer = timer_alloc( machine, wswan_scanline_interrupt, &state->vdp ); |
| 217 | timer_adjust_periodic( state->vdp.timer, ticks_to_attotime( 256, 3072000 ), 0, ticks_to_attotime( 256, 3072000 ) ); |
| 252 | 218 | |
| 253 | 219 | wswan_setup_bios(machine); |
| 254 | 220 | |
| 255 | 221 | /* Set up RTC timer */ |
| 256 | | if ( rtc.present ) |
| 222 | if ( state->rtc.present ) |
| 257 | 223 | timer_pulse(machine, ATTOTIME_IN_SEC(1), NULL, 0, wswan_rtc_callback ); |
| 258 | 224 | } |
| 259 | 225 | |
| 260 | 226 | MACHINE_RESET( wswan ) |
| 261 | 227 | { |
| 228 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 262 | 229 | address_space *space = cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ); |
| 263 | 230 | |
| 264 | 231 | /* Intialize ports */ |
| 265 | | memcpy( ws_portram, ws_portram_init, 256 ); |
| 232 | memcpy( state->ws_portram, ws_portram_init, 256 ); |
| 266 | 233 | |
| 267 | 234 | /* Initialize VDP */ |
| 268 | | memset( &wswan_vdp, 0, sizeof( wswan_vdp ) ); |
| 235 | memset( &state->vdp, 0, sizeof( state->vdp ) ); |
| 269 | 236 | |
| 270 | | wswan_vdp.vram = (UINT8*)space->get_read_ptr(0); |
| 271 | | wswan_vdp.palette_vram = (UINT8*)space->get_read_ptr(( system_type == TYPE_WSC ) ? 0xFE00 : 0 ); |
| 272 | | wswan_vdp.current_line = 145; /* Randomly chosen, beginning of VBlank period to give cart some time to boot up */ |
| 273 | | wswan_vdp.new_display_vertical = ROMMap[ROMBanks-1][0xfffc] & 0x01; |
| 274 | | wswan_vdp.display_vertical = ~wswan_vdp.new_display_vertical; |
| 275 | | wswan_vdp.color_mode = 0; |
| 276 | | wswan_vdp.colors_16 = 0; |
| 277 | | wswan_vdp.tile_packed = 0; |
| 237 | state->vdp.vram = (UINT8*)space->get_read_ptr(0); |
| 238 | state->vdp.palette_vram = (UINT8*)space->get_read_ptr(( state->system_type == TYPE_WSC ) ? 0xFE00 : 0 ); |
| 239 | state->vdp.current_line = 145; /* Randomly chosen, beginning of VBlank period to give cart some time to boot up */ |
| 240 | state->vdp.new_display_vertical = state->ROMMap[state->ROMBanks-1][0xfffc] & 0x01; |
| 241 | state->vdp.display_vertical = ~state->vdp.new_display_vertical; |
| 242 | state->vdp.color_mode = 0; |
| 243 | state->vdp.colors_16 = 0; |
| 244 | state->vdp.tile_packed = 0; |
| 278 | 245 | |
| 279 | 246 | /* Initialize sound DMA */ |
| 280 | | memset( &sound_dma, 0, sizeof( sound_dma ) ); |
| 247 | memset( &state->sound_dma, 0, sizeof( state->sound_dma ) ); |
| 281 | 248 | |
| 282 | 249 | /* Switch in the banks */ |
| 283 | | memory_set_bankptr( machine, "bank2", ROMMap[(ROMBanks - 1) & (ROMBanks - 1)] ); |
| 284 | | memory_set_bankptr( machine, "bank3", ROMMap[(ROMBanks - 1) & (ROMBanks - 1)] ); |
| 285 | | memory_set_bankptr( machine, "bank4", ROMMap[(ROMBanks - 12) & (ROMBanks - 1)] ); |
| 286 | | memory_set_bankptr( machine, "bank5", ROMMap[(ROMBanks - 11) & (ROMBanks - 1)] ); |
| 287 | | memory_set_bankptr( machine, "bank6", ROMMap[(ROMBanks - 10) & (ROMBanks - 1)] ); |
| 288 | | memory_set_bankptr( machine, "bank7", ROMMap[(ROMBanks - 9) & (ROMBanks - 1)] ); |
| 289 | | memory_set_bankptr( machine, "bank8", ROMMap[(ROMBanks - 8) & (ROMBanks - 1)] ); |
| 290 | | memory_set_bankptr( machine, "bank9", ROMMap[(ROMBanks - 7) & (ROMBanks - 1)] ); |
| 291 | | memory_set_bankptr( machine, "bank10", ROMMap[(ROMBanks - 6) & (ROMBanks - 1)] ); |
| 292 | | memory_set_bankptr( machine, "bank11", ROMMap[(ROMBanks - 5) & (ROMBanks - 1)] ); |
| 293 | | memory_set_bankptr( machine, "bank12", ROMMap[(ROMBanks - 4) & (ROMBanks - 1)] ); |
| 294 | | memory_set_bankptr( machine, "bank13", ROMMap[(ROMBanks - 3) & (ROMBanks - 1)] ); |
| 295 | | memory_set_bankptr( machine, "bank14", ROMMap[(ROMBanks - 2) & (ROMBanks - 1)] ); |
| 296 | | wswan_bios_disabled = 0; |
| 297 | | memory_set_bankptr( machine, "bank15", ws_bios_bank ); |
| 298 | | // memory_set_bankptr( machine, 15, ROMMap[(ROMBanks - 1) & (ROMBanks - 1)] ); |
| 250 | memory_set_bankptr( machine, "bank2", state->ROMMap[(state->ROMBanks - 1) & (state->ROMBanks - 1)] ); |
| 251 | memory_set_bankptr( machine, "bank3", state->ROMMap[(state->ROMBanks - 1) & (state->ROMBanks - 1)] ); |
| 252 | memory_set_bankptr( machine, "bank4", state->ROMMap[(state->ROMBanks - 12) & (state->ROMBanks - 1)] ); |
| 253 | memory_set_bankptr( machine, "bank5", state->ROMMap[(state->ROMBanks - 11) & (state->ROMBanks - 1)] ); |
| 254 | memory_set_bankptr( machine, "bank6", state->ROMMap[(state->ROMBanks - 10) & (state->ROMBanks - 1)] ); |
| 255 | memory_set_bankptr( machine, "bank7", state->ROMMap[(state->ROMBanks - 9) & (state->ROMBanks - 1)] ); |
| 256 | memory_set_bankptr( machine, "bank8", state->ROMMap[(state->ROMBanks - 8) & (state->ROMBanks - 1)] ); |
| 257 | memory_set_bankptr( machine, "bank9", state->ROMMap[(state->ROMBanks - 7) & (state->ROMBanks - 1)] ); |
| 258 | memory_set_bankptr( machine, "bank10", state->ROMMap[(state->ROMBanks - 6) & (state->ROMBanks - 1)] ); |
| 259 | memory_set_bankptr( machine, "bank11", state->ROMMap[(state->ROMBanks - 5) & (state->ROMBanks - 1)] ); |
| 260 | memory_set_bankptr( machine, "bank12", state->ROMMap[(state->ROMBanks - 4) & (state->ROMBanks - 1)] ); |
| 261 | memory_set_bankptr( machine, "bank13", state->ROMMap[(state->ROMBanks - 3) & (state->ROMBanks - 1)] ); |
| 262 | memory_set_bankptr( machine, "bank14", state->ROMMap[(state->ROMBanks - 2) & (state->ROMBanks - 1)] ); |
| 263 | state->bios_disabled = 0; |
| 264 | memory_set_bankptr( machine, "bank15", state->ws_bios_bank ); |
| 265 | // memory_set_bankptr( machine, 15, state->ROMMap[(state->ROMBanks - 1) & (state->ROMBanks - 1)] ); |
| 299 | 266 | } |
| 300 | 267 | |
| 301 | 268 | NVRAM_HANDLER( wswan ) |
| 302 | 269 | { |
| 270 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 303 | 271 | if ( read_or_write ) |
| 304 | 272 | { |
| 305 | 273 | /* Save the EEPROM data */ |
| 306 | | mame_fwrite( file, internal_eeprom, INTERNAL_EEPROM_SIZE ); |
| 274 | mame_fwrite( file, state->internal_eeprom, INTERNAL_EEPROM_SIZE ); |
| 307 | 275 | } |
| 308 | 276 | else |
| 309 | 277 | { |
| 310 | 278 | /* Load the EEPROM data */ |
| 311 | 279 | if ( file ) |
| 312 | 280 | { |
| 313 | | mame_fread( file, internal_eeprom, INTERNAL_EEPROM_SIZE ); |
| 281 | mame_fread( file, state->internal_eeprom, INTERNAL_EEPROM_SIZE ); |
| 314 | 282 | } |
| 315 | 283 | else |
| 316 | 284 | { |
| 317 | 285 | /* Initialize the EEPROM data */ |
| 318 | | memset( internal_eeprom, 0xFF, sizeof( internal_eeprom ) ); |
| 286 | memset( state->internal_eeprom, 0xFF, sizeof( state->internal_eeprom ) ); |
| 319 | 287 | } |
| 320 | 288 | } |
| 321 | 289 | } |
| 322 | 290 | |
| 323 | 291 | READ8_HANDLER( wswan_sram_r ) |
| 324 | 292 | { |
| 325 | | if ( eeprom.data == NULL ) |
| 293 | wswan_state *state = space->machine->driver_data<wswan_state>(); |
| 294 | if ( state->eeprom.data == NULL ) |
| 326 | 295 | { |
| 327 | 296 | return 0xFF; |
| 328 | 297 | } |
| 329 | | return eeprom.page[ offset & ( eeprom.size - 1 ) ]; |
| 298 | return state->eeprom.page[ offset & ( state->eeprom.size - 1 ) ]; |
| 330 | 299 | } |
| 331 | 300 | |
| 332 | 301 | WRITE8_HANDLER( wswan_sram_w ) |
| 333 | 302 | { |
| 334 | | if ( eeprom.data == NULL ) |
| 303 | wswan_state *state = space->machine->driver_data<wswan_state>(); |
| 304 | if ( state->eeprom.data == NULL ) |
| 335 | 305 | { |
| 336 | 306 | return; |
| 337 | 307 | } |
| 338 | | eeprom.page[ offset & ( eeprom.size - 1 ) ] = data; |
| 308 | state->eeprom.page[ offset & ( state->eeprom.size - 1 ) ] = data; |
| 339 | 309 | } |
| 340 | 310 | |
| 341 | 311 | READ8_HANDLER( wswan_port_r ) |
| 342 | 312 | { |
| 343 | | UINT8 value = ws_portram[offset]; |
| 313 | wswan_state *state = space->machine->driver_data<wswan_state>(); |
| 314 | UINT8 value = state->ws_portram[offset]; |
| 344 | 315 | |
| 345 | 316 | if ( offset != 2 ) |
| 346 | 317 | logerror( "PC=%X: port read %02X\n", cpu_get_pc( space->cpu ), offset ); |
| 347 | 318 | switch( offset ) |
| 348 | 319 | { |
| 349 | 320 | case 0x02: /* Current line */ |
| 350 | | value = wswan_vdp.current_line; |
| 321 | value = state->vdp.current_line; |
| 351 | 322 | break; |
| 352 | 323 | case 0x4A: /* Sound DMA source address (low) */ |
| 353 | | value = sound_dma.source & 0xFF; |
| 324 | value = state->sound_dma.source & 0xFF; |
| 354 | 325 | break; |
| 355 | 326 | case 0x4B: /* Sound DMA source address (high) */ |
| 356 | | value = ( sound_dma.source >> 8 ) & 0xFF; |
| 327 | value = ( state->sound_dma.source >> 8 ) & 0xFF; |
| 357 | 328 | break; |
| 358 | 329 | case 0x4C: /* Sound DMA source memory segment */ |
| 359 | | value = ( sound_dma.source >> 16 ) & 0xFF; |
| 330 | value = ( state->sound_dma.source >> 16 ) & 0xFF; |
| 360 | 331 | break; |
| 361 | 332 | case 0x4E: /* Sound DMA transfer size (low) */ |
| 362 | | value = sound_dma.size & 0xFF; |
| 333 | value = state->sound_dma.size & 0xFF; |
| 363 | 334 | break; |
| 364 | 335 | case 0x4F: /* Sound DMA transfer size (high) */ |
| 365 | | value = ( sound_dma.size >> 8 ) & 0xFF; |
| 336 | value = ( state->sound_dma.size >> 8 ) & 0xFF; |
| 366 | 337 | break; |
| 367 | 338 | case 0x52: /* Sound DMA start/stop */ |
| 368 | | value = sound_dma.enable; |
| 339 | value = state->sound_dma.enable; |
| 369 | 340 | break; |
| 370 | 341 | case 0xA0: /* Hardware type */ |
| 371 | 342 | /* Bit 0 - Disable/enable Bios */ |
| 372 | 343 | /* Bit 1 - Determine mono/color */ |
| 373 | 344 | /* Bit 2 - Determine color/crystal */ |
| 374 | 345 | value = value & ~ 0x02; |
| 375 | | if ( system_type == TYPE_WSC ) |
| 346 | if ( state->system_type == TYPE_WSC ) |
| 376 | 347 | { |
| 377 | 348 | value |= 2; |
| 378 | 349 | } |
| 379 | 350 | break; |
| 380 | 351 | case 0xA8: |
| 381 | | value = wswan_vdp.timer_hblank_count & 0xFF; |
| 352 | value = state->vdp.timer_hblank_count & 0xFF; |
| 382 | 353 | break; |
| 383 | 354 | case 0xA9: |
| 384 | | value = wswan_vdp.timer_hblank_count >> 8; |
| 355 | value = state->vdp.timer_hblank_count >> 8; |
| 385 | 356 | break; |
| 386 | 357 | case 0xAA: |
| 387 | | value = wswan_vdp.timer_vblank_count & 0xFF; |
| 358 | value = state->vdp.timer_vblank_count & 0xFF; |
| 388 | 359 | break; |
| 389 | 360 | case 0xAB: |
| 390 | | value = wswan_vdp.timer_vblank_count >> 8; |
| 361 | value = state->vdp.timer_vblank_count >> 8; |
| 391 | 362 | break; |
| 392 | 363 | case 0xCB: /* RTC data */ |
| 393 | | if ( ws_portram[0xca] == 0x95 && ( rtc.index < 7 ) ) |
| 364 | if ( state->ws_portram[0xca] == 0x95 && ( state->rtc.index < 7 ) ) |
| 394 | 365 | { |
| 395 | | switch( rtc.index ) |
| 366 | switch( state->rtc.index ) |
| 396 | 367 | { |
| 397 | | case 0: value = rtc.year; break; |
| 398 | | case 1: value = rtc.month; break; |
| 399 | | case 2: value = rtc.day; break; |
| 400 | | case 3: value = rtc.day_of_week; break; |
| 401 | | case 4: value = rtc.hour; break; |
| 402 | | case 5: value = rtc.minute; break; |
| 403 | | case 6: value = rtc.second; break; |
| 368 | case 0: value = state->rtc.year; break; |
| 369 | case 1: value = state->rtc.month; break; |
| 370 | case 2: value = state->rtc.day; break; |
| 371 | case 3: value = state->rtc.day_of_week; break; |
| 372 | case 4: value = state->rtc.hour; break; |
| 373 | case 5: value = state->rtc.minute; break; |
| 374 | case 6: value = state->rtc.second; break; |
| 404 | 375 | } |
| 405 | | rtc.index++; |
| 376 | state->rtc.index++; |
| 406 | 377 | } |
| 407 | 378 | } |
| 408 | 379 | |
| r9669 | r9670 | |
| 411 | 382 | |
| 412 | 383 | WRITE8_HANDLER( wswan_port_w ) |
| 413 | 384 | { |
| 385 | wswan_state *state = space->machine->driver_data<wswan_state>(); |
| 414 | 386 | logerror( "PC=%X: port write %02X <- %02X\n", cpu_get_pc( space->cpu ), offset, data ); |
| 415 | 387 | switch( offset ) |
| 416 | 388 | { |
| r9669 | r9670 | |
| 426 | 398 | 11 - Foreground layer is displayed outside foreground window area |
| 427 | 399 | Bit 6-7 - Unknown |
| 428 | 400 | */ |
| 429 | | wswan_vdp.layer_bg_enable = data & 0x1; |
| 430 | | wswan_vdp.layer_fg_enable = (data & 0x2) >> 1; |
| 431 | | wswan_vdp.sprites_enable = (data & 0x4) >> 2; |
| 432 | | wswan_vdp.window_sprites_enable = (data & 0x8) >> 3; |
| 433 | | wswan_vdp.window_fg_mode = (data & 0x30) >> 4; |
| 401 | state->vdp.layer_bg_enable = data & 0x1; |
| 402 | state->vdp.layer_fg_enable = (data & 0x2) >> 1; |
| 403 | state->vdp.sprites_enable = (data & 0x4) >> 2; |
| 404 | state->vdp.window_sprites_enable = (data & 0x8) >> 3; |
| 405 | state->vdp.window_fg_mode = (data & 0x30) >> 4; |
| 434 | 406 | break; |
| 435 | 407 | case 0x01: /* Background colour |
| 436 | 408 | In 16 colour mode: |
| r9669 | r9670 | |
| 444 | 416 | case 0x02: /* Current scanline |
| 445 | 417 | Bit 0-7 - Current scanline (Most likely read-only) |
| 446 | 418 | */ |
| 447 | | logerror( "Write to current scanline! Current value: %d Data to write: %d\n", wswan_vdp.current_line, data ); |
| 419 | logerror( "Write to current scanline! Current value: %d Data to write: %d\n", state->vdp.current_line, data ); |
| 448 | 420 | /* Returning so we don't overwrite the value here, not that it |
| 449 | 421 | * really matters */ |
| 450 | 422 | return; |
| 451 | 423 | case 0x03: /* Line compare |
| 452 | 424 | Bit 0-7 - Line compare |
| 453 | 425 | */ |
| 454 | | wswan_vdp.line_compare = data; |
| 426 | state->vdp.line_compare = data; |
| 455 | 427 | break; |
| 456 | 428 | case 0x04: /* Sprite table base address |
| 457 | 429 | Bit 0-5 - Determine sprite table base address 0 0xxxxxx0 00000000 |
| 458 | 430 | Bit 6-7 - Unknown |
| 459 | 431 | */ |
| 460 | | wswan_vdp.sprite_table_address = ( data & 0x3F ) << 9; |
| 432 | state->vdp.sprite_table_address = ( data & 0x3F ) << 9; |
| 461 | 433 | break; |
| 462 | 434 | case 0x05: /* Number of sprite to start drawing with |
| 463 | 435 | Bit 0-7 - First sprite number |
| 464 | 436 | */ |
| 465 | | wswan_vdp.sprite_first = data; |
| 437 | state->vdp.sprite_first = data; |
| 466 | 438 | break; |
| 467 | 439 | case 0x06: /* Number of sprites to draw |
| 468 | 440 | Bit 0-7 - Number of sprites to draw |
| 469 | 441 | */ |
| 470 | | wswan_vdp.sprite_count = data; |
| 442 | state->vdp.sprite_count = data; |
| 471 | 443 | break; |
| 472 | 444 | case 0x07: /* Background/Foreground table base addresses |
| 473 | 445 | Bit 0-2 - Determine background table base address 00xxx000 00000000 |
| r9669 | r9670 | |
| 475 | 447 | Bit 4-6 - Determine foreground table base address 00xxx000 00000000 |
| 476 | 448 | Bit 7 - Unknown |
| 477 | 449 | */ |
| 478 | | wswan_vdp.layer_bg_address = (data & 0x7) << 11; |
| 479 | | wswan_vdp.layer_fg_address = (data & 0x70) << 7; |
| 450 | state->vdp.layer_bg_address = (data & 0x7) << 11; |
| 451 | state->vdp.layer_fg_address = (data & 0x70) << 7; |
| 480 | 452 | break; |
| 481 | 453 | case 0x08: /* Left coordinate of foreground window |
| 482 | 454 | Bit 0-7 - Left coordinate of foreground window area |
| 483 | 455 | */ |
| 484 | | wswan_vdp.window_fg_left = data; |
| 456 | state->vdp.window_fg_left = data; |
| 485 | 457 | break; |
| 486 | 458 | case 0x09: /* Top coordinate of foreground window |
| 487 | 459 | Bit 0-7 - Top coordinatte of foreground window area |
| 488 | 460 | */ |
| 489 | | wswan_vdp.window_fg_top = data; |
| 461 | state->vdp.window_fg_top = data; |
| 490 | 462 | break; |
| 491 | 463 | case 0x0A: /* Right coordinate of foreground window |
| 492 | 464 | Bit 0-7 - Right coordinate of foreground window area |
| 493 | 465 | */ |
| 494 | | wswan_vdp.window_fg_right = data; |
| 466 | state->vdp.window_fg_right = data; |
| 495 | 467 | break; |
| 496 | 468 | case 0x0B: /* Bottom coordinate of foreground window |
| 497 | 469 | Bit 0-7 - Bottom coordinate of foreground window area |
| 498 | 470 | */ |
| 499 | | wswan_vdp.window_fg_bottom = data; |
| 471 | state->vdp.window_fg_bottom = data; |
| 500 | 472 | break; |
| 501 | 473 | case 0x0C: /* Left coordinate of sprite window |
| 502 | 474 | Bit 0-7 - Left coordinate of sprite window area |
| 503 | 475 | */ |
| 504 | | wswan_vdp.window_sprites_left = data; |
| 476 | state->vdp.window_sprites_left = data; |
| 505 | 477 | break; |
| 506 | 478 | case 0x0D: /* Top coordinate of sprite window |
| 507 | 479 | Bit 0-7 - Top coordinate of sprite window area |
| 508 | 480 | */ |
| 509 | | wswan_vdp.window_sprites_top = data; |
| 481 | state->vdp.window_sprites_top = data; |
| 510 | 482 | break; |
| 511 | 483 | case 0x0E: /* Right coordinate of sprite window |
| 512 | 484 | Bit 0-7 - Right coordinate of sprite window area |
| 513 | 485 | */ |
| 514 | | wswan_vdp.window_sprites_right = data; |
| 486 | state->vdp.window_sprites_right = data; |
| 515 | 487 | break; |
| 516 | 488 | case 0x0F: /* Bottom coordinate of sprite window |
| 517 | 489 | Bit 0-7 - Bottom coordiante of sprite window area |
| 518 | 490 | */ |
| 519 | | wswan_vdp.window_sprites_bottom = data; |
| 491 | state->vdp.window_sprites_bottom = data; |
| 520 | 492 | break; |
| 521 | 493 | case 0x10: /* Background layer X scroll |
| 522 | 494 | Bit 0-7 - Background layer X scroll |
| 523 | 495 | */ |
| 524 | | wswan_vdp.layer_bg_scroll_x = data; |
| 496 | state->vdp.layer_bg_scroll_x = data; |
| 525 | 497 | break; |
| 526 | 498 | case 0x11: /* Background layer Y scroll |
| 527 | 499 | Bit 0-7 - Background layer Y scroll |
| 528 | 500 | */ |
| 529 | | wswan_vdp.layer_bg_scroll_y = data; |
| 501 | state->vdp.layer_bg_scroll_y = data; |
| 530 | 502 | break; |
| 531 | 503 | case 0x12: /* Foreground layer X scroll |
| 532 | 504 | Bit 0-7 - Foreground layer X scroll |
| 533 | 505 | */ |
| 534 | | wswan_vdp.layer_fg_scroll_x = data; |
| 506 | state->vdp.layer_fg_scroll_x = data; |
| 535 | 507 | break; |
| 536 | 508 | case 0x13: /* Foreground layer Y scroll |
| 537 | 509 | Bit 0-7 - Foreground layer Y scroll |
| 538 | 510 | */ |
| 539 | | wswan_vdp.layer_fg_scroll_y = data; |
| 511 | state->vdp.layer_fg_scroll_y = data; |
| 540 | 512 | break; |
| 541 | 513 | case 0x14: /* LCD control |
| 542 | 514 | Bit 0 - LCD enable |
| 543 | 515 | Bit 1-7 - Unknown |
| 544 | 516 | */ |
| 545 | | wswan_vdp.lcd_enable = data & 0x1; |
| 517 | state->vdp.lcd_enable = data & 0x1; |
| 546 | 518 | break; |
| 547 | 519 | case 0x15: /* LCD icons |
| 548 | 520 | Bit 0 - LCD sleep icon enable |
| r9669 | r9670 | |
| 553 | 525 | Bit 5 - Dot 3 icon enable |
| 554 | 526 | Bit 6-7 - Unknown |
| 555 | 527 | */ |
| 556 | | wswan_vdp.icons = data; /* ummmmm */ |
| 528 | state->vdp.icons = data; /* ummmmm */ |
| 557 | 529 | break; |
| 558 | 530 | case 0x1c: /* Palette colors 0 and 1 |
| 559 | 531 | Bit 0-3 - Gray tone setting for main palette index 0 |
| 560 | 532 | Bit 4-7 - Gray tone setting for main palette index 1 |
| 561 | 533 | */ |
| 562 | | if ( system_type == TYPE_WSC ) |
| 534 | if ( state->system_type == TYPE_WSC ) |
| 563 | 535 | { |
| 564 | 536 | int i = 15 - ( data & 0x0F ); |
| 565 | 537 | int j = 15 - ( ( data & 0xF0 ) >> 4 ); |
| 566 | | wswan_vdp.main_palette[0] = ( i << 8 ) | ( i << 4 ) | i; |
| 567 | | wswan_vdp.main_palette[1] = ( j << 8 ) | ( j << 4 ) | j; |
| 538 | state->vdp.main_palette[0] = ( i << 8 ) | ( i << 4 ) | i; |
| 539 | state->vdp.main_palette[1] = ( j << 8 ) | ( j << 4 ) | j; |
| 568 | 540 | } |
| 569 | 541 | else |
| 570 | 542 | { |
| 571 | | wswan_vdp.main_palette[0] = data & 0x0F; |
| 572 | | wswan_vdp.main_palette[1] = ( data & 0xF0 ) >> 4; |
| 543 | state->vdp.main_palette[0] = data & 0x0F; |
| 544 | state->vdp.main_palette[1] = ( data & 0xF0 ) >> 4; |
| 573 | 545 | } |
| 574 | 546 | break; |
| 575 | 547 | case 0x1d: /* Palette colors 2 and 3 |
| 576 | 548 | Bit 0-3 - Gray tone setting for main palette index 2 |
| 577 | 549 | Bit 4-7 - Gray tone setting for main palette index 3 |
| 578 | 550 | */ |
| 579 | | if ( system_type == TYPE_WSC ) |
| 551 | if ( state->system_type == TYPE_WSC ) |
| 580 | 552 | { |
| 581 | 553 | int i = 15 - ( data & 0x0F ); |
| 582 | 554 | int j = 15 - ( ( data & 0xF0 ) >> 4 ); |
| 583 | | wswan_vdp.main_palette[2] = ( i << 8 ) | ( i << 4 ) | i; |
| 584 | | wswan_vdp.main_palette[3] = ( j << 8 ) | ( j << 4 ) | j; |
| 555 | state->vdp.main_palette[2] = ( i << 8 ) | ( i << 4 ) | i; |
| 556 | state->vdp.main_palette[3] = ( j << 8 ) | ( j << 4 ) | j; |
| 585 | 557 | } |
| 586 | 558 | else |
| 587 | 559 | { |
| 588 | | wswan_vdp.main_palette[2] = data & 0x0F; |
| 589 | | wswan_vdp.main_palette[3] = ( data & 0xF0 ) >> 4; |
| 560 | state->vdp.main_palette[2] = data & 0x0F; |
| 561 | state->vdp.main_palette[3] = ( data & 0xF0 ) >> 4; |
| 590 | 562 | } |
| 591 | 563 | break; |
| 592 | 564 | case 0x1e: /* Palette colors 4 and 5 |
| 593 | 565 | Bit 0-3 - Gray tone setting for main palette index 4 |
| 594 | 566 | Bit 4-7 - Gray tone setting for main paeltte index 5 |
| 595 | 567 | */ |
| 596 | | if ( system_type == TYPE_WSC ) |
| 568 | if ( state->system_type == TYPE_WSC ) |
| 597 | 569 | { |
| 598 | 570 | int i = 15 - ( data & 0x0F ); |
| 599 | 571 | int j = 15 - ( ( data & 0xF0 ) >> 4 ); |
| 600 | | wswan_vdp.main_palette[4] = ( i << 8 ) | ( i << 4 ) | i; |
| 601 | | wswan_vdp.main_palette[5] = ( j << 8 ) | ( j << 4 ) | j; |
| 572 | state->vdp.main_palette[4] = ( i << 8 ) | ( i << 4 ) | i; |
| 573 | state->vdp.main_palette[5] = ( j << 8 ) | ( j << 4 ) | j; |
| 602 | 574 | } |
| 603 | 575 | else |
| 604 | 576 | { |
| 605 | | wswan_vdp.main_palette[4] = data & 0x0F; |
| 606 | | wswan_vdp.main_palette[5] = ( data & 0xF0 ) >> 4; |
| 577 | state->vdp.main_palette[4] = data & 0x0F; |
| 578 | state->vdp.main_palette[5] = ( data & 0xF0 ) >> 4; |
| 607 | 579 | } |
| 608 | 580 | break; |
| 609 | 581 | case 0x1f: /* Palette colors 6 and 7 |
| 610 | 582 | Bit 0-3 - Gray tone setting for main palette index 6 |
| 611 | 583 | Bit 4-7 - Gray tone setting for main palette index 7 |
| 612 | 584 | */ |
| 613 | | if ( system_type == TYPE_WSC ) |
| 585 | if ( state->system_type == TYPE_WSC ) |
| 614 | 586 | { |
| 615 | 587 | int i = 15 - ( data & 0x0F ); |
| 616 | 588 | int j = 15 - ( ( data & 0xF0 ) >> 4 ); |
| 617 | | wswan_vdp.main_palette[6] = ( i << 8 ) | ( i << 4 ) | i; |
| 618 | | wswan_vdp.main_palette[7] = ( j << 8 ) | ( j << 4 ) | j; |
| 589 | state->vdp.main_palette[6] = ( i << 8 ) | ( i << 4 ) | i; |
| 590 | state->vdp.main_palette[7] = ( j << 8 ) | ( j << 4 ) | j; |
| 619 | 591 | } |
| 620 | 592 | else |
| 621 | 593 | { |
| 622 | | wswan_vdp.main_palette[6] = data & 0x0F; |
| 623 | | wswan_vdp.main_palette[7] = ( data & 0xF0 ) >> 4; |
| 594 | state->vdp.main_palette[6] = data & 0x0F; |
| 595 | state->vdp.main_palette[7] = ( data & 0xF0 ) >> 4; |
| 624 | 596 | } |
| 625 | 597 | break; |
| 626 | 598 | case 0x20: /* tile/sprite palette settings |
| r9669 | r9670 | |
| 723 | 695 | UINT32 src, dst; |
| 724 | 696 | UINT16 length; |
| 725 | 697 | |
| 726 | | src = ws_portram[0x40] + (ws_portram[0x41] << 8) + (ws_portram[0x42] << 16); |
| 727 | | dst = ws_portram[0x44] + (ws_portram[0x45] << 8) + (ws_portram[0x43] << 16); |
| 728 | | length = ws_portram[0x46] + (ws_portram[0x47] << 8); |
| 698 | src = state->ws_portram[0x40] + (state->ws_portram[0x41] << 8) + (state->ws_portram[0x42] << 16); |
| 699 | dst = state->ws_portram[0x44] + (state->ws_portram[0x45] << 8) + (state->ws_portram[0x43] << 16); |
| 700 | length = state->ws_portram[0x46] + (state->ws_portram[0x47] << 8); |
| 729 | 701 | for( ; length > 0; length-- ) |
| 730 | 702 | { |
| 731 | 703 | space->write_byte(dst, space->read_byte(src ) ); |
| r9669 | r9670 | |
| 735 | 707 | #ifdef DEBUG |
| 736 | 708 | logerror( "DMA src:%X dst:%X length:%d\n", src, dst, length ); |
| 737 | 709 | #endif |
| 738 | | ws_portram[0x40] = src & 0xFF; |
| 739 | | ws_portram[0x41] = ( src >> 8 ) & 0xFF; |
| 740 | | ws_portram[0x44] = dst & 0xFF; |
| 741 | | ws_portram[0x45] = ( dst >> 8 ) & 0xFF; |
| 742 | | ws_portram[0x46] = length & 0xFF; |
| 743 | | ws_portram[0x47] = ( length >> 8 ) & 0xFF; |
| 710 | state->ws_portram[0x40] = src & 0xFF; |
| 711 | state->ws_portram[0x41] = ( src >> 8 ) & 0xFF; |
| 712 | state->ws_portram[0x44] = dst & 0xFF; |
| 713 | state->ws_portram[0x45] = ( dst >> 8 ) & 0xFF; |
| 714 | state->ws_portram[0x46] = length & 0xFF; |
| 715 | state->ws_portram[0x47] = ( length >> 8 ) & 0xFF; |
| 744 | 716 | data &= 0x7F; |
| 745 | 717 | } |
| 746 | 718 | break; |
| 747 | 719 | case 0x4A: /* Sound DMA source address (low) |
| 748 | 720 | Bit 0-7 - Sound DMA source address bit 0-7 |
| 749 | 721 | */ |
| 750 | | sound_dma.source = ( sound_dma.source & 0x0FFF00 ) | data; |
| 722 | state->sound_dma.source = ( state->sound_dma.source & 0x0FFF00 ) | data; |
| 751 | 723 | break; |
| 752 | 724 | case 0x4B: /* Sound DMA source address (high) |
| 753 | 725 | Bit 0-7 - Sound DMA source address bit 8-15 |
| 754 | 726 | */ |
| 755 | | sound_dma.source = ( sound_dma.source & 0x0F00FF ) | ( data << 8 ); |
| 727 | state->sound_dma.source = ( state->sound_dma.source & 0x0F00FF ) | ( data << 8 ); |
| 756 | 728 | break; |
| 757 | 729 | case 0x4C: /* Sound DMA source memory segment |
| 758 | 730 | Bit 0-3 - Sound DMA source address segment |
| 759 | 731 | Bit 4-7 - Unknown |
| 760 | 732 | */ |
| 761 | | sound_dma.source = ( sound_dma.source & 0xFFFF ) | ( ( data & 0x0F ) << 16 ); |
| 733 | state->sound_dma.source = ( state->sound_dma.source & 0xFFFF ) | ( ( data & 0x0F ) << 16 ); |
| 762 | 734 | break; |
| 763 | 735 | case 0x4D: /* Unknown */ |
| 764 | 736 | break; |
| 765 | 737 | case 0x4E: /* Sound DMA transfer size (low) |
| 766 | 738 | Bit 0-7 - Sound DMA transfer size bit 0-7 |
| 767 | 739 | */ |
| 768 | | sound_dma.size = ( sound_dma.size & 0xFF00 ) | data; |
| 740 | state->sound_dma.size = ( state->sound_dma.size & 0xFF00 ) | data; |
| 769 | 741 | break; |
| 770 | 742 | case 0x4F: /* Sound DMA transfer size (high) |
| 771 | 743 | Bit 0-7 - Sound DMA transfer size bit 8-15 |
| 772 | 744 | */ |
| 773 | | sound_dma.size = ( sound_dma.size & 0xFF ) | ( data << 8 ); |
| 745 | state->sound_dma.size = ( state->sound_dma.size & 0xFF ) | ( data << 8 ); |
| 774 | 746 | break; |
| 775 | 747 | case 0x50: /* Unknown */ |
| 776 | 748 | case 0x51: /* Unknown */ |
| r9669 | r9670 | |
| 779 | 751 | Bit 0-6 - Unknown |
| 780 | 752 | Bit 7 - Sound DMA stop/start |
| 781 | 753 | */ |
| 782 | | sound_dma.enable = data; |
| 754 | state->sound_dma.enable = data; |
| 783 | 755 | break; |
| 784 | 756 | case 0x60: /* Video mode |
| 785 | 757 | Bit 0-4 - Unknown |
| r9669 | r9670 | |
| 797 | 769 | * 001 - packed, 4 color, use 2000, monochrome |
| 798 | 770 | * 000 - not packed, 4 color, use 2000, monochrome - Regular WS monochrome |
| 799 | 771 | */ |
| 800 | | if ( system_type == TYPE_WSC ) |
| 772 | if ( state->system_type == TYPE_WSC ) |
| 801 | 773 | { |
| 802 | | wswan_vdp.color_mode = data & 0x80; |
| 803 | | wswan_vdp.colors_16 = data & 0x40; |
| 804 | | wswan_vdp.tile_packed = data & 0x20; |
| 774 | state->vdp.color_mode = data & 0x80; |
| 775 | state->vdp.colors_16 = data & 0x40; |
| 776 | state->vdp.tile_packed = data & 0x20; |
| 805 | 777 | } |
| 806 | 778 | break; |
| 807 | 779 | case 0x80: /* Audio 1 freq (lo) |
| r9669 | r9670 | |
| 894 | 866 | Bit 1 - Hardware type: 0 = WS, 1 = WSC |
| 895 | 867 | Bit 2-7 - Unknown |
| 896 | 868 | */ |
| 897 | | if ( ( data & 0x01 ) && !wswan_bios_disabled ) |
| 869 | if ( ( data & 0x01 ) && !state->bios_disabled ) |
| 898 | 870 | { |
| 899 | | wswan_bios_disabled = 1; |
| 900 | | memory_set_bankptr( space->machine, "bank15", ROMMap[ ( ( ( ws_portram[0xc0] & 0x0F ) << 4 ) | 15 ) & ( ROMBanks - 1 ) ] ); |
| 871 | state->bios_disabled = 1; |
| 872 | memory_set_bankptr( space->machine, "bank15", state->ROMMap[ ( ( ( state->ws_portram[0xc0] & 0x0F ) << 4 ) | 15 ) & ( state->ROMBanks - 1 ) ] ); |
| 901 | 873 | } |
| 902 | 874 | break; |
| 903 | 875 | case 0xa2: /* Timer control |
| r9669 | r9670 | |
| 907 | 879 | Bit 3 - VBlank Timer mode: 0 = one shot, 1 = auto reset |
| 908 | 880 | Bit 4-7 - Unknown |
| 909 | 881 | */ |
| 910 | | wswan_vdp.timer_hblank_enable = data & 0x1; |
| 911 | | wswan_vdp.timer_hblank_mode = (data & 0x2) >> 1; |
| 912 | | wswan_vdp.timer_vblank_enable = (data & 0x4) >> 2; |
| 913 | | wswan_vdp.timer_vblank_mode = (data & 0x8) >> 3; |
| 882 | state->vdp.timer_hblank_enable = data & 0x1; |
| 883 | state->vdp.timer_hblank_mode = (data & 0x2) >> 1; |
| 884 | state->vdp.timer_vblank_enable = (data & 0x4) >> 2; |
| 885 | state->vdp.timer_vblank_mode = (data & 0x8) >> 3; |
| 914 | 886 | break; |
| 915 | 887 | case 0xa4: /* HBlank timer frequency (low) - reload value |
| 916 | 888 | Bit 0-7 - HBlank timer reload value bit 0-7 |
| 917 | 889 | */ |
| 918 | | wswan_vdp.timer_hblank_reload &= 0xff00; |
| 919 | | wswan_vdp.timer_hblank_reload += data; |
| 920 | | wswan_vdp.timer_hblank_count = wswan_vdp.timer_hblank_reload; |
| 890 | state->vdp.timer_hblank_reload &= 0xff00; |
| 891 | state->vdp.timer_hblank_reload += data; |
| 892 | state->vdp.timer_hblank_count = state->vdp.timer_hblank_reload; |
| 921 | 893 | break; |
| 922 | 894 | case 0xa5: /* HBlank timer frequency (high) - reload value |
| 923 | 895 | Bit 8-15 - HBlank timer reload value bit 8-15 |
| 924 | 896 | */ |
| 925 | | wswan_vdp.timer_hblank_reload &= 0xff; |
| 926 | | wswan_vdp.timer_hblank_reload += data << 8; |
| 927 | | wswan_vdp.timer_hblank_count = wswan_vdp.timer_hblank_reload; |
| 897 | state->vdp.timer_hblank_reload &= 0xff; |
| 898 | state->vdp.timer_hblank_reload += data << 8; |
| 899 | state->vdp.timer_hblank_count = state->vdp.timer_hblank_reload; |
| 928 | 900 | break; |
| 929 | 901 | case 0xa6: /* VBlank timer frequency (low) - reload value |
| 930 | 902 | Bit 0-7 - VBlank timer reload value bit 0-7 |
| 931 | 903 | */ |
| 932 | | wswan_vdp.timer_vblank_reload &= 0xff00; |
| 933 | | wswan_vdp.timer_vblank_reload += data; |
| 934 | | wswan_vdp.timer_vblank_count = wswan_vdp.timer_vblank_reload; |
| 904 | state->vdp.timer_vblank_reload &= 0xff00; |
| 905 | state->vdp.timer_vblank_reload += data; |
| 906 | state->vdp.timer_vblank_count = state->vdp.timer_vblank_reload; |
| 935 | 907 | break; |
| 936 | 908 | case 0xa7: /* VBlank timer frequency (high) - reload value |
| 937 | 909 | Bit 0-7 - VBlank timer reload value bit 8-15 |
| 938 | 910 | */ |
| 939 | | wswan_vdp.timer_vblank_reload &= 0xff; |
| 940 | | wswan_vdp.timer_vblank_reload += data << 8; |
| 941 | | wswan_vdp.timer_vblank_count = wswan_vdp.timer_vblank_reload; |
| 911 | state->vdp.timer_vblank_reload &= 0xff; |
| 912 | state->vdp.timer_vblank_reload += data << 8; |
| 913 | state->vdp.timer_vblank_count = state->vdp.timer_vblank_reload; |
| 942 | 914 | break; |
| 943 | 915 | case 0xa8: /* HBlank counter (low) |
| 944 | 916 | Bit 0-7 - HBlank counter bit 0-7 |
| r9669 | r9670 | |
| 983 | 955 | bit 7 - Receive data interrupt generation |
| 984 | 956 | */ |
| 985 | 957 | // data |= 0x02; |
| 986 | | ws_portram[0xb1] = 0xFF; |
| 958 | state->ws_portram[0xb1] = 0xFF; |
| 987 | 959 | if ( data & 0x80 ) |
| 988 | 960 | { |
| 989 | | // ws_portram[0xb1] = 0x00; |
| 961 | // state->ws_portram[0xb1] = 0x00; |
| 990 | 962 | data |= 0x04; |
| 991 | 963 | } |
| 992 | 964 | if (data & 0x20 ) |
| r9669 | r9670 | |
| 1027 | 999 | Bit 7 - HBlank timer interrupt acknowledge |
| 1028 | 1000 | */ |
| 1029 | 1001 | wswan_clear_irq_line( space->machine, data ); |
| 1030 | | data = ws_portram[0xB6]; |
| 1002 | data = state->ws_portram[0xB6]; |
| 1031 | 1003 | break; |
| 1032 | 1004 | case 0xba: /* Internal EEPROM data (low) |
| 1033 | 1005 | Bit 0-7 - Internal EEPROM data transfer bit 0-7 |
| r9669 | r9670 | |
| 1056 | 1028 | */ |
| 1057 | 1029 | if ( data & 0x20 ) |
| 1058 | 1030 | { |
| 1059 | | UINT16 addr = ( ( ( ws_portram[0xbd] << 8 ) | ws_portram[0xbc] ) << 1 ) & 0x1FF; |
| 1060 | | internal_eeprom[ addr ] = ws_portram[0xba]; |
| 1061 | | internal_eeprom[ addr + 1 ] = ws_portram[0xbb]; |
| 1031 | UINT16 addr = ( ( ( state->ws_portram[0xbd] << 8 ) | state->ws_portram[0xbc] ) << 1 ) & 0x1FF; |
| 1032 | state->internal_eeprom[ addr ] = state->ws_portram[0xba]; |
| 1033 | state->internal_eeprom[ addr + 1 ] = state->ws_portram[0xbb]; |
| 1062 | 1034 | data |= 0x02; |
| 1063 | 1035 | } |
| 1064 | 1036 | else if ( data & 0x10 ) |
| 1065 | 1037 | { |
| 1066 | | UINT16 addr = ( ( ( ws_portram[0xbd] << 8 ) | ws_portram[0xbc] ) << 1 ) & 0x1FF; |
| 1067 | | ws_portram[0xba] = internal_eeprom[ addr ]; |
| 1068 | | ws_portram[0xbb] = internal_eeprom[ addr + 1]; |
| 1038 | UINT16 addr = ( ( ( state->ws_portram[0xbd] << 8 ) | state->ws_portram[0xbc] ) << 1 ) & 0x1FF; |
| 1039 | state->ws_portram[0xba] = state->internal_eeprom[ addr ]; |
| 1040 | state->ws_portram[0xbb] = state->internal_eeprom[ addr + 1]; |
| 1069 | 1041 | data |= 0x01; |
| 1070 | 1042 | } |
| 1071 | 1043 | else |
| r9669 | r9670 | |
| 1077 | 1049 | Bit 0-3 - ROM bank base register for banks 4-15 |
| 1078 | 1050 | Bit 4-7 - Unknown |
| 1079 | 1051 | */ |
| 1080 | | memory_set_bankptr( space->machine, "bank4", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 4 ) & ( ROMBanks - 1 ) ] ); |
| 1081 | | memory_set_bankptr( space->machine, "bank5", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 5 ) & ( ROMBanks - 1 ) ] ); |
| 1082 | | memory_set_bankptr( space->machine, "bank6", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 6 ) & ( ROMBanks - 1 ) ] ); |
| 1083 | | memory_set_bankptr( space->machine, "bank7", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 7 ) & ( ROMBanks - 1 ) ] ); |
| 1084 | | memory_set_bankptr( space->machine, "bank8", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 8 ) & ( ROMBanks - 1 ) ] ); |
| 1085 | | memory_set_bankptr( space->machine, "bank9", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 9 ) & ( ROMBanks - 1 ) ] ); |
| 1086 | | memory_set_bankptr( space->machine, "bank10", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 10 ) & ( ROMBanks - 1 ) ] ); |
| 1087 | | memory_set_bankptr( space->machine, "bank11", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 11 ) & ( ROMBanks - 1 ) ] ); |
| 1088 | | memory_set_bankptr( space->machine, "bank12", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 12 ) & ( ROMBanks - 1 ) ] ); |
| 1089 | | memory_set_bankptr( space->machine, "bank13", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 13 ) & ( ROMBanks - 1 ) ] ); |
| 1090 | | memory_set_bankptr( space->machine, "bank14", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 14 ) & ( ROMBanks - 1 ) ] ); |
| 1091 | | if ( wswan_bios_disabled ) |
| 1052 | memory_set_bankptr( space->machine, "bank4", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 4 ) & ( state->ROMBanks - 1 ) ] ); |
| 1053 | memory_set_bankptr( space->machine, "bank5", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 5 ) & ( state->ROMBanks - 1 ) ] ); |
| 1054 | memory_set_bankptr( space->machine, "bank6", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 6 ) & ( state->ROMBanks - 1 ) ] ); |
| 1055 | memory_set_bankptr( space->machine, "bank7", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 7 ) & ( state->ROMBanks - 1 ) ] ); |
| 1056 | memory_set_bankptr( space->machine, "bank8", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 8 ) & ( state->ROMBanks - 1 ) ] ); |
| 1057 | memory_set_bankptr( space->machine, "bank9", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 9 ) & ( state->ROMBanks - 1 ) ] ); |
| 1058 | memory_set_bankptr( space->machine, "bank10", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 10 ) & ( state->ROMBanks - 1 ) ] ); |
| 1059 | memory_set_bankptr( space->machine, "bank11", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 11 ) & ( state->ROMBanks - 1 ) ] ); |
| 1060 | memory_set_bankptr( space->machine, "bank12", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 12 ) & ( state->ROMBanks - 1 ) ] ); |
| 1061 | memory_set_bankptr( space->machine, "bank13", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 13 ) & ( state->ROMBanks - 1 ) ] ); |
| 1062 | memory_set_bankptr( space->machine, "bank14", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 14 ) & ( state->ROMBanks - 1 ) ] ); |
| 1063 | if ( state->bios_disabled ) |
| 1092 | 1064 | { |
| 1093 | | memory_set_bankptr( space->machine, "bank15", ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 15 ) & ( ROMBanks - 1 ) ] ); |
| 1065 | memory_set_bankptr( space->machine, "bank15", state->ROMMap[ ( ( ( data & 0x0F ) << 4 ) | 15 ) & ( state->ROMBanks - 1 ) ] ); |
| 1094 | 1066 | } |
| 1095 | 1067 | break; |
| 1096 | 1068 | case 0xc1: /* SRAM bank select |
| 1097 | 1069 | Bit 0-7 - SRAM bank to select |
| 1098 | 1070 | */ |
| 1099 | | if ( eeprom.mode == SRAM_64K || eeprom.mode == SRAM_256K || eeprom.mode == SRAM_512K || eeprom.mode == SRAM_1M || eeprom.mode == SRAM_2M ) |
| 1071 | if ( state->eeprom.mode == SRAM_64K || state->eeprom.mode == SRAM_256K || state->eeprom.mode == SRAM_512K || state->eeprom.mode == SRAM_1M || state->eeprom.mode == SRAM_2M ) |
| 1100 | 1072 | { |
| 1101 | | eeprom.page = &eeprom.data[ ( data * 64 * 1024 ) & ( eeprom.size - 1 ) ]; |
| 1073 | state->eeprom.page = &state->eeprom.data[ ( data * 64 * 1024 ) & ( state->eeprom.size - 1 ) ]; |
| 1102 | 1074 | } |
| 1103 | 1075 | break; |
| 1104 | 1076 | case 0xc2: /* ROM bank select for segment 2 (0x20000 - 0x2ffff) |
| 1105 | 1077 | Bit 0-7 - ROM bank for segment 2 |
| 1106 | 1078 | */ |
| 1107 | | memory_set_bankptr( space->machine, "bank2", ROMMap[ data & ( ROMBanks - 1 ) ]); |
| 1079 | memory_set_bankptr( space->machine, "bank2", state->ROMMap[ data & ( state->ROMBanks - 1 ) ]); |
| 1108 | 1080 | break; |
| 1109 | 1081 | case 0xc3: /* ROM bank select for segment 3 (0x30000-0x3ffff) |
| 1110 | 1082 | Bit 0-7 - ROM bank for segment 3 |
| 1111 | 1083 | */ |
| 1112 | | memory_set_bankptr( space->machine, "bank3", ROMMap[ data & ( ROMBanks - 1 ) ]); |
| 1084 | memory_set_bankptr( space->machine, "bank3", state->ROMMap[ data & ( state->ROMBanks - 1 ) ]); |
| 1113 | 1085 | break; |
| 1114 | 1086 | case 0xc6: /* EEPROM address lower bits port/EEPROM address and command port |
| 1115 | 1087 | 1KBit EEPROM: |
| r9669 | r9670 | |
| 1126 | 1098 | 16KBit EEPROM: |
| 1127 | 1099 | Bit 0-7 - EEPROM address bit 1-8 |
| 1128 | 1100 | */ |
| 1129 | | switch( eeprom.mode ) |
| 1101 | switch( state->eeprom.mode ) |
| 1130 | 1102 | { |
| 1131 | 1103 | case EEPROM_1K: |
| 1132 | | eeprom.address = data & 0x3F; |
| 1133 | | eeprom.command = data >> 4; |
| 1134 | | if ( ( eeprom.command & 0x0C ) != 0x00 ) |
| 1104 | state->eeprom.address = data & 0x3F; |
| 1105 | state->eeprom.command = data >> 4; |
| 1106 | if ( ( state->eeprom.command & 0x0C ) != 0x00 ) |
| 1135 | 1107 | { |
| 1136 | | eeprom.command = eeprom.command & 0x0C; |
| 1108 | state->eeprom.command = state->eeprom.command & 0x0C; |
| 1137 | 1109 | } |
| 1138 | 1110 | break; |
| 1139 | 1111 | case EEPROM_16K: |
| 1140 | | eeprom.address = ( eeprom.address & 0xFF00 ) | data; |
| 1112 | state->eeprom.address = ( state->eeprom.address & 0xFF00 ) | data; |
| 1141 | 1113 | break; |
| 1142 | 1114 | default: |
| 1143 | 1115 | logerror( "Write EEPROM address/register register C6 for unsupported EEPROM type\n" ); |
| r9669 | r9670 | |
| 1162 | 1134 | Bit 4 - Start |
| 1163 | 1135 | Bit 5-7 - Unknown |
| 1164 | 1136 | */ |
| 1165 | | switch( eeprom.mode ) |
| 1137 | switch( state->eeprom.mode ) |
| 1166 | 1138 | { |
| 1167 | 1139 | case EEPROM_1K: |
| 1168 | | eeprom.start = data & 0x01; |
| 1140 | state->eeprom.start = data & 0x01; |
| 1169 | 1141 | break; |
| 1170 | 1142 | case EEPROM_16K: |
| 1171 | | eeprom.address = ( ( data & 0x03 ) << 8 ) | ( eeprom.address & 0xFF ); |
| 1172 | | eeprom.command = data & 0x0F; |
| 1173 | | if ( ( eeprom.command & 0x0C ) != 0x00 ) |
| 1143 | state->eeprom.address = ( ( data & 0x03 ) << 8 ) | ( state->eeprom.address & 0xFF ); |
| 1144 | state->eeprom.command = data & 0x0F; |
| 1145 | if ( ( state->eeprom.command & 0x0C ) != 0x00 ) |
| 1174 | 1146 | { |
| 1175 | | eeprom.command = eeprom.command & 0x0C; |
| 1147 | state->eeprom.command = state->eeprom.command & 0x0C; |
| 1176 | 1148 | } |
| 1177 | | eeprom.start = ( data >> 4 ) & 0x01; |
| 1149 | state->eeprom.start = ( data >> 4 ) & 0x01; |
| 1178 | 1150 | break; |
| 1179 | 1151 | default: |
| 1180 | 1152 | logerror( "Write EEPROM address/command register C7 for unsupported EEPROM type\n" ); |
| r9669 | r9670 | |
| 1190 | 1162 | Bit 6 - Protect |
| 1191 | 1163 | Bit 7 - Initialize |
| 1192 | 1164 | */ |
| 1193 | | if ( eeprom.mode == EEPROM_1K || eeprom.mode == EEPROM_16K ) |
| 1165 | if ( state->eeprom.mode == EEPROM_1K || state->eeprom.mode == EEPROM_16K ) |
| 1194 | 1166 | { |
| 1195 | 1167 | if ( data & 0x80 ) |
| 1196 | 1168 | { /* Initialize */ |
| r9669 | r9670 | |
| 1198 | 1170 | } |
| 1199 | 1171 | if ( data & 0x40 ) |
| 1200 | 1172 | { /* Protect */ |
| 1201 | | switch( eeprom.command ) |
| 1173 | switch( state->eeprom.command ) |
| 1202 | 1174 | { |
| 1203 | 1175 | case 0x00: |
| 1204 | | eeprom.write_enabled = 0; |
| 1176 | state->eeprom.write_enabled = 0; |
| 1205 | 1177 | data |= 0x02; |
| 1206 | 1178 | break; |
| 1207 | 1179 | case 0x03: |
| 1208 | | eeprom.write_enabled = 1; |
| 1180 | state->eeprom.write_enabled = 1; |
| 1209 | 1181 | data |= 0x02; |
| 1210 | 1182 | break; |
| 1211 | 1183 | default: |
| 1212 | | logerror( "Unsupported 'Protect' command %X\n", eeprom.command ); |
| 1184 | logerror( "Unsupported 'Protect' command %X\n", state->eeprom.command ); |
| 1213 | 1185 | } |
| 1214 | 1186 | } |
| 1215 | 1187 | if ( data & 0x20 ) |
| 1216 | 1188 | { /* Write */ |
| 1217 | | if ( eeprom.write_enabled ) |
| 1189 | if ( state->eeprom.write_enabled ) |
| 1218 | 1190 | { |
| 1219 | | switch( eeprom.command ) |
| 1191 | switch( state->eeprom.command ) |
| 1220 | 1192 | { |
| 1221 | 1193 | case 0x04: |
| 1222 | | eeprom.data[ ( eeprom.address << 1 ) + 1 ] = ws_portram[0xc4]; |
| 1223 | | eeprom.data[ eeprom.address << 1 ] = ws_portram[0xc5]; |
| 1194 | state->eeprom.data[ ( state->eeprom.address << 1 ) + 1 ] = state->ws_portram[0xc4]; |
| 1195 | state->eeprom.data[ state->eeprom.address << 1 ] = state->ws_portram[0xc5]; |
| 1224 | 1196 | data |= 0x02; |
| 1225 | 1197 | break; |
| 1226 | 1198 | default: |
| 1227 | | logerror( "Unsupported 'Write' command %X\n", eeprom.command ); |
| 1199 | logerror( "Unsupported 'Write' command %X\n", state->eeprom.command ); |
| 1228 | 1200 | } |
| 1229 | 1201 | } |
| 1230 | 1202 | } |
| 1231 | 1203 | if ( data & 0x10 ) |
| 1232 | 1204 | { /* Read */ |
| 1233 | | ws_portram[0xc4] = eeprom.data[ ( eeprom.address << 1 ) + 1 ]; |
| 1234 | | ws_portram[0xc5] = eeprom.data[ eeprom.address << 1 ]; |
| 1205 | state->ws_portram[0xc4] = state->eeprom.data[ ( state->eeprom.address << 1 ) + 1 ]; |
| 1206 | state->ws_portram[0xc5] = state->eeprom.data[ state->eeprom.address << 1 ]; |
| 1235 | 1207 | data |= 0x01; |
| 1236 | 1208 | } |
| 1237 | 1209 | } |
| r9669 | r9670 | |
| 1253 | 1225 | switch( data ) |
| 1254 | 1226 | { |
| 1255 | 1227 | case 0x10: /* Reset */ |
| 1256 | | rtc.index = 8; |
| 1257 | | rtc.year = 0; |
| 1258 | | rtc.month = 1; |
| 1259 | | rtc.day = 1; |
| 1260 | | rtc.day_of_week = 0; |
| 1261 | | rtc.hour = 0; |
| 1262 | | rtc.minute = 0; |
| 1263 | | rtc.second = 0; |
| 1264 | | rtc.setting = 0xFF; |
| 1228 | state->rtc.index = 8; |
| 1229 | state->rtc.year = 0; |
| 1230 | state->rtc.month = 1; |
| 1231 | state->rtc.day = 1; |
| 1232 | state->rtc.day_of_week = 0; |
| 1233 | state->rtc.hour = 0; |
| 1234 | state->rtc.minute = 0; |
| 1235 | state->rtc.second = 0; |
| 1236 | state->rtc.setting = 0xFF; |
| 1265 | 1237 | data |= 0x80; |
| 1266 | 1238 | break; |
| 1267 | 1239 | case 0x12: /* Write Timer Settings (Alarm) */ |
| 1268 | | rtc.index = 8; |
| 1269 | | rtc.setting = ws_portram[0xcb]; |
| 1240 | state->rtc.index = 8; |
| 1241 | state->rtc.setting = state->ws_portram[0xcb]; |
| 1270 | 1242 | data |= 0x80; |
| 1271 | 1243 | break; |
| 1272 | 1244 | case 0x13: /* Read Timer Settings (Alarm) */ |
| 1273 | | rtc.index = 8; |
| 1274 | | ws_portram[0xcb] = rtc.setting; |
| 1245 | state->rtc.index = 8; |
| 1246 | state->ws_portram[0xcb] = state->rtc.setting; |
| 1275 | 1247 | data |= 0x80; |
| 1276 | 1248 | break; |
| 1277 | 1249 | case 0x14: /* Set Time/Date */ |
| 1278 | | rtc.year = ws_portram[0xcb]; |
| 1279 | | rtc.index = 1; |
| 1250 | state->rtc.year = state->ws_portram[0xcb]; |
| 1251 | state->rtc.index = 1; |
| 1280 | 1252 | data |= 0x80; |
| 1281 | 1253 | break; |
| 1282 | 1254 | case 0x15: /* Get Time/Date */ |
| 1283 | | rtc.index = 0; |
| 1255 | state->rtc.index = 0; |
| 1284 | 1256 | data |= 0x80; |
| 1285 | | ws_portram[0xcb] = rtc.year; |
| 1257 | state->ws_portram[0xcb] = state->rtc.year; |
| 1286 | 1258 | break; |
| 1287 | 1259 | default: |
| 1288 | 1260 | logerror( "%X: Unknown RTC command (%X) requested\n", cpu_get_pc( space->cpu ), data ); |
| 1289 | 1261 | } |
| 1290 | 1262 | break; |
| 1291 | 1263 | case 0xcb: /* RTC Data */ |
| 1292 | | if ( ws_portram[0xca] == 0x94 && rtc.index < 7 ) |
| 1264 | if ( state->ws_portram[0xca] == 0x94 && state->rtc.index < 7 ) |
| 1293 | 1265 | { |
| 1294 | | switch( rtc.index ) |
| 1266 | switch( state->rtc.index ) |
| 1295 | 1267 | { |
| 1296 | | case 0: rtc.year = data; break; |
| 1297 | | case 1: rtc.month = data; break; |
| 1298 | | case 2: rtc.day = data; break; |
| 1299 | | case 3: rtc.day_of_week = data; break; |
| 1300 | | case 4: rtc.hour = data; break; |
| 1301 | | case 5: rtc.minute = data; break; |
| 1302 | | case 6: rtc.second = data; break; |
| 1268 | case 0: state->rtc.year = data; break; |
| 1269 | case 1: state->rtc.month = data; break; |
| 1270 | case 2: state->rtc.day = data; break; |
| 1271 | case 3: state->rtc.day_of_week = data; break; |
| 1272 | case 4: state->rtc.hour = data; break; |
| 1273 | case 5: state->rtc.minute = data; break; |
| 1274 | case 6: state->rtc.second = data; break; |
| 1303 | 1275 | } |
| 1304 | | rtc.index++; |
| 1276 | state->rtc.index++; |
| 1305 | 1277 | } |
| 1306 | 1278 | break; |
| 1307 | 1279 | default: |
| r9669 | r9670 | |
| 1310 | 1282 | } |
| 1311 | 1283 | |
| 1312 | 1284 | /* Update the port value */ |
| 1313 | | ws_portram[offset] = data; |
| 1285 | state->ws_portram[offset] = data; |
| 1314 | 1286 | } |
| 1315 | 1287 | |
| 1316 | | static const char* wswan_determine_sram( UINT8 data ) |
| 1288 | static const char* wswan_determine_sram( wswan_state *state, UINT8 data ) |
| 1317 | 1289 | { |
| 1318 | | eeprom.write_enabled = 0; |
| 1319 | | eeprom.mode = SRAM_UNKNOWN; |
| 1290 | state->eeprom.write_enabled = 0; |
| 1291 | state->eeprom.mode = SRAM_UNKNOWN; |
| 1320 | 1292 | switch( data ) |
| 1321 | 1293 | { |
| 1322 | | case 0x00: eeprom.mode = SRAM_NONE; break; |
| 1323 | | case 0x01: eeprom.mode = SRAM_64K; break; |
| 1324 | | case 0x02: eeprom.mode = SRAM_256K; break; |
| 1325 | | case 0x03: eeprom.mode = SRAM_1M; break; |
| 1326 | | case 0x04: eeprom.mode = SRAM_2M; break; |
| 1327 | | case 0x05: eeprom.mode = SRAM_512K; break; |
| 1328 | | case 0x10: eeprom.mode = EEPROM_1K; break; |
| 1329 | | case 0x20: eeprom.mode = EEPROM_16K; break; |
| 1330 | | case 0x50: eeprom.mode = EEPROM_8K; break; |
| 1294 | case 0x00: state->eeprom.mode = SRAM_NONE; break; |
| 1295 | case 0x01: state->eeprom.mode = SRAM_64K; break; |
| 1296 | case 0x02: state->eeprom.mode = SRAM_256K; break; |
| 1297 | case 0x03: state->eeprom.mode = SRAM_1M; break; |
| 1298 | case 0x04: state->eeprom.mode = SRAM_2M; break; |
| 1299 | case 0x05: state->eeprom.mode = SRAM_512K; break; |
| 1300 | case 0x10: state->eeprom.mode = EEPROM_1K; break; |
| 1301 | case 0x20: state->eeprom.mode = EEPROM_16K; break; |
| 1302 | case 0x50: state->eeprom.mode = EEPROM_8K; break; |
| 1331 | 1303 | } |
| 1332 | | eeprom.size = wswan_sram_size[ eeprom.mode ]; |
| 1333 | | return wswan_sram_str[ eeprom.mode ]; |
| 1304 | state->eeprom.size = wswan_sram_size[ state->eeprom.mode ]; |
| 1305 | return wswan_sram_str[ state->eeprom.mode ]; |
| 1334 | 1306 | } |
| 1335 | 1307 | |
| 1336 | 1308 | enum enum_romsize { ROM_4M=0, ROM_8M, ROM_16M, ROM_32M, ROM_64M, ROM_128M, ROM_UNKNOWN }; |
| r9669 | r9670 | |
| 1354 | 1326 | |
| 1355 | 1327 | DEVICE_START(wswan_cart) |
| 1356 | 1328 | { |
| 1329 | wswan_state *state = device->machine->driver_data<wswan_state>(); |
| 1357 | 1330 | /* Initialize EEPROM structure */ |
| 1358 | | memset( &eeprom, 0, sizeof( eeprom ) ); |
| 1359 | | eeprom.data = NULL; |
| 1360 | | eeprom.page = NULL; |
| 1331 | memset( &state->eeprom, 0, sizeof( state->eeprom ) ); |
| 1332 | state->eeprom.data = NULL; |
| 1333 | state->eeprom.page = NULL; |
| 1361 | 1334 | |
| 1362 | 1335 | /* Initialize RTC structure */ |
| 1363 | | rtc.present = 0; |
| 1364 | | rtc.index = 0; |
| 1365 | | rtc.year = 0; |
| 1366 | | rtc.month = 0; |
| 1367 | | rtc.day = 0; |
| 1368 | | rtc.day_of_week = 0; |
| 1369 | | rtc.hour = 0; |
| 1370 | | rtc.minute = 0; |
| 1371 | | rtc.second = 0; |
| 1372 | | rtc.setting = 0xFF; |
| 1336 | state->rtc.present = 0; |
| 1337 | state->rtc.index = 0; |
| 1338 | state->rtc.year = 0; |
| 1339 | state->rtc.month = 0; |
| 1340 | state->rtc.day = 0; |
| 1341 | state->rtc.day_of_week = 0; |
| 1342 | state->rtc.hour = 0; |
| 1343 | state->rtc.minute = 0; |
| 1344 | state->rtc.second = 0; |
| 1345 | state->rtc.setting = 0xFF; |
| 1373 | 1346 | } |
| 1374 | 1347 | |
| 1375 | 1348 | DEVICE_IMAGE_LOAD(wswan_cart) |
| 1376 | 1349 | { |
| 1350 | wswan_state *state = image.device().machine->driver_data<wswan_state>(); |
| 1377 | 1351 | UINT32 ii, size; |
| 1378 | 1352 | const char *sram_str; |
| 1379 | 1353 | |
| r9669 | r9670 | |
| 1382 | 1356 | else |
| 1383 | 1357 | size = image.get_software_region_length("rom"); |
| 1384 | 1358 | |
| 1385 | | ws_ram = (UINT8*) cputag_get_address_space(image.device().machine, "maincpu", ADDRESS_SPACE_PROGRAM)->get_read_ptr(0); |
| 1386 | | memset(ws_ram, 0, 0xffff); |
| 1387 | | ROMBanks = size / 65536; |
| 1359 | state->ws_ram = (UINT8*) cputag_get_address_space(image.device().machine, "maincpu", ADDRESS_SPACE_PROGRAM)->get_read_ptr(0); |
| 1360 | memset(state->ws_ram, 0, 0xffff); |
| 1361 | state->ROMBanks = size / 65536; |
| 1388 | 1362 | |
| 1389 | | for (ii = 0; ii < ROMBanks; ii++) |
| 1363 | for (ii = 0; ii < state->ROMBanks; ii++) |
| 1390 | 1364 | { |
| 1391 | | if ((ROMMap[ii] = auto_alloc_array(image.device().machine, UINT8, 0x10000))) |
| 1365 | if ((state->ROMMap[ii] = auto_alloc_array(image.device().machine, UINT8, 0x10000))) |
| 1392 | 1366 | { |
| 1393 | 1367 | if (image.software_entry() == NULL) |
| 1394 | 1368 | { |
| 1395 | | if (image.fread( ROMMap[ii], 0x10000) != 0x10000) |
| 1369 | if (image.fread( state->ROMMap[ii], 0x10000) != 0x10000) |
| 1396 | 1370 | { |
| 1397 | 1371 | logerror("Error while reading loading rom!\n"); |
| 1398 | 1372 | return IMAGE_INIT_FAIL; |
| 1399 | 1373 | } |
| 1400 | 1374 | } |
| 1401 | 1375 | else |
| 1402 | | memcpy(ROMMap[ii], image.get_software_region("rom") + ii * 0x10000, 0x10000); |
| 1376 | memcpy(state->ROMMap[ii], image.get_software_region("rom") + ii * 0x10000, 0x10000); |
| 1403 | 1377 | } |
| 1404 | 1378 | else |
| 1405 | 1379 | { |
| r9669 | r9670 | |
| 1408 | 1382 | } |
| 1409 | 1383 | } |
| 1410 | 1384 | |
| 1411 | | sram_str = wswan_determine_sram(ROMMap[ROMBanks - 1][0xfffb]); |
| 1385 | sram_str = wswan_determine_sram(state, state->ROMMap[state->ROMBanks - 1][0xfffb]); |
| 1412 | 1386 | |
| 1413 | | rtc.present = ROMMap[ROMBanks - 1][0xfffd] ? 1 : 0; |
| 1387 | state->rtc.present = state->ROMMap[state->ROMBanks - 1][0xfffd] ? 1 : 0; |
| 1414 | 1388 | |
| 1415 | 1389 | { |
| 1416 | 1390 | int sum = 0; |
| 1417 | 1391 | /* Spit out some info */ |
| 1418 | 1392 | logerror("ROM DETAILS\n" ); |
| 1419 | | logerror("\tDeveloper ID: %X\n", ROMMap[ROMBanks - 1][0xfff6]); |
| 1420 | | logerror("\tMinimum system: %s\n", ROMMap[ROMBanks - 1][0xfff7] ? "WonderSwan Color" : "WonderSwan"); |
| 1421 | | logerror("\tCart ID: %X\n", ROMMap[ROMBanks - 1][0xfff8]); |
| 1422 | | logerror("\tROM size: %s\n", wswan_determine_romsize(ROMMap[ROMBanks - 1][0xfffa])); |
| 1393 | logerror("\tDeveloper ID: %X\n", state->ROMMap[state->ROMBanks - 1][0xfff6]); |
| 1394 | logerror("\tMinimum system: %s\n", state->ROMMap[state->ROMBanks - 1][0xfff7] ? "WonderSwan Color" : "WonderSwan"); |
| 1395 | logerror("\tCart ID: %X\n", state->ROMMap[state->ROMBanks - 1][0xfff8]); |
| 1396 | logerror("\tROM size: %s\n", wswan_determine_romsize(state->ROMMap[state->ROMBanks - 1][0xfffa])); |
| 1423 | 1397 | logerror("\tSRAM size: %s\n", sram_str); |
| 1424 | | logerror("\tFeatures: %X\n", ROMMap[ROMBanks - 1][0xfffc]); |
| 1425 | | logerror("\tRTC: %s\n", ROMMap[ROMBanks - 1][0xfffd] ? "yes" : "no"); |
| 1426 | | for (ii = 0; ii < ROMBanks; ii++) |
| 1398 | logerror("\tFeatures: %X\n", state->ROMMap[state->ROMBanks - 1][0xfffc]); |
| 1399 | logerror("\tRTC: %s\n", state->ROMMap[state->ROMBanks - 1][0xfffd] ? "yes" : "no"); |
| 1400 | for (ii = 0; ii < state->ROMBanks; ii++) |
| 1427 | 1401 | { |
| 1428 | 1402 | int count; |
| 1429 | 1403 | for (count = 0; count < 0x10000; count++) |
| 1430 | 1404 | { |
| 1431 | | sum += ROMMap[ii][count]; |
| 1405 | sum += state->ROMMap[ii][count]; |
| 1432 | 1406 | } |
| 1433 | 1407 | } |
| 1434 | | sum -= ROMMap[ROMBanks - 1][0xffff]; |
| 1435 | | sum -= ROMMap[ROMBanks - 1][0xfffe]; |
| 1408 | sum -= state->ROMMap[state->ROMBanks - 1][0xffff]; |
| 1409 | sum -= state->ROMMap[state->ROMBanks - 1][0xfffe]; |
| 1436 | 1410 | sum &= 0xffff; |
| 1437 | | logerror("\tChecksum: %X%X (calculated: %04X)\n", ROMMap[ROMBanks - 1][0xffff], ROMMap[ROMBanks - 1][0xfffe], sum); |
| 1411 | logerror("\tChecksum: %X%X (calculated: %04X)\n", state->ROMMap[state->ROMBanks - 1][0xffff], state->ROMMap[state->ROMBanks - 1][0xfffe], sum); |
| 1438 | 1412 | } |
| 1439 | 1413 | |
| 1440 | | if (eeprom.size != 0) |
| 1414 | if (state->eeprom.size != 0) |
| 1441 | 1415 | { |
| 1442 | | eeprom.data = auto_alloc_array(image.device().machine, UINT8, eeprom.size); |
| 1443 | | image.battery_load(eeprom.data, eeprom.size, 0x00); |
| 1444 | | eeprom.page = eeprom.data; |
| 1416 | state->eeprom.data = auto_alloc_array(image.device().machine, UINT8, state->eeprom.size); |
| 1417 | image.battery_load(state->eeprom.data, state->eeprom.size, 0x00); |
| 1418 | state->eeprom.page = state->eeprom.data; |
| 1445 | 1419 | } |
| 1446 | 1420 | |
| 1447 | 1421 | if (image.software_entry() == NULL) |
| r9669 | r9670 | |
| 1457 | 1431 | |
| 1458 | 1432 | static TIMER_CALLBACK(wswan_scanline_interrupt) |
| 1459 | 1433 | { |
| 1460 | | if( wswan_vdp.current_line < 144 ) |
| 1434 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 1435 | if( state->vdp.current_line < 144 ) |
| 1461 | 1436 | { |
| 1462 | 1437 | wswan_refresh_scanline(machine); |
| 1463 | 1438 | } |
| 1464 | 1439 | |
| 1465 | 1440 | /* Decrement 12kHz (HBlank) counter */ |
| 1466 | | if ( wswan_vdp.timer_hblank_enable && wswan_vdp.timer_hblank_reload != 0 ) |
| 1441 | if ( state->vdp.timer_hblank_enable && state->vdp.timer_hblank_reload != 0 ) |
| 1467 | 1442 | { |
| 1468 | | wswan_vdp.timer_hblank_count--; |
| 1469 | | logerror( "timer_hblank_count: %X\n", wswan_vdp.timer_hblank_count ); |
| 1470 | | if ( wswan_vdp.timer_hblank_count == 0 ) |
| 1443 | state->vdp.timer_hblank_count--; |
| 1444 | logerror( "timer_hblank_count: %X\n", state->vdp.timer_hblank_count ); |
| 1445 | if ( state->vdp.timer_hblank_count == 0 ) |
| 1471 | 1446 | { |
| 1472 | | if ( wswan_vdp.timer_hblank_mode ) |
| 1447 | if ( state->vdp.timer_hblank_mode ) |
| 1473 | 1448 | { |
| 1474 | | wswan_vdp.timer_hblank_count = wswan_vdp.timer_hblank_reload; |
| 1449 | state->vdp.timer_hblank_count = state->vdp.timer_hblank_reload; |
| 1475 | 1450 | } |
| 1476 | 1451 | else |
| 1477 | 1452 | { |
| 1478 | | wswan_vdp.timer_hblank_reload = 0; |
| 1453 | state->vdp.timer_hblank_reload = 0; |
| 1479 | 1454 | } |
| 1480 | 1455 | logerror( "trigerring hbltmr interrupt\n" ); |
| 1481 | 1456 | wswan_set_irq_line( machine, WSWAN_IFLAG_HBLTMR ); |
| r9669 | r9670 | |
| 1483 | 1458 | } |
| 1484 | 1459 | |
| 1485 | 1460 | /* Handle Sound DMA */ |
| 1486 | | if ( ( sound_dma.enable & 0x88 ) == 0x80 ) |
| 1461 | if ( ( state->sound_dma.enable & 0x88 ) == 0x80 ) |
| 1487 | 1462 | { |
| 1488 | 1463 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM ); |
| 1489 | 1464 | /* TODO: Output sound DMA byte */ |
| 1490 | | wswan_port_w( space, 0x89, space->read_byte(sound_dma.source ) ); |
| 1491 | | sound_dma.size--; |
| 1492 | | sound_dma.source = ( sound_dma.source + 1 ) & 0x0FFFFF; |
| 1493 | | if ( sound_dma.size == 0 ) |
| 1465 | wswan_port_w( space, 0x89, space->read_byte(state->sound_dma.source ) ); |
| 1466 | state->sound_dma.size--; |
| 1467 | state->sound_dma.source = ( state->sound_dma.source + 1 ) & 0x0FFFFF; |
| 1468 | if ( state->sound_dma.size == 0 ) |
| 1494 | 1469 | { |
| 1495 | | sound_dma.enable &= 0x7F; |
| 1470 | state->sound_dma.enable &= 0x7F; |
| 1496 | 1471 | } |
| 1497 | 1472 | } |
| 1498 | 1473 | |
| 1499 | | // wswan_vdp.current_line = (wswan_vdp.current_line + 1) % 159; |
| 1474 | // state->vdp.current_line = (state->vdp.current_line + 1) % 159; |
| 1500 | 1475 | |
| 1501 | | if( wswan_vdp.current_line == 144 ) |
| 1476 | if( state->vdp.current_line == 144 ) |
| 1502 | 1477 | { |
| 1503 | 1478 | wswan_set_irq_line( machine, WSWAN_IFLAG_VBL ); |
| 1504 | 1479 | /* Decrement 75Hz (VBlank) counter */ |
| 1505 | | if ( wswan_vdp.timer_vblank_enable && wswan_vdp.timer_vblank_reload != 0 ) |
| 1480 | if ( state->vdp.timer_vblank_enable && state->vdp.timer_vblank_reload != 0 ) |
| 1506 | 1481 | { |
| 1507 | | wswan_vdp.timer_vblank_count--; |
| 1508 | | logerror( "timer_vblank_count: %X\n", wswan_vdp.timer_vblank_count ); |
| 1509 | | if ( wswan_vdp.timer_vblank_count == 0 ) |
| 1482 | state->vdp.timer_vblank_count--; |
| 1483 | logerror( "timer_vblank_count: %X\n", state->vdp.timer_vblank_count ); |
| 1484 | if ( state->vdp.timer_vblank_count == 0 ) |
| 1510 | 1485 | { |
| 1511 | | if ( wswan_vdp.timer_vblank_mode ) |
| 1486 | if ( state->vdp.timer_vblank_mode ) |
| 1512 | 1487 | { |
| 1513 | | wswan_vdp.timer_vblank_count = wswan_vdp.timer_vblank_reload; |
| 1488 | state->vdp.timer_vblank_count = state->vdp.timer_vblank_reload; |
| 1514 | 1489 | } |
| 1515 | 1490 | else |
| 1516 | 1491 | { |
| 1517 | | wswan_vdp.timer_vblank_reload = 0; |
| 1492 | state->vdp.timer_vblank_reload = 0; |
| 1518 | 1493 | } |
| 1519 | 1494 | logerror( "triggering vbltmr interrupt\n" ); |
| 1520 | 1495 | wswan_set_irq_line( machine, WSWAN_IFLAG_VBLTMR ); |
| r9669 | r9670 | |
| 1522 | 1497 | } |
| 1523 | 1498 | } |
| 1524 | 1499 | |
| 1525 | | // wswan_vdp.current_line = (wswan_vdp.current_line + 1) % 159; |
| 1500 | // state->vdp.current_line = (state->vdp.current_line + 1) % 159; |
| 1526 | 1501 | |
| 1527 | | if ( wswan_vdp.current_line == wswan_vdp.line_compare ) |
| 1502 | if ( state->vdp.current_line == state->vdp.line_compare ) |
| 1528 | 1503 | { |
| 1529 | 1504 | wswan_set_irq_line( machine, WSWAN_IFLAG_LCMP ); |
| 1530 | 1505 | } |
| 1531 | 1506 | |
| 1532 | | wswan_vdp.current_line = (wswan_vdp.current_line + 1) % 159; |
| 1507 | state->vdp.current_line = (state->vdp.current_line + 1) % 159; |
| 1533 | 1508 | |
| 1534 | | if ( wswan_vdp.current_line == 0 ) |
| 1509 | if ( state->vdp.current_line == 0 ) |
| 1535 | 1510 | { |
| 1536 | | if ( wswan_vdp.display_vertical != wswan_vdp.new_display_vertical ) |
| 1511 | if ( state->vdp.display_vertical != state->vdp.new_display_vertical ) |
| 1537 | 1512 | { |
| 1538 | | wswan_vdp.display_vertical = wswan_vdp.new_display_vertical; |
| 1539 | | if ( wswan_vdp.display_vertical ) |
| 1513 | state->vdp.display_vertical = state->vdp.new_display_vertical; |
| 1514 | if ( state->vdp.display_vertical ) |
| 1540 | 1515 | { |
| 1541 | 1516 | machine->primary_screen->set_visible_area(5*8, 5*8 + WSWAN_Y_PIXELS - 1, 0, WSWAN_X_PIXELS - 1 ); |
| 1542 | 1517 | } |
src/mess/machine/z80ne.c
| r9669 | r9670 | |
| 25 | 25 | #define VERBOSE 0 |
| 26 | 26 | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 27 | 27 | |
| 28 | | static UINT8 lx383_scan_counter; |
| 29 | | static UINT8 lx383_key[LX383_KEYS]; |
| 30 | | static int lx383_downsampler; |
| 31 | | static int nmi_delay_counter; |
| 32 | | static int reset_delay_counter; |
| 33 | | static running_device *z80ne_ay31015; |
| 34 | | static UINT8 lx385_ctrl; |
| 35 | | static running_device *lx388_kr2376; |
| 36 | 28 | |
| 37 | 29 | |
| 38 | 30 | |
| 39 | 31 | |
| 40 | 32 | /* timer to read cassette waveforms */ |
| 41 | | static emu_timer *cassette_timer; |
| 42 | 33 | |
| 43 | | /* wave duration threshold */ |
| 44 | | typedef enum |
| 45 | | { |
| 46 | | TAPE_300BPS = 300, /* 300 bps */ |
| 47 | | TAPE_600BPS = 600, /* 600 bps */ |
| 48 | | TAPE_1200BPS = 1200 /* 1200 bps */ |
| 49 | | } z80netape_speed; |
| 50 | | |
| 51 | | static struct { |
| 52 | | struct { |
| 53 | | int length; /* time cassette level is at input.level */ |
| 54 | | int level; /* cassette level */ |
| 55 | | int bit; /* bit being read */ |
| 56 | | } input; |
| 57 | | struct { |
| 58 | | int length; /* time cassette level is at output.level */ |
| 59 | | int level; /* cassette level */ |
| 60 | | int bit; /* bit to to output */ |
| 61 | | } output; |
| 62 | | z80netape_speed speed; /* 300 - 600 - 1200 */ |
| 63 | | int wave_filter; |
| 64 | | int wave_length; |
| 65 | | int wave_short; |
| 66 | | int wave_long; |
| 67 | | } cass_data; |
| 68 | | |
| 69 | | static struct _wd17xx_state { |
| 70 | | int drq; |
| 71 | | int intrq; |
| 72 | | UINT8 drive; /* current drive */ |
| 73 | | UINT8 head; /* current head */ |
| 74 | | } wd17xx_state; |
| 75 | | |
| 76 | 34 | static running_device *cassette_device_image(running_machine *machine) |
| 77 | 35 | { |
| 78 | | if (lx385_ctrl & 0x08) |
| 36 | z80ne_state *state = machine->driver_data<z80ne_state>(); |
| 37 | if (state->lx385_ctrl & 0x08) |
| 79 | 38 | return machine->device("cassetteb"); |
| 80 | 39 | else |
| 81 | 40 | return machine->device("cassettea"); |
| r9669 | r9670 | |
| 83 | 42 | |
| 84 | 43 | static TIMER_CALLBACK(z80ne_cassette_tc) |
| 85 | 44 | { |
| 45 | z80ne_state *state = machine->driver_data<z80ne_state>(); |
| 86 | 46 | UINT8 cass_ws = 0; |
| 87 | | cass_data.input.length++; |
| 47 | state->cass_data.input.length++; |
| 88 | 48 | |
| 89 | 49 | cass_ws = (cassette_input(cassette_device_image(machine)) > +0.02) ? 1 : 0; |
| 90 | 50 | |
| 91 | | if ((cass_ws ^ cass_data.input.level) & cass_ws) |
| 51 | if ((cass_ws ^ state->cass_data.input.level) & cass_ws) |
| 92 | 52 | { |
| 93 | | cass_data.input.level = cass_ws; |
| 94 | | cass_data.input.bit = ((cass_data.input.length < cass_data.wave_filter) || (cass_data.input.length > 0x20)) ? 1 : 0; |
| 95 | | cass_data.input.length = 0; |
| 96 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_SI, cass_data.input.bit ); |
| 53 | state->cass_data.input.level = cass_ws; |
| 54 | state->cass_data.input.bit = ((state->cass_data.input.length < state->cass_data.wave_filter) || (state->cass_data.input.length > 0x20)) ? 1 : 0; |
| 55 | state->cass_data.input.length = 0; |
| 56 | ay31015_set_input_pin( state->ay31015, AY31015_SI, state->cass_data.input.bit ); |
| 97 | 57 | } |
| 98 | | cass_data.input.level = cass_ws; |
| 58 | state->cass_data.input.level = cass_ws; |
| 99 | 59 | |
| 100 | 60 | /* saving a tape - convert the serial stream from the uart */ |
| 101 | 61 | |
| 102 | | cass_data.output.length--; |
| 62 | state->cass_data.output.length--; |
| 103 | 63 | |
| 104 | | if (!(cass_data.output.length)) |
| 64 | if (!(state->cass_data.output.length)) |
| 105 | 65 | { |
| 106 | | if (cass_data.output.level) |
| 107 | | cass_data.output.level = 0; |
| 66 | if (state->cass_data.output.level) |
| 67 | state->cass_data.output.level = 0; |
| 108 | 68 | else |
| 109 | 69 | { |
| 110 | | cass_data.output.level=1; |
| 111 | | cass_ws = ay31015_get_output_pin( z80ne_ay31015, AY31015_SO ); |
| 112 | | cass_data.wave_length = cass_ws ? cass_data.wave_short : cass_data.wave_long; |
| 70 | state->cass_data.output.level=1; |
| 71 | cass_ws = ay31015_get_output_pin( state->ay31015, AY31015_SO ); |
| 72 | state->cass_data.wave_length = cass_ws ? state->cass_data.wave_short : state->cass_data.wave_long; |
| 113 | 73 | } |
| 114 | | cassette_output(cassette_device_image(machine), cass_data.output.level ? -1.0 : +1.0); |
| 115 | | cass_data.output.length = cass_data.wave_length; |
| 74 | cassette_output(cassette_device_image(machine), state->cass_data.output.level ? -1.0 : +1.0); |
| 75 | state->cass_data.output.length = state->cass_data.wave_length; |
| 116 | 76 | } |
| 117 | 77 | } |
| 118 | 78 | |
| r9669 | r9670 | |
| 157 | 117 | |
| 158 | 118 | static TIMER_CALLBACK( z80ne_kbd_scan ) |
| 159 | 119 | { |
| 120 | z80ne_state *state = machine->driver_data<z80ne_state>(); |
| 160 | 121 | /* |
| 161 | 122 | * NE555 is connected to a 74LS93 binary counter |
| 162 | 123 | * 74LS93 output: |
| r9669 | r9670 | |
| 181 | 142 | UINT8 i; |
| 182 | 143 | |
| 183 | 144 | /* 4-bit counter */ |
| 184 | | --lx383_scan_counter; |
| 185 | | lx383_scan_counter &= 0x0f; |
| 145 | --state->lx383_scan_counter; |
| 146 | state->lx383_scan_counter &= 0x0f; |
| 186 | 147 | |
| 187 | | if ( --lx383_downsampler == 0 ) |
| 148 | if ( --state->lx383_downsampler == 0 ) |
| 188 | 149 | { |
| 189 | | lx383_downsampler = LX383_DOWNSAMPLING; |
| 150 | state->lx383_downsampler = LX383_DOWNSAMPLING; |
| 190 | 151 | key_bits = (input_port_read(machine, "ROW1") << 8) | input_port_read(machine, "ROW0"); |
| 191 | 152 | rst = input_port_read(machine, "RST"); |
| 192 | 153 | ctrl = input_port_read(machine, "CTRL"); |
| 193 | 154 | |
| 194 | 155 | for ( i = 0; i<LX383_KEYS; i++) |
| 195 | 156 | { |
| 196 | | lx383_key[i] = ( i | (key_bits & 0x01 ? 0x80 : 0x00) | ~ctrl); |
| 157 | state->lx383_key[i] = ( i | (key_bits & 0x01 ? 0x80 : 0x00) | ~ctrl); |
| 197 | 158 | key_bits >>= 1; |
| 198 | 159 | } |
| 199 | 160 | } |
| r9669 | r9670 | |
| 208 | 169 | */ |
| 209 | 170 | DIRECT_UPDATE_HANDLER( z80ne_nmi_delay_count ) |
| 210 | 171 | { |
| 211 | | nmi_delay_counter--; |
| 172 | z80ne_state *state = machine->driver_data<z80ne_state>(); |
| 173 | state->nmi_delay_counter--; |
| 212 | 174 | |
| 213 | | if (!nmi_delay_counter) |
| 175 | if (!state->nmi_delay_counter) |
| 214 | 176 | { |
| 215 | 177 | cputag_get_address_space(machine, "z80ne", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(z80ne_default, *machine)); |
| 216 | 178 | cputag_set_input_line(machine, "z80ne", INPUT_LINE_NMI, PULSE_LINE); |
| r9669 | r9670 | |
| 224 | 186 | */ |
| 225 | 187 | DIRECT_UPDATE_HANDLER( z80ne_reset_delay_count ) |
| 226 | 188 | { |
| 189 | z80ne_state *state = machine->driver_data<z80ne_state>(); |
| 227 | 190 | address_space *space = cputag_get_address_space(machine, "z80ne", ADDRESS_SPACE_PROGRAM); |
| 228 | 191 | /* |
| 229 | 192 | * TODO: when debugger is active, his memory access causes this callback |
| 230 | 193 | * |
| 231 | 194 | */ |
| 232 | 195 | if(!space->debugger_access()) |
| 233 | | reset_delay_counter--; |
| 196 | state->reset_delay_counter--; |
| 234 | 197 | |
| 235 | | if (!reset_delay_counter) |
| 198 | if (!state->reset_delay_counter) |
| 236 | 199 | { |
| 237 | 200 | /* remove this callback */ |
| 238 | 201 | cputag_get_address_space(machine, "z80ne", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(z80ne_default, *machine)); |
| r9669 | r9670 | |
| 244 | 207 | |
| 245 | 208 | static void reset_lx388(running_machine *machine) |
| 246 | 209 | { |
| 247 | | lx388_kr2376 = machine->device("lx388_kr2376"); |
| 248 | | kr2376_set_input_pin( lx388_kr2376, KR2376_DSII, 0); |
| 249 | | kr2376_set_input_pin( lx388_kr2376, KR2376_PII, 0); |
| 210 | z80ne_state *state = machine->driver_data<z80ne_state>(); |
| 211 | state->lx388_kr2376 = machine->device("lx388_kr2376"); |
| 212 | kr2376_set_input_pin( state->lx388_kr2376, KR2376_DSII, 0); |
| 213 | kr2376_set_input_pin( state->lx388_kr2376, KR2376_PII, 0); |
| 250 | 214 | } |
| 251 | 215 | |
| 252 | 216 | static void reset_lx382_banking(running_machine *machine) |
| 253 | 217 | { |
| 218 | z80ne_state *state = machine->driver_data<z80ne_state>(); |
| 254 | 219 | address_space *space = cputag_get_address_space(machine, "z80ne", ADDRESS_SPACE_PROGRAM); |
| 255 | 220 | |
| 256 | 221 | /* switch to ROM bank at address 0x0000 */ |
| r9669 | r9670 | |
| 258 | 223 | memory_set_bank(machine, "bank2", 0); /* ep382 at 0x8000 */ |
| 259 | 224 | |
| 260 | 225 | /* after the first 3 bytes have been read from ROM, switch the RAM back in */ |
| 261 | | reset_delay_counter = 2; |
| 226 | state->reset_delay_counter = 2; |
| 262 | 227 | space->set_direct_update_handler(direct_update_delegate_create_static(z80ne_reset_delay_count, *machine)); |
| 263 | 228 | } |
| 264 | 229 | |
| 265 | 230 | static void reset_lx390_banking(running_machine *machine) |
| 266 | 231 | { |
| 232 | z80ne_state *state = machine->driver_data<z80ne_state>(); |
| 267 | 233 | address_space *space = cputag_get_address_space(machine, "z80ne", ADDRESS_SPACE_PROGRAM); |
| 268 | | reset_delay_counter = 0; |
| 234 | state->reset_delay_counter = 0; |
| 269 | 235 | |
| 270 | 236 | switch (input_port_read(machine, "CONFIG") & 0x07) { |
| 271 | 237 | case 0x01: /* EP382 Hex Monitor */ |
| r9669 | r9670 | |
| 276 | 242 | memory_set_bank(machine, "bank3", 1); /* ep382 at 0x8000 */ |
| 277 | 243 | memory_set_bank(machine, "bank4", 0); /* RAM at 0xF000 */ |
| 278 | 244 | /* after the first 3 bytes have been read from ROM, switch the RAM back in */ |
| 279 | | reset_delay_counter = 2; |
| 245 | state->reset_delay_counter = 2; |
| 280 | 246 | space->set_direct_update_handler(direct_update_delegate_create_static(z80ne_reset_delay_count, *machine)); |
| 281 | 247 | break; |
| 282 | 248 | case 0x02: /* EP548 16k BASIC */ |
| r9669 | r9670 | |
| 324 | 290 | |
| 325 | 291 | static MACHINE_RESET(z80ne_base) |
| 326 | 292 | { |
| 293 | z80ne_state *state = machine->driver_data<z80ne_state>(); |
| 327 | 294 | int i; |
| 328 | 295 | address_space *space = cputag_get_address_space(machine, "z80ne", ADDRESS_SPACE_PROGRAM); |
| 329 | 296 | |
| 330 | 297 | LOG(("In MACHINE_RESET z80ne_base\n")); |
| 331 | 298 | |
| 332 | 299 | for ( i=0; i<LX383_KEYS; i++) |
| 333 | | lx383_key[i] = 0xf0 | i; |
| 334 | | lx383_scan_counter = 0x0f; |
| 335 | | lx383_downsampler = LX383_DOWNSAMPLING; |
| 300 | state->lx383_key[i] = 0xf0 | i; |
| 301 | state->lx383_scan_counter = 0x0f; |
| 302 | state->lx383_downsampler = LX383_DOWNSAMPLING; |
| 336 | 303 | |
| 337 | 304 | /* Initialize cassette interface */ |
| 338 | 305 | switch(input_port_read(machine, "LX.385") & 0x07) |
| 339 | 306 | { |
| 340 | 307 | case 0x01: |
| 341 | | cass_data.speed = TAPE_300BPS; |
| 342 | | cass_data.wave_filter = LX385_TAPE_SAMPLE_FREQ / 1600; |
| 343 | | cass_data.wave_short = LX385_TAPE_SAMPLE_FREQ / (2400 * 2); |
| 344 | | cass_data.wave_long = LX385_TAPE_SAMPLE_FREQ / (1200 * 2); |
| 308 | state->cass_data.speed = TAPE_300BPS; |
| 309 | state->cass_data.wave_filter = LX385_TAPE_SAMPLE_FREQ / 1600; |
| 310 | state->cass_data.wave_short = LX385_TAPE_SAMPLE_FREQ / (2400 * 2); |
| 311 | state->cass_data.wave_long = LX385_TAPE_SAMPLE_FREQ / (1200 * 2); |
| 345 | 312 | break; |
| 346 | 313 | case 0x02: |
| 347 | | cass_data.speed = TAPE_600BPS; |
| 348 | | cass_data.wave_filter = LX385_TAPE_SAMPLE_FREQ / 3200; |
| 349 | | cass_data.wave_short = LX385_TAPE_SAMPLE_FREQ / (4800 * 2); |
| 350 | | cass_data.wave_long = LX385_TAPE_SAMPLE_FREQ / (2400 * 2); |
| 314 | state->cass_data.speed = TAPE_600BPS; |
| 315 | state->cass_data.wave_filter = LX385_TAPE_SAMPLE_FREQ / 3200; |
| 316 | state->cass_data.wave_short = LX385_TAPE_SAMPLE_FREQ / (4800 * 2); |
| 317 | state->cass_data.wave_long = LX385_TAPE_SAMPLE_FREQ / (2400 * 2); |
| 351 | 318 | break; |
| 352 | 319 | case 0x04: |
| 353 | | cass_data.speed = TAPE_1200BPS; |
| 354 | | cass_data.wave_filter = LX385_TAPE_SAMPLE_FREQ / 6400; |
| 355 | | cass_data.wave_short = LX385_TAPE_SAMPLE_FREQ / (9600 * 2); |
| 356 | | cass_data.wave_long = LX385_TAPE_SAMPLE_FREQ / (4800 * 2); |
| 320 | state->cass_data.speed = TAPE_1200BPS; |
| 321 | state->cass_data.wave_filter = LX385_TAPE_SAMPLE_FREQ / 6400; |
| 322 | state->cass_data.wave_short = LX385_TAPE_SAMPLE_FREQ / (9600 * 2); |
| 323 | state->cass_data.wave_long = LX385_TAPE_SAMPLE_FREQ / (4800 * 2); |
| 357 | 324 | } |
| 358 | | cass_data.wave_length = cass_data.wave_short; |
| 359 | | cass_data.output.length = cass_data.wave_length; |
| 360 | | cass_data.output.level = 1; |
| 361 | | cass_data.input.length = 0; |
| 362 | | cass_data.input.bit = 1; |
| 325 | state->cass_data.wave_length = state->cass_data.wave_short; |
| 326 | state->cass_data.output.length = state->cass_data.wave_length; |
| 327 | state->cass_data.output.level = 1; |
| 328 | state->cass_data.input.length = 0; |
| 329 | state->cass_data.input.bit = 1; |
| 363 | 330 | |
| 364 | | z80ne_ay31015 = machine->device("ay_3_1015"); |
| 365 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_CS, 0 ); |
| 366 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_NB1, 1 ); |
| 367 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_NB2, 1 ); |
| 368 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_TSB, 1 ); |
| 369 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_EPS, 1 ); |
| 370 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_NP, input_port_read(machine, "LX.385") & 0x80 ? 1 : 0 ); |
| 371 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_CS, 1 ); |
| 372 | | ay31015_set_receiver_clock( z80ne_ay31015, cass_data.speed * 16.0); |
| 373 | | ay31015_set_transmitter_clock( z80ne_ay31015, cass_data.speed * 16.0); |
| 331 | state->ay31015 = machine->device("ay_3_1015"); |
| 332 | ay31015_set_input_pin( state->ay31015, AY31015_CS, 0 ); |
| 333 | ay31015_set_input_pin( state->ay31015, AY31015_NB1, 1 ); |
| 334 | ay31015_set_input_pin( state->ay31015, AY31015_NB2, 1 ); |
| 335 | ay31015_set_input_pin( state->ay31015, AY31015_TSB, 1 ); |
| 336 | ay31015_set_input_pin( state->ay31015, AY31015_EPS, 1 ); |
| 337 | ay31015_set_input_pin( state->ay31015, AY31015_NP, input_port_read(machine, "LX.385") & 0x80 ? 1 : 0 ); |
| 338 | ay31015_set_input_pin( state->ay31015, AY31015_CS, 1 ); |
| 339 | ay31015_set_receiver_clock( state->ay31015, state->cass_data.speed * 16.0); |
| 340 | ay31015_set_transmitter_clock( state->ay31015, state->cass_data.speed * 16.0); |
| 374 | 341 | |
| 375 | | nmi_delay_counter = 0; |
| 342 | state->nmi_delay_counter = 0; |
| 376 | 343 | lx385_ctrl_w(space, 0, 0); |
| 377 | 344 | |
| 378 | 345 | } |
| r9669 | r9670 | |
| 431 | 398 | |
| 432 | 399 | MACHINE_START( z80ne ) |
| 433 | 400 | { |
| 401 | z80ne_state *state = machine->driver_data<z80ne_state>(); |
| 434 | 402 | LOG(("In MACHINE_START z80ne\n")); |
| 435 | | lx385_ctrl = 0x1f; |
| 436 | | state_save_register_item( machine, "z80ne", NULL, 0, lx383_scan_counter ); |
| 437 | | state_save_register_item( machine, "z80ne", NULL, 0, lx383_downsampler ); |
| 438 | | state_save_register_item_array( machine, "z80ne", NULL, 0, lx383_key ); |
| 439 | | state_save_register_item( machine, "z80ne", NULL, 0, nmi_delay_counter ); |
| 440 | | cassette_timer = timer_alloc(machine, z80ne_cassette_tc, NULL); |
| 403 | state->lx385_ctrl = 0x1f; |
| 404 | state_save_register_item( machine, "z80ne", NULL, 0, state->lx383_scan_counter ); |
| 405 | state_save_register_item( machine, "z80ne", NULL, 0, state->lx383_downsampler ); |
| 406 | state_save_register_item_array( machine, "z80ne", NULL, 0, state->lx383_key ); |
| 407 | state_save_register_item( machine, "z80ne", NULL, 0, state->nmi_delay_counter ); |
| 408 | state->cassette_timer = timer_alloc(machine, z80ne_cassette_tc, NULL); |
| 441 | 409 | timer_pulse( machine, ATTOTIME_IN_HZ(1000), NULL, 0, z80ne_kbd_scan ); |
| 442 | 410 | } |
| 443 | 411 | |
| r9669 | r9670 | |
| 466 | 434 | /* LX.383 - LX.384 HEX keyboard and display */ |
| 467 | 435 | READ8_HANDLER( lx383_r ) |
| 468 | 436 | { |
| 437 | z80ne_state *state = space->machine->driver_data<z80ne_state>(); |
| 469 | 438 | /* |
| 470 | 439 | * Keyboard scanning |
| 471 | 440 | * |
| r9669 | r9670 | |
| 483 | 452 | * D6 - 0 |
| 484 | 453 | * D7 - ~KEY Pressed |
| 485 | 454 | */ |
| 486 | | return lx383_key[lx383_scan_counter]; |
| 455 | return state->lx383_key[state->lx383_scan_counter]; |
| 487 | 456 | } |
| 488 | 457 | |
| 489 | 458 | WRITE8_HANDLER( lx383_w ) |
| 490 | 459 | { |
| 460 | z80ne_state *state = space->machine->driver_data<z80ne_state>(); |
| 491 | 461 | /* |
| 492 | 462 | * First 8 locations (F0-F7) are mapped to a dual-port 8-byte RAM |
| 493 | 463 | * The 1KHz NE-555 astable oscillator circuit drive |
| r9669 | r9670 | |
| 517 | 487 | output_set_digit_value( offset, data ^ 0xff ); |
| 518 | 488 | else |
| 519 | 489 | /* after writing to port 0xF8 and the first ~M1 cycles strike a NMI for single step execution */ |
| 520 | | nmi_delay_counter = 1; |
| 490 | state->nmi_delay_counter = 1; |
| 521 | 491 | cputag_get_address_space(space->machine, "z80ne", ADDRESS_SPACE_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(z80ne_nmi_delay_count, *space->machine)); |
| 522 | 492 | } |
| 523 | 493 | |
| r9669 | r9670 | |
| 567 | 537 | */ |
| 568 | 538 | READ8_HANDLER(lx385_data_r) |
| 569 | 539 | { |
| 570 | | return ay31015_get_received_data( z80ne_ay31015 ); |
| 540 | z80ne_state *state = space->machine->driver_data<z80ne_state>(); |
| 541 | return ay31015_get_received_data( state->ay31015 ); |
| 571 | 542 | } |
| 572 | 543 | |
| 573 | 544 | READ8_HANDLER(lx385_ctrl_r) |
| 574 | 545 | { |
| 546 | z80ne_state *state = space->machine->driver_data<z80ne_state>(); |
| 575 | 547 | /* set unused bits high */ |
| 576 | 548 | UINT8 data = 0xc0; |
| 577 | 549 | |
| 578 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_SWE, 0 ); |
| 579 | | data |= (ay31015_get_output_pin( z80ne_ay31015, AY31015_OR ) ? 0x01 : 0); |
| 580 | | data |= (ay31015_get_output_pin( z80ne_ay31015, AY31015_FE ) ? 0x02 : 0); |
| 581 | | data |= (ay31015_get_output_pin( z80ne_ay31015, AY31015_PE ) ? 0x04 : 0); |
| 582 | | data |= (ay31015_get_output_pin( z80ne_ay31015, AY31015_TBMT ) ? 0x08 : 0); |
| 583 | | data |= (ay31015_get_output_pin( z80ne_ay31015, AY31015_DAV ) ? 0x10 : 0); |
| 584 | | data |= (ay31015_get_output_pin( z80ne_ay31015, AY31015_EOC ) ? 0x20 : 0); |
| 585 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_SWE, 1 ); |
| 550 | ay31015_set_input_pin( state->ay31015, AY31015_SWE, 0 ); |
| 551 | data |= (ay31015_get_output_pin( state->ay31015, AY31015_OR ) ? 0x01 : 0); |
| 552 | data |= (ay31015_get_output_pin( state->ay31015, AY31015_FE ) ? 0x02 : 0); |
| 553 | data |= (ay31015_get_output_pin( state->ay31015, AY31015_PE ) ? 0x04 : 0); |
| 554 | data |= (ay31015_get_output_pin( state->ay31015, AY31015_TBMT ) ? 0x08 : 0); |
| 555 | data |= (ay31015_get_output_pin( state->ay31015, AY31015_DAV ) ? 0x10 : 0); |
| 556 | data |= (ay31015_get_output_pin( state->ay31015, AY31015_EOC ) ? 0x20 : 0); |
| 557 | ay31015_set_input_pin( state->ay31015, AY31015_SWE, 1 ); |
| 586 | 558 | |
| 587 | 559 | return data; |
| 588 | 560 | } |
| 589 | 561 | |
| 590 | 562 | WRITE8_HANDLER(lx385_data_w) |
| 591 | 563 | { |
| 592 | | ay31015_set_transmit_data( z80ne_ay31015, data ); |
| 564 | z80ne_state *state = space->machine->driver_data<z80ne_state>(); |
| 565 | ay31015_set_transmit_data( state->ay31015, data ); |
| 593 | 566 | } |
| 594 | 567 | |
| 595 | 568 | #define LX385_CASSETTE_MOTOR_MASK ((1<<3)|(1<<4)) |
| 596 | 569 | |
| 597 | 570 | WRITE8_HANDLER(lx385_ctrl_w) |
| 598 | 571 | { |
| 572 | z80ne_state *state = space->machine->driver_data<z80ne_state>(); |
| 599 | 573 | /* Translate data to control signals |
| 600 | 574 | * 0 bit1=0, bit0=0 UART Reset pulse |
| 601 | 575 | * 1 bit1=0, bit0=1 UART RDAV (Reset Data Available) pulse |
| r9669 | r9670 | |
| 605 | 579 | */ |
| 606 | 580 | UINT8 uart_reset, uart_rdav, uart_tx_clock; |
| 607 | 581 | UINT8 motor_a, motor_b; |
| 608 | | UINT8 changed_bits = (lx385_ctrl ^ data) & 0x1C; |
| 609 | | lx385_ctrl = data; |
| 582 | UINT8 changed_bits = (state->lx385_ctrl ^ data) & 0x1C; |
| 583 | state->lx385_ctrl = data; |
| 610 | 584 | |
| 611 | 585 | uart_reset = ((data & 0x03) == 0x00); |
| 612 | 586 | uart_rdav = ((data & 0x03) == 0x01); |
| r9669 | r9670 | |
| 617 | 591 | /* UART Reset and RDAV */ |
| 618 | 592 | if(uart_reset) |
| 619 | 593 | { |
| 620 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_XR, 1 ); |
| 621 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_XR, 0 ); |
| 594 | ay31015_set_input_pin( state->ay31015, AY31015_XR, 1 ); |
| 595 | ay31015_set_input_pin( state->ay31015, AY31015_XR, 0 ); |
| 622 | 596 | } |
| 623 | 597 | |
| 624 | 598 | if(uart_rdav) |
| 625 | 599 | { |
| 626 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_RDAV, 1 ); |
| 627 | | ay31015_set_input_pin( z80ne_ay31015, AY31015_RDAV, 0 ); |
| 600 | ay31015_set_input_pin( state->ay31015, AY31015_RDAV, 1 ); |
| 601 | ay31015_set_input_pin( state->ay31015, AY31015_RDAV, 0 ); |
| 628 | 602 | } |
| 629 | 603 | |
| 630 | 604 | if (!changed_bits) return; |
| 631 | 605 | |
| 632 | 606 | /* UART Tx Clock enable/disable */ |
| 633 | 607 | if(changed_bits & 0x04) |
| 634 | | ay31015_set_transmitter_clock( z80ne_ay31015, uart_tx_clock ? cass_data.speed * 16.0 : 0.0); |
| 608 | ay31015_set_transmitter_clock( state->ay31015, uart_tx_clock ? state->cass_data.speed * 16.0 : 0.0); |
| 635 | 609 | |
| 636 | 610 | /* motors */ |
| 637 | 611 | if(changed_bits & 0x18) |
| r9669 | r9670 | |
| 643 | 617 | (motor_b) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR); |
| 644 | 618 | |
| 645 | 619 | if (motor_a || motor_b) |
| 646 | | timer_adjust_periodic(cassette_timer, attotime_zero, 0, ATTOTIME_IN_HZ(LX385_TAPE_SAMPLE_FREQ)); |
| 620 | timer_adjust_periodic(state->cassette_timer, attotime_zero, 0, ATTOTIME_IN_HZ(LX385_TAPE_SAMPLE_FREQ)); |
| 647 | 621 | else |
| 648 | | timer_adjust_oneshot(cassette_timer, attotime_zero, 0); |
| 622 | timer_adjust_oneshot(state->cassette_timer, attotime_zero, 0); |
| 649 | 623 | } |
| 650 | 624 | } |
| 651 | 625 | |
| r9669 | r9670 | |
| 671 | 645 | |
| 672 | 646 | READ8_HANDLER(lx388_data_r) |
| 673 | 647 | { |
| 648 | z80ne_state *state = space->machine->driver_data<z80ne_state>(); |
| 674 | 649 | UINT8 data; |
| 675 | 650 | |
| 676 | | data = kr2376_data_r(lx388_kr2376, 0) & 0x7f; |
| 677 | | data |= kr2376_get_output_pin(lx388_kr2376, KR2376_SO) << 7; |
| 651 | data = kr2376_data_r(state->lx388_kr2376, 0) & 0x7f; |
| 652 | data |= kr2376_get_output_pin(state->lx388_kr2376, KR2376_SO) << 7; |
| 678 | 653 | return data; |
| 679 | 654 | } |
| 680 | 655 | |
| r9669 | r9670 | |
| 695 | 670 | |
| 696 | 671 | WRITE8_DEVICE_HANDLER(lx390_motor_w) |
| 697 | 672 | { |
| 673 | z80ne_state *state = device->machine->driver_data<z80ne_state>(); |
| 698 | 674 | /* Selection of drive and parameters |
| 699 | 675 | A write also causes the selected drive motor to turn on for about 3 seconds. |
| 700 | 676 | When the motor turns off, the drive is deselected. |
| r9669 | r9670 | |
| 721 | 697 | if (data & 8) |
| 722 | 698 | drive = 3; |
| 723 | 699 | |
| 724 | | wd17xx_state.head = (data & 32) ? 1 : 0; |
| 725 | | wd17xx_state.drive = data & 0x0F; |
| 700 | state->wd17xx_state.head = (data & 32) ? 1 : 0; |
| 701 | state->wd17xx_state.drive = data & 0x0F; |
| 726 | 702 | |
| 727 | 703 | /* no drive selected, turn off all leds */ |
| 728 | | if (!wd17xx_state.drive) |
| 704 | if (!state->wd17xx_state.drive) |
| 729 | 705 | { |
| 730 | 706 | output_set_value("drv0", 0); |
| 731 | 707 | output_set_value("drv1", 0); |
| r9669 | r9670 | |
| 735 | 711 | { |
| 736 | 712 | LOG(("lx390_motor_w, set drive %1d\n", drive)); |
| 737 | 713 | wd17xx_set_drive(device,drive); |
| 738 | | LOG(("lx390_motor_w, set side %1d\n", wd17xx_state.head)); |
| 739 | | wd17xx_set_side(device, wd17xx_state.head); |
| 714 | LOG(("lx390_motor_w, set side %1d\n", state->wd17xx_state.head)); |
| 715 | wd17xx_set_side(device, state->wd17xx_state.head); |
| 740 | 716 | } |
| 741 | 717 | } |
| 742 | 718 | |
| r9669 | r9670 | |
| 796 | 772 | |
| 797 | 773 | WRITE8_DEVICE_HANDLER(lx390_fdc_w) |
| 798 | 774 | { |
| 775 | z80ne_state *state = device->machine->driver_data<z80ne_state>(); |
| 799 | 776 | UINT8 d; |
| 800 | 777 | |
| 801 | 778 | d = data; |
| r9669 | r9670 | |
| 804 | 781 | case 0: |
| 805 | 782 | LOG(("lx390_fdc_w, WD17xx command: %02x\n", d)); |
| 806 | 783 | wd17xx_command_w(device, offset, d); |
| 807 | | if (wd17xx_state.drive & 1) |
| 784 | if (state->wd17xx_state.drive & 1) |
| 808 | 785 | output_set_value("drv0", 2); |
| 809 | | else if (wd17xx_state.drive & 2) |
| 786 | else if (state->wd17xx_state.drive & 2) |
| 810 | 787 | output_set_value("drv1", 2); |
| 811 | 788 | break; |
| 812 | 789 | case 1: |
src/mess/machine/mac.c
| r9669 | r9670 | |
| 143 | 143 | static TIMER_CALLBACK(mac_adb_tick); |
| 144 | 144 | static TIMER_CALLBACK(mac_6015_tick); |
| 145 | 145 | static TIMER_CALLBACK(mac_pmu_tick); |
| 146 | | static emu_timer *mac_scanline_timer, *mac_adb_timer; |
| 147 | 146 | static int scan_keyboard(running_machine *machine); |
| 148 | 147 | static TIMER_CALLBACK(inquiry_timeout_func); |
| 149 | 148 | static void keyboard_receive(running_machine *machine, int val); |
| r9669 | r9670 | |
| 257 | 256 | Interrupt handling |
| 258 | 257 | */ |
| 259 | 258 | |
| 260 | | void mac_state::field_interrupts(running_machine *machine) |
| 259 | void mac_state::field_interrupts() |
| 261 | 260 | { |
| 262 | 261 | int take_interrupt = -1; |
| 263 | 262 | |
| r9669 | r9670 | |
| 305 | 304 | } |
| 306 | 305 | } |
| 307 | 306 | |
| 308 | | void mac_state::set_scc_interrupt(running_machine *machine, int value) |
| 307 | void mac_state::set_scc_interrupt(int value) |
| 309 | 308 | { |
| 310 | 309 | m_scc_interrupt = value; |
| 311 | | field_interrupts(machine); |
| 310 | this->field_interrupts(); |
| 312 | 311 | } |
| 313 | 312 | |
| 314 | | void mac_state::set_via_interrupt(running_machine *machine, int value) |
| 313 | void mac_state::set_via_interrupt(int value) |
| 315 | 314 | { |
| 316 | 315 | m_via_interrupt = value; |
| 317 | | field_interrupts(machine); |
| 316 | this->field_interrupts(); |
| 318 | 317 | } |
| 319 | 318 | |
| 320 | 319 | |
| 321 | | void mac_state::set_via2_interrupt(running_machine *machine, int value) |
| 320 | void mac_state::set_via2_interrupt(int value) |
| 322 | 321 | { |
| 323 | 322 | m_via2_interrupt = value; |
| 324 | | field_interrupts(machine); |
| 323 | this->field_interrupts(); |
| 325 | 324 | } |
| 326 | 325 | |
| 327 | 326 | void mac_asc_irq(running_device *device, int state) |
| r9669 | r9670 | |
| 337 | 336 | if (mac->m_rbv_ier & 0x10) // ASC on RBV is CB1, bit 4 of IER/IFR |
| 338 | 337 | { |
| 339 | 338 | mac->m_rbv_ifr |= 0x90; |
| 340 | | mac->set_via2_interrupt(device->machine, 1); |
| 339 | mac->set_via2_interrupt(1); |
| 341 | 340 | } |
| 342 | 341 | } |
| 343 | 342 | else |
| r9669 | r9670 | |
| 384 | 383 | /* Not Yet Implemented */ |
| 385 | 384 | } |
| 386 | 385 | |
| 387 | | void mac_state::v8_resize(running_machine *machine) |
| 386 | void mac_state::v8_resize() |
| 388 | 387 | { |
| 389 | 388 | offs_t memory_size; |
| 390 | 389 | UINT8 *memory_data; |
| r9669 | r9670 | |
| 459 | 458 | } |
| 460 | 459 | } |
| 461 | 460 | |
| 462 | | void mac_state::set_memory_overlay(running_machine *machine, int overlay) |
| 461 | void mac_state::set_memory_overlay(int overlay) |
| 463 | 462 | { |
| 464 | 463 | offs_t memory_size; |
| 465 | 464 | UINT8 *memory_data; |
| r9669 | r9670 | |
| 490 | 489 | if (((m_model >= MODEL_MAC_LC) && (m_model <= MODEL_MAC_COLOR_CLASSIC) && ((m_model != MODEL_MAC_LC_III) && (m_model != MODEL_MAC_LC_III_PLUS))) || (m_model == MODEL_MAC_CLASSIC_II)) |
| 491 | 490 | { |
| 492 | 491 | m_overlay = overlay; |
| 493 | | v8_resize(machine); |
| 492 | this->v8_resize(); |
| 494 | 493 | } |
| 495 | 494 | else if ((m_model >= MODEL_MAC_POWERMAC_6100) && (m_model >= MODEL_MAC_POWERMAC_8100)) |
| 496 | 495 | { |
| r9669 | r9670 | |
| 843 | 842 | * Mouse |
| 844 | 843 | * *************************************************************************/ |
| 845 | 844 | |
| 846 | | static void mouse_callback(running_machine *machine) |
| 845 | void mac_state::mouse_callback() |
| 847 | 846 | { |
| 848 | | static int last_mx = 0, last_my = 0; |
| 849 | | static int count_x = 0, count_y = 0; |
| 850 | 847 | int new_mx, new_my; |
| 851 | 848 | int x_needs_update = 0, y_needs_update = 0; |
| 852 | 849 | mac_state *mac = machine->driver_data<mac_state>(); |
| r9669 | r9670 | |
| 917 | 914 | |
| 918 | 915 | if (x_needs_update || y_needs_update) |
| 919 | 916 | /* assert Port B External Interrupt on the SCC */ |
| 920 | | mac->scc_mouse_irq(machine, x_needs_update, y_needs_update ); |
| 917 | mac->scc_mouse_irq(x_needs_update, y_needs_update ); |
| 921 | 918 | } |
| 922 | 919 | |
| 923 | 920 | /* ************************************************************************* |
| r9669 | r9670 | |
| 1072 | 1069 | if ((mac->m_scsiirq_enable) && ((mac->m_model == MODEL_MAC_SE) || (mac->m_model == MODEL_MAC_CLASSIC))) |
| 1073 | 1070 | { |
| 1074 | 1071 | mac->m_scsi_interrupt = state; |
| 1075 | | mac->field_interrupts(machine); |
| 1072 | mac->field_interrupts(); |
| 1076 | 1073 | } |
| 1077 | 1074 | } |
| 1078 | 1075 | |
| r9669 | r9670 | |
| 1086 | 1083 | { |
| 1087 | 1084 | mac_state *mac = device->machine->driver_data<mac_state>(); |
| 1088 | 1085 | |
| 1089 | | mac->set_scc_interrupt(device->machine, status); |
| 1086 | mac->set_scc_interrupt(status); |
| 1090 | 1087 | } |
| 1091 | 1088 | |
| 1092 | 1089 | |
| 1093 | 1090 | |
| 1094 | | void mac_state::scc_mouse_irq(running_machine *machine, int x, int y) |
| 1091 | void mac_state::scc_mouse_irq(int x, int y) |
| 1095 | 1092 | { |
| 1096 | 1093 | running_device *scc = machine->device("scc"); |
| 1097 | | static int last_was_x = 0; |
| 1098 | 1094 | if (x && y) |
| 1099 | 1095 | { |
| 1100 | 1096 | if (last_was_x) |
| r9669 | r9670 | |
| 1113 | 1109 | } |
| 1114 | 1110 | |
| 1115 | 1111 | //cputag_set_input_line(machine, "maincpu", 2, ASSERT_LINE); |
| 1116 | | set_scc_interrupt(machine, 1); |
| 1112 | this->set_scc_interrupt(1); |
| 1117 | 1113 | } |
| 1118 | 1114 | |
| 1119 | 1115 | |
| r9669 | r9670 | |
| 1520 | 1516 | static const char *const adb_statenames[4] = { "NEW", "EVEN", "ODD", "IDLE" }; |
| 1521 | 1517 | #endif |
| 1522 | 1518 | |
| 1523 | | int mac_state::adb_pollkbd(running_machine *machine, int update) |
| 1519 | int mac_state::adb_pollkbd(int update) |
| 1524 | 1520 | { |
| 1525 | 1521 | int i, j, keybuf, report, codes[2], result; |
| 1526 | 1522 | static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5" }; |
| r9669 | r9670 | |
| 1649 | 1645 | return result; |
| 1650 | 1646 | } |
| 1651 | 1647 | |
| 1652 | | int mac_state::adb_pollmouse(running_machine *machine) |
| 1648 | int mac_state::adb_pollmouse() |
| 1653 | 1649 | { |
| 1654 | 1650 | int NewX, NewY, NewButton; |
| 1655 | 1651 | |
| r9669 | r9670 | |
| 1670 | 1666 | return 0; |
| 1671 | 1667 | } |
| 1672 | 1668 | |
| 1673 | | void mac_state::adb_accummouse( running_machine *machine, UINT8 *MouseX, UINT8 *MouseY ) |
| 1669 | void mac_state::adb_accummouse( UINT8 *MouseX, UINT8 *MouseY ) |
| 1674 | 1670 | { |
| 1675 | 1671 | int MouseCountX = 0, MouseCountY = 0; |
| 1676 | 1672 | int NewX, NewY; |
| r9669 | r9670 | |
| 1714 | 1710 | *MouseY = (UINT8)MouseCountY; |
| 1715 | 1711 | } |
| 1716 | 1712 | |
| 1717 | | void mac_state::adb_talk(running_machine *machine) |
| 1713 | void mac_state::adb_talk() |
| 1718 | 1714 | { |
| 1719 | 1715 | int addr, reg; |
| 1720 | 1716 | |
| r9669 | r9670 | |
| 1792 | 1788 | } |
| 1793 | 1789 | else |
| 1794 | 1790 | { |
| 1795 | | adb_accummouse(machine, &mouseX, &mouseY); |
| 1791 | this->adb_accummouse(&mouseX, &mouseY); |
| 1796 | 1792 | } |
| 1797 | 1793 | m_adb_buffer[0] = (m_adb_lastbutton & 0x01) ? 0x00 : 0x80; |
| 1798 | 1794 | m_adb_buffer[0] |= mouseX & 0x7f; |
| r9669 | r9670 | |
| 1829 | 1825 | } |
| 1830 | 1826 | else |
| 1831 | 1827 | { |
| 1832 | | adb_pollkbd(machine, 1); |
| 1828 | this->adb_pollkbd(1); |
| 1833 | 1829 | } |
| 1834 | 1830 | // printf("keyboard = %02x %02x\n", m_adb_currentkeys[0], m_adb_currentkeys[1]); |
| 1835 | 1831 | m_adb_buffer[0] = m_adb_currentkeys[1]; |
| r9669 | r9670 | |
| 1839 | 1835 | |
| 1840 | 1836 | // read modifier keys |
| 1841 | 1837 | case 2: |
| 1842 | | adb_pollkbd(machine, 1); |
| 1838 | this->adb_pollkbd(1); |
| 1843 | 1839 | m_adb_buffer[0] = m_adb_modifiers; // nothing pressed |
| 1844 | 1840 | m_adb_buffer[1] = 0; |
| 1845 | 1841 | m_adb_datasize = 2; |
| r9669 | r9670 | |
| 1913 | 1909 | mac->m_adb_timer_ticks--; |
| 1914 | 1910 | if (!mac->m_adb_timer_ticks) |
| 1915 | 1911 | { |
| 1916 | | timer_adjust_oneshot(mac_adb_timer, attotime_never, 0); |
| 1912 | timer_adjust_oneshot(mac->adb_timer, attotime_never, 0); |
| 1917 | 1913 | |
| 1918 | 1914 | if ((mac->m_adb_direction) && (ADB_IS_BITBANG)) |
| 1919 | 1915 | { |
| 1920 | | mac->adb_talk(machine); |
| 1916 | mac->adb_talk(); |
| 1921 | 1917 | } |
| 1922 | 1918 | else if (ADB_IS_EGRET) |
| 1923 | 1919 | { |
| r9669 | r9670 | |
| 1961 | 1957 | } |
| 1962 | 1958 | |
| 1963 | 1959 | // mac->m_adb_timer_ticks = 8; |
| 1964 | | // timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 1960 | // timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 1965 | 1961 | |
| 1966 | 1962 | if ((mac->m_adb_datasize == 0) && (mac->m_adb_streaming == MCU_STREAMING_NONE)) |
| 1967 | 1963 | { |
| r9669 | r9670 | |
| 1987 | 1983 | } |
| 1988 | 1984 | else |
| 1989 | 1985 | { |
| 1990 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(200)), 0); |
| 1986 | timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(200)), 0); |
| 1991 | 1987 | } |
| 1992 | 1988 | } |
| 1993 | 1989 | |
| r9669 | r9670 | |
| 2031 | 2027 | mac->m_adb_direction = 1; // Mac is shifting us a command |
| 2032 | 2028 | mac->m_adb_waiting_cmd = 1; // we're going to get a command |
| 2033 | 2029 | mac->m_adb_irq_pending = 0; |
| 2034 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2030 | timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2035 | 2031 | break; |
| 2036 | 2032 | |
| 2037 | 2033 | case ADB_STATE_XFER_EVEN: |
| r9669 | r9670 | |
| 2061 | 2057 | mac->m_adb_irq_pending = 1; |
| 2062 | 2058 | } |
| 2063 | 2059 | |
| 2064 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2060 | timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2065 | 2061 | break; |
| 2066 | 2062 | |
| 2067 | 2063 | case ADB_STATE_IDLE: |
| r9669 | r9670 | |
| 2080 | 2076 | mac->m_adb_state |= 1; |
| 2081 | 2077 | mac->m_adb_timer_ticks = 8; |
| 2082 | 2078 | mac->m_adb_datasize = 3; |
| 2083 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2079 | timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2084 | 2080 | } |
| 2085 | 2081 | |
| 2086 | 2082 | static void mac_egret_response_adb(mac_state *mac, int type, int flag, int cmd, int extra) |
| r9669 | r9670 | |
| 2093 | 2089 | mac->m_adb_state |= 1; |
| 2094 | 2090 | mac->m_adb_timer_ticks = 8; |
| 2095 | 2091 | mac->m_adb_datasize = 4; |
| 2096 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2092 | timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2097 | 2093 | } |
| 2098 | 2094 | |
| 2099 | 2095 | static void mac_egret_response_read_pram(mac_state *mac, int cmd, int addr) |
| r9669 | r9670 | |
| 2108 | 2104 | |
| 2109 | 2105 | mac->m_adb_state |= 1; |
| 2110 | 2106 | mac->m_adb_timer_ticks = 8; |
| 2111 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2107 | timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2112 | 2108 | |
| 2113 | 2109 | // read PRAM is a "streaming" command, don't drop the state line when we're out of data |
| 2114 | 2110 | mac->m_adb_streaming = MCU_STREAMING_PRAMRD; |
| r9669 | r9670 | |
| 2130 | 2126 | |
| 2131 | 2127 | mac->m_adb_state |= 1; |
| 2132 | 2128 | mac->m_adb_timer_ticks = 8; |
| 2133 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2129 | timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2134 | 2130 | } |
| 2135 | 2131 | |
| 2136 | 2132 | static void mac_egret_mcu_exec(mac_state *mac) |
| r9669 | r9670 | |
| 2233 | 2229 | mac->m_adb_buffer[1] = 0; // spare |
| 2234 | 2230 | mac->m_adb_state |= 1; |
| 2235 | 2231 | mac->m_adb_timer_ticks = 8; |
| 2236 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2232 | timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2237 | 2233 | break; |
| 2238 | 2234 | |
| 2239 | 2235 | case 0x0e: // send to DFAC |
| r9669 | r9670 | |
| 2303 | 2299 | { |
| 2304 | 2300 | mac->m_adb_command = 0; |
| 2305 | 2301 | mac->m_adb_timer_ticks = 8; |
| 2306 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2302 | timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2307 | 2303 | } |
| 2308 | 2304 | |
| 2309 | 2305 | // if bit 2 is high and stays high, the falling edge of bit 1, and we're in send phase, the MCU should clock out a byte |
| 2310 | 2306 | if ((state & 0x04) && (mac->m_adb_state & 0x04) && !(state & 0x02) && (mac->m_adb_state & 0x02) && (mac->m_adb_state & 0x01)) |
| 2311 | 2307 | { |
| 2312 | 2308 | mac->m_adb_timer_ticks = 8; |
| 2313 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2309 | timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2314 | 2310 | } |
| 2315 | 2311 | |
| 2316 | 2312 | // if bit 2 rises, bit 1 is 0, and MCU XS is high, the MCU should clock out a byte |
| 2317 | 2313 | if ((state & 0x04) && !(mac->m_adb_state & 0x04) && !(state & 0x02) && (mac->m_adb_state & 0x01)) |
| 2318 | 2314 | { |
| 2319 | 2315 | mac->m_adb_timer_ticks = 8; |
| 2320 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2316 | timer_adjust_oneshot(mac->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2321 | 2317 | } |
| 2322 | 2318 | |
| 2323 | 2319 | // if bit 2 drops and bit 1 is 1, terminate the command |
| r9669 | r9670 | |
| 2506 | 2502 | } |
| 2507 | 2503 | } |
| 2508 | 2504 | |
| 2509 | | void mac_state::adb_vblank(running_machine *machine) |
| 2505 | void mac_state::adb_vblank() |
| 2510 | 2506 | { |
| 2511 | 2507 | if (m_adb_state == ADB_STATE_IDLE) |
| 2512 | 2508 | { |
| 2513 | | if (adb_pollmouse(machine)) |
| 2509 | if (this->adb_pollmouse()) |
| 2514 | 2510 | { |
| 2515 | 2511 | // if the mouse was the last TALK, we can just send the new data |
| 2516 | 2512 | // otherwise we need to pull SRQ |
| r9669 | r9670 | |
| 2518 | 2514 | { |
| 2519 | 2515 | // repeat last TALK to get updated data |
| 2520 | 2516 | m_adb_waiting_cmd = 1; |
| 2521 | | adb_talk(machine); |
| 2517 | this->adb_talk(); |
| 2522 | 2518 | |
| 2523 | 2519 | m_adb_timer_ticks = 8; |
| 2524 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2520 | timer_adjust_oneshot(this->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2525 | 2521 | } |
| 2526 | 2522 | else |
| 2527 | 2523 | { |
| 2528 | 2524 | m_adb_irq_pending = 1; |
| 2529 | 2525 | m_adb_command = m_adb_send = 0; |
| 2530 | 2526 | m_adb_timer_ticks = 1; // one tick should be sufficient to make it see the IRQ |
| 2531 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2527 | timer_adjust_oneshot(this->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2532 | 2528 | m_adb_srq_switch = 1; |
| 2533 | 2529 | } |
| 2534 | 2530 | } |
| 2535 | | else if (adb_pollkbd(machine, 0)) |
| 2531 | else if (this->adb_pollkbd(0)) |
| 2536 | 2532 | { |
| 2537 | 2533 | if (m_adb_last_talk == m_adb_keybaddr) |
| 2538 | 2534 | { |
| 2539 | 2535 | // repeat last TALK to get updated data |
| 2540 | 2536 | m_adb_waiting_cmd = 1; |
| 2541 | | adb_talk(machine); |
| 2537 | this->adb_talk(); |
| 2542 | 2538 | |
| 2543 | 2539 | m_adb_timer_ticks = 8; |
| 2544 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2540 | timer_adjust_oneshot(this->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2545 | 2541 | } |
| 2546 | 2542 | else |
| 2547 | 2543 | { |
| 2548 | 2544 | m_adb_irq_pending = 1; |
| 2549 | 2545 | m_adb_command = m_adb_send = 0; |
| 2550 | 2546 | m_adb_timer_ticks = 1; // one tick should be sufficient to make it see the IRQ |
| 2551 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2547 | timer_adjust_oneshot(this->adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 2552 | 2548 | m_adb_srq_switch = 1; |
| 2553 | 2549 | } |
| 2554 | 2550 | } |
| 2555 | 2551 | } |
| 2556 | 2552 | } |
| 2557 | 2553 | |
| 2558 | | void mac_state::adb_reset(running_machine *machine) |
| 2554 | void mac_state::adb_reset() |
| 2559 | 2555 | { |
| 2560 | 2556 | int i; |
| 2561 | 2557 | |
| r9669 | r9670 | |
| 2759 | 2755 | } |
| 2760 | 2756 | |
| 2761 | 2757 | set_scc_waitrequest((data & 0x80) >> 7); |
| 2762 | | mac_set_screen_buffer((data & 0x40) >> 6); |
| 2758 | mac->screen_buffer = (data & 0x40) >> 6; |
| 2763 | 2759 | sony_set_sel_line(fdc,(data & 0x20) >> 5); |
| 2764 | 2760 | if (mac->m_model == MODEL_MAC_SE) // on SE this selects which floppy drive (0 = upper, 1 = lower) |
| 2765 | 2761 | { |
| r9669 | r9670 | |
| 2781 | 2777 | * first access to the ROM. */ |
| 2782 | 2778 | if (mac->m_model < MODEL_MAC_SE) |
| 2783 | 2779 | { |
| 2784 | | mac->set_memory_overlay(device->machine, (data & 0x10) >> 4); |
| 2780 | mac->set_memory_overlay((data & 0x10) >> 4); |
| 2785 | 2781 | } |
| 2786 | 2782 | } |
| 2787 | 2783 | |
| r9669 | r9670 | |
| 2877 | 2873 | // clear the interrupt if we disabled it |
| 2878 | 2874 | if (!mac->m_se30_vbl_enable) |
| 2879 | 2875 | { |
| 2880 | | mac->nubus_slot_interrupt(device->machine, 0xe, 0); |
| 2876 | mac->nubus_slot_interrupt(0xe, 0); |
| 2881 | 2877 | } |
| 2882 | 2878 | } |
| 2883 | 2879 | |
| r9669 | r9670 | |
| 2902 | 2898 | mac_state *mac = device->machine->driver_data<mac_state>(); |
| 2903 | 2899 | |
| 2904 | 2900 | /* interrupt the 68k (level 1) */ |
| 2905 | | mac->set_via_interrupt(device->machine, state); |
| 2901 | mac->set_via_interrupt(state); |
| 2906 | 2902 | } |
| 2907 | 2903 | |
| 2908 | 2904 | READ16_MEMBER ( mac_state::mac_via_r ) |
| r9669 | r9670 | |
| 2938 | 2934 | static void mac_via2_irq(running_device *device, int state) |
| 2939 | 2935 | { |
| 2940 | 2936 | mac_state *mac = device->machine->driver_data<mac_state>(); |
| 2941 | | mac->set_via2_interrupt(device->machine, state); |
| 2937 | mac->set_via2_interrupt(state); |
| 2942 | 2938 | } |
| 2943 | 2939 | |
| 2944 | 2940 | READ16_MEMBER ( mac_state::mac_via2_r ) |
| r9669 | r9670 | |
| 3035 | 3031 | { |
| 3036 | 3032 | if (has_adb()) |
| 3037 | 3033 | { |
| 3038 | | mac_adb_timer = timer_alloc(machine, mac_adb_tick, NULL); |
| 3039 | | timer_adjust_oneshot(mac_adb_timer, attotime_never, 0); |
| 3034 | this->adb_timer = timer_alloc(machine, mac_adb_tick, NULL); |
| 3035 | timer_adjust_oneshot(this->adb_timer, attotime_never, 0); |
| 3040 | 3036 | |
| 3041 | 3037 | // also allocate PMU timer |
| 3042 | 3038 | if (ADB_IS_PM_CLASS) |
| 3043 | 3039 | { |
| 3044 | 3040 | m_pmu_send_timer = timer_alloc(machine, mac_pmu_tick, NULL); |
| 3045 | | timer_adjust_oneshot(mac_adb_timer, attotime_never, 0); |
| 3041 | timer_adjust_oneshot(this->adb_timer, attotime_never, 0); |
| 3046 | 3042 | } |
| 3047 | 3043 | |
| 3048 | 3044 | } |
| 3049 | | mac_scanline_timer = timer_alloc(machine, mac_scanline_tick, NULL); |
| 3050 | | timer_adjust_oneshot(mac_scanline_timer, machine->primary_screen->time_until_pos(0, 0), 0); |
| 3045 | this->scanline_timer = timer_alloc(machine, mac_scanline_tick, NULL); |
| 3046 | timer_adjust_oneshot(this->scanline_timer, machine->primary_screen->time_until_pos(0, 0), 0); |
| 3051 | 3047 | |
| 3052 | 3048 | m_6015_timer = timer_alloc(machine, mac_6015_tick, NULL); |
| 3053 | 3049 | timer_adjust_oneshot(m_6015_timer, attotime_never, 0); |
| r9669 | r9670 | |
| 3067 | 3063 | // clear PMU response timer |
| 3068 | 3064 | if (ADB_IS_PM_CLASS) |
| 3069 | 3065 | { |
| 3070 | | timer_adjust_oneshot(mac_adb_timer, attotime_never, 0); |
| 3066 | timer_adjust_oneshot(this->adb_timer, attotime_never, 0); |
| 3071 | 3067 | } |
| 3072 | 3068 | |
| 3073 | 3069 | // default to 32-bit mode on LC |
| r9669 | r9670 | |
| 3085 | 3081 | if (m_model < MODEL_MAC_POWERMAC_6100) // no overlay for PowerPC |
| 3086 | 3082 | { |
| 3087 | 3083 | m_overlay = -1; // insure no match |
| 3088 | | set_memory_overlay(machine, 1); |
| 3084 | this->set_memory_overlay(1); |
| 3089 | 3085 | } |
| 3090 | 3086 | |
| 3091 | 3087 | /* setup videoram */ |
| 3092 | | mac_set_screen_buffer(1); |
| 3088 | this->screen_buffer = 1; |
| 3093 | 3089 | |
| 3094 | 3090 | /* setup sound */ |
| 3095 | 3091 | if (AUDIO_IS_CLASSIC_CLASS) |
| r9669 | r9670 | |
| 3104 | 3100 | |
| 3105 | 3101 | if (has_adb()) |
| 3106 | 3102 | { |
| 3107 | | adb_reset(machine); |
| 3103 | this->adb_reset(); |
| 3108 | 3104 | } |
| 3109 | 3105 | |
| 3110 | 3106 | if ((m_model == MODEL_MAC_SE) || (m_model == MODEL_MAC_CLASSIC)) |
| r9669 | r9670 | |
| 3155 | 3151 | |
| 3156 | 3152 | overlay = mac->m_overlay; |
| 3157 | 3153 | mac->m_overlay = -1; |
| 3158 | | mac->set_memory_overlay(machine, overlay); |
| 3154 | mac->set_memory_overlay(overlay); |
| 3159 | 3155 | } |
| 3160 | 3156 | |
| 3161 | 3157 | |
| r9669 | r9670 | |
| 3169 | 3165 | { |
| 3170 | 3166 | if ((address >= 0x900000) && (address <= 0x9fffff)) |
| 3171 | 3167 | { |
| 3172 | | mac->set_memory_overlay(machine, 0); // kill the overlay |
| 3168 | mac->set_memory_overlay(0); // kill the overlay |
| 3173 | 3169 | } |
| 3174 | 3170 | } |
| 3175 | 3171 | else if ((mac->m_model == MODEL_MAC_SE) || (mac->m_model == MODEL_MAC_CLASSIC)) |
| 3176 | 3172 | { |
| 3177 | 3173 | if ((address >= 0x400000) && (address <= 0x4fffff)) |
| 3178 | 3174 | { |
| 3179 | | mac->set_memory_overlay(machine, 0); // kill the overlay |
| 3175 | mac->set_memory_overlay(0); // kill the overlay |
| 3180 | 3176 | } |
| 3181 | 3177 | } |
| 3182 | 3178 | else if ((mac->m_model == MODEL_MAC_LC) || (mac->m_model == MODEL_MAC_LC_II) || (mac->m_model == MODEL_MAC_CLASSIC_II)) |
| 3183 | 3179 | { |
| 3184 | 3180 | if ((address >= 0xa00000) && (address <= 0xafffff)) |
| 3185 | 3181 | { |
| 3186 | | mac->set_memory_overlay(machine, 0); // kill the overlay |
| 3182 | mac->set_memory_overlay(0); // kill the overlay |
| 3187 | 3183 | } |
| 3188 | 3184 | } |
| 3189 | 3185 | else |
| 3190 | 3186 | { |
| 3191 | 3187 | if ((address >= 0x40000000) && (address <= 0x4fffffff)) |
| 3192 | 3188 | { |
| 3193 | | mac->set_memory_overlay(machine, 0); // kill the overlay |
| 3189 | mac->set_memory_overlay(0); // kill the overlay |
| 3194 | 3190 | } |
| 3195 | 3191 | } |
| 3196 | 3192 | } |
| r9669 | r9670 | |
| 3220 | 3216 | } |
| 3221 | 3217 | |
| 3222 | 3218 | mac->m_overlay = -1; |
| 3223 | | mac->set_memory_overlay(machine, 1); |
| 3219 | mac->set_memory_overlay(1); |
| 3224 | 3220 | |
| 3225 | 3221 | memset(messram_get_ptr(mac->m_ram), 0, messram_get_size(mac->m_ram)); |
| 3226 | 3222 | |
| r9669 | r9670 | |
| 3295 | 3291 | mac_driver_init(machine, MODEL_MAC_IIX); |
| 3296 | 3292 | } |
| 3297 | 3293 | |
| 3298 | | void mac_state::nubus_slot_interrupt(running_machine *machine, UINT8 slot, UINT32 state) |
| 3294 | void mac_state::nubus_slot_interrupt(UINT8 slot, UINT32 state) |
| 3299 | 3295 | { |
| 3300 | 3296 | UINT8 masks[6] = { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20 }; |
| 3301 | 3297 | mac_state *mac = machine->driver_data<mac_state>(); |
| r9669 | r9670 | |
| 3327 | 3323 | } |
| 3328 | 3324 | } |
| 3329 | 3325 | |
| 3330 | | void mac_state::vblank_irq(running_machine *machine) |
| 3326 | void mac_state::vblank_irq() |
| 3331 | 3327 | { |
| 3332 | | static int irq_count = 0, ca1_data = 0, ca2_data = 0; |
| 3333 | | |
| 3334 | 3328 | /* handle ADB keyboard/mouse */ |
| 3335 | 3329 | if (has_adb()) |
| 3336 | 3330 | { |
| 3337 | | adb_vblank(machine); |
| 3331 | this->adb_vblank(); |
| 3338 | 3332 | } |
| 3339 | 3333 | |
| 3340 | 3334 | /* handle keyboard */ |
| r9669 | r9670 | |
| 3379 | 3373 | m_via2_vbl ^= 1; |
| 3380 | 3374 | if (!m_via2_vbl) |
| 3381 | 3375 | { |
| 3382 | | nubus_slot_interrupt(machine, 0xe, 1); |
| 3376 | this->nubus_slot_interrupt(0xe, 1); |
| 3383 | 3377 | } |
| 3384 | 3378 | } |
| 3385 | 3379 | } |
| r9669 | r9670 | |
| 3397 | 3391 | |
| 3398 | 3392 | scanline = machine->primary_screen->vpos(); |
| 3399 | 3393 | if (scanline == MAC_V_VIS) |
| 3400 | | mac->vblank_irq(machine); |
| 3394 | mac->vblank_irq(); |
| 3401 | 3395 | |
| 3402 | 3396 | /* check for mouse changes at 10 irqs per frame */ |
| 3403 | 3397 | if (mac->m_model <= MODEL_MAC_PLUS) |
| 3404 | 3398 | { |
| 3405 | 3399 | if (!(scanline % 10)) |
| 3406 | | mouse_callback(machine); |
| 3400 | mac->mouse_callback(); |
| 3407 | 3401 | } |
| 3408 | 3402 | |
| 3409 | | timer_adjust_oneshot(mac_scanline_timer, machine->primary_screen->time_until_pos((scanline+1) % MAC_V_TOTAL, 0), 0); |
| 3403 | timer_adjust_oneshot(mac->scanline_timer, machine->primary_screen->time_until_pos((scanline+1) % MAC_V_TOTAL, 0), 0); |
| 3410 | 3404 | } |
| 3411 | 3405 | |
| 3412 | 3406 | |
src/mess/machine/lynx.c
| r9669 | r9670 | |
| 9 | 9 | #include "devices/cartslot.h" |
| 10 | 10 | #include "hash.h" |
| 11 | 11 | |
| 12 | | static UINT16 lynx_granularity; |
| 13 | | static int lynx_line; |
| 14 | | static int lynx_line_y; |
| 15 | | static int sign_AB = 0, sign_CD = 0; |
| 16 | 12 | |
| 17 | | static UINT32 lynx_palette[0x10]; |
| 18 | 13 | |
| 19 | | static int rotate0 = 0; |
| 20 | | static int lynx_rotate; |
| 21 | | static running_device *lynx_audio; |
| 22 | 14 | |
| 23 | 15 | #define MATH_A 0x55 |
| 24 | 16 | #define MATH_B 0x54 |
| r9669 | r9670 | |
| 43 | 35 | #define PAD_LEFT 0x20 |
| 44 | 36 | #define PAD_RIGHT 0x10 |
| 45 | 37 | |
| 46 | | typedef struct |
| 47 | | { |
| 48 | | UINT8 data[0x100]; |
| 49 | | int accumulate_overflow; |
| 50 | | UINT8 high; |
| 51 | | int low; |
| 52 | | } SUZY; |
| 53 | 38 | |
| 54 | | static SUZY suzy; |
| 55 | | |
| 56 | | static struct |
| 57 | | { |
| 58 | | UINT8 *mem; |
| 59 | | // global |
| 60 | | UINT16 screen; |
| 61 | | UINT16 colbuf; |
| 62 | | UINT16 colpos; // byte where value of collision is written |
| 63 | | UINT16 xoff, yoff; |
| 64 | | // in command |
| 65 | | int mode; |
| 66 | | UINT16 cmd; |
| 67 | | UINT8 spritenr; |
| 68 | | int x,y; |
| 69 | | UINT16 width, height; // uint16 important for blue lightning |
| 70 | | UINT16 stretch, tilt; // uint16 important |
| 71 | | UINT8 color[16]; // or stored |
| 72 | | void (*line_function)(const int y, const int xdir); |
| 73 | | UINT16 bitmap; |
| 74 | | |
| 75 | | int everon; |
| 76 | | int memory_accesses; |
| 77 | | attotime time; |
| 78 | | } blitter; |
| 79 | | |
| 80 | | UINT8 *lynx_mem_0000; |
| 81 | | UINT8 *lynx_mem_fc00; |
| 82 | | UINT8 *lynx_mem_fd00; |
| 83 | | UINT8 *lynx_mem_fe00; |
| 84 | | UINT8 *lynx_mem_fffa; |
| 85 | | size_t lynx_mem_fe00_size; |
| 86 | | |
| 87 | | static UINT8 lynx_memory_config; |
| 88 | | |
| 89 | 39 | /**************************************** |
| 90 | 40 | |
| 91 | 41 | Graphics Drawing |
| r9669 | r9670 | |
| 121 | 71 | SHADOW |
| 122 | 72 | }; |
| 123 | 73 | |
| 124 | | static UINT8 sprite_collide; |
| 125 | 74 | |
| 126 | 75 | /* The pen numbers range from '0' to 'F. Pen numbers '1' thru 'D' are always collidable and opaque. The other |
| 127 | 76 | ones have different behavior depending on the sprite type: there are 8 types of sprites, each has different |
| r9669 | r9670 | |
| 151 | 100 | 0 0 0 0 0 0 0 1 exclusive-or the data |
| 152 | 101 | */ |
| 153 | 102 | |
| 154 | | INLINE void lynx_plot_pixel(const int mode, const int x, const int y, const int color) |
| 103 | INLINE void lynx_plot_pixel(lynx_state *state, const int mode, const int x, const int y, const int color) |
| 155 | 104 | { |
| 156 | 105 | int back; |
| 157 | 106 | UINT8 *screen; |
| 158 | 107 | UINT8 *colbuf; |
| 159 | 108 | |
| 160 | | blitter.everon = TRUE; |
| 161 | | screen = blitter.mem + blitter.screen + y * 80 + x / 2; |
| 162 | | colbuf = blitter.mem + blitter.colbuf + y * 80 + x / 2; |
| 109 | state->blitter.everon = TRUE; |
| 110 | screen = state->blitter.mem + state->blitter.screen + y * 80 + x / 2; |
| 111 | colbuf = state->blitter.mem + state->blitter.colbuf + y * 80 + x / 2; |
| 163 | 112 | |
| 164 | 113 | switch (mode) |
| 165 | 114 | { |
| r9669 | r9670 | |
| 172 | 121 | { |
| 173 | 122 | *screen = (*screen & 0x0f) | (color << 4); |
| 174 | 123 | |
| 175 | | if(sprite_collide) |
| 124 | if(state->sprite_collide) |
| 176 | 125 | { |
| 177 | 126 | back = *colbuf; |
| 178 | | *colbuf = (back & ~0xf0) | (blitter.spritenr << 4); |
| 179 | | if ((back >> 4) > blitter.mem[blitter.colpos]) |
| 180 | | blitter.mem[blitter.colpos] = back >> 4; |
| 181 | | blitter.memory_accesses += 2; |
| 127 | *colbuf = (back & ~0xf0) | (state->blitter.spritenr << 4); |
| 128 | if ((back >> 4) > state->blitter.mem[state->blitter.colpos]) |
| 129 | state->blitter.mem[state->blitter.colpos] = back >> 4; |
| 130 | state->blitter.memory_accesses += 2; |
| 182 | 131 | } |
| 183 | 132 | } |
| 184 | 133 | else /* Lower nibble */ |
| 185 | 134 | { |
| 186 | 135 | *screen = (*screen & 0xf0) | color; |
| 187 | 136 | |
| 188 | | if(sprite_collide) |
| 137 | if(state->sprite_collide) |
| 189 | 138 | { |
| 190 | 139 | back = *colbuf; |
| 191 | | *colbuf = (back & ~0x0f) | (blitter.spritenr); |
| 192 | | if ((back & 0x0f) > blitter.mem[blitter.colpos]) |
| 193 | | blitter.mem[blitter.colpos] = back & 0x0f; |
| 194 | | blitter.memory_accesses += 2; |
| 140 | *colbuf = (back & ~0x0f) | (state->blitter.spritenr); |
| 141 | if ((back & 0x0f) > state->blitter.mem[state->blitter.colpos]) |
| 142 | state->blitter.mem[state->blitter.colpos] = back & 0x0f; |
| 143 | state->blitter.memory_accesses += 2; |
| 195 | 144 | } |
| 196 | 145 | } |
| 197 | | blitter.memory_accesses++; |
| 146 | state->blitter.memory_accesses++; |
| 198 | 147 | break; |
| 199 | 148 | |
| 200 | 149 | case BOUNDARY: |
| r9669 | r9670 | |
| 207 | 156 | if (color != 0x0f) |
| 208 | 157 | { |
| 209 | 158 | *screen = (*screen & 0x0f) | (color << 4); |
| 210 | | blitter.memory_accesses++; |
| 159 | state->blitter.memory_accesses++; |
| 211 | 160 | } |
| 212 | | if(sprite_collide) |
| 161 | if(state->sprite_collide) |
| 213 | 162 | { |
| 214 | 163 | back = *colbuf; |
| 215 | | *colbuf = (back & ~0xf0) | (blitter.spritenr << 4); |
| 216 | | if ((back >> 4) > blitter.mem[blitter.colpos]) |
| 217 | | blitter.mem[blitter.colpos] = back >> 4; |
| 218 | | blitter.memory_accesses += 2; |
| 164 | *colbuf = (back & ~0xf0) | (state->blitter.spritenr << 4); |
| 165 | if ((back >> 4) > state->blitter.mem[state->blitter.colpos]) |
| 166 | state->blitter.mem[state->blitter.colpos] = back >> 4; |
| 167 | state->blitter.memory_accesses += 2; |
| 219 | 168 | } |
| 220 | 169 | } |
| 221 | 170 | else /* Lower nibble */ |
| r9669 | r9670 | |
| 223 | 172 | if (color != 0x0f) |
| 224 | 173 | { |
| 225 | 174 | *screen = (*screen & 0xf0) | color; |
| 226 | | blitter.memory_accesses++; |
| 175 | state->blitter.memory_accesses++; |
| 227 | 176 | } |
| 228 | | if(sprite_collide) |
| 177 | if(state->sprite_collide) |
| 229 | 178 | { |
| 230 | 179 | back = *colbuf; |
| 231 | | *colbuf = (back & ~0x0f) | (blitter.spritenr); |
| 232 | | if ((back & 0x0f) > blitter.mem[blitter.colpos]) |
| 233 | | blitter.mem[blitter.colpos] = back & 0x0f; |
| 234 | | blitter.memory_accesses += 2; |
| 180 | *colbuf = (back & ~0x0f) | (state->blitter.spritenr); |
| 181 | if ((back & 0x0f) > state->blitter.mem[state->blitter.colpos]) |
| 182 | state->blitter.mem[state->blitter.colpos] = back & 0x0f; |
| 183 | state->blitter.memory_accesses += 2; |
| 235 | 184 | } |
| 236 | 185 | } |
| 237 | 186 | break; |
| r9669 | r9670 | |
| 245 | 194 | { |
| 246 | 195 | *screen = (*screen & 0x0f) | (color << 4); |
| 247 | 196 | |
| 248 | | if (sprite_collide && (color != 0x0e)) |
| 197 | if (state->sprite_collide && (color != 0x0e)) |
| 249 | 198 | { |
| 250 | 199 | back = *colbuf; |
| 251 | | *colbuf = (back & ~0xf0) | (blitter.spritenr << 4); |
| 252 | | if ((back >> 4) > blitter.mem[blitter.colpos]) |
| 253 | | blitter.mem[blitter.colpos] = back >> 4; |
| 254 | | blitter.memory_accesses += 2; |
| 200 | *colbuf = (back & ~0xf0) | (state->blitter.spritenr << 4); |
| 201 | if ((back >> 4) > state->blitter.mem[state->blitter.colpos]) |
| 202 | state->blitter.mem[state->blitter.colpos] = back >> 4; |
| 203 | state->blitter.memory_accesses += 2; |
| 255 | 204 | } |
| 256 | 205 | } |
| 257 | 206 | else /* Lower nibble */ |
| 258 | 207 | { |
| 259 | 208 | *screen = (*screen & 0xf0) | color; |
| 260 | 209 | |
| 261 | | if (sprite_collide && (color != 0x0e)) |
| 210 | if (state->sprite_collide && (color != 0x0e)) |
| 262 | 211 | { |
| 263 | 212 | back = *colbuf; |
| 264 | | *colbuf = (back & ~0x0f) | (blitter.spritenr); |
| 265 | | if ((back & 0x0f) > blitter.mem[blitter.colpos]) |
| 266 | | blitter.mem[blitter.colpos] = back & 0x0f; |
| 267 | | blitter.memory_accesses += 2; |
| 213 | *colbuf = (back & ~0x0f) | (state->blitter.spritenr); |
| 214 | if ((back & 0x0f) > state->blitter.mem[state->blitter.colpos]) |
| 215 | state->blitter.mem[state->blitter.colpos] = back & 0x0f; |
| 216 | state->blitter.memory_accesses += 2; |
| 268 | 217 | } |
| 269 | 218 | } |
| 270 | | blitter.memory_accesses++; |
| 219 | state->blitter.memory_accesses++; |
| 271 | 220 | break; |
| 272 | 221 | |
| 273 | 222 | case BOUNDARY_SHADOW: |
| r9669 | r9670 | |
| 281 | 230 | if (color != 0x0f) |
| 282 | 231 | { |
| 283 | 232 | *screen = (*screen & 0x0f) | (color << 4); |
| 284 | | blitter.memory_accesses++; |
| 233 | state->blitter.memory_accesses++; |
| 285 | 234 | } |
| 286 | | if (sprite_collide && (color != 0x0e)) |
| 235 | if (state->sprite_collide && (color != 0x0e)) |
| 287 | 236 | { |
| 288 | 237 | back = *colbuf; |
| 289 | | *colbuf = (back & ~0xf0) | (blitter.spritenr << 4); |
| 290 | | if ((back >> 4) > blitter.mem[blitter.colpos]) |
| 291 | | blitter.mem[blitter.colpos] = back >> 4; |
| 292 | | blitter.memory_accesses += 2; |
| 238 | *colbuf = (back & ~0xf0) | (state->blitter.spritenr << 4); |
| 239 | if ((back >> 4) > state->blitter.mem[state->blitter.colpos]) |
| 240 | state->blitter.mem[state->blitter.colpos] = back >> 4; |
| 241 | state->blitter.memory_accesses += 2; |
| 293 | 242 | } |
| 294 | 243 | } |
| 295 | 244 | else /* Lower nibble */ |
| r9669 | r9670 | |
| 297 | 246 | if (color != 0x0f) |
| 298 | 247 | { |
| 299 | 248 | *screen = (*screen & 0xf0) | color; |
| 300 | | blitter.memory_accesses++; |
| 249 | state->blitter.memory_accesses++; |
| 301 | 250 | } |
| 302 | | if (sprite_collide && (color != 0x0e)) |
| 251 | if (state->sprite_collide && (color != 0x0e)) |
| 303 | 252 | { |
| 304 | 253 | back = *colbuf; |
| 305 | | *colbuf = (back & ~0x0f) | (blitter.spritenr); |
| 306 | | if ((back & 0x0f) > blitter.mem[blitter.colpos]) |
| 307 | | blitter.mem[blitter.colpos] = back & 0x0f; |
| 308 | | blitter.memory_accesses += 2; |
| 254 | *colbuf = (back & ~0x0f) | (state->blitter.spritenr); |
| 255 | if ((back & 0x0f) > state->blitter.mem[state->blitter.colpos]) |
| 256 | state->blitter.mem[state->blitter.colpos] = back & 0x0f; |
| 257 | state->blitter.memory_accesses += 2; |
| 309 | 258 | } |
| 310 | 259 | } |
| 311 | 260 | break; |
| r9669 | r9670 | |
| 320 | 269 | { |
| 321 | 270 | *screen = (*screen & 0x0f) | (color << 4); |
| 322 | 271 | |
| 323 | | if (sprite_collide && (color != 0x0e)) |
| 272 | if (state->sprite_collide && (color != 0x0e)) |
| 324 | 273 | { |
| 325 | | *colbuf = (*colbuf & ~0xf0) | (blitter.spritenr << 4); |
| 326 | | blitter.memory_accesses++; |
| 274 | *colbuf = (*colbuf & ~0xf0) | (state->blitter.spritenr << 4); |
| 275 | state->blitter.memory_accesses++; |
| 327 | 276 | } |
| 328 | 277 | } |
| 329 | 278 | else /* Lower nibble */ |
| 330 | 279 | { |
| 331 | 280 | *screen = (*screen & 0xf0) | color; |
| 332 | 281 | |
| 333 | | if (sprite_collide && (color != 0x0e)) |
| 282 | if (state->sprite_collide && (color != 0x0e)) |
| 334 | 283 | { |
| 335 | | *colbuf = (*colbuf & ~0x0f) | (blitter.spritenr); |
| 336 | | blitter.memory_accesses++; |
| 284 | *colbuf = (*colbuf & ~0x0f) | (state->blitter.spritenr); |
| 285 | state->blitter.memory_accesses++; |
| 337 | 286 | } |
| 338 | 287 | } |
| 339 | | blitter.memory_accesses++; |
| 288 | state->blitter.memory_accesses++; |
| 340 | 289 | break; |
| 341 | 290 | |
| 342 | 291 | case BACKGROUND_NO_COLL: |
| r9669 | r9670 | |
| 345 | 294 | *screen = (*screen & 0x0f) | (color << 4); |
| 346 | 295 | else /* Lower nibble */ |
| 347 | 296 | *screen = (*screen & 0xf0) | color; |
| 348 | | blitter.memory_accesses++; |
| 297 | state->blitter.memory_accesses++; |
| 349 | 298 | break; |
| 350 | 299 | |
| 351 | 300 | case NO_COLL: |
| r9669 | r9670 | |
| 357 | 306 | *screen = (*screen & 0x0f) | (color << 4); |
| 358 | 307 | else /* Lower nibble */ |
| 359 | 308 | *screen = (*screen & 0xf0) | color; |
| 360 | | blitter.memory_accesses++; |
| 309 | state->blitter.memory_accesses++; |
| 361 | 310 | break; |
| 362 | 311 | |
| 363 | 312 | case XOR_SPRITE: |
| r9669 | r9670 | |
| 374 | 323 | if (color != 0x0e) |
| 375 | 324 | { |
| 376 | 325 | back = *colbuf; |
| 377 | | *colbuf = (back & ~0xf0) | (blitter.spritenr << 4); |
| 378 | | if ((back >> 4) > blitter.mem[blitter.colpos]) |
| 379 | | blitter.mem[blitter.colpos] = back >> 4; |
| 380 | | blitter.memory_accesses += 2; |
| 326 | *colbuf = (back & ~0xf0) | (state->blitter.spritenr << 4); |
| 327 | if ((back >> 4) > state->blitter.mem[state->blitter.colpos]) |
| 328 | state->blitter.mem[state->blitter.colpos] = back >> 4; |
| 329 | state->blitter.memory_accesses += 2; |
| 381 | 330 | } |
| 382 | 331 | } |
| 383 | 332 | else /* Lower nibble */ |
| r9669 | r9670 | |
| 387 | 336 | if (color != 0x0e) |
| 388 | 337 | { |
| 389 | 338 | back = *colbuf; |
| 390 | | *colbuf = (back & ~0x0f) | (blitter.spritenr); |
| 391 | | if ((back & 0x0f) > blitter.mem[blitter.colpos]) |
| 392 | | blitter.mem[blitter.colpos] = back & 0x0f; |
| 393 | | blitter.memory_accesses += 2; |
| 339 | *colbuf = (back & ~0x0f) | (state->blitter.spritenr); |
| 340 | if ((back & 0x0f) > state->blitter.mem[state->blitter.colpos]) |
| 341 | state->blitter.mem[state->blitter.colpos] = back & 0x0f; |
| 342 | state->blitter.memory_accesses += 2; |
| 394 | 343 | } |
| 395 | 344 | } |
| 396 | | blitter.memory_accesses++; |
| 345 | state->blitter.memory_accesses++; |
| 397 | 346 | break; |
| 398 | 347 | } |
| 399 | 348 | } |
| 400 | 349 | |
| 401 | | static void lynx_blit_do_work( const int y, const int xdir, const int bits, const int mask ) |
| 350 | static void lynx_blit_do_work( lynx_state *state, const int y, const int xdir, const int bits, const int mask ) |
| 402 | 351 | { |
| 403 | 352 | int j, xi, wi, i; |
| 404 | 353 | int b, p, color; |
| 405 | 354 | |
| 406 | | i = blitter.mem[blitter.bitmap]; |
| 407 | | blitter.memory_accesses++; // ? |
| 355 | i = state->blitter.mem[state->blitter.bitmap]; |
| 356 | state->blitter.memory_accesses++; // ? |
| 408 | 357 | |
| 409 | | for (xi = blitter.x, p = 0, b = 0, j = 1, wi = 0; j < i;) |
| 358 | for (xi = state->blitter.x, p = 0, b = 0, j = 1, wi = 0; j < i;) |
| 410 | 359 | { |
| 411 | 360 | if (p < bits) |
| 412 | 361 | { |
| 413 | | b = (b << 8) | blitter.mem[blitter.bitmap + j]; |
| 362 | b = (b << 8) | state->blitter.mem[state->blitter.bitmap + j]; |
| 414 | 363 | j++; |
| 415 | 364 | p += 8; |
| 416 | | blitter.memory_accesses++; |
| 365 | state->blitter.memory_accesses++; |
| 417 | 366 | } |
| 418 | 367 | for ( ; (p >= bits); ) |
| 419 | 368 | { |
| 420 | | color = blitter.color[(b >> (p - bits)) & mask]; |
| 369 | color = state->blitter.color[(b >> (p - bits)) & mask]; |
| 421 | 370 | p -= bits; |
| 422 | | for ( ; wi < blitter.width; wi += 0x100, xi += xdir) |
| 371 | for ( ; wi < state->blitter.width; wi += 0x100, xi += xdir) |
| 423 | 372 | { |
| 424 | 373 | if ((xi >= 0) && (xi < 160)) |
| 425 | | lynx_plot_pixel(blitter.mode, xi, y, color); |
| 374 | lynx_plot_pixel(state, state->blitter.mode, xi, y, color); |
| 426 | 375 | } |
| 427 | | wi -= blitter.width; |
| 376 | wi -= state->blitter.width; |
| 428 | 377 | } |
| 429 | 378 | } |
| 430 | 379 | } |
| 431 | 380 | |
| 432 | 381 | |
| 433 | | static void lynx_blit_2color_line(const int y, const int xdir) |
| 382 | static void lynx_blit_2color_line(lynx_state *state, const int y, const int xdir) |
| 434 | 383 | { |
| 435 | 384 | const int bits = 1; |
| 436 | 385 | const int mask = 0x01; |
| 437 | 386 | |
| 438 | | lynx_blit_do_work(y, xdir, bits, mask); |
| 387 | lynx_blit_do_work(state, y, xdir, bits, mask); |
| 439 | 388 | } |
| 440 | | static void lynx_blit_4color_line(const int y, const int xdir) |
| 389 | static void lynx_blit_4color_line(lynx_state *state, const int y, const int xdir) |
| 441 | 390 | { |
| 442 | 391 | const int bits = 2; |
| 443 | 392 | const int mask = 0x03; |
| 444 | 393 | |
| 445 | | lynx_blit_do_work(y, xdir, bits, mask); |
| 394 | lynx_blit_do_work(state, y, xdir, bits, mask); |
| 446 | 395 | } |
| 447 | | static void lynx_blit_8color_line(const int y, const int xdir) |
| 396 | static void lynx_blit_8color_line(lynx_state *state, const int y, const int xdir) |
| 448 | 397 | { |
| 449 | 398 | const int bits = 3; |
| 450 | 399 | const int mask = 0x07; |
| 451 | 400 | |
| 452 | | lynx_blit_do_work(y, xdir, bits, mask); |
| 401 | lynx_blit_do_work(state, y, xdir, bits, mask); |
| 453 | 402 | } |
| 454 | | static void lynx_blit_16color_line(const int y, const int xdir) |
| 403 | static void lynx_blit_16color_line(lynx_state *state, const int y, const int xdir) |
| 455 | 404 | { |
| 456 | 405 | const int bits = 4; |
| 457 | 406 | const int mask = 0x0f; |
| 458 | 407 | |
| 459 | | lynx_blit_do_work(y, xdir, bits, mask); |
| 408 | lynx_blit_do_work(state, y, xdir, bits, mask); |
| 460 | 409 | } |
| 461 | 410 | |
| 462 | 411 | /* |
| r9669 | r9670 | |
| 483 | 432 | 1, 4 bit count of values-1, 4 bit color, .... |
| 484 | 433 | */ |
| 485 | 434 | |
| 486 | | static void lynx_blit_rle_do_work( const int y, const int xdir, const int bits, const int mask ) |
| 435 | static void lynx_blit_rle_do_work( lynx_state *state, const int y, const int xdir, const int bits, const int mask ) |
| 487 | 436 | { |
| 488 | 437 | int wi, xi; |
| 489 | 438 | int b, p, j; |
| 490 | 439 | int t, count, color; |
| 491 | 440 | |
| 492 | | for( p = 0, j = 0, b = 0, xi = blitter.x, wi = 0; ; ) /* through the rle entries */ |
| 441 | for( p = 0, j = 0, b = 0, xi = state->blitter.x, wi = 0; ; ) /* through the rle entries */ |
| 493 | 442 | { |
| 494 | 443 | if (p < 5 + bits) /* under 7 bits no complete entry */ |
| 495 | 444 | { |
| 496 | 445 | j++; |
| 497 | | if (j >= blitter.mem[blitter.bitmap]) |
| 446 | if (j >= state->blitter.mem[state->blitter.bitmap]) |
| 498 | 447 | return; |
| 499 | 448 | |
| 500 | 449 | p += 8; |
| 501 | | b = (b << 8) | blitter.mem[blitter.bitmap + j]; |
| 502 | | blitter.memory_accesses++; |
| 450 | b = (b << 8) | state->blitter.mem[state->blitter.bitmap + j]; |
| 451 | state->blitter.memory_accesses++; |
| 503 | 452 | } |
| 504 | 453 | |
| 505 | 454 | t = (b >> (p - 1)) & 0x01; |
| r9669 | r9670 | |
| 514 | 463 | if (p < bits) |
| 515 | 464 | { |
| 516 | 465 | j++; |
| 517 | | if (j >= blitter.mem[blitter.bitmap]) |
| 466 | if (j >= state->blitter.mem[state->blitter.bitmap]) |
| 518 | 467 | return; |
| 519 | 468 | p += 8; |
| 520 | | b = (b << 8) | blitter.mem[blitter.bitmap + j]; |
| 521 | | blitter.memory_accesses++; |
| 469 | b = (b << 8) | state->blitter.mem[state->blitter.bitmap + j]; |
| 470 | state->blitter.memory_accesses++; |
| 522 | 471 | } |
| 523 | 472 | |
| 524 | | color = blitter.color[(b >> (p - bits)) & mask]; |
| 473 | color = state->blitter.color[(b >> (p - bits)) & mask]; |
| 525 | 474 | p -= bits; |
| 526 | | for ( ; wi < blitter.width; wi += 0x100, xi += xdir) |
| 475 | for ( ; wi < state->blitter.width; wi += 0x100, xi += xdir) |
| 527 | 476 | { |
| 528 | 477 | if ((xi >= 0) && (xi < 160)) |
| 529 | | lynx_plot_pixel(blitter.mode, xi, y, color); |
| 478 | lynx_plot_pixel(state, state->blitter.mode, xi, y, color); |
| 530 | 479 | } |
| 531 | | wi -= blitter.width; |
| 480 | wi -= state->blitter.width; |
| 532 | 481 | } |
| 533 | 482 | } |
| 534 | 483 | else /* count of same pixels */ |
| r9669 | r9670 | |
| 539 | 488 | if (p < bits) |
| 540 | 489 | { |
| 541 | 490 | j++; |
| 542 | | if (j >= blitter.mem[blitter.bitmap]) |
| 491 | if (j >= state->blitter.mem[state->blitter.bitmap]) |
| 543 | 492 | return; |
| 544 | 493 | p += 8; |
| 545 | | b = (b << 8) | blitter.mem[blitter.bitmap + j]; |
| 546 | | blitter.memory_accesses++; |
| 494 | b = (b << 8) | state->blitter.mem[state->blitter.bitmap + j]; |
| 495 | state->blitter.memory_accesses++; |
| 547 | 496 | } |
| 548 | 497 | |
| 549 | | color = blitter.color[(b >> (p - bits)) & mask]; |
| 498 | color = state->blitter.color[(b >> (p - bits)) & mask]; |
| 550 | 499 | p -= bits; |
| 551 | 500 | |
| 552 | 501 | for ( ; count; count--) |
| 553 | 502 | { |
| 554 | | for ( ; wi < blitter.width; wi += 0x100, xi += xdir) |
| 503 | for ( ; wi < state->blitter.width; wi += 0x100, xi += xdir) |
| 555 | 504 | { |
| 556 | 505 | if ((xi >= 0) && (xi < 160)) |
| 557 | | lynx_plot_pixel(blitter.mode, xi, y, color); |
| 506 | lynx_plot_pixel(state, state->blitter.mode, xi, y, color); |
| 558 | 507 | } |
| 559 | | wi -= blitter.width; |
| 508 | wi -= state->blitter.width; |
| 560 | 509 | } |
| 561 | 510 | } |
| 562 | 511 | } |
| 563 | 512 | } |
| 564 | 513 | |
| 565 | | static void lynx_blit_2color_rle_line(const int y, const int xdir) |
| 514 | static void lynx_blit_2color_rle_line(lynx_state *state, const int y, const int xdir) |
| 566 | 515 | { |
| 567 | 516 | const int bits = 1; |
| 568 | 517 | const int mask = 0x01; |
| 569 | 518 | |
| 570 | | lynx_blit_rle_do_work(y, xdir, bits, mask); |
| 519 | lynx_blit_rle_do_work(state, y, xdir, bits, mask); |
| 571 | 520 | } |
| 572 | | static void lynx_blit_4color_rle_line(const int y, const int xdir) |
| 521 | static void lynx_blit_4color_rle_line(lynx_state *state, const int y, const int xdir) |
| 573 | 522 | { |
| 574 | 523 | const int bits = 2; |
| 575 | 524 | const int mask = 0x03; |
| 576 | 525 | |
| 577 | | lynx_blit_rle_do_work(y, xdir, bits, mask); |
| 526 | lynx_blit_rle_do_work(state, y, xdir, bits, mask); |
| 578 | 527 | } |
| 579 | | static void lynx_blit_8color_rle_line(const int y, const int xdir) |
| 528 | static void lynx_blit_8color_rle_line(lynx_state *state, const int y, const int xdir) |
| 580 | 529 | { |
| 581 | 530 | const int bits = 3; |
| 582 | 531 | const int mask = 0x07; |
| 583 | 532 | |
| 584 | | lynx_blit_rle_do_work(y, xdir, bits, mask); |
| 533 | lynx_blit_rle_do_work(state, y, xdir, bits, mask); |
| 585 | 534 | } |
| 586 | | static void lynx_blit_16color_rle_line(const int y, const int xdir) |
| 535 | static void lynx_blit_16color_rle_line(lynx_state *state, const int y, const int xdir) |
| 587 | 536 | { |
| 588 | 537 | const int bits = 4; |
| 589 | 538 | const int mask = 0x0f; |
| 590 | 539 | |
| 591 | | lynx_blit_rle_do_work(y, xdir, bits, mask); |
| 540 | lynx_blit_rle_do_work(state, y, xdir, bits, mask); |
| 592 | 541 | } |
| 593 | 542 | |
| 594 | 543 | |
| 595 | | static void lynx_blit_lines(void) |
| 544 | static void lynx_blit_lines(lynx_state *state) |
| 596 | 545 | { |
| 597 | 546 | int i, hi, y; |
| 598 | 547 | int ydir = 0, xdir = 0; |
| 599 | 548 | int flip = 0; |
| 600 | 549 | |
| 601 | | blitter.everon = FALSE; |
| 550 | state->blitter.everon = FALSE; |
| 602 | 551 | |
| 603 | 552 | // flipping sprdemo3 |
| 604 | 553 | // fat bobby 0x10 |
| 605 | 554 | // mirror the sprite in gameplay? |
| 606 | 555 | xdir = 1; |
| 607 | 556 | |
| 608 | | if (blitter.mem[blitter.cmd] & 0x20) /* Horizontal Flip */ |
| 557 | if (state->blitter.mem[state->blitter.cmd] & 0x20) /* Horizontal Flip */ |
| 609 | 558 | { |
| 610 | 559 | xdir = -1; |
| 611 | | blitter.x--; /*?*/ |
| 560 | state->blitter.x--; /*?*/ |
| 612 | 561 | } |
| 613 | 562 | |
| 614 | 563 | ydir = 1; |
| 615 | 564 | |
| 616 | | if (blitter.mem[blitter.cmd] & 0x10) /* Vertical Flip */ |
| 565 | if (state->blitter.mem[state->blitter.cmd] & 0x10) /* Vertical Flip */ |
| 617 | 566 | { |
| 618 | 567 | ydir = -1; |
| 619 | | blitter.y--; /*?*/ |
| 568 | state->blitter.y--; /*?*/ |
| 620 | 569 | } |
| 621 | 570 | |
| 622 | | switch (blitter.mem[blitter.cmd + 1] & 0x03) /* Start Left & Start Up */ |
| 571 | switch (state->blitter.mem[state->blitter.cmd + 1] & 0x03) /* Start Left & Start Up */ |
| 623 | 572 | { |
| 624 | 573 | case 0: |
| 625 | 574 | flip =0; |
| r9669 | r9670 | |
| 642 | 591 | break; |
| 643 | 592 | } |
| 644 | 593 | |
| 645 | | for (y = blitter.y, hi = 0; blitter.memory_accesses++, i = blitter.mem[blitter.bitmap]; blitter.bitmap += i ) |
| 594 | for (y = state->blitter.y, hi = 0; state->blitter.memory_accesses++, i = state->blitter.mem[state->blitter.bitmap]; state->blitter.bitmap += i ) |
| 646 | 595 | { |
| 647 | 596 | if (i == 1) |
| 648 | 597 | { |
| r9669 | r9670 | |
| 653 | 602 | case 0: |
| 654 | 603 | case 2: |
| 655 | 604 | ydir *= -1; |
| 656 | | blitter.y += ydir; |
| 605 | state->blitter.y += ydir; |
| 657 | 606 | break; |
| 658 | 607 | |
| 659 | 608 | case 1: |
| 660 | 609 | case 3: |
| 661 | 610 | xdir *= -1; |
| 662 | | blitter.x += xdir; |
| 611 | state->blitter.x += xdir; |
| 663 | 612 | break; |
| 664 | 613 | } |
| 665 | 614 | |
| 666 | | y = blitter.y; |
| 615 | y = state->blitter.y; |
| 667 | 616 | flip++; |
| 668 | 617 | continue; |
| 669 | 618 | } |
| 670 | 619 | |
| 671 | | for ( ; (hi < blitter.height); hi += 0x100, y += ydir) |
| 620 | for ( ; (hi < state->blitter.height); hi += 0x100, y += ydir) |
| 672 | 621 | { |
| 673 | 622 | if (y >= 0 && y < 102) |
| 674 | | blitter.line_function(y, xdir); |
| 675 | | blitter.width += blitter.stretch; |
| 676 | | blitter.x += blitter.tilt; |
| 623 | state->blitter.line_function(state, y, xdir); |
| 624 | state->blitter.width += state->blitter.stretch; |
| 625 | state->blitter.x += state->blitter.tilt; |
| 677 | 626 | } |
| 678 | 627 | |
| 679 | | hi -= blitter.height; |
| 628 | hi -= state->blitter.height; |
| 680 | 629 | } |
| 681 | 630 | |
| 682 | | if (suzy.data[SPRG0] & 0x04) |
| 631 | if (state->suzy.data[SPRG0] & 0x04) |
| 683 | 632 | { |
| 684 | | if (sprite_collide & !blitter.everon) |
| 685 | | blitter.mem[blitter.colpos] |= 0x80; |
| 633 | if (state->sprite_collide & !state->blitter.everon) |
| 634 | state->blitter.mem[state->blitter.colpos] |= 0x80; |
| 686 | 635 | else |
| 687 | | blitter.mem[blitter.colpos] &= 0x7f; |
| 636 | state->blitter.mem[state->blitter.colpos] &= 0x7f; |
| 688 | 637 | } |
| 689 | 638 | } |
| 690 | 639 | |
| 691 | 640 | static TIMER_CALLBACK(lynx_blitter_timer) |
| 692 | 641 | { |
| 693 | | suzy.data[SPRSYS] &= ~0x01; //blitter finished |
| 642 | lynx_state *state = machine->driver_data<lynx_state>(); |
| 643 | state->suzy.data[SPRSYS] &= ~0x01; //state->blitter finished |
| 694 | 644 | } |
| 695 | 645 | |
| 696 | 646 | /* |
| r9669 | r9670 | |
| 768 | 718 | |
| 769 | 719 | static void lynx_blitter(running_machine *machine) |
| 770 | 720 | { |
| 721 | lynx_state *state = machine->driver_data<lynx_state>(); |
| 771 | 722 | static const int lynx_colors[4]={2,4,8,16}; |
| 772 | 723 | |
| 773 | | static void (* const blit_line[4])(const int y, const int xdir)= { |
| 724 | static void (* const blit_line[4])(lynx_state *state, const int y, const int xdir)= { |
| 774 | 725 | lynx_blit_2color_line, |
| 775 | 726 | lynx_blit_4color_line, |
| 776 | 727 | lynx_blit_8color_line, |
| 777 | 728 | lynx_blit_16color_line |
| 778 | 729 | }; |
| 779 | 730 | |
| 780 | | static void (* const blit_rle_line[4])(const int y, const int xdir)= { |
| 731 | static void (* const blit_rle_line[4])(lynx_state *state, const int y, const int xdir)= { |
| 781 | 732 | lynx_blit_2color_rle_line, |
| 782 | 733 | lynx_blit_4color_rle_line, |
| 783 | 734 | lynx_blit_8color_rle_line, |
| r9669 | r9670 | |
| 785 | 736 | }; |
| 786 | 737 | int i; int o;int colors; |
| 787 | 738 | |
| 788 | | blitter.memory_accesses = 0; |
| 789 | | blitter.mem = (UINT8*)cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->get_read_ptr(0x0000); |
| 739 | state->blitter.memory_accesses = 0; |
| 740 | state->blitter.mem = (UINT8*)cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)->get_read_ptr(0x0000); |
| 790 | 741 | |
| 791 | | blitter.xoff = GET_WORD(suzy.data, 0x04); |
| 792 | | blitter.yoff = GET_WORD(suzy.data, 0x06); |
| 793 | | blitter.screen = GET_WORD(suzy.data, 0x08); |
| 794 | | blitter.colbuf = GET_WORD(suzy.data, 0x0a); |
| 795 | | // hsizeoff GET_WORD(suzy.data, 0x28) |
| 796 | | // vsizeoff GET_WORD(suzy.data, 0x2a) |
| 742 | state->blitter.xoff = GET_WORD(state->suzy.data, 0x04); |
| 743 | state->blitter.yoff = GET_WORD(state->suzy.data, 0x06); |
| 744 | state->blitter.screen = GET_WORD(state->suzy.data, 0x08); |
| 745 | state->blitter.colbuf = GET_WORD(state->suzy.data, 0x0a); |
| 746 | // hsizeoff GET_WORD(state->suzy.data, 0x28) |
| 747 | // vsizeoff GET_WORD(state->suzy.data, 0x2a) |
| 797 | 748 | |
| 798 | | // these might be never set by the blitter hardware |
| 799 | | blitter.width = 0x100; |
| 800 | | blitter.height = 0x100; |
| 801 | | blitter.stretch = 0; |
| 802 | | blitter.tilt = 0; |
| 803 | | sprite_collide = 0; |
| 749 | // these might be never set by the state->blitter hardware |
| 750 | state->blitter.width = 0x100; |
| 751 | state->blitter.height = 0x100; |
| 752 | state->blitter.stretch = 0; |
| 753 | state->blitter.tilt = 0; |
| 754 | state->sprite_collide = 0; |
| 804 | 755 | |
| 805 | | blitter.memory_accesses += 2; |
| 756 | state->blitter.memory_accesses += 2; |
| 806 | 757 | |
| 807 | | for (blitter.cmd = GET_WORD(suzy.data, 0x10); blitter.cmd; ) |
| 758 | for (state->blitter.cmd = GET_WORD(state->suzy.data, 0x10); state->blitter.cmd; ) |
| 808 | 759 | { |
| 809 | | blitter.memory_accesses += 1; |
| 760 | state->blitter.memory_accesses += 1; |
| 810 | 761 | |
| 811 | | if (!(blitter.mem[blitter.cmd + 1] & 0x04)) // if 0, we skip this sprite |
| 762 | if (!(state->blitter.mem[state->blitter.cmd + 1] & 0x04)) // if 0, we skip this sprite |
| 812 | 763 | { |
| 813 | | blitter.colpos = GET_WORD(suzy.data, 0x24) + blitter.cmd; |
| 764 | state->blitter.colpos = GET_WORD(state->suzy.data, 0x24) + state->blitter.cmd; |
| 814 | 765 | |
| 815 | | blitter.bitmap = GET_WORD(blitter.mem,blitter.cmd + 5); |
| 816 | | blitter.x = (INT16)GET_WORD(blitter.mem, blitter.cmd + 7) - blitter.xoff; |
| 817 | | blitter.y = (INT16)GET_WORD(blitter.mem, blitter.cmd + 9) - blitter.yoff; |
| 818 | | blitter.memory_accesses += 6; |
| 766 | state->blitter.bitmap = GET_WORD(state->blitter.mem,state->blitter.cmd + 5); |
| 767 | state->blitter.x = (INT16)GET_WORD(state->blitter.mem, state->blitter.cmd + 7) - state->blitter.xoff; |
| 768 | state->blitter.y = (INT16)GET_WORD(state->blitter.mem, state->blitter.cmd + 9) - state->blitter.yoff; |
| 769 | state->blitter.memory_accesses += 6; |
| 819 | 770 | |
| 820 | | blitter.mode = blitter.mem[blitter.cmd] & 0x07; |
| 771 | state->blitter.mode = state->blitter.mem[state->blitter.cmd] & 0x07; |
| 821 | 772 | |
| 822 | | if (blitter.mem[blitter.cmd + 1] & 0x80) |
| 823 | | blitter.line_function = blit_line[blitter.mem[blitter.cmd] >> 6]; |
| 773 | if (state->blitter.mem[state->blitter.cmd + 1] & 0x80) |
| 774 | state->blitter.line_function = blit_line[state->blitter.mem[state->blitter.cmd] >> 6]; |
| 824 | 775 | else |
| 825 | | blitter.line_function = blit_rle_line[blitter.mem[blitter.cmd] >> 6]; |
| 776 | state->blitter.line_function = blit_rle_line[state->blitter.mem[state->blitter.cmd] >> 6]; |
| 826 | 777 | |
| 827 | | if (!(blitter.mem[blitter.cmd + 2] & 0x20) && !(suzy.data[SPRSYS] & 0x20)) |
| 778 | if (!(state->blitter.mem[state->blitter.cmd + 2] & 0x20) && !(state->suzy.data[SPRSYS] & 0x20)) |
| 828 | 779 | { |
| 829 | | switch (blitter.mode) |
| 780 | switch (state->blitter.mode) |
| 830 | 781 | { |
| 831 | 782 | case BACKGROUND: |
| 832 | 783 | case BOUNDARY_SHADOW: |
| r9669 | r9670 | |
| 834 | 785 | case NORMAL_SPRITE: |
| 835 | 786 | case XOR_SPRITE: |
| 836 | 787 | case SHADOW: |
| 837 | | sprite_collide = 1; |
| 838 | | blitter.mem[blitter.colpos] = 0; |
| 839 | | blitter.spritenr = blitter.mem[blitter.cmd + 2] & 0x0f; |
| 788 | state->sprite_collide = 1; |
| 789 | state->blitter.mem[state->blitter.colpos] = 0; |
| 790 | state->blitter.spritenr = state->blitter.mem[state->blitter.cmd + 2] & 0x0f; |
| 840 | 791 | } |
| 841 | 792 | } |
| 842 | 793 | |
| 843 | 794 | /* Sprite Reload Bits */ |
| 844 | 795 | o = 0x0b; |
| 845 | | if (blitter.mem[blitter.cmd + 1] & 0x30) |
| 796 | if (state->blitter.mem[state->blitter.cmd + 1] & 0x30) |
| 846 | 797 | { |
| 847 | | blitter.width = GET_WORD(blitter.mem, blitter.cmd + 11); |
| 848 | | blitter.height = GET_WORD(blitter.mem, blitter.cmd + 13); |
| 849 | | blitter.memory_accesses += 4; |
| 798 | state->blitter.width = GET_WORD(state->blitter.mem, state->blitter.cmd + 11); |
| 799 | state->blitter.height = GET_WORD(state->blitter.mem, state->blitter.cmd + 13); |
| 800 | state->blitter.memory_accesses += 4; |
| 850 | 801 | o += 4; |
| 851 | 802 | } |
| 852 | | if (blitter.mem[blitter.cmd + 1] & 0x20) |
| 803 | if (state->blitter.mem[state->blitter.cmd + 1] & 0x20) |
| 853 | 804 | { |
| 854 | | blitter.stretch = GET_WORD(blitter.mem, blitter.cmd + o); |
| 855 | | blitter.memory_accesses += 2; |
| 805 | state->blitter.stretch = GET_WORD(state->blitter.mem, state->blitter.cmd + o); |
| 806 | state->blitter.memory_accesses += 2; |
| 856 | 807 | o += 2; |
| 857 | | if (blitter.mem[blitter.cmd + 1] & 0x10) |
| 808 | if (state->blitter.mem[state->blitter.cmd + 1] & 0x10) |
| 858 | 809 | { |
| 859 | | blitter.tilt = GET_WORD(blitter.mem, blitter.cmd+o); |
| 860 | | blitter.memory_accesses += 2; |
| 810 | state->blitter.tilt = GET_WORD(state->blitter.mem, state->blitter.cmd+o); |
| 811 | state->blitter.memory_accesses += 2; |
| 861 | 812 | o += 2; |
| 862 | 813 | } |
| 863 | 814 | } |
| 864 | 815 | |
| 865 | 816 | /* Reload Palette Bit */ |
| 866 | | colors = lynx_colors[blitter.mem[blitter.cmd] >> 6]; |
| 817 | colors = lynx_colors[state->blitter.mem[state->blitter.cmd] >> 6]; |
| 867 | 818 | |
| 868 | | if (!(blitter.mem[blitter.cmd + 1] & 0x08)) |
| 819 | if (!(state->blitter.mem[state->blitter.cmd + 1] & 0x08)) |
| 869 | 820 | { |
| 870 | 821 | for (i = 0; i < colors / 2; i++) |
| 871 | 822 | { |
| 872 | | blitter.color[i * 2] = blitter.mem[blitter.cmd + o + i] >> 4; |
| 873 | | blitter.color[i * 2 + 1 ] = blitter.mem[blitter.cmd + o + i] & 0x0f; |
| 874 | | blitter.memory_accesses++; |
| 823 | state->blitter.color[i * 2] = state->blitter.mem[state->blitter.cmd + o + i] >> 4; |
| 824 | state->blitter.color[i * 2 + 1 ] = state->blitter.mem[state->blitter.cmd + o + i] & 0x0f; |
| 825 | state->blitter.memory_accesses++; |
| 875 | 826 | } |
| 876 | 827 | } |
| 877 | 828 | |
| 878 | 829 | /* Draw Sprites */ |
| 879 | | lynx_blit_lines(); |
| 830 | lynx_blit_lines(state); |
| 880 | 831 | } |
| 881 | 832 | |
| 882 | | blitter.cmd = GET_WORD(blitter.mem, blitter.cmd + 3); |
| 883 | | blitter.memory_accesses += 2; |
| 833 | state->blitter.cmd = GET_WORD(state->blitter.mem, state->blitter.cmd + 3); |
| 834 | state->blitter.memory_accesses += 2; |
| 884 | 835 | |
| 885 | | if (!(blitter.cmd & 0xff00)) |
| 836 | if (!(state->blitter.cmd & 0xff00)) |
| 886 | 837 | break; |
| 887 | 838 | } |
| 888 | 839 | |
| 889 | 840 | if (0) |
| 890 | | timer_set(machine, machine->device<cpu_device>("maincpu")->cycles_to_attotime(blitter.memory_accesses*20), NULL, 0, lynx_blitter_timer); |
| 841 | timer_set(machine, machine->device<cpu_device>("maincpu")->cycles_to_attotime(state->blitter.memory_accesses*20), NULL, 0, lynx_blitter_timer); |
| 891 | 842 | } |
| 892 | 843 | |
| 893 | 844 | |
| r9669 | r9670 | |
| 908 | 859 | - in divide, the remainder will have 2 possible errors, depending on its actual value (no further |
| 909 | 860 | notes on these errors available) */ |
| 910 | 861 | |
| 911 | | static void lynx_divide( void ) |
| 862 | static void lynx_divide( lynx_state *state ) |
| 912 | 863 | { |
| 913 | 864 | UINT32 left; |
| 914 | 865 | UINT16 right; |
| r9669 | r9670 | |
| 922 | 873 | Remainder (JK)LM |
| 923 | 874 | */ |
| 924 | 875 | |
| 925 | | left = suzy.data[MATH_H] | (suzy.data[MATH_G] << 8) | (suzy.data[MATH_F] << 16) | (suzy.data[MATH_E] << 24); |
| 926 | | right = suzy.data[MATH_P] | (suzy.data[MATH_N] << 8); |
| 876 | left = state->suzy.data[MATH_H] | (state->suzy.data[MATH_G] << 8) | (state->suzy.data[MATH_F] << 16) | (state->suzy.data[MATH_E] << 24); |
| 877 | right = state->suzy.data[MATH_P] | (state->suzy.data[MATH_N] << 8); |
| 927 | 878 | |
| 928 | | suzy.accumulate_overflow = FALSE; |
| 879 | state->suzy.accumulate_overflow = FALSE; |
| 929 | 880 | if (right == 0) |
| 930 | 881 | { |
| 931 | | suzy.accumulate_overflow = TRUE; /* during divisions, this bit is used to detect denominator = 0 */ |
| 882 | state->suzy.accumulate_overflow = TRUE; /* during divisions, this bit is used to detect denominator = 0 */ |
| 932 | 883 | res = 0xffffffff; |
| 933 | 884 | mod = 0; //? |
| 934 | 885 | } |
| r9669 | r9670 | |
| 938 | 889 | mod = left % right; |
| 939 | 890 | } |
| 940 | 891 | // logerror("coprocessor %8x / %8x = %4x\n", left, right, res); |
| 941 | | suzy.data[MATH_D] = res & 0xff; |
| 942 | | suzy.data[MATH_C] = res >> 8; |
| 943 | | suzy.data[MATH_B] = res >> 16; |
| 944 | | suzy.data[MATH_A] = res >> 24; |
| 892 | state->suzy.data[MATH_D] = res & 0xff; |
| 893 | state->suzy.data[MATH_C] = res >> 8; |
| 894 | state->suzy.data[MATH_B] = res >> 16; |
| 895 | state->suzy.data[MATH_A] = res >> 24; |
| 945 | 896 | |
| 946 | | suzy.data[MATH_M] = mod & 0xff; |
| 947 | | suzy.data[MATH_L] = mod >> 8; |
| 948 | | suzy.data[MATH_K] = mod >> 16; |
| 949 | | suzy.data[MATH_J] = mod >> 24; |
| 897 | state->suzy.data[MATH_M] = mod & 0xff; |
| 898 | state->suzy.data[MATH_L] = mod >> 8; |
| 899 | state->suzy.data[MATH_K] = mod >> 16; |
| 900 | state->suzy.data[MATH_J] = mod >> 24; |
| 950 | 901 | } |
| 951 | 902 | |
| 952 | | static void lynx_multiply( void ) |
| 903 | static void lynx_multiply( lynx_state *state ) |
| 953 | 904 | { |
| 954 | 905 | UINT16 left, right; |
| 955 | 906 | UINT32 res, accu; |
| r9669 | r9670 | |
| 961 | 912 | EFGH |
| 962 | 913 | Accumulate JKLM |
| 963 | 914 | */ |
| 964 | | suzy.accumulate_overflow = FALSE; |
| 915 | state->suzy.accumulate_overflow = FALSE; |
| 965 | 916 | |
| 966 | | left = suzy.data[MATH_B] | (suzy.data[MATH_A] << 8); |
| 967 | | right = suzy.data[MATH_D] | (suzy.data[MATH_C] << 8); |
| 917 | left = state->suzy.data[MATH_B] | (state->suzy.data[MATH_A] << 8); |
| 918 | right = state->suzy.data[MATH_D] | (state->suzy.data[MATH_C] << 8); |
| 968 | 919 | |
| 969 | 920 | res = left * right; |
| 970 | 921 | |
| 971 | | if (suzy.data[SPRSYS] & 0x80) /* signed math */ |
| 922 | if (state->suzy.data[SPRSYS] & 0x80) /* signed math */ |
| 972 | 923 | { |
| 973 | | if (!(sign_AB + sign_CD)) /* different signs */ |
| 924 | if (!(state->sign_AB + state->sign_CD)) /* different signs */ |
| 974 | 925 | res = (res ^ 0xffffffff) + 1; |
| 975 | 926 | } |
| 976 | 927 | |
| 977 | | suzy.data[MATH_H] = res & 0xff; |
| 978 | | suzy.data[MATH_G] = res >> 8; |
| 979 | | suzy.data[MATH_F] = res >> 16; |
| 980 | | suzy.data[MATH_E] = res >> 24; |
| 928 | state->suzy.data[MATH_H] = res & 0xff; |
| 929 | state->suzy.data[MATH_G] = res >> 8; |
| 930 | state->suzy.data[MATH_F] = res >> 16; |
| 931 | state->suzy.data[MATH_E] = res >> 24; |
| 981 | 932 | |
| 982 | | if (suzy.data[SPRSYS] & 0x40) /* is accumulation allowed? */ |
| 933 | if (state->suzy.data[SPRSYS] & 0x40) /* is accumulation allowed? */ |
| 983 | 934 | { |
| 984 | | accu = suzy.data[MATH_M] | suzy.data[MATH_L] << 8 | suzy.data[MATH_K] << 16 | suzy.data[MATH_J] << 24; |
| 935 | accu = state->suzy.data[MATH_M] | state->suzy.data[MATH_L] << 8 | state->suzy.data[MATH_K] << 16 | state->suzy.data[MATH_J] << 24; |
| 985 | 936 | accu += res; |
| 986 | 937 | |
| 987 | 938 | if (accu < res) |
| 988 | | suzy.accumulate_overflow = TRUE; |
| 939 | state->suzy.accumulate_overflow = TRUE; |
| 989 | 940 | |
| 990 | | suzy.data[MATH_M] = accu; |
| 991 | | suzy.data[MATH_L] = accu >> 8; |
| 992 | | suzy.data[MATH_K] = accu >> 16; |
| 993 | | suzy.data[MATH_J] = accu >> 24; |
| 941 | state->suzy.data[MATH_M] = accu; |
| 942 | state->suzy.data[MATH_L] = accu >> 8; |
| 943 | state->suzy.data[MATH_K] = accu >> 16; |
| 944 | state->suzy.data[MATH_J] = accu >> 24; |
| 994 | 945 | } |
| 995 | 946 | } |
| 996 | 947 | |
| 997 | 948 | static READ8_HANDLER( suzy_read ) |
| 998 | 949 | { |
| 950 | lynx_state *state = space->machine->driver_data<lynx_state>(); |
| 999 | 951 | UINT8 value = 0, input; |
| 1000 | 952 | |
| 1001 | 953 | switch (offset) |
| r9669 | r9670 | |
| 1004 | 956 | value = 0x01; // must not be 0 for correct power up |
| 1005 | 957 | break; |
| 1006 | 958 | case 0x92: /* Better check this with docs! */ |
| 1007 | | if (!attotime_compare(blitter.time, attotime_zero)) |
| 959 | if (!attotime_compare(state->blitter.time, attotime_zero)) |
| 1008 | 960 | { |
| 1009 | | if (space->machine->device<cpu_device>("maincpu")->attotime_to_cycles(attotime_sub(timer_get_time(space->machine), blitter.time)) > blitter.memory_accesses * 20) |
| 961 | if (space->machine->device<cpu_device>("maincpu")->attotime_to_cycles(attotime_sub(timer_get_time(space->machine), state->blitter.time)) > state->blitter.memory_accesses * 20) |
| 1010 | 962 | { |
| 1011 | | suzy.data[offset] &= ~0x01; //blitter finished |
| 1012 | | blitter.time = attotime_zero; |
| 963 | state->suzy.data[offset] &= ~0x01; //state->blitter finished |
| 964 | state->blitter.time = attotime_zero; |
| 1013 | 965 | } |
| 1014 | 966 | } |
| 1015 | | value = suzy.data[offset]; |
| 967 | value = state->suzy.data[offset]; |
| 1016 | 968 | value &= ~0x80; // math finished |
| 1017 | 969 | value &= ~0x40; |
| 1018 | | if (suzy.accumulate_overflow) |
| 970 | if (state->suzy.accumulate_overflow) |
| 1019 | 971 | value |= 0x40; |
| 1020 | 972 | break; |
| 1021 | 973 | case 0xb0: |
| 1022 | 974 | input = input_port_read(space->machine, "JOY"); |
| 1023 | | switch (lynx_rotate) |
| 975 | switch (state->rotate) |
| 1024 | 976 | { |
| 1025 | 977 | case 1: |
| 1026 | 978 | value = input; |
| r9669 | r9670 | |
| 1039 | 991 | if (value & PAD_LEFT) input |= PAD_UP; |
| 1040 | 992 | break; |
| 1041 | 993 | } |
| 1042 | | if (suzy.data[SPRSYS] & 0x08) /* Left handed controls */ |
| 994 | if (state->suzy.data[SPRSYS] & 0x08) /* Left handed controls */ |
| 1043 | 995 | { |
| 1044 | 996 | value = input & 0x0f; |
| 1045 | 997 | if (input & PAD_UP) value |= PAD_DOWN; |
| r9669 | r9670 | |
| 1054 | 1006 | value = input_port_read(space->machine, "PAUSE"); |
| 1055 | 1007 | break; |
| 1056 | 1008 | case 0xb2: |
| 1057 | | value = *(memory_region(space->machine, "user1") + (suzy.high * lynx_granularity) + suzy.low); |
| 1058 | | suzy.low = (suzy.low + 1) & (lynx_granularity - 1); |
| 1009 | value = *(memory_region(space->machine, "user1") + (state->suzy.high * state->granularity) + state->suzy.low); |
| 1010 | state->suzy.low = (state->suzy.low + 1) & (state->granularity - 1); |
| 1059 | 1011 | break; |
| 1060 | 1012 | case 0xb3: /* we need bank 1 emulation!!! */ |
| 1061 | 1013 | default: |
| 1062 | | value = suzy.data[offset]; |
| 1014 | value = state->suzy.data[offset]; |
| 1063 | 1015 | } |
| 1064 | 1016 | // logerror("suzy read %.2x %.2x\n",offset,data); |
| 1065 | 1017 | return value; |
| r9669 | r9670 | |
| 1067 | 1019 | |
| 1068 | 1020 | static WRITE8_HANDLER( suzy_write ) |
| 1069 | 1021 | { |
| 1070 | | suzy.data[offset] = data; |
| 1022 | lynx_state *state = space->machine->driver_data<lynx_state>(); |
| 1023 | state->suzy.data[offset] = data; |
| 1071 | 1024 | |
| 1072 | 1025 | /* Additional effects of a write */ |
| 1073 | 1026 | /* Even addresses are the LSB. Any CPU write to an LSB in 0x00-0x7f will set the MSB to 0. */ |
| r9669 | r9670 | |
| 1086 | 1039 | case 0x70: case 0x72: case 0x74: case 0x76: case 0x78: case 0x7a: case 0x7c: case 0x7e: |
| 1087 | 1040 | /* B, D, F, H , K */ |
| 1088 | 1041 | case 0x52: case 0x54: case 0x60: case 0x62: case 0x6e: |
| 1089 | | suzy.data[offset + 1] = 0; |
| 1042 | state->suzy.data[offset + 1] = 0; |
| 1090 | 1043 | break; |
| 1091 | 1044 | /* Writing to M (0x6c) will also clear the accumulator overflow bit */ |
| 1092 | 1045 | case 0x6c: |
| 1093 | | suzy.data[offset + 1] = 0; |
| 1094 | | suzy.accumulate_overflow = FALSE; |
| 1046 | state->suzy.data[offset + 1] = 0; |
| 1047 | state->suzy.accumulate_overflow = FALSE; |
| 1095 | 1048 | break; |
| 1096 | 1049 | case 0x53: |
| 1097 | 1050 | /* If we are going to perform a signed multiplication, we store the sign and convert the number |
| 1098 | 1051 | to an unsigned one */ |
| 1099 | | if (suzy.data[SPRSYS] & 0x80) /* signed math */ |
| 1052 | if (state->suzy.data[SPRSYS] & 0x80) /* signed math */ |
| 1100 | 1053 | { |
| 1101 | 1054 | UINT16 factor, temp; |
| 1102 | | factor = suzy.data[MATH_D] | (suzy.data[MATH_C] << 8); |
| 1055 | factor = state->suzy.data[MATH_D] | (state->suzy.data[MATH_C] << 8); |
| 1103 | 1056 | if ((factor - 1) & 0x8000) /* here we use -1 to cover the math bugs on the sign of 0 and 0x8000 */ |
| 1104 | 1057 | { |
| 1105 | 1058 | temp = (factor ^ 0xffff) + 1; |
| 1106 | | sign_CD = - 1; |
| 1107 | | suzy.data[MATH_D] = temp & 0xff; |
| 1108 | | suzy.data[MATH_C] = temp >> 8; |
| 1059 | state->sign_CD = - 1; |
| 1060 | state->suzy.data[MATH_D] = temp & 0xff; |
| 1061 | state->suzy.data[MATH_C] = temp >> 8; |
| 1109 | 1062 | } |
| 1110 | 1063 | else |
| 1111 | | sign_CD = 1; |
| 1064 | state->sign_CD = 1; |
| 1112 | 1065 | } |
| 1113 | 1066 | break; |
| 1114 | 1067 | /* Writing to A will start a 16 bit multiply */ |
| 1115 | 1068 | /* If we are going to perform a signed multiplication, we also store the sign and convert the |
| 1116 | 1069 | number to an unsigned one */ |
| 1117 | 1070 | case 0x55: |
| 1118 | | if (suzy.data[SPRSYS] & 0x80) /* signed math */ |
| 1071 | if (state->suzy.data[SPRSYS] & 0x80) /* signed math */ |
| 1119 | 1072 | { |
| 1120 | 1073 | UINT16 factor, temp; |
| 1121 | | factor = suzy.data[MATH_B] | (suzy.data[MATH_A] << 8); |
| 1074 | factor = state->suzy.data[MATH_B] | (state->suzy.data[MATH_A] << 8); |
| 1122 | 1075 | if ((factor - 1) & 0x8000) /* here we use -1 to cover the math bugs on the sign of 0 and 0x8000 */ |
| 1123 | 1076 | { |
| 1124 | 1077 | temp = (factor ^ 0xffff) + 1; |
| 1125 | | sign_AB = - 1; |
| 1126 | | suzy.data[MATH_B] = temp & 0xff; |
| 1127 | | suzy.data[MATH_A] = temp >> 8; |
| 1078 | state->sign_AB = - 1; |
| 1079 | state->suzy.data[MATH_B] = temp & 0xff; |
| 1080 | state->suzy.data[MATH_A] = temp >> 8; |
| 1128 | 1081 | } |
| 1129 | 1082 | else |
| 1130 | | sign_AB = 1; |
| 1083 | state->sign_AB = 1; |
| 1131 | 1084 | } |
| 1132 | | lynx_multiply(); |
| 1085 | lynx_multiply(state); |
| 1133 | 1086 | break; |
| 1134 | 1087 | /* Writing to E will start a 16 bit divide */ |
| 1135 | 1088 | case 0x63: |
| 1136 | | lynx_divide(); |
| 1089 | lynx_divide(state); |
| 1137 | 1090 | break; |
| 1138 | 1091 | case 0x91: |
| 1139 | 1092 | if (data & 0x01) |
| 1140 | 1093 | { |
| 1141 | | blitter.time = timer_get_time(space->machine); |
| 1094 | state->blitter.time = timer_get_time(space->machine); |
| 1142 | 1095 | lynx_blitter(space->machine); |
| 1143 | 1096 | } |
| 1144 | 1097 | break; |
| r9669 | r9670 | |
| 1165 | 1118 | 0xfdb0-f rw bit0..3 farben 0..15 |
| 1166 | 1119 | */ |
| 1167 | 1120 | |
| 1168 | | typedef struct { |
| 1169 | | UINT8 data[0x100]; |
| 1170 | | } MIKEY; |
| 1171 | 1121 | |
| 1172 | | static MIKEY mikey; |
| 1173 | 1122 | |
| 1174 | | |
| 1175 | | static UINT8 lynx_read_vram(UINT16 address) |
| 1123 | static UINT8 lynx_read_vram(lynx_state *state, UINT16 address) |
| 1176 | 1124 | { |
| 1177 | 1125 | UINT8 result = 0x00; |
| 1178 | 1126 | if (address <= 0xfbff) |
| 1179 | | result = lynx_mem_0000[address - 0x0000]; |
| 1127 | result = state->mem_0000[address - 0x0000]; |
| 1180 | 1128 | else if (address <= 0xfcff) |
| 1181 | | result = lynx_mem_fc00[address - 0xfc00]; |
| 1129 | result = state->mem_fc00[address - 0xfc00]; |
| 1182 | 1130 | else if (address <= 0xfdff) |
| 1183 | | result = lynx_mem_fd00[address - 0xfd00]; |
| 1131 | result = state->mem_fd00[address - 0xfd00]; |
| 1184 | 1132 | else if (address <= 0xfff7) |
| 1185 | | result = lynx_mem_fe00[address - 0xfe00]; |
| 1133 | result = state->mem_fe00[address - 0xfe00]; |
| 1186 | 1134 | else if (address >= 0xfffa) |
| 1187 | | result = lynx_mem_fffa[address - 0xfffa]; |
| 1135 | result = state->mem_fffa[address - 0xfffa]; |
| 1188 | 1136 | return result; |
| 1189 | 1137 | } |
| 1190 | 1138 | |
| r9669 | r9670 | |
| 1198 | 1146 | ; B1 1 EQU flip screen |
| 1199 | 1147 | ; B0 1 EQU video DMA enabled |
| 1200 | 1148 | */ |
| 1201 | | static int lynx_height, lynx_width; |
| 1202 | 1149 | static void lynx_draw_lines(running_machine *machine, int newline) |
| 1203 | 1150 | { |
| 1151 | lynx_state *state = machine->driver_data<lynx_state>(); |
| 1204 | 1152 | int h,w; |
| 1205 | 1153 | int x, yend; |
| 1206 | 1154 | UINT16 j; // clipping needed! |
| r9669 | r9670 | |
| 1215 | 1163 | if (yend > 102) |
| 1216 | 1164 | yend = 102; |
| 1217 | 1165 | |
| 1218 | | if (yend == lynx_line_y) |
| 1166 | if (yend == state->line_y) |
| 1219 | 1167 | { |
| 1220 | 1168 | if (newline == -1) |
| 1221 | | lynx_line_y = 0; |
| 1169 | state->line_y = 0; |
| 1222 | 1170 | return; |
| 1223 | 1171 | } |
| 1224 | 1172 | |
| 1225 | | j = (mikey.data[0x94] | (mikey.data[0x95]<<8)) + lynx_line_y * 160 / 2; |
| 1226 | | if (mikey.data[0x92] & 0x02) |
| 1173 | j = (state->mikey.data[0x94] | (state->mikey.data[0x95]<<8)) + state->line_y * 160 / 2; |
| 1174 | if (state->mikey.data[0x92] & 0x02) |
| 1227 | 1175 | j -= 160 * 102 / 2 - 1; |
| 1228 | 1176 | |
| 1229 | 1177 | /* rotation */ |
| 1230 | | if (lynx_rotate & 0x03) |
| 1178 | if (state->rotate & 0x03) |
| 1231 | 1179 | { |
| 1232 | 1180 | h = 160; w = 102; |
| 1233 | | if (((lynx_rotate == 1) && (mikey.data[0x92] & 0x02)) || ((lynx_rotate == 2) && !(mikey.data[0x92] & 0x02))) |
| 1181 | if (((state->rotate == 1) && (state->mikey.data[0x92] & 0x02)) || ((state->rotate == 2) && !(state->mikey.data[0x92] & 0x02))) |
| 1234 | 1182 | { |
| 1235 | | for ( ; lynx_line_y < yend; lynx_line_y++) |
| 1183 | for ( ; state->line_y < yend; state->line_y++) |
| 1236 | 1184 | { |
| 1237 | | line = BITMAP_ADDR16(machine->generic.tmpbitmap, lynx_line_y, 0); |
| 1185 | line = BITMAP_ADDR16(machine->generic.tmpbitmap, state->line_y, 0); |
| 1238 | 1186 | for (x = 160 - 2; x >= 0; j++, x -= 2) |
| 1239 | 1187 | { |
| 1240 | | byte = lynx_read_vram(j); |
| 1241 | | line[x + 1] = lynx_palette[(byte >> 4) & 0x0f]; |
| 1242 | | line[x + 0] = lynx_palette[(byte >> 0) & 0x0f]; |
| 1188 | byte = lynx_read_vram(state, j); |
| 1189 | line[x + 1] = state->palette[(byte >> 4) & 0x0f]; |
| 1190 | line[x + 0] = state->palette[(byte >> 0) & 0x0f]; |
| 1243 | 1191 | } |
| 1244 | 1192 | } |
| 1245 | 1193 | } |
| 1246 | 1194 | else |
| 1247 | 1195 | { |
| 1248 | | for ( ; lynx_line_y < yend; lynx_line_y++) |
| 1196 | for ( ; state->line_y < yend; state->line_y++) |
| 1249 | 1197 | { |
| 1250 | | line = BITMAP_ADDR16(machine->generic.tmpbitmap, 102 - 1 - lynx_line_y, 0); |
| 1198 | line = BITMAP_ADDR16(machine->generic.tmpbitmap, 102 - 1 - state->line_y, 0); |
| 1251 | 1199 | for (x = 0; x < 160; j++, x += 2) |
| 1252 | 1200 | { |
| 1253 | | byte = lynx_read_vram(j); |
| 1254 | | line[x + 0] = lynx_palette[(byte >> 4) & 0x0f]; |
| 1255 | | line[x + 1] = lynx_palette[(byte >> 0) & 0x0f]; |
| 1201 | byte = lynx_read_vram(state, j); |
| 1202 | line[x + 0] = state->palette[(byte >> 4) & 0x0f]; |
| 1203 | line[x + 1] = state->palette[(byte >> 0) & 0x0f]; |
| 1256 | 1204 | } |
| 1257 | 1205 | } |
| 1258 | 1206 | } |
| r9669 | r9670 | |
| 1260 | 1208 | else |
| 1261 | 1209 | { |
| 1262 | 1210 | w = 160; h = 102; |
| 1263 | | if (mikey.data[0x92] & 0x02) |
| 1211 | if (state->mikey.data[0x92] & 0x02) |
| 1264 | 1212 | { |
| 1265 | | for ( ; lynx_line_y < yend; lynx_line_y++) |
| 1213 | for ( ; state->line_y < yend; state->line_y++) |
| 1266 | 1214 | { |
| 1267 | | line = BITMAP_ADDR16(machine->generic.tmpbitmap, 102 - 1 - lynx_line_y, 0); |
| 1215 | line = BITMAP_ADDR16(machine->generic.tmpbitmap, 102 - 1 - state->line_y, 0); |
| 1268 | 1216 | for (x = 160 - 2; x >= 0; j++, x -= 2) |
| 1269 | 1217 | { |
| 1270 | | byte = lynx_read_vram(j); |
| 1271 | | line[x + 1] = lynx_palette[(byte >> 4) & 0x0f]; |
| 1272 | | line[x + 0] = lynx_palette[(byte >> 0) & 0x0f]; |
| 1218 | byte = lynx_read_vram(state, j); |
| 1219 | line[x + 1] = state->palette[(byte >> 4) & 0x0f]; |
| 1220 | line[x + 0] = state->palette[(byte >> 0) & 0x0f]; |
| 1273 | 1221 | } |
| 1274 | 1222 | } |
| 1275 | 1223 | } |
| 1276 | 1224 | else |
| 1277 | 1225 | { |
| 1278 | | for ( ; lynx_line_y < yend; lynx_line_y++) |
| 1226 | for ( ; state->line_y < yend; state->line_y++) |
| 1279 | 1227 | { |
| 1280 | | line = BITMAP_ADDR16(machine->generic.tmpbitmap, lynx_line_y, 0); |
| 1228 | line = BITMAP_ADDR16(machine->generic.tmpbitmap, state->line_y, 0); |
| 1281 | 1229 | for (x = 0; x < 160; j++, x += 2) |
| 1282 | 1230 | { |
| 1283 | | byte = lynx_read_vram(j); |
| 1284 | | line[x + 0] = lynx_palette[(byte >> 4) & 0x0f]; |
| 1285 | | line[x + 1] = lynx_palette[(byte >> 0) & 0x0f]; |
| 1231 | byte = lynx_read_vram(state, j); |
| 1232 | line[x + 0] = state->palette[(byte >> 4) & 0x0f]; |
| 1233 | line[x + 1] = state->palette[(byte >> 0) & 0x0f]; |
| 1286 | 1234 | } |
| 1287 | 1235 | } |
| 1288 | 1236 | } |
| 1289 | 1237 | } |
| 1290 | 1238 | if (newline == -1) |
| 1291 | 1239 | { |
| 1292 | | lynx_line_y = 0; |
| 1293 | | if ((w != lynx_width) || (h != lynx_height)) |
| 1240 | state->line_y = 0; |
| 1241 | if ((w != state->width) || (h != state->height)) |
| 1294 | 1242 | { |
| 1295 | | lynx_width = w; |
| 1296 | | lynx_height = h; |
| 1243 | state->width = w; |
| 1244 | state->height = h; |
| 1297 | 1245 | machine->primary_screen->set_visible_area(0, w - 1, 0, h - 1); |
| 1298 | 1246 | } |
| 1299 | 1247 | } |
| r9669 | r9670 | |
| 1339 | 1287 | TIM_BORROWIN EQU %00000010 |
| 1340 | 1288 | TIM_BORROWOUT EQU %00000001 |
| 1341 | 1289 | */ |
| 1342 | | typedef struct { |
| 1343 | | UINT8 bakup; |
| 1344 | | UINT8 cntrl1; |
| 1345 | | UINT8 cntrl2; |
| 1346 | | int counter; |
| 1347 | | emu_timer *timer; |
| 1348 | | int timer_active; |
| 1349 | | } LYNX_TIMER; |
| 1350 | 1290 | |
| 1351 | 1291 | #define NR_LYNX_TIMERS 8 |
| 1352 | 1292 | |
| 1353 | | static LYNX_TIMER lynx_timer[NR_LYNX_TIMERS]; |
| 1354 | 1293 | |
| 1355 | 1294 | static TIMER_CALLBACK(lynx_timer_shot); |
| 1356 | 1295 | |
| 1357 | 1296 | static void lynx_timer_init(running_machine *machine, int which) |
| 1358 | 1297 | { |
| 1359 | | memset( &lynx_timer[which], 0, sizeof(LYNX_TIMER) ); |
| 1360 | | lynx_timer[which].timer = timer_alloc(machine, lynx_timer_shot , NULL); |
| 1298 | lynx_state *state = machine->driver_data<lynx_state>(); |
| 1299 | memset( &state->timer[which], 0, sizeof(LYNX_TIMER) ); |
| 1300 | state->timer[which].timer = timer_alloc(machine, lynx_timer_shot , NULL); |
| 1361 | 1301 | } |
| 1362 | 1302 | |
| 1363 | 1303 | static void lynx_timer_signal_irq(running_machine *machine, int which) |
| 1364 | 1304 | { |
| 1365 | | if ( ( lynx_timer[which].cntrl1 & 0x80 ) && ( which != 4 ) ) |
| 1305 | lynx_state *state = machine->driver_data<lynx_state>(); |
| 1306 | if ( ( state->timer[which].cntrl1 & 0x80 ) && ( which != 4 ) ) |
| 1366 | 1307 | { // irq flag handling later |
| 1367 | | mikey.data[0x81] |= ( 1 << which ); |
| 1308 | state->mikey.data[0x81] |= ( 1 << which ); |
| 1368 | 1309 | cputag_set_input_line(machine, "maincpu", M65SC02_IRQ_LINE, ASSERT_LINE); |
| 1369 | 1310 | } |
| 1370 | 1311 | switch ( which ) |
| 1371 | 1312 | { |
| 1372 | 1313 | case 0: |
| 1373 | 1314 | lynx_timer_count_down( machine, 2 ); |
| 1374 | | lynx_line++; |
| 1315 | state->line++; |
| 1375 | 1316 | break; |
| 1376 | 1317 | case 2: |
| 1377 | 1318 | lynx_timer_count_down( machine, 4 ); |
| 1378 | 1319 | lynx_draw_lines( machine, -1 ); |
| 1379 | | lynx_line=0; |
| 1320 | state->line=0; |
| 1380 | 1321 | break; |
| 1381 | 1322 | case 1: |
| 1382 | 1323 | lynx_timer_count_down( machine, 3 ); |
| r9669 | r9670 | |
| 1388 | 1329 | lynx_timer_count_down( machine, 7 ); |
| 1389 | 1330 | break; |
| 1390 | 1331 | case 7: |
| 1391 | | lynx_audio_count_down( lynx_audio, 0 ); |
| 1332 | lynx_audio_count_down( state->audio, 0 ); |
| 1392 | 1333 | break; |
| 1393 | 1334 | } |
| 1394 | 1335 | } |
| 1395 | 1336 | |
| 1396 | 1337 | void lynx_timer_count_down(running_machine *machine, int which) |
| 1397 | 1338 | { |
| 1398 | | if ( ( lynx_timer[which].cntrl1 & 0x0f ) == 0x0f ) |
| 1339 | lynx_state *state = machine->driver_data<lynx_state>(); |
| 1340 | if ( ( state->timer[which].cntrl1 & 0x0f ) == 0x0f ) |
| 1399 | 1341 | { |
| 1400 | | if ( lynx_timer[which].counter > 0 ) |
| 1342 | if ( state->timer[which].counter > 0 ) |
| 1401 | 1343 | { |
| 1402 | | lynx_timer[which].counter--; |
| 1344 | state->timer[which].counter--; |
| 1403 | 1345 | return; |
| 1404 | 1346 | } |
| 1405 | | if ( lynx_timer[which].counter == 0 ) |
| 1347 | if ( state->timer[which].counter == 0 ) |
| 1406 | 1348 | { |
| 1407 | | lynx_timer[which].cntrl2 |= 8; |
| 1349 | state->timer[which].cntrl2 |= 8; |
| 1408 | 1350 | lynx_timer_signal_irq(machine, which); |
| 1409 | | if ( lynx_timer[which].cntrl1 & 0x10 ) |
| 1351 | if ( state->timer[which].cntrl1 & 0x10 ) |
| 1410 | 1352 | { |
| 1411 | | lynx_timer[which].counter = lynx_timer[which].bakup; |
| 1353 | state->timer[which].counter = state->timer[which].bakup; |
| 1412 | 1354 | } |
| 1413 | 1355 | else |
| 1414 | 1356 | { |
| 1415 | | lynx_timer[which].counter--; |
| 1357 | state->timer[which].counter--; |
| 1416 | 1358 | } |
| 1417 | 1359 | return; |
| 1418 | 1360 | } |
| r9669 | r9670 | |
| 1421 | 1363 | |
| 1422 | 1364 | static TIMER_CALLBACK(lynx_timer_shot) |
| 1423 | 1365 | { |
| 1424 | | lynx_timer[param].cntrl2 |= 8; |
| 1366 | lynx_state *state = machine->driver_data<lynx_state>(); |
| 1367 | state->timer[param].cntrl2 |= 8; |
| 1425 | 1368 | lynx_timer_signal_irq( machine, param ); |
| 1426 | | if ( ! ( lynx_timer[param].cntrl1 & 0x10 ) ) |
| 1427 | | lynx_timer[param].timer_active = 0; |
| 1369 | if ( ! ( state->timer[param].cntrl1 & 0x10 ) ) |
| 1370 | state->timer[param].timer_active = 0; |
| 1428 | 1371 | } |
| 1429 | 1372 | |
| 1430 | 1373 | static UINT32 lynx_time_factor(int val) |
| r9669 | r9670 | |
| 1442 | 1385 | } |
| 1443 | 1386 | } |
| 1444 | 1387 | |
| 1445 | | static UINT8 lynx_timer_read(int which, int offset) |
| 1388 | static UINT8 lynx_timer_read(lynx_state *state, int which, int offset) |
| 1446 | 1389 | { |
| 1447 | 1390 | UINT8 value = 0; |
| 1448 | 1391 | |
| 1449 | 1392 | switch (offset) |
| 1450 | 1393 | { |
| 1451 | 1394 | case 0: |
| 1452 | | value = lynx_timer[which].bakup; |
| 1395 | value = state->timer[which].bakup; |
| 1453 | 1396 | break; |
| 1454 | 1397 | case 1: |
| 1455 | | value = lynx_timer[which].cntrl1; |
| 1398 | value = state->timer[which].cntrl1; |
| 1456 | 1399 | break; |
| 1457 | 1400 | case 2: |
| 1458 | | if ((lynx_timer[which].cntrl1 & 0x07) == 0x07) |
| 1401 | if ((state->timer[which].cntrl1 & 0x07) == 0x07) |
| 1459 | 1402 | { |
| 1460 | | value = lynx_timer[which].counter; |
| 1403 | value = state->timer[which].counter; |
| 1461 | 1404 | } |
| 1462 | 1405 | else |
| 1463 | 1406 | { |
| 1464 | | if ( lynx_timer[which].timer_active ) |
| 1465 | | value = (UINT8) ( lynx_timer[which].bakup - attotime_mul(timer_timeleft(lynx_timer[which].timer), lynx_time_factor( lynx_timer[which].cntrl1 & 0x07 )).seconds); |
| 1407 | if ( state->timer[which].timer_active ) |
| 1408 | value = (UINT8) ( state->timer[which].bakup - attotime_mul(timer_timeleft(state->timer[which].timer), lynx_time_factor( state->timer[which].cntrl1 & 0x07 )).seconds); |
| 1466 | 1409 | } |
| 1467 | 1410 | break; |
| 1468 | 1411 | |
| 1469 | 1412 | case 3: |
| 1470 | | value = lynx_timer[which].cntrl2; |
| 1413 | value = state->timer[which].cntrl2; |
| 1471 | 1414 | break; |
| 1472 | 1415 | } |
| 1473 | 1416 | logerror("timer %d read %x %.2x\n", which, offset, value); |
| 1474 | 1417 | return value; |
| 1475 | 1418 | } |
| 1476 | 1419 | |
| 1477 | | static void lynx_timer_write(int which, int offset, UINT8 data) |
| 1420 | static void lynx_timer_write(lynx_state *state, int which, int offset, UINT8 data) |
| 1478 | 1421 | { |
| 1479 | 1422 | logerror("timer %d write %x %.2x\n", which, offset, data); |
| 1480 | 1423 | |
| 1481 | 1424 | switch (offset) |
| 1482 | 1425 | { |
| 1483 | 1426 | case 0: |
| 1484 | | lynx_timer[which].bakup = data; |
| 1427 | state->timer[which].bakup = data; |
| 1485 | 1428 | break; |
| 1486 | 1429 | case 1: |
| 1487 | | lynx_timer[which].cntrl1 = data; |
| 1430 | state->timer[which].cntrl1 = data; |
| 1488 | 1431 | if (data & 0x40) |
| 1489 | | lynx_timer[which].cntrl2 &= ~0x08; |
| 1432 | state->timer[which].cntrl2 &= ~0x08; |
| 1490 | 1433 | break; |
| 1491 | 1434 | case 2: |
| 1492 | | // lynx_timer[which].counter = data; // why commented out? |
| 1435 | // state->timer[which].counter = data; // why commented out? |
| 1493 | 1436 | break; |
| 1494 | 1437 | case 3: |
| 1495 | | lynx_timer[which].cntrl2 = (lynx_timer[which].cntrl2 & 0x08) | (data & ~0x08); |
| 1438 | state->timer[which].cntrl2 = (state->timer[which].cntrl2 & 0x08) | (data & ~0x08); |
| 1496 | 1439 | break; |
| 1497 | 1440 | } |
| 1498 | 1441 | |
| 1499 | 1442 | /* Update timers */ |
| 1500 | 1443 | if ( offset < 3 ) |
| 1501 | 1444 | { |
| 1502 | | timer_reset(lynx_timer[which].timer, attotime_never); |
| 1503 | | lynx_timer[which].timer_active = 0; |
| 1504 | | if ((lynx_timer[which].cntrl1 & 0x08)) // 0x48? |
| 1445 | timer_reset(state->timer[which].timer, attotime_never); |
| 1446 | state->timer[which].timer_active = 0; |
| 1447 | if ((state->timer[which].cntrl1 & 0x08)) // 0x48? |
| 1505 | 1448 | { |
| 1506 | | if ((lynx_timer[which].cntrl1 & 0x07) != 0x07) |
| 1449 | if ((state->timer[which].cntrl1 & 0x07) != 0x07) |
| 1507 | 1450 | { |
| 1508 | | attotime t = attotime_mul(ATTOTIME_IN_HZ(lynx_time_factor(lynx_timer[which].cntrl1 & 0x07)), lynx_timer[which].bakup + 1); |
| 1509 | | if (lynx_timer[which].cntrl1 & 0x10) |
| 1510 | | timer_adjust_periodic(lynx_timer[which].timer, attotime_zero, which, t); |
| 1451 | attotime t = attotime_mul(ATTOTIME_IN_HZ(lynx_time_factor(state->timer[which].cntrl1 & 0x07)), state->timer[which].bakup + 1); |
| 1452 | if (state->timer[which].cntrl1 & 0x10) |
| 1453 | timer_adjust_periodic(state->timer[which].timer, attotime_zero, which, t); |
| 1511 | 1454 | else |
| 1512 | | timer_adjust_oneshot(lynx_timer[which].timer, t, which); |
| 1513 | | lynx_timer[which].timer_active = 1; |
| 1455 | timer_adjust_oneshot(state->timer[which].timer, t, which); |
| 1456 | state->timer[which].timer_active = 1; |
| 1514 | 1457 | } |
| 1515 | 1458 | } |
| 1516 | 1459 | } |
| r9669 | r9670 | |
| 1524 | 1467 | ****************************************/ |
| 1525 | 1468 | |
| 1526 | 1469 | |
| 1527 | | static struct { |
| 1528 | | UINT8 serctl; |
| 1529 | | UINT8 data_received, data_to_send, buffer; |
| 1530 | | |
| 1531 | | int received; |
| 1532 | | int sending; |
| 1533 | | int buffer_loaded; |
| 1534 | | } uart; |
| 1535 | | |
| 1536 | | static void lynx_uart_reset(void) |
| 1470 | static void lynx_uart_reset(lynx_state *state) |
| 1537 | 1471 | { |
| 1538 | | memset(&uart, 0, sizeof(uart)); |
| 1472 | memset(&state->uart, 0, sizeof(state->uart)); |
| 1539 | 1473 | } |
| 1540 | 1474 | |
| 1541 | 1475 | static TIMER_CALLBACK(lynx_uart_timer) |
| 1542 | 1476 | { |
| 1543 | | if (uart.buffer_loaded) |
| 1477 | lynx_state *state = machine->driver_data<lynx_state>(); |
| 1478 | if (state->uart.buffer_loaded) |
| 1544 | 1479 | { |
| 1545 | | uart.data_to_send = uart.buffer; |
| 1546 | | uart.buffer_loaded = FALSE; |
| 1480 | state->uart.data_to_send = state->uart.buffer; |
| 1481 | state->uart.buffer_loaded = FALSE; |
| 1547 | 1482 | timer_set(machine, ATTOTIME_IN_USEC(11), NULL, 0, lynx_uart_timer); |
| 1548 | 1483 | } |
| 1549 | 1484 | else |
| 1550 | | uart.sending = FALSE; |
| 1485 | state->uart.sending = FALSE; |
| 1551 | 1486 | |
| 1552 | | // mikey.data[0x80]|=0x10; |
| 1553 | | if (uart.serctl & 0x80) |
| 1487 | // state->mikey.data[0x80]|=0x10; |
| 1488 | if (state->uart.serctl & 0x80) |
| 1554 | 1489 | { |
| 1555 | | mikey.data[0x81] |= 0x10; |
| 1490 | state->mikey.data[0x81] |= 0x10; |
| 1556 | 1491 | cputag_set_input_line(machine, "maincpu", M65SC02_IRQ_LINE, ASSERT_LINE); |
| 1557 | 1492 | } |
| 1558 | 1493 | } |
| 1559 | 1494 | |
| 1560 | 1495 | static READ8_HANDLER(lynx_uart_r) |
| 1561 | 1496 | { |
| 1497 | lynx_state *state = space->machine->driver_data<lynx_state>(); |
| 1562 | 1498 | UINT8 value = 0x00; |
| 1563 | 1499 | switch (offset) |
| 1564 | 1500 | { |
| 1565 | 1501 | case 0x8c: |
| 1566 | | if (!uart.buffer_loaded) |
| 1502 | if (!state->uart.buffer_loaded) |
| 1567 | 1503 | value |= 0x80; |
| 1568 | | if (uart.received) |
| 1504 | if (state->uart.received) |
| 1569 | 1505 | value |= 0x40; |
| 1570 | | if (!uart.sending) |
| 1506 | if (!state->uart.sending) |
| 1571 | 1507 | value |= 0x20; |
| 1572 | 1508 | break; |
| 1573 | 1509 | |
| 1574 | 1510 | case 0x8d: |
| 1575 | | value = uart.data_received; |
| 1511 | value = state->uart.data_received; |
| 1576 | 1512 | break; |
| 1577 | 1513 | } |
| 1578 | 1514 | logerror("uart read %.2x %.2x\n", offset, value); |
| r9669 | r9670 | |
| 1581 | 1517 | |
| 1582 | 1518 | static WRITE8_HANDLER(lynx_uart_w) |
| 1583 | 1519 | { |
| 1520 | lynx_state *state = space->machine->driver_data<lynx_state>(); |
| 1584 | 1521 | logerror("uart write %.2x %.2x\n", offset, data); |
| 1585 | 1522 | switch (offset) |
| 1586 | 1523 | { |
| 1587 | 1524 | case 0x8c: |
| 1588 | | uart.serctl = data; |
| 1525 | state->uart.serctl = data; |
| 1589 | 1526 | break; |
| 1590 | 1527 | |
| 1591 | 1528 | case 0x8d: |
| 1592 | | if (uart.sending) |
| 1529 | if (state->uart.sending) |
| 1593 | 1530 | { |
| 1594 | | uart.buffer = data; |
| 1595 | | uart.buffer_loaded = TRUE; |
| 1531 | state->uart.buffer = data; |
| 1532 | state->uart.buffer_loaded = TRUE; |
| 1596 | 1533 | } |
| 1597 | 1534 | else |
| 1598 | 1535 | { |
| 1599 | | uart.sending = TRUE; |
| 1600 | | uart.data_to_send = data; |
| 1536 | state->uart.sending = TRUE; |
| 1537 | state->uart.data_to_send = data; |
| 1601 | 1538 | timer_set(space->machine, ATTOTIME_IN_USEC(11), NULL, 0, lynx_uart_timer); |
| 1602 | 1539 | } |
| 1603 | 1540 | break; |
| r9669 | r9670 | |
| 1614 | 1551 | |
| 1615 | 1552 | static READ8_HANDLER( mikey_read ) |
| 1616 | 1553 | { |
| 1554 | lynx_state *state = space->machine->driver_data<lynx_state>(); |
| 1617 | 1555 | UINT8 direction, value = 0x00; |
| 1618 | 1556 | |
| 1619 | 1557 | switch (offset) |
| r9669 | r9670 | |
| 1626 | 1564 | case 0x14: case 0x15: case 0x16: case 0x17: |
| 1627 | 1565 | case 0x18: case 0x19: case 0x1a: case 0x1b: |
| 1628 | 1566 | case 0x1c: case 0x1d: case 0x1e: case 0x1f: |
| 1629 | | value = lynx_timer_read(offset >> 2, offset & 0x03); |
| 1567 | value = lynx_timer_read(state, offset >> 2, offset & 0x03); |
| 1630 | 1568 | break; |
| 1631 | 1569 | |
| 1632 | 1570 | case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: |
| r9669 | r9670 | |
| 1634 | 1572 | case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: |
| 1635 | 1573 | case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f: |
| 1636 | 1574 | case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x50: |
| 1637 | | value = lynx_audio_read(lynx_audio, offset); |
| 1575 | value = lynx_audio_read(state->audio, offset); |
| 1638 | 1576 | break; |
| 1639 | 1577 | |
| 1640 | 1578 | case 0x80: |
| 1641 | 1579 | case 0x81: |
| 1642 | | value = mikey.data[offset]; |
| 1580 | value = state->mikey.data[offset]; |
| 1643 | 1581 | logerror( "mikey read %.2x %.2x\n", offset, value ); |
| 1644 | 1582 | break; |
| 1645 | 1583 | |
| r9669 | r9670 | |
| 1657 | 1595 | break; |
| 1658 | 1596 | |
| 1659 | 1597 | case 0x8b: |
| 1660 | | direction = mikey.data[0x8a]; |
| 1661 | | value |= (direction & 0x01) ? (mikey.data[offset] & 0x01) : 0x01; // External Power input |
| 1662 | | value |= (direction & 0x02) ? (mikey.data[offset] & 0x02) : 0x00; // Cart Address Data output (0 turns cart power on) |
| 1663 | | value |= (direction & 0x04) ? (mikey.data[offset] & 0x04) : 0x04; // noexp input |
| 1598 | direction = state->mikey.data[0x8a]; |
| 1599 | value |= (direction & 0x01) ? (state->mikey.data[offset] & 0x01) : 0x01; // External Power input |
| 1600 | value |= (direction & 0x02) ? (state->mikey.data[offset] & 0x02) : 0x00; // Cart Address Data output (0 turns cart power on) |
| 1601 | value |= (direction & 0x04) ? (state->mikey.data[offset] & 0x04) : 0x04; // noexp input |
| 1664 | 1602 | // REST still to implement |
| 1665 | | value |= (direction & 0x08) ? (mikey.data[offset] & 0x08) : 0x00; // rest output |
| 1666 | | value |= (direction & 0x10) ? (mikey.data[offset] & 0x10) : 0x10; // audin input |
| 1603 | value |= (direction & 0x08) ? (state->mikey.data[offset] & 0x08) : 0x00; // rest output |
| 1604 | value |= (direction & 0x10) ? (state->mikey.data[offset] & 0x10) : 0x10; // audin input |
| 1667 | 1605 | /* Hack: we disable COMLynx */ |
| 1668 | 1606 | value |= 0x04; |
| 1669 | 1607 | /* B5, B6 & B7 are not used */ |
| r9669 | r9670 | |
| 1675 | 1613 | break; |
| 1676 | 1614 | |
| 1677 | 1615 | default: |
| 1678 | | value = mikey.data[offset]; |
| 1616 | value = state->mikey.data[offset]; |
| 1679 | 1617 | logerror( "mikey read %.2x %.2x\n", offset, value ); |
| 1680 | 1618 | } |
| 1681 | 1619 | |
| r9669 | r9670 | |
| 1684 | 1622 | |
| 1685 | 1623 | static WRITE8_HANDLER( mikey_write ) |
| 1686 | 1624 | { |
| 1625 | lynx_state *state = space->machine->driver_data<lynx_state>(); |
| 1687 | 1626 | switch (offset) |
| 1688 | 1627 | { |
| 1689 | 1628 | case 0x00: case 0x01: case 0x02: case 0x03: |
| r9669 | r9670 | |
| 1694 | 1633 | case 0x14: case 0x15: case 0x16: case 0x17: |
| 1695 | 1634 | case 0x18: case 0x19: case 0x1a: case 0x1b: |
| 1696 | 1635 | case 0x1c: case 0x1d: case 0x1e: case 0x1f: |
| 1697 | | lynx_timer_write(offset >> 2, offset & 3, data); |
| 1636 | lynx_timer_write(state, offset >> 2, offset & 3, data); |
| 1698 | 1637 | return; |
| 1699 | 1638 | |
| 1700 | 1639 | case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: |
| r9669 | r9670 | |
| 1702 | 1641 | case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: |
| 1703 | 1642 | case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f: |
| 1704 | 1643 | case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x50: |
| 1705 | | lynx_audio_write(lynx_audio, offset, data); |
| 1644 | lynx_audio_write(state->audio, offset, data); |
| 1706 | 1645 | return; |
| 1707 | 1646 | |
| 1708 | 1647 | case 0x80: |
| 1709 | | mikey.data[0x81] &= ~data; // clear interrupt source |
| 1648 | state->mikey.data[0x81] &= ~data; // clear interrupt source |
| 1710 | 1649 | logerror("mikey write %.2x %.2x\n", offset, data); |
| 1711 | | if (!mikey.data[0x81]) |
| 1650 | if (!state->mikey.data[0x81]) |
| 1712 | 1651 | cputag_set_input_line(space->machine, "maincpu", M65SC02_IRQ_LINE, CLEAR_LINE); |
| 1713 | 1652 | break; |
| 1714 | 1653 | |
| 1715 | 1654 | /* Is this correct? */ |
| 1716 | 1655 | case 0x81: |
| 1717 | | mikey.data[offset] |= data; |
| 1656 | state->mikey.data[offset] |= data; |
| 1718 | 1657 | break; |
| 1719 | 1658 | |
| 1720 | 1659 | case 0x87: |
| 1721 | | mikey.data[offset] = data; |
| 1660 | state->mikey.data[offset] = data; |
| 1722 | 1661 | if (data & 0x02) // Power (1 = on) |
| 1723 | 1662 | { |
| 1724 | 1663 | if (data & 0x01) // Cart Address Strobe |
| 1725 | 1664 | { |
| 1726 | | suzy.high <<= 1; |
| 1727 | | if (mikey.data[0x8b] & 0x02) |
| 1728 | | suzy.high |= 1; |
| 1729 | | suzy.high &= 0xff; |
| 1730 | | suzy.low = 0; |
| 1665 | state->suzy.high <<= 1; |
| 1666 | if (state->mikey.data[0x8b] & 0x02) |
| 1667 | state->suzy.high |= 1; |
| 1668 | state->suzy.high &= 0xff; |
| 1669 | state->suzy.low = 0; |
| 1731 | 1670 | } |
| 1732 | 1671 | } |
| 1733 | 1672 | else |
| 1734 | 1673 | { |
| 1735 | | suzy.high = 0; |
| 1736 | | suzy.low = 0; |
| 1674 | state->suzy.high = 0; |
| 1675 | state->suzy.low = 0; |
| 1737 | 1676 | } |
| 1738 | 1677 | break; |
| 1739 | 1678 | |
| r9669 | r9670 | |
| 1745 | 1684 | case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf: |
| 1746 | 1685 | case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7: |
| 1747 | 1686 | case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: |
| 1748 | | mikey.data[offset] = data; |
| 1749 | | lynx_draw_lines(space->machine, lynx_line); |
| 1687 | state->mikey.data[offset] = data; |
| 1688 | lynx_draw_lines(space->machine, state->line); |
| 1750 | 1689 | |
| 1751 | 1690 | /* RED = 0xb- & 0x0f, GREEN = 0xa- & 0x0f, BLUE = (0xb- & 0xf0) >> 4 */ |
| 1752 | | lynx_palette[offset & 0x0f] = space->machine->pens[ |
| 1753 | | ((mikey.data[0xb0 + (offset & 0x0f)] & 0x0f)) | |
| 1754 | | ((mikey.data[0xa0 + (offset & 0x0f)] & 0x0f) << 4) | |
| 1755 | | ((mikey.data[0xb0 + (offset & 0x0f)] & 0xf0) << 4)]; |
| 1691 | state->palette[offset & 0x0f] = space->machine->pens[ |
| 1692 | ((state->mikey.data[0xb0 + (offset & 0x0f)] & 0x0f)) | |
| 1693 | ((state->mikey.data[0xa0 + (offset & 0x0f)] & 0x0f) << 4) | |
| 1694 | ((state->mikey.data[0xb0 + (offset & 0x0f)] & 0xf0) << 4)]; |
| 1756 | 1695 | break; |
| 1757 | 1696 | |
| 1758 | 1697 | /* TODO: properly implement these writes */ |
| 1759 | 1698 | case 0x8b: |
| 1760 | | mikey.data[offset] = data; |
| 1761 | | if (mikey.data[0x8a] & 0x10) |
| 1762 | | logerror("Trying to enable bank 1 write. %d\n", mikey.data[offset] & 0x10); |
| 1699 | state->mikey.data[offset] = data; |
| 1700 | if (state->mikey.data[0x8a] & 0x10) |
| 1701 | logerror("Trying to enable bank 1 write. %d\n", state->mikey.data[offset] & 0x10); |
| 1763 | 1702 | break; |
| 1764 | 1703 | |
| 1765 | 1704 | // case 0x90: // SDONEACK - Suzy Done Acknowledge |
| 1766 | 1705 | case 0x91: // CPUSLEEP - CPU Bus Request Disable |
| 1767 | | mikey.data[offset] = data; |
| 1706 | state->mikey.data[offset] = data; |
| 1768 | 1707 | if (!data) |
| 1769 | 1708 | { |
| 1770 | 1709 | /* A write of '0' to this address will reset the CPU bus request flip flop */ |
| r9669 | r9670 | |
| 1773 | 1712 | break; |
| 1774 | 1713 | |
| 1775 | 1714 | default: |
| 1776 | | mikey.data[offset]=data; |
| 1715 | state->mikey.data[offset]=data; |
| 1777 | 1716 | logerror("mikey write %.2x %.2x\n",offset,data); |
| 1778 | 1717 | break; |
| 1779 | 1718 | } |
| r9669 | r9670 | |
| 1787 | 1726 | |
| 1788 | 1727 | READ8_HANDLER( lynx_memory_config_r ) |
| 1789 | 1728 | { |
| 1790 | | return lynx_memory_config; |
| 1729 | lynx_state *state = space->machine->driver_data<lynx_state>(); |
| 1730 | return state->memory_config; |
| 1791 | 1731 | } |
| 1792 | 1732 | |
| 1793 | 1733 | WRITE8_HANDLER( lynx_memory_config_w ) |
| 1794 | 1734 | { |
| 1735 | lynx_state *state = space->machine->driver_data<lynx_state>(); |
| 1795 | 1736 | /* bit 7: hispeed, uses page mode accesses (4 instead of 5 cycles ) |
| 1796 | 1737 | * when these are safe in the cpu */ |
| 1797 | | lynx_memory_config = data; |
| 1738 | state->memory_config = data; |
| 1798 | 1739 | |
| 1799 | 1740 | if (data & 1) { |
| 1800 | 1741 | memory_install_readwrite_bank(space, 0xfc00, 0xfcff, 0, 0, "bank1"); |
| r9669 | r9670 | |
| 1808 | 1749 | } |
| 1809 | 1750 | |
| 1810 | 1751 | if (data & 1) |
| 1811 | | memory_set_bankptr(space->machine, "bank1", lynx_mem_fc00); |
| 1752 | memory_set_bankptr(space->machine, "bank1", state->mem_fc00); |
| 1812 | 1753 | if (data & 2) |
| 1813 | | memory_set_bankptr(space->machine, "bank2", lynx_mem_fd00); |
| 1754 | memory_set_bankptr(space->machine, "bank2", state->mem_fd00); |
| 1814 | 1755 | memory_set_bank(space->machine, "bank3", (data & 4) ? 1 : 0); |
| 1815 | 1756 | memory_set_bank(space->machine, "bank4", (data & 8) ? 1 : 0); |
| 1816 | 1757 | } |
| 1817 | 1758 | |
| 1818 | 1759 | static void lynx_reset(running_machine &machine) |
| 1819 | 1760 | { |
| 1761 | lynx_state *state = machine.driver_data<lynx_state>(); |
| 1820 | 1762 | lynx_memory_config_w(cputag_get_address_space(&machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0, 0); |
| 1821 | 1763 | |
| 1822 | 1764 | cputag_set_input_line(&machine, "maincpu", M65SC02_IRQ_LINE, CLEAR_LINE); |
| 1823 | 1765 | |
| 1824 | | memset(&suzy, 0, sizeof(suzy)); |
| 1825 | | memset(&mikey, 0, sizeof(mikey)); |
| 1766 | memset(&state->suzy, 0, sizeof(state->suzy)); |
| 1767 | memset(&state->mikey, 0, sizeof(state->mikey)); |
| 1826 | 1768 | |
| 1827 | | suzy.data[0x88] = 0x01; |
| 1828 | | suzy.data[0x90] = 0x00; |
| 1829 | | suzy.data[0x91] = 0x00; |
| 1830 | | mikey.data[0x80] = 0x00; |
| 1831 | | mikey.data[0x81] = 0x00; |
| 1832 | | mikey.data[0x88] = 0x01; |
| 1833 | | mikey.data[0x8a] = 0x00; |
| 1834 | | mikey.data[0x8c] = 0x00; |
| 1835 | | mikey.data[0x90] = 0x00; |
| 1836 | | mikey.data[0x92] = 0x00; |
| 1769 | state->suzy.data[0x88] = 0x01; |
| 1770 | state->suzy.data[0x90] = 0x00; |
| 1771 | state->suzy.data[0x91] = 0x00; |
| 1772 | state->mikey.data[0x80] = 0x00; |
| 1773 | state->mikey.data[0x81] = 0x00; |
| 1774 | state->mikey.data[0x88] = 0x01; |
| 1775 | state->mikey.data[0x8a] = 0x00; |
| 1776 | state->mikey.data[0x8c] = 0x00; |
| 1777 | state->mikey.data[0x90] = 0x00; |
| 1778 | state->mikey.data[0x92] = 0x00; |
| 1837 | 1779 | |
| 1838 | | lynx_uart_reset(); |
| 1780 | lynx_uart_reset(state); |
| 1839 | 1781 | |
| 1840 | 1782 | // hack to allow current object loading to work |
| 1841 | 1783 | #if 1 |
| 1842 | | lynx_timer_write( 0, 0, 160 ); |
| 1843 | | lynx_timer_write( 0, 1, 0x10 | 0x8 | 0 ); |
| 1844 | | lynx_timer_write( 2, 0, 102 ); |
| 1845 | | lynx_timer_write( 2, 1, 0x10 | 0x8 | 7 ); |
| 1784 | lynx_timer_write( state, 0, 0, 160 ); |
| 1785 | lynx_timer_write( state, 0, 1, 0x10 | 0x8 | 0 ); |
| 1786 | lynx_timer_write( state, 2, 0, 102 ); |
| 1787 | lynx_timer_write( state, 2, 1, 0x10 | 0x8 | 7 ); |
| 1846 | 1788 | #endif |
| 1847 | 1789 | } |
| 1848 | 1790 | |
| 1849 | 1791 | static STATE_POSTLOAD( lynx_postload ) |
| 1850 | 1792 | { |
| 1851 | | lynx_memory_config_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0, lynx_memory_config); |
| 1793 | lynx_state *state = machine->driver_data<lynx_state>(); |
| 1794 | lynx_memory_config_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0, state->memory_config); |
| 1852 | 1795 | } |
| 1853 | 1796 | |
| 1854 | 1797 | MACHINE_START( lynx ) |
| 1855 | 1798 | { |
| 1799 | lynx_state *state = machine->driver_data<lynx_state>(); |
| 1856 | 1800 | int i; |
| 1857 | | state_save_register_global(machine, lynx_memory_config); |
| 1858 | | state_save_register_global_pointer(machine, lynx_mem_fe00, lynx_mem_fe00_size); |
| 1801 | state_save_register_global(machine, state->memory_config); |
| 1802 | state_save_register_global_pointer(machine, state->mem_fe00, state->mem_fe00_size); |
| 1859 | 1803 | state_save_register_postload(machine, lynx_postload, NULL); |
| 1860 | 1804 | |
| 1861 | 1805 | memory_configure_bank(machine, "bank3", 0, 1, memory_region(machine, "maincpu") + 0x0000, 0); |
| 1862 | | memory_configure_bank(machine, "bank3", 1, 1, lynx_mem_fe00, 0); |
| 1806 | memory_configure_bank(machine, "bank3", 1, 1, state->mem_fe00, 0); |
| 1863 | 1807 | memory_configure_bank(machine, "bank4", 0, 1, memory_region(machine, "maincpu") + 0x01fa, 0); |
| 1864 | | memory_configure_bank(machine, "bank4", 1, 1, lynx_mem_fffa, 0); |
| 1808 | memory_configure_bank(machine, "bank4", 1, 1, state->mem_fffa, 0); |
| 1865 | 1809 | |
| 1866 | | lynx_audio = machine->device("custom"); |
| 1867 | | lynx_height = -1; |
| 1868 | | lynx_width = -1; |
| 1810 | state->audio = machine->device("custom"); |
| 1811 | state->height = -1; |
| 1812 | state->width = -1; |
| 1869 | 1813 | |
| 1870 | | memset(&suzy, 0, sizeof(suzy)); |
| 1814 | memset(&state->suzy, 0, sizeof(state->suzy)); |
| 1871 | 1815 | |
| 1872 | 1816 | machine->add_notifier(MACHINE_NOTIFY_RESET, lynx_reset); |
| 1873 | 1817 | |
| r9669 | r9670 | |
| 1922 | 1866 | |
| 1923 | 1867 | INTERRUPT_GEN( lynx_frame_int ) |
| 1924 | 1868 | { |
| 1925 | | lynx_rotate = rotate0; |
| 1869 | lynx_state *state = device->machine->driver_data<lynx_state>(); |
| 1870 | state->rotate = state->rotate0; |
| 1926 | 1871 | if ((input_port_read(device->machine, "ROTATION") & 0x03) != 0x03) |
| 1927 | | lynx_rotate=input_port_read(device->machine, "ROTATION") & 0x03; |
| 1872 | state->rotate=input_port_read(device->machine, "ROTATION") & 0x03; |
| 1928 | 1873 | } |
| 1929 | 1874 | |
| 1930 | 1875 | void lynx_crc_keyword(device_image_interface &image) |
| 1931 | 1876 | { |
| 1877 | lynx_state *state = image.device().machine->driver_data<lynx_state>(); |
| 1932 | 1878 | const char *info = NULL; |
| 1933 | 1879 | |
| 1934 | 1880 | if (strcmp(image.extrainfo(), "")) |
| 1935 | 1881 | info = image.extrainfo(); |
| 1936 | 1882 | |
| 1937 | | rotate0 = 0; |
| 1883 | state->rotate0 = 0; |
| 1938 | 1884 | |
| 1939 | 1885 | if (info) |
| 1940 | 1886 | { |
| 1941 | 1887 | if(strcmp(info, "ROTATE90DEGREE") == 0) |
| 1942 | | rotate0 = 1; |
| 1888 | state->rotate0 = 1; |
| 1943 | 1889 | else if (strcmp(info, "ROTATE270DEGREE") == 0) |
| 1944 | | rotate0 = 2; |
| 1890 | state->rotate0 = 2; |
| 1945 | 1891 | } |
| 1946 | 1892 | } |
| 1947 | 1893 | |
| 1948 | 1894 | static DEVICE_IMAGE_LOAD( lynx_cart ) |
| 1949 | 1895 | { |
| 1896 | lynx_state *state = image.device().machine->driver_data<lynx_state>(); |
| 1950 | 1897 | UINT8 *rom = memory_region(image.device().machine, "user1"); |
| 1951 | 1898 | UINT32 size; |
| 1952 | 1899 | UINT8 header[0x40]; |
| r9669 | r9670 | |
| 1977 | 1924 | /* 2008-10 FP: According to Handy source these should be page_size_bank0. Are we using |
| 1978 | 1925 | it correctly in MESS? Moreover, the next two values should be page_size_bank1. We should |
| 1979 | 1926 | implement this as well */ |
| 1980 | | lynx_granularity = header[4] | (header[5] << 8); |
| 1927 | state->granularity = header[4] | (header[5] << 8); |
| 1981 | 1928 | |
| 1982 | 1929 | logerror ("%s %dkb cartridge with %dbyte granularity from %s\n", |
| 1983 | | header + 10, size / 1024, lynx_granularity, header + 42); |
| 1930 | header + 10, size / 1024, state->granularity, header + 42); |
| 1984 | 1931 | |
| 1985 | 1932 | size -= 0x40; |
| 1986 | 1933 | } |
| r9669 | r9670 | |
| 1990 | 1937 | (see above). What if bank 0 has to be loaded elsewhere? And what about bank 1? |
| 1991 | 1938 | These should work with most .lyx files, but we need additional info on raw cart images */ |
| 1992 | 1939 | if (size == 0x20000) |
| 1993 | | lynx_granularity = 0x0200; |
| 1940 | state->granularity = 0x0200; |
| 1994 | 1941 | else if (size == 0x80000) |
| 1995 | | lynx_granularity = 0x0800; |
| 1942 | state->granularity = 0x0800; |
| 1996 | 1943 | else |
| 1997 | | lynx_granularity = 0x0400; |
| 1944 | state->granularity = 0x0400; |
| 1998 | 1945 | } |
| 1999 | 1946 | |
| 2000 | 1947 | if (image.fread( rom, size) != size) |
| r9669 | r9670 | |
| 2017 | 1964 | /* 2008-10 FP: According to Handy source these should be page_size_bank0. Are we using |
| 2018 | 1965 | it correctly in MESS? Moreover, the next two values should be page_size_bank1. We should |
| 2019 | 1966 | implement this as well */ |
| 2020 | | lynx_granularity = header[4] | (header[5] << 8); |
| 1967 | state->granularity = header[4] | (header[5] << 8); |
| 2021 | 1968 | |
| 2022 | 1969 | logerror ("%s %dkb cartridge with %dbyte granularity from %s\n", |
| 2023 | | header + 10, size / 1024, lynx_granularity, header + 42); |
| 1970 | header + 10, size / 1024, state->granularity, header + 42); |
| 2024 | 1971 | |
| 2025 | 1972 | size -= 0x40; |
| 2026 | 1973 | memcpy(rom, image.get_software_region("rom") + 0x40, size); |
src/mess/video/wswan.c
| r9669 | r9670 | |
| 12 | 12 | #include "emu.h" |
| 13 | 13 | #include "includes/wswan.h" |
| 14 | 14 | |
| 15 | | static int pal[16][16]; |
| 16 | 15 | |
| 17 | 16 | INLINE void wswan_plot_pixel(running_machine *machine,int x, int y, int pen) { |
| 17 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 18 | 18 | y += 5*8; |
| 19 | | if ( wswan_vdp.display_vertical ) { |
| 19 | if ( state->vdp.display_vertical ) { |
| 20 | 20 | *BITMAP_ADDR16(machine->generic.tmpbitmap, 28*8 - 1 - x, y) = pen; |
| 21 | 21 | } else { |
| 22 | 22 | *BITMAP_ADDR16(machine->generic.tmpbitmap, y, x) = pen; |
| r9669 | r9670 | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | INLINE void wswan_fillbitmap( running_machine *machine,int pen, rectangle *rec ) { |
| 27 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 27 | 28 | /* Fill empty area above line 0 when filling line 0 */ |
| 28 | | if ( wswan_vdp.current_line != 0 ) { |
| 29 | if ( state->vdp.current_line != 0 ) { |
| 29 | 30 | rec->min_y = rec->min_y + 5*8; |
| 30 | 31 | } |
| 31 | 32 | |
| 32 | 33 | /* Fill empty area below line 143 when filling line 143 */ |
| 33 | | if ( wswan_vdp.current_line != 143 ) { |
| 34 | if ( state->vdp.current_line != 143 ) { |
| 34 | 35 | rec->max_y = rec->max_y + 5*8; |
| 35 | 36 | } else { |
| 36 | 37 | rec->max_y = 28*8; |
| 37 | 38 | } |
| 38 | 39 | |
| 39 | | if ( wswan_vdp.display_vertical ) { |
| 40 | if ( state->vdp.display_vertical ) { |
| 40 | 41 | rectangle rec2; |
| 41 | 42 | rec2.min_y = 28*8 - 1 - rec->max_x; |
| 42 | 43 | rec2.max_y = 28*8 - 1 - rec->min_x; |
| r9669 | r9670 | |
| 49 | 50 | } |
| 50 | 51 | |
| 51 | 52 | |
| 52 | | static void wswan_setup_palettes(void) { |
| 53 | static void wswan_setup_palettes(wswan_state *state) { |
| 53 | 54 | int i,j; |
| 54 | 55 | |
| 55 | | if ( wswan_vdp.color_mode ) { |
| 56 | if ( state->vdp.color_mode ) { |
| 56 | 57 | for( i = 0; i < 16; i++ ) { |
| 57 | 58 | for( j = 0; j < 16; j++ ) { |
| 58 | | pal[i][j] = ( ( wswan_vdp.palette_vram[ ( i << 5 ) + j*2 + 1 ] << 8 ) | wswan_vdp.palette_vram[ ( i << 5 ) + j*2 ] ) & 0x0FFF; |
| 59 | state->pal[i][j] = ( ( state->vdp.palette_vram[ ( i << 5 ) + j*2 + 1 ] << 8 ) | state->vdp.palette_vram[ ( i << 5 ) + j*2 ] ) & 0x0FFF; |
| 59 | 60 | } |
| 60 | 61 | } |
| 61 | 62 | } else { |
| 62 | 63 | for( i = 0; i < 16; i++ ) { |
| 63 | | pal[i][0] = ws_portram[ 0x20 + ( i << 1 ) ] & 0x07; |
| 64 | | pal[i][1] = ( ws_portram[ 0x20 + ( i << 1 ) ] >> 4 ) & 0x07; |
| 65 | | pal[i][2] = ws_portram[ 0x21 + ( i << 1 ) ] & 0x07; |
| 66 | | pal[i][3] = ( ws_portram[ 0x21 + ( i << 1 ) ] >> 4 ) & 0x07; |
| 64 | state->pal[i][0] = state->ws_portram[ 0x20 + ( i << 1 ) ] & 0x07; |
| 65 | state->pal[i][1] = ( state->ws_portram[ 0x20 + ( i << 1 ) ] >> 4 ) & 0x07; |
| 66 | state->pal[i][2] = state->ws_portram[ 0x21 + ( i << 1 ) ] & 0x07; |
| 67 | state->pal[i][3] = ( state->ws_portram[ 0x21 + ( i << 1 ) ] >> 4 ) & 0x07; |
| 67 | 68 | } |
| 68 | 69 | } |
| 69 | 70 | } |
| 70 | 71 | |
| 71 | 72 | static void wswan_draw_background( running_machine *machine ) { |
| 73 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 72 | 74 | UINT16 map_addr; |
| 73 | 75 | UINT8 start_column; |
| 74 | 76 | int column; |
| 75 | 77 | |
| 76 | | map_addr = wswan_vdp.layer_bg_address + ( ( ( wswan_vdp.current_line + wswan_vdp.layer_bg_scroll_y ) & 0xF8 ) << 3 ); |
| 77 | | start_column = ( wswan_vdp.layer_bg_scroll_x >> 3 ); |
| 78 | map_addr = state->vdp.layer_bg_address + ( ( ( state->vdp.current_line + state->vdp.layer_bg_scroll_y ) & 0xF8 ) << 3 ); |
| 79 | start_column = ( state->vdp.layer_bg_scroll_x >> 3 ); |
| 78 | 80 | for( column = 0; column < 29; column++ ) { |
| 79 | 81 | int tile_data, tile_number, tile_palette, tile_line, tile_address; |
| 80 | 82 | UINT32 plane0=0, plane1=0, plane2=0, plane3=0; |
| 81 | 83 | int x, x_offset; |
| 82 | 84 | |
| 83 | | tile_data = ( wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 ) |
| 84 | | | wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ]; |
| 85 | tile_data = ( state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 ) |
| 86 | | state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ]; |
| 85 | 87 | tile_number = tile_data & 0x01FF; |
| 86 | 88 | tile_palette = ( tile_data >> 9 ) & 0x0F; |
| 87 | 89 | |
| 88 | | tile_line = ( wswan_vdp.current_line + wswan_vdp.layer_bg_scroll_y ) & 0x07; |
| 90 | tile_line = ( state->vdp.current_line + state->vdp.layer_bg_scroll_y ) & 0x07; |
| 89 | 91 | if ( tile_data & 0x8000 ) { |
| 90 | 92 | tile_line = 7 - tile_line; |
| 91 | 93 | } |
| 92 | 94 | |
| 93 | | if ( wswan_vdp.colors_16 ) { |
| 95 | if ( state->vdp.colors_16 ) { |
| 94 | 96 | tile_address = ( ( tile_data & 0x2000 ) ? 0x8000 : 0x4000 ) + ( tile_number * 32 ) + ( tile_line << 2 ); |
| 95 | | if ( wswan_vdp.tile_packed ) { |
| 96 | | plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 24 ) | ( wswan_vdp.vram[ tile_address + 1 ] << 16 ) | ( wswan_vdp.vram[ tile_address + 2 ] << 8 ) | wswan_vdp.vram[ tile_address + 3 ]; |
| 97 | if ( state->vdp.tile_packed ) { |
| 98 | plane0 = ( state->vdp.vram[ tile_address + 0 ] << 24 ) | ( state->vdp.vram[ tile_address + 1 ] << 16 ) | ( state->vdp.vram[ tile_address + 2 ] << 8 ) | state->vdp.vram[ tile_address + 3 ]; |
| 97 | 99 | } else { |
| 98 | | plane0 = wswan_vdp.vram[ tile_address + 0 ]; |
| 99 | | plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1; |
| 100 | | plane2 = wswan_vdp.vram[ tile_address + 2 ] << 2; |
| 101 | | plane3 = wswan_vdp.vram[ tile_address + 3 ] << 3; |
| 100 | plane0 = state->vdp.vram[ tile_address + 0 ]; |
| 101 | plane1 = state->vdp.vram[ tile_address + 1 ] << 1; |
| 102 | plane2 = state->vdp.vram[ tile_address + 2 ] << 2; |
| 103 | plane3 = state->vdp.vram[ tile_address + 3 ] << 3; |
| 102 | 104 | } |
| 103 | 105 | } else { |
| 104 | 106 | tile_address = 0x2000 + ( tile_number * 16 ) + ( tile_line << 1 ); |
| 105 | | if ( wswan_vdp.tile_packed ) { |
| 106 | | plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 8 ) | wswan_vdp.vram[ tile_address + 1 ]; |
| 107 | if ( state->vdp.tile_packed ) { |
| 108 | plane0 = ( state->vdp.vram[ tile_address + 0 ] << 8 ) | state->vdp.vram[ tile_address + 1 ]; |
| 107 | 109 | } else { |
| 108 | | plane0 = wswan_vdp.vram[ tile_address + 0 ]; |
| 109 | | plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1; |
| 110 | plane0 = state->vdp.vram[ tile_address + 0 ]; |
| 111 | plane1 = state->vdp.vram[ tile_address + 1 ] << 1; |
| 110 | 112 | plane2 = 0; |
| 111 | 113 | plane3 = 0; |
| 112 | 114 | } |
| r9669 | r9670 | |
| 114 | 116 | |
| 115 | 117 | for( x = 0; x < 8; x++ ) { |
| 116 | 118 | int col; |
| 117 | | if ( wswan_vdp.tile_packed ) { |
| 118 | | if ( wswan_vdp.colors_16 ) { |
| 119 | if ( state->vdp.tile_packed ) { |
| 120 | if ( state->vdp.colors_16 ) { |
| 119 | 121 | col = plane0 & 0x0F; |
| 120 | 122 | plane0 = plane0 >> 4; |
| 121 | 123 | } else { |
| r9669 | r9670 | |
| 130 | 132 | plane0 = plane0 >> 1; |
| 131 | 133 | } |
| 132 | 134 | if ( tile_data & 0x4000 ) { |
| 133 | | x_offset = x + ( column << 3 ) - ( wswan_vdp.layer_bg_scroll_x & 0x07 ); |
| 135 | x_offset = x + ( column << 3 ) - ( state->vdp.layer_bg_scroll_x & 0x07 ); |
| 134 | 136 | } else { |
| 135 | | x_offset = 7 - x + ( column << 3 ) - ( wswan_vdp.layer_bg_scroll_x & 0x07 ); |
| 137 | x_offset = 7 - x + ( column << 3 ) - ( state->vdp.layer_bg_scroll_x & 0x07 ); |
| 136 | 138 | } |
| 137 | 139 | if ( x_offset >= 0 && x_offset < WSWAN_X_PIXELS ) { |
| 138 | | if ( wswan_vdp.colors_16 ) { |
| 140 | if ( state->vdp.colors_16 ) { |
| 139 | 141 | if ( col ) { |
| 140 | | if ( wswan_vdp.color_mode ) { |
| 141 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 142 | if ( state->vdp.color_mode ) { |
| 143 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 142 | 144 | } else { |
| 143 | 145 | /* Hmmmm, what should we do here... Is this correct?? */ |
| 144 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 146 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 145 | 147 | } |
| 146 | 148 | } |
| 147 | 149 | } else { |
| 148 | 150 | if ( col || !(tile_palette & 4 ) ) { |
| 149 | | if ( wswan_vdp.color_mode ) { |
| 150 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 151 | if ( state->vdp.color_mode ) { |
| 152 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 151 | 153 | } else { |
| 152 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, wswan_vdp.main_palette[pal[tile_palette][col]] ); |
| 154 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->vdp.main_palette[state->pal[tile_palette][col]] ); |
| 153 | 155 | } |
| 154 | 156 | } |
| 155 | 157 | } |
| r9669 | r9670 | |
| 159 | 161 | } |
| 160 | 162 | |
| 161 | 163 | static void wswan_draw_foreground_0( running_machine *machine ) { |
| 164 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 162 | 165 | UINT16 map_addr; |
| 163 | 166 | UINT8 start_column; |
| 164 | 167 | int column; |
| 165 | | map_addr = wswan_vdp.layer_fg_address + ( ( ( wswan_vdp.current_line + wswan_vdp.layer_fg_scroll_y ) & 0xF8 ) << 3 ); |
| 166 | | start_column = ( wswan_vdp.layer_fg_scroll_x >> 3 ); |
| 168 | map_addr = state->vdp.layer_fg_address + ( ( ( state->vdp.current_line + state->vdp.layer_fg_scroll_y ) & 0xF8 ) << 3 ); |
| 169 | start_column = ( state->vdp.layer_fg_scroll_x >> 3 ); |
| 167 | 170 | for( column = 0; column < 29; column++ ) { |
| 168 | 171 | UINT32 plane0 = 0, plane1 = 0, plane2 = 0, plane3 = 0; |
| 169 | 172 | int x, x_offset, tile_line, tile_address; |
| 170 | | int tile_data = ( wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 ) |
| 171 | | | wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ]; |
| 173 | int tile_data = ( state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 ) |
| 174 | | state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ]; |
| 172 | 175 | int tile_number = tile_data & 0x01FF; |
| 173 | 176 | int tile_palette = ( tile_data >> 9 ) & 0x0F; |
| 174 | 177 | |
| 175 | | tile_line = ( wswan_vdp.current_line + wswan_vdp.layer_fg_scroll_y ) & 0x07; |
| 178 | tile_line = ( state->vdp.current_line + state->vdp.layer_fg_scroll_y ) & 0x07; |
| 176 | 179 | if ( tile_data & 0x8000 ) { |
| 177 | 180 | tile_line = 7 - tile_line; |
| 178 | 181 | } |
| 179 | 182 | |
| 180 | | if ( wswan_vdp.colors_16 ) { |
| 183 | if ( state->vdp.colors_16 ) { |
| 181 | 184 | tile_address = ( ( tile_data & 0x2000 ) ? 0x8000 : 0x4000 ) + ( tile_number * 32 ) + ( tile_line << 2 ); |
| 182 | | if ( wswan_vdp.tile_packed ) { |
| 183 | | plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 24 ) | ( wswan_vdp.vram[ tile_address + 1 ] << 16 ) | ( wswan_vdp.vram[ tile_address + 2 ] << 8 ) | wswan_vdp.vram[ tile_address + 3 ]; |
| 185 | if ( state->vdp.tile_packed ) { |
| 186 | plane0 = ( state->vdp.vram[ tile_address + 0 ] << 24 ) | ( state->vdp.vram[ tile_address + 1 ] << 16 ) | ( state->vdp.vram[ tile_address + 2 ] << 8 ) | state->vdp.vram[ tile_address + 3 ]; |
| 184 | 187 | } else { |
| 185 | | plane0 = wswan_vdp.vram[ tile_address + 0 ]; |
| 186 | | plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1; |
| 187 | | plane2 = wswan_vdp.vram[ tile_address + 2 ] << 2; |
| 188 | | plane3 = wswan_vdp.vram[ tile_address + 3 ] << 3; |
| 188 | plane0 = state->vdp.vram[ tile_address + 0 ]; |
| 189 | plane1 = state->vdp.vram[ tile_address + 1 ] << 1; |
| 190 | plane2 = state->vdp.vram[ tile_address + 2 ] << 2; |
| 191 | plane3 = state->vdp.vram[ tile_address + 3 ] << 3; |
| 189 | 192 | } |
| 190 | 193 | } else { |
| 191 | 194 | tile_address = 0x2000 + ( tile_number * 16 ) + ( tile_line << 1 ); |
| 192 | | if ( wswan_vdp.tile_packed ) { |
| 193 | | plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 8 ) | wswan_vdp.vram[ tile_address + 1 ]; |
| 195 | if ( state->vdp.tile_packed ) { |
| 196 | plane0 = ( state->vdp.vram[ tile_address + 0 ] << 8 ) | state->vdp.vram[ tile_address + 1 ]; |
| 194 | 197 | } else { |
| 195 | | plane0 = wswan_vdp.vram[ tile_address + 0 ]; |
| 196 | | plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1; |
| 198 | plane0 = state->vdp.vram[ tile_address + 0 ]; |
| 199 | plane1 = state->vdp.vram[ tile_address + 1 ] << 1; |
| 197 | 200 | plane2 = 0; |
| 198 | 201 | plane3 = 0; |
| 199 | 202 | } |
| r9669 | r9670 | |
| 201 | 204 | |
| 202 | 205 | for( x = 0; x < 8; x++ ) { |
| 203 | 206 | int col; |
| 204 | | if ( wswan_vdp.tile_packed ) { |
| 205 | | if ( wswan_vdp.colors_16 ) { |
| 207 | if ( state->vdp.tile_packed ) { |
| 208 | if ( state->vdp.colors_16 ) { |
| 206 | 209 | col = plane0 & 0x0F; |
| 207 | 210 | plane0 = plane0 >> 4; |
| 208 | 211 | } else { |
| r9669 | r9670 | |
| 217 | 220 | plane0 = plane0 >> 1; |
| 218 | 221 | } |
| 219 | 222 | if ( tile_data & 0x4000 ) { |
| 220 | | x_offset = x + ( column << 3 ) - ( wswan_vdp.layer_fg_scroll_x & 0x07 ); |
| 223 | x_offset = x + ( column << 3 ) - ( state->vdp.layer_fg_scroll_x & 0x07 ); |
| 221 | 224 | } else { |
| 222 | | x_offset = 7 - x + ( column << 3 ) - ( wswan_vdp.layer_fg_scroll_x & 0x07 ); |
| 225 | x_offset = 7 - x + ( column << 3 ) - ( state->vdp.layer_fg_scroll_x & 0x07 ); |
| 223 | 226 | } |
| 224 | 227 | if ( x_offset >= 0 && x_offset < WSWAN_X_PIXELS ) { |
| 225 | | if ( wswan_vdp.colors_16 ) { |
| 228 | if ( state->vdp.colors_16 ) { |
| 226 | 229 | if ( col ) { |
| 227 | | // if ( wswan_vdp.color_mode ) { |
| 228 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 230 | // if ( state->vdp.color_mode ) { |
| 231 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 229 | 232 | // } else { |
| 230 | 233 | // /* Hmmmm, what should we do here... Is this correct?? */ |
| 231 | | // wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 234 | // wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 232 | 235 | // } |
| 233 | 236 | } |
| 234 | 237 | } else { |
| 235 | 238 | if ( col || !(tile_palette & 4 ) ) { |
| 236 | | if ( wswan_vdp.color_mode ) { |
| 237 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 239 | if ( state->vdp.color_mode ) { |
| 240 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 238 | 241 | } else { |
| 239 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, wswan_vdp.main_palette[pal[tile_palette][col]] ); |
| 242 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->vdp.main_palette[state->pal[tile_palette][col]] ); |
| 240 | 243 | } |
| 241 | 244 | } |
| 242 | 245 | } |
| r9669 | r9670 | |
| 246 | 249 | } |
| 247 | 250 | |
| 248 | 251 | static void wswan_draw_foreground_2( running_machine *machine ) { |
| 252 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 249 | 253 | UINT16 map_addr; |
| 250 | 254 | UINT8 start_column; |
| 251 | 255 | int column; |
| 252 | | map_addr = wswan_vdp.layer_fg_address + ( ( ( wswan_vdp.current_line + wswan_vdp.layer_fg_scroll_y ) & 0xF8 ) << 3 ); |
| 253 | | start_column = ( wswan_vdp.layer_fg_scroll_x >> 3 ); |
| 256 | map_addr = state->vdp.layer_fg_address + ( ( ( state->vdp.current_line + state->vdp.layer_fg_scroll_y ) & 0xF8 ) << 3 ); |
| 257 | start_column = ( state->vdp.layer_fg_scroll_x >> 3 ); |
| 254 | 258 | for( column = 0; column < 29; column++ ) { |
| 255 | 259 | UINT32 plane0 = 0, plane1 = 0, plane2 = 0, plane3 = 0; |
| 256 | 260 | int x, x_offset, tile_line, tile_address; |
| 257 | | int tile_data = ( wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 ) |
| 258 | | | wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ]; |
| 261 | int tile_data = ( state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 ) |
| 262 | | state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ]; |
| 259 | 263 | int tile_number = tile_data & 0x01FF; |
| 260 | 264 | int tile_palette = ( tile_data >> 9 ) & 0x0F; |
| 261 | 265 | |
| 262 | | tile_line = ( wswan_vdp.current_line + wswan_vdp.layer_fg_scroll_y ) & 0x07; |
| 266 | tile_line = ( state->vdp.current_line + state->vdp.layer_fg_scroll_y ) & 0x07; |
| 263 | 267 | if ( tile_data & 0x8000 ) { |
| 264 | 268 | tile_line = 7 - tile_line; |
| 265 | 269 | } |
| 266 | 270 | |
| 267 | | if ( wswan_vdp.colors_16 ) { |
| 271 | if ( state->vdp.colors_16 ) { |
| 268 | 272 | tile_address = ( ( tile_data & 0x2000 ) ? 0x8000 : 0x4000 ) + ( tile_number * 32 ) + ( tile_line << 2 ); |
| 269 | | if ( wswan_vdp.tile_packed ) { |
| 270 | | plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 24 ) | ( wswan_vdp.vram[ tile_address + 1 ] << 16 ) | ( wswan_vdp.vram[ tile_address + 2 ] << 8 ) | wswan_vdp.vram[ tile_address + 3 ]; |
| 273 | if ( state->vdp.tile_packed ) { |
| 274 | plane0 = ( state->vdp.vram[ tile_address + 0 ] << 24 ) | ( state->vdp.vram[ tile_address + 1 ] << 16 ) | ( state->vdp.vram[ tile_address + 2 ] << 8 ) | state->vdp.vram[ tile_address + 3 ]; |
| 271 | 275 | } else { |
| 272 | | plane0 = wswan_vdp.vram[ tile_address + 0 ]; |
| 273 | | plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1; |
| 274 | | plane2 = wswan_vdp.vram[ tile_address + 2 ] << 2; |
| 275 | | plane3 = wswan_vdp.vram[ tile_address + 3 ] << 3; |
| 276 | plane0 = state->vdp.vram[ tile_address + 0 ]; |
| 277 | plane1 = state->vdp.vram[ tile_address + 1 ] << 1; |
| 278 | plane2 = state->vdp.vram[ tile_address + 2 ] << 2; |
| 279 | plane3 = state->vdp.vram[ tile_address + 3 ] << 3; |
| 276 | 280 | } |
| 277 | 281 | } else { |
| 278 | 282 | tile_address = 0x2000 + ( tile_number * 16 ) + ( tile_line << 1 ); |
| 279 | | if ( wswan_vdp.tile_packed ) { |
| 280 | | plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 8 ) | wswan_vdp.vram[ tile_address + 1 ]; |
| 283 | if ( state->vdp.tile_packed ) { |
| 284 | plane0 = ( state->vdp.vram[ tile_address + 0 ] << 8 ) | state->vdp.vram[ tile_address + 1 ]; |
| 281 | 285 | } else { |
| 282 | | plane0 = wswan_vdp.vram[ tile_address + 0 ]; |
| 283 | | plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1; |
| 286 | plane0 = state->vdp.vram[ tile_address + 0 ]; |
| 287 | plane1 = state->vdp.vram[ tile_address + 1 ] << 1; |
| 284 | 288 | plane2 = 0; |
| 285 | 289 | plane3 = 0; |
| 286 | 290 | } |
| r9669 | r9670 | |
| 288 | 292 | |
| 289 | 293 | for( x = 0; x < 8; x++ ) { |
| 290 | 294 | int col; |
| 291 | | if ( wswan_vdp.tile_packed ) { |
| 292 | | if ( wswan_vdp.colors_16 ) { |
| 295 | if ( state->vdp.tile_packed ) { |
| 296 | if ( state->vdp.colors_16 ) { |
| 293 | 297 | col = plane0 & 0x0F; |
| 294 | 298 | plane0 = plane0 >> 4; |
| 295 | 299 | } else { |
| r9669 | r9670 | |
| 304 | 308 | plane0 = plane0 >> 1; |
| 305 | 309 | } |
| 306 | 310 | if ( tile_data & 0x4000 ) { |
| 307 | | x_offset = x + ( column << 3 ) - ( wswan_vdp.layer_fg_scroll_x & 0x07 ); |
| 311 | x_offset = x + ( column << 3 ) - ( state->vdp.layer_fg_scroll_x & 0x07 ); |
| 308 | 312 | } else { |
| 309 | | x_offset = 7 - x + ( column << 3 ) - ( wswan_vdp.layer_fg_scroll_x & 0x07 ); |
| 313 | x_offset = 7 - x + ( column << 3 ) - ( state->vdp.layer_fg_scroll_x & 0x07 ); |
| 310 | 314 | } |
| 311 | | if ( x_offset >= 0 && x_offset >= wswan_vdp.window_fg_left && x_offset < wswan_vdp.window_fg_right && x_offset < WSWAN_X_PIXELS ) { |
| 312 | | if ( wswan_vdp.colors_16 ) { |
| 315 | if ( x_offset >= 0 && x_offset >= state->vdp.window_fg_left && x_offset < state->vdp.window_fg_right && x_offset < WSWAN_X_PIXELS ) { |
| 316 | if ( state->vdp.colors_16 ) { |
| 313 | 317 | if ( col ) { |
| 314 | | if ( wswan_vdp.color_mode ) { |
| 315 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 318 | if ( state->vdp.color_mode ) { |
| 319 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 316 | 320 | } else { |
| 317 | 321 | /* Hmmmm, what should we do here... Is this correct?? */ |
| 318 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 322 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 319 | 323 | } |
| 320 | 324 | } |
| 321 | 325 | } else { |
| 322 | 326 | if ( col || !(tile_palette & 4 ) ) { |
| 323 | | if ( wswan_vdp.color_mode ) { |
| 324 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 327 | if ( state->vdp.color_mode ) { |
| 328 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 325 | 329 | } else { |
| 326 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, wswan_vdp.main_palette[pal[tile_palette][col]] ); |
| 330 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->vdp.main_palette[state->pal[tile_palette][col]] ); |
| 327 | 331 | } |
| 328 | 332 | } |
| 329 | 333 | } |
| r9669 | r9670 | |
| 333 | 337 | } |
| 334 | 338 | |
| 335 | 339 | static void wswan_draw_foreground_3( running_machine *machine ) { |
| 340 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 336 | 341 | UINT16 map_addr; |
| 337 | 342 | UINT8 start_column; |
| 338 | 343 | int column; |
| 339 | | map_addr = wswan_vdp.layer_fg_address + ( ( ( wswan_vdp.current_line + wswan_vdp.layer_fg_scroll_y ) & 0xF8 ) << 3 ); |
| 340 | | start_column = ( wswan_vdp.layer_fg_scroll_x >> 3 ); |
| 344 | map_addr = state->vdp.layer_fg_address + ( ( ( state->vdp.current_line + state->vdp.layer_fg_scroll_y ) & 0xF8 ) << 3 ); |
| 345 | start_column = ( state->vdp.layer_fg_scroll_x >> 3 ); |
| 341 | 346 | for( column = 0; column < 29; column++ ) { |
| 342 | 347 | UINT32 plane0 = 0, plane1 = 0, plane2 = 0, plane3 = 0; |
| 343 | 348 | int x, x_offset, tile_line, tile_address; |
| 344 | | int tile_data = ( wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 ) |
| 345 | | | wswan_vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ]; |
| 349 | int tile_data = ( state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) + 1 ] << 8 ) |
| 350 | | state->vdp.vram[ map_addr + ( ( ( start_column + column ) & 0x1F ) << 1 ) ]; |
| 346 | 351 | int tile_number = tile_data & 0x01FF; |
| 347 | 352 | int tile_palette = ( tile_data >> 9 ) & 0x0F; |
| 348 | 353 | |
| 349 | | tile_line = ( wswan_vdp.current_line + wswan_vdp.layer_fg_scroll_y ) & 0x07; |
| 354 | tile_line = ( state->vdp.current_line + state->vdp.layer_fg_scroll_y ) & 0x07; |
| 350 | 355 | if ( tile_data & 0x8000 ) { |
| 351 | 356 | tile_line = 7 - tile_line; |
| 352 | 357 | } |
| 353 | 358 | |
| 354 | | if ( wswan_vdp.colors_16 ) { |
| 359 | if ( state->vdp.colors_16 ) { |
| 355 | 360 | tile_address = ( ( tile_data & 0x2000 ) ? 0x8000 : 0x4000 ) + ( tile_number * 32 ) + ( tile_line << 2 ); |
| 356 | | if ( wswan_vdp.tile_packed ) { |
| 357 | | plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 24 ) | ( wswan_vdp.vram[ tile_address + 1 ] << 16 ) | ( wswan_vdp.vram[ tile_address + 2 ] << 8 ) | wswan_vdp.vram[ tile_address + 3 ]; |
| 361 | if ( state->vdp.tile_packed ) { |
| 362 | plane0 = ( state->vdp.vram[ tile_address + 0 ] << 24 ) | ( state->vdp.vram[ tile_address + 1 ] << 16 ) | ( state->vdp.vram[ tile_address + 2 ] << 8 ) | state->vdp.vram[ tile_address + 3 ]; |
| 358 | 363 | } else { |
| 359 | | plane0 = wswan_vdp.vram[ tile_address + 0 ]; |
| 360 | | plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1; |
| 361 | | plane2 = wswan_vdp.vram[ tile_address + 2 ] << 2; |
| 362 | | plane3 = wswan_vdp.vram[ tile_address + 3 ] << 3; |
| 364 | plane0 = state->vdp.vram[ tile_address + 0 ]; |
| 365 | plane1 = state->vdp.vram[ tile_address + 1 ] << 1; |
| 366 | plane2 = state->vdp.vram[ tile_address + 2 ] << 2; |
| 367 | plane3 = state->vdp.vram[ tile_address + 3 ] << 3; |
| 363 | 368 | } |
| 364 | 369 | } else { |
| 365 | 370 | tile_address = 0x2000 + ( tile_number * 16 ) + ( tile_line << 1 ); |
| 366 | | if ( wswan_vdp.tile_packed ) { |
| 367 | | plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 8 ) | wswan_vdp.vram[ tile_address + 1 ]; |
| 371 | if ( state->vdp.tile_packed ) { |
| 372 | plane0 = ( state->vdp.vram[ tile_address + 0 ] << 8 ) | state->vdp.vram[ tile_address + 1 ]; |
| 368 | 373 | } else { |
| 369 | | plane0 = wswan_vdp.vram[ tile_address + 0 ]; |
| 370 | | plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1; |
| 374 | plane0 = state->vdp.vram[ tile_address + 0 ]; |
| 375 | plane1 = state->vdp.vram[ tile_address + 1 ] << 1; |
| 371 | 376 | plane2 = 0; |
| 372 | 377 | plane3 = 0; |
| 373 | 378 | } |
| r9669 | r9670 | |
| 375 | 380 | |
| 376 | 381 | for( x = 0; x < 8; x++ ) { |
| 377 | 382 | int col; |
| 378 | | if ( wswan_vdp.tile_packed ) { |
| 379 | | if ( wswan_vdp.colors_16 ) { |
| 383 | if ( state->vdp.tile_packed ) { |
| 384 | if ( state->vdp.colors_16 ) { |
| 380 | 385 | col = plane0 & 0x0F; |
| 381 | 386 | plane0 = plane0 >> 4; |
| 382 | 387 | } else { |
| r9669 | r9670 | |
| 391 | 396 | plane0 = plane0 >> 1; |
| 392 | 397 | } |
| 393 | 398 | if ( tile_data & 0x4000 ) { |
| 394 | | x_offset = x + ( column << 3 ) - ( wswan_vdp.layer_fg_scroll_x & 0x07 ); |
| 399 | x_offset = x + ( column << 3 ) - ( state->vdp.layer_fg_scroll_x & 0x07 ); |
| 395 | 400 | } else { |
| 396 | | x_offset = 7 - x + ( column << 3 ) - ( wswan_vdp.layer_fg_scroll_x & 0x07 ); |
| 401 | x_offset = 7 - x + ( column << 3 ) - ( state->vdp.layer_fg_scroll_x & 0x07 ); |
| 397 | 402 | } |
| 398 | | if ( ( x_offset >= 0 && x_offset < wswan_vdp.window_fg_left ) || ( x_offset >= wswan_vdp.window_fg_right && x_offset < WSWAN_X_PIXELS ) ) { |
| 399 | | if ( wswan_vdp.colors_16 ) { |
| 403 | if ( ( x_offset >= 0 && x_offset < state->vdp.window_fg_left ) || ( x_offset >= state->vdp.window_fg_right && x_offset < WSWAN_X_PIXELS ) ) { |
| 404 | if ( state->vdp.colors_16 ) { |
| 400 | 405 | if ( col ) { |
| 401 | | if ( wswan_vdp.color_mode ) { |
| 402 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 406 | if ( state->vdp.color_mode ) { |
| 407 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 403 | 408 | } else { |
| 404 | 409 | /* Hmmmm, what should we do here... Is this correct?? */ |
| 405 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 410 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 406 | 411 | } |
| 407 | 412 | } |
| 408 | 413 | } else { |
| 409 | 414 | if ( col || !(tile_palette & 4 ) ) { |
| 410 | | if ( wswan_vdp.color_mode ) { |
| 411 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 415 | if ( state->vdp.color_mode ) { |
| 416 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 412 | 417 | } else { |
| 413 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, wswan_vdp.main_palette[pal[tile_palette][col]] ); |
| 418 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->vdp.main_palette[state->pal[tile_palette][col]] ); |
| 414 | 419 | } |
| 415 | 420 | } |
| 416 | 421 | } |
| r9669 | r9670 | |
| 420 | 425 | } |
| 421 | 426 | |
| 422 | 427 | static void wswan_handle_sprites( running_machine *machine, int mask ) { |
| 428 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 423 | 429 | int i; |
| 424 | | if ( wswan_vdp.sprite_count == 0 ) |
| 430 | if ( state->vdp.sprite_count == 0 ) |
| 425 | 431 | return; |
| 426 | | for( i = wswan_vdp.sprite_first + wswan_vdp.sprite_count - 1; i >= wswan_vdp.sprite_first; i-- ) { |
| 432 | for( i = state->vdp.sprite_first + state->vdp.sprite_count - 1; i >= state->vdp.sprite_first; i-- ) { |
| 427 | 433 | UINT8 x, y; |
| 428 | 434 | UINT16 tile_data; |
| 429 | 435 | int tile_line; |
| 430 | 436 | |
| 431 | | tile_data = ( wswan_vdp.vram[ wswan_vdp.sprite_table_address + i * 4 + 1 ] << 8 ) |
| 432 | | | wswan_vdp.vram[ wswan_vdp.sprite_table_address + i * 4 ]; |
| 433 | | y = wswan_vdp.vram[ wswan_vdp.sprite_table_address + i * 4 + 2 ]; |
| 434 | | x = wswan_vdp.vram[ wswan_vdp.sprite_table_address + i * 4 + 3 ]; |
| 435 | | tile_line = wswan_vdp.current_line - y; |
| 437 | tile_data = ( state->vdp.vram[ state->vdp.sprite_table_address + i * 4 + 1 ] << 8 ) |
| 438 | | state->vdp.vram[ state->vdp.sprite_table_address + i * 4 ]; |
| 439 | y = state->vdp.vram[ state->vdp.sprite_table_address + i * 4 + 2 ]; |
| 440 | x = state->vdp.vram[ state->vdp.sprite_table_address + i * 4 + 3 ]; |
| 441 | tile_line = state->vdp.current_line - y; |
| 436 | 442 | tile_line = tile_line & 0xFF; |
| 437 | 443 | if ( ( tile_line >= 0 ) && ( tile_line < 8 ) && ( ( tile_data & mask ) == mask ) ) { |
| 438 | 444 | UINT32 plane0 = 0, plane1 = 0, plane2 = 0, plane3 = 0; |
| r9669 | r9670 | |
| 444 | 450 | tile_line = 7 - tile_line; |
| 445 | 451 | } |
| 446 | 452 | |
| 447 | | if ( wswan_vdp.colors_16 ) { |
| 453 | if ( state->vdp.colors_16 ) { |
| 448 | 454 | tile_address = 0x4000 + ( tile_number * 32 ) + ( tile_line << 2 ); |
| 449 | | if ( wswan_vdp.tile_packed ) { |
| 450 | | plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 24 ) | ( wswan_vdp.vram[ tile_address + 1 ] << 16 ) | ( wswan_vdp.vram[ tile_address + 2 ] << 8 ) | wswan_vdp.vram[ tile_address + 3 ]; |
| 455 | if ( state->vdp.tile_packed ) { |
| 456 | plane0 = ( state->vdp.vram[ tile_address + 0 ] << 24 ) | ( state->vdp.vram[ tile_address + 1 ] << 16 ) | ( state->vdp.vram[ tile_address + 2 ] << 8 ) | state->vdp.vram[ tile_address + 3 ]; |
| 451 | 457 | } else { |
| 452 | | plane0 = wswan_vdp.vram[ tile_address + 0 ]; |
| 453 | | plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1; |
| 454 | | plane2 = wswan_vdp.vram[ tile_address + 2 ] << 2; |
| 455 | | plane3 = wswan_vdp.vram[ tile_address + 3 ] << 3; |
| 458 | plane0 = state->vdp.vram[ tile_address + 0 ]; |
| 459 | plane1 = state->vdp.vram[ tile_address + 1 ] << 1; |
| 460 | plane2 = state->vdp.vram[ tile_address + 2 ] << 2; |
| 461 | plane3 = state->vdp.vram[ tile_address + 3 ] << 3; |
| 456 | 462 | } |
| 457 | 463 | } else { |
| 458 | 464 | tile_address = 0x2000 + ( tile_number * 16 ) + ( tile_line << 1 ); |
| 459 | | if ( wswan_vdp.tile_packed ) { |
| 460 | | plane0 = ( wswan_vdp.vram[ tile_address + 0 ] << 8 ) | wswan_vdp.vram[ tile_address + 1 ]; |
| 465 | if ( state->vdp.tile_packed ) { |
| 466 | plane0 = ( state->vdp.vram[ tile_address + 0 ] << 8 ) | state->vdp.vram[ tile_address + 1 ]; |
| 461 | 467 | } else { |
| 462 | | plane0 = wswan_vdp.vram[ tile_address + 0 ]; |
| 463 | | plane1 = wswan_vdp.vram[ tile_address + 1 ] << 1; |
| 468 | plane0 = state->vdp.vram[ tile_address + 0 ]; |
| 469 | plane1 = state->vdp.vram[ tile_address + 1 ] << 1; |
| 464 | 470 | plane2 = 0; |
| 465 | 471 | plane3 = 0; |
| 466 | 472 | } |
| 467 | 473 | } |
| 468 | 474 | |
| 469 | | if ( wswan_vdp.window_sprites_enable ) { |
| 475 | if ( state->vdp.window_sprites_enable ) { |
| 470 | 476 | if ( tile_data & 0x1000 ) { |
| 471 | | if ( wswan_vdp.current_line >= wswan_vdp.window_sprites_top && wswan_vdp.current_line <= wswan_vdp.window_sprites_bottom ) { |
| 477 | if ( state->vdp.current_line >= state->vdp.window_sprites_top && state->vdp.current_line <= state->vdp.window_sprites_bottom ) { |
| 472 | 478 | check_clip = 1; |
| 473 | 479 | } |
| 474 | 480 | } else { |
| 475 | | if ( wswan_vdp.current_line < wswan_vdp.window_sprites_top || wswan_vdp.current_line > wswan_vdp.window_sprites_bottom ) { |
| 481 | if ( state->vdp.current_line < state->vdp.window_sprites_top || state->vdp.current_line > state->vdp.window_sprites_bottom ) { |
| 476 | 482 | continue; |
| 477 | 483 | } |
| 478 | 484 | } |
| r9669 | r9670 | |
| 480 | 486 | |
| 481 | 487 | for ( j = 0; j < 8; j++ ) { |
| 482 | 488 | int col; |
| 483 | | if ( wswan_vdp.tile_packed ) { |
| 484 | | if ( wswan_vdp.colors_16 ) { |
| 489 | if ( state->vdp.tile_packed ) { |
| 490 | if ( state->vdp.colors_16 ) { |
| 485 | 491 | col = plane0 & 0x0F; |
| 486 | 492 | plane0 = plane0 >> 4; |
| 487 | 493 | } else { |
| r9669 | r9670 | |
| 501 | 507 | x_offset = x + 7 - j; |
| 502 | 508 | } |
| 503 | 509 | x_offset = x_offset & 0xFF; |
| 504 | | if ( wswan_vdp.window_sprites_enable ) { |
| 510 | if ( state->vdp.window_sprites_enable ) { |
| 505 | 511 | if ( tile_data & 0x1000 && check_clip ) { |
| 506 | | if ( x_offset >= wswan_vdp.window_sprites_left && x_offset <= wswan_vdp.window_sprites_right ) { |
| 512 | if ( x_offset >= state->vdp.window_sprites_left && x_offset <= state->vdp.window_sprites_right ) { |
| 507 | 513 | continue; |
| 508 | 514 | } |
| 509 | 515 | } else { |
| 510 | | if ( x_offset < wswan_vdp.window_sprites_left || x_offset > wswan_vdp.window_sprites_right ) { |
| 516 | if ( x_offset < state->vdp.window_sprites_left || x_offset > state->vdp.window_sprites_right ) { |
| 511 | 517 | // continue; |
| 512 | 518 | } |
| 513 | 519 | } |
| 514 | 520 | } |
| 515 | 521 | if ( x_offset >= 0 && x_offset < WSWAN_X_PIXELS ) { |
| 516 | | if ( wswan_vdp.colors_16 ) { |
| 522 | if ( state->vdp.colors_16 ) { |
| 517 | 523 | if ( col ) { |
| 518 | | if ( wswan_vdp.color_mode ) { |
| 519 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 524 | if ( state->vdp.color_mode ) { |
| 525 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 520 | 526 | } else { |
| 521 | 527 | /* Hmmmm, what should we do here... Is this correct?? */ |
| 522 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 528 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 523 | 529 | } |
| 524 | 530 | } |
| 525 | 531 | } else { |
| 526 | 532 | if ( col || !(tile_palette & 4 ) ) { |
| 527 | | if ( wswan_vdp.color_mode ) { |
| 528 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, pal[tile_palette][col] ); |
| 533 | if ( state->vdp.color_mode ) { |
| 534 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->pal[tile_palette][col] ); |
| 529 | 535 | } else { |
| 530 | | wswan_plot_pixel( machine, x_offset, wswan_vdp.current_line, wswan_vdp.main_palette[pal[tile_palette][col]] ); |
| 536 | wswan_plot_pixel( machine, x_offset, state->vdp.current_line, state->vdp.main_palette[state->pal[tile_palette][col]] ); |
| 531 | 537 | } |
| 532 | 538 | } |
| 533 | 539 | } |
| r9669 | r9670 | |
| 539 | 545 | |
| 540 | 546 | void wswan_refresh_scanline( running_machine *machine ) |
| 541 | 547 | { |
| 548 | wswan_state *state = machine->driver_data<wswan_state>(); |
| 542 | 549 | rectangle rec; |
| 543 | 550 | |
| 544 | | wswan_setup_palettes(); |
| 551 | wswan_setup_palettes(state); |
| 545 | 552 | |
| 546 | 553 | rec.min_x = 0; |
| 547 | 554 | rec.max_x = WSWAN_X_PIXELS; |
| 548 | | rec.min_y = rec.max_y = wswan_vdp.current_line; |
| 549 | | if ( ws_portram[0x14] ) { |
| 555 | rec.min_y = rec.max_y = state->vdp.current_line; |
| 556 | if ( state->ws_portram[0x14] ) { |
| 550 | 557 | /* Not sure if these background color checks and settings are correct */ |
| 551 | | if ( wswan_vdp.color_mode && wswan_vdp.colors_16 ) { |
| 552 | | wswan_fillbitmap( machine, pal[ws_portram[0x01]>>4][ws_portram[0x01]&0x0F], &rec ); |
| 558 | if ( state->vdp.color_mode && state->vdp.colors_16 ) { |
| 559 | wswan_fillbitmap( machine, state->pal[state->ws_portram[0x01]>>4][state->ws_portram[0x01]&0x0F], &rec ); |
| 553 | 560 | } else { |
| 554 | | wswan_fillbitmap( machine, wswan_vdp.main_palette[ws_portram[0x01]&0x07], &rec ); |
| 561 | wswan_fillbitmap( machine, state->vdp.main_palette[state->ws_portram[0x01]&0x07], &rec ); |
| 555 | 562 | } |
| 556 | 563 | } else { |
| 557 | 564 | wswan_fillbitmap( machine, 0, &rec ); |
| r9669 | r9670 | |
| 561 | 568 | /* |
| 562 | 569 | * Draw background layer |
| 563 | 570 | */ |
| 564 | | if ( wswan_vdp.layer_bg_enable ) { |
| 571 | if ( state->vdp.layer_bg_enable ) { |
| 565 | 572 | wswan_draw_background(machine); |
| 566 | 573 | } |
| 567 | 574 | |
| 568 | 575 | /* |
| 569 | 576 | * Draw sprites between background and foreground layers |
| 570 | 577 | */ |
| 571 | | if ( wswan_vdp.sprites_enable ) { |
| 578 | if ( state->vdp.sprites_enable ) { |
| 572 | 579 | wswan_handle_sprites( machine, 0 ); |
| 573 | 580 | } |
| 574 | 581 | |
| 575 | 582 | /* |
| 576 | 583 | * Draw foreground layer, taking window settings into account |
| 577 | 584 | */ |
| 578 | | if ( wswan_vdp.layer_fg_enable ) { |
| 579 | | switch( wswan_vdp.window_fg_mode ) { |
| 585 | if ( state->vdp.layer_fg_enable ) { |
| 586 | switch( state->vdp.window_fg_mode ) { |
| 580 | 587 | case 0: /* FG inside & outside window area */ |
| 581 | 588 | wswan_draw_foreground_0(machine); |
| 582 | 589 | break; |
| r9669 | r9670 | |
| 584 | 591 | logerror( "Unknown foreground mode 1 set\n" ); |
| 585 | 592 | break; |
| 586 | 593 | case 2: /* FG only inside window area */ |
| 587 | | if ( wswan_vdp.current_line >= wswan_vdp.window_fg_top && wswan_vdp.current_line <= wswan_vdp.window_fg_bottom ) { |
| 594 | if ( state->vdp.current_line >= state->vdp.window_fg_top && state->vdp.current_line <= state->vdp.window_fg_bottom ) { |
| 588 | 595 | wswan_draw_foreground_2(machine); |
| 589 | 596 | } |
| 590 | 597 | break; |
| 591 | 598 | case 3: /* FG only outside window area */ |
| 592 | | if ( wswan_vdp.current_line < wswan_vdp.window_fg_top || wswan_vdp.current_line > wswan_vdp.window_fg_bottom ) { |
| 599 | if ( state->vdp.current_line < state->vdp.window_fg_top || state->vdp.current_line > state->vdp.window_fg_bottom ) { |
| 593 | 600 | wswan_draw_foreground_0(machine); |
| 594 | 601 | } else { |
| 595 | 602 | wswan_draw_foreground_3(machine); |
| r9669 | r9670 | |
| 601 | 608 | /* |
| 602 | 609 | * Draw sprites in front of foreground layer |
| 603 | 610 | */ |
| 604 | | if ( wswan_vdp.sprites_enable ) { |
| 611 | if ( state->vdp.sprites_enable ) { |
| 605 | 612 | wswan_handle_sprites( machine, 0x2000 ); |
| 606 | 613 | } |
| 607 | 614 | } |
src/mess/video/x68k.c
| r9669 | r9670 | |
| 30 | 30 | #include "machine/68901mfp.h" |
| 31 | 31 | #include "devices/messram.h" |
| 32 | 32 | |
| 33 | | UINT16* x68k_gvram; // Graphic VRAM |
| 34 | | UINT16* x68k_tvram; // Text VRAM |
| 35 | | UINT16* x68k_spriteram; // sprite/background RAM |
| 36 | | UINT16* x68k_spritereg; // sprite/background registers |
| 37 | 33 | |
| 38 | | static tilemap_t* x68k_bg0_8; // two 64x64 tilemaps, 8x8 characters |
| 39 | | static tilemap_t* x68k_bg1_8; |
| 40 | | static tilemap_t* x68k_bg0_16; // two 64x64 tilemaps, 16x16 characters |
| 41 | | static tilemap_t* x68k_bg1_16; |
| 42 | 34 | |
| 43 | | static int sprite_shift; |
| 44 | 35 | |
| 45 | 36 | static void x68k_crtc_refresh_mode(running_machine *machine); |
| 46 | 37 | |
| r9669 | r9670 | |
| 87 | 78 | return NULL; // should never reach here either. |
| 88 | 79 | } |
| 89 | 80 | */ |
| 90 | | static void x68k_crtc_text_copy(int src, int dest) |
| 81 | static void x68k_crtc_text_copy(x68k_state *state, int src, int dest) |
| 91 | 82 | { |
| 92 | 83 | // copys one raster in T-VRAM to another raster |
| 93 | 84 | int src_ram = src * 256; // 128 bytes per scanline |
| r9669 | r9670 | |
| 100 | 91 | for(line=0;line<8;line++) |
| 101 | 92 | { |
| 102 | 93 | // update RAM in each plane |
| 103 | | memcpy(x68k_tvram+dest_ram,x68k_tvram+src_ram,128); |
| 104 | | memcpy(x68k_tvram+dest_ram+0x10000,x68k_tvram+src_ram+0x10000,128); |
| 105 | | memcpy(x68k_tvram+dest_ram+0x20000,x68k_tvram+src_ram+0x20000,128); |
| 106 | | memcpy(x68k_tvram+dest_ram+0x30000,x68k_tvram+src_ram+0x30000,128); |
| 94 | memcpy(state->tvram+dest_ram,state->tvram+src_ram,128); |
| 95 | memcpy(state->tvram+dest_ram+0x10000,state->tvram+src_ram+0x10000,128); |
| 96 | memcpy(state->tvram+dest_ram+0x20000,state->tvram+src_ram+0x20000,128); |
| 97 | memcpy(state->tvram+dest_ram+0x30000,state->tvram+src_ram+0x30000,128); |
| 107 | 98 | |
| 108 | 99 | src_ram+=64; |
| 109 | 100 | dest_ram+=64; |
| r9669 | r9670 | |
| 113 | 104 | |
| 114 | 105 | static TIMER_CALLBACK(x68k_crtc_operation_end) |
| 115 | 106 | { |
| 107 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 116 | 108 | int bit = param; |
| 117 | | x68k_sys.crtc.operation &= ~bit; |
| 109 | state->crtc.operation &= ~bit; |
| 118 | 110 | } |
| 119 | 111 | |
| 120 | 112 | static void x68k_crtc_refresh_mode(running_machine *machine) |
| 121 | 113 | { |
| 114 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 122 | 115 | // rectangle rect; |
| 123 | 116 | // double scantime; |
| 124 | 117 | rectangle scr,visiblescr; |
| 125 | 118 | int length; |
| 126 | 119 | |
| 127 | 120 | // Calculate data from register values |
| 128 | | x68k_sys.crtc.vmultiple = 1; |
| 129 | | if((x68k_sys.crtc.reg[20] & 0x10) != 0 && (x68k_sys.crtc.reg[20] & 0x0c) == 0) |
| 130 | | x68k_sys.crtc.vmultiple = 2; // 31.5kHz + 256 lines = doublescan |
| 131 | | if(x68k_sys.crtc.interlace != 0) |
| 132 | | x68k_sys.crtc.vmultiple = 0.5f; // 31.5kHz + 1024 lines or 15kHz + 512 lines = interlaced |
| 133 | | x68k_sys.crtc.htotal = (x68k_sys.crtc.reg[0] + 1) * 8; |
| 134 | | x68k_sys.crtc.vtotal = (x68k_sys.crtc.reg[4] + 1) / x68k_sys.crtc.vmultiple; // default is 567 (568 scanlines) |
| 135 | | x68k_sys.crtc.hbegin = (x68k_sys.crtc.reg[2] * 8) + 1; |
| 136 | | x68k_sys.crtc.hend = (x68k_sys.crtc.reg[3] * 8); |
| 137 | | x68k_sys.crtc.vbegin = (x68k_sys.crtc.reg[6]) / x68k_sys.crtc.vmultiple; |
| 138 | | x68k_sys.crtc.vend = (x68k_sys.crtc.reg[7] - 1) / x68k_sys.crtc.vmultiple; |
| 139 | | x68k_sys.crtc.hsync_end = (x68k_sys.crtc.reg[1]) * 8; |
| 140 | | x68k_sys.crtc.vsync_end = (x68k_sys.crtc.reg[5]) / x68k_sys.crtc.vmultiple; |
| 141 | | x68k_sys.crtc.hsyncadjust = x68k_sys.crtc.reg[8]; |
| 121 | state->crtc.vmultiple = 1; |
| 122 | if((state->crtc.reg[20] & 0x10) != 0 && (state->crtc.reg[20] & 0x0c) == 0) |
| 123 | state->crtc.vmultiple = 2; // 31.5kHz + 256 lines = doublescan |
| 124 | if(state->crtc.interlace != 0) |
| 125 | state->crtc.vmultiple = 0.5f; // 31.5kHz + 1024 lines or 15kHz + 512 lines = interlaced |
| 126 | state->crtc.htotal = (state->crtc.reg[0] + 1) * 8; |
| 127 | state->crtc.vtotal = (state->crtc.reg[4] + 1) / state->crtc.vmultiple; // default is 567 (568 scanlines) |
| 128 | state->crtc.hbegin = (state->crtc.reg[2] * 8) + 1; |
| 129 | state->crtc.hend = (state->crtc.reg[3] * 8); |
| 130 | state->crtc.vbegin = (state->crtc.reg[6]) / state->crtc.vmultiple; |
| 131 | state->crtc.vend = (state->crtc.reg[7] - 1) / state->crtc.vmultiple; |
| 132 | state->crtc.hsync_end = (state->crtc.reg[1]) * 8; |
| 133 | state->crtc.vsync_end = (state->crtc.reg[5]) / state->crtc.vmultiple; |
| 134 | state->crtc.hsyncadjust = state->crtc.reg[8]; |
| 142 | 135 | scr.min_x = scr.min_y = 0; |
| 143 | | scr.max_x = x68k_sys.crtc.htotal - 8; |
| 144 | | scr.max_y = x68k_sys.crtc.vtotal; |
| 145 | | if(scr.max_y <= x68k_sys.crtc.vend) |
| 146 | | scr.max_y = x68k_sys.crtc.vend + 2; |
| 147 | | if(scr.max_x <= x68k_sys.crtc.hend) |
| 148 | | scr.max_x = x68k_sys.crtc.hend + 2; |
| 149 | | visiblescr.min_x = x68k_sys.crtc.hbegin; |
| 150 | | visiblescr.max_x = x68k_sys.crtc.hend; |
| 151 | | visiblescr.min_y = x68k_sys.crtc.vbegin; |
| 152 | | visiblescr.max_y = x68k_sys.crtc.vend; |
| 136 | scr.max_x = state->crtc.htotal - 8; |
| 137 | scr.max_y = state->crtc.vtotal; |
| 138 | if(scr.max_y <= state->crtc.vend) |
| 139 | scr.max_y = state->crtc.vend + 2; |
| 140 | if(scr.max_x <= state->crtc.hend) |
| 141 | scr.max_x = state->crtc.hend + 2; |
| 142 | visiblescr.min_x = state->crtc.hbegin; |
| 143 | visiblescr.max_x = state->crtc.hend; |
| 144 | visiblescr.min_y = state->crtc.vbegin; |
| 145 | visiblescr.max_y = state->crtc.vend; |
| 153 | 146 | |
| 154 | 147 | // expand visible area to the size indicated by CRTC reg 20 |
| 155 | | length = x68k_sys.crtc.hend - x68k_sys.crtc.hbegin; |
| 156 | | if (length < x68k_sys.crtc.width) |
| 148 | length = state->crtc.hend - state->crtc.hbegin; |
| 149 | if (length < state->crtc.width) |
| 157 | 150 | { |
| 158 | | visiblescr.min_x = x68k_sys.crtc.hbegin - ((x68k_sys.crtc.width - length)/2); |
| 159 | | visiblescr.max_x = x68k_sys.crtc.hend + ((x68k_sys.crtc.width - length)/2); |
| 151 | visiblescr.min_x = state->crtc.hbegin - ((state->crtc.width - length)/2); |
| 152 | visiblescr.max_x = state->crtc.hend + ((state->crtc.width - length)/2); |
| 160 | 153 | } |
| 161 | | length = x68k_sys.crtc.vend - x68k_sys.crtc.vbegin; |
| 162 | | if (length < x68k_sys.crtc.height) |
| 154 | length = state->crtc.vend - state->crtc.vbegin; |
| 155 | if (length < state->crtc.height) |
| 163 | 156 | { |
| 164 | | visiblescr.min_y = x68k_sys.crtc.vbegin - ((x68k_sys.crtc.height - length)/2); |
| 165 | | visiblescr.max_y = x68k_sys.crtc.vend + ((x68k_sys.crtc.height - length)/2); |
| 157 | visiblescr.min_y = state->crtc.vbegin - ((state->crtc.height - length)/2); |
| 158 | visiblescr.max_y = state->crtc.vend + ((state->crtc.height - length)/2); |
| 166 | 159 | } |
| 167 | 160 | // bounds check |
| 168 | 161 | if(visiblescr.min_x < 0) |
| r9669 | r9670 | |
| 174 | 167 | if(visiblescr.max_y >= scr.max_y - 1) |
| 175 | 168 | visiblescr.max_y = scr.max_y - 2; |
| 176 | 169 | |
| 177 | | // logerror("CRTC regs - %i %i %i %i - %i %i %i %i - %i - %i\n",x68k_sys.crtc.reg[0],x68k_sys.crtc.reg[1],x68k_sys.crtc.reg[2],x68k_sys.crtc.reg[3], |
| 178 | | // x68k_sys.crtc.reg[4],x68k_sys.crtc.reg[5],x68k_sys.crtc.reg[6],x68k_sys.crtc.reg[7],x68k_sys.crtc.reg[8],x68k_sys.crtc.reg[9]); |
| 170 | // logerror("CRTC regs - %i %i %i %i - %i %i %i %i - %i - %i\n",state->crtc.reg[0],state->crtc.reg[1],state->crtc.reg[2],state->crtc.reg[3], |
| 171 | // state->crtc.reg[4],state->crtc.reg[5],state->crtc.reg[6],state->crtc.reg[7],state->crtc.reg[8],state->crtc.reg[9]); |
| 179 | 172 | logerror("video_screen_configure(machine->primary_screen,%i,%i,[%i,%i,%i,%i],55.45)\n",scr.max_x,scr.max_y,visiblescr.min_x,visiblescr.min_y,visiblescr.max_x,visiblescr.max_y); |
| 180 | 173 | machine->primary_screen->configure(scr.max_x,scr.max_y,visiblescr,HZ_TO_ATTOSECONDS(55.45)); |
| 181 | 174 | } |
| 182 | 175 | |
| 183 | 176 | TIMER_CALLBACK(x68k_hsync) |
| 184 | 177 | { |
| 185 | | int state = param; |
| 178 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 179 | int hstate = param; |
| 186 | 180 | attotime hsync_time; |
| 187 | 181 | |
| 188 | | x68k_sys.crtc.hblank = state; |
| 189 | | if(x68k_sys.crtc.vmultiple == 2) // 256-line (doublescan) |
| 182 | state->crtc.hblank = hstate; |
| 183 | if(state->crtc.vmultiple == 2) // 256-line (doublescan) |
| 190 | 184 | { |
| 191 | | static int oddscanline; |
| 192 | | if(state == 1) |
| 185 | if(hstate == 1) |
| 193 | 186 | { |
| 194 | | if(oddscanline == 1) |
| 187 | if(state->oddscanline == 1) |
| 195 | 188 | { |
| 196 | 189 | int scan = machine->primary_screen->vpos(); |
| 197 | | if(scan > x68k_sys.crtc.vend) |
| 198 | | scan = x68k_sys.crtc.vbegin; |
| 199 | | hsync_time = machine->primary_screen->time_until_pos(scan,(x68k_sys.crtc.htotal + x68k_sys.crtc.hend) / 2); |
| 200 | | timer_adjust_oneshot(x68k_scanline_timer, hsync_time, 0); |
| 190 | if(scan > state->crtc.vend) |
| 191 | scan = state->crtc.vbegin; |
| 192 | hsync_time = machine->primary_screen->time_until_pos(scan,(state->crtc.htotal + state->crtc.hend) / 2); |
| 193 | timer_adjust_oneshot(state->scanline_timer, hsync_time, 0); |
| 201 | 194 | if(scan != 0) |
| 202 | 195 | { |
| 203 | 196 | if((input_port_read(machine, "options") & 0x04)) |
| r9669 | r9670 | |
| 209 | 202 | else |
| 210 | 203 | { |
| 211 | 204 | int scan = machine->primary_screen->vpos(); |
| 212 | | if(scan > x68k_sys.crtc.vend) |
| 213 | | scan = x68k_sys.crtc.vbegin; |
| 214 | | hsync_time = machine->primary_screen->time_until_pos(scan,x68k_sys.crtc.hend / 2); |
| 215 | | timer_adjust_oneshot(x68k_scanline_timer, hsync_time, 0); |
| 205 | if(scan > state->crtc.vend) |
| 206 | scan = state->crtc.vbegin; |
| 207 | hsync_time = machine->primary_screen->time_until_pos(scan,state->crtc.hend / 2); |
| 208 | timer_adjust_oneshot(state->scanline_timer, hsync_time, 0); |
| 216 | 209 | if(scan != 0) |
| 217 | 210 | { |
| 218 | 211 | if((input_port_read(machine, "options") & 0x04)) |
| r9669 | r9670 | |
| 222 | 215 | } |
| 223 | 216 | } |
| 224 | 217 | } |
| 225 | | if(state == 0) |
| 218 | if(hstate == 0) |
| 226 | 219 | { |
| 227 | | if(oddscanline == 1) |
| 220 | if(state->oddscanline == 1) |
| 228 | 221 | { |
| 229 | 222 | int scan = machine->primary_screen->vpos(); |
| 230 | | if(scan > x68k_sys.crtc.vend) |
| 231 | | scan = x68k_sys.crtc.vbegin; |
| 223 | if(scan > state->crtc.vend) |
| 224 | scan = state->crtc.vbegin; |
| 232 | 225 | else |
| 233 | 226 | scan++; |
| 234 | | hsync_time = machine->primary_screen->time_until_pos(scan,x68k_sys.crtc.hbegin / 2); |
| 235 | | timer_adjust_oneshot(x68k_scanline_timer, hsync_time, 1); |
| 236 | | oddscanline = 0; |
| 227 | hsync_time = machine->primary_screen->time_until_pos(scan,state->crtc.hbegin / 2); |
| 228 | timer_adjust_oneshot(state->scanline_timer, hsync_time, 1); |
| 229 | state->oddscanline = 0; |
| 237 | 230 | } |
| 238 | 231 | else |
| 239 | 232 | { |
| 240 | | hsync_time = machine->primary_screen->time_until_pos(machine->primary_screen->vpos(),(x68k_sys.crtc.htotal + x68k_sys.crtc.hbegin) / 2); |
| 241 | | timer_adjust_oneshot(x68k_scanline_timer, hsync_time, 1); |
| 242 | | oddscanline = 1; |
| 233 | hsync_time = machine->primary_screen->time_until_pos(machine->primary_screen->vpos(),(state->crtc.htotal + state->crtc.hbegin) / 2); |
| 234 | timer_adjust_oneshot(state->scanline_timer, hsync_time, 1); |
| 235 | state->oddscanline = 1; |
| 243 | 236 | } |
| 244 | 237 | } |
| 245 | 238 | } |
| 246 | 239 | else // 512-line |
| 247 | 240 | { |
| 248 | | if(state == 1) |
| 241 | if(hstate == 1) |
| 249 | 242 | { |
| 250 | 243 | int scan = machine->primary_screen->vpos(); |
| 251 | | if(scan > x68k_sys.crtc.vend) |
| 244 | if(scan > state->crtc.vend) |
| 252 | 245 | scan = 0; |
| 253 | | hsync_time = machine->primary_screen->time_until_pos(scan,x68k_sys.crtc.hend); |
| 254 | | timer_adjust_oneshot(x68k_scanline_timer, hsync_time, 0); |
| 246 | hsync_time = machine->primary_screen->time_until_pos(scan,state->crtc.hend); |
| 247 | timer_adjust_oneshot(state->scanline_timer, hsync_time, 0); |
| 255 | 248 | if(scan != 0) |
| 256 | 249 | { |
| 257 | 250 | if((input_port_read(machine, "options") & 0x04)) |
| r9669 | r9670 | |
| 260 | 253 | } |
| 261 | 254 | } |
| 262 | 255 | } |
| 263 | | if(state == 0) |
| 256 | if(hstate == 0) |
| 264 | 257 | { |
| 265 | | hsync_time = machine->primary_screen->time_until_pos(machine->primary_screen->vpos()+1,x68k_sys.crtc.hbegin); |
| 266 | | timer_adjust_oneshot(x68k_scanline_timer, hsync_time, 1); |
| 267 | | // if(!(x68k_sys.mfp.gpio & 0x40)) // if GPIP6 is active, clear it |
| 268 | | // x68k_sys.mfp.gpio |= 0x40; |
| 258 | hsync_time = machine->primary_screen->time_until_pos(machine->primary_screen->vpos()+1,state->crtc.hbegin); |
| 259 | timer_adjust_oneshot(state->scanline_timer, hsync_time, 1); |
| 260 | // if(!(state->mfp.gpio & 0x40)) // if GPIP6 is active, clear it |
| 261 | // state->mfp.gpio |= 0x40; |
| 269 | 262 | } |
| 270 | 263 | } |
| 271 | 264 | } |
| 272 | 265 | |
| 273 | 266 | static TIMER_CALLBACK(x68k_crtc_raster_end) |
| 274 | 267 | { |
| 275 | | x68k_sys.mfp.gpio |= 0x40; |
| 268 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 269 | state->mfp.gpio |= 0x40; |
| 276 | 270 | } |
| 277 | 271 | |
| 278 | 272 | TIMER_CALLBACK(x68k_crtc_raster_irq) |
| 279 | 273 | { |
| 274 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 280 | 275 | int scan = param; |
| 281 | 276 | attotime irq_time; |
| 282 | 277 | attotime end_time; |
| 283 | 278 | |
| 284 | | if(scan <= x68k_sys.crtc.vtotal) |
| 279 | if(scan <= state->crtc.vtotal) |
| 285 | 280 | { |
| 286 | | x68k_sys.mfp.gpio &= ~0x40; // GPIP6 |
| 281 | state->mfp.gpio &= ~0x40; // GPIP6 |
| 287 | 282 | machine->primary_screen->update_partial(scan); |
| 288 | | irq_time = machine->primary_screen->time_until_pos(scan,x68k_sys.crtc.hbegin); |
| 283 | irq_time = machine->primary_screen->time_until_pos(scan,state->crtc.hbegin); |
| 289 | 284 | // end of HBlank period clears GPIP6 also? |
| 290 | | end_time = machine->primary_screen->time_until_pos(scan,x68k_sys.crtc.hend); |
| 291 | | timer_adjust_oneshot(x68k_raster_irq, irq_time, scan); |
| 285 | end_time = machine->primary_screen->time_until_pos(scan,state->crtc.hend); |
| 286 | timer_adjust_oneshot(state->raster_irq, irq_time, scan); |
| 292 | 287 | timer_set(machine, end_time,NULL,0,x68k_crtc_raster_end); |
| 293 | 288 | logerror("GPIP6: Raster triggered at line %i (%i)\n",scan,machine->primary_screen->vpos()); |
| 294 | 289 | } |
| r9669 | r9670 | |
| 296 | 291 | |
| 297 | 292 | TIMER_CALLBACK(x68k_crtc_vblank_irq) |
| 298 | 293 | { |
| 294 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 299 | 295 | running_device *x68k_mfp = machine->device(MC68901_TAG); |
| 300 | 296 | int val = param; |
| 301 | 297 | attotime irq_time; |
| r9669 | r9670 | |
| 303 | 299 | |
| 304 | 300 | if(val == 1) // VBlank on |
| 305 | 301 | { |
| 306 | | x68k_sys.crtc.vblank = 1; |
| 307 | | vblank_line = x68k_sys.crtc.vbegin; |
| 302 | state->crtc.vblank = 1; |
| 303 | vblank_line = state->crtc.vbegin; |
| 308 | 304 | irq_time = machine->primary_screen->time_until_pos(vblank_line,2); |
| 309 | | timer_adjust_oneshot(x68k_vblank_irq, irq_time, 0); |
| 305 | timer_adjust_oneshot(state->vblank_irq, irq_time, 0); |
| 310 | 306 | logerror("CRTC: VBlank on\n"); |
| 311 | 307 | } |
| 312 | 308 | if(val == 0) // VBlank off |
| 313 | 309 | { |
| 314 | | x68k_sys.crtc.vblank = 0; |
| 315 | | vblank_line = x68k_sys.crtc.vend; |
| 316 | | if(vblank_line > x68k_sys.crtc.vtotal) |
| 317 | | vblank_line = x68k_sys.crtc.vtotal; |
| 310 | state->crtc.vblank = 0; |
| 311 | vblank_line = state->crtc.vend; |
| 312 | if(vblank_line > state->crtc.vtotal) |
| 313 | vblank_line = state->crtc.vtotal; |
| 318 | 314 | irq_time = machine->primary_screen->time_until_pos(vblank_line,2); |
| 319 | | timer_adjust_oneshot(x68k_vblank_irq, irq_time, 1); |
| 315 | timer_adjust_oneshot(state->vblank_irq, irq_time, 1); |
| 320 | 316 | logerror("CRTC: VBlank off\n"); |
| 321 | 317 | } |
| 322 | 318 | |
| 323 | 319 | if (x68k_mfp != NULL) |
| 324 | | mc68901_tai_w(x68k_mfp, !x68k_sys.crtc.vblank); |
| 320 | mc68901_tai_w(x68k_mfp, !state->crtc.vblank); |
| 325 | 321 | } |
| 326 | 322 | |
| 327 | 323 | |
| r9669 | r9670 | |
| 374 | 370 | */ |
| 375 | 371 | WRITE16_HANDLER( x68k_crtc_w ) |
| 376 | 372 | { |
| 377 | | COMBINE_DATA(x68k_sys.crtc.reg+offset); |
| 373 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 374 | COMBINE_DATA(state->crtc.reg+offset); |
| 378 | 375 | switch(offset) |
| 379 | 376 | { |
| 380 | 377 | case 0: |
| r9669 | r9670 | |
| 391 | 388 | case 9: // CRTC raster IRQ (GPIP6) |
| 392 | 389 | { |
| 393 | 390 | attotime irq_time; |
| 394 | | irq_time = space->machine->primary_screen->time_until_pos((data) / x68k_sys.crtc.vmultiple,2); |
| 391 | irq_time = space->machine->primary_screen->time_until_pos((data) / state->crtc.vmultiple,2); |
| 395 | 392 | |
| 396 | 393 | if(attotime_to_double(irq_time) > 0) |
| 397 | | timer_adjust_oneshot(x68k_raster_irq, irq_time, (data) / x68k_sys.crtc.vmultiple); |
| 394 | timer_adjust_oneshot(state->raster_irq, irq_time, (data) / state->crtc.vmultiple); |
| 398 | 395 | } |
| 399 | 396 | logerror("CRTC: Write to raster IRQ register - %i\n",data); |
| 400 | 397 | break; |
| 401 | 398 | case 20: |
| 402 | 399 | if(ACCESSING_BITS_0_7) |
| 403 | 400 | { |
| 404 | | x68k_sys.crtc.interlace = 0; |
| 401 | state->crtc.interlace = 0; |
| 405 | 402 | switch(data & 0x0c) |
| 406 | 403 | { |
| 407 | 404 | case 0x00: |
| 408 | | x68k_sys.crtc.height = 256; |
| 405 | state->crtc.height = 256; |
| 409 | 406 | break; |
| 410 | 407 | case 0x08: |
| 411 | 408 | case 0x0c: // TODO: 1024 vertical, if horizontal freq = 31kHz |
| 412 | | x68k_sys.crtc.height = 512; |
| 413 | | x68k_sys.crtc.interlace = 1; // if 31kHz, 1024 lines = interlaced |
| 409 | state->crtc.height = 512; |
| 410 | state->crtc.interlace = 1; // if 31kHz, 1024 lines = interlaced |
| 414 | 411 | break; |
| 415 | 412 | case 0x04: |
| 416 | | x68k_sys.crtc.height = 512; |
| 417 | | if(!(x68k_sys.crtc.reg[20] & 0x0010)) // if 15kHz, 512 lines = interlaced |
| 418 | | x68k_sys.crtc.interlace = 1; |
| 413 | state->crtc.height = 512; |
| 414 | if(!(state->crtc.reg[20] & 0x0010)) // if 15kHz, 512 lines = interlaced |
| 415 | state->crtc.interlace = 1; |
| 419 | 416 | break; |
| 420 | 417 | } |
| 421 | 418 | switch(data & 0x03) |
| 422 | 419 | { |
| 423 | 420 | case 0x00: |
| 424 | | x68k_sys.crtc.width = 256; |
| 421 | state->crtc.width = 256; |
| 425 | 422 | break; |
| 426 | 423 | case 0x01: |
| 427 | | x68k_sys.crtc.width = 512; |
| 424 | state->crtc.width = 512; |
| 428 | 425 | break; |
| 429 | 426 | case 0x02: |
| 430 | 427 | case 0x03: // 0x03 = 50MHz clock mode (XVI only) |
| 431 | | x68k_sys.crtc.width = 768; |
| 428 | state->crtc.width = 768; |
| 432 | 429 | break; |
| 433 | 430 | } |
| 434 | 431 | } |
| 435 | 432 | /* if(ACCESSING_BITS_8_15) |
| 436 | 433 | { |
| 437 | | x68k_sys.crtc.interlace = 0; |
| 434 | state->crtc.interlace = 0; |
| 438 | 435 | if(data & 0x0400) |
| 439 | | x68k_sys.crtc.interlace = 1; |
| 436 | state->crtc.interlace = 1; |
| 440 | 437 | }*/ |
| 441 | 438 | x68k_crtc_refresh_mode(space->machine); |
| 442 | 439 | break; |
| 443 | 440 | case 576: // operation register |
| 444 | | x68k_sys.crtc.operation = data; |
| 441 | state->crtc.operation = data; |
| 445 | 442 | if(data & 0x08) // text screen raster copy |
| 446 | 443 | { |
| 447 | | x68k_crtc_text_copy((x68k_sys.crtc.reg[22] & 0xff00) >> 8,(x68k_sys.crtc.reg[22] & 0x00ff)); |
| 444 | x68k_crtc_text_copy(state, (state->crtc.reg[22] & 0xff00) >> 8,(state->crtc.reg[22] & 0x00ff)); |
| 448 | 445 | timer_set(space->machine, ATTOTIME_IN_MSEC(1), NULL, 0x02,x68k_crtc_operation_end); // time taken to do operation is a complete guess. |
| 449 | 446 | } |
| 450 | 447 | if(data & 0x02) // high-speed graphic screen clear |
| 451 | 448 | { |
| 452 | | memset(x68k_gvram,0,0x40000); |
| 449 | memset(state->gvram,0,0x40000); |
| 453 | 450 | timer_set(space->machine, ATTOTIME_IN_MSEC(10), NULL, 0x02,x68k_crtc_operation_end); // time taken to do operation is a complete guess. |
| 454 | 451 | } |
| 455 | 452 | break; |
| r9669 | r9670 | |
| 459 | 456 | |
| 460 | 457 | READ16_HANDLER( x68k_crtc_r ) |
| 461 | 458 | { |
| 459 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 462 | 460 | #if 0 |
| 463 | 461 | switch(offset) |
| 464 | 462 | { |
| r9669 | r9670 | |
| 470 | 468 | |
| 471 | 469 | if(offset < 24) |
| 472 | 470 | { |
| 473 | | // logerror("CRTC: [%08x] Read %04x from CRTC register %i\n",cpu_get_pc(space->machine->device("maincpu")),x68k_sys.crtc.reg[offset],offset); |
| 471 | // logerror("CRTC: [%08x] Read %04x from CRTC register %i\n",cpu_get_pc(space->machine->device("maincpu")),state->crtc.reg[offset],offset); |
| 474 | 472 | switch(offset) |
| 475 | 473 | { |
| 476 | 474 | case 9: |
| r9669 | r9670 | |
| 479 | 477 | case 11: |
| 480 | 478 | case 12: // Graphic layer 0 scroll |
| 481 | 479 | case 13: |
| 482 | | return x68k_sys.crtc.reg[offset] & 0x3ff; |
| 480 | return state->crtc.reg[offset] & 0x3ff; |
| 483 | 481 | case 14: // Graphic layer 1 scroll |
| 484 | 482 | case 15: |
| 485 | 483 | case 16: // Graphic layer 2 scroll |
| 486 | 484 | case 17: |
| 487 | 485 | case 18: // Graphic layer 3 scroll |
| 488 | 486 | case 19: |
| 489 | | return x68k_sys.crtc.reg[offset] & 0x1ff; |
| 487 | return state->crtc.reg[offset] & 0x1ff; |
| 490 | 488 | default: |
| 491 | | return x68k_sys.crtc.reg[offset]; |
| 489 | return state->crtc.reg[offset]; |
| 492 | 490 | } |
| 493 | 491 | } |
| 494 | 492 | if(offset == 576) // operation port, operation bits are set to 0 when operation is complete |
| 495 | | return x68k_sys.crtc.operation; |
| 493 | return state->crtc.operation; |
| 496 | 494 | // logerror("CRTC: [%08x] Read from unknown CRTC register %i\n",activecpu_get_pc(),offset); |
| 497 | 495 | return 0xffff; |
| 498 | 496 | } |
| 499 | 497 | |
| 500 | 498 | WRITE16_HANDLER( x68k_gvram_w ) |
| 501 | 499 | { |
| 500 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 502 | 501 | // int xloc,yloc,pageoffset; |
| 503 | 502 | /* |
| 504 | 503 | G-VRAM usage is determined by colour depth and "real" screen size. |
| r9669 | r9670 | |
| 516 | 515 | */ |
| 517 | 516 | |
| 518 | 517 | // handle different G-VRAM page setups |
| 519 | | if(x68k_sys.crtc.reg[20] & 0x08) // G-VRAM set to buffer |
| 518 | if(state->crtc.reg[20] & 0x08) // G-VRAM set to buffer |
| 520 | 519 | { |
| 521 | 520 | if(offset < 0x40000) |
| 522 | | COMBINE_DATA(x68k_gvram+offset); |
| 521 | COMBINE_DATA(state->gvram+offset); |
| 523 | 522 | } |
| 524 | 523 | else |
| 525 | 524 | { |
| 526 | | switch(x68k_sys.crtc.reg[20] & 0x0300) |
| 525 | switch(state->crtc.reg[20] & 0x0300) |
| 527 | 526 | { |
| 528 | 527 | case 0x0300: |
| 529 | 528 | if(offset < 0x40000) |
| 530 | | COMBINE_DATA(x68k_gvram+offset); |
| 529 | COMBINE_DATA(state->gvram+offset); |
| 531 | 530 | break; |
| 532 | 531 | case 0x0100: |
| 533 | 532 | if(offset < 0x40000) |
| 534 | 533 | { |
| 535 | | x68k_gvram[offset] = (x68k_gvram[offset] & 0xff00) | (data & 0x00ff); |
| 534 | state->gvram[offset] = (state->gvram[offset] & 0xff00) | (data & 0x00ff); |
| 536 | 535 | } |
| 537 | 536 | if(offset >= 0x40000 && offset < 0x80000) |
| 538 | 537 | { |
| 539 | | x68k_gvram[offset-0x40000] = (x68k_gvram[offset-0x40000] & 0x00ff) | ((data & 0x00ff) << 8); |
| 538 | state->gvram[offset-0x40000] = (state->gvram[offset-0x40000] & 0x00ff) | ((data & 0x00ff) << 8); |
| 540 | 539 | } |
| 541 | 540 | break; |
| 542 | 541 | case 0x0000: |
| 543 | 542 | if(offset < 0x40000) |
| 544 | 543 | { |
| 545 | | x68k_gvram[offset] = (x68k_gvram[offset] & 0xfff0) | (data & 0x000f); |
| 544 | state->gvram[offset] = (state->gvram[offset] & 0xfff0) | (data & 0x000f); |
| 546 | 545 | } |
| 547 | 546 | if(offset >= 0x40000 && offset < 0x80000) |
| 548 | 547 | { |
| 549 | | x68k_gvram[offset-0x40000] = (x68k_gvram[offset-0x40000] & 0xff0f) | ((data & 0x000f) << 4); |
| 548 | state->gvram[offset-0x40000] = (state->gvram[offset-0x40000] & 0xff0f) | ((data & 0x000f) << 4); |
| 550 | 549 | } |
| 551 | 550 | if(offset >= 0x80000 && offset < 0xc0000) |
| 552 | 551 | { |
| 553 | | x68k_gvram[offset-0x80000] = (x68k_gvram[offset-0x80000] & 0xf0ff) | ((data & 0x000f) << 8); |
| 552 | state->gvram[offset-0x80000] = (state->gvram[offset-0x80000] & 0xf0ff) | ((data & 0x000f) << 8); |
| 554 | 553 | } |
| 555 | 554 | if(offset >= 0xc0000 && offset < 0x100000) |
| 556 | 555 | { |
| 557 | | x68k_gvram[offset-0xc0000] = (x68k_gvram[offset-0xc0000] & 0x0fff) | ((data & 0x000f) << 12); |
| 556 | state->gvram[offset-0xc0000] = (state->gvram[offset-0xc0000] & 0x0fff) | ((data & 0x000f) << 12); |
| 558 | 557 | } |
| 559 | 558 | break; |
| 560 | 559 | default: |
| r9669 | r9670 | |
| 565 | 564 | |
| 566 | 565 | WRITE16_HANDLER( x68k_tvram_w ) |
| 567 | 566 | { |
| 567 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 568 | 568 | UINT16 text_mask; |
| 569 | 569 | |
| 570 | | text_mask = ~(x68k_sys.crtc.reg[23]) & mem_mask; |
| 570 | text_mask = ~(state->crtc.reg[23]) & mem_mask; |
| 571 | 571 | |
| 572 | | if(!(x68k_sys.crtc.reg[21] & 0x0200)) // text access mask enable |
| 572 | if(!(state->crtc.reg[21] & 0x0200)) // text access mask enable |
| 573 | 573 | text_mask = 0xffff & mem_mask; |
| 574 | 574 | |
| 575 | 575 | mem_mask = text_mask; |
| 576 | 576 | |
| 577 | | if(x68k_sys.crtc.reg[21] & 0x0100) |
| 577 | if(state->crtc.reg[21] & 0x0100) |
| 578 | 578 | { // simultaneous T-VRAM plane access (I think ;)) |
| 579 | 579 | int plane,wr; |
| 580 | 580 | offset = offset & 0x00ffff; |
| 581 | | wr = (x68k_sys.crtc.reg[21] & 0x00f0) >> 4; |
| 581 | wr = (state->crtc.reg[21] & 0x00f0) >> 4; |
| 582 | 582 | for(plane=0;plane<4;plane++) |
| 583 | 583 | { |
| 584 | 584 | if(wr & (1 << plane)) |
| 585 | 585 | { |
| 586 | | COMBINE_DATA(x68k_tvram+offset+(0x10000*plane)); |
| 586 | COMBINE_DATA(state->tvram+offset+(0x10000*plane)); |
| 587 | 587 | } |
| 588 | 588 | } |
| 589 | 589 | } |
| 590 | 590 | else |
| 591 | 591 | { |
| 592 | | COMBINE_DATA(x68k_tvram+offset); |
| 592 | COMBINE_DATA(state->tvram+offset); |
| 593 | 593 | } |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | READ16_HANDLER( x68k_gvram_r ) |
| 597 | 597 | { |
| 598 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 598 | 599 | UINT16 ret = 0; |
| 599 | 600 | |
| 600 | | if(x68k_sys.crtc.reg[20] & 0x08) // G-VRAM set to buffer |
| 601 | | return x68k_gvram[offset]; |
| 601 | if(state->crtc.reg[20] & 0x08) // G-VRAM set to buffer |
| 602 | return state->gvram[offset]; |
| 602 | 603 | |
| 603 | | switch(x68k_sys.crtc.reg[20] & 0x0300) // colour setup determines G-VRAM use |
| 604 | switch(state->crtc.reg[20] & 0x0300) // colour setup determines G-VRAM use |
| 604 | 605 | { |
| 605 | 606 | case 0x0300: // 65,536 colour (RGB) - 16-bits per word |
| 606 | 607 | if(offset < 0x40000) |
| 607 | | ret = x68k_gvram[offset]; |
| 608 | ret = state->gvram[offset]; |
| 608 | 609 | else |
| 609 | 610 | ret = 0xffff; |
| 610 | 611 | break; |
| 611 | 612 | case 0x0100: // 256 colour (paletted) - 8 bits per word |
| 612 | 613 | if(offset < 0x40000) |
| 613 | | ret = x68k_gvram[offset] & 0x00ff; |
| 614 | ret = state->gvram[offset] & 0x00ff; |
| 614 | 615 | if(offset >= 0x40000 && offset < 0x80000) |
| 615 | | ret = (x68k_gvram[offset-0x40000] & 0xff00) >> 8; |
| 616 | ret = (state->gvram[offset-0x40000] & 0xff00) >> 8; |
| 616 | 617 | if(offset >= 0x80000) |
| 617 | 618 | ret = 0xffff; |
| 618 | 619 | break; |
| 619 | 620 | case 0x0000: // 16 colour (paletted) - 4 bits per word |
| 620 | 621 | if(offset < 0x40000) |
| 621 | | ret = x68k_gvram[offset] & 0x000f; |
| 622 | ret = state->gvram[offset] & 0x000f; |
| 622 | 623 | if(offset >= 0x40000 && offset < 0x80000) |
| 623 | | ret = (x68k_gvram[offset-0x40000] & 0x00f0) >> 4; |
| 624 | ret = (state->gvram[offset-0x40000] & 0x00f0) >> 4; |
| 624 | 625 | if(offset >= 0x80000 && offset < 0xc0000) |
| 625 | | ret = (x68k_gvram[offset-0x80000] & 0x0f00) >> 8; |
| 626 | ret = (state->gvram[offset-0x80000] & 0x0f00) >> 8; |
| 626 | 627 | if(offset >= 0xc0000 && offset < 0x100000) |
| 627 | | ret = (x68k_gvram[offset-0xc0000] & 0xf000) >> 12; |
| 628 | ret = (state->gvram[offset-0xc0000] & 0xf000) >> 12; |
| 628 | 629 | break; |
| 629 | 630 | default: |
| 630 | 631 | logerror("G-VRAM read while layer setup is undefined.\n"); |
| r9669 | r9670 | |
| 636 | 637 | |
| 637 | 638 | READ16_HANDLER( x68k_tvram_r ) |
| 638 | 639 | { |
| 639 | | return x68k_tvram[offset]; |
| 640 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 641 | return state->tvram[offset]; |
| 640 | 642 | } |
| 641 | 643 | |
| 642 | 644 | READ32_HANDLER( x68k_tvram32_r ) |
| r9669 | r9670 | |
| 689 | 691 | |
| 690 | 692 | WRITE16_HANDLER( x68k_spritereg_w ) |
| 691 | 693 | { |
| 692 | | COMBINE_DATA(x68k_spritereg+offset); |
| 694 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 695 | COMBINE_DATA(state->spritereg+offset); |
| 693 | 696 | switch(offset) |
| 694 | 697 | { |
| 695 | 698 | case 0x400: |
| 696 | | tilemap_set_scrollx(x68k_bg0_8,0,(data - x68k_sys.crtc.hbegin) & 0x3ff); |
| 697 | | tilemap_set_scrollx(x68k_bg0_16,0,(data - x68k_sys.crtc.hbegin) & 0x3ff); |
| 699 | tilemap_set_scrollx(state->bg0_8,0,(data - state->crtc.hbegin) & 0x3ff); |
| 700 | tilemap_set_scrollx(state->bg0_16,0,(data - state->crtc.hbegin) & 0x3ff); |
| 698 | 701 | break; |
| 699 | 702 | case 0x401: |
| 700 | | tilemap_set_scrolly(x68k_bg0_8,0,(data - x68k_sys.crtc.vbegin) & 0x3ff); |
| 701 | | tilemap_set_scrolly(x68k_bg0_16,0,(data - x68k_sys.crtc.vbegin) & 0x3ff); |
| 703 | tilemap_set_scrolly(state->bg0_8,0,(data - state->crtc.vbegin) & 0x3ff); |
| 704 | tilemap_set_scrolly(state->bg0_16,0,(data - state->crtc.vbegin) & 0x3ff); |
| 702 | 705 | break; |
| 703 | 706 | case 0x402: |
| 704 | | tilemap_set_scrollx(x68k_bg1_8,0,(data - x68k_sys.crtc.hbegin) & 0x3ff); |
| 705 | | tilemap_set_scrollx(x68k_bg1_16,0,(data - x68k_sys.crtc.hbegin) & 0x3ff); |
| 707 | tilemap_set_scrollx(state->bg1_8,0,(data - state->crtc.hbegin) & 0x3ff); |
| 708 | tilemap_set_scrollx(state->bg1_16,0,(data - state->crtc.hbegin) & 0x3ff); |
| 706 | 709 | break; |
| 707 | 710 | case 0x403: |
| 708 | | tilemap_set_scrolly(x68k_bg1_8,0,(data - x68k_sys.crtc.vbegin) & 0x3ff); |
| 709 | | tilemap_set_scrolly(x68k_bg1_16,0,(data - x68k_sys.crtc.vbegin) & 0x3ff); |
| 711 | tilemap_set_scrolly(state->bg1_8,0,(data - state->crtc.vbegin) & 0x3ff); |
| 712 | tilemap_set_scrolly(state->bg1_16,0,(data - state->crtc.vbegin) & 0x3ff); |
| 710 | 713 | break; |
| 711 | 714 | case 0x405: // BG H-DISP (like CRTC reg 2) |
| 712 | 715 | if(data != 0x00ff) |
| 713 | 716 | { |
| 714 | | x68k_sys.crtc.bg_visible_width = (x68k_sys.crtc.reg[3] - ((data & 0x003f) - 4)) * 8; |
| 715 | | x68k_sys.crtc.bg_hshift = (x68k_sys.crtc.width - x68k_sys.crtc.bg_visible_width) / 2; |
| 717 | state->crtc.bg_visible_width = (state->crtc.reg[3] - ((data & 0x003f) - 4)) * 8; |
| 718 | state->crtc.bg_hshift = (state->crtc.width - state->crtc.bg_visible_width) / 2; |
| 716 | 719 | } |
| 717 | 720 | else |
| 718 | | x68k_sys.crtc.bg_hshift = x68k_sys.crtc.hshift; |
| 721 | state->crtc.bg_hshift = state->crtc.hshift; |
| 719 | 722 | break; |
| 720 | 723 | case 0x406: // BG V-DISP (like CRTC reg 6) |
| 721 | | x68k_sys.crtc.bg_vshift = x68k_sys.crtc.vshift; |
| 724 | state->crtc.bg_vshift = state->crtc.vshift; |
| 722 | 725 | break; |
| 723 | 726 | } |
| 724 | 727 | } |
| 725 | 728 | |
| 726 | 729 | READ16_HANDLER( x68k_spritereg_r ) |
| 727 | 730 | { |
| 731 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 728 | 732 | if(offset >= 0x400 && offset < 0x404) |
| 729 | | return x68k_spritereg[offset] & 0x3ff; |
| 730 | | return x68k_spritereg[offset]; |
| 733 | return state->spritereg[offset] & 0x3ff; |
| 734 | return state->spritereg[offset]; |
| 731 | 735 | } |
| 732 | 736 | |
| 733 | 737 | WRITE16_HANDLER( x68k_spriteram_w ) |
| 734 | 738 | { |
| 735 | | COMBINE_DATA(x68k_spriteram+offset); |
| 736 | | x68k_sys.video.tile8_dirty[offset / 16] = 1; |
| 737 | | x68k_sys.video.tile16_dirty[offset / 64] = 1; |
| 739 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 740 | COMBINE_DATA(state->spriteram+offset); |
| 741 | state->video.tile8_dirty[offset / 16] = 1; |
| 742 | state->video.tile16_dirty[offset / 64] = 1; |
| 738 | 743 | if(offset < 0x2000) |
| 739 | 744 | { |
| 740 | | tilemap_mark_all_tiles_dirty(x68k_bg1_8); |
| 741 | | tilemap_mark_all_tiles_dirty(x68k_bg1_16); |
| 742 | | tilemap_mark_all_tiles_dirty(x68k_bg0_8); |
| 743 | | tilemap_mark_all_tiles_dirty(x68k_bg0_16); |
| 745 | tilemap_mark_all_tiles_dirty(state->bg1_8); |
| 746 | tilemap_mark_all_tiles_dirty(state->bg1_16); |
| 747 | tilemap_mark_all_tiles_dirty(state->bg0_8); |
| 748 | tilemap_mark_all_tiles_dirty(state->bg0_16); |
| 744 | 749 | } |
| 745 | 750 | if(offset >= 0x2000 && offset < 0x3000) |
| 746 | 751 | { |
| 747 | | tilemap_mark_tile_dirty(x68k_bg1_8,offset & 0x0fff); |
| 748 | | tilemap_mark_tile_dirty(x68k_bg1_16,offset & 0x0fff); |
| 752 | tilemap_mark_tile_dirty(state->bg1_8,offset & 0x0fff); |
| 753 | tilemap_mark_tile_dirty(state->bg1_16,offset & 0x0fff); |
| 749 | 754 | } |
| 750 | 755 | if(offset >= 0x3000) |
| 751 | 756 | { |
| 752 | | tilemap_mark_tile_dirty(x68k_bg0_8,offset & 0x0fff); |
| 753 | | tilemap_mark_tile_dirty(x68k_bg0_16,offset & 0x0fff); |
| 757 | tilemap_mark_tile_dirty(state->bg0_8,offset & 0x0fff); |
| 758 | tilemap_mark_tile_dirty(state->bg0_16,offset & 0x0fff); |
| 754 | 759 | } |
| 755 | 760 | } |
| 756 | 761 | |
| 757 | 762 | READ16_HANDLER( x68k_spriteram_r ) |
| 758 | 763 | { |
| 759 | | return x68k_spriteram[offset]; |
| 764 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 765 | return state->spriteram[offset]; |
| 760 | 766 | } |
| 761 | 767 | |
| 762 | 768 | static void x68k_draw_text(running_machine* machine,bitmap_t* bitmap, int xscr, int yscr, rectangle rect) |
| 763 | 769 | { |
| 770 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 764 | 771 | unsigned int line,pixel; // location on screen |
| 765 | 772 | UINT32 loc; // location in TVRAM |
| 766 | 773 | UINT32 colour; |
| r9669 | r9670 | |
| 769 | 776 | for(line=rect.min_y;line<=rect.max_y;line++) // per scanline |
| 770 | 777 | { |
| 771 | 778 | // adjust for scroll registers |
| 772 | | loc = (((line - x68k_sys.crtc.vbegin) + yscr) & 0x3ff) * 64; |
| 779 | loc = (((line - state->crtc.vbegin) + yscr) & 0x3ff) * 64; |
| 773 | 780 | loc += (xscr / 16) & 0x7f; |
| 774 | 781 | loc &= 0xffff; |
| 775 | 782 | bit = 15 - (xscr & 0x0f); |
| 776 | 783 | for(pixel=rect.min_x;pixel<=rect.max_x;pixel++) // per pixel |
| 777 | 784 | { |
| 778 | | colour = (((x68k_tvram[loc] >> bit) & 0x01) ? 1 : 0) |
| 779 | | + (((x68k_tvram[loc+0x10000] >> bit) & 0x01) ? 2 : 0) |
| 780 | | + (((x68k_tvram[loc+0x20000] >> bit) & 0x01) ? 4 : 0) |
| 781 | | + (((x68k_tvram[loc+0x30000] >> bit) & 0x01) ? 8 : 0); |
| 782 | | if(x68k_sys.video.text_pal[colour] != 0x0000) // any colour but black |
| 785 | colour = (((state->tvram[loc] >> bit) & 0x01) ? 1 : 0) |
| 786 | + (((state->tvram[loc+0x10000] >> bit) & 0x01) ? 2 : 0) |
| 787 | + (((state->tvram[loc+0x20000] >> bit) & 0x01) ? 4 : 0) |
| 788 | + (((state->tvram[loc+0x30000] >> bit) & 0x01) ? 8 : 0); |
| 789 | if(state->video.text_pal[colour] != 0x0000) // any colour but black |
| 783 | 790 | { |
| 784 | 791 | // Colour 0 is displayable if the text layer is at the priority level 2 |
| 785 | | if(colour == 0 && (x68k_sys.video.reg[1] & 0x0c00) == 0x0800) |
| 786 | | *BITMAP_ADDR16(bitmap,line,pixel) = 512 + (x68k_sys.video.text_pal[colour] >> 1); |
| 792 | if(colour == 0 && (state->video.reg[1] & 0x0c00) == 0x0800) |
| 793 | *BITMAP_ADDR16(bitmap,line,pixel) = 512 + (state->video.text_pal[colour] >> 1); |
| 787 | 794 | else |
| 788 | 795 | if(colour != 0) |
| 789 | | *BITMAP_ADDR16(bitmap,line,pixel) = 512 + (x68k_sys.video.text_pal[colour] >> 1); |
| 796 | *BITMAP_ADDR16(bitmap,line,pixel) = 512 + (state->video.text_pal[colour] >> 1); |
| 790 | 797 | } |
| 791 | 798 | bit--; |
| 792 | 799 | if(bit < 0) |
| r9669 | r9670 | |
| 799 | 806 | } |
| 800 | 807 | } |
| 801 | 808 | |
| 802 | | static void x68k_draw_gfx_scanline(bitmap_t* bitmap, rectangle cliprect, UINT8 priority) |
| 809 | static void x68k_draw_gfx_scanline(running_machine *machine, bitmap_t* bitmap, rectangle cliprect, UINT8 priority) |
| 803 | 810 | { |
| 811 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 804 | 812 | int pixel; |
| 805 | 813 | int page; |
| 806 | 814 | UINT32 loc; // location in GVRAM |
| r9669 | r9670 | |
| 812 | 820 | |
| 813 | 821 | for(scanline=cliprect.min_y;scanline<=cliprect.max_y;scanline++) // per scanline |
| 814 | 822 | { |
| 815 | | if(x68k_sys.crtc.reg[20] & 0x0400) // 1024x1024 "real" screen size - use 1024x1024 16-colour gfx layer |
| 823 | if(state->crtc.reg[20] & 0x0400) // 1024x1024 "real" screen size - use 1024x1024 16-colour gfx layer |
| 816 | 824 | { |
| 817 | 825 | // adjust for scroll registers |
| 818 | | if(x68k_sys.video.reg[2] & 0x0010 && priority == x68k_sys.video.gfxlayer_pri[0]) |
| 826 | if(state->video.reg[2] & 0x0010 && priority == state->video.gfxlayer_pri[0]) |
| 819 | 827 | { |
| 820 | | xscr = (x68k_sys.crtc.reg[12] & 0x3ff); |
| 821 | | yscr = (x68k_sys.crtc.reg[13] & 0x3ff); |
| 822 | | lineoffset = (((scanline - x68k_sys.crtc.vbegin) + yscr) & 0x3ff) * 1024; |
| 828 | xscr = (state->crtc.reg[12] & 0x3ff); |
| 829 | yscr = (state->crtc.reg[13] & 0x3ff); |
| 830 | lineoffset = (((scanline - state->crtc.vbegin) + yscr) & 0x3ff) * 1024; |
| 823 | 831 | loc = xscr & 0x3ff; |
| 824 | | for(pixel=x68k_sys.crtc.hbegin;pixel<=x68k_sys.crtc.hend;pixel++) |
| 832 | for(pixel=state->crtc.hbegin;pixel<=state->crtc.hend;pixel++) |
| 825 | 833 | { |
| 826 | 834 | switch(lineoffset & 0xc0000) |
| 827 | 835 | { |
| 828 | 836 | case 0x00000: |
| 829 | | colour = x68k_gvram[lineoffset + (loc & 0x3ff)] & 0x000f; |
| 837 | colour = state->gvram[lineoffset + (loc & 0x3ff)] & 0x000f; |
| 830 | 838 | break; |
| 831 | 839 | case 0x40000: |
| 832 | | colour = (x68k_gvram[(lineoffset - 0x40000) + (loc & 0x3ff)] & 0x00f0) >> 4; |
| 840 | colour = (state->gvram[(lineoffset - 0x40000) + (loc & 0x3ff)] & 0x00f0) >> 4; |
| 833 | 841 | break; |
| 834 | 842 | case 0x80000: |
| 835 | | colour = (x68k_gvram[(lineoffset - 0x80000) + (loc & 0x3ff)] & 0x0f00) >> 8; |
| 843 | colour = (state->gvram[(lineoffset - 0x80000) + (loc & 0x3ff)] & 0x0f00) >> 8; |
| 836 | 844 | break; |
| 837 | 845 | case 0xc0000: |
| 838 | | colour = (x68k_gvram[(lineoffset - 0xc0000) + (loc & 0x3ff)] & 0xf000) >> 12; |
| 846 | colour = (state->gvram[(lineoffset - 0xc0000) + (loc & 0x3ff)] & 0xf000) >> 12; |
| 839 | 847 | break; |
| 840 | 848 | } |
| 841 | 849 | if(colour != 0) |
| 842 | | *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (x68k_sys.video.gfx_pal[colour] >> 1); |
| 850 | *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (state->video.gfx_pal[colour] >> 1); |
| 843 | 851 | loc++; |
| 844 | 852 | loc &= 0x3ff; |
| 845 | 853 | } |
| r9669 | r9670 | |
| 847 | 855 | } |
| 848 | 856 | else // else 512x512 "real" screen size |
| 849 | 857 | { |
| 850 | | if(x68k_sys.video.reg[2] & (1 << priority)) |
| 858 | if(state->video.reg[2] & (1 << priority)) |
| 851 | 859 | { |
| 852 | | page = x68k_sys.video.gfxlayer_pri[priority]; |
| 860 | page = state->video.gfxlayer_pri[priority]; |
| 853 | 861 | // adjust for scroll registers |
| 854 | | switch(x68k_sys.video.reg[0] & 0x03) |
| 862 | switch(state->video.reg[0] & 0x03) |
| 855 | 863 | { |
| 856 | 864 | case 0x00: // 16 colours |
| 857 | | xscr = ((x68k_sys.crtc.reg[12+(page*2)])) & 0x1ff; |
| 858 | | yscr = ((x68k_sys.crtc.reg[13+(page*2)])) & 0x1ff; |
| 859 | | lineoffset = (((scanline - x68k_sys.crtc.vbegin) + yscr) & 0x1ff) * 512; |
| 865 | xscr = ((state->crtc.reg[12+(page*2)])) & 0x1ff; |
| 866 | yscr = ((state->crtc.reg[13+(page*2)])) & 0x1ff; |
| 867 | lineoffset = (((scanline - state->crtc.vbegin) + yscr) & 0x1ff) * 512; |
| 860 | 868 | loc = xscr & 0x1ff; |
| 861 | 869 | shift = 4; |
| 862 | | for(pixel=x68k_sys.crtc.hbegin;pixel<=x68k_sys.crtc.hend;pixel++) |
| 870 | for(pixel=state->crtc.hbegin;pixel<=state->crtc.hend;pixel++) |
| 863 | 871 | { |
| 864 | | colour = ((x68k_gvram[lineoffset + loc] >> page*shift) & 0x000f); |
| 872 | colour = ((state->gvram[lineoffset + loc] >> page*shift) & 0x000f); |
| 865 | 873 | if(colour != 0) |
| 866 | | *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (x68k_sys.video.gfx_pal[colour & 0x0f] >> 1); |
| 874 | *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (state->video.gfx_pal[colour & 0x0f] >> 1); |
| 867 | 875 | loc++; |
| 868 | 876 | loc &= 0x1ff; |
| 869 | 877 | } |
| r9669 | r9670 | |
| 871 | 879 | case 0x01: // 256 colours |
| 872 | 880 | if(page == 0 || page == 2) |
| 873 | 881 | { |
| 874 | | xscr = ((x68k_sys.crtc.reg[12+(page*2)])) & 0x1ff; |
| 875 | | yscr = ((x68k_sys.crtc.reg[13+(page*2)])) & 0x1ff; |
| 876 | | lineoffset = (((scanline - x68k_sys.crtc.vbegin) + yscr) & 0x1ff) * 512; |
| 882 | xscr = ((state->crtc.reg[12+(page*2)])) & 0x1ff; |
| 883 | yscr = ((state->crtc.reg[13+(page*2)])) & 0x1ff; |
| 884 | lineoffset = (((scanline - state->crtc.vbegin) + yscr) & 0x1ff) * 512; |
| 877 | 885 | loc = xscr & 0x1ff; |
| 878 | 886 | shift = 4; |
| 879 | | for(pixel=x68k_sys.crtc.hbegin;pixel<=x68k_sys.crtc.hend;pixel++) |
| 887 | for(pixel=state->crtc.hbegin;pixel<=state->crtc.hend;pixel++) |
| 880 | 888 | { |
| 881 | | colour = ((x68k_gvram[lineoffset + loc] >> page*shift) & 0x00ff); |
| 889 | colour = ((state->gvram[lineoffset + loc] >> page*shift) & 0x00ff); |
| 882 | 890 | if(colour != 0) |
| 883 | | *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (x68k_sys.video.gfx_pal[colour & 0xff] >> 1); |
| 891 | *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (state->video.gfx_pal[colour & 0xff] >> 1); |
| 884 | 892 | loc++; |
| 885 | 893 | loc &= 0x1ff; |
| 886 | 894 | } |
| 887 | 895 | } |
| 888 | 896 | break; |
| 889 | 897 | case 0x03: // 65536 colours |
| 890 | | xscr = ((x68k_sys.crtc.reg[12])) & 0x1ff; |
| 891 | | yscr = ((x68k_sys.crtc.reg[13])) & 0x1ff; |
| 892 | | lineoffset = (((scanline - x68k_sys.crtc.vbegin) + yscr) & 0x1ff) * 512; |
| 898 | xscr = ((state->crtc.reg[12])) & 0x1ff; |
| 899 | yscr = ((state->crtc.reg[13])) & 0x1ff; |
| 900 | lineoffset = (((scanline - state->crtc.vbegin) + yscr) & 0x1ff) * 512; |
| 893 | 901 | loc = xscr & 0x1ff; |
| 894 | | for(pixel=x68k_sys.crtc.hbegin;pixel<=x68k_sys.crtc.hend;pixel++) |
| 902 | for(pixel=state->crtc.hbegin;pixel<=state->crtc.hend;pixel++) |
| 895 | 903 | { |
| 896 | | colour = x68k_gvram[lineoffset + loc]; |
| 904 | colour = state->gvram[lineoffset + loc]; |
| 897 | 905 | if(colour != 0) |
| 898 | 906 | *BITMAP_ADDR16(bitmap,scanline,pixel) = 512 + (colour >> 1); |
| 899 | 907 | loc++; |
| r9669 | r9670 | |
| 906 | 914 | } |
| 907 | 915 | } |
| 908 | 916 | |
| 909 | | static void x68k_draw_gfx(bitmap_t* bitmap,rectangle cliprect) |
| 917 | static void x68k_draw_gfx(running_machine *machine, bitmap_t* bitmap,rectangle cliprect) |
| 910 | 918 | { |
| 919 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 911 | 920 | int priority; |
| 912 | 921 | //rectangle rect; |
| 913 | 922 | //int xscr,yscr; |
| 914 | 923 | //int gpage; |
| 915 | 924 | |
| 916 | | if(x68k_sys.crtc.reg[20] & 0x0800) // if graphic layers are set to buffer, then they aren't visible |
| 925 | if(state->crtc.reg[20] & 0x0800) // if graphic layers are set to buffer, then they aren't visible |
| 917 | 926 | return; |
| 918 | 927 | |
| 919 | 928 | for(priority=3;priority>=0;priority--) |
| 920 | 929 | { |
| 921 | | x68k_draw_gfx_scanline(bitmap,cliprect,priority); |
| 930 | x68k_draw_gfx_scanline(machine, bitmap,cliprect,priority); |
| 922 | 931 | } |
| 923 | 932 | } |
| 924 | 933 | |
| 925 | 934 | // Sprite controller "Cynthia" at 0xeb0000 |
| 926 | 935 | static void x68k_draw_sprites(running_machine *machine, bitmap_t* bitmap, int priority, rectangle cliprect) |
| 927 | 936 | { |
| 937 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 928 | 938 | /* |
| 929 | 939 | 0xeb0000 - 0xeb07ff - Sprite registers (up to 128) |
| 930 | 940 | + 00 : b9-0, Sprite X position |
| r9669 | r9670 | |
| 958 | 968 | |
| 959 | 969 | for(ptr=508;ptr>=0;ptr-=4) // stepping through sprites |
| 960 | 970 | { |
| 961 | | pri = x68k_spritereg[ptr+3] & 0x03; |
| 971 | pri = state->spritereg[ptr+3] & 0x03; |
| 962 | 972 | #ifdef MAME_DEBUG |
| 963 | 973 | if(!(input_code_pressed(machine,KEYCODE_I))) |
| 964 | 974 | #endif |
| 965 | 975 | if(pri == priority) |
| 966 | 976 | { // if at the right priority level, draw the sprite |
| 967 | 977 | rectangle rect; |
| 968 | | int code = x68k_spritereg[ptr+2] & 0x00ff; |
| 969 | | int colour = (x68k_spritereg[ptr+2] & 0x0f00) >> 8; |
| 970 | | int xflip = x68k_spritereg[ptr+2] & 0x4000; |
| 971 | | int yflip = x68k_spritereg[ptr+2] & 0x8000; |
| 972 | | int sx = (x68k_spritereg[ptr+0] & 0x3ff) - 16; |
| 973 | | int sy = (x68k_spritereg[ptr+1] & 0x3ff) - 16; |
| 978 | int code = state->spritereg[ptr+2] & 0x00ff; |
| 979 | int colour = (state->spritereg[ptr+2] & 0x0f00) >> 8; |
| 980 | int xflip = state->spritereg[ptr+2] & 0x4000; |
| 981 | int yflip = state->spritereg[ptr+2] & 0x8000; |
| 982 | int sx = (state->spritereg[ptr+0] & 0x3ff) - 16; |
| 983 | int sy = (state->spritereg[ptr+1] & 0x3ff) - 16; |
| 974 | 984 | |
| 975 | | rect.min_x=x68k_sys.crtc.hshift; |
| 976 | | rect.min_y=x68k_sys.crtc.vshift; |
| 977 | | rect.max_x=rect.min_x + x68k_sys.crtc.visible_width-1; |
| 978 | | rect.max_y=rect.min_y + x68k_sys.crtc.visible_height-1; |
| 985 | rect.min_x=state->crtc.hshift; |
| 986 | rect.min_y=state->crtc.vshift; |
| 987 | rect.max_x=rect.min_x + state->crtc.visible_width-1; |
| 988 | rect.max_y=rect.min_y + state->crtc.visible_height-1; |
| 979 | 989 | |
| 980 | | sx += sprite_shift; |
| 990 | sx += state->sprite_shift; |
| 981 | 991 | |
| 982 | | if(x68k_sys.crtc.interlace != 0) |
| 983 | | drawgfxzoom_transpen(bitmap,&cliprect,machine->gfx[1],code,colour+0x10,xflip,yflip,x68k_sys.crtc.hbegin+sx,x68k_sys.crtc.vbegin+(sy*2),0x10000,0x20000,0x00); |
| 992 | if(state->crtc.interlace != 0) |
| 993 | drawgfxzoom_transpen(bitmap,&cliprect,machine->gfx[1],code,colour+0x10,xflip,yflip,state->crtc.hbegin+sx,state->crtc.vbegin+(sy*2),0x10000,0x20000,0x00); |
| 984 | 994 | else |
| 985 | | drawgfx_transpen(bitmap,&cliprect,machine->gfx[1],code,colour+0x10,xflip,yflip,x68k_sys.crtc.hbegin+sx,x68k_sys.crtc.vbegin+sy,0x00); |
| 995 | drawgfx_transpen(bitmap,&cliprect,machine->gfx[1],code,colour+0x10,xflip,yflip,state->crtc.hbegin+sx,state->crtc.vbegin+sy,0x00); |
| 986 | 996 | } |
| 987 | 997 | } |
| 988 | 998 | } |
| r9669 | r9670 | |
| 1033 | 1043 | |
| 1034 | 1044 | static TILE_GET_INFO(x68k_get_bg0_tile) |
| 1035 | 1045 | { |
| 1036 | | int code = x68k_spriteram[0x3000+tile_index] & 0x00ff; |
| 1037 | | int colour = (x68k_spriteram[0x3000+tile_index] & 0x0f00) >> 8; |
| 1038 | | int flags = (x68k_spriteram[0x3000+tile_index] & 0xc000) >> 14; |
| 1046 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 1047 | int code = state->spriteram[0x3000+tile_index] & 0x00ff; |
| 1048 | int colour = (state->spriteram[0x3000+tile_index] & 0x0f00) >> 8; |
| 1049 | int flags = (state->spriteram[0x3000+tile_index] & 0xc000) >> 14; |
| 1039 | 1050 | SET_TILE_INFO(0,code,colour+16,flags); |
| 1040 | 1051 | } |
| 1041 | 1052 | |
| 1042 | 1053 | static TILE_GET_INFO(x68k_get_bg1_tile) |
| 1043 | 1054 | { |
| 1044 | | int code = x68k_spriteram[0x2000+tile_index] & 0x00ff; |
| 1045 | | int colour = (x68k_spriteram[0x2000+tile_index] & 0x0f00) >> 8; |
| 1046 | | int flags = (x68k_spriteram[0x2000+tile_index] & 0xc000) >> 14; |
| 1055 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 1056 | int code = state->spriteram[0x2000+tile_index] & 0x00ff; |
| 1057 | int colour = (state->spriteram[0x2000+tile_index] & 0x0f00) >> 8; |
| 1058 | int flags = (state->spriteram[0x2000+tile_index] & 0xc000) >> 14; |
| 1047 | 1059 | SET_TILE_INFO(0,code,colour+16,flags); |
| 1048 | 1060 | } |
| 1049 | 1061 | |
| 1050 | 1062 | static TILE_GET_INFO(x68k_get_bg0_tile_16) |
| 1051 | 1063 | { |
| 1052 | | int code = x68k_spriteram[0x3000+tile_index] & 0x00ff; |
| 1053 | | int colour = (x68k_spriteram[0x3000+tile_index] & 0x0f00) >> 8; |
| 1054 | | int flags = (x68k_spriteram[0x3000+tile_index] & 0xc000) >> 14; |
| 1064 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 1065 | int code = state->spriteram[0x3000+tile_index] & 0x00ff; |
| 1066 | int colour = (state->spriteram[0x3000+tile_index] & 0x0f00) >> 8; |
| 1067 | int flags = (state->spriteram[0x3000+tile_index] & 0xc000) >> 14; |
| 1055 | 1068 | SET_TILE_INFO(1,code,colour+16,flags); |
| 1056 | 1069 | } |
| 1057 | 1070 | |
| 1058 | 1071 | static TILE_GET_INFO(x68k_get_bg1_tile_16) |
| 1059 | 1072 | { |
| 1060 | | int code = x68k_spriteram[0x2000+tile_index] & 0x00ff; |
| 1061 | | int colour = (x68k_spriteram[0x2000+tile_index] & 0x0f00) >> 8; |
| 1062 | | int flags = (x68k_spriteram[0x2000+tile_index] & 0xc000) >> 14; |
| 1073 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 1074 | int code = state->spriteram[0x2000+tile_index] & 0x00ff; |
| 1075 | int colour = (state->spriteram[0x2000+tile_index] & 0x0f00) >> 8; |
| 1076 | int flags = (state->spriteram[0x2000+tile_index] & 0xc000) >> 14; |
| 1063 | 1077 | SET_TILE_INFO(1,code,colour+16,flags); |
| 1064 | 1078 | } |
| 1065 | 1079 | |
| 1066 | 1080 | VIDEO_START( x68000 ) |
| 1067 | 1081 | { |
| 1082 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 1068 | 1083 | int gfx_index; |
| 1069 | 1084 | |
| 1070 | 1085 | for (gfx_index = 0; gfx_index < MAX_GFX_ELEMENTS; gfx_index++) |
| r9669 | r9670 | |
| 1080 | 1095 | machine->gfx[gfx_index]->total_colors = 32; |
| 1081 | 1096 | |
| 1082 | 1097 | /* Tilemaps */ |
| 1083 | | x68k_bg0_8 = tilemap_create(machine, x68k_get_bg0_tile,tilemap_scan_rows,8,8,64,64); |
| 1084 | | x68k_bg1_8 = tilemap_create(machine, x68k_get_bg1_tile,tilemap_scan_rows,8,8,64,64); |
| 1085 | | x68k_bg0_16 = tilemap_create(machine, x68k_get_bg0_tile_16,tilemap_scan_rows,16,16,64,64); |
| 1086 | | x68k_bg1_16 = tilemap_create(machine, x68k_get_bg1_tile_16,tilemap_scan_rows,16,16,64,64); |
| 1098 | state->bg0_8 = tilemap_create(machine, x68k_get_bg0_tile,tilemap_scan_rows,8,8,64,64); |
| 1099 | state->bg1_8 = tilemap_create(machine, x68k_get_bg1_tile,tilemap_scan_rows,8,8,64,64); |
| 1100 | state->bg0_16 = tilemap_create(machine, x68k_get_bg0_tile_16,tilemap_scan_rows,16,16,64,64); |
| 1101 | state->bg1_16 = tilemap_create(machine, x68k_get_bg1_tile_16,tilemap_scan_rows,16,16,64,64); |
| 1087 | 1102 | |
| 1088 | | tilemap_set_transparent_pen(x68k_bg0_8,0); |
| 1089 | | tilemap_set_transparent_pen(x68k_bg1_8,0); |
| 1090 | | tilemap_set_transparent_pen(x68k_bg0_16,0); |
| 1091 | | tilemap_set_transparent_pen(x68k_bg1_16,0); |
| 1103 | tilemap_set_transparent_pen(state->bg0_8,0); |
| 1104 | tilemap_set_transparent_pen(state->bg1_8,0); |
| 1105 | tilemap_set_transparent_pen(state->bg0_16,0); |
| 1106 | tilemap_set_transparent_pen(state->bg1_16,0); |
| 1092 | 1107 | |
| 1093 | | // timer_adjust_periodic(x68k_scanline_timer, attotime_zero, 0, ATTOTIME_IN_HZ(55.45)/568); |
| 1108 | // timer_adjust_periodic(state->scanline_timer, attotime_zero, 0, ATTOTIME_IN_HZ(55.45)/568); |
| 1094 | 1109 | } |
| 1095 | 1110 | |
| 1096 | 1111 | VIDEO_UPDATE( x68000 ) |
| 1097 | 1112 | { |
| 1113 | x68k_state *state = screen->machine->driver_data<x68k_state>(); |
| 1098 | 1114 | rectangle rect = {0,0,0,0}; |
| 1099 | 1115 | int priority; |
| 1100 | 1116 | int xscr,yscr; |
| r9669 | r9670 | |
| 1103 | 1119 | tilemap_t* x68k_bg1; |
| 1104 | 1120 | //UINT8 *rom; |
| 1105 | 1121 | |
| 1106 | | if((x68k_spritereg[0x408] & 0x03) == 0x00) // Sprite/BG H-Res 0=8x8, 1=16x16, 2 or 3 = undefined. |
| 1122 | if((state->spritereg[0x408] & 0x03) == 0x00) // Sprite/BG H-Res 0=8x8, 1=16x16, 2 or 3 = undefined. |
| 1107 | 1123 | { |
| 1108 | | x68k_bg0 = x68k_bg0_8; |
| 1109 | | x68k_bg1 = x68k_bg1_8; |
| 1124 | x68k_bg0 = state->bg0_8; |
| 1125 | x68k_bg1 = state->bg1_8; |
| 1110 | 1126 | } |
| 1111 | 1127 | else |
| 1112 | 1128 | { |
| 1113 | | x68k_bg0 = x68k_bg0_16; |
| 1114 | | x68k_bg1 = x68k_bg1_16; |
| 1129 | x68k_bg0 = state->bg0_16; |
| 1130 | x68k_bg1 = state->bg1_16; |
| 1115 | 1131 | } |
| 1116 | | // rect.max_x=x68k_sys.crtc.width; |
| 1117 | | // rect.max_y=x68k_sys.crtc.height; |
| 1132 | // rect.max_x=state->crtc.width; |
| 1133 | // rect.max_y=state->crtc.height; |
| 1118 | 1134 | bitmap_fill(bitmap,cliprect,0); |
| 1119 | 1135 | |
| 1120 | | if(x68k_sys.sysport.contrast == 0) // if monitor contrast is 0, then don't bother displaying anything |
| 1136 | if(state->sysport.contrast == 0) // if monitor contrast is 0, then don't bother displaying anything |
| 1121 | 1137 | return 0; |
| 1122 | 1138 | |
| 1123 | | rect.min_x=x68k_sys.crtc.hbegin; |
| 1124 | | rect.min_y=x68k_sys.crtc.vbegin; |
| 1125 | | // rect.max_x=rect.min_x + x68k_sys.crtc.visible_width-1; |
| 1126 | | // rect.max_y=rect.min_y + x68k_sys.crtc.visible_height-1; |
| 1127 | | rect.max_x=x68k_sys.crtc.hend; |
| 1128 | | rect.max_y=x68k_sys.crtc.vend; |
| 1139 | rect.min_x=state->crtc.hbegin; |
| 1140 | rect.min_y=state->crtc.vbegin; |
| 1141 | // rect.max_x=rect.min_x + state->crtc.visible_width-1; |
| 1142 | // rect.max_y=rect.min_y + state->crtc.visible_height-1; |
| 1143 | rect.max_x=state->crtc.hend; |
| 1144 | rect.max_y=state->crtc.vend; |
| 1129 | 1145 | |
| 1130 | 1146 | if(rect.min_y < cliprect->min_y) |
| 1131 | 1147 | rect.min_y = cliprect->min_y; |
| r9669 | r9670 | |
| 1136 | 1152 | //rom = memory_region(screen->machine, "user1"); |
| 1137 | 1153 | for(x=0;x<256;x++) |
| 1138 | 1154 | { |
| 1139 | | if(x68k_sys.video.tile16_dirty[x] != 0) |
| 1155 | if(state->video.tile16_dirty[x] != 0) |
| 1140 | 1156 | { |
| 1141 | 1157 | gfx_element_mark_dirty(screen->machine->gfx[1], x); |
| 1142 | | x68k_sys.video.tile16_dirty[x] = 0; |
| 1158 | state->video.tile16_dirty[x] = 0; |
| 1143 | 1159 | } |
| 1144 | | if(x68k_sys.video.tile8_dirty[x] != 0) |
| 1160 | if(state->video.tile8_dirty[x] != 0) |
| 1145 | 1161 | { |
| 1146 | 1162 | gfx_element_mark_dirty(screen->machine->gfx[0], x); |
| 1147 | | x68k_sys.video.tile8_dirty[x] = 0; |
| 1163 | state->video.tile8_dirty[x] = 0; |
| 1148 | 1164 | } |
| 1149 | 1165 | } |
| 1150 | 1166 | |
| 1151 | 1167 | for(priority=3;priority>=0;priority--) |
| 1152 | 1168 | { |
| 1153 | 1169 | // Graphics screen(s) |
| 1154 | | if(priority == x68k_sys.video.gfx_pri) |
| 1155 | | x68k_draw_gfx(bitmap,rect); |
| 1170 | if(priority == state->video.gfx_pri) |
| 1171 | x68k_draw_gfx(screen->machine,bitmap,rect); |
| 1156 | 1172 | |
| 1157 | 1173 | // Sprite / BG Tiles |
| 1158 | | if(priority == x68k_sys.video.sprite_pri /*&& (x68k_spritereg[0x404] & 0x0200)*/ && (x68k_sys.video.reg[2] & 0x0040)) |
| 1174 | if(priority == state->video.sprite_pri /*&& (state->spritereg[0x404] & 0x0200)*/ && (state->video.reg[2] & 0x0040)) |
| 1159 | 1175 | { |
| 1160 | 1176 | x68k_draw_sprites(screen->machine, bitmap,1,rect); |
| 1161 | | if((x68k_spritereg[0x404] & 0x0008)) |
| 1177 | if((state->spritereg[0x404] & 0x0008)) |
| 1162 | 1178 | { |
| 1163 | | if((x68k_spritereg[0x404] & 0x0030) == 0x10) // BG1 TXSEL |
| 1179 | if((state->spritereg[0x404] & 0x0030) == 0x10) // BG1 TXSEL |
| 1164 | 1180 | { |
| 1165 | | tilemap_set_scrollx(x68k_bg0,0,(x68k_spritereg[0x402] - x68k_sys.crtc.hbegin) & 0x3ff); |
| 1166 | | tilemap_set_scrolly(x68k_bg0,0,(x68k_spritereg[0x403] - x68k_sys.crtc.vbegin) & 0x3ff); |
| 1181 | tilemap_set_scrollx(x68k_bg0,0,(state->spritereg[0x402] - state->crtc.hbegin) & 0x3ff); |
| 1182 | tilemap_set_scrolly(x68k_bg0,0,(state->spritereg[0x403] - state->crtc.vbegin) & 0x3ff); |
| 1167 | 1183 | tilemap_draw(bitmap,&rect,x68k_bg0,0,0); |
| 1168 | 1184 | } |
| 1169 | 1185 | else |
| 1170 | 1186 | { |
| 1171 | | tilemap_set_scrollx(x68k_bg1,0,(x68k_spritereg[0x402] - x68k_sys.crtc.hbegin) & 0x3ff); |
| 1172 | | tilemap_set_scrolly(x68k_bg1,0,(x68k_spritereg[0x403] - x68k_sys.crtc.vbegin) & 0x3ff); |
| 1187 | tilemap_set_scrollx(x68k_bg1,0,(state->spritereg[0x402] - state->crtc.hbegin) & 0x3ff); |
| 1188 | tilemap_set_scrolly(x68k_bg1,0,(state->spritereg[0x403] - state->crtc.vbegin) & 0x3ff); |
| 1173 | 1189 | tilemap_draw(bitmap,&rect,x68k_bg1,0,0); |
| 1174 | 1190 | } |
| 1175 | 1191 | } |
| 1176 | 1192 | x68k_draw_sprites(screen->machine,bitmap,2,rect); |
| 1177 | | if((x68k_spritereg[0x404] & 0x0001)) |
| 1193 | if((state->spritereg[0x404] & 0x0001)) |
| 1178 | 1194 | { |
| 1179 | | if((x68k_spritereg[0x404] & 0x0006) == 0x02) // BG0 TXSEL |
| 1195 | if((state->spritereg[0x404] & 0x0006) == 0x02) // BG0 TXSEL |
| 1180 | 1196 | { |
| 1181 | | tilemap_set_scrollx(x68k_bg0,0,(x68k_spritereg[0x400] - x68k_sys.crtc.hbegin) & 0x3ff); |
| 1182 | | tilemap_set_scrolly(x68k_bg0,0,(x68k_spritereg[0x401] - x68k_sys.crtc.vbegin) & 0x3ff); |
| 1197 | tilemap_set_scrollx(x68k_bg0,0,(state->spritereg[0x400] - state->crtc.hbegin) & 0x3ff); |
| 1198 | tilemap_set_scrolly(x68k_bg0,0,(state->spritereg[0x401] - state->crtc.vbegin) & 0x3ff); |
| 1183 | 1199 | tilemap_draw(bitmap,&rect,x68k_bg0,0,0); |
| 1184 | 1200 | } |
| 1185 | 1201 | else |
| 1186 | 1202 | { |
| 1187 | | tilemap_set_scrollx(x68k_bg1,0,(x68k_spritereg[0x400] - x68k_sys.crtc.hbegin) & 0x3ff); |
| 1188 | | tilemap_set_scrolly(x68k_bg1,0,(x68k_spritereg[0x401] - x68k_sys.crtc.vbegin) & 0x3ff); |
| 1203 | tilemap_set_scrollx(x68k_bg1,0,(state->spritereg[0x400] - state->crtc.hbegin) & 0x3ff); |
| 1204 | tilemap_set_scrolly(x68k_bg1,0,(state->spritereg[0x401] - state->crtc.vbegin) & 0x3ff); |
| 1189 | 1205 | tilemap_draw(bitmap,&rect,x68k_bg1,0,0); |
| 1190 | 1206 | } |
| 1191 | 1207 | } |
| r9669 | r9670 | |
| 1193 | 1209 | } |
| 1194 | 1210 | |
| 1195 | 1211 | // Text screen |
| 1196 | | if(x68k_sys.video.reg[2] & 0x0020 && priority == x68k_sys.video.text_pri) |
| 1212 | if(state->video.reg[2] & 0x0020 && priority == state->video.text_pri) |
| 1197 | 1213 | { |
| 1198 | | xscr = (x68k_sys.crtc.reg[10] & 0x3ff); |
| 1199 | | yscr = (x68k_sys.crtc.reg[11] & 0x3ff); |
| 1200 | | if(!(x68k_sys.crtc.reg[20] & 0x1000)) // if text layer is set to buffer, then it's not visible |
| 1214 | xscr = (state->crtc.reg[10] & 0x3ff); |
| 1215 | yscr = (state->crtc.reg[11] & 0x3ff); |
| 1216 | if(!(state->crtc.reg[20] & 0x1000)) // if text layer is set to buffer, then it's not visible |
| 1201 | 1217 | x68k_draw_text(screen->machine,bitmap,xscr,yscr,rect); |
| 1202 | 1218 | } |
| 1203 | 1219 | } |
| r9669 | r9670 | |
| 1205 | 1221 | #ifdef MAME_DEBUG |
| 1206 | 1222 | if(input_code_pressed(screen->machine,KEYCODE_I)) |
| 1207 | 1223 | { |
| 1208 | | x68k_sys.mfp.isra = 0; |
| 1209 | | x68k_sys.mfp.isrb = 0; |
| 1224 | state->mfp.isra = 0; |
| 1225 | state->mfp.isrb = 0; |
| 1210 | 1226 | // mfp_trigger_irq(MFP_IRQ_GPIP6); |
| 1211 | 1227 | // cputag_set_input_line_and_vector(machine, "maincpu",6,ASSERT_LINE,0x43); |
| 1212 | 1228 | } |
| 1213 | 1229 | if(input_code_pressed(screen->machine,KEYCODE_9)) |
| 1214 | 1230 | { |
| 1215 | | sprite_shift--; |
| 1216 | | popmessage("Sprite shift = %i",sprite_shift); |
| 1231 | state->sprite_shift--; |
| 1232 | popmessage("Sprite shift = %i",state->sprite_shift); |
| 1217 | 1233 | } |
| 1218 | 1234 | if(input_code_pressed(screen->machine,KEYCODE_0)) |
| 1219 | 1235 | { |
| 1220 | | sprite_shift++; |
| 1221 | | popmessage("Sprite shift = %i",sprite_shift); |
| 1236 | state->sprite_shift++; |
| 1237 | popmessage("Sprite shift = %i",state->sprite_shift); |
| 1222 | 1238 | } |
| 1223 | 1239 | |
| 1224 | 1240 | #endif |
| 1225 | 1241 | |
| 1226 | 1242 | #ifdef MAME_DEBUG |
| 1227 | | // popmessage("Layer priorities [%04x] - Txt: %i Spr: %i Gfx: %i Layer Pri0-3: %i %i %i %i",x68k_sys.video.reg[1],x68k_sys.video.text_pri,x68k_sys.video.sprite_pri, |
| 1228 | | // x68k_sys.video.gfx_pri,x68k_sys.video.gfxlayer_pri[0],x68k_sys.video.gfxlayer_pri[1],x68k_sys.video.gfxlayer_pri[2],x68k_sys.video.gfxlayer_pri[3]); |
| 1229 | | // popmessage("CRTC regs - %i %i %i %i - %i %i %i %i - %i - %i",x68k_sys.crtc.reg[0],x68k_sys.crtc.reg[1],x68k_sys.crtc.reg[2],x68k_sys.crtc.reg[3], |
| 1230 | | // x68k_sys.crtc.reg[4],x68k_sys.crtc.reg[5],x68k_sys.crtc.reg[6],x68k_sys.crtc.reg[7],x68k_sys.crtc.reg[8],x68k_sys.crtc.reg[9]); |
| 1231 | | // popmessage("Visible resolution = %ix%i (%s) Screen size = %ix%i",x68k_sys.crtc.visible_width,x68k_sys.crtc.visible_height,x68k_sys.crtc.interlace ? "Interlaced" : "Non-interlaced",x68k_sys.crtc.video_width,x68k_sys.crtc.video_height); |
| 1232 | | // popmessage("VBlank : x68k_scanline = %i",x68k_scanline); |
| 1233 | | // popmessage("CRTC/BG compare H-TOTAL %i/%i H-DISP %i/%i V-DISP %i/%i BG Res %02x",x68k_sys.crtc.reg[0],x68k_spritereg[0x405],x68k_sys.crtc.reg[2],x68k_spritereg[0x406], |
| 1234 | | // x68k_sys.crtc.reg[6],x68k_spritereg[0x407],x68k_spritereg[0x408]); |
| 1235 | | // popmessage("IER %02x %02x IPR %02x %02x ISR %02x %02x IMR %02x %02x", x68k_sys.mfp.iera,x68k_sys.mfp.ierb,x68k_sys.mfp.ipra,x68k_sys.mfp.iprb, |
| 1236 | | // x68k_sys.mfp.isra,x68k_sys.mfp.isrb,x68k_sys.mfp.imra,x68k_sys.mfp.imrb); |
| 1237 | | // popmessage("BG Scroll - BG0 X %i Y %i BG1 X %i Y %i",x68k_spriteram[0x400],x68k_spriteram[0x401],x68k_spriteram[0x402],x68k_spriteram[0x403]); |
| 1238 | | // popmessage("Keyboard buffer position = %i",x68k_sys.keyboard.headpos); |
| 1239 | | // popmessage("IERA = 0x%02x, IERB = 0x%02x",x68k_sys.mfp.iera,x68k_sys.mfp.ierb); |
| 1240 | | // popmessage("IPRA = 0x%02x, IPRB = 0x%02x",x68k_sys.mfp.ipra,x68k_sys.mfp.iprb); |
| 1243 | // popmessage("Layer priorities [%04x] - Txt: %i Spr: %i Gfx: %i Layer Pri0-3: %i %i %i %i",state->video.reg[1],state->video.text_pri,state->video.sprite_pri, |
| 1244 | // state->video.gfx_pri,state->video.gfxlayer_pri[0],state->video.gfxlayer_pri[1],state->video.gfxlayer_pri[2],state->video.gfxlayer_pri[3]); |
| 1245 | // popmessage("CRTC regs - %i %i %i %i - %i %i %i %i - %i - %i",state->crtc.reg[0],state->crtc.reg[1],state->crtc.reg[2],state->crtc.reg[3], |
| 1246 | // state->crtc.reg[4],state->crtc.reg[5],state->crtc.reg[6],state->crtc.reg[7],state->crtc.reg[8],state->crtc.reg[9]); |
| 1247 | // popmessage("Visible resolution = %ix%i (%s) Screen size = %ix%i",state->crtc.visible_width,state->crtc.visible_height,state->crtc.interlace ? "Interlaced" : "Non-interlaced",state->crtc.video_width,state->crtc.video_height); |
| 1248 | // popmessage("VBlank : scanline = %i",state->scanline); |
| 1249 | // popmessage("CRTC/BG compare H-TOTAL %i/%i H-DISP %i/%i V-DISP %i/%i BG Res %02x",state->crtc.reg[0],state->spritereg[0x405],state->crtc.reg[2],state->spritereg[0x406], |
| 1250 | // state->crtc.reg[6],state->spritereg[0x407],state->spritereg[0x408]); |
| 1251 | // popmessage("IER %02x %02x IPR %02x %02x ISR %02x %02x IMR %02x %02x", state->mfp.iera,state->mfp.ierb,state->mfp.ipra,state->mfp.iprb, |
| 1252 | // state->mfp.isra,state->mfp.isrb,state->mfp.imra,state->mfp.imrb); |
| 1253 | // popmessage("BG Scroll - BG0 X %i Y %i BG1 X %i Y %i",state->spriteram[0x400],state->spriteram[0x401],state->spriteram[0x402],state->spriteram[0x403]); |
| 1254 | // popmessage("Keyboard buffer position = %i",state->keyboard.headpos); |
| 1255 | // popmessage("IERA = 0x%02x, IERB = 0x%02x",state->mfp.iera,state->mfp.ierb); |
| 1256 | // popmessage("IPRA = 0x%02x, IPRB = 0x%02x",state->mfp.ipra,state->mfp.iprb); |
| 1241 | 1257 | // popmessage("uPD72065 status = %02x",upd765_status_r(machine, 0)); |
| 1242 | | // popmessage("Layer enable - 0x%02x",x68k_sys.video.reg[2] & 0xff); |
| 1258 | // popmessage("Layer enable - 0x%02x",state->video.reg[2] & 0xff); |
| 1243 | 1259 | // popmessage("Graphic layer scroll - %i, %i - %i, %i - %i, %i - %i, %i", |
| 1244 | | // x68k_sys.crtc.reg[12],x68k_sys.crtc.reg[13],x68k_sys.crtc.reg[14],x68k_sys.crtc.reg[15],x68k_sys.crtc.reg[16],x68k_sys.crtc.reg[17],x68k_sys.crtc.reg[18],x68k_sys.crtc.reg[19]); |
| 1245 | | // popmessage("IOC IRQ status - %02x",x68k_sys.ioc.irqstatus); |
| 1260 | // state->crtc.reg[12],state->crtc.reg[13],state->crtc.reg[14],state->crtc.reg[15],state->crtc.reg[16],state->crtc.reg[17],state->crtc.reg[18],state->crtc.reg[19]); |
| 1261 | // popmessage("IOC IRQ status - %02x",state->ioc.irqstatus); |
| 1246 | 1262 | // popmessage("RAM: mouse data - %02x %02x %02x %02x",messram_get_ptr(machine->device("messram"))[0x931],messram_get_ptr(machine->device("messram"))[0x930],messram_get_ptr(machine->device("messram"))[0x933],messram_get_ptr(machine->device("messram"))[0x932]); |
| 1247 | 1263 | #endif |
| 1248 | 1264 | return 0; |
src/mess/video/vc4000.c
| r9669 | r9670 | |
| 22 | 22 | |
| 23 | 23 | #define VC4000_END_LINE (269) |
| 24 | 24 | |
| 25 | | typedef struct { |
| 26 | | UINT8 bitmap[10],x1,x2,y1,y2, res1, res2; |
| 27 | | } SPRITE_HELPER; |
| 28 | 25 | |
| 29 | | typedef struct { |
| 30 | | const SPRITE_HELPER *data; |
| 31 | | int mask; |
| 32 | | int state; |
| 33 | | int delay; |
| 34 | | int size; |
| 35 | | int y; |
| 36 | | UINT8 scolor; |
| 37 | | int finished; |
| 38 | | int finished_now; |
| 39 | | } SPRITE; |
| 40 | 26 | |
| 41 | | static struct |
| 42 | | { |
| 43 | | SPRITE sprites[4]; |
| 44 | | int line; |
| 45 | | UINT8 sprite_collision; |
| 46 | | UINT8 background_collision; |
| 47 | | union |
| 48 | | { |
| 49 | | UINT8 data[0x100]; |
| 50 | | struct |
| 51 | | { |
| 52 | | SPRITE_HELPER sprites[3]; |
| 53 | | UINT8 res[0x10]; |
| 54 | | SPRITE_HELPER sprite4; |
| 55 | | UINT8 res2[0x30]; |
| 56 | | UINT8 grid[20][2]; |
| 57 | | UINT8 grid_control[5]; |
| 58 | | UINT8 res3[0x13]; |
| 59 | | UINT8 sprite_sizes; |
| 60 | | UINT8 sprite_colors[2]; |
| 61 | | UINT8 score_control; |
| 62 | | UINT8 res4[2]; |
| 63 | | UINT8 background; |
| 64 | | UINT8 sound; |
| 65 | | UINT8 bcd[2]; |
| 66 | | UINT8 background_collision; |
| 67 | | UINT8 sprite_collision; |
| 68 | | } d; |
| 69 | | } reg; |
| 70 | | |
| 71 | | bitmap_t *bitmap; |
| 72 | | } vc4000_video; |
| 73 | | |
| 74 | | static UINT8 sprite_collision[0x20]; |
| 75 | | static UINT8 background_collision[0x20]; |
| 76 | | static UINT8 joy1_x,joy1_y,joy2_x,joy2_y; |
| 77 | | |
| 78 | 27 | VIDEO_START(vc4000) |
| 79 | 28 | { |
| 29 | vc4000_state *state = machine->driver_data<vc4000_state>(); |
| 80 | 30 | screen_device *screen = screen_first(*machine); |
| 81 | 31 | int width = screen->width(); |
| 82 | 32 | int height = screen->height(); |
| r9669 | r9670 | |
| 84 | 34 | |
| 85 | 35 | for (i=0;i<0x20; i++) |
| 86 | 36 | { |
| 87 | | sprite_collision[i]=0; |
| 88 | | if ((i&3)==3) sprite_collision[i]|=0x20; |
| 89 | | if ((i&5)==5) sprite_collision[i]|=0x10; |
| 90 | | if ((i&9)==9) sprite_collision[i]|=8; |
| 91 | | if ((i&6)==6) sprite_collision[i]|=4; |
| 92 | | if ((i&0xa)==0xa) sprite_collision[i]|=2; |
| 93 | | if ((i&0xc)==0xc) sprite_collision[i]|=1; |
| 94 | | background_collision[i]=0; |
| 95 | | if ((i&0x11)==0x11) background_collision[i]|=0x80; |
| 96 | | if ((i&0x12)==0x12) background_collision[i]|=0x40; |
| 97 | | if ((i&0x14)==0x14) background_collision[i]|=0x20; |
| 98 | | if ((i&0x18)==0x18) background_collision[i]|=0x10; |
| 37 | state->sprite_collision[i]=0; |
| 38 | if ((i&3)==3) state->sprite_collision[i]|=0x20; |
| 39 | if ((i&5)==5) state->sprite_collision[i]|=0x10; |
| 40 | if ((i&9)==9) state->sprite_collision[i]|=8; |
| 41 | if ((i&6)==6) state->sprite_collision[i]|=4; |
| 42 | if ((i&0xa)==0xa) state->sprite_collision[i]|=2; |
| 43 | if ((i&0xc)==0xc) state->sprite_collision[i]|=1; |
| 44 | state->background_collision[i]=0; |
| 45 | if ((i&0x11)==0x11) state->background_collision[i]|=0x80; |
| 46 | if ((i&0x12)==0x12) state->background_collision[i]|=0x40; |
| 47 | if ((i&0x14)==0x14) state->background_collision[i]|=0x20; |
| 48 | if ((i&0x18)==0x18) state->background_collision[i]|=0x10; |
| 99 | 49 | } |
| 100 | 50 | |
| 101 | | joy1_x = STICKCENTRE; |
| 102 | | joy1_y = STICKCENTRE; |
| 103 | | joy2_x = STICKCENTRE; |
| 104 | | joy2_y = STICKCENTRE; |
| 51 | state->joy1_x = STICKCENTRE; |
| 52 | state->joy1_y = STICKCENTRE; |
| 53 | state->joy2_x = STICKCENTRE; |
| 54 | state->joy2_y = STICKCENTRE; |
| 105 | 55 | |
| 106 | | memset(&vc4000_video, 0, sizeof(vc4000_video)); |
| 56 | memset(&state->video, 0, sizeof(state->video)); |
| 107 | 57 | for (i=0; i<3; i++) |
| 108 | 58 | { |
| 109 | | vc4000_video.sprites[i].data = &vc4000_video.reg.d.sprites[i]; |
| 110 | | vc4000_video.sprites[i].mask = 1 << i; |
| 59 | state->video.sprites[i].data = &state->video.reg.d.sprites[i]; |
| 60 | state->video.sprites[i].mask = 1 << i; |
| 111 | 61 | } |
| 112 | | vc4000_video.sprites[3].data = &vc4000_video.reg.d.sprite4; |
| 113 | | vc4000_video.sprites[3].mask = 1 << 3; |
| 62 | state->video.sprites[3].data = &state->video.reg.d.sprite4; |
| 63 | state->video.sprites[3].mask = 1 << 3; |
| 114 | 64 | |
| 115 | | vc4000_video.bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16); |
| 65 | state->video.bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16); |
| 116 | 66 | } |
| 117 | 67 | |
| 118 | 68 | INLINE UINT8 vc4000_joystick_return_to_centre(UINT8 joy) |
| r9669 | r9670 | |
| 132 | 82 | |
| 133 | 83 | READ8_HANDLER(vc4000_video_r) |
| 134 | 84 | { |
| 85 | vc4000_state *state = space->machine->driver_data<vc4000_state>(); |
| 135 | 86 | UINT8 data=0; |
| 136 | 87 | if (offset > 0xcf) offset &= 0xcf; // c0-cf is mirrored at d0-df, e0-ef, f0-ff |
| 137 | 88 | switch (offset) { |
| 138 | 89 | |
| 139 | 90 | case 0xca: // Background-sprite collision (bit 7-4) and sprite finished (bit 3-0) |
| 140 | | data |= vc4000_video.background_collision; |
| 141 | | vc4000_video.background_collision=0; |
| 142 | | if (vc4000_video.sprites[3].finished) |
| 91 | data |= state->video.background_collision; |
| 92 | state->video.background_collision=0; |
| 93 | if (state->video.sprites[3].finished) |
| 143 | 94 | { |
| 144 | 95 | data |= 1; |
| 145 | | vc4000_video.sprites[3].finished = FALSE; |
| 96 | state->video.sprites[3].finished = FALSE; |
| 146 | 97 | } |
| 147 | 98 | |
| 148 | | if (vc4000_video.sprites[2].finished) |
| 99 | if (state->video.sprites[2].finished) |
| 149 | 100 | { |
| 150 | 101 | data |= 2; |
| 151 | | vc4000_video.sprites[2].finished = FALSE; |
| 102 | state->video.sprites[2].finished = FALSE; |
| 152 | 103 | } |
| 153 | | if (vc4000_video.sprites[1].finished) |
| 104 | if (state->video.sprites[1].finished) |
| 154 | 105 | { |
| 155 | 106 | data |= 4; |
| 156 | | vc4000_video.sprites[1].finished = FALSE; |
| 107 | state->video.sprites[1].finished = FALSE; |
| 157 | 108 | } |
| 158 | | if (vc4000_video.sprites[0].finished) |
| 109 | if (state->video.sprites[0].finished) |
| 159 | 110 | { |
| 160 | 111 | data |= 8; |
| 161 | | vc4000_video.sprites[0].finished = FALSE; |
| 112 | state->video.sprites[0].finished = FALSE; |
| 162 | 113 | } |
| 163 | 114 | break; |
| 164 | 115 | |
| 165 | 116 | case 0xcb: // VRST-Flag (bit 6) and intersprite collision (bit5-0) |
| 166 | | data = vc4000_video.sprite_collision | (vc4000_video.reg.d.sprite_collision & 0xc0); |
| 167 | | vc4000_video.sprite_collision = 0; |
| 168 | | vc4000_video.reg.d.sprite_collision &= 0xbf; |
| 117 | data = state->video.sprite_collision | (state->video.reg.d.sprite_collision & 0xc0); |
| 118 | state->video.sprite_collision = 0; |
| 119 | state->video.reg.d.sprite_collision &= 0xbf; |
| 169 | 120 | break; |
| 170 | 121 | |
| 171 | 122 | #ifndef ANALOG_HACK |
| r9669 | r9670 | |
| 188 | 139 | switch (data) |
| 189 | 140 | { |
| 190 | 141 | case 0x01: |
| 191 | | joy1_x-=5; |
| 192 | | if (joy1_x < STICKLOW) joy1_x=STICKLOW; |
| 142 | state->joy1_x-=5; |
| 143 | if (state->joy1_x < STICKLOW) state->joy1_x=STICKLOW; |
| 193 | 144 | break; |
| 194 | 145 | case 0x02: |
| 195 | | joy1_x+=5; |
| 196 | | if (joy1_x > STICKHIGH) joy1_x=STICKHIGH; |
| 146 | state->joy1_x+=5; |
| 147 | if (state->joy1_x > STICKHIGH) state->joy1_x=STICKHIGH; |
| 197 | 148 | break; |
| 198 | 149 | case 0x00: |
| 199 | | joy1_x = vc4000_joystick_return_to_centre(joy1_x); |
| 150 | state->joy1_x = vc4000_joystick_return_to_centre(state->joy1_x); |
| 200 | 151 | } |
| 201 | | data=joy1_x; |
| 152 | data=state->joy1_x; |
| 202 | 153 | } |
| 203 | 154 | else |
| 204 | 155 | { |
| r9669 | r9670 | |
| 206 | 157 | switch (data) |
| 207 | 158 | { |
| 208 | 159 | case 0x08: |
| 209 | | joy1_y-=5; |
| 210 | | if (joy1_y < STICKLOW) joy1_y=STICKLOW; |
| 160 | state->joy1_y-=5; |
| 161 | if (state->joy1_y < STICKLOW) state->joy1_y=STICKLOW; |
| 211 | 162 | break; |
| 212 | 163 | case 0x04: |
| 213 | | joy1_y+=5; |
| 214 | | if (joy1_y > STICKHIGH) joy1_y=STICKHIGH; |
| 164 | state->joy1_y+=5; |
| 165 | if (state->joy1_y > STICKHIGH) state->joy1_y=STICKHIGH; |
| 215 | 166 | break; |
| 216 | 167 | // case 0x00: |
| 217 | | // joy1_y = vc4000_joystick_return_to_centre(joy1_y); |
| 168 | // state->joy1_y = vc4000_joystick_return_to_centre(state->joy1_y); |
| 218 | 169 | } |
| 219 | | data=joy1_y; |
| 170 | data=state->joy1_y; |
| 220 | 171 | } |
| 221 | 172 | } |
| 222 | 173 | else |
| r9669 | r9670 | |
| 227 | 178 | switch (data) |
| 228 | 179 | { |
| 229 | 180 | case 0x01: |
| 230 | | joy1_x=STICKLOW; |
| 181 | state->joy1_x=STICKLOW; |
| 231 | 182 | break; |
| 232 | 183 | case 0x02: |
| 233 | | joy1_x=STICKHIGH; |
| 184 | state->joy1_x=STICKHIGH; |
| 234 | 185 | break; |
| 235 | 186 | default: /* autocentre */ |
| 236 | | joy1_x=STICKCENTRE; |
| 187 | state->joy1_x=STICKCENTRE; |
| 237 | 188 | } |
| 238 | | data=joy1_x; |
| 189 | data=state->joy1_x; |
| 239 | 190 | } |
| 240 | 191 | else |
| 241 | 192 | { |
| r9669 | r9670 | |
| 243 | 194 | switch (data) |
| 244 | 195 | { |
| 245 | 196 | case 0x08: |
| 246 | | joy1_y=STICKLOW; |
| 197 | state->joy1_y=STICKLOW; |
| 247 | 198 | break; |
| 248 | 199 | case 0x04: |
| 249 | | joy1_y=STICKHIGH; |
| 200 | state->joy1_y=STICKHIGH; |
| 250 | 201 | break; |
| 251 | 202 | default: |
| 252 | | joy1_y=STICKCENTRE; |
| 203 | state->joy1_y=STICKCENTRE; |
| 253 | 204 | } |
| 254 | | data=joy1_y; |
| 205 | data=state->joy1_y; |
| 255 | 206 | } |
| 256 | 207 | } |
| 257 | 208 | break; |
| r9669 | r9670 | |
| 265 | 216 | switch (data) |
| 266 | 217 | { |
| 267 | 218 | case 0x10: |
| 268 | | joy2_x-=5; |
| 269 | | if (joy2_x < STICKLOW) joy2_x=STICKLOW; |
| 219 | state->joy2_x-=5; |
| 220 | if (state->joy2_x < STICKLOW) state->joy2_x=STICKLOW; |
| 270 | 221 | break; |
| 271 | 222 | case 0x20: |
| 272 | | joy2_x+=5; |
| 273 | | if (joy2_x > STICKHIGH) joy2_x=STICKHIGH; |
| 223 | state->joy2_x+=5; |
| 224 | if (state->joy2_x > STICKHIGH) state->joy2_x=STICKHIGH; |
| 274 | 225 | case 0x00: |
| 275 | | joy2_x = vc4000_joystick_return_to_centre(joy2_x); |
| 226 | state->joy2_x = vc4000_joystick_return_to_centre(state->joy2_x); |
| 276 | 227 | break; |
| 277 | 228 | } |
| 278 | | data=joy2_x; |
| 229 | data=state->joy2_x; |
| 279 | 230 | } |
| 280 | 231 | else |
| 281 | 232 | { |
| r9669 | r9670 | |
| 283 | 234 | switch (data) |
| 284 | 235 | { |
| 285 | 236 | case 0x80: |
| 286 | | joy2_y-=5; |
| 287 | | if (joy2_y < STICKLOW) joy2_y=STICKLOW; |
| 237 | state->joy2_y-=5; |
| 238 | if (state->joy2_y < STICKLOW) state->joy2_y=STICKLOW; |
| 288 | 239 | break; |
| 289 | 240 | case 0x40: |
| 290 | | joy2_y+=5; |
| 291 | | if (joy2_y > STICKHIGH) joy2_y=STICKHIGH; |
| 241 | state->joy2_y+=5; |
| 242 | if (state->joy2_y > STICKHIGH) state->joy2_y=STICKHIGH; |
| 292 | 243 | break; |
| 293 | 244 | // case 0x00: |
| 294 | | // joy2_y = vc4000_joystick_return_to_centre(joy2_y); |
| 245 | // state->joy2_y = vc4000_joystick_return_to_centre(state->joy2_y); |
| 295 | 246 | } |
| 296 | | data=joy2_y; |
| 247 | data=state->joy2_y; |
| 297 | 248 | } |
| 298 | 249 | } |
| 299 | 250 | else |
| r9669 | r9670 | |
| 304 | 255 | switch (data) |
| 305 | 256 | { |
| 306 | 257 | case 0x10: |
| 307 | | joy2_x=STICKLOW; |
| 258 | state->joy2_x=STICKLOW; |
| 308 | 259 | break; |
| 309 | 260 | case 0x20: |
| 310 | | joy2_x=STICKHIGH; |
| 261 | state->joy2_x=STICKHIGH; |
| 311 | 262 | break; |
| 312 | 263 | default: /* autocentre */ |
| 313 | | joy2_x=STICKCENTRE; |
| 264 | state->joy2_x=STICKCENTRE; |
| 314 | 265 | } |
| 315 | | data=joy2_x; |
| 266 | data=state->joy2_x; |
| 316 | 267 | } |
| 317 | 268 | else |
| 318 | 269 | { |
| r9669 | r9670 | |
| 320 | 271 | switch (data) |
| 321 | 272 | { |
| 322 | 273 | case 0x80: |
| 323 | | joy2_y=STICKLOW; |
| 274 | state->joy2_y=STICKLOW; |
| 324 | 275 | break; |
| 325 | 276 | case 0x40: |
| 326 | | joy2_y=STICKHIGH; |
| 277 | state->joy2_y=STICKHIGH; |
| 327 | 278 | break; |
| 328 | 279 | default: |
| 329 | | joy2_y=STICKCENTRE; |
| 280 | state->joy2_y=STICKCENTRE; |
| 330 | 281 | } |
| 331 | | data=joy2_y; |
| 282 | data=state->joy2_y; |
| 332 | 283 | } |
| 333 | 284 | } |
| 334 | 285 | break; |
| 335 | 286 | #endif |
| 336 | 287 | |
| 337 | 288 | default: |
| 338 | | data = vc4000_video.reg.data[offset]; |
| 289 | data = state->video.reg.data[offset]; |
| 339 | 290 | break; |
| 340 | 291 | } |
| 341 | 292 | return data; |
| r9669 | r9670 | |
| 343 | 294 | |
| 344 | 295 | WRITE8_HANDLER(vc4000_video_w) |
| 345 | 296 | { |
| 346 | | // vc4000_video.reg.data[offset]=data; |
| 297 | vc4000_state *state = space->machine->driver_data<vc4000_state>(); |
| 298 | // state->video.reg.data[offset]=data; |
| 347 | 299 | if (offset > 0xcf) offset &= 0xcf; // c0-cf is mirrored at d0-df, e0-ef, f0-ff |
| 348 | 300 | |
| 349 | 301 | switch (offset) { |
| 350 | 302 | |
| 351 | 303 | case 0xc0: // Sprite size |
| 352 | | vc4000_video.sprites[0].size=1<<(data&3); |
| 353 | | vc4000_video.sprites[1].size=1<<((data>>2)&3); |
| 354 | | vc4000_video.sprites[2].size=1<<((data>>4)&3); |
| 355 | | vc4000_video.sprites[3].size=1<<((data>>6)&3); |
| 304 | state->video.sprites[0].size=1<<(data&3); |
| 305 | state->video.sprites[1].size=1<<((data>>2)&3); |
| 306 | state->video.sprites[2].size=1<<((data>>4)&3); |
| 307 | state->video.sprites[3].size=1<<((data>>6)&3); |
| 356 | 308 | break; |
| 357 | 309 | |
| 358 | 310 | case 0xc1: // Sprite 1+2 color |
| 359 | | vc4000_video.sprites[0].scolor=((~data>>3)&7); |
| 360 | | vc4000_video.sprites[1].scolor=(~data&7); |
| 311 | state->video.sprites[0].scolor=((~data>>3)&7); |
| 312 | state->video.sprites[1].scolor=(~data&7); |
| 361 | 313 | break; |
| 362 | 314 | |
| 363 | 315 | case 0xc2: // Sprite 2+3 color |
| 364 | | vc4000_video.sprites[2].scolor=((~data>>3)&7); |
| 365 | | vc4000_video.sprites[3].scolor=(~data&7); |
| 316 | state->video.sprites[2].scolor=((~data>>3)&7); |
| 317 | state->video.sprites[3].scolor=(~data&7); |
| 366 | 318 | break; |
| 367 | 319 | |
| 368 | 320 | case 0xc3: // Score control |
| 369 | | vc4000_video.reg.d.score_control = data; |
| 321 | state->video.reg.d.score_control = data; |
| 370 | 322 | break; |
| 371 | 323 | |
| 372 | 324 | case 0xc6: // Background color |
| 373 | | vc4000_video.reg.d.background = data; |
| 325 | state->video.reg.d.background = data; |
| 374 | 326 | break; |
| 375 | 327 | |
| 376 | 328 | case 0xc7: // Soundregister |
| 377 | | vc4000_video.reg.data[offset] = data; |
| 329 | state->video.reg.data[offset] = data; |
| 378 | 330 | vc4000_soundport_w(space->machine->device("custom"), 0, data); |
| 379 | 331 | break; |
| 380 | 332 | |
| 381 | 333 | case 0xc8: // Digits 1 and 2 |
| 382 | | vc4000_video.reg.d.bcd[0] = data; |
| 334 | state->video.reg.d.bcd[0] = data; |
| 383 | 335 | break; |
| 384 | 336 | |
| 385 | 337 | case 0xc9: // Digits 3 and 4 |
| 386 | | vc4000_video.reg.d.bcd[1] = data; |
| 338 | state->video.reg.d.bcd[1] = data; |
| 387 | 339 | break; |
| 388 | 340 | |
| 389 | 341 | case 0xca: // Background-sprite collision (bit 7-4) and sprite finished (bit 3-0) |
| 390 | | vc4000_video.reg.data[offset]=data; |
| 391 | | vc4000_video.background_collision=data; |
| 342 | state->video.reg.data[offset]=data; |
| 343 | state->video.background_collision=data; |
| 392 | 344 | break; |
| 393 | 345 | |
| 394 | 346 | case 0xcb: // VRST-Flag (bit 6) and intersprite collision (bit5-0) |
| 395 | | vc4000_video.reg.data[offset]=data; |
| 396 | | vc4000_video.sprite_collision=data; |
| 347 | state->video.reg.data[offset]=data; |
| 348 | state->video.sprite_collision=data; |
| 397 | 349 | break; |
| 398 | 350 | |
| 399 | 351 | default: |
| 400 | | vc4000_video.reg.data[offset]=data; |
| 352 | state->video.reg.data[offset]=data; |
| 401 | 353 | } |
| 402 | 354 | } |
| 403 | 355 | |
| 404 | 356 | |
| 405 | 357 | READ8_HANDLER(vc4000_vsync_r) |
| 406 | 358 | { |
| 407 | | return vc4000_video.line >= VC4000_END_LINE ? 0x80 : 0; |
| 359 | vc4000_state *state = space->machine->driver_data<vc4000_state>(); |
| 360 | return state->video.line >= VC4000_END_LINE ? 0x80 : 0; |
| 408 | 361 | } |
| 409 | 362 | |
| 410 | 363 | static const char led[20][12+1] = |
| r9669 | r9670 | |
| 431 | 384 | "iiiihhhhgggg" |
| 432 | 385 | }; |
| 433 | 386 | |
| 434 | | static UINT8 objects[256]; |
| 435 | 387 | |
| 436 | | static void vc4000_draw_digit(bitmap_t *bitmap, int x, int y, int d, int line) |
| 388 | static void vc4000_draw_digit(vc4000_state *state, bitmap_t *bitmap, int x, int y, int d, int line) |
| 437 | 389 | { |
| 438 | 390 | static const int digit_to_segment[0x10]={ |
| 439 | 391 | 0x0fff, 0x007c, 0x17df, 0x15ff, 0x1c7d, 0x1df7, 0x1ff7, 0x007f, 0x1fff, 0x1dff |
| r9669 | r9670 | |
| 444 | 396 | for (j=0; j<sizeof(led[0]); j++) |
| 445 | 397 | { |
| 446 | 398 | if (digit_to_segment[d]&(1<<(led[i][j]-'a')) ) |
| 447 | | *BITMAP_ADDR16(bitmap, y+i, x+j) = ((vc4000_video.reg.d.background>>4)&7)^7; |
| 399 | *BITMAP_ADDR16(bitmap, y+i, x+j) = ((state->video.reg.d.background>>4)&7)^7; |
| 448 | 400 | } |
| 449 | 401 | } |
| 450 | 402 | |
| r9669 | r9670 | |
| 462 | 414 | } |
| 463 | 415 | |
| 464 | 416 | |
| 465 | | static void vc4000_sprite_update(bitmap_t *bitmap, UINT8 *collision, SPRITE *This) |
| 417 | static void vc4000_sprite_update(vc4000_state *state, bitmap_t *bitmap, UINT8 *collision, SPRITE *This) |
| 466 | 418 | { |
| 467 | 419 | int i,j,m; |
| 468 | 420 | |
| 469 | | if (vc4000_video.line==0) |
| 421 | if (state->video.line==0) |
| 470 | 422 | { |
| 471 | 423 | This->y=This->data->y1; |
| 472 | 424 | This->state=0; |
| r9669 | r9670 | |
| 476 | 428 | |
| 477 | 429 | This->finished_now=FALSE; |
| 478 | 430 | |
| 479 | | if (vc4000_video.line>VC4000_END_LINE) return; |
| 431 | if (state->video.line>VC4000_END_LINE) return; |
| 480 | 432 | |
| 481 | 433 | switch (This->state) |
| 482 | 434 | { |
| 483 | 435 | case 0: |
| 484 | | if (vc4000_video.line != This->y + 2) break; |
| 436 | if (state->video.line != This->y + 2) break; |
| 485 | 437 | This->state++; |
| 486 | 438 | |
| 487 | 439 | case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:case 9:case 10: |
| r9669 | r9670 | |
| 494 | 446 | { |
| 495 | 447 | for (i=0; i<This->size; i++) |
| 496 | 448 | { |
| 497 | | objects[This->data->x1 + i + j*This->size] |= This->scolor; |
| 498 | | objects[This->data->x1 + i + j*This->size] &= 7; |
| 449 | state->objects[This->data->x1 + i + j*This->size] |= This->scolor; |
| 450 | state->objects[This->data->x1 + i + j*This->size] &= 7; |
| 499 | 451 | } |
| 500 | 452 | } |
| 501 | 453 | } |
| r9669 | r9670 | |
| 546 | 498 | { |
| 547 | 499 | for (i=0; i<This->size; i++) |
| 548 | 500 | { |
| 549 | | objects[This->data->x2 + i + j*This->size] |= This->scolor; |
| 550 | | objects[This->data->x2 + i + j*This->size] &= 7; |
| 501 | state->objects[This->data->x2 + i + j*This->size] |= This->scolor; |
| 502 | state->objects[This->data->x2 + i + j*This->size] &= 7; |
| 551 | 503 | } |
| 552 | 504 | } |
| 553 | 505 | } |
| r9669 | r9670 | |
| 565 | 517 | |
| 566 | 518 | INLINE void vc4000_draw_grid(running_machine *machine, UINT8 *collision) |
| 567 | 519 | { |
| 520 | vc4000_state *state = machine->driver_data<vc4000_state>(); |
| 568 | 521 | screen_device *screen = screen_first(*machine); |
| 569 | 522 | int width = screen->width(); |
| 570 | 523 | int height = screen->height(); |
| 571 | | int i, j, m, x, line=vc4000_video.line-20; |
| 524 | int i, j, m, x, line=state->video.line-20; |
| 572 | 525 | int w, k; |
| 573 | 526 | |
| 574 | | if (vc4000_video.line>=height) return; |
| 527 | if (state->video.line>=height) return; |
| 575 | 528 | |
| 576 | | plot_box(vc4000_video.bitmap, 0, vc4000_video.line, width, 1, (vc4000_video.reg.d.background)&7); |
| 529 | plot_box(state->video.bitmap, 0, state->video.line, width, 1, (state->video.reg.d.background)&7); |
| 577 | 530 | |
| 578 | 531 | if (line<0 || line>=200) return; |
| 579 | | if (~vc4000_video.reg.d.background & 8) return; |
| 532 | if (~state->video.reg.d.background & 8) return; |
| 580 | 533 | |
| 581 | 534 | i=(line/20)*2; |
| 582 | 535 | if (line%20>=2) i++; |
| 583 | 536 | |
| 584 | | k=vc4000_video.reg.d.grid_control[i>>2]; |
| 537 | k=state->video.reg.d.grid_control[i>>2]; |
| 585 | 538 | switch (k>>6) { |
| 586 | 539 | default: |
| 587 | 540 | case 0:case 2: w=1;break; |
| r9669 | r9670 | |
| 609 | 562 | } |
| 610 | 563 | for (x=30, j=0, m=0x80; j<16; j++, x+=8, m>>=1) |
| 611 | 564 | { |
| 612 | | if (vc4000_video.reg.d.grid[i][j>>3]&m) |
| 565 | if (state->video.reg.d.grid[i][j>>3]&m) |
| 613 | 566 | { |
| 614 | 567 | int l; |
| 615 | 568 | for (l=0; l<w; l++) collision[x+l]|=0x10; |
| 616 | | plot_box(vc4000_video.bitmap, x, vc4000_video.line, w, 1, (vc4000_video.reg.d.background>>4)&7); |
| 569 | plot_box(state->video.bitmap, x, state->video.line, w, 1, (state->video.reg.d.background>>4)&7); |
| 617 | 570 | } |
| 618 | 571 | if (j==7) m=0x100; |
| 619 | 572 | } |
| r9669 | r9670 | |
| 621 | 574 | |
| 622 | 575 | INTERRUPT_GEN( vc4000_video_line ) |
| 623 | 576 | { |
| 577 | vc4000_state *state = device->machine->driver_data<vc4000_state>(); |
| 624 | 578 | int x,y,i; |
| 625 | 579 | UINT8 collision[400]={0}; // better alloca or gcc feature of non constant long automatic arrays |
| 626 | | static UINT8 irq_pause=0; |
| 627 | 580 | const rectangle &visarea = device->machine->primary_screen->visible_area(); |
| 628 | 581 | assert(ARRAY_LENGTH(collision) >= device->machine->primary_screen->width()); |
| 629 | 582 | |
| 630 | | vc4000_video.line++; |
| 631 | | if (irq_pause) irq_pause++; |
| 632 | | if (vc4000_video.line>311) vc4000_video.line=0; |
| 583 | state->video.line++; |
| 584 | if (state->irq_pause) state->irq_pause++; |
| 585 | if (state->video.line>311) state->video.line=0; |
| 633 | 586 | |
| 634 | | if (vc4000_video.line==0) |
| 587 | if (state->video.line==0) |
| 635 | 588 | { |
| 636 | | vc4000_video.background_collision=0; |
| 637 | | vc4000_video.sprite_collision=0; |
| 638 | | vc4000_video.reg.d.sprite_collision=0; |
| 589 | state->video.background_collision=0; |
| 590 | state->video.sprite_collision=0; |
| 591 | state->video.reg.d.sprite_collision=0; |
| 639 | 592 | // logerror("begin of frame\n"); |
| 640 | 593 | } |
| 641 | 594 | |
| 642 | | if (irq_pause>10) |
| 595 | if (state->irq_pause>10) |
| 643 | 596 | { |
| 644 | 597 | cputag_set_input_line(device->machine, "maincpu", 0, CLEAR_LINE); |
| 645 | | irq_pause = 0; |
| 598 | state->irq_pause = 0; |
| 646 | 599 | } |
| 647 | 600 | |
| 648 | | if (vc4000_video.line <= VC4000_END_LINE) |
| 601 | if (state->video.line <= VC4000_END_LINE) |
| 649 | 602 | { |
| 650 | 603 | vc4000_draw_grid(device->machine, collision); |
| 651 | 604 | |
| 652 | 605 | /* init object colours */ |
| 653 | | for (i=visarea.min_x; i<visarea.max_x; i++) objects[i]=8; |
| 606 | for (i=visarea.min_x; i<visarea.max_x; i++) state->objects[i]=8; |
| 654 | 607 | |
| 655 | 608 | /* calculate object colours and OR overlapping object colours */ |
| 656 | | vc4000_sprite_update(vc4000_video.bitmap, collision, &vc4000_video.sprites[0]); |
| 657 | | vc4000_sprite_update(vc4000_video.bitmap, collision, &vc4000_video.sprites[1]); |
| 658 | | vc4000_sprite_update(vc4000_video.bitmap, collision, &vc4000_video.sprites[2]); |
| 659 | | vc4000_sprite_update(vc4000_video.bitmap, collision, &vc4000_video.sprites[3]); |
| 609 | vc4000_sprite_update(state, state->video.bitmap, collision, &state->video.sprites[0]); |
| 610 | vc4000_sprite_update(state, state->video.bitmap, collision, &state->video.sprites[1]); |
| 611 | vc4000_sprite_update(state, state->video.bitmap, collision, &state->video.sprites[2]); |
| 612 | vc4000_sprite_update(state, state->video.bitmap, collision, &state->video.sprites[3]); |
| 660 | 613 | |
| 661 | 614 | for (i=visarea.min_x; i<visarea.max_x; i++) |
| 662 | 615 | { |
| 663 | | vc4000_video.sprite_collision|=sprite_collision[collision[i]]; |
| 664 | | vc4000_video.background_collision|=background_collision[collision[i]]; |
| 616 | state->video.sprite_collision|=state->sprite_collision[collision[i]]; |
| 617 | state->video.background_collision|=state->background_collision[collision[i]]; |
| 665 | 618 | /* display final object colours */ |
| 666 | | if (objects[i] < 8) |
| 667 | | *BITMAP_ADDR16(vc4000_video.bitmap, vc4000_video.line, i) = objects[i]; |
| 619 | if (state->objects[i] < 8) |
| 620 | *BITMAP_ADDR16(state->video.bitmap, state->video.line, i) = state->objects[i]; |
| 668 | 621 | } |
| 669 | 622 | |
| 670 | | y = vc4000_video.reg.d.score_control&1?200:20; |
| 623 | y = state->video.reg.d.score_control&1?200:20; |
| 671 | 624 | |
| 672 | | if ((vc4000_video.line>=y)&&(vc4000_video.line<y+20)) |
| 625 | if ((state->video.line>=y)&&(state->video.line<y+20)) |
| 673 | 626 | { |
| 674 | 627 | x = 60; |
| 675 | | vc4000_draw_digit(vc4000_video.bitmap, x, y, vc4000_video.reg.d.bcd[0]>>4, vc4000_video.line-y); |
| 676 | | vc4000_draw_digit(vc4000_video.bitmap, x+16, y, vc4000_video.reg.d.bcd[0]&0xf, vc4000_video.line-y); |
| 677 | | if (vc4000_video.reg.d.score_control&2) x -= 16; |
| 678 | | vc4000_draw_digit(vc4000_video.bitmap, x+48, y, vc4000_video.reg.d.bcd[1]>>4, vc4000_video.line-y); |
| 679 | | vc4000_draw_digit(vc4000_video.bitmap, x+64, y, vc4000_video.reg.d.bcd[1]&0xf, vc4000_video.line-y); |
| 628 | vc4000_draw_digit(state, state->video.bitmap, x, y, state->video.reg.d.bcd[0]>>4, state->video.line-y); |
| 629 | vc4000_draw_digit(state, state->video.bitmap, x+16, y, state->video.reg.d.bcd[0]&0xf, state->video.line-y); |
| 630 | if (state->video.reg.d.score_control&2) x -= 16; |
| 631 | vc4000_draw_digit(state, state->video.bitmap, x+48, y, state->video.reg.d.bcd[1]>>4, state->video.line-y); |
| 632 | vc4000_draw_digit(state, state->video.bitmap, x+64, y, state->video.reg.d.bcd[1]&0xf, state->video.line-y); |
| 680 | 633 | } |
| 681 | 634 | } |
| 682 | | if (vc4000_video.line==VC4000_END_LINE) vc4000_video.reg.d.sprite_collision |=0x40; |
| 635 | if (state->video.line==VC4000_END_LINE) state->video.reg.d.sprite_collision |=0x40; |
| 683 | 636 | |
| 684 | | if (((vc4000_video.line == VC4000_END_LINE) | |
| 685 | | (vc4000_video.sprites[3].finished_now) | |
| 686 | | (vc4000_video.sprites[2].finished_now) | |
| 687 | | (vc4000_video.sprites[1].finished_now) | |
| 688 | | (vc4000_video.sprites[0].finished_now)) && (!irq_pause)) |
| 637 | if (((state->video.line == VC4000_END_LINE) | |
| 638 | (state->video.sprites[3].finished_now) | |
| 639 | (state->video.sprites[2].finished_now) | |
| 640 | (state->video.sprites[1].finished_now) | |
| 641 | (state->video.sprites[0].finished_now)) && (!state->irq_pause)) |
| 689 | 642 | { |
| 690 | 643 | cputag_set_input_line_and_vector(device->machine, "maincpu", 0, ASSERT_LINE, 3); |
| 691 | | irq_pause=1; |
| 644 | state->irq_pause=1; |
| 692 | 645 | } |
| 693 | 646 | } |
| 694 | 647 | |
| 695 | 648 | VIDEO_UPDATE( vc4000 ) |
| 696 | 649 | { |
| 697 | | copybitmap(bitmap, vc4000_video.bitmap, 0, 0, 0, 0, cliprect); |
| 650 | vc4000_state *state = screen->machine->driver_data<vc4000_state>(); |
| 651 | copybitmap(bitmap, state->video.bitmap, 0, 0, 0, 0, cliprect); |
| 698 | 652 | return 0; |
| 699 | 653 | } |
src/mess/drivers/x68k.c
| r9669 | r9670 | |
| 139 | 139 | #include "x68000.lh" |
| 140 | 140 | |
| 141 | 141 | |
| 142 | | struct x68k_system x68k_sys; |
| 143 | 142 | |
| 144 | | static UINT16* sram; // SRAM |
| 145 | | static UINT8 ppi_port[3]; |
| 146 | | static int current_vector[8]; |
| 147 | | static UINT8 current_irq_line; |
| 148 | | static unsigned int x68k_scanline; |
| 149 | | static int led_state; |
| 150 | | |
| 151 | | static emu_timer* kb_timer; |
| 152 | 143 | //emu_timer* mfp_timer[4]; |
| 153 | 144 | //emu_timer* mfp_irq; |
| 154 | | emu_timer* x68k_scanline_timer; |
| 155 | | emu_timer* x68k_raster_irq; |
| 156 | | emu_timer* x68k_vblank_irq; |
| 157 | | static emu_timer* mouse_timer; // to set off the mouse interrupts via the SCC |
| 158 | | static emu_timer* led_timer; // to make disk drive control LEDs blink |
| 159 | 145 | |
| 160 | 146 | // MFP is clocked at 4MHz, so at /4 prescaler the timer is triggered after 1us (4 cycles) |
| 161 | 147 | // No longer necessary with the new MFP core |
| r9669 | r9670 | |
| 178 | 164 | } |
| 179 | 165 | #endif |
| 180 | 166 | |
| 181 | | static void mfp_init(void); |
| 182 | | //static TIMER_CALLBACK(mfp_update_irq); |
| 183 | | |
| 184 | | static void mfp_init() |
| 167 | static void mfp_init(running_machine *machine) |
| 185 | 168 | { |
| 186 | | x68k_sys.mfp.tadr = x68k_sys.mfp.tbdr = x68k_sys.mfp.tcdr = x68k_sys.mfp.tddr = 0xff; |
| 169 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 170 | state->mfp.tadr = state->mfp.tbdr = state->mfp.tcdr = state->mfp.tddr = 0xff; |
| 187 | 171 | |
| 188 | | x68k_sys.mfp.irqline = 6; // MFP is connected to 68000 IRQ line 6 |
| 189 | | x68k_sys.mfp.current_irq = -1; // No current interrupt |
| 172 | state->mfp.irqline = 6; // MFP is connected to 68000 IRQ line 6 |
| 173 | state->mfp.current_irq = -1; // No current interrupt |
| 190 | 174 | |
| 191 | 175 | #if 0 |
| 192 | 176 | mfp_timer[0] = timer_alloc(machine, mfp_timer_a_callback, NULL); |
| r9669 | r9670 | |
| 201 | 185 | #ifdef UNUSED_FUNCTION |
| 202 | 186 | TIMER_CALLBACK(mfp_update_irq) |
| 203 | 187 | { |
| 188 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 204 | 189 | int x; |
| 205 | 190 | |
| 206 | | if((x68k_sys.ioc.irqstatus & 0xc0) != 0) |
| 191 | if((state->ioc.irqstatus & 0xc0) != 0) |
| 207 | 192 | return; |
| 208 | 193 | |
| 209 | 194 | // check for pending IRQs, in priority order |
| 210 | | if(x68k_sys.mfp.ipra != 0) |
| 195 | if(state->mfp.ipra != 0) |
| 211 | 196 | { |
| 212 | 197 | for(x=7;x>=0;x--) |
| 213 | 198 | { |
| 214 | | if((x68k_sys.mfp.ipra & (1 << x)) && (x68k_sys.mfp.imra & (1 << x))) |
| 199 | if((state->mfp.ipra & (1 << x)) && (state->mfp.imra & (1 << x))) |
| 215 | 200 | { |
| 216 | | current_irq_line = x68k_sys.mfp.irqline; |
| 217 | | x68k_sys.mfp.current_irq = x + 8; |
| 201 | state->current_irq_line = state->mfp.irqline; |
| 202 | state->mfp.current_irq = x + 8; |
| 218 | 203 | // assert IRQ line |
| 219 | | // if(x68k_sys.mfp.iera & (1 << x)) |
| 204 | // if(state->mfp.iera & (1 << x)) |
| 220 | 205 | { |
| 221 | | current_vector[6] = (x68k_sys.mfp.vr & 0xf0) | (x+8); |
| 222 | | cputag_set_input_line_and_vector(machine, "maincpu",x68k_sys.mfp.irqline,ASSERT_LINE,(x68k_sys.mfp.vr & 0xf0) | (x + 8)); |
| 223 | | // logerror("MFP: Sent IRQ vector 0x%02x (IRQ line %i)\n",(x68k_sys.mfp.vr & 0xf0) | (x+8),x68k_sys.mfp.irqline); |
| 206 | state->current_vector[6] = (state->mfp.vr & 0xf0) | (x+8); |
| 207 | cputag_set_input_line_and_vector(machine, "maincpu",state->mfp.irqline,ASSERT_LINE,(state->mfp.vr & 0xf0) | (x + 8)); |
| 208 | // logerror("MFP: Sent IRQ vector 0x%02x (IRQ line %i)\n",(state->mfp.vr & 0xf0) | (x+8),state->mfp.irqline); |
| 224 | 209 | return; // one at a time only |
| 225 | 210 | } |
| 226 | 211 | } |
| 227 | 212 | } |
| 228 | 213 | } |
| 229 | | if(x68k_sys.mfp.iprb != 0) |
| 214 | if(state->mfp.iprb != 0) |
| 230 | 215 | { |
| 231 | 216 | for(x=7;x>=0;x--) |
| 232 | 217 | { |
| 233 | | if((x68k_sys.mfp.iprb & (1 << x)) && (x68k_sys.mfp.imrb & (1 << x))) |
| 218 | if((state->mfp.iprb & (1 << x)) && (state->mfp.imrb & (1 << x))) |
| 234 | 219 | { |
| 235 | | current_irq_line = x68k_sys.mfp.irqline; |
| 236 | | x68k_sys.mfp.current_irq = x; |
| 220 | state->current_irq_line = state->mfp.irqline; |
| 221 | state->mfp.current_irq = x; |
| 237 | 222 | // assert IRQ line |
| 238 | | // if(x68k_sys.mfp.ierb & (1 << x)) |
| 223 | // if(state->mfp.ierb & (1 << x)) |
| 239 | 224 | { |
| 240 | | current_vector[6] = (x68k_sys.mfp.vr & 0xf0) | x; |
| 241 | | cputag_set_input_line_and_vector(machine, "maincpu",x68k_sys.mfp.irqline,ASSERT_LINE,(x68k_sys.mfp.vr & 0xf0) | x); |
| 242 | | // logerror("MFP: Sent IRQ vector 0x%02x (IRQ line %i)\n",(x68k_sys.mfp.vr & 0xf0) | x,x68k_sys.mfp.irqline); |
| 225 | state->current_vector[6] = (state->mfp.vr & 0xf0) | x; |
| 226 | cputag_set_input_line_and_vector(machine, "maincpu",state->mfp.irqline,ASSERT_LINE,(state->mfp.vr & 0xf0) | x); |
| 227 | // logerror("MFP: Sent IRQ vector 0x%02x (IRQ line %i)\n",(state->mfp.vr & 0xf0) | x,state->mfp.irqline); |
| 243 | 228 | return; // one at a time only |
| 244 | 229 | } |
| 245 | 230 | } |
| r9669 | r9670 | |
| 247 | 232 | } |
| 248 | 233 | } |
| 249 | 234 | |
| 250 | | void mfp_trigger_irq(int irq) |
| 235 | void mfp_trigger_irq(running_machine *machine, int irq) |
| 251 | 236 | { |
| 237 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 252 | 238 | // check if interrupt is enabled |
| 253 | 239 | if(irq > 7) |
| 254 | 240 | { |
| 255 | | if(!(x68k_sys.mfp.iera & (1 << (irq-8)))) |
| 241 | if(!(state->mfp.iera & (1 << (irq-8)))) |
| 256 | 242 | return; // not enabled, no action taken |
| 257 | 243 | } |
| 258 | 244 | else |
| 259 | 245 | { |
| 260 | | if(!(x68k_sys.mfp.ierb & (1 << irq))) |
| 246 | if(!(state->mfp.ierb & (1 << irq))) |
| 261 | 247 | return; // not enabled, no action taken |
| 262 | 248 | } |
| 263 | 249 | |
| 264 | 250 | // set requested IRQ as pending |
| 265 | 251 | if(irq > 7) |
| 266 | | x68k_sys.mfp.ipra |= (1 << (irq-8)); |
| 252 | state->mfp.ipra |= (1 << (irq-8)); |
| 267 | 253 | else |
| 268 | | x68k_sys.mfp.iprb |= (1 << irq); |
| 254 | state->mfp.iprb |= (1 << irq); |
| 269 | 255 | |
| 270 | 256 | // check for IRQs to be called |
| 271 | 257 | // mfp_update_irq(0); |
| r9669 | r9670 | |
| 274 | 260 | |
| 275 | 261 | TIMER_CALLBACK(mfp_timer_a_callback) |
| 276 | 262 | { |
| 277 | | x68k_sys.mfp.timer[0].counter--; |
| 278 | | if(x68k_sys.mfp.timer[0].counter == 0) |
| 263 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 264 | state->mfp.timer[0].counter--; |
| 265 | if(state->mfp.timer[0].counter == 0) |
| 279 | 266 | { |
| 280 | | x68k_sys.mfp.timer[0].counter = x68k_sys.mfp.tadr; |
| 267 | state->mfp.timer[0].counter = state->mfp.tadr; |
| 281 | 268 | mfp_trigger_irq(MFP_IRQ_TIMERA); |
| 282 | 269 | } |
| 283 | 270 | } |
| 284 | 271 | |
| 285 | 272 | TIMER_CALLBACK(mfp_timer_b_callback) |
| 286 | 273 | { |
| 287 | | x68k_sys.mfp.timer[1].counter--; |
| 288 | | if(x68k_sys.mfp.timer[1].counter == 0) |
| 274 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 275 | state->mfp.timer[1].counter--; |
| 276 | if(state->mfp.timer[1].counter == 0) |
| 289 | 277 | { |
| 290 | | x68k_sys.mfp.timer[1].counter = x68k_sys.mfp.tbdr; |
| 278 | state->mfp.timer[1].counter = state->mfp.tbdr; |
| 291 | 279 | mfp_trigger_irq(MFP_IRQ_TIMERB); |
| 292 | 280 | } |
| 293 | 281 | } |
| 294 | 282 | |
| 295 | 283 | TIMER_CALLBACK(mfp_timer_c_callback) |
| 296 | 284 | { |
| 297 | | x68k_sys.mfp.timer[2].counter--; |
| 298 | | if(x68k_sys.mfp.timer[2].counter == 0) |
| 285 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 286 | state->mfp.timer[2].counter--; |
| 287 | if(state->mfp.timer[2].counter == 0) |
| 299 | 288 | { |
| 300 | | x68k_sys.mfp.timer[2].counter = x68k_sys.mfp.tcdr; |
| 289 | state->mfp.timer[2].counter = state->mfp.tcdr; |
| 301 | 290 | mfp_trigger_irq(MFP_IRQ_TIMERC); |
| 302 | 291 | } |
| 303 | 292 | } |
| 304 | 293 | |
| 305 | 294 | TIMER_CALLBACK(mfp_timer_d_callback) |
| 306 | 295 | { |
| 307 | | x68k_sys.mfp.timer[3].counter--; |
| 308 | | if(x68k_sys.mfp.timer[3].counter == 0) |
| 296 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 297 | state->mfp.timer[3].counter--; |
| 298 | if(state->mfp.timer[3].counter == 0) |
| 309 | 299 | { |
| 310 | | x68k_sys.mfp.timer[3].counter = x68k_sys.mfp.tddr; |
| 300 | state->mfp.timer[3].counter = state->mfp.tddr; |
| 311 | 301 | mfp_trigger_irq(MFP_IRQ_TIMERD); |
| 312 | 302 | } |
| 313 | 303 | } |
| r9669 | r9670 | |
| 330 | 320 | // LED timer callback |
| 331 | 321 | static TIMER_CALLBACK( x68k_led_callback ) |
| 332 | 322 | { |
| 323 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 333 | 324 | int drive; |
| 334 | | if(led_state == 0) |
| 335 | | led_state = 1; |
| 325 | if(state->led_state == 0) |
| 326 | state->led_state = 1; |
| 336 | 327 | else |
| 337 | | led_state = 0; |
| 338 | | if(led_state == 1) |
| 328 | state->led_state = 0; |
| 329 | if(state->led_state == 1) |
| 339 | 330 | { |
| 340 | 331 | for(drive=0;drive<4;drive++) |
| 341 | | output_set_indexed_value("ctrl_drv",drive,x68k_sys.fdc.led_ctrl[drive] ? 0 : 1); |
| 332 | output_set_indexed_value("ctrl_drv",drive,state->fdc.led_ctrl[drive] ? 0 : 1); |
| 342 | 333 | } |
| 343 | 334 | else |
| 344 | 335 | { |
| r9669 | r9670 | |
| 361 | 352 | return hd63450_r(device, offset, mem_mask); |
| 362 | 353 | } |
| 363 | 354 | |
| 364 | | static void x68k_keyboard_ctrl_w(int data) |
| 355 | static void x68k_keyboard_ctrl_w(x68k_state *state, int data) |
| 365 | 356 | { |
| 366 | 357 | /* Keyboard control commands: |
| 367 | 358 | 00xxxxxx - TV Control |
| r9669 | r9670 | |
| 414 | 405 | |
| 415 | 406 | if((data & 0xf8) == 0x48) // Keyboard enable |
| 416 | 407 | { |
| 417 | | x68k_sys.keyboard.enabled = data & 0x01; |
| 418 | | logerror("KB: Keyboard enable bit = %i\n",x68k_sys.keyboard.enabled); |
| 408 | state->keyboard.enabled = data & 0x01; |
| 409 | logerror("KB: Keyboard enable bit = %i\n",state->keyboard.enabled); |
| 419 | 410 | } |
| 420 | 411 | |
| 421 | 412 | if((data & 0xf0) == 0x60) // Key delay time |
| 422 | 413 | { |
| 423 | | x68k_sys.keyboard.delay = data & 0x0f; |
| 414 | state->keyboard.delay = data & 0x0f; |
| 424 | 415 | logerror("KB: Keypress delay time is now %ims\n",(data & 0x0f)*100+200); |
| 425 | 416 | } |
| 426 | 417 | |
| 427 | 418 | if((data & 0xf0) == 0x70) // Key repeat rate |
| 428 | 419 | { |
| 429 | | x68k_sys.keyboard.repeat = data & 0x0f; |
| 420 | state->keyboard.repeat = data & 0x0f; |
| 430 | 421 | logerror("KB: Keypress repeat rate is now %ims\n",((data & 0x0f)^2)*5+30); |
| 431 | 422 | } |
| 432 | 423 | |
| 433 | 424 | } |
| 434 | 425 | |
| 435 | | static int x68k_keyboard_pop_scancode(void) |
| 426 | static int x68k_keyboard_pop_scancode(x68k_state *state) |
| 436 | 427 | { |
| 437 | 428 | int ret; |
| 438 | | if(x68k_sys.keyboard.keynum == 0) // no scancodes in USART buffer |
| 429 | if(state->keyboard.keynum == 0) // no scancodes in USART buffer |
| 439 | 430 | return 0x00; |
| 440 | 431 | |
| 441 | | x68k_sys.keyboard.keynum--; |
| 442 | | ret = x68k_sys.keyboard.buffer[x68k_sys.keyboard.tailpos++]; |
| 443 | | if(x68k_sys.keyboard.tailpos > 15) |
| 444 | | x68k_sys.keyboard.tailpos = 0; |
| 432 | state->keyboard.keynum--; |
| 433 | ret = state->keyboard.buffer[state->keyboard.tailpos++]; |
| 434 | if(state->keyboard.tailpos > 15) |
| 435 | state->keyboard.tailpos = 0; |
| 445 | 436 | |
| 446 | 437 | logerror("MFP: Keyboard buffer pop 0x%02x\n",ret); |
| 447 | 438 | return ret; |
| r9669 | r9670 | |
| 449 | 440 | |
| 450 | 441 | static void x68k_keyboard_push_scancode(running_machine* machine,unsigned char code) |
| 451 | 442 | { |
| 452 | | x68k_sys.keyboard.keynum++; |
| 453 | | if(x68k_sys.keyboard.keynum >= 1) |
| 443 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 444 | state->keyboard.keynum++; |
| 445 | if(state->keyboard.keynum >= 1) |
| 454 | 446 | { // keyboard buffer full |
| 455 | | if(x68k_sys.keyboard.enabled != 0) |
| 447 | if(state->keyboard.enabled != 0) |
| 456 | 448 | { |
| 457 | | x68k_sys.mfp.rsr |= 0x80; // Buffer full |
| 449 | state->mfp.rsr |= 0x80; // Buffer full |
| 458 | 450 | // mfp_trigger_irq(MFP_IRQ_RX_FULL); |
| 459 | 451 | if(input_port_read(machine,"options") & 0x01) |
| 460 | 452 | { |
| 461 | | current_vector[6] = 0x4c; |
| 453 | state->current_vector[6] = 0x4c; |
| 462 | 454 | cputag_set_input_line_and_vector(machine, "maincpu",6,ASSERT_LINE,0x4c); |
| 463 | 455 | logerror("MFP: Receive buffer full IRQ sent\n"); |
| 464 | 456 | } |
| 465 | 457 | } |
| 466 | 458 | } |
| 467 | | x68k_sys.keyboard.buffer[x68k_sys.keyboard.headpos++] = code; |
| 468 | | if(x68k_sys.keyboard.headpos > 15) |
| 459 | state->keyboard.buffer[state->keyboard.headpos++] = code; |
| 460 | if(state->keyboard.headpos > 15) |
| 469 | 461 | { |
| 470 | | x68k_sys.keyboard.headpos = 0; |
| 462 | state->keyboard.headpos = 0; |
| 471 | 463 | // mfp_trigger_irq(MFP_IRQ_RX_ERROR); |
| 472 | | current_vector[6] = 0x4b; |
| 464 | state->current_vector[6] = 0x4b; |
| 473 | 465 | // cputag_set_input_line_and_vector(machine, "maincpu",6,ASSERT_LINE,0x4b); |
| 474 | 466 | } |
| 475 | 467 | } |
| 476 | 468 | |
| 477 | 469 | static TIMER_CALLBACK(x68k_keyboard_poll) |
| 478 | 470 | { |
| 471 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 479 | 472 | int x; |
| 480 | 473 | static const char *const keynames[] = { "key1", "key2", "key3", "key4" }; |
| 481 | 474 | |
| 482 | 475 | for(x=0;x<0x80;x++) |
| 483 | 476 | { |
| 484 | 477 | // adjust delay/repeat timers |
| 485 | | if(x68k_sys.keyboard.keytime[x] > 0) |
| 478 | if(state->keyboard.keytime[x] > 0) |
| 486 | 479 | { |
| 487 | | x68k_sys.keyboard.keytime[x] -= 5; |
| 480 | state->keyboard.keytime[x] -= 5; |
| 488 | 481 | } |
| 489 | 482 | if(!(input_port_read(machine, keynames[x / 32]) & (1 << (x % 32)))) |
| 490 | 483 | { |
| 491 | | if(x68k_sys.keyboard.keyon[x] != 0) |
| 484 | if(state->keyboard.keyon[x] != 0) |
| 492 | 485 | { |
| 493 | 486 | x68k_keyboard_push_scancode(machine,0x80 + x); |
| 494 | | x68k_sys.keyboard.keytime[x] = 0; |
| 495 | | x68k_sys.keyboard.keyon[x] = 0; |
| 496 | | x68k_sys.keyboard.last_pressed = 0; |
| 487 | state->keyboard.keytime[x] = 0; |
| 488 | state->keyboard.keyon[x] = 0; |
| 489 | state->keyboard.last_pressed = 0; |
| 497 | 490 | logerror("KB: Released key 0x%02x\n",x); |
| 498 | 491 | } |
| 499 | 492 | } |
| 500 | 493 | // check to see if a key is being held |
| 501 | | if(x68k_sys.keyboard.keyon[x] != 0 && x68k_sys.keyboard.keytime[x] == 0 && x68k_sys.keyboard.last_pressed == x) |
| 494 | if(state->keyboard.keyon[x] != 0 && state->keyboard.keytime[x] == 0 && state->keyboard.last_pressed == x) |
| 502 | 495 | { |
| 503 | | if(input_port_read(machine, keynames[x68k_sys.keyboard.last_pressed / 32]) & (1 << (x68k_sys.keyboard.last_pressed % 32))) |
| 496 | if(input_port_read(machine, keynames[state->keyboard.last_pressed / 32]) & (1 << (state->keyboard.last_pressed % 32))) |
| 504 | 497 | { |
| 505 | | x68k_keyboard_push_scancode(machine,x68k_sys.keyboard.last_pressed); |
| 506 | | x68k_sys.keyboard.keytime[x68k_sys.keyboard.last_pressed] = (x68k_sys.keyboard.repeat^2)*5+30; |
| 507 | | logerror("KB: Holding key 0x%02x\n",x68k_sys.keyboard.last_pressed); |
| 498 | x68k_keyboard_push_scancode(machine,state->keyboard.last_pressed); |
| 499 | state->keyboard.keytime[state->keyboard.last_pressed] = (state->keyboard.repeat^2)*5+30; |
| 500 | logerror("KB: Holding key 0x%02x\n",state->keyboard.last_pressed); |
| 508 | 501 | } |
| 509 | 502 | } |
| 510 | 503 | if((input_port_read(machine, keynames[x / 32]) & (1 << (x % 32)))) |
| 511 | 504 | { |
| 512 | | if(x68k_sys.keyboard.keyon[x] == 0) |
| 505 | if(state->keyboard.keyon[x] == 0) |
| 513 | 506 | { |
| 514 | 507 | x68k_keyboard_push_scancode(machine,x); |
| 515 | | x68k_sys.keyboard.keytime[x] = x68k_sys.keyboard.delay * 100 + 200; |
| 516 | | x68k_sys.keyboard.keyon[x] = 1; |
| 517 | | x68k_sys.keyboard.last_pressed = x; |
| 508 | state->keyboard.keytime[x] = state->keyboard.delay * 100 + 200; |
| 509 | state->keyboard.keyon[x] = 1; |
| 510 | state->keyboard.last_pressed = x; |
| 518 | 511 | logerror("KB: Pushed key 0x%02x\n",x); |
| 519 | 512 | } |
| 520 | 513 | } |
| r9669 | r9670 | |
| 525 | 518 | #ifdef UNUSED_FUNCTION |
| 526 | 519 | void mfp_recv_data(int data) |
| 527 | 520 | { |
| 528 | | x68k_sys.mfp.rsr |= 0x80; // Buffer full |
| 529 | | x68k_sys.mfp.tsr |= 0x80; |
| 530 | | x68k_sys.mfp.usart.recv_buffer = 0x00; // TODO: set up keyboard data |
| 531 | | x68k_sys.mfp.vector = current_vector[6] = (x68k_sys.mfp.vr & 0xf0) | 0x0c; |
| 521 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 522 | state->mfp.rsr |= 0x80; // Buffer full |
| 523 | state->mfp.tsr |= 0x80; |
| 524 | state->mfp.usart.recv_buffer = 0x00; // TODO: set up keyboard data |
| 525 | state->mfp.vector = state->current_vector[6] = (state->mfp.vr & 0xf0) | 0x0c; |
| 532 | 526 | // mfp_trigger_irq(MFP_IRQ_RX_FULL); |
| 533 | 527 | // logerror("MFP: Receive buffer full IRQ sent\n"); |
| 534 | 528 | } |
| r9669 | r9670 | |
| 539 | 533 | // typically read from the SCC data port on receive buffer full interrupt per byte |
| 540 | 534 | static int x68k_read_mouse(running_machine *machine) |
| 541 | 535 | { |
| 536 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 542 | 537 | running_device *scc = machine->device("scc"); |
| 543 | 538 | char val = 0; |
| 544 | 539 | char ipt = 0; |
| r9669 | r9670 | |
| 546 | 541 | if(!(scc8530_get_reg_b(scc,5) & 0x02)) |
| 547 | 542 | return 0xff; |
| 548 | 543 | |
| 549 | | switch(x68k_sys.mouse.inputtype) |
| 544 | switch(state->mouse.inputtype) |
| 550 | 545 | { |
| 551 | 546 | case 0: |
| 552 | 547 | ipt = input_port_read(machine, "mouse1"); |
| 553 | 548 | break; |
| 554 | 549 | case 1: |
| 555 | 550 | val = input_port_read(machine, "mouse2"); |
| 556 | | ipt = val - x68k_sys.mouse.last_mouse_x; |
| 557 | | x68k_sys.mouse.last_mouse_x = val; |
| 551 | ipt = val - state->mouse.last_mouse_x; |
| 552 | state->mouse.last_mouse_x = val; |
| 558 | 553 | break; |
| 559 | 554 | case 2: |
| 560 | 555 | val = input_port_read(machine, "mouse3"); |
| 561 | | ipt = val - x68k_sys.mouse.last_mouse_y; |
| 562 | | x68k_sys.mouse.last_mouse_y = val; |
| 556 | ipt = val - state->mouse.last_mouse_y; |
| 557 | state->mouse.last_mouse_y = val; |
| 563 | 558 | break; |
| 564 | 559 | } |
| 565 | | x68k_sys.mouse.inputtype++; |
| 566 | | if(x68k_sys.mouse.inputtype > 2) |
| 560 | state->mouse.inputtype++; |
| 561 | if(state->mouse.inputtype > 2) |
| 567 | 562 | { |
| 568 | 563 | int i_val = scc8530_get_reg_b(scc, 0); |
| 569 | | x68k_sys.mouse.inputtype = 0; |
| 570 | | x68k_sys.mouse.bufferempty = 1; |
| 564 | state->mouse.inputtype = 0; |
| 565 | state->mouse.bufferempty = 1; |
| 571 | 566 | i_val &= ~0x01; |
| 572 | 567 | scc8530_set_reg_b(scc, 0, i_val); |
| 573 | 568 | logerror("SCC: mouse buffer empty\n"); |
| r9669 | r9670 | |
| 601 | 596 | } |
| 602 | 597 | } |
| 603 | 598 | |
| 604 | | static unsigned char scc_prev; |
| 605 | 599 | static WRITE16_HANDLER( x68k_scc_w ) |
| 606 | 600 | { |
| 601 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 607 | 602 | running_device *scc = space->machine->device("scc"); |
| 608 | 603 | offset %= 4; |
| 609 | 604 | |
| r9669 | r9670 | |
| 611 | 606 | { |
| 612 | 607 | case 0: |
| 613 | 608 | scc8530_w(scc, 0,(UINT8)data); |
| 614 | | if((scc8530_get_reg_b(scc, 5) & 0x02) != scc_prev) |
| 609 | if((scc8530_get_reg_b(scc, 5) & 0x02) != state->scc_prev) |
| 615 | 610 | { |
| 616 | 611 | if(scc8530_get_reg_b(scc, 5) & 0x02) // Request to Send |
| 617 | 612 | { |
| 618 | 613 | int val = scc8530_get_reg_b(scc, 0); |
| 619 | | x68k_sys.mouse.bufferempty = 0; |
| 614 | state->mouse.bufferempty = 0; |
| 620 | 615 | val |= 0x01; |
| 621 | 616 | scc8530_set_reg_b(scc, 0,val); |
| 622 | 617 | } |
| r9669 | r9670 | |
| 632 | 627 | scc8530_w(scc, 3,(UINT8)data); |
| 633 | 628 | break; |
| 634 | 629 | } |
| 635 | | scc_prev = scc8530_get_reg_b(scc, 5) & 0x02; |
| 630 | state->scc_prev = scc8530_get_reg_b(scc, 5) & 0x02; |
| 636 | 631 | } |
| 637 | 632 | |
| 638 | 633 | static TIMER_CALLBACK(x68k_scc_ack) |
| 639 | 634 | { |
| 635 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 640 | 636 | running_device *scc = machine->device("scc"); |
| 641 | | if(x68k_sys.mouse.bufferempty != 0) // nothing to do if the mouse data buffer is empty |
| 637 | if(state->mouse.bufferempty != 0) // nothing to do if the mouse data buffer is empty |
| 642 | 638 | return; |
| 643 | 639 | |
| 644 | | // if((x68k_sys.ioc.irqstatus & 0xc0) != 0) |
| 640 | // if((state->ioc.irqstatus & 0xc0) != 0) |
| 645 | 641 | // return; |
| 646 | 642 | |
| 647 | 643 | // hard-code the IRQ vector for now, until the SCC code is more complete |
| r9669 | r9670 | |
| 651 | 647 | { |
| 652 | 648 | if(scc8530_get_reg_b(scc, 5) & 0x02) // RTS signal |
| 653 | 649 | { |
| 654 | | x68k_sys.mouse.irqactive = 1; |
| 655 | | current_vector[5] = 0x54; |
| 656 | | current_irq_line = 5; |
| 650 | state->mouse.irqactive = 1; |
| 651 | state->current_vector[5] = 0x54; |
| 652 | state->current_irq_line = 5; |
| 657 | 653 | cputag_set_input_line_and_vector(machine, "maincpu",5,ASSERT_LINE,0x54); |
| 658 | 654 | } |
| 659 | 655 | } |
| r9669 | r9670 | |
| 662 | 658 | |
| 663 | 659 | static void x68k_set_adpcm(running_machine* machine) |
| 664 | 660 | { |
| 661 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 665 | 662 | running_device *dev = machine->device("hd63450"); |
| 666 | 663 | UINT32 rate = 0; |
| 667 | 664 | |
| 668 | | switch(x68k_sys.adpcm.rate & 0x0c) |
| 665 | switch(state->adpcm.rate & 0x0c) |
| 669 | 666 | { |
| 670 | 667 | case 0x00: |
| 671 | 668 | rate = 7812/2; |
| r9669 | r9670 | |
| 680 | 677 | logerror("PPI: Invalid ADPCM sample rate set.\n"); |
| 681 | 678 | rate = 15625/2; |
| 682 | 679 | } |
| 683 | | if(x68k_sys.adpcm.clock != 0) |
| 680 | if(state->adpcm.clock != 0) |
| 684 | 681 | rate = rate/2; |
| 685 | 682 | hd63450_set_timer(dev,3,ATTOTIME_IN_HZ(rate)); |
| 686 | 683 | } |
| r9669 | r9670 | |
| 693 | 690 | |
| 694 | 691 | static UINT8 md_3button_r(running_device* device, int port) |
| 695 | 692 | { |
| 693 | x68k_state *state = device->machine->driver_data<x68k_state>(); |
| 696 | 694 | if(port == 1) |
| 697 | 695 | { |
| 698 | 696 | UINT8 porta = input_port_read(device->machine,"md3b") & 0xff; |
| 699 | 697 | UINT8 portb = (input_port_read(device->machine,"md3b") >> 8) & 0xff; |
| 700 | | if(x68k_sys.mdctrl.mux1 & 0x10) |
| 698 | if(state->mdctrl.mux1 & 0x10) |
| 701 | 699 | { |
| 702 | 700 | return porta | 0x90; |
| 703 | 701 | } |
| r9669 | r9670 | |
| 710 | 708 | { |
| 711 | 709 | UINT8 porta = (input_port_read(device->machine,"md3b") >> 16) & 0xff; |
| 712 | 710 | UINT8 portb = (input_port_read(device->machine,"md3b") >> 24) & 0xff; |
| 713 | | if(x68k_sys.mdctrl.mux2 & 0x20) |
| 711 | if(state->mdctrl.mux2 & 0x20) |
| 714 | 712 | { |
| 715 | 713 | return porta | 0x90; |
| 716 | 714 | } |
| r9669 | r9670 | |
| 725 | 723 | // Megadrive 6 button gamepad |
| 726 | 724 | static TIMER_CALLBACK(md_6button_port1_timeout) |
| 727 | 725 | { |
| 728 | | x68k_sys.mdctrl.seq1 = 0; |
| 726 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 727 | state->mdctrl.seq1 = 0; |
| 729 | 728 | } |
| 730 | 729 | |
| 731 | 730 | static TIMER_CALLBACK(md_6button_port2_timeout) |
| 732 | 731 | { |
| 733 | | x68k_sys.mdctrl.seq2 = 0; |
| 732 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 733 | state->mdctrl.seq2 = 0; |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | static void md_6button_init(running_machine* machine) |
| 737 | 737 | { |
| 738 | | x68k_sys.mdctrl.io_timeout1 = timer_alloc(machine,md_6button_port1_timeout,NULL); |
| 739 | | x68k_sys.mdctrl.io_timeout2 = timer_alloc(machine,md_6button_port2_timeout,NULL); |
| 738 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 739 | state->mdctrl.io_timeout1 = timer_alloc(machine,md_6button_port1_timeout,NULL); |
| 740 | state->mdctrl.io_timeout2 = timer_alloc(machine,md_6button_port2_timeout,NULL); |
| 740 | 741 | } |
| 741 | 742 | |
| 742 | 743 | static UINT8 md_6button_r(running_device* device, int port) |
| 743 | 744 | { |
| 745 | x68k_state *state = device->machine->driver_data<x68k_state>(); |
| 744 | 746 | if(port == 1) |
| 745 | 747 | { |
| 746 | 748 | UINT8 porta = input_port_read(device->machine,"md6b") & 0xff; |
| 747 | 749 | UINT8 portb = (input_port_read(device->machine,"md6b") >> 8) & 0xff; |
| 748 | 750 | UINT8 extra = input_port_read(device->machine,"md6b_extra") & 0x0f; |
| 749 | 751 | |
| 750 | | switch(x68k_sys.mdctrl.seq1) |
| 752 | switch(state->mdctrl.seq1) |
| 751 | 753 | { |
| 752 | 754 | case 1: |
| 753 | 755 | default: |
| 754 | | if(x68k_sys.mdctrl.mux1 & 0x10) |
| 756 | if(state->mdctrl.mux1 & 0x10) |
| 755 | 757 | { |
| 756 | 758 | return porta | 0x90; |
| 757 | 759 | } |
| r9669 | r9670 | |
| 760 | 762 | return (portb & 0x60) | (porta & 0x03) | 0x90; |
| 761 | 763 | } |
| 762 | 764 | case 2: |
| 763 | | if(x68k_sys.mdctrl.mux1 & 0x10) |
| 765 | if(state->mdctrl.mux1 & 0x10) |
| 764 | 766 | { |
| 765 | 767 | return porta | 0x90; |
| 766 | 768 | } |
| r9669 | r9670 | |
| 769 | 771 | return (portb & 0x60) | 0x90; |
| 770 | 772 | } |
| 771 | 773 | case 3: |
| 772 | | if(x68k_sys.mdctrl.mux1 & 0x10) |
| 774 | if(state->mdctrl.mux1 & 0x10) |
| 773 | 775 | { |
| 774 | 776 | return (porta & 0x60) | (extra & 0x0f) | 0x90; |
| 775 | 777 | } |
| r9669 | r9670 | |
| 785 | 787 | UINT8 portb = (input_port_read(device->machine,"md6b") >> 24) & 0xff; |
| 786 | 788 | UINT8 extra = (input_port_read(device->machine,"md6b_extra") >> 4) & 0x0f; |
| 787 | 789 | |
| 788 | | switch(x68k_sys.mdctrl.seq2) |
| 790 | switch(state->mdctrl.seq2) |
| 789 | 791 | { |
| 790 | 792 | case 1: |
| 791 | 793 | default: |
| 792 | | if(x68k_sys.mdctrl.mux2 & 0x20) |
| 794 | if(state->mdctrl.mux2 & 0x20) |
| 793 | 795 | { |
| 794 | 796 | return porta | 0x90; |
| 795 | 797 | } |
| r9669 | r9670 | |
| 798 | 800 | return (portb & 0x60) | (porta & 0x03) | 0x90; |
| 799 | 801 | } |
| 800 | 802 | case 2: |
| 801 | | if(x68k_sys.mdctrl.mux2 & 0x20) |
| 803 | if(state->mdctrl.mux2 & 0x20) |
| 802 | 804 | { |
| 803 | 805 | return porta | 0x90; |
| 804 | 806 | } |
| r9669 | r9670 | |
| 807 | 809 | return (portb & 0x60) | 0x90; |
| 808 | 810 | } |
| 809 | 811 | case 3: |
| 810 | | if(x68k_sys.mdctrl.mux2 & 0x20) |
| 812 | if(state->mdctrl.mux2 & 0x20) |
| 811 | 813 | { |
| 812 | 814 | return (porta & 0x60) | (extra & 0x0f) | 0x90; |
| 813 | 815 | } |
| r9669 | r9670 | |
| 829 | 831 | // The buttons are read the same as normal, regardless of ctl. |
| 830 | 832 | static UINT8 xpd1lr_r(running_device* device, int port) |
| 831 | 833 | { |
| 834 | x68k_state *state = device->machine->driver_data<x68k_state>(); |
| 832 | 835 | if(port == 1) |
| 833 | 836 | { |
| 834 | 837 | UINT8 porta = input_port_read(device->machine,"xpd1lr") & 0xff; |
| 835 | 838 | UINT8 portb = (input_port_read(device->machine,"xpd1lr") >> 8) & 0xff; |
| 836 | | if(x68k_sys.mdctrl.mux1 & 0x10) |
| 839 | if(state->mdctrl.mux1 & 0x10) |
| 837 | 840 | { |
| 838 | 841 | return porta; |
| 839 | 842 | } |
| r9669 | r9670 | |
| 846 | 849 | { |
| 847 | 850 | UINT8 porta = (input_port_read(device->machine,"xpd1lr") >> 16) & 0xff; |
| 848 | 851 | UINT8 portb = (input_port_read(device->machine,"xpd1lr") >> 24) & 0xff; |
| 849 | | if(x68k_sys.mdctrl.mux2 & 0x20) |
| 852 | if(state->mdctrl.mux2 & 0x20) |
| 850 | 853 | { |
| 851 | 854 | return porta; |
| 852 | 855 | } |
| r9669 | r9670 | |
| 861 | 864 | // Judging from the XM6 source code, PPI ports A and B are joystick inputs |
| 862 | 865 | static READ8_DEVICE_HANDLER( ppi_port_a_r ) |
| 863 | 866 | { |
| 867 | x68k_state *state = device->machine->driver_data<x68k_state>(); |
| 864 | 868 | int ctrl = input_port_read(device->machine,"ctrltype") & 0x0f; |
| 865 | 869 | |
| 866 | 870 | switch(ctrl) |
| 867 | 871 | { |
| 868 | 872 | case 0x00: // standard MSX/FM-Towns joystick |
| 869 | | if(x68k_sys.joy.joy1_enable == 0) |
| 873 | if(state->joy.joy1_enable == 0) |
| 870 | 874 | return input_port_read(device->machine, "joy1"); |
| 871 | 875 | else |
| 872 | 876 | return 0xff; |
| r9669 | r9670 | |
| 883 | 887 | |
| 884 | 888 | static READ8_DEVICE_HANDLER( ppi_port_b_r ) |
| 885 | 889 | { |
| 890 | x68k_state *state = device->machine->driver_data<x68k_state>(); |
| 886 | 891 | int ctrl = input_port_read(device->machine,"ctrltype") & 0xf0; |
| 887 | 892 | |
| 888 | 893 | switch(ctrl) |
| 889 | 894 | { |
| 890 | 895 | case 0x00: // standard MSX/FM-Towns joystick |
| 891 | | if(x68k_sys.joy.joy2_enable == 0) |
| 896 | if(state->joy.joy2_enable == 0) |
| 892 | 897 | return input_port_read(device->machine, "joy2"); |
| 893 | 898 | else |
| 894 | 899 | return 0xff; |
| r9669 | r9670 | |
| 905 | 910 | |
| 906 | 911 | static READ8_DEVICE_HANDLER( ppi_port_c_r ) |
| 907 | 912 | { |
| 908 | | return ppi_port[2]; |
| 913 | x68k_state *state = device->machine->driver_data<x68k_state>(); |
| 914 | return state->ppi_port[2]; |
| 909 | 915 | } |
| 910 | 916 | |
| 911 | 917 | /* PPI port C (Joystick control, R/W) |
| r9669 | r9670 | |
| 916 | 922 | bits 3,2 - ADPCM Sample rate |
| 917 | 923 | bits 1,0 - ADPCM Pan |
| 918 | 924 | */ |
| 919 | | static UINT16 ppi_prev; |
| 920 | 925 | static WRITE8_DEVICE_HANDLER( ppi_port_c_w ) |
| 921 | 926 | { |
| 927 | x68k_state *state = device->machine->driver_data<x68k_state>(); |
| 922 | 928 | // ADPCM / Joystick control |
| 923 | 929 | running_device *oki = device->machine->device("okim6258"); |
| 924 | 930 | |
| 925 | | ppi_port[2] = data; |
| 926 | | if((data & 0x0f) != (ppi_prev & 0x0f)) |
| 931 | state->ppi_port[2] = data; |
| 932 | if((data & 0x0f) != (state->ppi_prev & 0x0f)) |
| 927 | 933 | { |
| 928 | | x68k_sys.adpcm.pan = data & 0x03; |
| 929 | | x68k_sys.adpcm.rate = data & 0x0c; |
| 934 | state->adpcm.pan = data & 0x03; |
| 935 | state->adpcm.rate = data & 0x0c; |
| 930 | 936 | x68k_set_adpcm(device->machine); |
| 931 | 937 | okim6258_set_divider(oki, (data >> 2) & 3); |
| 932 | 938 | } |
| 933 | 939 | |
| 934 | 940 | // The joystick enable bits also handle the multiplexer for various controllers |
| 935 | | x68k_sys.joy.joy1_enable = data & 0x10; |
| 936 | | x68k_sys.mdctrl.mux1 = data & 0x10; |
| 937 | | if((ppi_prev & 0x10) == 0x00 && (data & 0x10) == 0x10) |
| 941 | state->joy.joy1_enable = data & 0x10; |
| 942 | state->mdctrl.mux1 = data & 0x10; |
| 943 | if((state->ppi_prev & 0x10) == 0x00 && (data & 0x10) == 0x10) |
| 938 | 944 | { |
| 939 | | x68k_sys.mdctrl.seq1++; |
| 940 | | timer_adjust_oneshot(x68k_sys.mdctrl.io_timeout1,device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(8192),0); |
| 945 | state->mdctrl.seq1++; |
| 946 | timer_adjust_oneshot(state->mdctrl.io_timeout1,device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(8192),0); |
| 941 | 947 | } |
| 942 | 948 | |
| 943 | | x68k_sys.joy.joy2_enable = data & 0x20; |
| 944 | | x68k_sys.mdctrl.mux2 = data & 0x20; |
| 945 | | if((ppi_prev & 0x20) == 0x00 && (data & 0x20) == 0x20) |
| 949 | state->joy.joy2_enable = data & 0x20; |
| 950 | state->mdctrl.mux2 = data & 0x20; |
| 951 | if((state->ppi_prev & 0x20) == 0x00 && (data & 0x20) == 0x20) |
| 946 | 952 | { |
| 947 | | x68k_sys.mdctrl.seq2++; |
| 948 | | timer_adjust_oneshot(x68k_sys.mdctrl.io_timeout2,device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(8192),0); |
| 953 | state->mdctrl.seq2++; |
| 954 | timer_adjust_oneshot(state->mdctrl.io_timeout2,device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(8192),0); |
| 949 | 955 | } |
| 950 | | ppi_prev = data; |
| 956 | state->ppi_prev = data; |
| 951 | 957 | |
| 952 | | x68k_sys.joy.ioc6 = data & 0x40; |
| 953 | | x68k_sys.joy.ioc7 = data & 0x80; |
| 958 | state->joy.ioc6 = data & 0x40; |
| 959 | state->joy.ioc7 = data & 0x80; |
| 954 | 960 | } |
| 955 | 961 | |
| 956 | 962 | |
| 957 | 963 | // NEC uPD72065 at 0xe94000 |
| 958 | 964 | static WRITE16_HANDLER( x68k_fdc_w ) |
| 959 | 965 | { |
| 966 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 960 | 967 | running_device *fdc = space->machine->device("upd72065"); |
| 961 | 968 | unsigned int drive, x; |
| 962 | 969 | switch(offset) |
| r9669 | r9670 | |
| 969 | 976 | x = data & 0x0f; |
| 970 | 977 | for(drive=0;drive<4;drive++) |
| 971 | 978 | { |
| 972 | | if(x68k_sys.fdc.selected_drive & (1 << drive)) |
| 979 | if(state->fdc.selected_drive & (1 << drive)) |
| 973 | 980 | { |
| 974 | 981 | if(!(x & (1 << drive))) // functions take place on 1->0 transitions of drive bits only |
| 975 | 982 | { |
| 976 | | x68k_sys.fdc.led_ctrl[drive] = data & 0x80; // blinking drive LED if no disk inserted |
| 977 | | x68k_sys.fdc.led_eject[drive] = data & 0x40; // eject button LED (on when set to 0) |
| 983 | state->fdc.led_ctrl[drive] = data & 0x80; // blinking drive LED if no disk inserted |
| 984 | state->fdc.led_eject[drive] = data & 0x40; // eject button LED (on when set to 0) |
| 978 | 985 | output_set_indexed_value("eject_drv",drive,(data & 0x40) ? 1 : 0); |
| 979 | 986 | if(data & 0x20) // ejects disk |
| 980 | 987 | { |
| r9669 | r9670 | |
| 984 | 991 | } |
| 985 | 992 | } |
| 986 | 993 | } |
| 987 | | x68k_sys.fdc.selected_drive = data & 0x0f; |
| 994 | state->fdc.selected_drive = data & 0x0f; |
| 988 | 995 | logerror("FDC: signal control set to %02x\n",data); |
| 989 | 996 | break; |
| 990 | 997 | case 0x03: |
| 991 | | x68k_sys.fdc.media_density[data & 0x03] = data & 0x10; |
| 992 | | x68k_sys.fdc.motor[data & 0x03] = data & 0x80; |
| 998 | state->fdc.media_density[data & 0x03] = data & 0x10; |
| 999 | state->fdc.motor[data & 0x03] = data & 0x80; |
| 993 | 1000 | floppy_mon_w(floppy_get_device(space->machine, data & 0x03), !BIT(data, 7)); |
| 994 | 1001 | if(data & 0x80) |
| 995 | 1002 | { |
| r9669 | r9670 | |
| 1033 | 1040 | |
| 1034 | 1041 | static READ16_HANDLER( x68k_fdc_r ) |
| 1035 | 1042 | { |
| 1043 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1036 | 1044 | unsigned int ret; |
| 1037 | 1045 | int x; |
| 1038 | 1046 | running_device *fdc = space->machine->device("upd72065"); |
| r9669 | r9670 | |
| 1047 | 1055 | ret = 0x00; |
| 1048 | 1056 | for(x=0;x<4;x++) |
| 1049 | 1057 | { |
| 1050 | | if(x68k_sys.fdc.selected_drive & (1 << x)) |
| 1058 | if(state->fdc.selected_drive & (1 << x)) |
| 1051 | 1059 | { |
| 1052 | 1060 | ret = 0x00; |
| 1053 | | if(x68k_sys.fdc.disk_inserted[x] != 0) |
| 1061 | if(state->fdc.disk_inserted[x] != 0) |
| 1054 | 1062 | { |
| 1055 | 1063 | ret |= 0x80; |
| 1056 | 1064 | } |
| r9669 | r9670 | |
| 1071 | 1079 | |
| 1072 | 1080 | static WRITE_LINE_DEVICE_HANDLER( fdc_irq ) |
| 1073 | 1081 | { |
| 1074 | | if((x68k_sys.ioc.irqstatus & 0x04) && state == ASSERT_LINE) |
| 1082 | x68k_state *drvstate = device->machine->driver_data<x68k_state>(); |
| 1083 | if((drvstate->ioc.irqstatus & 0x04) && state == ASSERT_LINE) |
| 1075 | 1084 | { |
| 1076 | | current_vector[1] = x68k_sys.ioc.fdcvector; |
| 1077 | | x68k_sys.ioc.irqstatus |= 0x80; |
| 1078 | | current_irq_line = 1; |
| 1085 | drvstate->current_vector[1] = drvstate->ioc.fdcvector; |
| 1086 | drvstate->ioc.irqstatus |= 0x80; |
| 1087 | drvstate->current_irq_line = 1; |
| 1079 | 1088 | logerror("FDC: IRQ triggered\n"); |
| 1080 | | cputag_set_input_line_and_vector(device->machine, "maincpu", 1, ASSERT_LINE, current_vector[1]); |
| 1089 | cputag_set_input_line_and_vector(device->machine, "maincpu", 1, ASSERT_LINE, drvstate->current_vector[1]); |
| 1081 | 1090 | } |
| 1082 | 1091 | } |
| 1083 | 1092 | |
| 1084 | 1093 | static int x68k_fdc_read_byte(running_machine *machine,int addr) |
| 1085 | 1094 | { |
| 1095 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 1086 | 1096 | int data = -1; |
| 1087 | 1097 | running_device *fdc = machine->device("upd72065"); |
| 1088 | 1098 | |
| 1089 | | if(x68k_sys.fdc.drq_state != 0) |
| 1099 | if(state->fdc.drq_state != 0) |
| 1090 | 1100 | data = upd765_dack_r(fdc, 0); |
| 1091 | 1101 | // logerror("FDC: DACK reading\n"); |
| 1092 | 1102 | return data; |
| r9669 | r9670 | |
| 1100 | 1110 | |
| 1101 | 1111 | static WRITE_LINE_DEVICE_HANDLER ( fdc_drq ) |
| 1102 | 1112 | { |
| 1103 | | x68k_sys.fdc.drq_state = state; |
| 1113 | x68k_state *drvstate = device->machine->driver_data<x68k_state>(); |
| 1114 | drvstate->fdc.drq_state = state; |
| 1104 | 1115 | } |
| 1105 | 1116 | |
| 1106 | 1117 | static WRITE16_HANDLER( x68k_fm_w ) |
| r9669 | r9670 | |
| 1124 | 1135 | |
| 1125 | 1136 | static WRITE8_DEVICE_HANDLER( x68k_ct_w ) |
| 1126 | 1137 | { |
| 1138 | x68k_state *state = device->machine->driver_data<x68k_state>(); |
| 1127 | 1139 | running_device *fdc = device->machine->device("upd72065"); |
| 1128 | 1140 | running_device *okim = device->machine->device("okim6258"); |
| 1129 | 1141 | |
| r9669 | r9670 | |
| 1131 | 1143 | // CT1 - ADPCM clock - 0 = 8MHz, 1 = 4MHz |
| 1132 | 1144 | // CT2 - 1 = Set ready state of FDC |
| 1133 | 1145 | upd765_ready_w(fdc,data & 0x01); |
| 1134 | | x68k_sys.adpcm.clock = data & 0x02; |
| 1146 | state->adpcm.clock = data & 0x02; |
| 1135 | 1147 | x68k_set_adpcm(device->machine); |
| 1136 | 1148 | okim6258_set_clock(okim, data & 0x02 ? 4000000 : 8000000); |
| 1137 | 1149 | } |
| r9669 | r9670 | |
| 1154 | 1166 | */ |
| 1155 | 1167 | static WRITE16_HANDLER( x68k_ioc_w ) |
| 1156 | 1168 | { |
| 1169 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1157 | 1170 | switch(offset) |
| 1158 | 1171 | { |
| 1159 | 1172 | case 0x00: |
| 1160 | | x68k_sys.ioc.irqstatus = data & 0x0f; |
| 1173 | state->ioc.irqstatus = data & 0x0f; |
| 1161 | 1174 | logerror("I/O: Status register write %02x\n",data); |
| 1162 | 1175 | break; |
| 1163 | 1176 | case 0x01: |
| 1164 | 1177 | switch(data & 0x03) |
| 1165 | 1178 | { |
| 1166 | 1179 | case 0x00: |
| 1167 | | x68k_sys.ioc.fdcvector = data & 0xfc; |
| 1180 | state->ioc.fdcvector = data & 0xfc; |
| 1168 | 1181 | logerror("IOC: FDC IRQ vector = 0x%02x\n",data & 0xfc); |
| 1169 | 1182 | break; |
| 1170 | 1183 | case 0x01: |
| 1171 | | x68k_sys.ioc.fddvector = data & 0xfc; |
| 1184 | state->ioc.fddvector = data & 0xfc; |
| 1172 | 1185 | logerror("IOC: FDD IRQ vector = 0x%02x\n",data & 0xfc); |
| 1173 | 1186 | break; |
| 1174 | 1187 | case 0x02: |
| 1175 | | x68k_sys.ioc.hdcvector = data & 0xfc; |
| 1188 | state->ioc.hdcvector = data & 0xfc; |
| 1176 | 1189 | logerror("IOC: HDD IRQ vector = 0x%02x\n",data & 0xfc); |
| 1177 | 1190 | break; |
| 1178 | 1191 | case 0x03: |
| 1179 | | x68k_sys.ioc.prnvector = data & 0xfc; |
| 1192 | state->ioc.prnvector = data & 0xfc; |
| 1180 | 1193 | logerror("IOC: Printer IRQ vector = 0x%02x\n",data & 0xfc); |
| 1181 | 1194 | break; |
| 1182 | 1195 | } |
| r9669 | r9670 | |
| 1186 | 1199 | |
| 1187 | 1200 | static READ16_HANDLER( x68k_ioc_r ) |
| 1188 | 1201 | { |
| 1202 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1189 | 1203 | switch(offset) |
| 1190 | 1204 | { |
| 1191 | 1205 | case 0x00: |
| 1192 | 1206 | logerror("I/O: Status register read\n"); |
| 1193 | | return (x68k_sys.ioc.irqstatus & 0xdf) | 0x20; |
| 1207 | return (state->ioc.irqstatus & 0xdf) | 0x20; |
| 1194 | 1208 | default: |
| 1195 | 1209 | return 0x00; |
| 1196 | 1210 | } |
| r9669 | r9670 | |
| 1218 | 1232 | */ |
| 1219 | 1233 | static WRITE16_HANDLER( x68k_sysport_w ) |
| 1220 | 1234 | { |
| 1235 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1221 | 1236 | switch(offset) |
| 1222 | 1237 | { |
| 1223 | 1238 | case 0x00: |
| 1224 | | x68k_sys.sysport.contrast = data & 0x0f; // often used for screen fades / blanking |
| 1239 | state->sysport.contrast = data & 0x0f; // often used for screen fades / blanking |
| 1225 | 1240 | // TODO: implement a decent, not slow, brightness control |
| 1226 | 1241 | break; |
| 1227 | 1242 | case 0x01: |
| 1228 | | x68k_sys.sysport.monitor = data & 0x08; |
| 1243 | state->sysport.monitor = data & 0x08; |
| 1229 | 1244 | break; |
| 1230 | 1245 | case 0x03: |
| 1231 | | x68k_sys.sysport.keyctrl = data & 0x08; // bit 3 = enable keyboard data transmission |
| 1246 | state->sysport.keyctrl = data & 0x08; // bit 3 = enable keyboard data transmission |
| 1232 | 1247 | break; |
| 1233 | 1248 | case 0x06: |
| 1234 | | x68k_sys.sysport.sram_writeprotect = data; |
| 1249 | state->sysport.sram_writeprotect = data; |
| 1235 | 1250 | break; |
| 1236 | 1251 | default: |
| 1237 | 1252 | // logerror("SYS: [%08x] Wrote %04x to invalid or unimplemented system port %04x\n",cpu_get_pc(space->cpu),data,offset); |
| r9669 | r9670 | |
| 1241 | 1256 | |
| 1242 | 1257 | static READ16_HANDLER( x68k_sysport_r ) |
| 1243 | 1258 | { |
| 1259 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1244 | 1260 | int ret = 0; |
| 1245 | 1261 | switch(offset) |
| 1246 | 1262 | { |
| 1247 | 1263 | case 0x00: // monitor contrast setting (bits3-0) |
| 1248 | | return x68k_sys.sysport.contrast; |
| 1264 | return state->sysport.contrast; |
| 1249 | 1265 | case 0x01: // monitor control (bit3) / 3D Scope (bits1,0) |
| 1250 | | ret |= x68k_sys.sysport.monitor; |
| 1266 | ret |= state->sysport.monitor; |
| 1251 | 1267 | return ret; |
| 1252 | 1268 | case 0x03: // bit 3 = key control (is 1 if keyboard is connected) |
| 1253 | 1269 | return 0x08; |
| 1254 | 1270 | case 0x05: // CPU type and speed |
| 1255 | | return x68k_sys.sysport.cputype; |
| 1271 | return state->sysport.cputype; |
| 1256 | 1272 | default: |
| 1257 | 1273 | logerror("Read from invalid or unimplemented system port %04x\n",offset); |
| 1258 | 1274 | return 0xff; |
| r9669 | r9670 | |
| 1270 | 1286 | |
| 1271 | 1287 | static READ16_HANDLER( x68k_mfp_r ) |
| 1272 | 1288 | { |
| 1289 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1273 | 1290 | running_device *x68k_mfp = space->machine->device(MC68901_TAG); |
| 1274 | 1291 | // Initial settings indicate that IRQs are generated for FM (YM2151), Receive buffer error or full, |
| 1275 | 1292 | // MFP Timer C, and the power switch |
| r9669 | r9670 | |
| 1279 | 1296 | #if 0 |
| 1280 | 1297 | case 0x00: // GPIP - General purpose I/O register (read-only) |
| 1281 | 1298 | ret = 0x23; |
| 1282 | | if(machine->primary_screen->vpos() == x68k_sys.crtc.reg[9]) |
| 1299 | if(machine->primary_screen->vpos() == state->crtc.reg[9]) |
| 1283 | 1300 | ret |= 0x40; |
| 1284 | | if(x68k_sys.crtc.vblank == 0) |
| 1301 | if(state->crtc.vblank == 0) |
| 1285 | 1302 | ret |= 0x10; // Vsync signal (low if in vertical retrace) |
| 1286 | | // if(x68k_sys.mfp.isrb & 0x08) |
| 1303 | // if(state->mfp.isrb & 0x08) |
| 1287 | 1304 | // ret |= 0x08; // FM IRQ signal |
| 1288 | | if(machine->primary_screen->hpos() > x68k_sys.crtc.width - 32) |
| 1305 | if(machine->primary_screen->hpos() > state->crtc.width - 32) |
| 1289 | 1306 | ret |= 0x80; // Hsync signal |
| 1290 | 1307 | // logerror("MFP: [%08x] Reading offset %i (ret=%02x)\n",cpu_get_pc(space->cpu),offset,ret); |
| 1291 | 1308 | return ret; // bit 5 is always 1 |
| 1292 | 1309 | case 3: |
| 1293 | | return x68k_sys.mfp.iera; |
| 1310 | return state->mfp.iera; |
| 1294 | 1311 | case 4: |
| 1295 | | return x68k_sys.mfp.ierb; |
| 1312 | return state->mfp.ierb; |
| 1296 | 1313 | case 5: |
| 1297 | | return x68k_sys.mfp.ipra; |
| 1314 | return state->mfp.ipra; |
| 1298 | 1315 | case 6: |
| 1299 | | return x68k_sys.mfp.iprb; |
| 1316 | return state->mfp.iprb; |
| 1300 | 1317 | case 7: |
| 1301 | | if(x68k_sys.mfp.eoi_mode == 0) // forced low in auto EOI mode |
| 1318 | if(state->mfp.eoi_mode == 0) // forced low in auto EOI mode |
| 1302 | 1319 | return 0; |
| 1303 | 1320 | else |
| 1304 | | return x68k_sys.mfp.isra; |
| 1321 | return state->mfp.isra; |
| 1305 | 1322 | case 8: |
| 1306 | | if(x68k_sys.mfp.eoi_mode == 0) // forced low in auto EOI mode |
| 1323 | if(state->mfp.eoi_mode == 0) // forced low in auto EOI mode |
| 1307 | 1324 | return 0; |
| 1308 | 1325 | else |
| 1309 | | return x68k_sys.mfp.isrb; |
| 1326 | return state->mfp.isrb; |
| 1310 | 1327 | case 9: |
| 1311 | | return x68k_sys.mfp.imra; |
| 1328 | return state->mfp.imra; |
| 1312 | 1329 | case 10: |
| 1313 | | return x68k_sys.mfp.imrb; |
| 1330 | return state->mfp.imrb; |
| 1314 | 1331 | case 15: // TADR |
| 1315 | | return x68k_sys.mfp.timer[0].counter; // Timer data registers return their main counter values |
| 1332 | return state->mfp.timer[0].counter; // Timer data registers return their main counter values |
| 1316 | 1333 | case 16: // TBDR |
| 1317 | | return x68k_sys.mfp.timer[1].counter; |
| 1334 | return state->mfp.timer[1].counter; |
| 1318 | 1335 | case 17: // TCDR |
| 1319 | | return x68k_sys.mfp.timer[2].counter; |
| 1336 | return state->mfp.timer[2].counter; |
| 1320 | 1337 | case 18: // TDDR |
| 1321 | | return x68k_sys.mfp.timer[3].counter; |
| 1338 | return state->mfp.timer[3].counter; |
| 1322 | 1339 | #endif |
| 1323 | 1340 | case 21: // RSR |
| 1324 | | return x68k_sys.mfp.rsr; |
| 1341 | return state->mfp.rsr; |
| 1325 | 1342 | case 22: // TSR |
| 1326 | | return x68k_sys.mfp.tsr | 0x80; // buffer is typically empty? |
| 1343 | return state->mfp.tsr | 0x80; // buffer is typically empty? |
| 1327 | 1344 | case 23: |
| 1328 | | return x68k_keyboard_pop_scancode(); |
| 1345 | return x68k_keyboard_pop_scancode(state); |
| 1329 | 1346 | default: |
| 1330 | 1347 | if (ACCESSING_BITS_0_7) return mc68901_register_r(x68k_mfp, offset); |
| 1331 | 1348 | } |
| r9669 | r9670 | |
| 1334 | 1351 | |
| 1335 | 1352 | static WRITE16_HANDLER( x68k_mfp_w ) |
| 1336 | 1353 | { |
| 1354 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1337 | 1355 | running_device *x68k_mfp = space->machine->device(MC68901_TAG); |
| 1338 | 1356 | |
| 1339 | 1357 | /* For the Interrupt registers, the bits are set out as such: |
| r9669 | r9670 | |
| 1361 | 1379 | // All bits are inputs generally, so no action taken. |
| 1362 | 1380 | break; |
| 1363 | 1381 | case 1: // AER |
| 1364 | | x68k_sys.mfp.aer = data; |
| 1382 | state->mfp.aer = data; |
| 1365 | 1383 | break; |
| 1366 | 1384 | case 2: // DDR |
| 1367 | | x68k_sys.mfp.ddr = data; // usually all bits are 0 (input) |
| 1385 | state->mfp.ddr = data; // usually all bits are 0 (input) |
| 1368 | 1386 | break; |
| 1369 | 1387 | case 3: // IERA |
| 1370 | | x68k_sys.mfp.iera = data; |
| 1388 | state->mfp.iera = data; |
| 1371 | 1389 | break; |
| 1372 | 1390 | case 4: // IERB |
| 1373 | | x68k_sys.mfp.ierb = data; |
| 1391 | state->mfp.ierb = data; |
| 1374 | 1392 | break; |
| 1375 | 1393 | case 5: // IPRA |
| 1376 | | x68k_sys.mfp.ipra = data; |
| 1394 | state->mfp.ipra = data; |
| 1377 | 1395 | break; |
| 1378 | 1396 | case 6: // IPRB |
| 1379 | | x68k_sys.mfp.iprb = data; |
| 1397 | state->mfp.iprb = data; |
| 1380 | 1398 | break; |
| 1381 | 1399 | case 7: |
| 1382 | | x68k_sys.mfp.isra = data; |
| 1400 | state->mfp.isra = data; |
| 1383 | 1401 | break; |
| 1384 | 1402 | case 8: |
| 1385 | | x68k_sys.mfp.isrb = data; |
| 1403 | state->mfp.isrb = data; |
| 1386 | 1404 | break; |
| 1387 | 1405 | case 9: |
| 1388 | | x68k_sys.mfp.imra = data; |
| 1406 | state->mfp.imra = data; |
| 1389 | 1407 | // mfp_update_irq(0); |
| 1390 | 1408 | // logerror("MFP: IRQ Mask A write: %02x\n",data); |
| 1391 | 1409 | break; |
| 1392 | 1410 | case 10: |
| 1393 | | x68k_sys.mfp.imrb = data; |
| 1411 | state->mfp.imrb = data; |
| 1394 | 1412 | // mfp_update_irq(0); |
| 1395 | 1413 | // logerror("MFP: IRQ Mask B write: %02x\n",data); |
| 1396 | 1414 | break; |
| 1397 | 1415 | case 11: // VR |
| 1398 | | x68k_sys.mfp.vr = 0x40;//data; // High 4 bits = high 4 bits of IRQ vector |
| 1399 | | x68k_sys.mfp.eoi_mode = data & 0x08; // 0 = Auto, 1 = Software End-of-interrupt |
| 1400 | | if(x68k_sys.mfp.eoi_mode == 0) // In-service registers are cleared if this bit is cleared. |
| 1416 | state->mfp.vr = 0x40;//data; // High 4 bits = high 4 bits of IRQ vector |
| 1417 | state->mfp.eoi_mode = data & 0x08; // 0 = Auto, 1 = Software End-of-interrupt |
| 1418 | if(state->mfp.eoi_mode == 0) // In-service registers are cleared if this bit is cleared. |
| 1401 | 1419 | { |
| 1402 | | x68k_sys.mfp.isra = 0; |
| 1403 | | x68k_sys.mfp.isrb = 0; |
| 1420 | state->mfp.isra = 0; |
| 1421 | state->mfp.isrb = 0; |
| 1404 | 1422 | } |
| 1405 | 1423 | break; |
| 1406 | 1424 | case 12: // TACR |
| 1407 | | x68k_sys.mfp.tacr = data; |
| 1425 | state->mfp.tacr = data; |
| 1408 | 1426 | mfp_set_timer(0,data & 0x0f); |
| 1409 | 1427 | break; |
| 1410 | 1428 | case 13: // TBCR |
| 1411 | | x68k_sys.mfp.tbcr = data; |
| 1429 | state->mfp.tbcr = data; |
| 1412 | 1430 | mfp_set_timer(1,data & 0x0f); |
| 1413 | 1431 | break; |
| 1414 | 1432 | case 14: // TCDCR |
| 1415 | | x68k_sys.mfp.tcdcr = data; |
| 1433 | state->mfp.tcdcr = data; |
| 1416 | 1434 | mfp_set_timer(2,(data & 0x70)>>4); |
| 1417 | 1435 | mfp_set_timer(3,data & 0x07); |
| 1418 | 1436 | break; |
| 1419 | 1437 | case 15: // TADR |
| 1420 | | x68k_sys.mfp.tadr = data; |
| 1421 | | x68k_sys.mfp.timer[0].counter = data; |
| 1438 | state->mfp.tadr = data; |
| 1439 | state->mfp.timer[0].counter = data; |
| 1422 | 1440 | break; |
| 1423 | 1441 | case 16: // TBDR |
| 1424 | | x68k_sys.mfp.tbdr = data; |
| 1425 | | x68k_sys.mfp.timer[1].counter = data; |
| 1442 | state->mfp.tbdr = data; |
| 1443 | state->mfp.timer[1].counter = data; |
| 1426 | 1444 | break; |
| 1427 | 1445 | case 17: // TCDR |
| 1428 | | x68k_sys.mfp.tcdr = data; |
| 1429 | | x68k_sys.mfp.timer[2].counter = data; |
| 1446 | state->mfp.tcdr = data; |
| 1447 | state->mfp.timer[2].counter = data; |
| 1430 | 1448 | break; |
| 1431 | 1449 | case 18: // TDDR |
| 1432 | | x68k_sys.mfp.tddr = data; |
| 1433 | | x68k_sys.mfp.timer[3].counter = data; |
| 1450 | state->mfp.tddr = data; |
| 1451 | state->mfp.timer[3].counter = data; |
| 1434 | 1452 | break; |
| 1435 | 1453 | case 20: |
| 1436 | | x68k_sys.mfp.ucr = data; |
| 1454 | state->mfp.ucr = data; |
| 1437 | 1455 | break; |
| 1438 | 1456 | #endif |
| 1439 | 1457 | case 21: |
| 1440 | 1458 | if(data & 0x01) |
| 1441 | | x68k_sys.mfp.usart.recv_enable = 1; |
| 1459 | state->mfp.usart.recv_enable = 1; |
| 1442 | 1460 | else |
| 1443 | | x68k_sys.mfp.usart.recv_enable = 0; |
| 1461 | state->mfp.usart.recv_enable = 0; |
| 1444 | 1462 | break; |
| 1445 | 1463 | case 22: |
| 1446 | 1464 | if(data & 0x01) |
| 1447 | | x68k_sys.mfp.usart.send_enable = 1; |
| 1465 | state->mfp.usart.send_enable = 1; |
| 1448 | 1466 | else |
| 1449 | | x68k_sys.mfp.usart.send_enable = 0; |
| 1467 | state->mfp.usart.send_enable = 0; |
| 1450 | 1468 | break; |
| 1451 | 1469 | case 23: |
| 1452 | | if(x68k_sys.mfp.usart.send_enable != 0) |
| 1470 | if(state->mfp.usart.send_enable != 0) |
| 1453 | 1471 | { |
| 1454 | 1472 | // Keyboard control command. |
| 1455 | | x68k_sys.mfp.usart.send_buffer = data; |
| 1456 | | x68k_keyboard_ctrl_w(data); |
| 1473 | state->mfp.usart.send_buffer = data; |
| 1474 | x68k_keyboard_ctrl_w(state, data); |
| 1457 | 1475 | // logerror("MFP: [%08x] USART Sent data %04x\n",cpu_get_pc(space->cpu),data); |
| 1458 | 1476 | } |
| 1459 | 1477 | break; |
| r9669 | r9670 | |
| 1484 | 1502 | rp5c15_w(device, offset, data, mem_mask); |
| 1485 | 1503 | } |
| 1486 | 1504 | |
| 1487 | | static void x68k_rtc_alarm_irq(int state) |
| 1505 | static void x68k_rtc_alarm_irq(running_machine *machine, int state) |
| 1488 | 1506 | { |
| 1489 | | if(x68k_sys.mfp.aer & 0x01) |
| 1507 | x68k_state *drvstate = machine->driver_data<x68k_state>(); |
| 1508 | if(drvstate->mfp.aer & 0x01) |
| 1490 | 1509 | { |
| 1491 | 1510 | if(state == 1) |
| 1492 | | x68k_sys.mfp.gpio |= 0x01; |
| 1511 | drvstate->mfp.gpio |= 0x01; |
| 1493 | 1512 | //mfp_trigger_irq(MFP_IRQ_GPIP0); // RTC ALARM |
| 1494 | 1513 | } |
| 1495 | 1514 | else |
| 1496 | 1515 | { |
| 1497 | 1516 | if(state == 0) |
| 1498 | | x68k_sys.mfp.gpio &= ~0x01; |
| 1517 | drvstate->mfp.gpio &= ~0x01; |
| 1499 | 1518 | //mfp_trigger_irq(MFP_IRQ_GPIP0); // RTC ALARM |
| 1500 | 1519 | } |
| 1501 | 1520 | } |
| r9669 | r9670 | |
| 1505 | 1524 | { |
| 1506 | 1525 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1507 | 1526 | |
| 1508 | | if(x68k_sys.sysport.sram_writeprotect == 0x31) |
| 1527 | if(state->sysport.sram_writeprotect == 0x31) |
| 1509 | 1528 | { |
| 1510 | 1529 | COMBINE_DATA(state->m_nvram + offset); |
| 1511 | 1530 | } |
| r9669 | r9670 | |
| 1549 | 1568 | static WRITE32_HANDLER( x68k_sram32_w ) |
| 1550 | 1569 | { |
| 1551 | 1570 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1552 | | if(x68k_sys.sysport.sram_writeprotect == 0x31) |
| 1571 | if(state->sysport.sram_writeprotect == 0x31) |
| 1553 | 1572 | { |
| 1554 | 1573 | COMBINE_DATA(state->m_nvram + offset); |
| 1555 | 1574 | } |
| r9669 | r9670 | |
| 1557 | 1576 | |
| 1558 | 1577 | static WRITE16_HANDLER( x68k_vid_w ) |
| 1559 | 1578 | { |
| 1579 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1560 | 1580 | int val; |
| 1561 | 1581 | if(offset < 0x100) // Graphic layer palette |
| 1562 | 1582 | { |
| 1563 | | COMBINE_DATA(x68k_sys.video.gfx_pal+offset); |
| 1564 | | val = x68k_sys.video.gfx_pal[offset]; |
| 1583 | COMBINE_DATA(state->video.gfx_pal+offset); |
| 1584 | val = state->video.gfx_pal[offset]; |
| 1565 | 1585 | palette_set_color_rgb(space->machine,offset,(val & 0x07c0) >> 3,(val & 0xf800) >> 8,(val & 0x003e) << 2); |
| 1566 | 1586 | return; |
| 1567 | 1587 | } |
| 1568 | 1588 | |
| 1569 | 1589 | if(offset >= 0x100 && offset < 0x200) // Text / Sprites / Tilemap palette |
| 1570 | 1590 | { |
| 1571 | | COMBINE_DATA(x68k_sys.video.text_pal+(offset-0x100)); |
| 1572 | | val = x68k_sys.video.text_pal[offset-0x100]; |
| 1591 | COMBINE_DATA(state->video.text_pal+(offset-0x100)); |
| 1592 | val = state->video.text_pal[offset-0x100]; |
| 1573 | 1593 | palette_set_color_rgb(space->machine,offset,(val & 0x07c0) >> 3,(val & 0xf800) >> 8,(val & 0x003e) << 2); |
| 1574 | 1594 | return; |
| 1575 | 1595 | } |
| r9669 | r9670 | |
| 1577 | 1597 | switch(offset) |
| 1578 | 1598 | { |
| 1579 | 1599 | case 0x200: |
| 1580 | | COMBINE_DATA(x68k_sys.video.reg); |
| 1600 | COMBINE_DATA(state->video.reg); |
| 1581 | 1601 | break; |
| 1582 | 1602 | case 0x280: // priority levels |
| 1583 | | COMBINE_DATA(x68k_sys.video.reg+1); |
| 1603 | COMBINE_DATA(state->video.reg+1); |
| 1584 | 1604 | if(ACCESSING_BITS_0_7) |
| 1585 | 1605 | { |
| 1586 | | x68k_sys.video.gfxlayer_pri[0] = data & 0x0003; |
| 1587 | | x68k_sys.video.gfxlayer_pri[1] = (data & 0x000c) >> 2; |
| 1588 | | x68k_sys.video.gfxlayer_pri[2] = (data & 0x0030) >> 4; |
| 1589 | | x68k_sys.video.gfxlayer_pri[3] = (data & 0x00c0) >> 6; |
| 1606 | state->video.gfxlayer_pri[0] = data & 0x0003; |
| 1607 | state->video.gfxlayer_pri[1] = (data & 0x000c) >> 2; |
| 1608 | state->video.gfxlayer_pri[2] = (data & 0x0030) >> 4; |
| 1609 | state->video.gfxlayer_pri[3] = (data & 0x00c0) >> 6; |
| 1590 | 1610 | } |
| 1591 | 1611 | if(ACCESSING_BITS_8_15) |
| 1592 | 1612 | { |
| 1593 | | x68k_sys.video.gfx_pri = (data & 0x0300) >> 8; |
| 1594 | | x68k_sys.video.text_pri = (data & 0x0c00) >> 10; |
| 1595 | | x68k_sys.video.sprite_pri = (data & 0x3000) >> 12; |
| 1596 | | if(x68k_sys.video.gfx_pri == 3) |
| 1597 | | x68k_sys.video.gfx_pri--; |
| 1598 | | if(x68k_sys.video.text_pri == 3) |
| 1599 | | x68k_sys.video.text_pri--; |
| 1600 | | if(x68k_sys.video.sprite_pri == 3) |
| 1601 | | x68k_sys.video.sprite_pri--; |
| 1613 | state->video.gfx_pri = (data & 0x0300) >> 8; |
| 1614 | state->video.text_pri = (data & 0x0c00) >> 10; |
| 1615 | state->video.sprite_pri = (data & 0x3000) >> 12; |
| 1616 | if(state->video.gfx_pri == 3) |
| 1617 | state->video.gfx_pri--; |
| 1618 | if(state->video.text_pri == 3) |
| 1619 | state->video.text_pri--; |
| 1620 | if(state->video.sprite_pri == 3) |
| 1621 | state->video.sprite_pri--; |
| 1602 | 1622 | } |
| 1603 | 1623 | break; |
| 1604 | 1624 | case 0x300: |
| 1605 | | COMBINE_DATA(x68k_sys.video.reg+2); |
| 1625 | COMBINE_DATA(state->video.reg+2); |
| 1606 | 1626 | break; |
| 1607 | 1627 | default: |
| 1608 | 1628 | logerror("VC: Invalid video controller write (offset = 0x%04x, data = %04x)\n",offset,data); |
| r9669 | r9670 | |
| 1611 | 1631 | |
| 1612 | 1632 | static READ16_HANDLER( x68k_vid_r ) |
| 1613 | 1633 | { |
| 1634 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1614 | 1635 | if(offset < 0x100) |
| 1615 | | return x68k_sys.video.gfx_pal[offset]; |
| 1636 | return state->video.gfx_pal[offset]; |
| 1616 | 1637 | |
| 1617 | 1638 | if(offset >= 0x100 && offset < 0x200) |
| 1618 | | return x68k_sys.video.text_pal[offset-0x100]; |
| 1639 | return state->video.text_pal[offset-0x100]; |
| 1619 | 1640 | |
| 1620 | 1641 | switch(offset) |
| 1621 | 1642 | { |
| 1622 | 1643 | case 0x200: |
| 1623 | | return x68k_sys.video.reg[0]; |
| 1644 | return state->video.reg[0]; |
| 1624 | 1645 | case 0x280: |
| 1625 | | return x68k_sys.video.reg[1]; |
| 1646 | return state->video.reg[1]; |
| 1626 | 1647 | case 0x300: |
| 1627 | | return x68k_sys.video.reg[2]; |
| 1648 | return state->video.reg[2]; |
| 1628 | 1649 | default: |
| 1629 | 1650 | logerror("VC: Invalid video controller read (offset = 0x%04x)\n",offset); |
| 1630 | 1651 | } |
| r9669 | r9670 | |
| 1690 | 1711 | |
| 1691 | 1712 | static READ16_HANDLER( x68k_rom0_r ) |
| 1692 | 1713 | { |
| 1714 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1693 | 1715 | /* this location contains the address of some expansion device ROM, if no ROM exists, |
| 1694 | 1716 | then access causes a bus error */ |
| 1695 | | current_vector[2] = 0x02; // bus error |
| 1696 | | current_irq_line = 2; |
| 1697 | | // cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,current_vector[2]); |
| 1717 | state->current_vector[2] = 0x02; // bus error |
| 1718 | state->current_irq_line = 2; |
| 1719 | // cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,state->current_vector[2]); |
| 1698 | 1720 | if(input_port_read(space->machine, "options") & 0x02) |
| 1699 | 1721 | { |
| 1700 | 1722 | offset *= 2; |
| r9669 | r9670 | |
| 1707 | 1729 | |
| 1708 | 1730 | static WRITE16_HANDLER( x68k_rom0_w ) |
| 1709 | 1731 | { |
| 1732 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1710 | 1733 | /* this location contains the address of some expansion device ROM, if no ROM exists, |
| 1711 | 1734 | then access causes a bus error */ |
| 1712 | | current_vector[2] = 0x02; // bus error |
| 1713 | | current_irq_line = 2; |
| 1714 | | // cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,current_vector[2]); |
| 1735 | state->current_vector[2] = 0x02; // bus error |
| 1736 | state->current_irq_line = 2; |
| 1737 | // cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,state->current_vector[2]); |
| 1715 | 1738 | if(input_port_read(space->machine, "options") & 0x02) |
| 1716 | 1739 | { |
| 1717 | 1740 | offset *= 2; |
| r9669 | r9670 | |
| 1723 | 1746 | |
| 1724 | 1747 | static READ16_HANDLER( x68k_emptyram_r ) |
| 1725 | 1748 | { |
| 1749 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1726 | 1750 | /* this location is unused RAM, access here causes a bus error |
| 1727 | 1751 | Often a method for detecting amount of installed RAM, is to read or write at 1MB intervals, until a bus error occurs */ |
| 1728 | | current_vector[2] = 0x02; // bus error |
| 1729 | | current_irq_line = 2; |
| 1730 | | // cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,current_vector[2]); |
| 1752 | state->current_vector[2] = 0x02; // bus error |
| 1753 | state->current_irq_line = 2; |
| 1754 | // cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,state->current_vector[2]); |
| 1731 | 1755 | if(input_port_read(space->machine, "options") & 0x02) |
| 1732 | 1756 | { |
| 1733 | 1757 | offset *= 2; |
| r9669 | r9670 | |
| 1740 | 1764 | |
| 1741 | 1765 | static WRITE16_HANDLER( x68k_emptyram_w ) |
| 1742 | 1766 | { |
| 1767 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1743 | 1768 | /* this location is unused RAM, access here causes a bus error |
| 1744 | 1769 | Often a method for detecting amount of installed RAM, is to read or write at 1MB intervals, until a bus error occurs */ |
| 1745 | | current_vector[2] = 0x02; // bus error |
| 1746 | | current_irq_line = 2; |
| 1747 | | // cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,current_vector[2]); |
| 1770 | state->current_vector[2] = 0x02; // bus error |
| 1771 | state->current_irq_line = 2; |
| 1772 | // cputag_set_input_line_and_vector(space->machine, "maincpu",2,ASSERT_LINE,state->current_vector[2]); |
| 1748 | 1773 | if(input_port_read(space->machine, "options") & 0x02) |
| 1749 | 1774 | { |
| 1750 | 1775 | offset *= 2; |
| r9669 | r9670 | |
| 1756 | 1781 | |
| 1757 | 1782 | static READ16_HANDLER( x68k_exp_r ) |
| 1758 | 1783 | { |
| 1784 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1759 | 1785 | /* These are expansion devices, if not present, they cause a bus error */ |
| 1760 | 1786 | if(input_port_read(space->machine, "options") & 0x02) |
| 1761 | 1787 | { |
| 1762 | | current_vector[2] = 0x02; // bus error |
| 1763 | | current_irq_line = 2; |
| 1788 | state->current_vector[2] = 0x02; // bus error |
| 1789 | state->current_irq_line = 2; |
| 1764 | 1790 | offset *= 2; |
| 1765 | 1791 | if(ACCESSING_BITS_0_7) |
| 1766 | 1792 | offset++; |
| 1767 | 1793 | timer_set(space->machine, space->machine->device<cpu_device>("maincpu")->cycles_to_attotime(16), NULL, 0xeafa00+offset,x68k_fake_bus_error); |
| 1768 | | // cputag_set_input_line_and_vector(machine, "maincpu",2,ASSERT_LINE,current_vector[2]); |
| 1794 | // cputag_set_input_line_and_vector(machine, "maincpu",2,ASSERT_LINE,state->current_vector[2]); |
| 1769 | 1795 | } |
| 1770 | 1796 | return 0xffff; |
| 1771 | 1797 | } |
| 1772 | 1798 | |
| 1773 | 1799 | static WRITE16_HANDLER( x68k_exp_w ) |
| 1774 | 1800 | { |
| 1801 | x68k_state *state = space->machine->driver_data<x68k_state>(); |
| 1775 | 1802 | /* These are expansion devices, if not present, they cause a bus error */ |
| 1776 | 1803 | if(input_port_read(space->machine, "options") & 0x02) |
| 1777 | 1804 | { |
| 1778 | | current_vector[2] = 0x02; // bus error |
| 1779 | | current_irq_line = 2; |
| 1805 | state->current_vector[2] = 0x02; // bus error |
| 1806 | state->current_irq_line = 2; |
| 1780 | 1807 | offset *= 2; |
| 1781 | 1808 | if(ACCESSING_BITS_0_7) |
| 1782 | 1809 | offset++; |
| 1783 | 1810 | timer_set(space->machine, space->machine->device<cpu_device>("maincpu")->cycles_to_attotime(16), NULL, 0xeafa00+offset,x68k_fake_bus_error); |
| 1784 | | // cputag_set_input_line_and_vector(machine, "maincpu",2,ASSERT_LINE,current_vector[2]); |
| 1811 | // cputag_set_input_line_and_vector(machine, "maincpu",2,ASSERT_LINE,state->current_vector[2]); |
| 1785 | 1812 | } |
| 1786 | 1813 | } |
| 1787 | 1814 | |
| 1788 | 1815 | static void x68k_dma_irq(running_machine *machine, int channel) |
| 1789 | 1816 | { |
| 1817 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 1790 | 1818 | running_device *device = machine->device("hd63450"); |
| 1791 | | current_vector[3] = hd63450_get_vector(device, channel); |
| 1792 | | current_irq_line = 3; |
| 1793 | | logerror("DMA#%i: DMA End (vector 0x%02x)\n",channel,current_vector[3]); |
| 1794 | | cputag_set_input_line_and_vector(machine, "maincpu",3,ASSERT_LINE,current_vector[3]); |
| 1819 | state->current_vector[3] = hd63450_get_vector(device, channel); |
| 1820 | state->current_irq_line = 3; |
| 1821 | logerror("DMA#%i: DMA End (vector 0x%02x)\n",channel,state->current_vector[3]); |
| 1822 | cputag_set_input_line_and_vector(machine, "maincpu",3,ASSERT_LINE,state->current_vector[3]); |
| 1795 | 1823 | } |
| 1796 | 1824 | |
| 1797 | 1825 | static void x68k_dma_end(running_machine *machine, int channel,int irq) |
| r9669 | r9670 | |
| 1804 | 1832 | |
| 1805 | 1833 | static void x68k_dma_error(running_machine *machine, int channel, int irq) |
| 1806 | 1834 | { |
| 1835 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 1807 | 1836 | running_device *device = machine->device("hd63450"); |
| 1808 | 1837 | if(irq != 0) |
| 1809 | 1838 | { |
| 1810 | | current_vector[3] = hd63450_get_error_vector(device,channel); |
| 1811 | | current_irq_line = 3; |
| 1812 | | cputag_set_input_line_and_vector(machine, "maincpu",3,ASSERT_LINE,current_vector[3]); |
| 1839 | state->current_vector[3] = hd63450_get_error_vector(device,channel); |
| 1840 | state->current_irq_line = 3; |
| 1841 | cputag_set_input_line_and_vector(machine, "maincpu",3,ASSERT_LINE,state->current_vector[3]); |
| 1813 | 1842 | } |
| 1814 | 1843 | } |
| 1815 | 1844 | |
| 1816 | 1845 | static void x68k_fm_irq(running_device *device, int irq) |
| 1817 | 1846 | { |
| 1847 | x68k_state *state = device->machine->driver_data<x68k_state>(); |
| 1818 | 1848 | if(irq == CLEAR_LINE) |
| 1819 | 1849 | { |
| 1820 | | x68k_sys.mfp.gpio |= 0x08; |
| 1850 | state->mfp.gpio |= 0x08; |
| 1821 | 1851 | } |
| 1822 | 1852 | else |
| 1823 | 1853 | { |
| 1824 | | x68k_sys.mfp.gpio &= ~0x08; |
| 1854 | state->mfp.gpio &= ~0x08; |
| 1825 | 1855 | } |
| 1826 | 1856 | } |
| 1827 | 1857 | |
| 1828 | 1858 | static READ8_DEVICE_HANDLER( mfp_gpio_r ) |
| 1829 | 1859 | { |
| 1830 | | UINT8 data = x68k_sys.mfp.gpio; |
| 1860 | x68k_state *state = device->machine->driver_data<x68k_state>(); |
| 1861 | UINT8 data = state->mfp.gpio; |
| 1831 | 1862 | |
| 1832 | | data &= ~(x68k_sys.crtc.hblank << 7); |
| 1833 | | data &= ~(x68k_sys.crtc.vblank << 4); |
| 1863 | data &= ~(state->crtc.hblank << 7); |
| 1864 | data &= ~(state->crtc.vblank << 4); |
| 1834 | 1865 | data |= 0x23; // GPIP5 is unused, always 1 |
| 1835 | 1866 | |
| 1836 | | // mc68901_tai_w(mfp, x68k_sys.crtc.vblank); |
| 1867 | // mc68901_tai_w(mfp, state->crtc.vblank); |
| 1837 | 1868 | |
| 1838 | 1869 | return data; |
| 1839 | 1870 | } |
| r9669 | r9670 | |
| 1851 | 1882 | } |
| 1852 | 1883 | } |
| 1853 | 1884 | |
| 1854 | | static int mfp_prev; |
| 1855 | 1885 | static WRITE_LINE_DEVICE_HANDLER( mfp_irq_callback ) |
| 1856 | 1886 | { |
| 1857 | | if(mfp_prev == CLEAR_LINE && state == CLEAR_LINE) // eliminate unnecessary calls to set the IRQ line for speed reasons |
| 1887 | x68k_state *drvstate = device->machine->driver_data<x68k_state>(); |
| 1888 | if(drvstate->mfp_prev == CLEAR_LINE && state == CLEAR_LINE) // eliminate unnecessary calls to set the IRQ line for speed reasons |
| 1858 | 1889 | return; |
| 1859 | 1890 | if(state != CLEAR_LINE) |
| 1860 | 1891 | state = HOLD_LINE; // to get around erroneous spurious interrupt |
| 1861 | | // if((x68k_sys.ioc.irqstatus & 0xc0) != 0) // if the FDC is busy, then we don't want to miss that IRQ |
| 1892 | // if((state->ioc.irqstatus & 0xc0) != 0) // if the FDC is busy, then we don't want to miss that IRQ |
| 1862 | 1893 | // return; |
| 1863 | 1894 | cputag_set_input_line(device->machine, "maincpu", 6, state); |
| 1864 | | current_vector[6] = 0; |
| 1865 | | mfp_prev = state; |
| 1895 | drvstate->current_vector[6] = 0; |
| 1896 | drvstate->mfp_prev = state; |
| 1866 | 1897 | } |
| 1867 | 1898 | |
| 1868 | 1899 | static INTERRUPT_GEN( x68k_vsync_irq ) |
| 1869 | 1900 | { |
| 1870 | | // if(x68k_sys.mfp.ierb & 0x40) |
| 1871 | | // { |
| 1872 | | // x68k_sys.mfp.isrb |= 0x40; |
| 1873 | | // current_vector[6] = (x68k_sys.mfp.vr & 0xf0) | 0x06; // GPIP4 (V-DISP) |
| 1874 | | // current_irq_line = 6; |
| 1875 | | // mfp_timer_a_callback(0); // Timer A is usually always in event count mode, and is tied to V-DISP |
| 1876 | | // mfp_trigger_irq(MFP_IRQ_GPIP4); |
| 1877 | | // } |
| 1878 | | // if(x68k_sys.crtc.height == 256) |
| 1879 | | // machine->primary_screen->update_partial(256);//x68k_sys.crtc.reg[4]/2); |
| 1880 | | // else |
| 1881 | | // machine->primary_screen->update_partial(512);//x68k_sys.crtc.reg[4]); |
| 1901 | #if 0 |
| 1902 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 1903 | if(state->mfp.ierb & 0x40) |
| 1904 | { |
| 1905 | state->mfp.isrb |= 0x40; |
| 1906 | state->current_vector[6] = (state->mfp.vr & 0xf0) | 0x06; // GPIP4 (V-DISP) |
| 1907 | state->current_irq_line = 6; |
| 1908 | mfp_timer_a_callback(0); // Timer A is usually always in event count mode, and is tied to V-DISP |
| 1909 | mfp_trigger_irq(MFP_IRQ_GPIP4); |
| 1910 | } |
| 1911 | if(state->crtc.height == 256) |
| 1912 | machine->primary_screen->update_partial(256);//state->crtc.reg[4]/2); |
| 1913 | else |
| 1914 | machine->primary_screen->update_partial(512);//state->crtc.reg[4]); |
| 1915 | #endif |
| 1882 | 1916 | } |
| 1883 | 1917 | |
| 1884 | 1918 | static IRQ_CALLBACK(x68k_int_ack) |
| 1885 | 1919 | { |
| 1920 | x68k_state *state = device->machine->driver_data<x68k_state>(); |
| 1886 | 1921 | running_device *x68k_mfp = device->machine->device(MC68901_TAG); |
| 1887 | 1922 | |
| 1888 | 1923 | if(irqline == 6) // MFP |
| 1889 | 1924 | { |
| 1890 | | x68k_sys.mfp.current_irq = -1; |
| 1891 | | if(current_vector[6] != 0x4b && current_vector[6] != 0x4c) |
| 1892 | | current_vector[6] = mc68901_get_vector(x68k_mfp); |
| 1925 | state->mfp.current_irq = -1; |
| 1926 | if(state->current_vector[6] != 0x4b && state->current_vector[6] != 0x4c) |
| 1927 | state->current_vector[6] = mc68901_get_vector(x68k_mfp); |
| 1893 | 1928 | else |
| 1894 | | cputag_set_input_line_and_vector(device->machine, "maincpu",irqline,CLEAR_LINE,current_vector[irqline]); |
| 1895 | | logerror("SYS: IRQ acknowledged (vector=0x%02x, line = %i)\n",current_vector[6],irqline); |
| 1896 | | return current_vector[6]; |
| 1929 | cputag_set_input_line_and_vector(device->machine, "maincpu",irqline,CLEAR_LINE,state->current_vector[irqline]); |
| 1930 | logerror("SYS: IRQ acknowledged (vector=0x%02x, line = %i)\n",state->current_vector[6],irqline); |
| 1931 | return state->current_vector[6]; |
| 1897 | 1932 | } |
| 1898 | 1933 | |
| 1899 | | cputag_set_input_line_and_vector(device->machine, "maincpu",irqline,CLEAR_LINE,current_vector[irqline]); |
| 1934 | cputag_set_input_line_and_vector(device->machine, "maincpu",irqline,CLEAR_LINE,state->current_vector[irqline]); |
| 1900 | 1935 | if(irqline == 1) // IOSC |
| 1901 | 1936 | { |
| 1902 | | x68k_sys.ioc.irqstatus &= ~0xf0; |
| 1937 | state->ioc.irqstatus &= ~0xf0; |
| 1903 | 1938 | } |
| 1904 | 1939 | if(irqline == 5) // SCC |
| 1905 | 1940 | { |
| 1906 | | x68k_sys.mouse.irqactive = 0; |
| 1941 | state->mouse.irqactive = 0; |
| 1907 | 1942 | } |
| 1908 | 1943 | |
| 1909 | | logerror("SYS: IRQ acknowledged (vector=0x%02x, line = %i)\n",current_vector[irqline],irqline); |
| 1910 | | return current_vector[irqline]; |
| 1944 | logerror("SYS: IRQ acknowledged (vector=0x%02x, line = %i)\n",state->current_vector[irqline],irqline); |
| 1945 | return state->current_vector[irqline]; |
| 1911 | 1946 | } |
| 1912 | 1947 | |
| 1913 | 1948 | static ADDRESS_MAP_START(x68k_map, ADDRESS_SPACE_PROGRAM, 16) |
| 1914 | 1949 | // AM_RANGE(0x000000, 0xbfffff) AM_RAMBANK(1) |
| 1915 | 1950 | AM_RANGE(0xbffffc, 0xbfffff) AM_READWRITE(x68k_rom0_r, x68k_rom0_w) |
| 1916 | | // AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(x68k_gvram_r, x68k_gvram_w) AM_BASE(&x68k_gvram) |
| 1917 | | // AM_RANGE(0xe00000, 0xe7ffff) AM_READWRITE(x68k_tvram_r, x68k_tvram_w) AM_BASE(&x68k_tvram) |
| 1951 | // AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(x68k_gvram_r, x68k_gvram_w) AM_BASE_MEMBER(x68k_state, gvram) |
| 1952 | // AM_RANGE(0xe00000, 0xe7ffff) AM_READWRITE(x68k_tvram_r, x68k_tvram_w) AM_BASE_MEMBER(x68k_state, tvram) |
| 1918 | 1953 | AM_RANGE(0xc00000, 0xdfffff) AM_RAMBANK("bank2") |
| 1919 | 1954 | AM_RANGE(0xe00000, 0xe7ffff) AM_RAMBANK("bank3") |
| 1920 | 1955 | AM_RANGE(0xe80000, 0xe81fff) AM_READWRITE(x68k_crtc_r, x68k_crtc_w) |
| r9669 | r9670 | |
| 1949 | 1984 | static ADDRESS_MAP_START(x68030_map, ADDRESS_SPACE_PROGRAM, 32) |
| 1950 | 1985 | // AM_RANGE(0x000000, 0xbfffff) AM_RAMBANK(1) |
| 1951 | 1986 | AM_RANGE(0xbffffc, 0xbfffff) AM_READWRITE16(x68k_rom0_r, x68k_rom0_w,0xffffffff) |
| 1952 | | // AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(x68k_gvram_r, x68k_gvram_w) AM_BASE(&x68k_gvram) |
| 1953 | | // AM_RANGE(0xe00000, 0xe7ffff) AM_READWRITE(x68k_tvram_r, x68k_tvram_w) AM_BASE(&x68k_tvram) |
| 1987 | // AM_RANGE(0xc00000, 0xdfffff) AM_READWRITE(x68k_gvram_r, x68k_gvram_w) AM_BASE_MEMBER(x68k_state, gvram) |
| 1988 | // AM_RANGE(0xe00000, 0xe7ffff) AM_READWRITE(x68k_tvram_r, x68k_tvram_w) AM_BASE_MEMBER(x68k_state, tvram) |
| 1954 | 1989 | AM_RANGE(0xc00000, 0xdfffff) AM_RAMBANK("bank2") |
| 1955 | 1990 | AM_RANGE(0xe00000, 0xe7ffff) AM_RAMBANK("bank3") |
| 1956 | 1991 | AM_RANGE(0xe80000, 0xe81fff) AM_READWRITE16(x68k_crtc_r, x68k_crtc_w,0xffffffff) |
| r9669 | r9670 | |
| 2362 | 2397 | |
| 2363 | 2398 | static void x68k_load_proc(device_image_interface &image) |
| 2364 | 2399 | { |
| 2365 | | if(x68k_sys.ioc.irqstatus & 0x02) |
| 2400 | x68k_state *state = image.device().machine->driver_data<x68k_state>(); |
| 2401 | if(state->ioc.irqstatus & 0x02) |
| 2366 | 2402 | { |
| 2367 | | current_vector[1] = 0x61; |
| 2368 | | x68k_sys.ioc.irqstatus |= 0x40; |
| 2369 | | current_irq_line = 1; |
| 2370 | | cputag_set_input_line_and_vector(image.device().machine, "maincpu",1,ASSERT_LINE,current_vector[1]); // Disk insert/eject interrupt |
| 2403 | state->current_vector[1] = 0x61; |
| 2404 | state->ioc.irqstatus |= 0x40; |
| 2405 | state->current_irq_line = 1; |
| 2406 | cputag_set_input_line_and_vector(image.device().machine, "maincpu",1,ASSERT_LINE,state->current_vector[1]); // Disk insert/eject interrupt |
| 2371 | 2407 | logerror("IOC: Disk image inserted\n"); |
| 2372 | 2408 | } |
| 2373 | | x68k_sys.fdc.disk_inserted[floppy_get_drive(&image.device())] = 1; |
| 2409 | state->fdc.disk_inserted[floppy_get_drive(&image.device())] = 1; |
| 2374 | 2410 | } |
| 2375 | 2411 | |
| 2376 | 2412 | static void x68k_unload_proc(device_image_interface &image) |
| 2377 | 2413 | { |
| 2378 | | if(x68k_sys.ioc.irqstatus & 0x02) |
| 2414 | x68k_state *state = image.device().machine->driver_data<x68k_state>(); |
| 2415 | if(state->ioc.irqstatus & 0x02) |
| 2379 | 2416 | { |
| 2380 | | current_vector[1] = 0x61; |
| 2381 | | x68k_sys.ioc.irqstatus |= 0x40; |
| 2382 | | current_irq_line = 1; |
| 2383 | | cputag_set_input_line_and_vector(image.device().machine, "maincpu",1,ASSERT_LINE,current_vector[1]); // Disk insert/eject interrupt |
| 2417 | state->current_vector[1] = 0x61; |
| 2418 | state->ioc.irqstatus |= 0x40; |
| 2419 | state->current_irq_line = 1; |
| 2420 | cputag_set_input_line_and_vector(image.device().machine, "maincpu",1,ASSERT_LINE,state->current_vector[1]); // Disk insert/eject interrupt |
| 2384 | 2421 | } |
| 2385 | | x68k_sys.fdc.disk_inserted[floppy_get_drive(&image.device())] = 0; |
| 2422 | state->fdc.disk_inserted[floppy_get_drive(&image.device())] = 0; |
| 2386 | 2423 | } |
| 2387 | 2424 | |
| 2388 | 2425 | static FLOPPY_OPTIONS_START( x68k ) |
| r9669 | r9670 | |
| 2410 | 2447 | |
| 2411 | 2448 | static MACHINE_RESET( x68000 ) |
| 2412 | 2449 | { |
| 2450 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 2413 | 2451 | /* The last half of the IPLROM is mapped to 0x000000 on reset only |
| 2414 | 2452 | Just copying the inital stack pointer and program counter should |
| 2415 | 2453 | more or less do the same job */ |
| r9669 | r9670 | |
| 2422 | 2460 | memcpy(messram_get_ptr(machine->device("messram")),romdata,8); |
| 2423 | 2461 | |
| 2424 | 2462 | // init keyboard |
| 2425 | | x68k_sys.keyboard.delay = 500; // 3*100+200 |
| 2426 | | x68k_sys.keyboard.repeat = 110; // 4^2*5+30 |
| 2463 | state->keyboard.delay = 500; // 3*100+200 |
| 2464 | state->keyboard.repeat = 110; // 4^2*5+30 |
| 2427 | 2465 | |
| 2428 | 2466 | // check for disks |
| 2429 | 2467 | for(drive=0;drive<4;drive++) |
| 2430 | 2468 | { |
| 2431 | 2469 | device_image_interface *image = dynamic_cast<device_image_interface *>(floppy_get_device(machine, drive)); |
| 2432 | 2470 | if(image->exists()) |
| 2433 | | x68k_sys.fdc.disk_inserted[drive] = 1; |
| 2471 | state->fdc.disk_inserted[drive] = 1; |
| 2434 | 2472 | else |
| 2435 | | x68k_sys.fdc.disk_inserted[drive] = 0; |
| 2473 | state->fdc.disk_inserted[drive] = 0; |
| 2436 | 2474 | } |
| 2437 | 2475 | |
| 2438 | 2476 | // initialise CRTC, set registers to defaults for the standard text mode (768x512) |
| 2439 | | x68k_sys.crtc.reg[0] = 137; // Horizontal total (in characters) |
| 2440 | | x68k_sys.crtc.reg[1] = 14; // Horizontal sync end |
| 2441 | | x68k_sys.crtc.reg[2] = 28; // Horizontal start |
| 2442 | | x68k_sys.crtc.reg[3] = 124; // Horizontal end |
| 2443 | | x68k_sys.crtc.reg[4] = 567; // Vertical total |
| 2444 | | x68k_sys.crtc.reg[5] = 5; // Vertical sync end |
| 2445 | | x68k_sys.crtc.reg[6] = 40; // Vertical start |
| 2446 | | x68k_sys.crtc.reg[7] = 552; // Vertical end |
| 2447 | | x68k_sys.crtc.reg[8] = 27; // Horizontal adjust |
| 2477 | state->crtc.reg[0] = 137; // Horizontal total (in characters) |
| 2478 | state->crtc.reg[1] = 14; // Horizontal sync end |
| 2479 | state->crtc.reg[2] = 28; // Horizontal start |
| 2480 | state->crtc.reg[3] = 124; // Horizontal end |
| 2481 | state->crtc.reg[4] = 567; // Vertical total |
| 2482 | state->crtc.reg[5] = 5; // Vertical sync end |
| 2483 | state->crtc.reg[6] = 40; // Vertical start |
| 2484 | state->crtc.reg[7] = 552; // Vertical end |
| 2485 | state->crtc.reg[8] = 27; // Horizontal adjust |
| 2448 | 2486 | |
| 2449 | | mfp_init(); |
| 2487 | mfp_init(machine); |
| 2450 | 2488 | |
| 2451 | | x68k_scanline = machine->primary_screen->vpos();// = x68k_sys.crtc.reg[6]; // Vertical start |
| 2489 | state->scanline = machine->primary_screen->vpos();// = state->crtc.reg[6]; // Vertical start |
| 2452 | 2490 | |
| 2453 | 2491 | // start VBlank timer |
| 2454 | | x68k_sys.crtc.vblank = 1; |
| 2455 | | irq_time = machine->primary_screen->time_until_pos(x68k_sys.crtc.reg[6],2); |
| 2456 | | timer_adjust_oneshot(x68k_vblank_irq, irq_time, 0); |
| 2492 | state->crtc.vblank = 1; |
| 2493 | irq_time = machine->primary_screen->time_until_pos(state->crtc.reg[6],2); |
| 2494 | timer_adjust_oneshot(state->vblank_irq, irq_time, 0); |
| 2457 | 2495 | |
| 2458 | 2496 | // start HBlank timer |
| 2459 | | timer_adjust_oneshot(x68k_scanline_timer, machine->primary_screen->scan_period(), 1); |
| 2497 | timer_adjust_oneshot(state->scanline_timer, machine->primary_screen->scan_period(), 1); |
| 2460 | 2498 | |
| 2461 | | x68k_sys.mfp.gpio = 0xfb; |
| 2499 | state->mfp.gpio = 0xfb; |
| 2462 | 2500 | |
| 2463 | 2501 | // reset output values |
| 2464 | 2502 | output_set_value("key_led_kana",1); |
| r9669 | r9670 | |
| 2486 | 2524 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 2487 | 2525 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 2488 | 2526 | /* Install RAM handlers */ |
| 2489 | | x68k_spriteram = (UINT16*)memory_region(machine, "user1"); |
| 2527 | state->spriteram = (UINT16*)memory_region(machine, "user1"); |
| 2490 | 2528 | memory_install_read16_handler(space,0x000000,0xbffffb,0xffffffff,0,(read16_space_func)x68k_emptyram_r); |
| 2491 | 2529 | memory_install_write16_handler(space,0x000000,0xbffffb,0xffffffff,0,(write16_space_func)x68k_emptyram_w); |
| 2492 | 2530 | memory_install_readwrite_bank(space,0x000000,messram_get_size(machine->device("messram"))-1,0xffffffff,0,"bank1"); |
| 2493 | 2531 | memory_set_bankptr(machine, "bank1",messram_get_ptr(machine->device("messram"))); |
| 2494 | 2532 | memory_install_read16_handler(space,0xc00000,0xdfffff,0xffffffff,0,x68k_gvram_r); |
| 2495 | 2533 | memory_install_write16_handler(space,0xc00000,0xdfffff,0xffffffff,0,x68k_gvram_w); |
| 2496 | | memory_set_bankptr(machine, "bank2",x68k_gvram); // so that code in VRAM is executable - needed for Terra Cresta |
| 2534 | memory_set_bankptr(machine, "bank2",state->gvram); // so that code in VRAM is executable - needed for Terra Cresta |
| 2497 | 2535 | memory_install_read16_handler(space,0xe00000,0xe7ffff,0xffffffff,0,x68k_tvram_r); |
| 2498 | 2536 | memory_install_write16_handler(space,0xe00000,0xe7ffff,0xffffffff,0,x68k_tvram_w); |
| 2499 | | memory_set_bankptr(machine, "bank3",x68k_tvram); // so that code in VRAM is executable - needed for Terra Cresta |
| 2537 | memory_set_bankptr(machine, "bank3",state->tvram); // so that code in VRAM is executable - needed for Terra Cresta |
| 2500 | 2538 | memory_install_read16_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram_r); |
| 2501 | 2539 | memory_install_write16_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram_w); |
| 2502 | 2540 | memory_set_bankptr(machine, "bank4",state->m_nvram); // so that code in SRAM is executable, there is an option for booting from SRAM |
| 2503 | 2541 | |
| 2504 | 2542 | // start keyboard timer |
| 2505 | | timer_adjust_periodic(kb_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(5)); // every 5ms |
| 2543 | timer_adjust_periodic(state->kb_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(5)); // every 5ms |
| 2506 | 2544 | |
| 2507 | 2545 | // start mouse timer |
| 2508 | | timer_adjust_periodic(mouse_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(1)); // a guess for now |
| 2509 | | x68k_sys.mouse.inputtype = 0; |
| 2546 | timer_adjust_periodic(state->mouse_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(1)); // a guess for now |
| 2547 | state->mouse.inputtype = 0; |
| 2510 | 2548 | |
| 2511 | 2549 | // start LED timer |
| 2512 | | timer_adjust_periodic(led_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(400)); |
| 2550 | timer_adjust_periodic(state->led_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(400)); |
| 2513 | 2551 | } |
| 2514 | 2552 | |
| 2515 | 2553 | static MACHINE_START( x68030 ) |
| r9669 | r9670 | |
| 2517 | 2555 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 2518 | 2556 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 2519 | 2557 | /* Install RAM handlers */ |
| 2520 | | x68k_spriteram = (UINT16*)memory_region(machine, "user1"); |
| 2558 | state->spriteram = (UINT16*)memory_region(machine, "user1"); |
| 2521 | 2559 | memory_install_read32_handler(space,0x000000,0xbffffb,0xffffffff,0,(read32_space_func)x68k_rom0_r); |
| 2522 | 2560 | memory_install_write32_handler(space,0x000000,0xbffffb,0xffffffff,0,(write32_space_func)x68k_rom0_w); |
| 2523 | 2561 | memory_install_readwrite_bank(space,0x000000,messram_get_size(machine->device("messram"))-1,0xffffffff,0,"bank1"); |
| r9669 | r9670 | |
| 2527 | 2565 | memory_set_bankptr(machine, "bank5",messram_get_ptr(machine->device("messram"))); |
| 2528 | 2566 | memory_install_read32_handler(space,0xc00000,0xdfffff,0xffffffff,0,x68k_gvram32_r); |
| 2529 | 2567 | memory_install_write32_handler(space,0xc00000,0xdfffff,0xffffffff,0,x68k_gvram32_w); |
| 2530 | | memory_set_bankptr(machine, "bank2",x68k_gvram); // so that code in VRAM is executable - needed for Terra Cresta |
| 2568 | memory_set_bankptr(machine, "bank2",state->gvram); // so that code in VRAM is executable - needed for Terra Cresta |
| 2531 | 2569 | memory_install_read32_handler(space,0xe00000,0xe7ffff,0xffffffff,0,x68k_tvram32_r); |
| 2532 | 2570 | memory_install_write32_handler(space,0xe00000,0xe7ffff,0xffffffff,0,x68k_tvram32_w); |
| 2533 | | memory_set_bankptr(machine, "bank3",x68k_tvram); // so that code in VRAM is executable - needed for Terra Cresta |
| 2571 | memory_set_bankptr(machine, "bank3",state->tvram); // so that code in VRAM is executable - needed for Terra Cresta |
| 2534 | 2572 | memory_install_read32_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram32_r); |
| 2535 | 2573 | memory_install_write32_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram32_w); |
| 2536 | 2574 | memory_set_bankptr(machine, "bank4",state->m_nvram); // so that code in SRAM is executable, there is an option for booting from SRAM |
| 2537 | 2575 | |
| 2538 | 2576 | // start keyboard timer |
| 2539 | | timer_adjust_periodic(kb_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(5)); // every 5ms |
| 2577 | timer_adjust_periodic(state->kb_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(5)); // every 5ms |
| 2540 | 2578 | |
| 2541 | 2579 | // start mouse timer |
| 2542 | | timer_adjust_periodic(mouse_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(1)); // a guess for now |
| 2543 | | x68k_sys.mouse.inputtype = 0; |
| 2580 | timer_adjust_periodic(state->mouse_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(1)); // a guess for now |
| 2581 | state->mouse.inputtype = 0; |
| 2544 | 2582 | |
| 2545 | 2583 | // start LED timer |
| 2546 | | timer_adjust_periodic(led_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(400)); |
| 2584 | timer_adjust_periodic(state->led_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(400)); |
| 2547 | 2585 | } |
| 2548 | 2586 | |
| 2549 | 2587 | static DRIVER_INIT( x68000 ) |
| 2550 | 2588 | { |
| 2589 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 2551 | 2590 | unsigned char* rom = memory_region(machine, "maincpu"); |
| 2552 | 2591 | unsigned char* user2 = memory_region(machine, "user2"); |
| 2553 | | x68k_gvram = auto_alloc_array(machine, UINT16, 0x080000/sizeof(UINT16)); |
| 2554 | | x68k_tvram = auto_alloc_array(machine, UINT16, 0x080000/sizeof(UINT16)); |
| 2555 | | sram = auto_alloc_array(machine, UINT16, 0x4000/sizeof(UINT16)); |
| 2592 | state->gvram = auto_alloc_array(machine, UINT16, 0x080000/sizeof(UINT16)); |
| 2593 | state->tvram = auto_alloc_array(machine, UINT16, 0x080000/sizeof(UINT16)); |
| 2594 | state->sram = auto_alloc_array(machine, UINT16, 0x4000/sizeof(UINT16)); |
| 2556 | 2595 | |
| 2557 | | x68k_spritereg = auto_alloc_array_clear(machine, UINT16, 0x8000/sizeof(UINT16)); |
| 2596 | state->spritereg = auto_alloc_array_clear(machine, UINT16, 0x8000/sizeof(UINT16)); |
| 2558 | 2597 | |
| 2559 | 2598 | #ifdef USE_PREDEFINED_SRAM |
| 2560 | 2599 | { |
| 2561 | 2600 | unsigned char* ramptr = memory_region(machine, "user3"); |
| 2562 | | memcpy(sram,ramptr,0x4000); |
| 2601 | memcpy(state->sram,ramptr,0x4000); |
| 2563 | 2602 | } |
| 2564 | 2603 | #endif |
| 2565 | 2604 | |
| 2566 | 2605 | // copy last half of BIOS to a user region, to use for inital startup |
| 2567 | 2606 | memcpy(user2,(rom+0xff0000),0x10000); |
| 2568 | 2607 | |
| 2569 | | memset(&x68k_sys,0,sizeof(x68k_sys)); |
| 2608 | mfp_init(machine); |
| 2570 | 2609 | |
| 2571 | | mfp_init(); |
| 2572 | | |
| 2573 | 2610 | cpu_set_irq_callback(machine->device("maincpu"), x68k_int_ack); |
| 2574 | 2611 | |
| 2575 | 2612 | // init keyboard |
| 2576 | | x68k_sys.keyboard.delay = 500; // 3*100+200 |
| 2577 | | x68k_sys.keyboard.repeat = 110; // 4^2*5+30 |
| 2578 | | kb_timer = timer_alloc(machine, x68k_keyboard_poll,NULL); |
| 2579 | | x68k_scanline_timer = timer_alloc(machine, x68k_hsync,NULL); |
| 2580 | | x68k_raster_irq = timer_alloc(machine, x68k_crtc_raster_irq,NULL); |
| 2581 | | x68k_vblank_irq = timer_alloc(machine, x68k_crtc_vblank_irq,NULL); |
| 2582 | | mouse_timer = timer_alloc(machine, x68k_scc_ack,NULL); |
| 2583 | | led_timer = timer_alloc(machine, x68k_led_callback,NULL); |
| 2613 | state->keyboard.delay = 500; // 3*100+200 |
| 2614 | state->keyboard.repeat = 110; // 4^2*5+30 |
| 2615 | state->kb_timer = timer_alloc(machine, x68k_keyboard_poll,NULL); |
| 2616 | state->scanline_timer = timer_alloc(machine, x68k_hsync,NULL); |
| 2617 | state->raster_irq = timer_alloc(machine, x68k_crtc_raster_irq,NULL); |
| 2618 | state->vblank_irq = timer_alloc(machine, x68k_crtc_vblank_irq,NULL); |
| 2619 | state->mouse_timer = timer_alloc(machine, x68k_scc_ack,NULL); |
| 2620 | state->led_timer = timer_alloc(machine, x68k_led_callback,NULL); |
| 2584 | 2621 | |
| 2585 | 2622 | // Initialise timers for 6-button MD controllers |
| 2586 | 2623 | md_6button_init(machine); |
| 2587 | 2624 | |
| 2588 | | x68k_sys.sysport.cputype = 0xff; // 68000, 10MHz |
| 2625 | state->sysport.cputype = 0xff; // 68000, 10MHz |
| 2589 | 2626 | } |
| 2590 | 2627 | |
| 2591 | 2628 | static DRIVER_INIT( x68kxvi ) |
| 2592 | 2629 | { |
| 2630 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 2593 | 2631 | DRIVER_INIT_CALL( x68000 ); |
| 2594 | | x68k_sys.sysport.cputype = 0xfe; // 68000, 16MHz |
| 2632 | state->sysport.cputype = 0xfe; // 68000, 16MHz |
| 2595 | 2633 | } |
| 2596 | 2634 | |
| 2597 | 2635 | static DRIVER_INIT( x68030 ) |
| 2598 | 2636 | { |
| 2637 | x68k_state *state = machine->driver_data<x68k_state>(); |
| 2599 | 2638 | DRIVER_INIT_CALL( x68000 ); |
| 2600 | | x68k_sys.sysport.cputype = 0xdc; // 68030, 25MHz |
| 2639 | state->sysport.cputype = 0xdc; // 68030, 25MHz |
| 2601 | 2640 | } |
| 2602 | 2641 | |
| 2603 | 2642 | static MACHINE_CONFIG_START( x68000, x68k_state ) |