src/mame/video/snes.c
| r7312 | r7313 | |
| 81 | 81 | #define SNES_CLIP_OUT 2 |
| 82 | 82 | #define SNES_CLIP_ALL2 3 |
| 83 | 83 | |
| 84 | | #ifdef MAME_DEBUG |
| 84 | #ifdef SNES_LAYER_DEBUG |
| 85 | 85 | struct DEBUGOPTS |
| 86 | 86 | { |
| 87 | 87 | UINT8 input_count; |
| r7312 | r7313 | |
| 95 | 95 | /* red green blue purple yellow cyan grey white */ |
| 96 | 96 | static const UINT16 dbg_mode_colours[8] = { 0x1f, 0x3e0, 0x7c00, 0x7c1f, 0x3ff, 0x7fe0, 0x4210, 0x7fff }; |
| 97 | 97 | static UINT8 snes_dbg_video(running_machine *machine, bitmap_t *bitmap, UINT16 curline); |
| 98 | | #endif /* MAME_DEBUG */ |
| 98 | #endif /* SNES_LAYER_DEBUG */ |
| 99 | 99 | |
| 100 | 100 | static const UINT16 table_obj_offset[8][8] = |
| 101 | 101 | { |
| r7312 | r7313 | |
| 146 | 146 | if (clip == SNES_CLIP_ALL2) // blending mode 3 == always OFF |
| 147 | 147 | return; |
| 148 | 148 | |
| 149 | | #ifdef MAME_DEBUG |
| 149 | #ifdef SNES_LAYER_DEBUG |
| 150 | 150 | if (!debug_options.transparency_disabled) |
| 151 | | #endif /* MAME_DEBUG */ |
| 151 | #endif /* SNES_LAYER_DEBUG */ |
| 152 | 152 | if ((clip == SNES_CLIP_ALL) || |
| 153 | 153 | (clip == SNES_CLIP_IN && !snes_ppu.clipmasks[SNES_COLOR][offset]) || |
| 154 | 154 | (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset])) |
| r7312 | r7313 | |
| 264 | 264 | mask >>= 1; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | | #ifdef MAME_DEBUG |
| 267 | #ifdef SNES_LAYER_DEBUG |
| 268 | 268 | if (!debug_options.windows_disabled) |
| 269 | | #endif /* MAME_DEBUG */ |
| 269 | #endif /* SNES_LAYER_DEBUG */ |
| 270 | 270 | /* Clip to windows */ |
| 271 | 271 | window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled; |
| 272 | 272 | if (window_enabled) |
| r7312 | r7313 | |
| 372 | 372 | mask >>= 1; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | | #ifdef MAME_DEBUG |
| 375 | #ifdef SNES_LAYER_DEBUG |
| 376 | 376 | if (!debug_options.windows_disabled) |
| 377 | | #endif /* MAME_DEBUG */ |
| 377 | #endif /* SNES_LAYER_DEBUG */ |
| 378 | 378 | /* Clip to windows */ |
| 379 | | window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[4].main_window_enabled : snes_ppu.layer[SNES_OAM].sub_window_enabled; |
| 379 | window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[SNES_OAM].main_window_enabled : snes_ppu.layer[SNES_OAM].sub_window_enabled; |
| 380 | 380 | if (window_enabled) |
| 381 | 381 | colour &= snes_ppu.clipmasks[SNES_OAM][ii]; |
| 382 | 382 | |
| r7312 | r7313 | |
| 426 | 426 | UINT8 tile_divider = 1; |
| 427 | 427 | UINT8 wrap_around_x; //helper for wrap-around |
| 428 | 428 | |
| 429 | | #ifdef MAME_DEBUG |
| 429 | #ifdef SNES_LAYER_DEBUG |
| 430 | 430 | if (debug_options.bg_disabled[layer]) |
| 431 | 431 | return; |
| 432 | 432 | |
| 433 | 433 | if (debug_options.mode_disabled[snes_ppu.mode]) |
| 434 | 434 | return; |
| 435 | | #endif /* MAME_DEBUG */ |
| 435 | #endif /* SNES_LAYER_DEBUG */ |
| 436 | 436 | |
| 437 | 437 | /* Handle Mosaic effects */ |
| 438 | 438 | if (snes_ppu.layer[layer].mosaic_enabled) |
| r7312 | r7313 | |
| 599 | 599 | UINT8 colour = 0, window_enabled = 0; |
| 600 | 600 | UINT16 *mosaic_x, *mosaic_y; |
| 601 | 601 | |
| 602 | | #ifdef MAME_DEBUG |
| 602 | #ifdef SNES_LAYER_DEBUG |
| 603 | 603 | if (debug_options.bg_disabled[layer]) |
| 604 | 604 | return; |
| 605 | 605 | |
| 606 | 606 | if (debug_options.mode_disabled[snes_ppu.mode]) |
| 607 | 607 | return; |
| 608 | | #endif /* MAME_DEBUG */ |
| 608 | #endif /* SNES_LAYER_DEBUG */ |
| 609 | 609 | |
| 610 | 610 | ma = snes_ppu.mode7.matrix_a; |
| 611 | 611 | mb = snes_ppu.mode7.matrix_b; |
| r7312 | r7313 | |
| 756 | 756 | {1, 2, 5, 8} // mode 1 + BG3 priority bit |
| 757 | 757 | }; |
| 758 | 758 | |
| 759 | | #ifdef MAME_DEBUG |
| 759 | #ifdef SNES_LAYER_DEBUG |
| 760 | 760 | if (debug_options.bg_disabled[4]) |
| 761 | 761 | return; |
| 762 | | #endif /* MAME_DEBUG */ |
| 762 | #endif /* SNES_LAYER_DEBUG */ |
| 763 | 763 | |
| 764 | 764 | if (snes_ppu.mode == 5 || snes_ppu.mode == 6) |
| 765 | 765 | widemode = 1; |
| r7312 | r7313 | |
| 874 | 874 | bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; |
| 875 | 875 | |
| 876 | 876 | if (bg_enabled[4]) snes_update_objects(screen, 0, curline); |
| 877 | | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 7, 10, 0, curline, 0, 0); |
| 878 | | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 6, 9, 1, curline, 0, 0); |
| 879 | | if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 1, 4, 2, curline, 0, 0); |
| 880 | | if (bg_enabled[3]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 3, 3, curline, 0, 0); |
| 877 | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 7, 10, SNES_BG1, curline, 0, 0); |
| 878 | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 6, 9, SNES_BG2, curline, 0, 0); |
| 879 | if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 1, 4, SNES_BG3, curline, 0, 0); |
| 880 | if (bg_enabled[3]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 3, SNES_BG4, curline, 0, 0); |
| 881 | 881 | } |
| 882 | 882 | |
| 883 | 883 | static void snes_update_mode_1( UINT8 screen, UINT16 curline ) |
| r7312 | r7313 | |
| 888 | 888 | if (!snes_ppu.bg3_priority_bit) |
| 889 | 889 | { |
| 890 | 890 | if (bg_enabled[4]) snes_update_objects(screen, 1, curline); |
| 891 | | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 5, 8, 0, curline, 0, 0); |
| 892 | | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 4, 7, 1, curline, 0, 0); |
| 893 | | if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 2, 2, curline, 0, 0); |
| 891 | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 5, 8, SNES_BG1, curline, 0, 0); |
| 892 | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 4, 7, SNES_BG2, curline, 0, 0); |
| 893 | if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 2, SNES_BG3, curline, 0, 0); |
| 894 | 894 | } |
| 895 | 895 | else |
| 896 | 896 | { |
| 897 | 897 | if (bg_enabled[4]) snes_update_objects(screen, 9, curline); |
| 898 | | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 4, 7, 0, curline, 0, 0); |
| 899 | | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 3, 6, 1, curline, 0, 0); |
| 900 | | if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 9, 2, curline, 0, 0); |
| 898 | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 4, 7, SNES_BG1, curline, 0, 0); |
| 899 | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 3, 6, SNES_BG2, curline, 0, 0); |
| 900 | if (bg_enabled[2]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 9, SNES_BG3, curline, 0, 0); |
| 901 | 901 | } |
| 902 | 902 | } |
| 903 | 903 | |
| r7312 | r7313 | |
| 907 | 907 | bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; |
| 908 | 908 | |
| 909 | 909 | if (bg_enabled[4]) snes_update_objects(screen, 2, curline); |
| 910 | | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 2, 6, 0, curline, 1, 0); |
| 911 | | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 0, 4, 1, curline, 1, 0); |
| 910 | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 2, 6, SNES_BG1, curline, 1, 0); |
| 911 | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 0, 4, SNES_BG2, curline, 1, 0); |
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | static void snes_update_mode_3( UINT8 screen, UINT16 curline ) |
| r7312 | r7313 | |
| 917 | 917 | bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; |
| 918 | 918 | |
| 919 | 919 | if (bg_enabled[4]) snes_update_objects(screen, 3, curline); |
| 920 | | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, 0, curline, 0, snes_ppu.direct_color); |
| 921 | | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 0, 4, 1, curline, 0, 0); |
| 920 | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, SNES_BG1, curline, 0, snes_ppu.direct_color); |
| 921 | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 0, 4, SNES_BG2, curline, 0, 0); |
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | static void snes_update_mode_4( UINT8 screen, UINT16 curline ) |
| r7312 | r7313 | |
| 927 | 927 | bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; |
| 928 | 928 | |
| 929 | 929 | if (bg_enabled[4]) snes_update_objects(screen, 4, curline); |
| 930 | | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, 0, curline, 0, snes_ppu.direct_color); |
| 931 | | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 4, 1, curline, 0, 0); |
| 930 | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, SNES_BG1, curline, 0, snes_ppu.direct_color); |
| 931 | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 0, 4, SNES_BG2, curline, 0, 0); |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | static void snes_update_mode_5( UINT8 screen, UINT16 curline ) |
| r7312 | r7313 | |
| 937 | 937 | bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; |
| 938 | 938 | |
| 939 | 939 | if (bg_enabled[4]) snes_update_objects(screen, 5, curline); |
| 940 | | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 2, 6, 0, curline, 0, 0); |
| 941 | | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 1, 0, 4, 1, curline, 0, 0); |
| 940 | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 2, 6, SNES_BG1, curline, 0, 0); |
| 941 | if (bg_enabled[1]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 1, 0, 4, SNES_BG2, curline, 0, 0); |
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | static void snes_update_mode_6( UINT8 screen, UINT16 curline ) |
| r7312 | r7313 | |
| 947 | 947 | bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; |
| 948 | 948 | |
| 949 | 949 | if (bg_enabled[4]) snes_update_objects(screen, 6, curline); |
| 950 | | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 1, 4, 0, curline, 1, 0); |
| 950 | if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 1, 4, SNES_BG1, curline, 1, 0); |
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | static void snes_update_mode_7( UINT8 screen, UINT16 curline ) |
| r7312 | r7313 | |
| 958 | 958 | if (!snes_ppu.mode7.extbg) |
| 959 | 959 | { |
| 960 | 960 | if (bg_enabled[4]) snes_update_objects(screen, 7, curline); |
| 961 | | if (bg_enabled[0]) snes_update_line_mode7(screen, 1, 1, 0, curline); |
| 961 | if (bg_enabled[0]) snes_update_line_mode7(screen, 1, 1, SNES_BG1, curline); |
| 962 | 962 | } |
| 963 | 963 | else |
| 964 | 964 | { |
| 965 | 965 | if (bg_enabled[4]) snes_update_objects(screen, 8, curline); |
| 966 | | if (bg_enabled[0]) snes_update_line_mode7(screen, 2, 2, 0, curline); |
| 967 | | if (bg_enabled[1]) snes_update_line_mode7(screen, 0, 4, 1, curline); |
| 966 | if (bg_enabled[0]) snes_update_line_mode7(screen, 2, 2, SNES_BG1, curline); |
| 967 | if (bg_enabled[1]) snes_update_line_mode7(screen, 0, 4, SNES_BG2, curline); |
| 968 | 968 | } |
| 969 | 969 | } |
| 970 | 970 | |
| r7312 | r7313 | |
| 1189 | 1189 | /* Draw SNES_SUBSCREEN */ |
| 1190 | 1190 | snes_draw_screen(SNES_SUBSCREEN, curline); |
| 1191 | 1191 | |
| 1192 | | |
| 1193 | 1192 | /* Draw SNES_MAINSCREEN */ |
| 1194 | 1193 | snes_draw_screen(SNES_MAINSCREEN, curline); |
| 1195 | 1194 | |
| 1196 | | #ifdef MAME_DEBUG |
| 1195 | #ifdef SNES_LAYER_DEBUG |
| 1197 | 1196 | if (snes_dbg_video(machine, bitmap, curline)) |
| 1198 | 1197 | { |
| 1199 | 1198 | profiler_mark_end(); |
| r7312 | r7313 | |
| 1204 | 1203 | if (debug_options.draw_subscreen) |
| 1205 | 1204 | scanline = &scanlines[SNES_SUBSCREEN]; |
| 1206 | 1205 | else |
| 1207 | | #endif /* MAME_DEBUG */ |
| 1206 | #endif /* SNES_LAYER_DEBUG */ |
| 1208 | 1207 | scanline = &scanlines[SNES_MAINSCREEN]; |
| 1209 | 1208 | |
| 1210 | 1209 | /* Phew! Draw the line to screen */ |
| r7312 | r7313 | |
| 1212 | 1211 | |
| 1213 | 1212 | for (x = 0; x < SNES_SCR_WIDTH * 2; x++) |
| 1214 | 1213 | { |
| 1214 | int r, g, b; |
| 1215 | 1215 | c = scanline->buffer[x]; |
| 1216 | |
| 1216 | 1217 | /* perform color math if the layer wants it (except if it's an object > 192) */ |
| 1217 | 1218 | if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && |
| 1218 | 1219 | ((scanlines[SNES_MAINSCREEN].layer[x] != SNES_COLOR && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math) |
| 1219 | 1220 | || (scanlines[SNES_MAINSCREEN].layer[x] == SNES_COLOR && snes_ppu.colour.color_math))) |
| 1220 | 1221 | snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); |
| 1221 | 1222 | |
| 1222 | | int r = ((c & 0x1f) * fade) >> 4; |
| 1223 | | int g = (((c & 0x3e0) >> 5) * fade) >> 4; |
| 1224 | | int b = (((c & 0x7c00) >> 10) * fade) >> 4; |
| 1223 | r = ((c & 0x1f) * fade) >> 4; |
| 1224 | g = (((c & 0x3e0) >> 5) * fade) >> 4; |
| 1225 | b = (((c & 0x7c00) >> 10) * fade) >> 4; |
| 1225 | 1226 | |
| 1226 | 1227 | if (snes_htmult == 1) |
| 1227 | 1228 | { |
| 1228 | | *BITMAP_ADDR32(bitmap, curline, x*2+0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1229 | | *BITMAP_ADDR32(bitmap, curline, x*2+1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1229 | *BITMAP_ADDR32(bitmap, curline, x * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1230 | *BITMAP_ADDR32(bitmap, curline, x * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1230 | 1231 | } |
| 1231 | 1232 | else |
| 1232 | 1233 | *BITMAP_ADDR32(bitmap, curline, x) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| r7312 | r7313 | |
| 1238 | 1239 | |
| 1239 | 1240 | VIDEO_START( snes ) |
| 1240 | 1241 | { |
| 1241 | | #ifdef MAME_DEBUG |
| 1242 | #ifdef SNES_LAYER_DEBUG |
| 1242 | 1243 | memset(&debug_options, 0, sizeof(debug_options)); |
| 1243 | 1244 | debug_options.input_count = 5; |
| 1244 | 1245 | #endif |
| r7312 | r7313 | |
| 1250 | 1251 | |
| 1251 | 1252 | /*NTSC SNES draw range is 1-225. */ |
| 1252 | 1253 | for (y = cliprect->min_y; y <= cliprect->max_y; y++) |
| 1253 | | snes_refresh_scanline(screen->machine, bitmap, y+1); |
| 1254 | snes_refresh_scanline(screen->machine, bitmap, y + 1); |
| 1254 | 1255 | return 0; |
| 1255 | 1256 | } |
| 1256 | 1257 | |
| 1257 | 1258 | |
| 1258 | 1259 | /***** Debug Functions *****/ |
| 1259 | 1260 | |
| 1260 | | #ifdef MAME_DEBUG |
| 1261 | #ifdef SNES_LAYER_DEBUG |
| 1261 | 1262 | |
| 1262 | 1263 | static UINT8 snes_dbg_video( running_machine *machine, bitmap_t *bitmap, UINT16 curline ) |
| 1263 | 1264 | { |
| 1264 | 1265 | /* Check if the user has enabled or disabled stuff */ |
| 1265 | | if (curline == 0) |
| 1266 | if (curline == 1) |
| 1266 | 1267 | { |
| 1267 | 1268 | //UINT16 y = 1; |
| 1268 | 1269 | static const char WINLOGIC[4] = { '|', '&', '^', '!' }; |
| r7312 | r7313 | |
| 1415 | 1416 | return 0; |
| 1416 | 1417 | } |
| 1417 | 1418 | |
| 1418 | | #endif /* MAME_DEBUG */ |
| 1419 | #endif /* SNES_LAYER_DEBUG */ |