src/mess/video/fm7.c
| r5143 | r5144 | |
| 120 | 120 | fm7_video.vram_access = 0; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | static void fm7_alu_function_compare(UINT32 offset) |
| 124 | { |
| 125 | // COMPARE - compares which colors match those in the compare registers |
| 126 | // can be used on its own, or when bit 6 of the command register is high. |
| 127 | |
| 128 | UINT8 red,green,blue; |
| 129 | UINT8 dat = 0; |
| 130 | UINT8 colour; |
| 131 | UINT8 banks; |
| 132 | int x,y; |
| 133 | int match; |
| 134 | int page = 0; |
| 135 | |
| 136 | if(offset >= 0xc000) |
| 137 | page = 1; |
| 138 | |
| 139 | blue = fm7_video_ram[(offset & 0x3fff) + (page * 0xc000)]; |
| 140 | red = fm7_video_ram[(offset & 0x3fff) + 0x4000 + (page * 0xc000)]; |
| 141 | green = fm7_video_ram[(offset & 0x3fff) + 0x8000 + (page * 0xc000)]; |
| 142 | |
| 143 | banks = (~fm7_alu.bank_disable) & 0x07; |
| 144 | |
| 145 | for(x=0;x<8;x++) // loop through each pixel |
| 146 | { |
| 147 | colour = 0; |
| 148 | if(blue & (1 << x)) |
| 149 | colour |= 1; |
| 150 | if(red & (1 << x)) |
| 151 | colour |= 2; |
| 152 | if(green & (1 << x)) |
| 153 | colour |= 4; |
| 154 | |
| 155 | match = 0; |
| 156 | for(y=0;y<8;y++) // loop through each compare register |
| 157 | { |
| 158 | if(!(fm7_alu.compare[y] & 0x80)) // don't compare if register is masked |
| 159 | { |
| 160 | if((fm7_alu.compare[y] & banks) == (colour & banks)) |
| 161 | match = 1; |
| 162 | } |
| 163 | } |
| 164 | if(match != 0) |
| 165 | dat |= (1 << x); |
| 166 | } |
| 167 | fm7_alu.compare_data = dat; |
| 168 | } |
| 169 | |
| 123 | 170 | static void fm7_alu_function_pset(UINT32 offset) |
| 124 | 171 | { |
| 125 | 172 | // PSET - simply sets the pixels to the selected logical colour |
| r5143 | r5144 | |
| 128 | 175 | int page = 0; |
| 129 | 176 | UINT8 mask; |
| 130 | 177 | |
| 131 | | if(offset > 0xc000) |
| 178 | if(fm7_alu.command & 0x40) |
| 179 | fm7_alu_function_compare(offset); |
| 180 | |
| 181 | if(offset >= 0xc000) |
| 132 | 182 | page = 1; |
| 133 | 183 | |
| 134 | 184 | for(x=0;x<3;x++) // cycle through banks |
| 135 | 185 | { |
| 136 | | if(fm7_alu.lcolour & (1 << x)) |
| 137 | | dat = 0xff; |
| 138 | | else |
| 139 | | dat = 0; |
| 186 | if(!(fm7_alu.bank_disable & (1 << x))) |
| 187 | { |
| 188 | if(fm7_alu.lcolour & (1 << x)) |
| 189 | dat = 0xff; |
| 190 | else |
| 191 | dat = 0; |
| 192 | |
| 193 | mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]) & fm7_alu.mask; |
| 194 | dat &= ~fm7_alu.mask; |
| 195 | dat |= mask; |
| 196 | |
| 197 | fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat; |
| 198 | } |
| 199 | } |
| 200 | } |
| 140 | 201 | |
| 141 | | mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]) & fm7_alu.mask; |
| 142 | | dat &= ~fm7_alu.mask; |
| 143 | | dat |= mask; |
| 202 | static void fm7_alu_function_or(UINT32 offset) |
| 203 | { |
| 204 | int x; |
| 205 | UINT8 dat; |
| 206 | int page = 0; |
| 207 | UINT8 mask; |
| 208 | |
| 209 | if(fm7_alu.command & 0x40) |
| 210 | fm7_alu_function_compare(offset); |
| 211 | |
| 212 | if(offset >= 0xc000) |
| 213 | page = 1; |
| 214 | |
| 215 | for(x=0;x<3;x++) // cycle through banks |
| 216 | { |
| 217 | if(!(fm7_alu.bank_disable & (1 << x))) |
| 218 | { |
| 219 | if(fm7_alu.lcolour & (1 << x)) |
| 220 | dat = 0xff; |
| 221 | else |
| 222 | dat = 0; |
| 223 | |
| 224 | mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]); |
| 225 | dat |= mask; |
| 144 | 226 | |
| 145 | | fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat; |
| 227 | mask &= fm7_alu.mask; |
| 228 | dat &= ~fm7_alu.mask; |
| 229 | dat |= mask; |
| 230 | |
| 231 | fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat; |
| 232 | } |
| 146 | 233 | } |
| 147 | 234 | } |
| 148 | 235 | |
| 236 | static void fm7_alu_function_and(UINT32 offset) |
| 237 | { |
| 238 | int x; |
| 239 | UINT8 dat; |
| 240 | int page = 0; |
| 241 | UINT8 mask; |
| 242 | |
| 243 | if(fm7_alu.command & 0x40) |
| 244 | fm7_alu_function_compare(offset); |
| 245 | |
| 246 | if(offset >= 0xc000) |
| 247 | page = 1; |
| 248 | |
| 249 | for(x=0;x<3;x++) // cycle through banks |
| 250 | { |
| 251 | if(!(fm7_alu.bank_disable & (1 << x))) |
| 252 | { |
| 253 | if(fm7_alu.lcolour & (1 << x)) |
| 254 | dat = 0xff; |
| 255 | else |
| 256 | dat = 0; |
| 257 | |
| 258 | mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]); |
| 259 | dat &= mask; |
| 260 | |
| 261 | mask &= fm7_alu.mask; |
| 262 | dat &= ~fm7_alu.mask; |
| 263 | dat |= mask; |
| 264 | |
| 265 | fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | static void fm7_alu_function_xor(UINT32 offset) |
| 271 | { |
| 272 | int x; |
| 273 | UINT8 dat; |
| 274 | int page = 0; |
| 275 | UINT8 mask; |
| 276 | |
| 277 | if(fm7_alu.command & 0x40) |
| 278 | fm7_alu_function_compare(offset); |
| 279 | |
| 280 | if(offset >= 0xc000) |
| 281 | page = 1; |
| 282 | |
| 283 | for(x=0;x<3;x++) // cycle through banks |
| 284 | { |
| 285 | if(!(fm7_alu.bank_disable & (1 << x))) |
| 286 | { |
| 287 | if(fm7_alu.lcolour & (1 << x)) |
| 288 | dat = 0xff; |
| 289 | else |
| 290 | dat = 0; |
| 291 | |
| 292 | mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]); |
| 293 | dat ^= mask; |
| 294 | |
| 295 | mask &= fm7_alu.mask; |
| 296 | dat &= ~fm7_alu.mask; |
| 297 | dat |= mask; |
| 298 | |
| 299 | fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat; |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | static void fm7_alu_function_not(UINT32 offset) |
| 305 | { |
| 306 | int x; |
| 307 | UINT8 dat; |
| 308 | int page = 0; |
| 309 | UINT8 mask; |
| 310 | |
| 311 | if(fm7_alu.command & 0x40) |
| 312 | fm7_alu_function_compare(offset); |
| 313 | |
| 314 | if(offset >= 0xc000) |
| 315 | page = 1; |
| 316 | |
| 317 | for(x=0;x<3;x++) // cycle through banks |
| 318 | { |
| 319 | if(!(fm7_alu.bank_disable & (1 << x))) |
| 320 | { |
| 321 | if(fm7_alu.lcolour & (1 << x)) |
| 322 | dat = 0xff; |
| 323 | else |
| 324 | dat = 0; |
| 325 | |
| 326 | mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]); |
| 327 | dat = ~mask; |
| 328 | |
| 329 | mask &= fm7_alu.mask; |
| 330 | dat &= ~fm7_alu.mask; |
| 331 | dat |= mask; |
| 332 | |
| 333 | fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat; |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 149 | 338 | static void fm7_alu_function_tilepaint(UINT32 offset) |
| 150 | 339 | { |
| 151 | 340 | // TILEPAINT - writes to VRAM based on the tilepaint colour registers |
| r5143 | r5144 | |
| 154 | 343 | int page = 0; |
| 155 | 344 | UINT8 mask; |
| 156 | 345 | |
| 157 | | if(offset > 0xc000) |
| 346 | if(fm7_alu.command & 0x40) |
| 347 | fm7_alu_function_compare(offset); |
| 348 | |
| 349 | if(offset >= 0xc000) |
| 158 | 350 | page = 1; |
| 159 | 351 | |
| 160 | 352 | for(x=0;x<3;x++) // cycle through banks |
| 161 | 353 | { |
| 162 | | switch(x) |
| 354 | if(!(fm7_alu.bank_disable & (1 << x))) |
| 163 | 355 | { |
| 164 | | case 0: |
| 165 | | dat = fm7_alu.tilepaint_b; |
| 166 | | break; |
| 167 | | case 1: |
| 168 | | dat = fm7_alu.tilepaint_r; |
| 169 | | break; |
| 170 | | case 2: |
| 171 | | dat = fm7_alu.tilepaint_g; |
| 172 | | break; |
| 356 | switch(x) |
| 357 | { |
| 358 | case 0: |
| 359 | dat = fm7_alu.tilepaint_b; |
| 360 | break; |
| 361 | case 1: |
| 362 | dat = fm7_alu.tilepaint_r; |
| 363 | break; |
| 364 | case 2: |
| 365 | dat = fm7_alu.tilepaint_g; |
| 366 | break; |
| 367 | } |
| 368 | dat &= ~fm7_alu.mask; |
| 369 | mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]) & fm7_alu.mask; |
| 370 | dat |= mask; |
| 371 | |
| 372 | fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat; |
| 173 | 373 | } |
| 174 | | dat &= ~fm7_alu.mask; |
| 175 | | mask = (fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)]) & fm7_alu.mask; |
| 176 | | dat |= mask; |
| 177 | | |
| 178 | | fm7_video_ram[(offset & 0x3fff) + (x * 0x4000) + (page * 0xc000)] = dat; |
| 179 | 374 | } |
| 180 | 375 | } |
| 181 | 376 | |
| r5143 | r5144 | |
| 186 | 381 | case 0x00: // PSET |
| 187 | 382 | fm7_alu_function_pset(offset); |
| 188 | 383 | break; |
| 189 | | case 0x06: // TILEPAINT |
| 190 | | fm7_alu_function_tilepaint(offset); |
| 384 | case 0x02: // OR |
| 385 | fm7_alu_function_or(offset); |
| 191 | 386 | break; |
| 192 | | case 0x02: // OR |
| 193 | 387 | case 0x03: // AND |
| 388 | fm7_alu_function_and(offset); |
| 389 | break; |
| 194 | 390 | case 0x04: // XOR |
| 391 | fm7_alu_function_xor(offset); |
| 392 | break; |
| 195 | 393 | case 0x05: // NOT |
| 394 | fm7_alu_function_not(offset); |
| 395 | break; |
| 396 | case 0x06: // TILEPAINT |
| 397 | fm7_alu_function_tilepaint(offset); |
| 398 | break; |
| 196 | 399 | case 0x07: // COMPARE |
| 197 | | logerror("ALU: Unimplemented draw mode %i used\n",fm7_alu.command & 0x07); |
| 400 | fm7_alu_function_compare(offset); |
| 198 | 401 | break; |
| 199 | 402 | case 0x01: |
| 200 | 403 | default: |
| 201 | | logerror("ALU: Invalid draw mode %i used\n",fm7_alu.command & 0x07); |
| 404 | popmessage("ALU: Invalid draw mode %i used\n",fm7_alu.command & 0x07); |
| 202 | 405 | } |
| 203 | 406 | } |
| 204 | 407 | |
| r5143 | r5144 | |
| 210 | 413 | if(fm7_video.active_video_page != 0) |
| 211 | 414 | page = 0xc000; |
| 212 | 415 | |
| 213 | | if(fm7_alu.command & 0x80) // ALU active, writes to VRAM even when reading it (go figure) |
| 214 | | { |
| 215 | | fm7_alu_function(offset+page); |
| 216 | | } |
| 217 | | |
| 218 | 416 | if(offset < 0x4000 && (fm7_video.multi_page & 0x01)) |
| 219 | 417 | return 0xff; |
| 220 | 418 | if((offset < 0x8000 && offset >=0x4000) && (fm7_video.multi_page & 0x02)) |
| r5143 | r5144 | |
| 222 | 420 | if((offset < 0xc000 && offset >=0x8000) && (fm7_video.multi_page & 0x04)) |
| 223 | 421 | return 0xff; |
| 224 | 422 | |
| 423 | if(fm7_alu.command & 0x80) // ALU active, writes to VRAM even when reading it (go figure) |
| 424 | { |
| 425 | fm7_alu_function(offset+page); |
| 426 | } |
| 427 | |
| 225 | 428 | offs = (offset & 0xc000) | ((offset + fm7_video.vram_offset) & 0x3fff); |
| 226 | 429 | return fm7_video_ram[offs + page]; |
| 227 | 430 | } |
| r5143 | r5144 | |
| 234 | 437 | if(fm7_video.active_video_page != 0) |
| 235 | 438 | page = 0xc000; |
| 236 | 439 | |
| 237 | | if(fm7_alu.command & 0x80) // ALU active |
| 238 | | { |
| 239 | | fm7_alu_function(offset+page); |
| 240 | | return; |
| 241 | | } |
| 242 | | |
| 243 | 440 | if(offset < 0x4000 && (fm7_video.multi_page & 0x01)) |
| 244 | 441 | return; |
| 245 | 442 | if((offset < 0x8000 && offset >=0x4000) && (fm7_video.multi_page & 0x02)) |
| 246 | 443 | return; |
| 247 | 444 | if((offset < 0xc000 && offset >=0x8000) && (fm7_video.multi_page & 0x04)) |
| 248 | 445 | return; |
| 446 | |
| 447 | if(fm7_alu.command & 0x80) // ALU active |
| 448 | { |
| 449 | fm7_alu_function(offset+page); |
| 450 | return; |
| 451 | } |
| 249 | 452 | |
| 250 | 453 | offs = (offset & 0xc000) | ((offset + fm7_video.vram_offset) & 0x3fff); |
| 251 | 454 | if(fm7_video.vram_access != 0) |
| r5143 | r5144 | |
| 264 | 467 | if(fm7_video.active_video_page != 0) |
| 265 | 468 | page = 0xc000; |
| 266 | 469 | |
| 267 | | if(fm7_alu.command & 0x80) // ALU active |
| 268 | | { |
| 269 | | fm7_alu_function(offset+page); |
| 270 | | return; |
| 271 | | } |
| 272 | | |
| 273 | 470 | if(offset < 0x4000 && (fm7_video.multi_page & 0x01)) |
| 274 | 471 | return; |
| 275 | 472 | if((offset < 0x8000 && offset >=0x4000) && (fm7_video.multi_page & 0x02)) |
| r5143 | r5144 | |
| 277 | 474 | if((offset < 0xc000 && offset >=0x8000) && (fm7_video.multi_page & 0x04)) |
| 278 | 475 | return; |
| 279 | 476 | |
| 477 | if(fm7_alu.command & 0x80) // ALU active |
| 478 | { |
| 479 | fm7_alu_function(offset+page); |
| 480 | return; |
| 481 | } |
| 482 | |
| 280 | 483 | offs = (offset & 0xc000) | ((offset + fm7_video.vram_offset) & 0x3fff); |
| 281 | 484 | fm7_video_ram[offs+page] = data; |
| 282 | 485 | } |