src/mess/machine/lynx.c
| r14276 | r14277 | |
| 36 | 36 | This whole part will be eventually moved to video/ once I'm satisfied (or I give up). |
| 37 | 37 | */ |
| 38 | 38 | |
| 39 | | #define GET_WORD(mem, index) ((mem)[(index)]|((mem)[(index)+1]<<8)) |
| 40 | | |
| 41 | 39 | /* modes from blitter command */ |
| 42 | 40 | enum { |
| 43 | 41 | BACKGROUND = 0, |
| r14276 | r14277 | |
| 50 | 48 | SHADOW |
| 51 | 49 | }; |
| 52 | 50 | |
| 51 | static UINT8 lynx_read_ram(lynx_state *state, UINT16 address) |
| 52 | { |
| 53 | UINT8 result = 0x00; |
| 54 | if (address <= 0xfbff) |
| 55 | result = state->m_mem_0000[address - 0x0000]; |
| 56 | else if (address <= 0xfcff) |
| 57 | result = state->m_mem_fc00[address - 0xfc00]; |
| 58 | else if (address <= 0xfdff) |
| 59 | result = state->m_mem_fd00[address - 0xfd00]; |
| 60 | else if (address <= 0xfff7) |
| 61 | result = state->m_mem_fe00[address - 0xfe00]; |
| 62 | else if (address >= 0xfffa) |
| 63 | result = state->m_mem_fffa[address - 0xfffa]; |
| 64 | return result; |
| 65 | } |
| 53 | 66 | |
| 67 | static void lynx_write_ram(lynx_state *state, UINT16 address, UINT8 data) |
| 68 | { |
| 69 | if (address <= 0xfbff) |
| 70 | state->m_mem_0000[address - 0x0000] = data; |
| 71 | else if (address <= 0xfcff) |
| 72 | state->m_mem_fc00[address - 0xfc00] = data; |
| 73 | else if (address <= 0xfdff) |
| 74 | state->m_mem_fd00[address - 0xfd00] = data; |
| 75 | else if (address <= 0xfff7) |
| 76 | state->m_mem_fe00[address - 0xfe00] = data; |
| 77 | else if (address >= 0xfffa) |
| 78 | state->m_mem_fffa[address - 0xfffa] = data; |
| 79 | } |
| 80 | |
| 54 | 81 | /* The pen numbers range from '0' to 'F. Pen numbers '1' through 'D' are always collidable and opaque. The other |
| 55 | 82 | ones have different behavior depending on the sprite type: there are 8 types of sprites, each has different |
| 56 | 83 | characteristics relating to some or all of their pen numbers. |
| r14276 | r14277 | |
| 82 | 109 | INLINE void lynx_plot_pixel(lynx_state *state, const int mode, const INT16 x, const int y, const int color) |
| 83 | 110 | { |
| 84 | 111 | UINT8 back; |
| 85 | | UINT8 *screen; |
| 86 | | UINT8 *colbuf; |
| 112 | UINT16 screen; |
| 113 | UINT16 colbuf; |
| 87 | 114 | |
| 88 | 115 | state->m_blitter.everon = TRUE; |
| 89 | | screen = state->m_blitter.mem + state->m_blitter.screen + y * 80 + x / 2; |
| 90 | | colbuf = state->m_blitter.mem + state->m_blitter.colbuf + y * 80 + x / 2; |
| 116 | screen = state->m_blitter.screen + y * 80 + x / 2; |
| 117 | colbuf = state->m_blitter.colbuf + y * 80 + x / 2; |
| 91 | 118 | |
| 92 | 119 | switch (mode&0x7) |
| 93 | 120 | { |
| r14276 | r14277 | |
| 98 | 125 | break; |
| 99 | 126 | if (!(x & 0x01)) /* Upper nibble */ |
| 100 | 127 | { |
| 101 | | *screen = (*screen & 0x0f) | (color << 4); |
| 128 | back = lynx_read_ram(state, screen); |
| 129 | lynx_write_ram(state, screen, (back & 0x0f) | (color << 4)); |
| 102 | 130 | |
| 103 | 131 | if(state->m_sprite_collide) |
| 104 | 132 | { |
| 105 | | back = *colbuf; |
| 106 | | *colbuf = (back & ~0xf0) | (state->m_blitter.spritenr << 4); |
| 107 | | if ((back >> 4) > state->m_blitter.mem[state->m_blitter.colpos]) |
| 108 | | state->m_blitter.mem[state->m_blitter.colpos] = back >> 4; |
| 133 | back = lynx_read_ram(state, colbuf); |
| 134 | lynx_write_ram(state, colbuf, (back & ~0xf0) | (state->m_blitter.spritenr << 4)); |
| 135 | if ((back >> 4) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f)) |
| 136 | lynx_write_ram(state, state->m_blitter.colpos, back >> 4); |
| 109 | 137 | state->m_blitter.memory_accesses += 2; |
| 110 | 138 | } |
| 111 | 139 | } |
| 112 | 140 | else /* Lower nibble */ |
| 113 | 141 | { |
| 114 | | *screen = (*screen & 0xf0) | color; |
| 142 | back = lynx_read_ram(state, screen); |
| 143 | lynx_write_ram(state, screen, (back & 0xf0) | color); |
| 115 | 144 | |
| 116 | 145 | if(state->m_sprite_collide) |
| 117 | 146 | { |
| 118 | | back = *colbuf; |
| 119 | | *colbuf = (back & ~0x0f) | (state->m_blitter.spritenr); |
| 120 | | if ((back & 0x0f) > state->m_blitter.mem[state->m_blitter.colpos]) |
| 121 | | state->m_blitter.mem[state->m_blitter.colpos] = back & 0x0f; |
| 147 | back = lynx_read_ram(state, colbuf); |
| 148 | lynx_write_ram(state, colbuf, (back & ~0x0f) | (state->m_blitter.spritenr)); |
| 149 | if ((back & 0x0f) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f)) |
| 150 | lynx_write_ram(state, state->m_blitter.colpos, back & 0x0f); |
| 122 | 151 | state->m_blitter.memory_accesses += 2; |
| 123 | 152 | } |
| 124 | 153 | } |
| r14276 | r14277 | |
| 134 | 163 | { |
| 135 | 164 | if (color != 0x0f) |
| 136 | 165 | { |
| 137 | | *screen = (*screen & 0x0f) | (color << 4); |
| 166 | back = lynx_read_ram(state, screen); |
| 167 | lynx_write_ram(state, screen, (back & 0x0f) | (color << 4)); |
| 138 | 168 | state->m_blitter.memory_accesses++; |
| 139 | 169 | } |
| 140 | 170 | if(state->m_sprite_collide) |
| 141 | 171 | { |
| 142 | | back = *colbuf; |
| 143 | | *colbuf = (back & ~0xf0) | (state->m_blitter.spritenr << 4); |
| 144 | | if ((back >> 4) > state->m_blitter.mem[state->m_blitter.colpos]) |
| 145 | | state->m_blitter.mem[state->m_blitter.colpos] = back >> 4; |
| 172 | back = lynx_read_ram(state, colbuf); |
| 173 | lynx_write_ram(state, colbuf, (back & ~0xf0) | (state->m_blitter.spritenr << 4)); |
| 174 | if ((back >> 4) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f)) |
| 175 | lynx_write_ram(state, state->m_blitter.colpos, back >> 4); |
| 146 | 176 | state->m_blitter.memory_accesses += 2; |
| 147 | 177 | } |
| 148 | 178 | } |
| r14276 | r14277 | |
| 150 | 180 | { |
| 151 | 181 | if (color != 0x0f) |
| 152 | 182 | { |
| 153 | | *screen = (*screen & 0xf0) | color; |
| 183 | back = lynx_read_ram(state, screen); |
| 184 | lynx_write_ram(state, screen, (back & 0xf0) | color); |
| 154 | 185 | state->m_blitter.memory_accesses++; |
| 155 | 186 | } |
| 156 | 187 | if(state->m_sprite_collide) |
| 157 | 188 | { |
| 158 | | back = *colbuf; |
| 159 | | *colbuf = (back & ~0x0f) | (state->m_blitter.spritenr); |
| 160 | | if ((back & 0x0f) > state->m_blitter.mem[state->m_blitter.colpos]) |
| 161 | | state->m_blitter.mem[state->m_blitter.colpos] = back & 0x0f; |
| 189 | back = lynx_read_ram(state, colbuf); |
| 190 | lynx_write_ram(state, colbuf, (back & ~0x0f) | (state->m_blitter.spritenr)); |
| 191 | if ((back & 0x0f) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f)) |
| 192 | lynx_write_ram(state, state->m_blitter.colpos, back & 0x0f); |
| 162 | 193 | state->m_blitter.memory_accesses += 2; |
| 163 | 194 | } |
| 164 | 195 | } |
| r14276 | r14277 | |
| 171 | 202 | break; |
| 172 | 203 | if (!(x & 0x01)) /* Upper nibble */ |
| 173 | 204 | { |
| 174 | | *screen = (*screen & 0x0f) | (color << 4); |
| 205 | back = lynx_read_ram(state, screen); |
| 206 | lynx_write_ram(state, screen, (back & 0x0f) | (color << 4)); |
| 175 | 207 | |
| 176 | 208 | if (state->m_sprite_collide && (color != 0x0e)) |
| 177 | 209 | { |
| 178 | | back = *colbuf; |
| 179 | | *colbuf = (back & ~0xf0) | (state->m_blitter.spritenr << 4); |
| 180 | | if ((back >> 4) > state->m_blitter.mem[state->m_blitter.colpos]) |
| 181 | | state->m_blitter.mem[state->m_blitter.colpos] = back >> 4; |
| 210 | back = lynx_read_ram(state, colbuf); |
| 211 | lynx_write_ram(state, colbuf, (back & ~0xf0) | (state->m_blitter.spritenr << 4)); |
| 212 | if ((back >> 4) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f)) |
| 213 | lynx_write_ram(state, state->m_blitter.colpos, back >> 4); |
| 182 | 214 | state->m_blitter.memory_accesses += 2; |
| 183 | 215 | } |
| 184 | 216 | } |
| 185 | 217 | else /* Lower nibble */ |
| 186 | 218 | { |
| 187 | | *screen = (*screen & 0xf0) | color; |
| 219 | back = lynx_read_ram(state, screen); |
| 220 | lynx_write_ram(state, screen, (back & 0xf0) | color); |
| 188 | 221 | |
| 189 | 222 | if (state->m_sprite_collide && (color != 0x0e)) |
| 190 | 223 | { |
| 191 | | back = *colbuf; |
| 192 | | *colbuf = (back & ~0x0f) | (state->m_blitter.spritenr); |
| 193 | | if ((back & 0x0f) > state->m_blitter.mem[state->m_blitter.colpos]) |
| 194 | | state->m_blitter.mem[state->m_blitter.colpos] = back & 0x0f; |
| 224 | back = lynx_read_ram(state, colbuf); |
| 225 | lynx_write_ram(state, colbuf, (back & ~0x0f) | (state->m_blitter.spritenr)); |
| 226 | if ((back & 0x0f) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f)) |
| 227 | lynx_write_ram(state, state->m_blitter.colpos, back & 0x0f); |
| 195 | 228 | state->m_blitter.memory_accesses += 2; |
| 196 | 229 | } |
| 197 | 230 | } |
| r14276 | r14277 | |
| 208 | 241 | { |
| 209 | 242 | if (color != 0x0f) |
| 210 | 243 | { |
| 211 | | *screen = (*screen & 0x0f) | (color << 4); |
| 244 | back = lynx_read_ram(state, screen); |
| 245 | lynx_write_ram(state, screen, (back & 0x0f) | (color << 4)); |
| 212 | 246 | state->m_blitter.memory_accesses++; |
| 213 | 247 | } |
| 214 | 248 | if (state->m_sprite_collide && (color != 0x0e)) |
| 215 | 249 | { |
| 216 | | back = *colbuf; |
| 217 | | *colbuf = (back & ~0xf0) | (state->m_blitter.spritenr << 4); |
| 218 | | if ((back >> 4) > state->m_blitter.mem[state->m_blitter.colpos]) |
| 219 | | state->m_blitter.mem[state->m_blitter.colpos] = back >> 4; |
| 250 | back = lynx_read_ram(state, colbuf); |
| 251 | lynx_write_ram(state, colbuf, (back & ~0xf0) | (state->m_blitter.spritenr << 4)); |
| 252 | if ((back >> 4) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f)) |
| 253 | lynx_write_ram(state, state->m_blitter.colpos, back >> 4); |
| 220 | 254 | state->m_blitter.memory_accesses += 2; |
| 221 | 255 | } |
| 222 | 256 | } |
| r14276 | r14277 | |
| 224 | 258 | { |
| 225 | 259 | if (color != 0x0f) |
| 226 | 260 | { |
| 227 | | *screen = (*screen & 0xf0) | color; |
| 261 | back = lynx_read_ram(state, screen); |
| 262 | lynx_write_ram(state, screen, (back & 0xf0) | color); |
| 228 | 263 | state->m_blitter.memory_accesses++; |
| 229 | 264 | } |
| 230 | 265 | if (state->m_sprite_collide && (color != 0x0e)) |
| 231 | 266 | { |
| 232 | | back = *colbuf; |
| 233 | | *colbuf = (back & ~0x0f) | (state->m_blitter.spritenr); |
| 234 | | if ((back & 0x0f) > state->m_blitter.mem[state->m_blitter.colpos]) |
| 235 | | state->m_blitter.mem[state->m_blitter.colpos] = back & 0x0f; |
| 267 | back = lynx_read_ram(state, colbuf); |
| 268 | lynx_write_ram(state, colbuf, (back & ~0x0f) | (state->m_blitter.spritenr)); |
| 269 | if ((back & 0x0f) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f)) |
| 270 | lynx_write_ram(state, state->m_blitter.colpos, back & 0x0f); |
| 236 | 271 | state->m_blitter.memory_accesses += 2; |
| 237 | 272 | } |
| 238 | 273 | } |
| r14276 | r14277 | |
| 246 | 281 | and therefore not clear the collision buffer */ |
| 247 | 282 | if (!(x & 0x01)) /* Upper nibble */ |
| 248 | 283 | { |
| 249 | | *screen = (*screen & 0x0f) | (color << 4); |
| 284 | back = lynx_read_ram(state, screen); |
| 285 | lynx_write_ram(state, screen, (back & 0x0f) | (color << 4)); |
| 250 | 286 | |
| 251 | 287 | if (state->m_sprite_collide && (color != 0x0e)) |
| 252 | 288 | { |
| 253 | | *colbuf = (*colbuf & ~0xf0) | (state->m_blitter.spritenr << 4); |
| 289 | back = lynx_read_ram(state, colbuf); |
| 290 | lynx_write_ram(state, colbuf, (back & ~0xf0) | (state->m_blitter.spritenr << 4)); |
| 254 | 291 | state->m_blitter.memory_accesses++; |
| 255 | 292 | } |
| 256 | 293 | } |
| 257 | 294 | else /* Lower nibble */ |
| 258 | 295 | { |
| 259 | | *screen = (*screen & 0xf0) | color; |
| 296 | back = lynx_read_ram(state, screen); |
| 297 | lynx_write_ram(state, screen, (back & 0xf0) | color); |
| 260 | 298 | |
| 261 | 299 | if (state->m_sprite_collide && (color != 0x0e)) |
| 262 | 300 | { |
| 263 | | *colbuf = (*colbuf & ~0x0f) | (state->m_blitter.spritenr); |
| 301 | back = lynx_read_ram(state, colbuf); |
| 302 | lynx_write_ram(state, colbuf, (back & ~0x0f) | (state->m_blitter.spritenr)); |
| 264 | 303 | state->m_blitter.memory_accesses++; |
| 265 | 304 | } |
| 266 | 305 | } |
| r14276 | r14277 | |
| 270 | 309 | case BACKGROUND_NO_COLL: |
| 271 | 310 | /* This is a 'background' sprite with the exception that no activity occurs in the collision buffer */ |
| 272 | 311 | if (!(x & 0x01)) /* Upper nibble */ |
| 273 | | *screen = (*screen & 0x0f) | (color << 4); |
| 312 | { |
| 313 | back = lynx_read_ram(state, screen); |
| 314 | lynx_write_ram(state, screen, (back & 0x0f) | (color << 4)); |
| 315 | } |
| 274 | 316 | else /* Lower nibble */ |
| 275 | | *screen = (*screen & 0xf0) | color; |
| 317 | { |
| 318 | back = lynx_read_ram(state, screen); |
| 319 | lynx_write_ram(state, screen, (back & 0xf0) | color); |
| 320 | } |
| 276 | 321 | state->m_blitter.memory_accesses++; |
| 277 | 322 | break; |
| 278 | 323 | |
| r14276 | r14277 | |
| 282 | 327 | if (color == 0) |
| 283 | 328 | break; |
| 284 | 329 | if (!(x & 0x01)) /* Upper nibble */ |
| 285 | | *screen = (*screen & 0x0f) | (color << 4); |
| 330 | { |
| 331 | back = lynx_read_ram(state, screen); |
| 332 | lynx_write_ram(state, screen, (back & 0x0f) | (color << 4)); |
| 333 | } |
| 286 | 334 | else /* Lower nibble */ |
| 287 | | *screen = (*screen & 0xf0) | color; |
| 335 | { |
| 336 | back = lynx_read_ram(state, screen); |
| 337 | lynx_write_ram(state, screen, (back & 0xf0) | color); |
| 338 | } |
| 288 | 339 | state->m_blitter.memory_accesses++; |
| 289 | 340 | break; |
| 290 | 341 | |
| r14276 | r14277 | |
| 297 | 348 | break; |
| 298 | 349 | if (!(x & 0x01)) /* Upper nibble */ |
| 299 | 350 | { |
| 300 | | *screen = (*screen)^(color<<4); |
| 301 | | if (color != 0x0e) |
| 351 | back = lynx_read_ram(state, screen); |
| 352 | lynx_write_ram(state, screen, back^(color << 4)); |
| 353 | if (state->m_sprite_collide && (color != 0x0e)) |
| 302 | 354 | { |
| 303 | | back = *colbuf; |
| 304 | | *colbuf = (back & ~0xf0) | (state->m_blitter.spritenr << 4); |
| 305 | | if ((back >> 4) > state->m_blitter.mem[state->m_blitter.colpos]) |
| 306 | | state->m_blitter.mem[state->m_blitter.colpos] = back >> 4; |
| 355 | back = lynx_read_ram(state, colbuf); |
| 356 | lynx_write_ram(state, colbuf, (back & ~0xf0) | (state->m_blitter.spritenr << 4)); |
| 357 | if ((back >> 4) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f)) |
| 358 | lynx_write_ram(state, state->m_blitter.colpos, back >> 4); |
| 307 | 359 | state->m_blitter.memory_accesses += 2; |
| 308 | 360 | } |
| 309 | 361 | } |
| 310 | 362 | else /* Lower nibble */ |
| 311 | 363 | { |
| 312 | | *screen = (*screen)^color; |
| 313 | | if (color != 0x0e) |
| 364 | back = lynx_read_ram(state, screen); |
| 365 | lynx_write_ram(state, screen, back^color); |
| 366 | if (state->m_sprite_collide && (color != 0x0e)) |
| 314 | 367 | { |
| 315 | | back = *colbuf; |
| 316 | | *colbuf = (back & ~0x0f) | (state->m_blitter.spritenr); |
| 317 | | if ((back & 0x0f) > state->m_blitter.mem[state->m_blitter.colpos]) |
| 318 | | state->m_blitter.mem[state->m_blitter.colpos] = back & 0x0f; |
| 368 | back = lynx_read_ram(state, colbuf); |
| 369 | lynx_write_ram(state, colbuf, (back & ~0x0f) | (state->m_blitter.spritenr)); |
| 370 | if ((back & 0x0f) > (lynx_read_ram(state, state->m_blitter.colpos) & 0x0f)) |
| 371 | lynx_write_ram(state, state->m_blitter.colpos, back & 0x0f); |
| 319 | 372 | state->m_blitter.memory_accesses += 2; |
| 320 | 373 | } |
| 321 | 374 | } |
| r14276 | r14277 | |
| 330 | 383 | int xi, bits, color; |
| 331 | 384 | UINT16 width_accum, buffer; |
| 332 | 385 | |
| 333 | | next_line_addr = state->m_blitter.mem[state->m_blitter.bitmap]; // offset to second sprite line |
| 386 | next_line_addr = lynx_read_ram(state, state->m_blitter.bitmap); // offset to second sprite line |
| 334 | 387 | width_accum = (xdir == 1) ? state->m_blitter.width_offset : 0; |
| 335 | 388 | state->m_blitter.memory_accesses++; |
| 336 | 389 | |
| 337 | 390 | for (xi = state->m_blitter.x_pos - state->m_blitter.xoff, bits = 0, buffer = 0, j = 1; j < next_line_addr;j++) |
| 338 | 391 | { |
| 339 | | buffer = (buffer << 8) | state->m_blitter.mem[state->m_blitter.bitmap + j]; |
| 392 | buffer = (buffer << 8) | lynx_read_ram(state, state->m_blitter.bitmap + j); |
| 340 | 393 | bits += 8; // current bits in buffer |
| 341 | 394 | state->m_blitter.memory_accesses++; |
| 342 | 395 | |
| r14276 | r14277 | |
| 356 | 409 | } |
| 357 | 410 | } |
| 358 | 411 | |
| 412 | static void lynx_blit_2color_line(lynx_state *state, const int y, const int xdir) {lynx_blit_do_work(state, y, xdir, 1, 0x01);} |
| 413 | static void lynx_blit_4color_line(lynx_state *state, const int y, const int xdir) {lynx_blit_do_work(state, y, xdir, 2, 0x03);} |
| 414 | static void lynx_blit_8color_line(lynx_state *state, const int y, const int xdir) {lynx_blit_do_work(state, y, xdir, 3, 0x07);} |
| 415 | static void lynx_blit_16color_line(lynx_state *state, const int y, const int xdir) {lynx_blit_do_work(state, y, xdir, 4, 0x0f);} |
| 359 | 416 | |
| 360 | | static void lynx_blit_2color_line(lynx_state *state, const int y, const int xdir) |
| 361 | | { |
| 362 | | const int bits = 1; |
| 363 | | const int mask = 0x01; |
| 364 | | |
| 365 | | lynx_blit_do_work(state, y, xdir, bits, mask); |
| 366 | | } |
| 367 | | static void lynx_blit_4color_line(lynx_state *state, const int y, const int xdir) |
| 368 | | { |
| 369 | | const int bits = 2; |
| 370 | | const int mask = 0x03; |
| 371 | | |
| 372 | | lynx_blit_do_work(state, y, xdir, bits, mask); |
| 373 | | } |
| 374 | | static void lynx_blit_8color_line(lynx_state *state, const int y, const int xdir) |
| 375 | | { |
| 376 | | const int bits = 3; |
| 377 | | const int mask = 0x07; |
| 378 | | |
| 379 | | lynx_blit_do_work(state, y, xdir, bits, mask); |
| 380 | | } |
| 381 | | static void lynx_blit_16color_line(lynx_state *state, const int y, const int xdir) |
| 382 | | { |
| 383 | | const int bits = 4; |
| 384 | | const int mask = 0x0f; |
| 385 | | |
| 386 | | lynx_blit_do_work(state, y, xdir, bits, mask); |
| 387 | | } |
| 388 | | |
| 389 | | /* |
| 390 | | 2 color rle: ?? |
| 391 | | 0, 4 bit repeat count-1, 1 bit color |
| 392 | | 1, 4 bit count of values-1, 1 bit color, .... |
| 393 | | */ |
| 394 | | |
| 395 | | /* |
| 396 | | 4 color rle: |
| 397 | | 0, 4 bit repeat count-1, 2 bit color |
| 398 | | 1, 4 bit count of values-1, 2 bit color, .... |
| 399 | | */ |
| 400 | | |
| 401 | | /* |
| 402 | | 8 color rle: |
| 403 | | 0, 4 bit repeat count-1, 3 bit color |
| 404 | | 1, 4 bit count of values-1, 3 bit color, .... |
| 405 | | */ |
| 406 | | |
| 407 | | /* |
| 408 | | 16 color rle: |
| 409 | | 0, 4 bit repeat count-1, 4 bit color |
| 410 | | 1, 4 bit count of values-1, 4 bit color, .... |
| 411 | | */ |
| 412 | | |
| 413 | 417 | static void lynx_blit_rle_do_work( lynx_state *state, const INT16 y, const int xdir, const int bits_per_pixel, const int mask ) |
| 414 | 418 | { |
| 415 | 419 | int i; |
| r14276 | r14277 | |
| 424 | 428 | if (bits < 5 + bits_per_pixel) /* under 7 bits no complete entry */ |
| 425 | 429 | { |
| 426 | 430 | j++; |
| 427 | | if (j >= state->m_blitter.mem[state->m_blitter.bitmap]) |
| 431 | if (j >= lynx_read_ram(state, state->m_blitter.bitmap)) |
| 428 | 432 | return; |
| 429 | 433 | |
| 430 | 434 | bits += 8; |
| 431 | | buffer = (buffer << 8) | state->m_blitter.mem[state->m_blitter.bitmap + j]; |
| 435 | buffer = (buffer << 8) | lynx_read_ram(state,state->m_blitter.bitmap + j); |
| 432 | 436 | state->m_blitter.memory_accesses++; |
| 433 | 437 | } |
| 434 | 438 | |
| r14276 | r14277 | |
| 444 | 448 | if (bits < bits_per_pixel) |
| 445 | 449 | { |
| 446 | 450 | j++; |
| 447 | | if (j >= state->m_blitter.mem[state->m_blitter.bitmap]) |
| 451 | if (j >= lynx_read_ram(state, state->m_blitter.bitmap)) |
| 448 | 452 | return; |
| 449 | 453 | bits += 8; |
| 450 | | buffer = (buffer << 8) | state->m_blitter.mem[state->m_blitter.bitmap + j]; |
| 454 | buffer = (buffer << 8) | lynx_read_ram(state, state->m_blitter.bitmap + j); |
| 451 | 455 | state->m_blitter.memory_accesses++; |
| 452 | 456 | } |
| 453 | 457 | |
| r14276 | r14277 | |
| 470 | 474 | if (bits < bits_per_pixel) |
| 471 | 475 | { |
| 472 | 476 | j++; |
| 473 | | if (j >= state->m_blitter.mem[state->m_blitter.bitmap]) |
| 477 | if (j >= lynx_read_ram(state, state->m_blitter.bitmap)) |
| 474 | 478 | return; |
| 475 | 479 | bits += 8; |
| 476 | | buffer = (buffer << 8) | state->m_blitter.mem[state->m_blitter.bitmap + j]; |
| 480 | buffer = (buffer << 8) | lynx_read_ram(state, state->m_blitter.bitmap + j); |
| 477 | 481 | state->m_blitter.memory_accesses++; |
| 478 | 482 | } |
| 479 | 483 | |
| r14276 | r14277 | |
| 494 | 498 | } |
| 495 | 499 | } |
| 496 | 500 | |
| 497 | | static void lynx_blit_2color_rle_line(lynx_state *state, const int y, const int xdir) |
| 498 | | { |
| 499 | | const int bits = 1; |
| 500 | | const int mask = 0x01; |
| 501 | static void lynx_blit_2color_rle_line(lynx_state *state, const int y, const int xdir) {lynx_blit_rle_do_work(state, y, xdir, 1, 0x01);} |
| 502 | static void lynx_blit_4color_rle_line(lynx_state *state, const int y, const int xdir) {lynx_blit_rle_do_work(state, y, xdir, 2, 0x03);} |
| 503 | static void lynx_blit_8color_rle_line(lynx_state *state, const int y, const int xdir) {lynx_blit_rle_do_work(state, y, xdir, 3, 0x07);} |
| 504 | static void lynx_blit_16color_rle_line(lynx_state *state, const int y, const int xdir) {lynx_blit_rle_do_work(state, y, xdir, 4, 0x0f);} |
| 501 | 505 | |
| 502 | | lynx_blit_rle_do_work(state, y, xdir, bits, mask); |
| 503 | | } |
| 504 | | static void lynx_blit_4color_rle_line(lynx_state *state, const int y, const int xdir) |
| 505 | | { |
| 506 | | const int bits = 2; |
| 507 | | const int mask = 0x03; |
| 508 | | |
| 509 | | lynx_blit_rle_do_work(state, y, xdir, bits, mask); |
| 510 | | } |
| 511 | | static void lynx_blit_8color_rle_line(lynx_state *state, const int y, const int xdir) |
| 512 | | { |
| 513 | | const int bits = 3; |
| 514 | | const int mask = 0x07; |
| 515 | | |
| 516 | | lynx_blit_rle_do_work(state, y, xdir, bits, mask); |
| 517 | | } |
| 518 | | static void lynx_blit_16color_rle_line(lynx_state *state, const int y, const int xdir) |
| 519 | | { |
| 520 | | const int bits = 4; |
| 521 | | const int mask = 0x0f; |
| 522 | | |
| 523 | | lynx_blit_rle_do_work(state, y, xdir, bits, mask); |
| 524 | | } |
| 525 | | |
| 526 | | |
| 527 | 506 | static void lynx_blit_lines(lynx_state *state) |
| 528 | 507 | { |
| 529 | 508 | int i; |
| r14276 | r14277 | |
| 560 | 539 | if (state->m_blitter.spr_ctl0 & 0x20) /* Horizontal Flip */ |
| 561 | 540 | { |
| 562 | 541 | xdir *= -1; |
| 563 | | //state->m_blitter.x_pos -= xdir; // causes blank lines in todds adventures, klax, etc |
| 564 | 542 | } |
| 565 | 543 | |
| 566 | 544 | if (state->m_blitter.spr_ctl0 & 0x10) /* Vertical Flip */ |
| 567 | 545 | { |
| 568 | 546 | ydir *= -1; |
| 569 | | //state->m_blitter.y_pos -= ydir; // causes blank lines in todds adventures, klax, etc |
| 570 | 547 | } |
| 571 | 548 | |
| 572 | 549 | // Set height accumulator based on drawing direction |
| 573 | 550 | state->m_blitter.height_accumulator = (ydir == 1) ? state->m_blitter.height_offset : 0x00; |
| 574 | 551 | |
| 575 | | for (y = state->m_blitter.y_pos - state->m_blitter.yoff; (i = state->m_blitter.mem[state->m_blitter.bitmap]); state->m_blitter.bitmap += i) |
| 552 | for (y = state->m_blitter.y_pos - state->m_blitter.yoff; (i = lynx_read_ram(state, state->m_blitter.bitmap)); state->m_blitter.bitmap += i) |
| 576 | 553 | { |
| 577 | 554 | state->m_blitter.memory_accesses++; |
| 578 | 555 | |
| r14276 | r14277 | |
| 598 | 575 | continue; |
| 599 | 576 | } |
| 600 | 577 | |
| 601 | | INT16 x = state->m_blitter.x_pos - state->m_blitter.xoff; |
| 602 | | // superclipping |
| 603 | | if (((x > 159) && (xdir == 1)) || ((x < 0) && (xdir == -1)) || ((y > 101) && (ydir == 1)) || ((y < 0) && (ydir == -1))) |
| 604 | | continue; |
| 605 | 578 | |
| 606 | 579 | state->m_blitter.height_accumulator += state->m_blitter.height; |
| 607 | 580 | for (int i=0; i < (state->m_blitter.height_accumulator>>8); i++, y += ydir) |
| r14276 | r14277 | |
| 609 | 582 | if (y >= 0 && y < 102) |
| 610 | 583 | state->m_blitter.line_function(state, y, xdir); |
| 611 | 584 | state->m_blitter.width += (INT16)state->m_blitter.stretch; |
| 612 | | if (state->m_suzy.data[SPRSYS] & 0x10) // Vertical stretch enabled (doesn't seem to be used) |
| 585 | if (state->m_blitter.vstretch) // doesn't seem to be used |
| 613 | 586 | { |
| 614 | 587 | state->m_blitter.height += (INT16)state->m_blitter.stretch; |
| 615 | 588 | logerror("vertical stretch enabled"); |
| r14276 | r14277 | |
| 633 | 606 | static TIMER_CALLBACK(lynx_blitter_timer) |
| 634 | 607 | { |
| 635 | 608 | lynx_state *state = machine.driver_data<lynx_state>(); |
| 636 | | state->m_suzy.data[SPRSYS] &= ~0x01; //state->m_blitter finished |
| 609 | state->m_blitter.busy=0; // blitter finished |
| 637 | 610 | } |
| 638 | 611 | |
| 639 | 612 | /* |
| r14276 | r14277 | |
| 728 | 701 | lynx_blit_8color_rle_line, |
| 729 | 702 | lynx_blit_16color_rle_line |
| 730 | 703 | }; |
| 704 | |
| 731 | 705 | int i; int colors; |
| 732 | 706 | |
| 733 | 707 | state->m_blitter.memory_accesses = 0; |
| r14276 | r14277 | |
| 735 | 709 | |
| 736 | 710 | // these might be never set by the state->m_blitter hardware |
| 737 | 711 | state->m_sprite_collide = 0; |
| 712 | |
| 713 | //state->m_blitter.busy = 1; // blitter working (there's a bug somewhere that's causing slowdown when this is enabled) |
| 738 | 714 | |
| 739 | | state->m_blitter.memory_accesses += 2; |
| 740 | | |
| 741 | 715 | // Last SCB is indicated by zero in the high byte of SCBNEXT |
| 742 | 716 | while (state->m_blitter.scb_next & 0xff00) |
| 743 | 717 | { |
| r14276 | r14277 | |
| 745 | 719 | state->m_blitter.tilt = 0; |
| 746 | 720 | state->m_blitter.tilt_accumulator = 0; |
| 747 | 721 | |
| 748 | | state->m_blitter.memory_accesses += 1; |
| 749 | | |
| 750 | 722 | // move to load_scb() function |
| 751 | 723 | state->m_blitter.scb = state->m_blitter.scb_next; // current scb |
| 752 | | state->m_blitter.scb_next = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_SCBNEXT); // next scb |
| 724 | state->m_blitter.scb_next = lynx_read_ram(state, state->m_blitter.scb + SCB_SCBNEXT) | (lynx_read_ram(state, state->m_blitter.scb + SCB_SCBNEXT + 1) << 8); // next scb |
| 725 | state->m_blitter.spr_ctl0 = lynx_read_ram(state, state->m_blitter.scb + SCB_SPRCTL0); |
| 726 | state->m_blitter.spr_ctl1 = lynx_read_ram(state, state->m_blitter.scb + SCB_SPRCTL1); |
| 727 | state->m_blitter.spr_coll = lynx_read_ram(state, state->m_blitter.scb + SCB_SPRCOLL); |
| 728 | state->m_blitter.memory_accesses += 8; |
| 753 | 729 | |
| 754 | | state->m_blitter.spr_ctl0 = state->m_blitter.mem[state->m_blitter.scb + SCB_SPRCTL0]; |
| 755 | | state->m_blitter.spr_ctl1 = state->m_blitter.mem[state->m_blitter.scb + SCB_SPRCTL1]; |
| 756 | | state->m_blitter.spr_coll = state->m_blitter.mem[state->m_blitter.scb + SCB_SPRCOLL]; |
| 757 | | |
| 758 | 730 | if(!(state->m_blitter.spr_ctl1 & 0x04)) // sprite will be processed (if sprite is skipped first 5 bytes are still copied to suzy) |
| 759 | 731 | { |
| 760 | | state->m_blitter.bitmap = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_SPRDLINE); |
| 761 | | state->m_blitter.x_pos = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_HPOSSTRT); |
| 762 | | state->m_blitter.y_pos = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_VPOSSTRT); |
| 732 | state->m_blitter.bitmap = lynx_read_ram(state, state->m_blitter.scb + SCB_SPRDLINE) | (lynx_read_ram(state, state->m_blitter.scb + SCB_SPRDLINE + 1) << 8); |
| 733 | state->m_blitter.x_pos = lynx_read_ram(state, state->m_blitter.scb + SCB_HPOSSTRT) | (lynx_read_ram(state, state->m_blitter.scb + SCB_HPOSSTRT + 1) << 8); |
| 734 | state->m_blitter.y_pos = lynx_read_ram(state, state->m_blitter.scb + SCB_VPOSSTRT) | (lynx_read_ram(state, state->m_blitter.scb + SCB_VPOSSTRT + 1) << 8); |
| 735 | state->m_blitter.memory_accesses += 6; |
| 763 | 736 | |
| 764 | 737 | switch(state->m_blitter.spr_ctl1 & 0x30) // reload sprite scaling |
| 765 | 738 | { |
| 766 | 739 | case 0x30: // width, height, tilt, stretch |
| 767 | | state->m_blitter.tilt = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_TILT); |
| 740 | state->m_blitter.tilt = lynx_read_ram(state, state->m_blitter.scb + SCB_TILT) | (lynx_read_ram(state, state->m_blitter.scb + SCB_TILT + 1) << 8); |
| 741 | state->m_blitter.memory_accesses+=2; |
| 768 | 742 | case 0x20: // width, height, stretch |
| 769 | | state->m_blitter.stretch = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_STRETCH); |
| 743 | state->m_blitter.stretch = lynx_read_ram(state, state->m_blitter.scb + SCB_STRETCH) | (lynx_read_ram(state, state->m_blitter.scb + SCB_STRETCH + 1) << 8); |
| 744 | state->m_blitter.memory_accesses+=2; |
| 770 | 745 | case 0x10: // width, height |
| 771 | | state->m_blitter.width = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_SPRHSIZ); |
| 772 | | state->m_blitter.height = GET_WORD(state->m_blitter.mem, state->m_blitter.scb + SCB_SPRVSIZ); |
| 746 | state->m_blitter.width = lynx_read_ram(state, state->m_blitter.scb + SCB_SPRHSIZ) | (lynx_read_ram(state, state->m_blitter.scb + SCB_SPRHSIZ + 1) << 8); |
| 747 | state->m_blitter.height = lynx_read_ram(state, state->m_blitter.scb + SCB_SPRVSIZ) | (lynx_read_ram(state, state->m_blitter.scb + SCB_SPRVSIZ + 1) << 8); |
| 748 | state->m_blitter.memory_accesses+=4; |
| 773 | 749 | } |
| 774 | 750 | |
| 775 | 751 | if(!(state->m_blitter.spr_ctl1 & 0x08)) // reload palette |
| r14276 | r14277 | |
| 783 | 759 | |
| 784 | 760 | for (i = 0; i < colors / 2; i++) |
| 785 | 761 | { |
| 786 | | state->m_blitter.color[i * 2] = state->m_blitter.mem[state->m_blitter.scb + palette_offset + i] >> 4; |
| 787 | | state->m_blitter.color[i * 2 + 1 ] = state->m_blitter.mem[state->m_blitter.scb + palette_offset + i] & 0x0f; |
| 762 | state->m_blitter.color[i * 2] = lynx_read_ram(state, state->m_blitter.scb + palette_offset + i) >> 4; |
| 763 | state->m_blitter.color[i * 2 + 1 ] = lynx_read_ram(state, state->m_blitter.scb + palette_offset + i) & 0x0f; |
| 788 | 764 | state->m_blitter.memory_accesses++; |
| 789 | 765 | } |
| 790 | 766 | } |
| r14276 | r14277 | |
| 793 | 769 | |
| 794 | 770 | if (!(state->m_blitter.spr_ctl1 & 0x04)) // if 0, we skip this sprite |
| 795 | 771 | { |
| 796 | | state->m_blitter.colpos = state->m_blitter.scb + GET_WORD(state->m_suzy.data, COLLOFFL); |
| 797 | | state->m_blitter.memory_accesses += 6; |
| 798 | | |
| 772 | state->m_blitter.colpos = state->m_blitter.scb + (state->m_suzy.data[COLLOFFL] | (state->m_suzy.data[COLLOFFH]<<8)); |
| 799 | 773 | state->m_blitter.mode = state->m_blitter.spr_ctl0 & 0x07; |
| 800 | 774 | |
| 801 | 775 | if (state->m_blitter.spr_ctl1 & 0x80) // totally literal sprite |
| r14276 | r14277 | |
| 803 | 777 | else |
| 804 | 778 | state->m_blitter.line_function = blit_rle_line[state->m_blitter.spr_ctl0 >> 6]; |
| 805 | 779 | |
| 806 | | if (!(state->m_blitter.spr_coll & 0x20) && !(state->m_suzy.data[SPRSYS] & 0x20)) |
| 780 | if (!(state->m_blitter.spr_coll & 0x20) && !(state->m_blitter.no_collide)) |
| 807 | 781 | { |
| 808 | 782 | switch (state->m_blitter.mode) |
| 809 | 783 | { |
| r14276 | r14277 | |
| 813 | 787 | case XOR_SPRITE: |
| 814 | 788 | case SHADOW: |
| 815 | 789 | state->m_sprite_collide = 1; |
| 816 | | state->m_blitter.mem[state->m_blitter.colpos] = 0; |
| 790 | lynx_write_ram(state, state->m_blitter.colpos, 0); |
| 817 | 791 | state->m_blitter.spritenr = state->m_blitter.spr_coll & 0x0f; |
| 818 | 792 | break; |
| 819 | 793 | case BACKGROUND: |
| r14276 | r14277 | |
| 825 | 799 | /* Draw Sprites */ |
| 826 | 800 | lynx_blit_lines(state); |
| 827 | 801 | } |
| 828 | | state->m_blitter.memory_accesses += 2; |
| 829 | 802 | } |
| 830 | | |
| 831 | | if (0) |
| 832 | | machine.scheduler().timer_set(machine.device<cpu_device>("maincpu")->cycles_to_attotime(state->m_blitter.memory_accesses*20), FUNC(lynx_blitter_timer)); |
| 803 | |
| 804 | if (0) // turned off for now as it cuases slowdown in some games due to a bug somewhere |
| 805 | { |
| 806 | if (state->m_blitter.memory_accesses != 0) |
| 807 | machine.scheduler().timer_set(machine.device<cpu_device>("maincpu")->cycles_to_attotime(state->m_blitter.memory_accesses), FUNC(lynx_blitter_timer)); |
| 808 | else |
| 809 | state->m_blitter.busy = 0; // blitter done |
| 810 | } |
| 833 | 811 | } |
| 834 | 812 | |
| 835 | 813 | |
| r14276 | r14277 | |
| 910 | 888 | |
| 911 | 889 | res = left * right; |
| 912 | 890 | |
| 913 | | if (state->m_suzy.data[SPRSYS] & 0x80) /* signed math */ |
| 891 | if (state->m_suzy.signed_math) |
| 914 | 892 | { |
| 915 | 893 | if (!(state->m_sign_AB + state->m_sign_CD)) /* different signs */ |
| 916 | 894 | res = (res ^ 0xffffffff) + 1; |
| r14276 | r14277 | |
| 921 | 899 | state->m_suzy.data[MATH_F] = res >> 16; |
| 922 | 900 | state->m_suzy.data[MATH_E] = res >> 24; |
| 923 | 901 | |
| 924 | | if (state->m_suzy.data[SPRSYS] & 0x40) /* is accumulation allowed? */ |
| 902 | if (state->m_suzy.accumulate) |
| 925 | 903 | { |
| 926 | 904 | accu = state->m_suzy.data[MATH_M] | state->m_suzy.data[MATH_L] << 8 | state->m_suzy.data[MATH_K] << 16 | state->m_suzy.data[MATH_J] << 24; |
| 927 | 905 | accu += res; |
| r14276 | r14277 | |
| 1017 | 995 | //case PROCADRL: |
| 1018 | 996 | case SUZYHREV: |
| 1019 | 997 | return 0x01; // must not be 0 for correct power up |
| 1020 | | case SPRSYS: /* Better check this with docs! */ |
| 1021 | | if (state->m_blitter.time==attotime::zero) |
| 1022 | | { |
| 1023 | | if (space->machine().device<cpu_device>("maincpu")->attotime_to_cycles(space->machine().time() - state->m_blitter.time) > state->m_blitter.memory_accesses * 20) |
| 1024 | | { |
| 1025 | | state->m_suzy.data[offset] &= ~0x01; //state->m_blitter finished |
| 1026 | | state->m_blitter.time = attotime::zero; |
| 1027 | | } |
| 1028 | | } |
| 1029 | | value = state->m_suzy.data[offset]; |
| 1030 | | value &= ~0x80; // math finished |
| 1031 | | value &= ~0x40; |
| 998 | case SPRSYS: |
| 999 | // math busy, last carry, unsafe access, and stop on current sprite bits not implemented. |
| 1032 | 1000 | if (state->m_suzy.accumulate_overflow) |
| 1033 | 1001 | value |= 0x40; |
| 1002 | if (state->m_blitter.vstretch) |
| 1003 | value |= 0x10; |
| 1004 | if (state->m_blitter.lefthanded) |
| 1005 | value |= 0x08; |
| 1006 | if (state->m_blitter.busy) |
| 1007 | value |= 0x01; |
| 1034 | 1008 | break; |
| 1035 | 1009 | case JOYSTICK: |
| 1036 | 1010 | input = input_port_read(space->machine(), "JOY"); |
| r14276 | r14277 | |
| 1053 | 1027 | if (value & PAD_LEFT) input |= PAD_UP; |
| 1054 | 1028 | break; |
| 1055 | 1029 | } |
| 1056 | | if (state->m_suzy.data[SPRSYS] & 0x08) /* Left handed controls */ |
| 1030 | if (state->m_blitter.lefthanded) |
| 1057 | 1031 | { |
| 1058 | 1032 | value = input & 0x0f; |
| 1059 | 1033 | if (input & PAD_UP) value |= PAD_DOWN; |
| r14276 | r14277 | |
| 1076 | 1050 | case SPRCTL1: |
| 1077 | 1051 | case SPRCOLL: |
| 1078 | 1052 | case SPRINIT: |
| 1079 | | //case SUZYBUSEN: |
| 1053 | case SUZYBUSEN: |
| 1080 | 1054 | case SPRGO: |
| 1081 | 1055 | logerror("read from write only register %x\n", offset); |
| 1082 | 1056 | value = 0; |
| r14276 | r14277 | |
| 1092 | 1066 | { |
| 1093 | 1067 | lynx_state *state = space->machine().driver_data<lynx_state>(); |
| 1094 | 1068 | state->m_suzy.data[offset] = data; |
| 1095 | | |
| 1069 | //logerror("suzy write %.2x %.2x\n",offset,data); |
| 1096 | 1070 | /* Additional effects of a write */ |
| 1097 | 1071 | /* Even addresses are the LSB. Any CPU write to an LSB in 0x00-0x7f will set the MSB to 0. */ |
| 1098 | 1072 | /* This in particular holds for math quantities: Writing to B (0x54), D (0x52), |
| r14276 | r14277 | |
| 1232 | 1206 | case MATH_C: |
| 1233 | 1207 | /* If we are going to perform a signed multiplication, we store the sign and convert the number |
| 1234 | 1208 | to an unsigned one */ |
| 1235 | | if (state->m_suzy.data[SPRSYS] & 0x80) /* signed math */ |
| 1209 | if (state->m_suzy.signed_math) |
| 1236 | 1210 | { |
| 1237 | 1211 | UINT16 factor, temp; |
| 1238 | 1212 | factor = state->m_suzy.data[MATH_D] | (state->m_suzy.data[MATH_C] << 8); |
| r14276 | r14277 | |
| 1251 | 1225 | /* If we are going to perform a signed multiplication, we also store the sign and convert the |
| 1252 | 1226 | number to an unsigned one */ |
| 1253 | 1227 | case MATH_A: |
| 1254 | | if (state->m_suzy.data[SPRSYS] & 0x80) /* signed math */ |
| 1228 | if (state->m_suzy.signed_math) |
| 1255 | 1229 | { |
| 1256 | 1230 | UINT16 factor, temp; |
| 1257 | 1231 | factor = state->m_suzy.data[MATH_B] | (state->m_suzy.data[MATH_A] << 8); |
| r14276 | r14277 | |
| 1280 | 1254 | case SPRCOLL: |
| 1281 | 1255 | state->m_blitter.spr_coll = data; |
| 1282 | 1256 | break; |
| 1257 | case SUZYBUSEN: |
| 1258 | logerror("write to SUSYBUSEN %x \n", data); |
| 1259 | break; |
| 1260 | case SPRSYS: |
| 1261 | state->m_suzy.signed_math = data & 0x80; |
| 1262 | state->m_suzy.accumulate = data & 0x40; |
| 1263 | state->m_blitter.no_collide = data & 0x20; |
| 1264 | state->m_blitter.vstretch = data & 0x10; |
| 1265 | state->m_blitter.lefthanded = data & 0x08; |
| 1266 | // unsafe access clear and sprite engine stop request are not enabled |
| 1267 | break; |
| 1283 | 1268 | case SPRGO: |
| 1284 | | if (data & 0x01) |
| 1269 | if ((data & 0x01) && state->m_suzy.data[SUZYBUSEN]) |
| 1285 | 1270 | { |
| 1286 | | state->m_blitter.time = space->machine().time(); |
| 1271 | //state->m_blitter.time = space->machine().time(); |
| 1287 | 1272 | lynx_blitter(space->machine()); |
| 1288 | 1273 | } |
| 1289 | 1274 | break; |
| r14276 | r14277 | |
| 1314 | 1299 | */ |
| 1315 | 1300 | |
| 1316 | 1301 | |
| 1317 | | |
| 1318 | | static UINT8 lynx_read_vram(lynx_state *state, UINT16 address) |
| 1319 | | { |
| 1320 | | UINT8 result = 0x00; |
| 1321 | | if (address <= 0xfbff) |
| 1322 | | result = state->m_mem_0000[address - 0x0000]; |
| 1323 | | else if (address <= 0xfcff) |
| 1324 | | result = state->m_mem_fc00[address - 0xfc00]; |
| 1325 | | else if (address <= 0xfdff) |
| 1326 | | result = state->m_mem_fd00[address - 0xfd00]; |
| 1327 | | else if (address <= 0xfff7) |
| 1328 | | result = state->m_mem_fe00[address - 0xfe00]; |
| 1329 | | else if (address >= 0xfffa) |
| 1330 | | result = state->m_mem_fffa[address - 0xfffa]; |
| 1331 | | return result; |
| 1332 | | } |
| 1333 | | |
| 1334 | | |
| 1335 | 1302 | /* |
| 1336 | 1303 | DISPCTL EQU $FD92 ; set to $D by INITMIKEY |
| 1337 | 1304 | |
| r14276 | r14277 | |
| 1341 | 1308 | ; B1 1 EQU flip screen |
| 1342 | 1309 | ; B0 1 EQU video DMA enabled |
| 1343 | 1310 | */ |
| 1344 | | static void lynx_draw_lines(running_machine &machine, int newline) |
| 1311 | |
| 1312 | static void lynx_draw_line(running_machine &machine) |
| 1345 | 1313 | { |
| 1346 | 1314 | lynx_state *state = machine.driver_data<lynx_state>(); |
| 1347 | | int x, yend; |
| 1315 | int x, y; |
| 1348 | 1316 | UINT16 j; // clipping needed! |
| 1349 | 1317 | UINT8 byte; |
| 1350 | 1318 | UINT16 *line; |
| 1351 | | |
| 1352 | | if (newline == -1) |
| 1353 | | yend = 102; |
| 1354 | | else |
| 1355 | | yend = newline; |
| 1356 | | |
| 1357 | | if (yend > 102) |
| 1358 | | yend = 102; |
| 1359 | | |
| 1360 | | if (yend == state->m_line_y) |
| 1361 | | { |
| 1362 | | if (newline == -1) |
| 1363 | | state->m_line_y = 0; |
| 1364 | | return; |
| 1365 | | } |
| 1366 | | |
| 1319 | |
| 1320 | |
| 1321 | // calculate y: first three lines are vblank, |
| 1322 | y = 101-state->m_timer[2].counter; |
| 1367 | 1323 | // Documentation states lower two bits of buffer address are ignored (thus 0xfffc mask) |
| 1368 | | j = (state->m_mikey.disp_addr & 0xfffc) + state->m_line_y * 160 / 2; |
| 1324 | j = (state->m_mikey.disp_addr & 0xfffc) + y * 160 / 2; |
| 1369 | 1325 | |
| 1370 | 1326 | if (state->m_mikey.data[0x92] & 0x02) |
| 1371 | 1327 | { |
| 1372 | 1328 | j -= 160 * 102 / 2 - 1; |
| 1373 | | for ( ; state->m_line_y < yend; state->m_line_y++) |
| 1329 | line = &state->m_bitmap_temp.pix16(102 - 1 - y); |
| 1330 | for (x = 160 - 2; x >= 0; j++, x -= 2) |
| 1374 | 1331 | { |
| 1375 | | line = &state->m_bitmap.pix16(102 - 1 - state->m_line_y); |
| 1376 | | for (x = 160 - 2; x >= 0; j++, x -= 2) |
| 1377 | | { |
| 1378 | | byte = lynx_read_vram(state, j); |
| 1379 | | line[x + 1] = state->m_palette[(byte >> 4) & 0x0f]; |
| 1380 | | line[x + 0] = state->m_palette[(byte >> 0) & 0x0f]; |
| 1381 | | } |
| 1332 | byte = lynx_read_ram(state, j); |
| 1333 | line[x + 1] = state->m_palette[(byte >> 4) & 0x0f]; |
| 1334 | line[x + 0] = state->m_palette[(byte >> 0) & 0x0f]; |
| 1382 | 1335 | } |
| 1383 | 1336 | } |
| 1384 | 1337 | else |
| 1385 | 1338 | { |
| 1386 | | for ( ; state->m_line_y < yend; state->m_line_y++) |
| 1339 | line = &state->m_bitmap_temp.pix16(y); |
| 1340 | for (x = 0; x < 160; j++, x += 2) |
| 1387 | 1341 | { |
| 1388 | | line = &state->m_bitmap.pix16(state->m_line_y); |
| 1389 | | for (x = 0; x < 160; j++, x += 2) |
| 1390 | | { |
| 1391 | | byte = lynx_read_vram(state, j); |
| 1392 | | line[x + 0] = state->m_palette[(byte >> 4) & 0x0f]; |
| 1393 | | line[x + 1] = state->m_palette[(byte >> 0) & 0x0f]; |
| 1394 | | } |
| 1342 | byte = lynx_read_ram(state, j); |
| 1343 | line[x + 0] = state->m_palette[(byte >> 4) & 0x0f]; |
| 1344 | line[x + 1] = state->m_palette[(byte >> 0) & 0x0f]; |
| 1395 | 1345 | } |
| 1396 | 1346 | } |
| 1397 | 1347 | } |
| 1398 | 1348 | |
| 1399 | | |
| 1400 | 1349 | /**************************************** |
| 1401 | 1350 | |
| 1402 | 1351 | Timers |
| r14276 | r14277 | |
| 1460 | 1409 | switch ( which ) // count down linked timers |
| 1461 | 1410 | { |
| 1462 | 1411 | case 0: |
| 1463 | | if ((state->m_line == 2) || (state->m_line == 3) || (state->m_line == 4)) |
| 1412 | switch (state->m_timer[2].counter) |
| 1464 | 1413 | { |
| 1465 | | //state->m_mikey.vb_rest = 1; |
| 1414 | case 104: |
| 1415 | case 103: |
| 1416 | state->m_mikey.vb_rest = 1; |
| 1417 | break; |
| 1418 | case 102: |
| 1419 | state->m_mikey.disp_addr = state->m_mikey.data[0x94] | (state->m_mikey.data[0x95] << 8); |
| 1420 | break; |
| 1421 | case 101: |
| 1422 | state->m_mikey.vb_rest = 0; |
| 1423 | lynx_draw_line( machine ); |
| 1424 | break; |
| 1425 | default: |
| 1426 | lynx_draw_line( machine ); |
| 1466 | 1427 | } |
| 1467 | | else |
| 1468 | | state->m_mikey.vb_rest = 0; |
| 1469 | | if (state->m_line == 3) |
| 1470 | | { |
| 1471 | | state->m_mikey.disp_addr = state->m_mikey.data[0x94] | (state->m_mikey.data[0x95] << 8); |
| 1472 | | lynx_draw_lines( machine, -1 ); |
| 1473 | | } |
| 1474 | 1428 | lynx_timer_count_down( machine, 2 ); |
| 1475 | | state->m_line++; |
| 1476 | 1429 | break; |
| 1477 | | case 2: |
| 1430 | case 2: |
| 1431 | copybitmap(state->m_bitmap, state->m_bitmap_temp, 0, 0, 0, 0, machine.primary_screen->cliprect()); |
| 1478 | 1432 | lynx_timer_count_down( machine, 4 ); |
| 1479 | | lynx_draw_lines( machine, -1 ); |
| 1480 | | state->m_line=0; |
| 1481 | 1433 | break; |
| 1482 | 1434 | case 1: |
| 1483 | 1435 | lynx_timer_count_down( machine, 3 ); |
| r14276 | r14277 | |
| 1502 | 1454 | if ( state->m_timer[which].counter > 0 ) |
| 1503 | 1455 | { |
| 1504 | 1456 | state->m_timer[which].counter--; |
| 1457 | //state->m_timer[which].borrow_in = 1; |
| 1505 | 1458 | return; |
| 1506 | 1459 | } |
| 1507 | 1460 | if ( state->m_timer[which].counter == 0 ) |
| 1508 | 1461 | { |
| 1509 | | state->m_timer[which].cntrl2 |= 8; // set timer done |
| 1462 | if (state->m_timer[which].cntrl2 & 0x01) // borrow out |
| 1463 | { |
| 1510 | 1464 | lynx_timer_signal_irq(machine, which); |
| 1511 | 1465 | if ( state->m_timer[which].cntrl1 & 0x10 ) // if reload enabled |
| 1512 | 1466 | { |
| 1513 | 1467 | state->m_timer[which].counter = state->m_timer[which].bakup; |
| 1514 | | // should we unset timer done? |
| 1515 | 1468 | } |
| 1516 | 1469 | else |
| 1517 | 1470 | { |
| 1518 | | state->m_timer[which].counter--; // Is this correct or should it stop at zero? |
| 1471 | state->m_timer[which].cntrl2 |= 8; // set timer done |
| 1519 | 1472 | } |
| 1473 | state->m_timer[which].cntrl2 &= ~0x01; // clear borrow out |
| 1474 | } |
| 1475 | else |
| 1476 | state->m_timer[which].cntrl2 |= 0x01; // set borrow out |
| 1520 | 1477 | return; |
| 1521 | 1478 | } |
| 1522 | 1479 | } |
| 1480 | else |
| 1481 | { |
| 1482 | //state->m_timer[which].borrow_in = 0; |
| 1483 | state->m_timer[which].cntrl2 &= ~0x01; |
| 1484 | } |
| 1523 | 1485 | } |
| 1524 | 1486 | |
| 1525 | 1487 | static UINT32 lynx_time_factor(int val) |
| r14276 | r14277 | |
| 1540 | 1502 | static TIMER_CALLBACK(lynx_timer_shot) |
| 1541 | 1503 | { |
| 1542 | 1504 | lynx_state *state = machine.driver_data<lynx_state>(); |
| 1543 | | state->m_timer[param].cntrl2 |= 8; // set timer done |
| 1544 | 1505 | lynx_timer_signal_irq( machine, param ); |
| 1545 | 1506 | if ( ! ( state->m_timer[param].cntrl1 & 0x10 ) ) // if reload not enabled |
| 1507 | { |
| 1546 | 1508 | state->m_timer[param].timer_active = 0; |
| 1509 | state->m_timer[param].cntrl2 |= 8; // set timer done |
| 1510 | } |
| 1547 | 1511 | else |
| 1548 | 1512 | { |
| 1549 | 1513 | attotime t = (attotime::from_hz(lynx_time_factor(state->m_timer[param].cntrl1 & 0x07)) * (state->m_timer[param].bakup + 1)); |
| r14276 | r14277 | |
| 1571 | 1535 | else |
| 1572 | 1536 | { |
| 1573 | 1537 | if ( state->m_timer[which].timer_active ) |
| 1574 | | //value = (UINT8) ( state->m_timer[which].bakup - (state->m_timer[which].timer->remaining() * lynx_time_factor( state->m_timer[which].cntrl1 & 0x07 )).seconds); |
| 1575 | | value = (UINT8) (state->m_timer[which].timer->remaining().as_ticks(1000000>>(state->m_timer[which].cntrl1 & 0x07))); // aren't we just returning the remaining time? |
| 1538 | { |
| 1539 | state->m_timer[which].counter = (UINT8) (state->m_timer[which].timer->remaining().as_ticks(1000000>>(state->m_timer[which].cntrl1 & 0x07))); |
| 1540 | state->m_timer[which].counter -= (state->m_timer[which].counter) ? 1 : 0; |
| 1541 | } |
| 1576 | 1542 | } |
| 1577 | 1543 | break; |
| 1578 | 1544 | |
| r14276 | r14277 | |
| 1586 | 1552 | |
| 1587 | 1553 | static void lynx_timer_write(lynx_state *state, int which, int offset, UINT8 data) |
| 1588 | 1554 | { |
| 1589 | | // logerror("timer %d write %x %.2x\n", which, offset, data); |
| 1555 | //logerror("timer %d write %x %.2x\n", which, offset, data); |
| 1590 | 1556 | attotime t; |
| 1557 | |
| 1558 | if ( state->m_timer[which].timer_active && ((state->m_timer[which].cntrl1 & 0x07) != 0x07)) |
| 1559 | { |
| 1560 | state->m_timer[which].counter = (UINT8) (state->m_timer[which].timer->remaining().as_ticks(1000000>>(state->m_timer[which].cntrl1 & 0x07))); |
| 1561 | state->m_timer[which].counter -= (state->m_timer[which].counter) ? 1 : 0; |
| 1562 | } |
| 1563 | |
| 1591 | 1564 | switch (offset) |
| 1592 | 1565 | { |
| 1593 | 1566 | case 0: |
| r14276 | r14277 | |
| 1607 | 1580 | } |
| 1608 | 1581 | |
| 1609 | 1582 | /* Update timers */ |
| 1610 | | if ( offset < 3 ) |
| 1611 | | { |
| 1583 | //if ( offset < 3 ) |
| 1584 | //{ |
| 1612 | 1585 | state->m_timer[which].timer->reset(); |
| 1613 | 1586 | state->m_timer[which].timer_active = 0; |
| 1614 | | if ((state->m_timer[which].cntrl1 & 0x08)) // if enable count |
| 1587 | if ((state->m_timer[which].cntrl1 & 0x08) && !(state->m_timer[which].cntrl2 & 0x08)) // if enable count |
| 1615 | 1588 | { |
| 1616 | | if ((state->m_timer[which].cntrl1 & 0x07) != 0x07) // if not set to link mode |
| 1589 | if ((state->m_timer[which].cntrl1 & 0x07) != 0x07) // if not set to link mode |
| 1617 | 1590 | { |
| 1618 | | if (state->m_timer[which].cntrl1 & 0x10) // reload enabled |
| 1619 | | t = (attotime::from_hz(lynx_time_factor(state->m_timer[which].cntrl1 & 0x07)) * (state->m_timer[which].bakup + 1)); |
| 1620 | | else |
| 1621 | | t = (attotime::from_hz(lynx_time_factor(state->m_timer[which].cntrl1 & 0x07)) * (state->m_timer[which].counter + 1)); |
| 1591 | t = (attotime::from_hz(lynx_time_factor(state->m_timer[which].cntrl1 & 0x07)) * (state->m_timer[which].counter + 1)); |
| 1622 | 1592 | state->m_timer[which].timer->adjust(t, which); |
| 1623 | 1593 | state->m_timer[which].timer_active = 1; |
| 1624 | 1594 | } |
| 1625 | 1595 | } |
| 1626 | | } |
| 1596 | //} |
| 1627 | 1597 | } |
| 1628 | 1598 | |
| 1629 | 1599 | |
| r14276 | r14277 | |
| 1678 | 1648 | value = state->m_uart.data_received; |
| 1679 | 1649 | break; |
| 1680 | 1650 | } |
| 1681 | | // logerror("uart read %.2x %.2x\n", offset, value); |
| 1651 | logerror("uart read %.2x %.2x\n", offset, value); |
| 1682 | 1652 | return value; |
| 1683 | 1653 | } |
| 1684 | 1654 | |
| 1685 | 1655 | static WRITE8_HANDLER(lynx_uart_w) |
| 1686 | 1656 | { |
| 1687 | 1657 | lynx_state *state = space->machine().driver_data<lynx_state>(); |
| 1688 | | // logerror("uart write %.2x %.2x\n", offset, data); |
| 1658 | logerror("uart write %.2x %.2x\n", offset, data); |
| 1689 | 1659 | switch (offset) |
| 1690 | 1660 | { |
| 1691 | 1661 | case 0x8c: |
| r14276 | r14277 | |
| 1813 | 1783 | case 0x80: |
| 1814 | 1784 | state->m_mikey.data[0x81] &= ~data; // clear interrupt source |
| 1815 | 1785 | // logerror("mikey write %.2x %.2x\n", offset, data); |
| 1816 | | if (!state->m_mikey.data[0x81]) |
| 1786 | if (!(state->m_mikey.data[0x81] & ~0x10)) |
| 1817 | 1787 | cputag_set_input_line(space->machine(), "maincpu", M65SC02_IRQ_LINE, CLEAR_LINE); |
| 1818 | 1788 | break; |
| 1819 | 1789 | |
| 1820 | 1790 | /* Is this correct? */ // Notes say writing to register will result in interupt being triggered. |
| 1821 | 1791 | case 0x81: |
| 1822 | 1792 | state->m_mikey.data[0x81] |= data; |
| 1823 | | if (data) |
| 1793 | if (data & ~0x10) |
| 1824 | 1794 | cputag_set_input_line(space->machine(), "maincpu", M65SC02_IRQ_LINE, ASSERT_LINE); |
| 1825 | 1795 | break; |
| 1826 | 1796 | |
| r14276 | r14277 | |
| 1853 | 1823 | case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7: |
| 1854 | 1824 | case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: |
| 1855 | 1825 | state->m_mikey.data[offset] = data; |
| 1856 | | lynx_draw_lines(space->machine(), state->m_line); |
| 1857 | 1826 | |
| 1858 | 1827 | /* RED = 0xb- & 0x0f, GREEN = 0xa- & 0x0f, BLUE = (0xb- & 0xf0) >> 4 */ |
| 1859 | 1828 | state->m_palette[offset & 0x0f] = space->machine().pens[ |
| r14276 | r14277 | |
| 1971 | 1940 | */ |
| 1972 | 1941 | |
| 1973 | 1942 | lynx_uart_reset(state); |
| 1974 | | |
| 1943 | |
| 1975 | 1944 | // hack to allow current object loading to work |
| 1976 | | #if 1 |
| 1945 | #if |
| 1977 | 1946 | lynx_timer_write( state, 0, 0, 160 ); // set backup value (hpos) = 160 |
| 1978 | 1947 | lynx_timer_write( state, 0, 1, 0x10 | 0x8 | 0 ); // enable count, enable reload, 1us period |
| 1979 | | lynx_timer_write( state, 2, 0, 102 ); // set backup value (vpos) = 102 |
| 1948 | lynx_timer_write( state, 2, 0, 105 ); // set backup value (vpos) = 102 |
| 1980 | 1949 | lynx_timer_write( state, 2, 1, 0x10 | 0x8 | 7 ); // enable count, enable reload, link |
| 1981 | 1950 | #endif |
| 1982 | 1951 | } |
| r14276 | r14277 | |
| 1989 | 1958 | MACHINE_START( lynx ) |
| 1990 | 1959 | { |
| 1991 | 1960 | lynx_state *state = machine.driver_data<lynx_state>(); |
| 1961 | state->m_bitmap_temp.allocate(160,102,0,0); |
| 1962 | |
| 1992 | 1963 | int i; |
| 1993 | 1964 | state->save_item(NAME(state->m_memory_config)); |
| 1994 | 1965 | state->save_pointer(NAME(state->m_mem_fe00), state->m_mem_fe00_size); |