src/mess/machine/lynx.c
| r3406 | r3407 | |
| 6 | 6 | #include "includes/lynx.h" |
| 7 | 7 | #include "cpu/m6502/m6502.h" |
| 8 | 8 | |
| 9 | #include "devices/cartslot.h" |
| 10 | #include "hash.h" |
| 9 | 11 | |
| 10 | | UINT16 lynx_granularity = 1; |
| 12 | |
| 13 | static UINT16 lynx_granularity = 1; |
| 11 | 14 | static int lynx_line; |
| 15 | static int lynx_line_y; |
| 16 | static int sign_AB = 0, sign_CD = 0; |
| 12 | 17 | |
| 18 | static UINT32 lynx_palette[0x10]; |
| 19 | |
| 20 | static int rotate = 0; |
| 21 | static int lynx_rotate; |
| 22 | |
| 23 | #define MATH_A 0x55 |
| 24 | #define MATH_B 0x54 |
| 25 | #define MATH_C 0x53 |
| 26 | #define MATH_D 0x52 |
| 27 | #define MATH_E 0x63 |
| 28 | #define MATH_F 0x62 |
| 29 | #define MATH_G 0x61 |
| 30 | #define MATH_H 0x60 |
| 31 | #define MATH_J 0x6f |
| 32 | #define MATH_K 0x6e |
| 33 | #define MATH_L 0x6d |
| 34 | #define MATH_M 0x6c |
| 35 | #define MATH_N 0x57 |
| 36 | #define MATH_P 0x56 |
| 37 | #define SPRG0 0x91 |
| 38 | #define SPRSYS 0x92 |
| 39 | |
| 40 | |
| 41 | #define PAD_UP 0x80 |
| 42 | #define PAD_DOWN 0x40 |
| 43 | #define PAD_LEFT 0x20 |
| 44 | #define PAD_RIGHT 0x10 |
| 45 | |
| 13 | 46 | typedef struct |
| 14 | 47 | { |
| 15 | | union |
| 16 | | { |
| 17 | | UINT8 data[0x100]; |
| 18 | | struct |
| 19 | | { |
| 20 | | struct { UINT8 l, h; } |
| 21 | | // eng used by the blitter engine |
| 22 | | // scb written by the blitter scb blocks to engine expander |
| 23 | | // used by the engine |
| 24 | | // might be used directly by software! |
| 25 | | eng1, eng2, |
| 26 | | h_offset, v_offset, vidbas, colbas, |
| 27 | | eng3, eng4, |
| 28 | | scb1, scb2, scb3, scb4, scb5, scb6, |
| 29 | | eng5, eng6, eng7, eng8, |
| 30 | | colloff, |
| 31 | | eng9, |
| 32 | | hsizoff, vsizoff, |
| 33 | | eng10, eng11; |
| 34 | | UINT8 res[0x20]; |
| 35 | | UINT8 used[2]; |
| 36 | | UINT8 D,C,B,A,P,N; |
| 37 | | UINT8 res1[8]; |
| 38 | | UINT8 H,G,F,E; |
| 39 | | UINT8 res2[8]; |
| 40 | | UINT8 M,L,K,J; |
| 41 | | UINT8 res3[0x21]; |
| 42 | | UINT8 SPRG0; |
| 43 | | UINT8 SPRSYS; |
| 44 | | } s; |
| 45 | | } u; |
| 46 | | int accumulate_overflow; |
| 47 | | UINT8 high; |
| 48 | | int low; |
| 48 | UINT8 data[0x100]; |
| 49 | int accumulate_overflow; |
| 50 | UINT8 high; |
| 51 | int low; |
| 49 | 52 | } SUZY; |
| 50 | 53 | |
| 51 | 54 | static SUZY suzy; |
| 52 | 55 | |
| 53 | 56 | static struct |
| 54 | 57 | { |
| 55 | | UINT8 *mem; |
| 56 | | // global |
| 57 | | UINT16 screen; |
| 58 | | UINT16 colbuf; |
| 59 | | UINT16 colpos; // byte where value of collision is written |
| 60 | | UINT16 xoff, yoff; |
| 61 | | // in command |
| 62 | | int mode; |
| 63 | | UINT16 cmd; |
| 64 | | UINT8 spritenr; |
| 65 | | int x,y; |
| 66 | | UINT16 width, height; // uint16 important for blue lightning |
| 67 | | UINT16 stretch, tilt; // uint16 important |
| 68 | | UINT8 color[16]; // or stored |
| 69 | | void (*line_function)(const int y, const int xdir); |
| 70 | | UINT16 bitmap; |
| 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; |
| 71 | 74 | |
| 72 | | int everon; |
| 73 | | int memory_accesses; |
| 74 | | attotime time; |
| 75 | int everon; |
| 76 | int memory_accesses; |
| 77 | attotime time; |
| 75 | 78 | } blitter; |
| 76 | 79 | |
| 77 | 80 | UINT8 *lynx_mem_0000; |
| r3406 | r3407 | |
| 83 | 86 | |
| 84 | 87 | static UINT8 lynx_memory_config; |
| 85 | 88 | |
| 86 | | #define GET_WORD(mem, index) ((mem)[(index)]|((mem)[(index)+1]<<8)) |
| 89 | /**************************************** |
| 87 | 90 | |
| 91 | Graphics Drawing |
| 92 | |
| 93 | ****************************************/ |
| 94 | |
| 88 | 95 | /* |
| 89 | | mode from blitter command |
| 90 | | #define SHADOW (0x07) |
| 91 | | #define XORSHADOW (0x06) |
| 92 | | #define NONCOLLIDABLE (0x05) |
| 93 | | #define NORMAL (0x04) |
| 94 | | #define BOUNDARY (0x03) |
| 95 | | #define BOUNDARYSHADOW (0x02) |
| 96 | | #define BKGRNDNOCOL (0x01) |
| 97 | | #define BKGRND (0x00) |
| 96 | 2008-10 FP: |
| 97 | Current implementation: lynx_blitter reads what will be drawn and sets which line_functions to use. |
| 98 | It then calls lynx_blit_lines which sets the various flip bits (horizontal and vertical) and calls |
| 99 | the chosen line_function. These functions (available in various versions, depending on how many |
| 100 | color bits are to be used) finally call lynx_plot_pixel which draws the sprite. |
| 101 | |
| 102 | Notice however that, based on the problems in Electrocop, Jimmy Connors Tennis and Switchblade II |
| 103 | (among the others), it clearly seems that something is being lost in some of the passages. From |
| 104 | my partial understanding while comparing the code with the manual, I would suspect the loops in |
| 105 | the line_functions to be not completely correct. |
| 106 | |
| 107 | This whole part will be eventually moved to video/ once I'm satisfied (or I give up). |
| 98 | 108 | */ |
| 99 | 109 | |
| 110 | #define GET_WORD(mem, index) ((mem)[(index)]|((mem)[(index)+1]<<8)) |
| 111 | |
| 112 | /* modes from blitter command */ |
| 113 | enum { |
| 114 | BACKGROUND = 0, |
| 115 | BACKGROUND_NO_COLL, |
| 116 | BOUNDARY_SHADOW, |
| 117 | BOUNDARY, |
| 118 | NORMAL_SPRITE, |
| 119 | NO_COLL, |
| 120 | XOR_SPRITE, |
| 121 | SHADOW |
| 122 | }; |
| 123 | |
| 124 | static UINT8 sprite_collide; |
| 125 | |
| 126 | /* The pen numbers range from '0' to 'F. Pen numbers '1' thru 'D' are always collidable and opaque. The other |
| 127 | ones have different behavior depending on the sprite type: there are 8 types of sprites, each has different |
| 128 | characteristics relating to some or all of their pen numbers. |
| 129 | |
| 130 | * Shadow Error: The hardware is missing an inverter in the 'shadow' generator. This causes sprite types that |
| 131 | did not invoke shadow to now invoke it and vice versa. The only actual functionality loss is that 'exclusive or' |
| 132 | sprites and 'background' sprites will have shadow enabled. |
| 133 | |
| 134 | The sprite types relate to specific hardware functions according to the following table: |
| 135 | |
| 136 | |
| 137 | -------------------------- SHADOW |
| 138 | | ----------------------- BOUNDARY_SHADOW |
| 139 | | | -------------------- NORMAL_SPRITE |
| 140 | | | | ----------------- BOUNDARY |
| 141 | | | | | -------------- BACKGROUND (+ shadow, due to bug in 'E' pen) |
| 142 | | | | | | ----------- BACKGROUND_NO_COLL |
| 143 | | | | | | | -------- NO_COLL |
| 144 | | | | | | | | ----- XOR_SPRITE (+ shadow, due to bug in 'E' pen) |
| 145 | | | | | | | | | |
| 146 | 1 0 1 0 1 1 1 1 F is opaque |
| 147 | 0 0 1 1 0 0 0 0 E is collideable |
| 148 | 0 0 1 1 0 0 0 0 0 is opaque and collideable |
| 149 | 1 1 1 1 0 0 0 1 allow collision detect |
| 150 | 1 1 1 1 1 0 0 1 allow coll. buffer access |
| 151 | 0 0 0 0 0 0 0 1 exclusive-or the data |
| 152 | */ |
| 153 | |
| 100 | 154 | INLINE void lynx_plot_pixel(const int mode, const int x, const int y, const int color) |
| 101 | 155 | { |
| 102 | | int back; |
| 103 | | UINT8 *screen; |
| 104 | | UINT8 *colbuf; |
| 156 | int back; |
| 157 | UINT8 *screen; |
| 158 | UINT8 *colbuf; |
| 105 | 159 | |
| 106 | | blitter.everon=TRUE; |
| 107 | | screen=blitter.mem+blitter.screen+y*80+x/2; |
| 108 | | colbuf=blitter.mem+blitter.colbuf+y*80+x/2; |
| 109 | | switch (mode) { |
| 110 | | case 0x00: // background (shadow bug!) |
| 111 | | if (!(x&1)) { |
| 112 | | *screen=(*screen&0x0f)|(color<<4); |
| 113 | | } else { |
| 114 | | *screen=(*screen&0xf0)|color; |
| 160 | blitter.everon = TRUE; |
| 161 | screen = blitter.mem + blitter.screen + y * 80 + x / 2; |
| 162 | colbuf = blitter.mem + blitter.colbuf + y * 80 + x / 2; |
| 163 | |
| 164 | switch (mode) |
| 165 | { |
| 166 | case NORMAL_SPRITE: |
| 167 | /* A sprite may be set to 'normal'. This means that pen number '0' will be transparent and |
| 168 | non-collideable. All other pens will be opaque and collideable */ |
| 169 | if (color == 0) |
| 170 | break; |
| 171 | if (!(x & 0x01)) /* Upper nibble */ |
| 172 | { |
| 173 | *screen = (*screen & 0x0f) | (color << 4); |
| 174 | |
| 175 | if(sprite_collide) |
| 176 | { |
| 177 | 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; |
| 182 | } |
| 183 | } |
| 184 | else /* Lower nibble */ |
| 185 | { |
| 186 | *screen = (*screen & 0xf0) | color; |
| 187 | |
| 188 | if(sprite_collide) |
| 189 | { |
| 190 | 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; |
| 195 | } |
| 196 | } |
| 197 | blitter.memory_accesses++; |
| 198 | break; |
| 199 | |
| 200 | case BOUNDARY: |
| 201 | /* A sprite may be set to 'boundary'. This is a 'normal' sprite with the exception that pen |
| 202 | number 'F' is transparent (and still collideable). */ |
| 203 | if (color == 0) |
| 204 | break; |
| 205 | if (!(x & 0x01)) /* Upper nibble */ |
| 206 | { |
| 207 | if (color != 0x0f) |
| 208 | { |
| 209 | *screen = (*screen & 0x0f) | (color << 4); |
| 210 | blitter.memory_accesses++; |
| 211 | } |
| 212 | if(sprite_collide) |
| 213 | { |
| 214 | 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; |
| 219 | } |
| 220 | } |
| 221 | else /* Lower nibble */ |
| 222 | { |
| 223 | if (color != 0x0f) |
| 224 | { |
| 225 | *screen = (*screen & 0xf0) | color; |
| 226 | blitter.memory_accesses++; |
| 227 | } |
| 228 | if(sprite_collide) |
| 229 | { |
| 230 | 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; |
| 235 | } |
| 236 | } |
| 237 | break; |
| 238 | |
| 239 | case SHADOW: |
| 240 | /* A sprite may be set to 'shadow'. This is a 'normal' sprite with the exception that pen |
| 241 | number 'E' is non-collideable (but still opaque) */ |
| 242 | if (color == 0) |
| 243 | break; |
| 244 | if (!(x & 0x01)) /* Upper nibble */ |
| 245 | { |
| 246 | *screen = (*screen & 0x0f) | (color << 4); |
| 247 | |
| 248 | if (sprite_collide && (color != 0x0e)) |
| 249 | { |
| 250 | 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; |
| 255 | } |
| 256 | } |
| 257 | else /* Lower nibble */ |
| 258 | { |
| 259 | *screen = (*screen & 0xf0) | color; |
| 260 | |
| 261 | if (sprite_collide && (color != 0x0e)) |
| 262 | { |
| 263 | 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; |
| 268 | } |
| 269 | } |
| 270 | blitter.memory_accesses++; |
| 271 | break; |
| 272 | |
| 273 | case BOUNDARY_SHADOW: |
| 274 | /* This sprite is a 'normal' sprite with the characteristics of both 'boundary' |
| 275 | and 'shadow'. That is, pen number 'F' is transparent (and still collideable) and |
| 276 | pen number 'E' is non-collideable (but still opaque). */ |
| 277 | if (color == 0) |
| 278 | break; |
| 279 | if (!(x & 0x01)) /* Upper nibble */ |
| 280 | { |
| 281 | if (color != 0x0f) |
| 282 | { |
| 283 | *screen = (*screen & 0x0f) | (color << 4); |
| 284 | blitter.memory_accesses++; |
| 285 | } |
| 286 | if (sprite_collide && (color != 0x0e)) |
| 287 | { |
| 288 | 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; |
| 293 | } |
| 294 | } |
| 295 | else /* Lower nibble */ |
| 296 | { |
| 297 | if (color != 0x0f) |
| 298 | { |
| 299 | *screen = (*screen & 0xf0) | color; |
| 300 | blitter.memory_accesses++; |
| 301 | } |
| 302 | if (sprite_collide && (color != 0x0e)) |
| 303 | { |
| 304 | 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; |
| 309 | } |
| 310 | } |
| 311 | break; |
| 312 | |
| 313 | case BACKGROUND: |
| 314 | /* A sprite may be set to 'background'. This sprite will overwrite the contents of the video and |
| 315 | collision buffers. Pens '0' and 'F' are no longer transparent. This sprite is used to initialize |
| 316 | the buffers at the start of a 'painting'. Additionally, no collision detection is done, and no write |
| 317 | to the collision depository occurs. The 'E' error will cause the pen number 'E' to be non-collideable |
| 318 | and therefore not clear the collision buffer */ |
| 319 | if (!(x & 0x01)) /* Upper nibble */ |
| 320 | { |
| 321 | *screen = (*screen & 0x0f) | (color << 4); |
| 322 | |
| 323 | if (sprite_collide && (color != 0x0e)) |
| 324 | { |
| 325 | *colbuf = (*colbuf & ~0xf0) | (blitter.spritenr << 4); |
| 326 | blitter.memory_accesses++; |
| 327 | } |
| 328 | } |
| 329 | else /* Lower nibble */ |
| 330 | { |
| 331 | *screen = (*screen & 0xf0) | color; |
| 332 | |
| 333 | if (sprite_collide && (color != 0x0e)) |
| 334 | { |
| 335 | *colbuf = (*colbuf & ~0x0f) | (blitter.spritenr); |
| 336 | blitter.memory_accesses++; |
| 337 | } |
| 338 | } |
| 339 | blitter.memory_accesses++; |
| 340 | break; |
| 341 | |
| 342 | case BACKGROUND_NO_COLL: |
| 343 | /* This is a 'background' sprite with the exception that no activity occurs in the collision buffer */ |
| 344 | if (!(x & 0x01)) /* Upper nibble */ |
| 345 | *screen = (*screen & 0x0f) | (color << 4); |
| 346 | else /* Lower nibble */ |
| 347 | *screen = (*screen & 0xf0) | color; |
| 348 | blitter.memory_accesses++; |
| 349 | break; |
| 350 | |
| 351 | case NO_COLL: |
| 352 | /* A sprite may be set to 'non-collideable'. This means that it will have no affect on the contents of |
| 353 | the collision buffer and all other collision activities are overridden (pen 'F' is not collideable). */ |
| 354 | if (color == 0) |
| 355 | break; |
| 356 | if (!(x & 0x01)) /* Upper nibble */ |
| 357 | *screen = (*screen & 0x0f) | (color << 4); |
| 358 | else /* Lower nibble */ |
| 359 | *screen = (*screen & 0xf0) | color; |
| 360 | blitter.memory_accesses++; |
| 361 | break; |
| 362 | |
| 363 | case XOR_SPRITE: |
| 364 | /* This is a 'normal' sprite with the exception that the data from the video buffer is exclusive-ored |
| 365 | with the sprite data and written back out to the video buffer. Collision activity is 'normal'. The 'E' |
| 366 | error will cause the pen number 'E' to be non-collideable and therefore not react with the collision |
| 367 | buffer */ |
| 368 | if (color == 0) |
| 369 | break; |
| 370 | if (!(x & 0x01)) /* Upper nibble */ |
| 371 | { |
| 372 | *screen = (*screen & 0x0f)^(color<<4); |
| 373 | |
| 374 | if (color != 0x0e) |
| 375 | { |
| 376 | 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; |
| 381 | } |
| 382 | } |
| 383 | else /* Lower nibble */ |
| 384 | { |
| 385 | *screen = (*screen & 0xf0)^color; |
| 386 | |
| 387 | if (color != 0x0e) |
| 388 | { |
| 389 | 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; |
| 394 | } |
| 395 | } |
| 396 | blitter.memory_accesses++; |
| 397 | break; |
| 115 | 398 | } |
| 116 | | blitter.memory_accesses++; |
| 117 | | break; |
| 118 | | case 0x10: |
| 119 | | if (!(x&1)) { |
| 120 | | if (color!=0xe) { |
| 121 | | *colbuf=(*colbuf&~0xf0)|(blitter.spritenr<<4); |
| 122 | | blitter.memory_accesses++; |
| 123 | | } |
| 124 | | *screen=(*screen&0x0f)|(color<<4); |
| 125 | | } else { |
| 126 | | if (color!=0xe) { |
| 127 | | *colbuf=(*colbuf&~0xf)|(blitter.spritenr); |
| 128 | | blitter.memory_accesses++; |
| 129 | | } |
| 130 | | *screen=(*screen&0xf0)|color; |
| 399 | } |
| 400 | |
| 401 | static void lynx_blit_do_work( const int y, const int xdir, const int bits, const int mask ) |
| 402 | { |
| 403 | int j, xi, wi, i; |
| 404 | int b, p, color; |
| 405 | |
| 406 | i = blitter.mem[blitter.bitmap]; |
| 407 | blitter.memory_accesses++; // ? |
| 408 | |
| 409 | for (xi = blitter.x, p = 0, b = 0, j = 1, wi = 0; j < i;) |
| 410 | { |
| 411 | if (p < bits) |
| 412 | { |
| 413 | b = (b << 8) | blitter.mem[blitter.bitmap + j]; |
| 414 | j++; |
| 415 | p += 8; |
| 416 | blitter.memory_accesses++; |
| 417 | } |
| 418 | for ( ; (p >= bits); ) |
| 419 | { |
| 420 | color = blitter.color[(b >> (p - bits)) & mask]; |
| 421 | p -= bits; |
| 422 | for ( ; wi < blitter.width; wi += 0x100, xi += xdir) |
| 423 | { |
| 424 | if ((xi >= 0) && (xi < 160)) |
| 425 | lynx_plot_pixel(blitter.mode, xi, y, color); |
| 426 | } |
| 427 | wi -= blitter.width; |
| 428 | } |
| 131 | 429 | } |
| 132 | | blitter.memory_accesses++; |
| 133 | | break; |
| 134 | | case 0x01: // background, no colliding |
| 135 | | case 0x11: |
| 136 | | if (!(x&1)) { |
| 137 | | *screen=(*screen&0x0f)|(color<<4); |
| 138 | | } else { |
| 139 | | *screen=(*screen&0xf0)|color; |
| 140 | | } |
| 141 | | blitter.memory_accesses++; |
| 142 | | break; |
| 143 | | case 0x03: // boundary: pen P? transparent, but collides |
| 144 | | case 0x02: // boundary, shadow |
| 145 | | if ((color==0)||(color==0xf)) break; |
| 146 | | if (!(x&1)) { |
| 147 | | *screen=(*screen&0x0f)|(color<<4); |
| 148 | | } else { |
| 149 | | *screen=(*screen&0xf0)|color; |
| 150 | | } |
| 151 | | blitter.memory_accesses++; |
| 152 | | break; |
| 153 | | case 0x13: |
| 154 | | if (color==0) break; |
| 155 | | if (!(x&1)) { |
| 156 | | back=*colbuf; |
| 157 | | if (back>>4>blitter.mem[blitter.colpos]) |
| 158 | | blitter.mem[blitter.colpos]=back>>4; |
| 159 | | *colbuf=(back&~0xf0)|(blitter.spritenr<<4); |
| 160 | | if (color!=0xf) { |
| 161 | | *screen=(*screen&0x0f)|(color<<4); |
| 162 | | blitter.memory_accesses++; |
| 163 | | } |
| 164 | | } else { |
| 165 | | back=*colbuf; |
| 166 | | if ((back&0xf)>blitter.mem[blitter.colpos]) |
| 167 | | blitter.mem[blitter.colpos]=back&0xf; |
| 168 | | *colbuf=(back&~0xf)|(blitter.spritenr); |
| 169 | | if (color!=0xf) { |
| 170 | | *screen=(*screen&0xf0)|color; |
| 171 | | blitter.memory_accesses++; |
| 172 | | } |
| 173 | | } |
| 174 | | blitter.memory_accesses+=2; |
| 175 | | break; |
| 176 | | case 0x12: |
| 177 | | if (color==0) break; |
| 178 | | if (!(x&1)) { |
| 179 | | if (color!=0xe) { |
| 180 | | back=*colbuf; |
| 181 | | if (back>>4>blitter.mem[blitter.colpos]) |
| 182 | | blitter.mem[blitter.colpos]=back>>4; |
| 183 | | *colbuf=(back&~0xf0)|(blitter.spritenr<<4); |
| 184 | | } |
| 185 | | if (color!=0xf) { |
| 186 | | *screen=(*screen&0x0f)|(color<<4); |
| 187 | | blitter.memory_accesses++; |
| 188 | | } |
| 189 | | } else { |
| 190 | | if (color!=0xe) { |
| 191 | | back=*colbuf; |
| 192 | | if ((back&0xf)>blitter.mem[blitter.colpos]) |
| 193 | | blitter.mem[blitter.colpos]=back&0xf; |
| 194 | | *colbuf=(back&~0xf)|(blitter.spritenr); |
| 195 | | } |
| 196 | | if (color!=0xf) { |
| 197 | | *screen=(*screen&0xf0)|color; |
| 198 | | blitter.memory_accesses++; |
| 199 | | } |
| 200 | | } |
| 201 | | blitter.memory_accesses+=2; |
| 202 | | break; |
| 203 | | case 0x04: // pen 0 transparent, |
| 204 | | case 0x07: // shadow: pen e doesn't collide |
| 205 | | case 0x05: // non collidable sprite |
| 206 | | case 0x15: |
| 207 | | if (color==0) break; |
| 208 | | if (!(x&1)) { |
| 209 | | *screen=(*screen&0x0f)|(color<<4); |
| 210 | | } else { |
| 211 | | *screen=(*screen&0xf0)|color; |
| 212 | | } |
| 213 | | blitter.memory_accesses++; |
| 214 | | break; |
| 215 | | case 0x14: |
| 216 | | if (color==0) break; |
| 217 | | if (!(x&1)) { |
| 218 | | back=*colbuf; |
| 219 | | *colbuf=(back&~0xf0)|(blitter.spritenr<<4); |
| 220 | | if (back>>4>blitter.mem[blitter.colpos]) |
| 221 | | blitter.mem[blitter.colpos]=back>>4; |
| 222 | | *screen=(*screen&0x0f)|(color<<4); |
| 223 | | } else { |
| 224 | | back=*colbuf; |
| 225 | | *colbuf=(back&~0xf)|(blitter.spritenr); |
| 226 | | if ((back&0xf)>blitter.mem[blitter.colpos]) |
| 227 | | blitter.mem[blitter.colpos]=back&0xf; |
| 228 | | *screen=(*screen&0xf0)|color; |
| 229 | | } |
| 230 | | blitter.memory_accesses+=3; |
| 231 | | break; |
| 232 | | case 0x17: |
| 233 | | if (color==0) break; |
| 234 | | if (!(x&1)) { |
| 235 | | if (color!=0xe) { |
| 236 | | back=*colbuf; |
| 237 | | if (back>>4>blitter.mem[blitter.colpos]) |
| 238 | | blitter.mem[blitter.colpos]=back>>4; |
| 239 | | *colbuf=(back&~0xf0)|(blitter.spritenr<<4); |
| 240 | | blitter.memory_accesses+=2; |
| 241 | | } |
| 242 | | *screen=(*screen&0x0f)|(color<<4); |
| 243 | | } else { |
| 244 | | if (color!=0xe) { |
| 245 | | back=*colbuf; |
| 246 | | if ((back&0xf)>blitter.mem[blitter.colpos]) |
| 247 | | blitter.mem[blitter.colpos]=back&0xf; |
| 248 | | *colbuf=(back&~0xf)|(blitter.spritenr); |
| 249 | | blitter.memory_accesses+=2; |
| 250 | | } |
| 251 | | *screen=(*screen&0xf0)|color; |
| 252 | | } |
| 253 | | blitter.memory_accesses++; |
| 254 | | break; |
| 255 | | case 0x06: // xor sprite (shadow bug!) |
| 256 | | if (!(x&1)) { |
| 257 | | *screen=(*screen&0x0f)^(color<<4); |
| 258 | | } else { |
| 259 | | *screen=(*screen&0xf0)^color; |
| 260 | | } |
| 261 | | blitter.memory_accesses++; |
| 262 | | break; |
| 263 | | case 0x16: |
| 264 | | if (!(x&1)) { |
| 265 | | if (color!=0xe) { |
| 266 | | back=*colbuf; |
| 267 | | if (back>>4>blitter.mem[blitter.colpos]) |
| 268 | | blitter.mem[blitter.colpos]=back>>4; |
| 269 | | *colbuf=(back&~0xf0)|(blitter.spritenr<<4); |
| 270 | | blitter.memory_accesses+=2; |
| 271 | | } |
| 272 | | *screen=(*screen&0x0f)^(color<<4); |
| 273 | | } else { |
| 274 | | if (color!=0xe) { |
| 275 | | back=*colbuf; |
| 276 | | if ((back&0xf)>blitter.mem[blitter.colpos]) |
| 277 | | blitter.mem[blitter.colpos]=back&0xf; |
| 278 | | *colbuf=(back&~0xf)|(blitter.spritenr); |
| 279 | | blitter.memory_accesses+=2; |
| 280 | | } |
| 281 | | *screen=(*screen&0xf0)^color; |
| 282 | | } |
| 283 | | blitter.memory_accesses++; |
| 284 | | break; |
| 285 | | } |
| 286 | 430 | } |
| 287 | 431 | |
| 288 | | #define INCLUDE_LYNX_LINE_FUNCTION |
| 432 | |
| 289 | 433 | static void lynx_blit_2color_line(const int y, const int xdir) |
| 290 | 434 | { |
| 291 | | const int bits=1; |
| 292 | | const int mask=0x1; |
| 293 | | #include "includes/lynx.h" |
| 435 | const int bits = 1; |
| 436 | const int mask = 0x01; |
| 437 | |
| 438 | lynx_blit_do_work(y, xdir, bits, mask); |
| 294 | 439 | } |
| 295 | 440 | static void lynx_blit_4color_line(const int y, const int xdir) |
| 296 | 441 | { |
| 297 | | const int bits=2; |
| 298 | | const int mask=0x3; |
| 299 | | #include "includes/lynx.h" |
| 442 | const int bits = 2; |
| 443 | const int mask = 0x03; |
| 444 | |
| 445 | lynx_blit_do_work(y, xdir, bits, mask); |
| 300 | 446 | } |
| 301 | 447 | static void lynx_blit_8color_line(const int y, const int xdir) |
| 302 | 448 | { |
| 303 | | const int bits=3; |
| 304 | | const int mask=0x7; |
| 305 | | #include "includes/lynx.h" |
| 449 | const int bits = 3; |
| 450 | const int mask = 0x07; |
| 451 | |
| 452 | lynx_blit_do_work(y, xdir, bits, mask); |
| 306 | 453 | } |
| 307 | 454 | static void lynx_blit_16color_line(const int y, const int xdir) |
| 308 | 455 | { |
| 309 | | const int bits=4; |
| 310 | | const int mask=0xf; |
| 311 | | #include "includes/lynx.h" |
| 456 | const int bits = 4; |
| 457 | const int mask = 0x0f; |
| 458 | |
| 459 | lynx_blit_do_work(y, xdir, bits, mask); |
| 312 | 460 | } |
| 313 | | #undef INCLUDE_LYNX_LINE_FUNCTION |
| 314 | 461 | |
| 315 | 462 | /* |
| 316 | 463 | 2 color rle: ?? |
| r3406 | r3407 | |
| 335 | 482 | 0, 4 bit repeat count-1, 4 bit color |
| 336 | 483 | 1, 4 bit count of values-1, 4 bit color, .... |
| 337 | 484 | */ |
| 338 | | #define INCLUDE_LYNX_LINE_RLE_FUNCTION |
| 485 | |
| 486 | static void lynx_blit_rle_do_work( const int y, const int xdir, const int bits, const int mask ) |
| 487 | { |
| 488 | int wi, xi; |
| 489 | int b, p, j; |
| 490 | int t, count, color; |
| 491 | |
| 492 | for( p = 0, j = 0, b = 0, xi = blitter.x, wi = 0; ; ) /* through the rle entries */ |
| 493 | { |
| 494 | if (p < 5 + bits) /* under 7 bits no complete entry */ |
| 495 | { |
| 496 | j++; |
| 497 | if (j >= blitter.mem[blitter.bitmap]) |
| 498 | return; |
| 499 | |
| 500 | p += 8; |
| 501 | b = (b << 8) | blitter.mem[blitter.bitmap + j]; |
| 502 | blitter.memory_accesses++; |
| 503 | } |
| 504 | |
| 505 | t = (b >> (p - 1)) & 0x01; |
| 506 | p--; |
| 507 | count = ((b >> (p - 4)) & 0x0f) + 1; |
| 508 | p -= 4; |
| 509 | |
| 510 | if (t) /* count of different pixels */ |
| 511 | { |
| 512 | for ( ; count; count--) |
| 513 | { |
| 514 | if (p < bits) |
| 515 | { |
| 516 | j++; |
| 517 | if (j >= blitter.mem[blitter.bitmap]) |
| 518 | return; |
| 519 | p += 8; |
| 520 | b = (b << 8) | blitter.mem[blitter.bitmap + j]; |
| 521 | blitter.memory_accesses++; |
| 522 | } |
| 523 | |
| 524 | color = blitter.color[(b >> (p - bits)) & mask]; |
| 525 | p -= bits; |
| 526 | for ( ; wi < blitter.width; wi += 0x100, xi += xdir) |
| 527 | { |
| 528 | if ((xi >= 0) && (xi < 160)) |
| 529 | lynx_plot_pixel(blitter.mode, xi, y, color); |
| 530 | } |
| 531 | wi -= blitter.width; |
| 532 | } |
| 533 | } |
| 534 | else /* count of same pixels */ |
| 535 | { |
| 536 | if (count == 0) |
| 537 | return; |
| 538 | |
| 539 | if (p < bits) |
| 540 | { |
| 541 | j++; |
| 542 | if (j >= blitter.mem[blitter.bitmap]) |
| 543 | return; |
| 544 | p += 8; |
| 545 | b = (b << 8) | blitter.mem[blitter.bitmap + j]; |
| 546 | blitter.memory_accesses++; |
| 547 | } |
| 548 | |
| 549 | color = blitter.color[(b >> (p - bits)) & mask]; |
| 550 | p -= bits; |
| 551 | |
| 552 | for ( ; count; count--) |
| 553 | { |
| 554 | for ( ; wi < blitter.width; wi += 0x100, xi += xdir) |
| 555 | { |
| 556 | if ((xi >= 0) && (xi < 160)) |
| 557 | lynx_plot_pixel(blitter.mode, xi, y, color); |
| 558 | } |
| 559 | wi -= blitter.width; |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | |
| 339 | 565 | static void lynx_blit_2color_rle_line(const int y, const int xdir) |
| 340 | 566 | { |
| 341 | | const int bits=1; |
| 342 | | const int mask=0x1; |
| 343 | | #include "includes/lynx.h" |
| 567 | const int bits = 1; |
| 568 | const int mask = 0x01; |
| 569 | |
| 570 | lynx_blit_rle_do_work(y, xdir, bits, mask); |
| 344 | 571 | } |
| 345 | 572 | static void lynx_blit_4color_rle_line(const int y, const int xdir) |
| 346 | 573 | { |
| 347 | | const int bits=2; |
| 348 | | const int mask=0x3; |
| 349 | | #include "includes/lynx.h" |
| 574 | const int bits = 2; |
| 575 | const int mask = 0x03; |
| 576 | |
| 577 | lynx_blit_rle_do_work(y, xdir, bits, mask); |
| 350 | 578 | } |
| 351 | 579 | static void lynx_blit_8color_rle_line(const int y, const int xdir) |
| 352 | 580 | { |
| 353 | | const int bits=3; |
| 354 | | const int mask=0x7; |
| 355 | | #include "includes/lynx.h" |
| 581 | const int bits = 3; |
| 582 | const int mask = 0x07; |
| 583 | |
| 584 | lynx_blit_rle_do_work(y, xdir, bits, mask); |
| 356 | 585 | } |
| 357 | 586 | static void lynx_blit_16color_rle_line(const int y, const int xdir) |
| 358 | 587 | { |
| 359 | | const int bits=4; |
| 360 | | const int mask=0xf; |
| 361 | | #include "includes/lynx.h" |
| 588 | const int bits = 4; |
| 589 | const int mask = 0x0f; |
| 590 | |
| 591 | lynx_blit_rle_do_work(y, xdir, bits, mask); |
| 362 | 592 | } |
| 363 | | #undef INCLUDE_LYNX_LINE_RLE_FUNCTION |
| 364 | 593 | |
| 365 | 594 | |
| 366 | 595 | static void lynx_blit_lines(void) |
| 367 | 596 | { |
| 368 | 597 | int i, hi, y; |
| 369 | | int ydir=0, xdir=0; |
| 370 | | int flip=blitter.mem[blitter.cmd+1]&3; |
| 598 | int ydir = 0, xdir = 0; |
| 599 | int flip; |
| 371 | 600 | |
| 372 | | blitter.everon=FALSE; |
| 601 | blitter.everon = FALSE; |
| 373 | 602 | |
| 374 | 603 | // flipping sprdemo3 |
| 375 | 604 | // fat bobby 0x10 |
| 376 | 605 | // mirror the sprite in gameplay? |
| 377 | | xdir=1; |
| 378 | | if (blitter.mem[blitter.cmd]&0x20) { xdir=-1;blitter.x--;/*?*/ } |
| 379 | | ydir=1; |
| 380 | | if (blitter.mem[blitter.cmd]&0x10) { ydir=-1;blitter.y--;/*?*/ } |
| 381 | | switch (blitter.mem[blitter.cmd+1]&3) { |
| 382 | | case 0: |
| 383 | | flip =0; |
| 384 | | break; |
| 385 | | case 1: // blockout |
| 386 | | xdir*=-1; |
| 387 | | flip=1; |
| 388 | | break; |
| 389 | | case 2: // fat bobby horicontal |
| 390 | | ydir*=-1; |
| 391 | | flip=1; |
| 392 | | break; |
| 393 | | case 3: |
| 394 | | xdir*=-1; |
| 395 | | ydir*=-1; |
| 396 | | flip=3; |
| 397 | | break; |
| 606 | xdir = 1; |
| 607 | |
| 608 | if (blitter.mem[blitter.cmd] & 0x20) /* Horizontal Flip */ |
| 609 | { |
| 610 | xdir = -1; |
| 611 | blitter.x--; /*?*/ |
| 398 | 612 | } |
| 613 | |
| 614 | ydir = 1; |
| 399 | 615 | |
| 400 | | for ( y=blitter.y, hi=0; (blitter.memory_accesses++,i=blitter.mem[blitter.bitmap]); blitter.bitmap+=i ) { |
| 401 | | if (i==1) { |
| 402 | | // centered sprites sprdemo3, fat bobby, blockout |
| 403 | | hi=0; |
| 404 | | switch (flip&3) { |
| 405 | | case 0: |
| 406 | | case 2: |
| 407 | | ydir*=-1; |
| 408 | | blitter.y+=ydir; |
| 616 | if (blitter.mem[blitter.cmd] & 0x10) /* Vertical Flip */ |
| 617 | { |
| 618 | ydir = -1; |
| 619 | blitter.y--; /*?*/ |
| 620 | } |
| 621 | |
| 622 | switch (blitter.mem[blitter.cmd + 1] & 0x03) /* Start Left & Start Up */ |
| 623 | { |
| 624 | case 0: |
| 625 | flip =0; |
| 409 | 626 | break; |
| 410 | | case 1: |
| 411 | | case 3: |
| 412 | | xdir*=-1; |
| 413 | | blitter.x+=xdir; |
| 627 | |
| 628 | case 1: // blockout |
| 629 | xdir *= -1; |
| 630 | flip = 1; |
| 414 | 631 | break; |
| 415 | | } |
| 416 | | y=blitter.y; |
| 417 | | flip++; |
| 632 | |
| 633 | case 2: // fat bobby horicontal |
| 634 | ydir *= -1; |
| 635 | flip = 1; |
| 636 | break; |
| 637 | |
| 638 | case 3: |
| 639 | xdir *= -1; |
| 640 | ydir *= -1; |
| 641 | flip = 3; |
| 642 | break; |
| 643 | } |
| 644 | |
| 645 | for (y = blitter.y, hi = 0; blitter.memory_accesses++, i = blitter.mem[blitter.bitmap]; blitter.bitmap += i ) |
| 646 | { |
| 647 | if (i == 1) |
| 648 | { |
| 649 | // centered sprites sprdemo3, fat bobby, blockout |
| 650 | hi = 0; |
| 651 | switch (flip & 0x03) |
| 652 | { |
| 653 | case 0: |
| 654 | case 2: |
| 655 | ydir *= -1; |
| 656 | blitter.y += ydir; |
| 657 | break; |
| 658 | |
| 659 | case 1: |
| 660 | case 3: |
| 661 | xdir *= -1; |
| 662 | blitter.x += xdir; |
| 663 | break; |
| 664 | } |
| 665 | |
| 666 | y = blitter.y; |
| 667 | flip++; |
| 418 | 668 | continue; |
| 419 | 669 | } |
| 420 | | for (;(hi<blitter.height); hi+=0x100, y+=ydir) { |
| 421 | | if ( y>=0 && y<102 ) |
| 422 | | blitter.line_function(y,xdir); |
| 423 | | blitter.width+=blitter.stretch; |
| 424 | | blitter.x+=blitter.tilt; |
| 670 | |
| 671 | for ( ; (hi < blitter.height); hi += 0x100, y += ydir) |
| 672 | { |
| 673 | if (y >= 0 && y < 102) |
| 674 | blitter.line_function(y, xdir); |
| 675 | blitter.width += blitter.stretch; |
| 676 | blitter.x += blitter.tilt; |
| 425 | 677 | } |
| 426 | | hi-=blitter.height; |
| 678 | |
| 679 | hi -= blitter.height; |
| 427 | 680 | } |
| 428 | | switch (blitter.mode) { |
| 429 | | case 0x12: case 0x13: case 0x14: case 0x16: case 0x17: |
| 430 | | if (suzy.u.s.SPRG0&0x20 && blitter.everon) { |
| 431 | | blitter.mem[blitter.colpos]|=0x80; |
| 432 | | } |
| 681 | |
| 682 | if (suzy.data[SPRG0] & 0x04) |
| 683 | { |
| 684 | if (sprite_collide & !blitter.everon) |
| 685 | blitter.mem[blitter.colpos] |= 0x80; |
| 686 | else |
| 687 | blitter.mem[blitter.colpos] &= 0x7f; |
| 433 | 688 | } |
| 434 | 689 | } |
| 435 | 690 | |
| 436 | 691 | static TIMER_CALLBACK(lynx_blitter_timer) |
| 437 | 692 | { |
| 438 | | suzy.u.s.SPRSYS&=~1; //blitter finished |
| 693 | suzy.data[SPRSYS] &= ~0x01; //blitter finished |
| 439 | 694 | } |
| 440 | 695 | |
| 441 | 696 | /* |
| r3406 | r3407 | |
| 513 | 768 | |
| 514 | 769 | static void lynx_blitter(void) |
| 515 | 770 | { |
| 516 | | static const int lynx_colors[4]={2,4,8,16}; |
| 771 | static const int lynx_colors[4]={2,4,8,16}; |
| 517 | 772 | |
| 518 | | static void (* const blit_line[4])(const int y, const int xdir)= { |
| 773 | static void (* const blit_line[4])(const int y, const int xdir)= { |
| 519 | 774 | lynx_blit_2color_line, |
| 520 | 775 | lynx_blit_4color_line, |
| 521 | 776 | lynx_blit_8color_line, |
| 522 | 777 | lynx_blit_16color_line |
| 523 | | }; |
| 778 | }; |
| 524 | 779 | |
| 525 | | static void (* const blit_rle_line[4])(const int y, const int xdir)= { |
| 780 | static void (* const blit_rle_line[4])(const int y, const int xdir)= { |
| 526 | 781 | lynx_blit_2color_rle_line, |
| 527 | 782 | lynx_blit_4color_rle_line, |
| 528 | 783 | lynx_blit_8color_rle_line, |
| 529 | 784 | lynx_blit_16color_rle_line |
| 530 | | }; |
| 531 | | int i; int o;int colors; |
| 785 | }; |
| 786 | int i; int o;int colors; |
| 532 | 787 | |
| 533 | | blitter.memory_accesses=0; |
| 534 | | blitter.mem = memory_get_read_ptr(0, ADDRESS_SPACE_PROGRAM, 0x0000); |
| 535 | | blitter.colbuf=GET_WORD(suzy.u.data, 0xa); |
| 536 | | blitter.screen=GET_WORD(suzy.u.data, 8); |
| 537 | | blitter.xoff=GET_WORD(suzy.u.data,4); |
| 538 | | blitter.yoff=GET_WORD(suzy.u.data,6); |
| 539 | | // hsizeoff GET_WORD(suzy.u.data, 0x28) |
| 540 | | // vsizeoff GET_WORD(suzy.u.data, 0x2a) |
| 788 | blitter.memory_accesses = 0; |
| 789 | blitter.mem = memory_get_read_ptr(0, ADDRESS_SPACE_PROGRAM, 0x0000); |
| 541 | 790 | |
| 542 | | // these might be never set by the blitter hardware |
| 543 | | blitter.width=0x100; |
| 544 | | blitter.height=0x100; |
| 545 | | blitter.stretch=0; |
| 546 | | blitter.tilt=0; |
| 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) |
| 547 | 797 | |
| 548 | | blitter.memory_accesses+=2; |
| 549 | | for (blitter.cmd=GET_WORD(suzy.u.data, 0x10); blitter.cmd; ) { |
| 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; |
| 550 | 804 | |
| 551 | | blitter.memory_accesses+=1; |
| 552 | | if (!(blitter.mem[blitter.cmd+1]&4)) { |
| 805 | blitter.memory_accesses += 2; |
| 553 | 806 | |
| 554 | | blitter.colpos=GET_WORD(suzy.u.data, 0x24)+blitter.cmd; |
| 807 | for (blitter.cmd = GET_WORD(suzy.data, 0x10); blitter.cmd; ) |
| 808 | { |
| 809 | blitter.memory_accesses += 1; |
| 555 | 810 | |
| 556 | | blitter.bitmap=GET_WORD(blitter.mem,blitter.cmd+5); |
| 557 | | blitter.x=(INT16)GET_WORD(blitter.mem, blitter.cmd+7)-blitter.xoff; |
| 558 | | blitter.y=(INT16)GET_WORD(blitter.mem, blitter.cmd+9)-blitter.yoff; |
| 559 | | blitter.memory_accesses+=6; |
| 811 | if (!(blitter.mem[blitter.cmd + 1] & 0x04)) // if 0, we skip this sprite |
| 812 | { |
| 813 | blitter.colpos = GET_WORD(suzy.data, 0x24) + blitter.cmd; |
| 560 | 814 | |
| 561 | | blitter.mode=blitter.mem[blitter.cmd]&07; |
| 562 | | if (blitter.mem[blitter.cmd+1]&0x80) { |
| 563 | | blitter.line_function=blit_line[blitter.mem[blitter.cmd]>>6]; |
| 564 | | } else { |
| 565 | | blitter.line_function=blit_rle_line[blitter.mem[blitter.cmd]>>6]; |
| 566 | | } |
| 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; |
| 567 | 819 | |
| 568 | | if (!(blitter.mem[blitter.cmd+2]&0x20) && !( suzy.u.s.SPRSYS&0x20) ) { |
| 569 | | switch (blitter.mode) { |
| 570 | | case 0: case 2: case 3: case 4: case 6: case 7: |
| 571 | | blitter.mode|=0x10; |
| 572 | | blitter.mem[blitter.colpos]=0; |
| 573 | | blitter.spritenr=blitter.mem[blitter.cmd+2]&0xf; |
| 574 | | } |
| 575 | | } |
| 820 | blitter.mode = blitter.mem[blitter.cmd] & 0x07; |
| 576 | 821 | |
| 577 | | o=0xb; |
| 578 | | if (blitter.mem[blitter.cmd+1]&0x30) { |
| 579 | | blitter.width=GET_WORD(blitter.mem, blitter.cmd+11); |
| 580 | | blitter.height=GET_WORD(blitter.mem, blitter.cmd+13); |
| 581 | | blitter.memory_accesses+=4; |
| 582 | | o+=4; |
| 583 | | } |
| 822 | if (blitter.mem[blitter.cmd + 1] & 0x80) |
| 823 | blitter.line_function = blit_line[blitter.mem[blitter.cmd] >> 6]; |
| 824 | else |
| 825 | blitter.line_function = blit_rle_line[blitter.mem[blitter.cmd] >> 6]; |
| 584 | 826 | |
| 585 | | if (blitter.mem[blitter.cmd+1]&0x20) { |
| 586 | | blitter.stretch=GET_WORD(blitter.mem, blitter.cmd+o); |
| 587 | | blitter.memory_accesses+=2; |
| 588 | | o+=2; |
| 589 | | if (blitter.mem[blitter.cmd+1]&0x10) { |
| 590 | | blitter.tilt=GET_WORD(blitter.mem, blitter.cmd+o); |
| 591 | | blitter.memory_accesses+=2; |
| 592 | | o+=2; |
| 827 | if (!(blitter.mem[blitter.cmd + 2] & 0x20) && !(suzy.data[SPRSYS] & 0x20)) |
| 828 | { |
| 829 | switch (blitter.mode) |
| 830 | { |
| 831 | case BACKGROUND: |
| 832 | case BOUNDARY_SHADOW: |
| 833 | case BOUNDARY: |
| 834 | case NORMAL_SPRITE: |
| 835 | case XOR_SPRITE: |
| 836 | case SHADOW: |
| 837 | sprite_collide = 1; |
| 838 | blitter.mem[blitter.colpos] = 0; |
| 839 | blitter.spritenr = blitter.mem[blitter.cmd + 2] & 0x0f; |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | /* Sprite Reload Bits */ |
| 844 | o = 0x0b; |
| 845 | if (blitter.mem[blitter.cmd + 1] & 0x30) |
| 846 | { |
| 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; |
| 850 | o += 4; |
| 851 | } |
| 852 | if (blitter.mem[blitter.cmd + 1] & 0x20) |
| 853 | { |
| 854 | blitter.stretch = GET_WORD(blitter.mem, blitter.cmd + o); |
| 855 | blitter.memory_accesses += 2; |
| 856 | o += 2; |
| 857 | if (blitter.mem[blitter.cmd + 1] & 0x10) |
| 858 | { |
| 859 | blitter.tilt = GET_WORD(blitter.mem, blitter.cmd+o); |
| 860 | blitter.memory_accesses += 2; |
| 861 | o += 2; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | /* Reload Palette Bit */ |
| 866 | colors = lynx_colors[blitter.mem[blitter.cmd] >> 6]; |
| 867 | |
| 868 | if (!(blitter.mem[blitter.cmd + 1] & 0x08)) |
| 869 | { |
| 870 | for (i = 0; i < colors / 2; i++) |
| 871 | { |
| 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++; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | /* Draw Sprites */ |
| 879 | lynx_blit_lines(); |
| 593 | 880 | } |
| 594 | | } |
| 595 | | colors=lynx_colors[blitter.mem[blitter.cmd]>>6]; |
| 596 | 881 | |
| 597 | | if (!(blitter.mem[blitter.cmd+1]&8)) { |
| 598 | | for (i=0; i<colors/2; i++) { |
| 599 | | blitter.color[i*2]=blitter.mem[blitter.cmd+o+i]>>4; |
| 600 | | blitter.color[i*2+1]=blitter.mem[blitter.cmd+o+i]&0xf; |
| 601 | | blitter.memory_accesses++; |
| 602 | | } |
| 603 | | } |
| 604 | | lynx_blit_lines(); |
| 882 | blitter.cmd = GET_WORD(blitter.mem, blitter.cmd + 3); |
| 883 | blitter.memory_accesses += 2; |
| 884 | |
| 885 | if (!(blitter.cmd & 0xff00)) |
| 886 | break; |
| 605 | 887 | } |
| 606 | | blitter.cmd=GET_WORD(blitter.mem, blitter.cmd+3); |
| 607 | | blitter.memory_accesses+=2; |
| 608 | | if (!(blitter.cmd&0xff00)) break; |
| 609 | | } |
| 610 | 888 | |
| 611 | 889 | if (0) |
| 612 | 890 | timer_set(ATTOTIME_IN_CYCLES(blitter.memory_accesses*20,0), NULL, 0, lynx_blitter_timer); |
| 613 | 891 | } |
| 614 | 892 | |
| 615 | | static void lynx_divide(void) |
| 893 | |
| 894 | /**************************************** |
| 895 | |
| 896 | Suzy Emulation |
| 897 | |
| 898 | ****************************************/ |
| 899 | |
| 900 | |
| 901 | /* Math bugs of the original hardware: |
| 902 | |
| 903 | - in signed multiply, the hardware thinks that 8000 is a positive number |
| 904 | - in signed multiply, the hardware thinks that 0 is a negative number. This is not an immediate |
| 905 | problem for a multiply by zero, since the answer will be re-negated to the correct polarity of |
| 906 | zero. However, since it will set the sign flag, you can not depend on the sign flag to be correct |
| 907 | if you just load the lower byte after a multiply by zero. |
| 908 | - in divide, the remainder will have 2 possible errors, depending on its actual value (no further |
| 909 | notes on these errors available) */ |
| 910 | |
| 911 | static void lynx_divide( void ) |
| 616 | 912 | { |
| 617 | | UINT32 left=suzy.u.s.H|(suzy.u.s.G<<8)|(suzy.u.s.F<<16)|(suzy.u.s.E<<24); |
| 618 | | UINT16 right=suzy.u.s.P|(suzy.u.s.N<<8); |
| 913 | UINT32 left; |
| 914 | UINT16 right; |
| 619 | 915 | UINT32 res, mod; |
| 620 | | suzy.accumulate_overflow=FALSE; |
| 621 | | if (right==0) { |
| 622 | | suzy.accumulate_overflow=TRUE; |
| 623 | | res=0xffffffff; |
| 624 | | mod=0; //? |
| 625 | | } else { |
| 626 | | res=left/right; |
| 627 | | mod=left%right; |
| 916 | /* |
| 917 | Hardware divide: |
| 918 | EFGH |
| 919 | * NP |
| 920 | ---------------- |
| 921 | ABCD |
| 922 | Remainder (JK)LM |
| 923 | */ |
| 924 | |
| 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); |
| 927 | |
| 928 | suzy.accumulate_overflow = FALSE; |
| 929 | if (right == 0) |
| 930 | { |
| 931 | suzy.accumulate_overflow = TRUE; /* during divisions, this bit is used to detect denominator = 0 */ |
| 932 | res = 0xffffffff; |
| 933 | mod = 0; //? |
| 934 | } |
| 935 | else |
| 936 | { |
| 937 | res = left / right; |
| 938 | mod = left % right; |
| 628 | 939 | } |
| 629 | 940 | // logerror("coprocessor %8x / %8x = %4x\n", left, right, res); |
| 630 | | suzy.u.s.D=res&0xff; |
| 631 | | suzy.u.s.C=res>>8; |
| 632 | | suzy.u.s.B=res>>16; |
| 633 | | suzy.u.s.A=res>>24; |
| 634 | | suzy.u.s.M=mod&0xff; |
| 635 | | suzy.u.s.L=mod>>8; |
| 636 | | suzy.u.s.K=mod>>16; |
| 637 | | suzy.u.s.J=mod>>24; |
| 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; |
| 945 | |
| 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; |
| 638 | 950 | } |
| 639 | 951 | |
| 640 | | static void lynx_multiply(void) |
| 952 | static void lynx_multiply( void ) |
| 641 | 953 | { |
| 642 | 954 | UINT16 left, right; |
| 643 | 955 | UINT32 res, accu; |
| 644 | | left=suzy.u.s.B|(suzy.u.s.A<<8); |
| 645 | | right=suzy.u.s.D|(suzy.u.s.C<<8); |
| 646 | | if (suzy.u.s.SPRSYS&0x80) { |
| 647 | | // to do |
| 648 | | res=(INT16)left*(INT16)right; |
| 649 | | } else res=left*right; |
| 650 | | // logerror("coprocessor %4x * %4x = %4x\n", left, right, res); |
| 651 | | suzy.u.s.H=res&0xff; |
| 652 | | suzy.u.s.G=res>>8; |
| 653 | | suzy.u.s.F=res>>16; |
| 654 | | suzy.u.s.E=res>>24; |
| 655 | | if (suzy.u.s.SPRSYS&0x40) { |
| 656 | | accu=suzy.u.s.M|suzy.u.s.L<<8|suzy.u.s.K<<16|suzy.u.s.J<<24; |
| 657 | | accu+=res; |
| 658 | | if (accu<res) suzy.accumulate_overflow=TRUE; |
| 659 | | suzy.u.s.M=accu; |
| 660 | | suzy.u.s.L=accu>>8; |
| 661 | | suzy.u.s.K=accu>>16; |
| 662 | | suzy.u.s.J=accu>>24; |
| 956 | /* |
| 957 | Hardware multiply: |
| 958 | AB |
| 959 | * CD |
| 960 | ---------------- |
| 961 | EFGH |
| 962 | Accumulate JKLM |
| 963 | */ |
| 964 | suzy.accumulate_overflow = FALSE; |
| 965 | |
| 966 | left = suzy.data[MATH_B] | (suzy.data[MATH_A] << 8); |
| 967 | right = suzy.data[MATH_D] | (suzy.data[MATH_C] << 8); |
| 968 | |
| 969 | res = left * right; |
| 970 | |
| 971 | if (suzy.data[SPRSYS] & 0x80) /* signed math */ |
| 972 | { |
| 973 | if (!(sign_AB + sign_CD)) /* different signs */ |
| 974 | res = (res ^ 0xffffffff) + 1; |
| 975 | } |
| 976 | |
| 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; |
| 981 | |
| 982 | if (suzy.data[SPRSYS] & 0x40) /* is accumulation allowed? */ |
| 983 | { |
| 984 | accu = suzy.data[MATH_M] | suzy.data[MATH_L] << 8 | suzy.data[MATH_K] << 16 | suzy.data[MATH_J] << 24; |
| 985 | accu += res; |
| 986 | |
| 987 | if (accu < res) |
| 988 | suzy.accumulate_overflow = TRUE; |
| 989 | |
| 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; |
| 663 | 994 | } |
| 664 | 995 | } |
| 665 | 996 | |
| 666 | | READ8_HANDLER(suzy_read) |
| 997 | READ8_HANDLER( suzy_read ) |
| 667 | 998 | { |
| 668 | | UINT8 data=0, input; |
| 669 | | switch (offset) { |
| 670 | | case 0x88: |
| 671 | | data=1; // must not be 0 for correct power up |
| 672 | | break; |
| 673 | | case 0x92: |
| 674 | | if (!attotime_compare(blitter.time, attotime_zero)) |
| 675 | | { |
| 676 | | if ( ATTOTIME_TO_CYCLES(0,attotime_sub(timer_get_time(), blitter.time)) > blitter.memory_accesses*20) |
| 999 | UINT8 value = 0, input; |
| 1000 | |
| 1001 | switch (offset) |
| 1002 | { |
| 1003 | case 0x88: |
| 1004 | value = 0x01; // must not be 0 for correct power up |
| 1005 | break; |
| 1006 | case 0x92: /* Better check this with docs! */ |
| 1007 | if (!attotime_compare(blitter.time, attotime_zero)) |
| 677 | 1008 | { |
| 678 | | suzy.u.data[offset]&=~1; //blitter finished |
| 679 | | blitter.time = attotime_zero; |
| 1009 | if (ATTOTIME_TO_CYCLES(0, attotime_sub(timer_get_time(), blitter.time)) > blitter.memory_accesses * 20) |
| 1010 | { |
| 1011 | suzy.data[offset] &= ~0x01; //blitter finished |
| 1012 | blitter.time = attotime_zero; |
| 1013 | } |
| 680 | 1014 | } |
| 681 | | } |
| 682 | | data=suzy.u.data[offset]; |
| 683 | | data&=~0x80; // math finished |
| 684 | | data&=~0x40; |
| 685 | | if (suzy.accumulate_overflow) data|=0x40; |
| 686 | | break; |
| 687 | | case 0xb0: |
| 688 | | input=input_port_read(machine, "JOY"); |
| 689 | | switch (lynx_rotate) { |
| 690 | | case 1: |
| 691 | | data=input; |
| 692 | | input&=0xf; |
| 693 | | if (data&PAD_UP) input|=PAD_LEFT; |
| 694 | | if (data&PAD_LEFT) input|=PAD_DOWN; |
| 695 | | if (data&PAD_DOWN) input|=PAD_RIGHT; |
| 696 | | if (data&PAD_RIGHT) input|=PAD_UP; |
| 1015 | value = suzy.data[offset]; |
| 1016 | value &= ~0x80; // math finished |
| 1017 | value &= ~0x40; |
| 1018 | if (suzy.accumulate_overflow) |
| 1019 | value |= 0x40; |
| 697 | 1020 | break; |
| 698 | | case 2: |
| 699 | | data=input; |
| 700 | | input&=0xf; |
| 701 | | if (data&PAD_UP) input|=PAD_RIGHT; |
| 702 | | if (data&PAD_RIGHT) input|=PAD_DOWN; |
| 703 | | if (data&PAD_DOWN) input|=PAD_LEFT; |
| 704 | | if (data&PAD_LEFT) input|=PAD_UP; |
| 1021 | case 0xb0: |
| 1022 | input = input_port_read(machine, "JOY"); |
| 1023 | switch (lynx_rotate) |
| 1024 | { |
| 1025 | case 1: |
| 1026 | value = input; |
| 1027 | input &= 0x0f; |
| 1028 | if (value & PAD_UP) input |= PAD_LEFT; |
| 1029 | if (value & PAD_LEFT) input |= PAD_DOWN; |
| 1030 | if (value & PAD_DOWN) input |= PAD_RIGHT; |
| 1031 | if (value & PAD_RIGHT) input |= PAD_UP; |
| 1032 | break; |
| 1033 | case 2: |
| 1034 | value = input; |
| 1035 | input &= 0x0f; |
| 1036 | if (value & PAD_UP) input |= PAD_RIGHT; |
| 1037 | if (value & PAD_RIGHT) input |= PAD_DOWN; |
| 1038 | if (value & PAD_DOWN) input |= PAD_LEFT; |
| 1039 | if (value & PAD_LEFT) input |= PAD_UP; |
| 1040 | break; |
| 1041 | } |
| 1042 | if (suzy.data[SPRSYS] & 0x08) /* Left handed controls */ |
| 1043 | { |
| 1044 | value = input & 0x0f; |
| 1045 | if (input & PAD_UP) value |= PAD_DOWN; |
| 1046 | if (input & PAD_DOWN) value |= PAD_UP; |
| 1047 | if (input & PAD_LEFT) value |= PAD_RIGHT; |
| 1048 | if (input & PAD_RIGHT) value |= PAD_LEFT; |
| 1049 | } |
| 1050 | else |
| 1051 | value = input; |
| 705 | 1052 | break; |
| 706 | | } |
| 707 | | if (suzy.u.s.SPRSYS&8) { |
| 708 | | data=input&0xf; |
| 709 | | if (input&PAD_UP) data|=PAD_DOWN; |
| 710 | | if (input&PAD_DOWN) data|=PAD_UP; |
| 711 | | if (input&PAD_LEFT) data|=PAD_RIGHT; |
| 712 | | if (input&PAD_RIGHT) data|=PAD_LEFT; |
| 713 | | } else { |
| 714 | | data=input; |
| 715 | | } |
| 716 | | break; |
| 717 | | case 0xb1: data=input_port_read(machine, "PAUSE");break; |
| 718 | | case 0xb2: |
| 719 | | data=*(memory_region(machine, "user1")+(suzy.high*lynx_granularity)+suzy.low); |
| 720 | | suzy.low=(suzy.low+1)&(lynx_granularity-1); |
| 721 | | break; |
| 722 | | default: |
| 723 | | data=suzy.u.data[offset]; |
| 1053 | case 0xb1: |
| 1054 | value = input_port_read(machine, "PAUSE"); |
| 1055 | break; |
| 1056 | case 0xb2: |
| 1057 | value = *(memory_region(machine, "user1") + (suzy.high * lynx_granularity) + suzy.low); |
| 1058 | suzy.low = (suzy.low + 1) & (lynx_granularity - 1); |
| 1059 | break; |
| 1060 | case 0xb3: /* we need bank 1 emulation!!! */ |
| 1061 | default: |
| 1062 | value = suzy.data[offset]; |
| 724 | 1063 | } |
| 725 | 1064 | // logerror("suzy read %.2x %.2x\n",offset,data); |
| 726 | | return data; |
| 1065 | return value; |
| 727 | 1066 | } |
| 728 | 1067 | |
| 729 | 1068 | WRITE8_HANDLER(suzy_write) |
| 730 | 1069 | { |
| 731 | | suzy.u.data[offset]=data; |
| 732 | | switch(offset) { |
| 733 | | case 0x52: case 0x54: case 0x56: |
| 734 | | case 0x60: case 0x62: |
| 735 | | case 0x6e: |
| 736 | | suzy.u.data[offset+1]=0; |
| 737 | | break; |
| 1070 | suzy.data[offset] = data; |
| 1071 | |
| 1072 | /* Additional effects of a write */ |
| 1073 | /* Even addresses are the LSB. Any CPU write to an LSB in 0x00-0x7f will set the MSB to 0. */ |
| 1074 | /* This in particular holds for math quantities: Writing to B (0x54), D (0x52), |
| 1075 | F (0x62), H (0x60), K (0x6e) or M (0x6c) will force a '0' to be written to A (0x55), |
| 1076 | C (0x53), E (0x63), G (0x61), J (0x6f) or L (0x6d) respectively */ |
| 1077 | switch(offset) |
| 1078 | { |
| 1079 | case 0x00: case 0x02: case 0x04: case 0x06: case 0x08: case 0x0a: case 0x0c: case 0x0e: |
| 1080 | case 0x10: case 0x12: case 0x14: case 0x16: case 0x18: case 0x1a: case 0x1c: case 0x1e: |
| 1081 | case 0x20: case 0x22: case 0x24: case 0x26: case 0x28: case 0x2a: case 0x2c: case 0x2e: |
| 1082 | case 0x30: case 0x32: case 0x34: case 0x36: case 0x38: case 0x3a: case 0x3c: case 0x3e: |
| 1083 | case 0x40: case 0x42: case 0x44: case 0x46: case 0x48: case 0x4a: case 0x4c: case 0x4e: |
| 1084 | case 0x50: case 0x56: case 0x58: case 0x5a: case 0x5c: case 0x5e: |
| 1085 | case 0x64: case 0x66: case 0x68: case 0x6a: |
| 1086 | case 0x70: case 0x72: case 0x74: case 0x76: case 0x78: case 0x7a: case 0x7c: case 0x7e: |
| 1087 | /* B, D, F, H , K */ |
| 1088 | case 0x52: case 0x54: case 0x60: case 0x62: case 0x6e: |
| 1089 | suzy.data[offset + 1] = 0; |
| 1090 | break; |
| 1091 | /* Writing to M (0x6c) will also clear the accumulator overflow bit */ |
| 738 | 1092 | case 0x6c: |
| 739 | | suzy.u.data[offset+1]=0; |
| 740 | | suzy.accumulate_overflow=FALSE; |
| 741 | | break; |
| 742 | | case 0x55: lynx_multiply();break; |
| 743 | | case 0x63: lynx_divide();break; |
| 1093 | suzy.data[offset + 1] = 0; |
| 1094 | suzy.accumulate_overflow = FALSE; |
| 1095 | break; |
| 1096 | case 0x53: |
| 1097 | /* If we are going to perform a signed multiplication, we store the sign and convert the number |
| 1098 | to an unsigned one */ |
| 1099 | if (suzy.data[SPRSYS] & 0x80) /* signed math */ |
| 1100 | { |
| 1101 | UINT16 factor, temp; |
| 1102 | factor = suzy.data[MATH_D] | (suzy.data[MATH_C] << 8); |
| 1103 | if ((factor - 1) & 0x8000) /* here we use -1 to cover the math bugs on the sign of 0 and 0x8000 */ |
| 1104 | { |
| 1105 | temp = (factor ^ 0xffff) + 1; |
| 1106 | sign_CD = - 1; |
| 1107 | suzy.data[MATH_D] = temp & 0xff; |
| 1108 | suzy.data[MATH_C] = temp >> 8; |
| 1109 | } |
| 1110 | else |
| 1111 | sign_CD = 1; |
| 1112 | } |
| 1113 | break; |
| 1114 | /* Writing to A will start a 16 bit multiply */ |
| 1115 | /* If we are going to perform a signed multiplication, we also store the sign and convert the |
| 1116 | number to an unsigned one */ |
| 1117 | case 0x55: |
| 1118 | if (suzy.data[SPRSYS] & 0x80) /* signed math */ |
| 1119 | { |
| 1120 | UINT16 factor, temp; |
| 1121 | factor = suzy.data[MATH_B] | (suzy.data[MATH_A] << 8); |
| 1122 | if ((factor - 1) & 0x8000) /* here we use -1 to cover the math bugs on the sign of 0 and 0x8000 */ |
| 1123 | { |
| 1124 | temp = (factor ^ 0xffff) + 1; |
| 1125 | sign_AB = - 1; |
| 1126 | suzy.data[MATH_B] = temp & 0xff; |
| 1127 | suzy.data[MATH_A] = temp >> 8; |
| 1128 | } |
| 1129 | else |
| 1130 | sign_AB = 1; |
| 1131 | } |
| 1132 | lynx_multiply(); |
| 1133 | break; |
| 1134 | /* Writing to E will start a 16 bit divide */ |
| 1135 | case 0x63: |
| 1136 | lynx_divide(); |
| 1137 | break; |
| 744 | 1138 | case 0x91: |
| 745 | | if (data&1) { |
| 746 | | blitter.time=timer_get_time(); |
| 747 | | lynx_blitter(); |
| 748 | | } |
| 749 | | // logerror("suzy write %.2x %.2x\n",offset,data); |
| 750 | | break; |
| 751 | | // default: |
| 752 | | // logerror("suzy write %.2x %.2x\n",offset,data); |
| 1139 | if (data & 0x01) |
| 1140 | { |
| 1141 | blitter.time = timer_get_time(); |
| 1142 | lynx_blitter(); |
| 1143 | } |
| 1144 | break; |
| 1145 | // case 0xb2: case 0xb3: /* Cart Bank 0 & 1 */ |
| 753 | 1146 | } |
| 754 | 1147 | } |
| 755 | 1148 | |
| 1149 | |
| 1150 | /**************************************** |
| 1151 | |
| 1152 | Mikey emulation |
| 1153 | |
| 1154 | ****************************************/ |
| 1155 | |
| 756 | 1156 | /* |
| 757 | 1157 | 0xfd0a r sync signal? |
| 758 | 1158 | 0xfd81 r interrupt source bit 2 vertical refresh |
| r3406 | r3407 | |
| 764 | 1164 | 0xfda0-f rw farben 0..15 |
| 765 | 1165 | 0xfdb0-f rw bit0..3 farben 0..15 |
| 766 | 1166 | */ |
| 1167 | |
| 1168 | typedef struct { |
| 1169 | UINT8 data[0x100]; |
| 1170 | } MIKEY; |
| 1171 | |
| 767 | 1172 | MIKEY mikey={ { 0 } }; |
| 768 | 1173 | |
| 769 | 1174 | |
| 1175 | UINT8 lynx_read_vram(UINT16 address) |
| 1176 | { |
| 1177 | UINT8 result = 0x00; |
| 1178 | if (address <= 0xfbff) |
| 1179 | result = lynx_mem_0000[address - 0x0000]; |
| 1180 | else if (address <= 0xfcff) |
| 1181 | result = lynx_mem_fc00[address - 0xfc00]; |
| 1182 | else if (address <= 0xfdff) |
| 1183 | result = lynx_mem_fd00[address - 0xfd00]; |
| 1184 | else if (address <= 0xfff7) |
| 1185 | result = lynx_mem_fe00[address - 0xfe00]; |
| 1186 | else if (address >= 0xfffa) |
| 1187 | result = lynx_mem_fffa[address - 0xfffa]; |
| 1188 | return result; |
| 1189 | } |
| 1190 | |
| 1191 | |
| 770 | 1192 | /* |
| 1193 | DISPCTL EQU $FD92 ; set to $D by INITMIKEY |
| 1194 | |
| 1195 | ; B7..B4 0 |
| 1196 | ; B3 1 EQU color |
| 1197 | ; B2 1 EQU 4 bit mode |
| 1198 | ; B1 1 EQU flip screen |
| 1199 | ; B0 1 EQU video DMA enabled |
| 1200 | */ |
| 1201 | void lynx_draw_lines(running_machine *machine, int newline) |
| 1202 | { |
| 1203 | static int height = -1, width = -1; |
| 1204 | int h,w; |
| 1205 | int x, yend; |
| 1206 | UINT16 j; // clipping needed! |
| 1207 | UINT8 byte; |
| 1208 | UINT16 *line; |
| 1209 | |
| 1210 | if (newline == -1) |
| 1211 | yend = 102; |
| 1212 | else |
| 1213 | yend = newline; |
| 1214 | |
| 1215 | if (yend > 102) |
| 1216 | yend = 102; |
| 1217 | |
| 1218 | if (yend == lynx_line_y) |
| 1219 | { |
| 1220 | if (newline == -1) |
| 1221 | lynx_line_y = 0; |
| 1222 | return; |
| 1223 | } |
| 1224 | |
| 1225 | j = (mikey.data[0x94] | (mikey.data[0x95]<<8)) + lynx_line_y * 160 / 2; |
| 1226 | if (mikey.data[0x92] & 0x02) |
| 1227 | j -= 160 * 102 / 2 - 1; |
| 1228 | |
| 1229 | /* rotation */ |
| 1230 | if (lynx_rotate & 0x03) |
| 1231 | { |
| 1232 | h = 160; w = 102; |
| 1233 | if (((lynx_rotate == 1) && (mikey.data[0x92] & 0x02)) || ((lynx_rotate == 2) && !(mikey.data[0x92] & 0x02))) |
| 1234 | { |
| 1235 | for ( ; lynx_line_y < yend; lynx_line_y++) |
| 1236 | { |
| 1237 | line = BITMAP_ADDR16(tmpbitmap, lynx_line_y, 0); |
| 1238 | for (x = 160 - 2; x >= 0; j++, x -= 2) |
| 1239 | { |
| 1240 | byte = lynx_read_vram(j); |
| 1241 | line[x + 1] = lynx_palette[(byte >> 4) & 0x0f]; |
| 1242 | line[x + 0] = lynx_palette[(byte >> 0) & 0x0f]; |
| 1243 | } |
| 1244 | } |
| 1245 | } |
| 1246 | else |
| 1247 | { |
| 1248 | for ( ; lynx_line_y < yend; lynx_line_y++) |
| 1249 | { |
| 1250 | line = BITMAP_ADDR16(tmpbitmap, 102 - 1 - lynx_line_y, 0); |
| 1251 | for (x = 0; x < 160; j++, x += 2) |
| 1252 | { |
| 1253 | byte = lynx_read_vram(j); |
| 1254 | line[x + 0] = lynx_palette[(byte >> 4) & 0x0f]; |
| 1255 | line[x + 1] = lynx_palette[(byte >> 0) & 0x0f]; |
| 1256 | } |
| 1257 | } |
| 1258 | } |
| 1259 | } |
| 1260 | else |
| 1261 | { |
| 1262 | w = 160; h = 102; |
| 1263 | if (mikey.data[0x92] & 0x02) |
| 1264 | { |
| 1265 | for ( ; lynx_line_y < yend; lynx_line_y++) |
| 1266 | { |
| 1267 | line = BITMAP_ADDR16(tmpbitmap, 102 - 1 - lynx_line_y, 0); |
| 1268 | for (x = 160 - 2; x >= 0; j++, x -= 2) |
| 1269 | { |
| 1270 | byte = lynx_read_vram(j); |
| 1271 | line[x + 1] = lynx_palette[(byte >> 4) & 0x0f]; |
| 1272 | line[x + 0] = lynx_palette[(byte >> 0) & 0x0f]; |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | else |
| 1277 | { |
| 1278 | for ( ; lynx_line_y < yend; lynx_line_y++) |
| 1279 | { |
| 1280 | line = BITMAP_ADDR16(tmpbitmap, lynx_line_y, 0); |
| 1281 | for (x = 0; x < 160; j++, x += 2) |
| 1282 | { |
| 1283 | byte = lynx_read_vram(j); |
| 1284 | line[x + 0] = lynx_palette[(byte >> 4) & 0x0f]; |
| 1285 | line[x + 1] = lynx_palette[(byte >> 0) & 0x0f]; |
| 1286 | } |
| 1287 | } |
| 1288 | } |
| 1289 | } |
| 1290 | if (newline == -1) |
| 1291 | { |
| 1292 | lynx_line_y = 0; |
| 1293 | if ((w != width) || (h != height)) |
| 1294 | { |
| 1295 | width = w; |
| 1296 | height = h; |
| 1297 | video_screen_set_visarea(machine->primary_screen, 0, width - 1, 0, height - 1); |
| 1298 | } |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | |
| 1303 | /**************************************** |
| 1304 | |
| 1305 | Timers |
| 1306 | |
| 1307 | ****************************************/ |
| 1308 | |
| 1309 | /* |
| 771 | 1310 | HCOUNTER EQU TIMER0 |
| 772 | 1311 | VCOUNTER EQU TIMER2 |
| 773 | 1312 | SERIALRATE EQU TIMER4 |
| r3406 | r3407 | |
| 823 | 1362 | |
| 824 | 1363 | static void lynx_timer_signal_irq(running_machine *machine, int which) |
| 825 | 1364 | { |
| 826 | | if ( ( lynx_timer[which].cntrl1 & 0x80 ) && ( which != 4 ) ) { // irq flag handling later |
| 1365 | if ( ( lynx_timer[which].cntrl1 & 0x80 ) && ( which != 4 ) ) { // irq flag handling later |
| 827 | 1366 | mikey.data[0x81] |= ( 1 << which ); |
| 828 | 1367 | cpunum_set_input_line(machine, 0, M65SC02_IRQ_LINE, ASSERT_LINE); |
| 829 | | } |
| 830 | | switch ( which ) { |
| 831 | | case 0: |
| 1368 | } |
| 1369 | switch ( which ) { |
| 1370 | case 0: |
| 832 | 1371 | lynx_timer_count_down( machine, 2 ); |
| 833 | 1372 | lynx_line++; |
| 834 | 1373 | break; |
| 835 | | case 2: |
| 1374 | case 2: |
| 836 | 1375 | lynx_timer_count_down( machine, 4 ); |
| 837 | 1376 | lynx_draw_lines( machine, -1 ); |
| 838 | 1377 | lynx_line=0; |
| 839 | 1378 | break; |
| 840 | | case 1: |
| 1379 | case 1: |
| 841 | 1380 | lynx_timer_count_down( machine, 3 ); |
| 842 | 1381 | break; |
| 843 | | case 3: |
| 1382 | case 3: |
| 844 | 1383 | lynx_timer_count_down( machine, 5 ); |
| 845 | 1384 | break; |
| 846 | | case 5: |
| 1385 | case 5: |
| 847 | 1386 | lynx_timer_count_down( machine, 7 ); |
| 848 | 1387 | break; |
| 849 | | case 7: |
| 1388 | case 7: |
| 850 | 1389 | lynx_audio_count_down( machine, 0 ); |
| 851 | 1390 | break; |
| 852 | | } |
| 1391 | } |
| 853 | 1392 | } |
| 854 | 1393 | |
| 855 | 1394 | void lynx_timer_count_down(running_machine *machine, int which) |
| 856 | 1395 | { |
| 857 | | if ( ( lynx_timer[which].cntrl1 & 0x0f ) == 0x0f ) { |
| 1396 | if ( ( lynx_timer[which].cntrl1 & 0x0f ) == 0x0f ) { |
| 858 | 1397 | if ( lynx_timer[which].counter > 0 ) { |
| 859 | | lynx_timer[which].counter--; |
| 860 | | return; |
| 1398 | lynx_timer[which].counter--; |
| 1399 | return; |
| 861 | 1400 | } |
| 862 | 1401 | if ( lynx_timer[which].counter == 0 ) { |
| 863 | 1402 | lynx_timer[which].cntrl2 |= 8; |
| 864 | | lynx_timer_signal_irq(machine, which); |
| 865 | | if ( lynx_timer[which].cntrl1 & 0x10 ) { |
| 1403 | lynx_timer_signal_irq(machine, which); |
| 1404 | if ( lynx_timer[which].cntrl1 & 0x10 ) { |
| 866 | 1405 | lynx_timer[which].counter = lynx_timer[which].bakup; |
| 867 | | } else { |
| 1406 | } else { |
| 868 | 1407 | lynx_timer[which].counter--; |
| 869 | | } |
| 870 | | return; |
| 1408 | } |
| 1409 | return; |
| 871 | 1410 | } |
| 872 | | } |
| 1411 | } |
| 873 | 1412 | } |
| 874 | 1413 | |
| 875 | 1414 | static TIMER_CALLBACK(lynx_timer_shot) |
| 876 | 1415 | { |
| 877 | 1416 | lynx_timer[param].cntrl2 |= 8; |
| 878 | | lynx_timer_signal_irq( machine, param ); |
| 879 | | if ( ! ( lynx_timer[param].cntrl1 & 0x10 ) ) |
| 1417 | lynx_timer_signal_irq( machine, param ); |
| 1418 | if ( ! ( lynx_timer[param].cntrl1 & 0x10 ) ) |
| 880 | 1419 | lynx_timer[param].timer_active = 0; |
| 881 | 1420 | } |
| 882 | 1421 | |
| r3406 | r3407 | |
| 897 | 1436 | |
| 898 | 1437 | static UINT8 lynx_timer_read(int which, int offset) |
| 899 | 1438 | { |
| 900 | | UINT8 data = 0; |
| 901 | | switch (offset) { |
| 902 | | case 0: |
| 903 | | data = lynx_timer[which].bakup; |
| 904 | | break; |
| 905 | | case 1: |
| 906 | | data = lynx_timer[which].cntrl1; |
| 907 | | break; |
| 908 | | case 2: |
| 909 | | if ( ( lynx_timer[which].cntrl1 & 7 ) == 7 ) |
| 910 | | { |
| 911 | | data = lynx_timer[which].counter; |
| 912 | | } |
| 913 | | else |
| 914 | | { |
| 915 | | if ( lynx_timer[which].timer_active ) |
| 916 | | data = (UINT8) ( lynx_timer[which].bakup - attotime_mul(timer_timeleft(lynx_timer[which].timer), lynx_time_factor( lynx_timer[which].cntrl1 & 7 )).seconds); |
| 917 | | } |
| 918 | | break; |
| 1439 | UINT8 value = 0; |
| 919 | 1440 | |
| 920 | | case 3: |
| 921 | | data = lynx_timer[which].cntrl2; |
| 922 | | break; |
| 1441 | switch (offset) |
| 1442 | { |
| 1443 | case 0: |
| 1444 | value = lynx_timer[which].bakup; |
| 1445 | break; |
| 1446 | case 1: |
| 1447 | value = lynx_timer[which].cntrl1; |
| 1448 | break; |
| 1449 | case 2: |
| 1450 | if ((lynx_timer[which].cntrl1 & 0x07) == 0x07) |
| 1451 | { |
| 1452 | value = lynx_timer[which].counter; |
| 1453 | } |
| 1454 | else |
| 1455 | { |
| 1456 | if ( lynx_timer[which].timer_active ) |
| 1457 | value = (UINT8) ( lynx_timer[which].bakup - attotime_mul(timer_timeleft(lynx_timer[which].timer), lynx_time_factor( lynx_timer[which].cntrl1 & 0x07 )).seconds); |
| 1458 | } |
| 1459 | break; |
| 1460 | |
| 1461 | case 3: |
| 1462 | value = lynx_timer[which].cntrl2; |
| 1463 | break; |
| 923 | 1464 | } |
| 924 | | logerror("timer %d read %x %.2x\n", which, offset, data); |
| 925 | | return data; |
| 1465 | logerror("timer %d read %x %.2x\n", which, offset, value); |
| 1466 | return value; |
| 926 | 1467 | } |
| 927 | 1468 | |
| 928 | 1469 | static void lynx_timer_write(int which, int offset, UINT8 data) |
| 929 | 1470 | { |
| 930 | 1471 | logerror("timer %d write %x %.2x\n", which, offset, data); |
| 931 | 1472 | |
| 932 | | switch (offset) { |
| 933 | | case 0: |
| 934 | | lynx_timer[which].bakup = data; |
| 935 | | break; |
| 936 | | case 1: |
| 937 | | lynx_timer[which].cntrl1 = data; |
| 938 | | if ( data & 0x40 ) |
| 939 | | lynx_timer[which].cntrl2 &= ~8; |
| 940 | | break; |
| 941 | | case 2: |
| 942 | | // lynx_timer[which].counter = data; |
| 943 | | break; |
| 944 | | case 3: |
| 945 | | lynx_timer[which].cntrl2 = ( lynx_timer[which].cntrl2 & 8 ) | ( data & ~8 ); |
| 946 | | break; |
| 1473 | switch (offset) |
| 1474 | { |
| 1475 | case 0: |
| 1476 | lynx_timer[which].bakup = data; |
| 1477 | break; |
| 1478 | case 1: |
| 1479 | lynx_timer[which].cntrl1 = data; |
| 1480 | if (data & 0x40) |
| 1481 | lynx_timer[which].cntrl2 &= ~0x08; |
| 1482 | break; |
| 1483 | case 2: |
| 1484 | // lynx_timer[which].counter = data; // why commented out? |
| 1485 | break; |
| 1486 | case 3: |
| 1487 | lynx_timer[which].cntrl2 = (lynx_timer[which].cntrl2 & 0x08) | (data & ~0x08); |
| 1488 | break; |
| 947 | 1489 | } |
| 948 | 1490 | |
| 949 | 1491 | /* Update timers */ |
| 950 | | if ( offset < 3 ) { |
| 951 | | timer_reset( lynx_timer[which].timer, attotime_never); |
| 1492 | if ( offset < 3 ) |
| 1493 | { |
| 1494 | timer_reset(lynx_timer[which].timer, attotime_never); |
| 952 | 1495 | lynx_timer[which].timer_active = 0; |
| 953 | | if ( ( lynx_timer[which].cntrl1 & 0x08 ) ) |
| 1496 | if ((lynx_timer[which].cntrl1 & 0x08)) // 0x48? |
| 954 | 1497 | { |
| 955 | | if ( ( lynx_timer[which].cntrl1 & 7 ) != 7 ) |
| 1498 | if ((lynx_timer[which].cntrl1 & 0x07) != 0x07) |
| 956 | 1499 | { |
| 957 | | attotime t = attotime_mul(ATTOTIME_IN_HZ( lynx_time_factor( lynx_timer[which].cntrl1 & 7 ) ), lynx_timer[which].bakup + 1 ); |
| 958 | | if ( lynx_timer[which].cntrl1 & 0x10 ) |
| 1500 | attotime t = attotime_mul(ATTOTIME_IN_HZ(lynx_time_factor(lynx_timer[which].cntrl1 & 0x07)), lynx_timer[which].bakup + 1); |
| 1501 | if (lynx_timer[which].cntrl1 & 0x10) |
| 959 | 1502 | timer_adjust_periodic(lynx_timer[which].timer, attotime_zero, which, t); |
| 960 | 1503 | else |
| 961 | 1504 | timer_adjust_oneshot(lynx_timer[which].timer, t, which); |
| r3406 | r3407 | |
| 965 | 1508 | } |
| 966 | 1509 | } |
| 967 | 1510 | |
| 1511 | |
| 1512 | /**************************************** |
| 1513 | |
| 1514 | UART Emulation |
| 1515 | |
| 1516 | ****************************************/ |
| 1517 | |
| 1518 | |
| 968 | 1519 | static struct { |
| 969 | | UINT8 serctl; |
| 970 | | UINT8 data_received, data_to_send, buffer; |
| 1520 | UINT8 serctl; |
| 1521 | UINT8 data_received, data_to_send, buffer; |
| 971 | 1522 | |
| 972 | | int received; |
| 973 | | int sending; |
| 974 | | int buffer_loaded; |
| 1523 | int received; |
| 1524 | int sending; |
| 1525 | int buffer_loaded; |
| 975 | 1526 | } uart; |
| 976 | 1527 | |
| 977 | 1528 | static void lynx_uart_reset(void) |
| 978 | 1529 | { |
| 979 | | memset(&uart, 0, sizeof(uart)); |
| 1530 | memset(&uart, 0, sizeof(uart)); |
| 980 | 1531 | } |
| 981 | 1532 | |
| 982 | 1533 | static TIMER_CALLBACK(lynx_uart_timer) |
| 983 | 1534 | { |
| 984 | | if (uart.buffer_loaded) { |
| 985 | | uart.data_to_send=uart.buffer; |
| 986 | | uart.buffer_loaded=FALSE; |
| 987 | | timer_set(ATTOTIME_IN_USEC(11), NULL, 0, lynx_uart_timer); |
| 988 | | } else { |
| 989 | | uart.sending=FALSE; |
| 990 | | } |
| 1535 | if (uart.buffer_loaded) |
| 1536 | { |
| 1537 | uart.data_to_send = uart.buffer; |
| 1538 | uart.buffer_loaded = FALSE; |
| 1539 | timer_set(ATTOTIME_IN_USEC(11), NULL, 0, lynx_uart_timer); |
| 1540 | } |
| 1541 | else |
| 1542 | uart.sending = FALSE; |
| 1543 | |
| 991 | 1544 | // mikey.data[0x80]|=0x10; |
| 992 | | if (uart.serctl&0x80) { |
| 993 | | mikey.data[0x81]|=0x10; |
| 994 | | cpunum_set_input_line(machine, 0, M65SC02_IRQ_LINE, ASSERT_LINE); |
| 1545 | if (uart.serctl & 0x80) |
| 1546 | { |
| 1547 | mikey.data[0x81] |= 0x10; |
| 1548 | cpunum_set_input_line(machine, 0, M65SC02_IRQ_LINE, ASSERT_LINE); |
| 995 | 1549 | } |
| 996 | 1550 | } |
| 997 | 1551 | |
| 998 | 1552 | static READ8_HANDLER(lynx_uart_r) |
| 999 | 1553 | { |
| 1000 | | UINT8 data=0; |
| 1001 | | switch (offset) { |
| 1002 | | case 0x8c: |
| 1003 | | if (!uart.buffer_loaded) data|=0x80; |
| 1004 | | if (uart.received) data|=0x40; |
| 1005 | | if (!uart.sending) data|=0x20; |
| 1006 | | break; |
| 1007 | | case 0x8d: |
| 1008 | | data=uart.data_received; |
| 1009 | | break; |
| 1010 | | } |
| 1011 | | logerror("uart read %.2x %.2x\n",offset,data); |
| 1012 | | return data; |
| 1554 | UINT8 value = 0x00; |
| 1555 | switch (offset) |
| 1556 | { |
| 1557 | case 0x8c: |
| 1558 | if (!uart.buffer_loaded) |
| 1559 | value |= 0x80; |
| 1560 | if (uart.received) |
| 1561 | value |= 0x40; |
| 1562 | if (!uart.sending) |
| 1563 | value |= 0x20; |
| 1564 | break; |
| 1565 | |
| 1566 | case 0x8d: |
| 1567 | value = uart.data_received; |
| 1568 | break; |
| 1569 | } |
| 1570 | logerror("uart read %.2x %.2x\n", offset, value); |
| 1571 | return value; |
| 1013 | 1572 | } |
| 1014 | 1573 | |
| 1015 | 1574 | static WRITE8_HANDLER(lynx_uart_w) |
| 1016 | 1575 | { |
| 1017 | | logerror("uart write %.2x %.2x\n",offset,data); |
| 1018 | | switch (offset) { |
| 1019 | | case 0x8c: |
| 1020 | | uart.serctl=data; |
| 1021 | | break; |
| 1022 | | case 0x8d: |
| 1023 | | if (uart.sending) { |
| 1024 | | uart.buffer=data; |
| 1025 | | uart.buffer_loaded=TRUE; |
| 1026 | | } else { |
| 1027 | | uart.sending=TRUE; |
| 1028 | | uart.data_to_send=data; |
| 1029 | | timer_set(ATTOTIME_IN_USEC(11), NULL, 0, lynx_uart_timer); |
| 1576 | logerror("uart write %.2x %.2x\n", offset, data); |
| 1577 | switch (offset) |
| 1578 | { |
| 1579 | case 0x8c: |
| 1580 | uart.serctl = data; |
| 1581 | break; |
| 1582 | |
| 1583 | case 0x8d: |
| 1584 | if (uart.sending) |
| 1585 | { |
| 1586 | uart.buffer = data; |
| 1587 | uart.buffer_loaded = TRUE; |
| 1588 | } |
| 1589 | else |
| 1590 | { |
| 1591 | uart.sending = TRUE; |
| 1592 | uart.data_to_send = data; |
| 1593 | timer_set(ATTOTIME_IN_USEC(11), NULL, 0, lynx_uart_timer); |
| 1594 | } |
| 1595 | break; |
| 1030 | 1596 | } |
| 1031 | | break; |
| 1032 | | } |
| 1033 | 1597 | } |
| 1034 | 1598 | |
| 1035 | | READ8_HANDLER(mikey_read) |
| 1599 | |
| 1600 | /**************************************** |
| 1601 | |
| 1602 | Mikey memory handlers |
| 1603 | |
| 1604 | ****************************************/ |
| 1605 | |
| 1606 | |
| 1607 | READ8_HANDLER(mikey_read) |
| 1036 | 1608 | { |
| 1037 | | UINT8 data=0; |
| 1038 | | switch (offset) { |
| 1039 | | case 0: case 1: case 2: case 3: |
| 1040 | | case 4: case 5: case 6: case 7: |
| 1041 | | case 8: case 9: case 0xa: case 0xb: |
| 1042 | | case 0xc: case 0xd: case 0xe: case 0xf: |
| 1043 | | case 0x10: case 0x11: case 0x12: case 0x13: |
| 1044 | | case 0x14: case 0x15: case 0x16: case 0x17: |
| 1045 | | case 0x18: case 0x19: case 0x1a: case 0x1b: |
| 1046 | | case 0x1c: case 0x1d: case 0x1e: case 0x1f: |
| 1047 | | data = lynx_timer_read( offset >> 2, offset & 3 ); |
| 1048 | | return data; |
| 1049 | | case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: |
| 1050 | | case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f: |
| 1051 | | case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: |
| 1052 | | case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f: |
| 1053 | | case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x50: |
| 1054 | | data = lynx_audio_read( offset ); |
| 1055 | | return data; |
| 1056 | | case 0x81: |
| 1057 | | data = mikey.data[offset]; |
| 1058 | | logerror( "mikey read %.2x %.2x\n", offset, data ); |
| 1609 | UINT8 direction, value = 0x00; |
| 1610 | |
| 1611 | switch (offset) |
| 1612 | { |
| 1613 | case 0x00: case 0x01: case 0x02: case 0x03: |
| 1614 | case 0x04: case 0x05: case 0x06: case 0x07: |
| 1615 | case 0x08: case 0x09: case 0x0a: case 0x0b: |
| 1616 | case 0x0c: case 0x0d: case 0x0e: case 0x0f: |
| 1617 | case 0x10: case 0x11: case 0x12: case 0x13: |
| 1618 | case 0x14: case 0x15: case 0x16: case 0x17: |
| 1619 | case 0x18: case 0x19: case 0x1a: case 0x1b: |
| 1620 | case 0x1c: case 0x1d: case 0x1e: case 0x1f: |
| 1621 | value = lynx_timer_read(offset >> 2, offset & 0x03); |
| 1059 | 1622 | break; |
| 1060 | | case 0x8b: |
| 1061 | | data = mikey.data[offset]; |
| 1062 | | data |= 4; // no comlynx adapter |
| 1623 | |
| 1624 | case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: |
| 1625 | case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f: |
| 1626 | case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: |
| 1627 | case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f: |
| 1628 | case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x50: |
| 1629 | value = lynx_audio_read(offset); |
| 1063 | 1630 | break; |
| 1064 | | case 0x8c: case 0x8d: |
| 1065 | | data = lynx_uart_r(machine, offset); |
| 1631 | |
| 1632 | case 0x80: |
| 1633 | case 0x81: |
| 1634 | value = mikey.data[offset]; |
| 1635 | logerror( "mikey read %.2x %.2x\n", offset, value ); |
| 1066 | 1636 | break; |
| 1067 | | default: |
| 1068 | | data = mikey.data[offset]; |
| 1069 | | logerror( "mikey read %.2x %.2x\n", offset, data ); |
| 1070 | | } |
| 1071 | | return data; |
| 1637 | |
| 1638 | case 0x84: |
| 1639 | case 0x85: |
| 1640 | value = 0x00; |
| 1641 | break; |
| 1642 | |
| 1643 | case 0x86: |
| 1644 | value = 0x80; |
| 1645 | break; |
| 1646 | |
| 1647 | case 0x88: |
| 1648 | value = 0x01; |
| 1649 | break; |
| 1650 | |
| 1651 | case 0x8b: |
| 1652 | direction = mikey.data[0x8a]; |
| 1653 | value |= (direction & 0x01) ? (mikey.data[offset] & 0x01) : 0x01; // External Power input |
| 1654 | value |= (direction & 0x02) ? (mikey.data[offset] & 0x02) : 0x00; // Cart Address Data output (0 turns cart power on) |
| 1655 | value |= (direction & 0x04) ? (mikey.data[offset] & 0x04) : 0x04; // noexp input |
| 1656 | // REST still to implement |
| 1657 | value |= (direction & 0x08) ? (mikey.data[offset] & 0x08) : 0x00; // rest output |
| 1658 | value |= (direction & 0x10) ? (mikey.data[offset] & 0x10) : 0x10; // audin input |
| 1659 | /* Hack: we disable COMLynx */ |
| 1660 | value |= 0x04; |
| 1661 | /* B5, B6 & B7 are not used */ |
| 1662 | break; |
| 1663 | |
| 1664 | case 0x8c: |
| 1665 | case 0x8d: |
| 1666 | value = lynx_uart_r(machine, offset); |
| 1667 | break; |
| 1668 | |
| 1669 | default: |
| 1670 | value = mikey.data[offset]; |
| 1671 | logerror( "mikey read %.2x %.2x\n", offset, value ); |
| 1672 | } |
| 1673 | |
| 1674 | return value; |
| 1072 | 1675 | } |
| 1073 | 1676 | |
| 1074 | 1677 | WRITE8_HANDLER(mikey_write) |
| 1075 | 1678 | { |
| 1076 | | switch (offset) { |
| 1077 | | case 0: case 1: case 2: case 3: |
| 1078 | | case 4: case 5: case 6: case 7: |
| 1079 | | case 8: case 9: case 0xa: case 0xb: |
| 1080 | | case 0xc: case 0xd: case 0xe: case 0xf: |
| 1679 | switch (offset) |
| 1680 | { |
| 1681 | case 0x00: case 0x01: case 0x02: case 0x03: |
| 1682 | case 0x04: case 0x05: case 0x06: case 0x07: |
| 1683 | case 0x08: case 0x09: case 0x0a: case 0x0b: |
| 1684 | case 0x0c: case 0x0d: case 0x0e: case 0x0f: |
| 1081 | 1685 | case 0x10: case 0x11: case 0x12: case 0x13: |
| 1082 | 1686 | case 0x14: case 0x15: case 0x16: case 0x17: |
| 1083 | 1687 | case 0x18: case 0x19: case 0x1a: case 0x1b: |
| 1084 | 1688 | case 0x1c: case 0x1d: case 0x1e: case 0x1f: |
| 1085 | | lynx_timer_write( offset >> 2, offset & 3, data ); |
| 1689 | lynx_timer_write(offset >> 2, offset & 3, data); |
| 1086 | 1690 | return; |
| 1087 | 1691 | |
| 1088 | 1692 | case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: |
| r3406 | r3407 | |
| 1094 | 1698 | return; |
| 1095 | 1699 | |
| 1096 | 1700 | case 0x80: |
| 1097 | | mikey.data[0x81]&=~data; // clear interrupt source |
| 1098 | | logerror("mikey write %.2x %.2x\n",offset,data); |
| 1701 | mikey.data[0x81] &= ~data; // clear interrupt source |
| 1702 | logerror("mikey write %.2x %.2x\n", offset, data); |
| 1099 | 1703 | if (!mikey.data[0x81]) |
| 1100 | 1704 | cpunum_set_input_line(machine, 0, M65SC02_IRQ_LINE, CLEAR_LINE); |
| 1101 | 1705 | break; |
| 1102 | 1706 | |
| 1707 | /* Is this correct? */ |
| 1708 | case 0x81: |
| 1709 | mikey.data[offset] |= data; |
| 1710 | break; |
| 1711 | |
| 1103 | 1712 | case 0x87: |
| 1104 | | mikey.data[offset]=data; //? |
| 1105 | | if (data&2) |
| 1713 | mikey.data[offset] = data; |
| 1714 | if (data & 0x02) // Power (1 = on) |
| 1106 | 1715 | { |
| 1107 | | if (data&1) |
| 1716 | if (data & 0x01) // Cart Address Strobe |
| 1108 | 1717 | { |
| 1109 | | suzy.high<<=1; |
| 1110 | | if (mikey.data[0x8b]&2) |
| 1111 | | suzy.high|=1; |
| 1112 | | suzy.low=0; |
| 1718 | suzy.high <<= 1; |
| 1719 | if (mikey.data[0x8b] & 0x02) |
| 1720 | suzy.high |= 1; |
| 1721 | suzy.high &= 0xff; |
| 1722 | suzy.low = 0; |
| 1113 | 1723 | } |
| 1114 | 1724 | } |
| 1115 | 1725 | else |
| 1116 | 1726 | { |
| 1117 | | suzy.high=0; |
| 1118 | | suzy.low=0; |
| 1727 | suzy.high = 0; |
| 1728 | suzy.low = 0; |
| 1119 | 1729 | } |
| 1120 | 1730 | break; |
| 1121 | 1731 | |
| r3406 | r3407 | |
| 1127 | 1737 | case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf: |
| 1128 | 1738 | case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7: |
| 1129 | 1739 | case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: |
| 1130 | | mikey.data[offset]=data; |
| 1740 | mikey.data[offset] = data; |
| 1131 | 1741 | lynx_draw_lines(machine, lynx_line); |
| 1132 | | #if 0 |
| 1133 | | palette_set_color_rgb(offset&0xf, |
| 1134 | | (mikey.data[0xb0+(offset&0xf)]&0xf)<<4, |
| 1135 | | (mikey.data[0xa0+(offset&0xf)]&0xf)<<4, |
| 1136 | | mikey.data[0xb0+(offset&0xf)]&0xf0 ); |
| 1137 | | #else |
| 1138 | | lynx_palette[offset&0xf]=machine->pens[((mikey.data[0xb0+(offset&0xf)]&0xf)) |
| 1139 | | |((mikey.data[0xa0+(offset&0xf)]&0xf)<<4) |
| 1140 | | |((mikey.data[0xb0+(offset&0xf)]&0xf0)<<4)]; |
| 1141 | | #endif |
| 1742 | |
| 1743 | /* RED = 0xb- & 0x0f, GREEN = 0xa- & 0x0f, BLUE = (0xb- & 0xf0) >> 4 */ |
| 1744 | lynx_palette[offset & 0x0f] = machine->pens[ |
| 1745 | ((mikey.data[0xb0 + (offset & 0x0f)] & 0x0f)) | |
| 1746 | ((mikey.data[0xa0 + (offset & 0x0f)] & 0x0f) << 4) | |
| 1747 | ((mikey.data[0xb0 + (offset & 0x0f)] & 0xf0) << 4)]; |
| 1142 | 1748 | break; |
| 1143 | 1749 | |
| 1144 | | case 0x8b:case 0x90:case 0x91: |
| 1145 | | mikey.data[offset]=data; |
| 1750 | /* TODO: properly implement these writes */ |
| 1751 | case 0x8b: |
| 1752 | mikey.data[offset] = data; |
| 1753 | if (mikey.data[0x8a] & 0x10) |
| 1754 | logerror("Trying to enable bank 1 write. %d\n", mikey.data[offset] & 0x10); |
| 1146 | 1755 | break; |
| 1756 | |
| 1757 | // case 0x90: // SDONEACK - Suzy Done Acknowledge |
| 1758 | case 0x91: // CPUSLEEP - CPU Bus Request Disable |
| 1759 | mikey.data[offset] = data; |
| 1760 | if (!data) |
| 1761 | { |
| 1762 | /* A write of '0' to this address will reset the CPU bus request flip flop */ |
| 1763 | logerror("CPUSLEEP request \n"); |
| 1764 | } |
| 1765 | break; |
| 1147 | 1766 | |
| 1148 | | default: |
| 1767 | default: |
| 1149 | 1768 | mikey.data[offset]=data; |
| 1150 | 1769 | logerror("mikey write %.2x %.2x\n",offset,data); |
| 1151 | 1770 | break; |
| 1152 | | } |
| 1771 | } |
| 1153 | 1772 | } |
| 1154 | 1773 | |
| 1774 | /**************************************** |
| 1775 | |
| 1776 | Init / Config |
| 1777 | |
| 1778 | ****************************************/ |
| 1779 | |
| 1155 | 1780 | READ8_HANDLER( lynx_memory_config_r ) |
| 1156 | 1781 | { |
| 1157 | 1782 | return lynx_memory_config; |
| r3406 | r3407 | |
| 1159 | 1784 | |
| 1160 | 1785 | WRITE8_HANDLER( lynx_memory_config_w ) |
| 1161 | 1786 | { |
| 1162 | | /* bit 7: hispeed, uses page mode accesses (4 instead of 5 cycles ) |
| 1163 | | * when these are safe in the cpu */ |
| 1164 | | lynx_memory_config = data; |
| 1787 | /* bit 7: hispeed, uses page mode accesses (4 instead of 5 cycles ) |
| 1788 | * when these are safe in the cpu */ |
| 1789 | lynx_memory_config = data; |
| 1165 | 1790 | |
| 1166 | 1791 | memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xfc00, 0xfcff, 0, 0, (data & 1) ? SMH_BANK1 : suzy_read); |
| 1167 | 1792 | memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xfc00, 0xfcff, 0, 0, (data & 1) ? SMH_BANK1 : suzy_write); |
| r3406 | r3407 | |
| 1186 | 1811 | memset(&suzy, 0, sizeof(suzy)); |
| 1187 | 1812 | memset(&mikey, 0, sizeof(mikey)); |
| 1188 | 1813 | |
| 1189 | | mikey.data[0x80] = 0; |
| 1190 | | mikey.data[0x81] = 0; |
| 1814 | suzy.data[0x88] = 0x01; |
| 1815 | suzy.data[0x90] = 0x00; |
| 1816 | suzy.data[0x91] = 0x00; |
| 1817 | mikey.data[0x80] = 0x00; |
| 1818 | mikey.data[0x81] = 0x00; |
| 1819 | mikey.data[0x88] = 0x01; |
| 1820 | mikey.data[0x8a] = 0x00; |
| 1821 | mikey.data[0x8c] = 0x00; |
| 1822 | mikey.data[0x90] = 0x00; |
| 1823 | mikey.data[0x92] = 0x00; |
| 1191 | 1824 | |
| 1192 | 1825 | lynx_uart_reset(); |
| 1193 | 1826 | |
| r3406 | r3407 | |
| 1225 | 1858 | |
| 1226 | 1859 | add_reset_callback(machine, lynx_reset); |
| 1227 | 1860 | } |
| 1861 | |
| 1862 | |
| 1863 | /**************************************** |
| 1864 | |
| 1865 | Image handling |
| 1866 | |
| 1867 | ****************************************/ |
| 1868 | |
| 1869 | |
| 1870 | static void lynx_partialhash(char *dest, const unsigned char *data, |
| 1871 | unsigned long length, unsigned int functions) |
| 1872 | { |
| 1873 | if (length <= 64) |
| 1874 | return; |
| 1875 | hash_compute(dest, &data[64], length - 64, functions); |
| 1876 | } |
| 1877 | |
| 1878 | int lynx_verify_cart (char *header, int kind) |
| 1879 | { |
| 1880 | if (kind) |
| 1881 | { |
| 1882 | if (strncmp("BS93", &header[6], 4)) |
| 1883 | { |
| 1884 | logerror("This is not a valid Lynx image\n"); |
| 1885 | return IMAGE_VERIFY_FAIL; |
| 1886 | } |
| 1887 | } |
| 1888 | else |
| 1889 | { |
| 1890 | if (strncmp("LYNX",&header[0],4)) |
| 1891 | { |
| 1892 | if (!strncmp("BS93", &header[6], 4)) |
| 1893 | { |
| 1894 | logerror("This image is probably a Quickload image with .lnx extension\n"); |
| 1895 | logerror("Try to load it with -quickload\n"); |
| 1896 | } |
| 1897 | else |
| 1898 | logerror("This is not a valid Lynx image\n"); |
| 1899 | return IMAGE_VERIFY_FAIL; |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | return IMAGE_VERIFY_PASS; |
| 1904 | } |
| 1905 | |
| 1906 | INTERRUPT_GEN( lynx_frame_int ) |
| 1907 | { |
| 1908 | lynx_rotate = rotate; |
| 1909 | if ((input_port_read(machine, "ROTATION") & 0x03) != 0x03) |
| 1910 | lynx_rotate=input_port_read(machine, "ROTATION") & 0x03; |
| 1911 | } |
| 1912 | |
| 1913 | void lynx_crc_keyword(const device_config *image) |
| 1914 | { |
| 1915 | const char *info; |
| 1916 | |
| 1917 | info = image_extrainfo(image); |
| 1918 | rotate = 0; |
| 1919 | |
| 1920 | if (info) |
| 1921 | { |
| 1922 | if(strcmp(info, "ROTATE90DEGREE") == 0) |
| 1923 | rotate = 1; |
| 1924 | else if (strcmp(info, "ROTATE270DEGREE") == 0) |
| 1925 | rotate = 2; |
| 1926 | } |
| 1927 | } |
| 1928 | |
| 1929 | static DEVICE_IMAGE_LOAD( lynx_cart ) |
| 1930 | { |
| 1931 | UINT8 *rom = memory_region(image->machine, "user1"); |
| 1932 | int size = image_length(image); |
| 1933 | const char *filetype; |
| 1934 | UINT8 header[0x40]; |
| 1935 | /* 64 byte header |
| 1936 | LYNX |
| 1937 | intelword lower counter size |
| 1938 | 0 0 1 0 |
| 1939 | 32 chars name |
| 1940 | 22 chars manufacturer |
| 1941 | */ |
| 1942 | |
| 1943 | filetype = image_filetype(image); |
| 1944 | |
| 1945 | if (!mame_stricmp (filetype, "lnx")) |
| 1946 | { |
| 1947 | if (image_fread(image, header, 0x40)!=0x40) |
| 1948 | return INIT_FAIL; |
| 1949 | |
| 1950 | /* Check the image */ |
| 1951 | if (lynx_verify_cart((char*)header, LYNX_CART) == IMAGE_VERIFY_FAIL) |
| 1952 | return INIT_FAIL; |
| 1953 | |
| 1954 | /* 2008-10 FP: According to Handy source these should be page_size_bank0. Are we using |
| 1955 | it correctly in MESS? Moreover, the next two values should be page_size_bank1. We should |
| 1956 | implement this as well */ |
| 1957 | lynx_granularity = header[4] | (header[5] << 8); |
| 1958 | |
| 1959 | logerror ("%s %dkb cartridge with %dbyte granularity from %s\n", |
| 1960 | header + 10, size / 1024, lynx_granularity, header + 42); |
| 1961 | |
| 1962 | size -= 0x40; |
| 1963 | } |
| 1964 | else if (!mame_stricmp (filetype, "lyx")) |
| 1965 | { |
| 1966 | /* 2008-10 FP: FIXME: .lyx file don't have an header, hence they miss "lynx_granularity" |
| 1967 | (see above). What if bank 0 has to be loaded elsewhere? And what about bank 1? |
| 1968 | These should work with most .lyx files, but we need additional info on raw cart images */ |
| 1969 | if (size == 0x20000) |
| 1970 | lynx_granularity = 0x0200; |
| 1971 | else if (size == 0x80000) |
| 1972 | lynx_granularity = 0x0800; |
| 1973 | else |
| 1974 | lynx_granularity = 0x0400; |
| 1975 | } |
| 1976 | |
| 1977 | if (image_fread(image, rom, size) != size) |
| 1978 | return INIT_FAIL; |
| 1979 | |
| 1980 | lynx_crc_keyword(image); |
| 1981 | |
| 1982 | return INIT_PASS; |
| 1983 | } |
| 1984 | |
| 1985 | void lynx_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 1986 | { |
| 1987 | /* cartslot */ |
| 1988 | switch(state) |
| 1989 | { |
| 1990 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1991 | case MESS_DEVINFO_INT_COUNT: info->i = 1; break; |
| 1992 | |
| 1993 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1994 | case MESS_DEVINFO_PTR_LOAD: info->load = DEVICE_IMAGE_LOAD_NAME(lynx_cart); break; |
| 1995 | case MESS_DEVINFO_PTR_PARTIAL_HASH: info->partialhash = lynx_partialhash; break; |
| 1996 | |
| 1997 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1998 | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "lnx,lyx"); break; |
| 1999 | |
| 2000 | default: cartslot_device_getinfo(devclass, state, info); break; |
| 2001 | } |
| 2002 | } |