src/mame/machine/snes.c
| r7315 | r7316 | |
| 1158 | 1158 | snes_ppu.layer[SNES_OAM].window1_enabled = data & 0x02; |
| 1159 | 1159 | snes_ppu.layer[SNES_OAM].window2_invert = data & 0x04; |
| 1160 | 1160 | snes_ppu.layer[SNES_OAM].window2_enabled = data & 0x08; |
| 1161 | | snes_ppu.colour.window1_invert = data & 0x10; |
| 1162 | | snes_ppu.colour.window1_enabled = data & 0x20; |
| 1163 | | snes_ppu.colour.window2_invert = data & 0x40; |
| 1164 | | snes_ppu.colour.window2_enabled = data & 0x80; |
| 1161 | snes_ppu.layer[SNES_COLOR].window1_invert = data & 0x10; |
| 1162 | snes_ppu.layer[SNES_COLOR].window1_enabled = data & 0x20; |
| 1163 | snes_ppu.layer[SNES_COLOR].window2_invert = data & 0x40; |
| 1164 | snes_ppu.layer[SNES_COLOR].window2_enabled = data & 0x80; |
| 1165 | 1165 | snes_ppu.update_windows = 1; |
| 1166 | 1166 | } |
| 1167 | 1167 | break; |
| r7315 | r7316 | |
| 1207 | 1207 | if (data != snes_ram[offset]) |
| 1208 | 1208 | { |
| 1209 | 1209 | snes_ppu.layer[SNES_OAM].wlog_mask = data & 0x03; |
| 1210 | | snes_ppu.colour.wlog_mask = (data & 0x0c) >> 2; |
| 1210 | snes_ppu.layer[SNES_COLOR].wlog_mask = (data & 0x0c) >> 2; |
| 1211 | 1211 | snes_ppu.update_windows = 1; |
| 1212 | 1212 | } |
| 1213 | 1213 | break; |
| r7315 | r7316 | |
| 1257 | 1257 | snes_ppu.layer[SNES_BG3].color_math = data & 0x04; |
| 1258 | 1258 | snes_ppu.layer[SNES_BG4].color_math = data & 0x08; |
| 1259 | 1259 | snes_ppu.layer[SNES_OAM].color_math = data & 0x10; |
| 1260 | | snes_ppu.colour.color_math = data & 0x20; |
| 1260 | snes_ppu.layer[SNES_COLOR].color_math = data & 0x20; |
| 1261 | 1261 | break; |
| 1262 | 1262 | case COLDATA: /* Fixed colour data for fixed colour addition/subtraction */ |
| 1263 | 1263 | { |
| r7315 | r7316 | |
| 2019 | 2019 | int i, j; |
| 2020 | 2020 | |
| 2021 | 2021 | /* Init VRAM */ |
| 2022 | | memset( snes_vram, 0, SNES_VRAM_SIZE ); |
| 2022 | memset(snes_vram, 0, SNES_VRAM_SIZE ); |
| 2023 | 2023 | |
| 2024 | 2024 | /* Init Colour RAM */ |
| 2025 | | memset( (UINT8 *)snes_cgram, 0, SNES_CGRAM_SIZE); |
| 2025 | memset((UINT8 *)snes_cgram, 0, SNES_CGRAM_SIZE); |
| 2026 | 2026 | |
| 2027 | 2027 | /* Init oam RAM */ |
| 2028 | | memset( snes_oam, 0xff, SNES_OAM_SIZE ); |
| 2028 | memset(snes_oam, 0xff, SNES_OAM_SIZE ); |
| 2029 | 2029 | |
| 2030 | 2030 | /* Init work RAM - 0x55 isn't exactly right but it's close */ |
| 2031 | 2031 | /* make sure it happens to the 65816 (CPU 0) */ |
src/mame/video/snes.c
| r7315 | r7316 | |
| 136 | 136 | * Routine for additive/subtractive blending |
| 137 | 137 | * between the main and sub screens. |
| 138 | 138 | *****************************************/ |
| 139 | | INLINE void snes_draw_blend(UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip ) |
| 139 | INLINE void snes_draw_blend(UINT16 offset, UINT16 *colour, UINT8 factor, UINT8 clip, UINT8 black_pen_clip ) |
| 140 | 140 | { |
| 141 | 141 | if ((black_pen_clip == SNES_CLIP_ALL2) || |
| 142 | | (black_pen_clip == SNES_CLIP_IN && snes_ppu.clipmasks[SNES_COLOR][offset]) || |
| 143 | | (black_pen_clip == SNES_CLIP_OUT && !snes_ppu.clipmasks[SNES_COLOR][offset])) |
| 142 | (black_pen_clip == SNES_CLIP_IN && snes_ppu.clipmasks[SNES_COLOR][offset / factor]) || |
| 143 | (black_pen_clip == SNES_CLIP_OUT && !snes_ppu.clipmasks[SNES_COLOR][offset / factor])) |
| 144 | 144 | *colour = 0; //clip to black before color math |
| 145 | 145 | |
| 146 | 146 | if (clip == SNES_CLIP_ALL2) // blending mode 3 == always OFF |
| r7315 | r7316 | |
| 150 | 150 | if (!debug_options.transparency_disabled) |
| 151 | 151 | #endif /* SNES_LAYER_DEBUG */ |
| 152 | 152 | if ((clip == SNES_CLIP_ALL) || |
| 153 | | (clip == SNES_CLIP_IN && !snes_ppu.clipmasks[SNES_COLOR][offset]) || |
| 154 | | (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset])) |
| 153 | (clip == SNES_CLIP_IN && !snes_ppu.clipmasks[SNES_COLOR][offset / factor]) || |
| 154 | (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset / factor])) |
| 155 | 155 | { |
| 156 | 156 | UINT16 r, g, b; |
| 157 | 157 | int clip_max = 0; // if add then clip to 0x1f, if sub then clip to 0 |
| r7315 | r7316 | |
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | INLINE void snes_draw_blend_lores(UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip ) |
| 227 | { |
| 228 | snes_draw_blend(offset, colour, 1, clip, black_pen_clip); |
| 229 | } |
| 226 | 230 | |
| 231 | INLINE void snes_draw_blend_hires(UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip ) |
| 232 | { |
| 233 | snes_draw_blend(offset, colour, 2, clip, black_pen_clip); |
| 234 | } |
| 235 | |
| 227 | 236 | /***************************************** |
| 228 | 237 | * snes_draw_tile() |
| 229 | 238 | * |
| r7315 | r7316 | |
| 1009 | 1018 | |
| 1010 | 1019 | for (ii = 0; ii < SNES_SCR_WIDTH + 8; ii++) |
| 1011 | 1020 | { |
| 1012 | | /* update bg 1, 2, 3, 4 & obj */ |
| 1021 | /* update bg 1, 2, 3, 4, obj & color windows */ |
| 1013 | 1022 | /* jj = layer */ |
| 1014 | | for (jj = 0; jj < 5; jj++) |
| 1023 | for (jj = 0; jj < 6; jj++) |
| 1015 | 1024 | { |
| 1016 | | snes_ppu.clipmasks[jj][ii] = 0xff; |
| 1025 | snes_ppu.clipmasks[jj][ii] = 0xff; /* let's start from un-masked */ |
| 1017 | 1026 | w1 = w2 = -1; |
| 1027 | |
| 1018 | 1028 | if (snes_ppu.layer[jj].window1_enabled) |
| 1019 | 1029 | { |
| 1030 | /* Default to mask area inside */ |
| 1020 | 1031 | if ((ii < snes_ppu.window1_left) || (ii > snes_ppu.window1_right)) |
| 1021 | 1032 | w1 = 0; |
| 1022 | 1033 | else |
| 1023 | 1034 | w1 = 1; |
| 1035 | |
| 1036 | /* If mask area is outside then swap */ |
| 1024 | 1037 | if (snes_ppu.layer[jj].window1_invert) |
| 1025 | 1038 | w1 = !w1; |
| 1026 | 1039 | } |
| 1040 | |
| 1027 | 1041 | if (snes_ppu.layer[jj].window2_enabled) |
| 1028 | 1042 | { |
| 1029 | 1043 | if ((ii < snes_ppu.window2_left) || (ii > snes_ppu.window2_right)) |
| r7315 | r7316 | |
| 1033 | 1047 | if (snes_ppu.layer[jj].window2_invert) |
| 1034 | 1048 | w2 = !w2; |
| 1035 | 1049 | } |
| 1050 | |
| 1051 | /* mask if the appropriate expression is true */ |
| 1036 | 1052 | if (w1 >= 0 && w2 >= 0) |
| 1037 | 1053 | { |
| 1038 | 1054 | switch (snes_ppu.layer[jj].wlog_mask) |
| r7315 | r7316 | |
| 1056 | 1072 | else if (w2 >= 0) |
| 1057 | 1073 | snes_ppu.clipmasks[jj][ii] = w2 ? 0x00 : 0xff; |
| 1058 | 1074 | } |
| 1059 | | |
| 1060 | | /* update colour window */ |
| 1061 | | snes_ppu.clipmasks[SNES_COLOR][ii] = 0xff; |
| 1062 | | w1 = w2 = -1; |
| 1063 | | if (snes_ppu.colour.window1_enabled) |
| 1064 | | { |
| 1065 | | /* Default to mask area inside */ |
| 1066 | | if ((ii < snes_ppu.window1_left) || (ii > snes_ppu.window1_right)) |
| 1067 | | w1 = 0; |
| 1068 | | else |
| 1069 | | w1 = 1; |
| 1070 | | /* If mask area is outside then swap */ |
| 1071 | | if (snes_ppu.colour.window1_invert) |
| 1072 | | w1 = !w1; |
| 1073 | | } |
| 1074 | | if (snes_ppu.colour.window2_enabled) |
| 1075 | | { |
| 1076 | | if ((ii < snes_ppu.window2_left) || (ii > snes_ppu.window2_right)) |
| 1077 | | w2 = 0; |
| 1078 | | else |
| 1079 | | w2 = 1; |
| 1080 | | if (snes_ppu.colour.window2_invert) |
| 1081 | | w2 = !w2; |
| 1082 | | } |
| 1083 | | if (w1 >= 0 && w2 >= 0) |
| 1084 | | { |
| 1085 | | switch (snes_ppu.colour.wlog_mask) |
| 1086 | | { |
| 1087 | | case 0x0: /* OR */ |
| 1088 | | snes_ppu.clipmasks[SNES_COLOR][ii] = w1 | w2 ? 0x00 : 0xff; |
| 1089 | | break; |
| 1090 | | case 0x4: /* AND */ |
| 1091 | | snes_ppu.clipmasks[SNES_COLOR][ii] = w1 & w2 ? 0x00 : 0xff; |
| 1092 | | break; |
| 1093 | | case 0x8: /* XOR */ |
| 1094 | | snes_ppu.clipmasks[SNES_COLOR][ii] = w1 ^ w2 ? 0x00 : 0xff; |
| 1095 | | break; |
| 1096 | | case 0xc: /* XNOR */ |
| 1097 | | snes_ppu.clipmasks[SNES_COLOR][ii] = !(w1 ^ w2) ? 0x00 : 0xff; |
| 1098 | | break; |
| 1099 | | } |
| 1100 | | } |
| 1101 | | else if (w1 >= 0) |
| 1102 | | snes_ppu.clipmasks[SNES_COLOR][ii] = w1 ? 0x00 : 0xff; |
| 1103 | | else if (w2 >= 0) |
| 1104 | | snes_ppu.clipmasks[SNES_COLOR][ii] = w2 ? 0x00 : 0xff; |
| 1105 | 1075 | } |
| 1106 | 1076 | } |
| 1107 | 1077 | |
| r7315 | r7316 | |
| 1209 | 1179 | /* Phew! Draw the line to screen */ |
| 1210 | 1180 | fade = snes_ppu.screen_brightness; |
| 1211 | 1181 | |
| 1212 | | for (x = 0; x < SNES_SCR_WIDTH * 2; x++) |
| 1182 | for (x = 0; x < SNES_SCR_WIDTH * 2; x += 2) |
| 1213 | 1183 | { |
| 1214 | | int r, g, b; |
| 1215 | | c = scanline->buffer[x]; |
| 1184 | if (snes_ppu.mode != 5 && snes_ppu.mode != 6) |
| 1185 | { |
| 1186 | int r, g, b; |
| 1187 | c = scanline->buffer[x]; |
| 1216 | 1188 | |
| 1217 | | /* perform color math if the layer wants it (except if it's an object > 192) */ |
| 1218 | | if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && |
| 1219 | | ((scanlines[SNES_MAINSCREEN].layer[x] != SNES_COLOR && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math) |
| 1220 | | || (scanlines[SNES_MAINSCREEN].layer[x] == SNES_COLOR && snes_ppu.colour.color_math))) |
| 1221 | | snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); |
| 1189 | /* perform color math if the layer wants it (except if it's an object > 192) */ |
| 1190 | if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math) |
| 1191 | snes_draw_blend_lores(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); |
| 1222 | 1192 | |
| 1223 | | r = ((c & 0x1f) * fade) >> 4; |
| 1224 | | g = (((c & 0x3e0) >> 5) * fade) >> 4; |
| 1225 | | b = (((c & 0x7c00) >> 10) * fade) >> 4; |
| 1193 | r = ((c & 0x1f) * fade) >> 4; |
| 1194 | g = (((c & 0x3e0) >> 5) * fade) >> 4; |
| 1195 | b = (((c & 0x7c00) >> 10) * fade) >> 4; |
| 1226 | 1196 | |
| 1227 | | if (snes_htmult == 1) |
| 1228 | | { |
| 1229 | 1197 | *BITMAP_ADDR32(bitmap, curline, x * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1230 | 1198 | *BITMAP_ADDR32(bitmap, curline, x * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1199 | |
| 1200 | c = scanline->buffer[x + 1]; |
| 1201 | |
| 1202 | /* perform color math if the layer wants it (except if it's an object > 192) */ |
| 1203 | if (!scanlines[SNES_MAINSCREEN].blend_exception[x + 1] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x + 1]].color_math) |
| 1204 | snes_draw_blend_lores(x + 1, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); |
| 1205 | |
| 1206 | r = ((c & 0x1f) * fade) >> 4; |
| 1207 | g = (((c & 0x3e0) >> 5) * fade) >> 4; |
| 1208 | b = (((c & 0x7c00) >> 10) * fade) >> 4; |
| 1209 | |
| 1210 | *BITMAP_ADDR32(bitmap, curline, (x + 1) * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1211 | *BITMAP_ADDR32(bitmap, curline, (x + 1) * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1212 | |
| 1231 | 1213 | } |
| 1232 | 1214 | else |
| 1215 | { |
| 1216 | int r, g, b; |
| 1217 | UINT16 temp_col; |
| 1218 | c = scanline->buffer[x]; |
| 1219 | temp_col = scanline->buffer[x]; |
| 1220 | |
| 1221 | /* perform color math if the layer wants it (except if it's an object > 192) */ |
| 1222 | if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math) |
| 1223 | snes_draw_blend_hires(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); |
| 1224 | |
| 1225 | r = ((c & 0x1f) * fade) >> 4; |
| 1226 | g = (((c & 0x3e0) >> 5) * fade) >> 4; |
| 1227 | b = (((c & 0x7c00) >> 10) * fade) >> 4; |
| 1228 | |
| 1233 | 1229 | *BITMAP_ADDR32(bitmap, curline, x) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1230 | |
| 1231 | c = scanlines[SNES_SUBSCREEN].buffer[x]; |
| 1232 | scanlines[SNES_SUBSCREEN].buffer[x] = temp_col; |
| 1233 | |
| 1234 | /* perform color math only if it's been done on the previous pixel */ |
| 1235 | if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math) |
| 1236 | snes_draw_blend_hires(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); |
| 1237 | |
| 1238 | r = ((c & 0x1f) * fade) >> 4; |
| 1239 | g = (((c & 0x3e0) >> 5) * fade) >> 4; |
| 1240 | b = (((c & 0x7c00) >> 10) * fade) >> 4; |
| 1241 | |
| 1242 | *BITMAP_ADDR32(bitmap, curline, x + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b)); |
| 1243 | } |
| 1234 | 1244 | } |
| 1235 | 1245 | } |
| 1236 | 1246 | |