trunk/src/mame/includes/snes.h
r17389 | r17390 | |
494 | 494 | DECLARE_DRIVER_INIT(snes_hirom); |
495 | 495 | DECLARE_DRIVER_INIT(snes_mess); |
496 | 496 | DECLARE_DRIVER_INIT(snesst); |
| 497 | |
| 498 | inline UINT16 snes_get_bgcolor( UINT8 direct_colors, UINT16 palette, UINT8 color ); |
| 499 | inline void snes_set_scanline_pixel( int screen, INT16 x, UINT16 color, UINT8 priority, UINT8 layer, int blend ); |
| 500 | inline void snes_draw_bgtile_lores( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority ); |
| 501 | inline void snes_draw_bgtile_hires( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority ); |
| 502 | inline void snes_draw_oamtile( INT16 ii, UINT8 colour, UINT16 pal, UINT8 priority ); |
| 503 | inline void snes_draw_tile( UINT8 planes, UINT8 layer, UINT32 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires ); |
| 504 | inline UINT32 snes_get_tmap_addr( UINT8 layer, UINT8 tile_size, UINT32 base, UINT32 x, UINT32 y ); |
| 505 | inline void snes_update_line( UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a, UINT8 color_depth, UINT8 hires, UINT8 offset_per_tile, UINT8 direct_colors ); |
| 506 | void snes_update_line_mode7( UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a ); |
| 507 | void snes_update_obsel( void ); |
| 508 | void snes_oam_list_build( void ); |
| 509 | int is_sprite_on_scanline( UINT16 curline, UINT8 sprite ); |
| 510 | void snes_update_objects_rto( UINT16 curline ); |
| 511 | void snes_update_objects( UINT8 priority_oam0, UINT8 priority_oam1, UINT8 priority_oam2, UINT8 priority_oam3 ); |
| 512 | void snes_update_mode_0( UINT16 curline ); |
| 513 | void snes_update_mode_1( UINT16 curline ); |
| 514 | void snes_update_mode_2( UINT16 curline ); |
| 515 | void snes_update_mode_3( UINT16 curline ); |
| 516 | void snes_update_mode_4( UINT16 curline ); |
| 517 | void snes_update_mode_5( UINT16 curline ); |
| 518 | void snes_update_mode_6( UINT16 curline ); |
| 519 | void snes_update_mode_7( UINT16 curline ); |
| 520 | void snes_draw_screens( UINT16 curline ); |
| 521 | void snes_update_windowmasks( void ); |
| 522 | void snes_update_offsets( void ); |
| 523 | inline void snes_draw_blend( UINT16 offset, UINT16 *colour, UINT8 prevent_color_math, UINT8 black_pen_clip, int switch_screens ); |
| 524 | void snes_refresh_scanline( running_machine &machine, bitmap_rgb32 &bitmap, UINT16 curline ); |
| 525 | |
497 | 526 | }; |
498 | 527 | |
499 | 528 | /* Special chips, checked at init and used in memory handlers */ |
trunk/src/mame/video/snes.c
r17389 | r17390 | |
140 | 140 | * Get the proper color (direct or from cgram) |
141 | 141 | *****************************************/ |
142 | 142 | |
143 | | INLINE UINT16 snes_get_bgcolor( UINT8 direct_colors, UINT16 palette, UINT8 color ) |
| 143 | inline UINT16 snes_state::snes_get_bgcolor( UINT8 direct_colors, UINT16 palette, UINT8 color ) |
144 | 144 | { |
145 | 145 | UINT16 c = 0; |
146 | 146 | |
r17389 | r17390 | |
164 | 164 | * proper scanline |
165 | 165 | *****************************************/ |
166 | 166 | |
167 | | INLINE void snes_set_scanline_pixel( int screen, INT16 x, UINT16 color, UINT8 priority, UINT8 layer, int blend ) |
| 167 | inline void snes_state::snes_set_scanline_pixel( int screen, INT16 x, UINT16 color, UINT8 priority, UINT8 layer, int blend ) |
168 | 168 | { |
169 | 169 | scanlines[screen].buffer[x] = color; |
170 | 170 | scanlines[screen].priority[x] = priority; |
r17389 | r17390 | |
195 | 195 | * or lores) |
196 | 196 | *****************************************/ |
197 | 197 | |
198 | | INLINE void snes_draw_bgtile_lores( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority ) |
| 198 | inline void snes_state::snes_draw_bgtile_lores( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority ) |
199 | 199 | { |
200 | 200 | int screen; |
201 | 201 | UINT16 c; |
r17389 | r17390 | |
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | | INLINE void snes_draw_bgtile_hires( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority ) |
| 232 | inline void snes_state::snes_draw_bgtile_hires( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority ) |
233 | 233 | { |
234 | 234 | int screen; |
235 | 235 | UINT16 c; |
r17389 | r17390 | |
264 | 264 | } |
265 | 265 | } |
266 | 266 | |
267 | | INLINE void snes_draw_oamtile( INT16 ii, UINT8 colour, UINT16 pal, UINT8 priority ) |
| 267 | inline void snes_state::snes_draw_oamtile( INT16 ii, UINT8 colour, UINT16 pal, UINT8 priority ) |
268 | 268 | { |
269 | 269 | int screen; |
270 | 270 | int blend; |
r17389 | r17390 | |
307 | 307 | * (depending on layer and resolution) |
308 | 308 | *****************************************/ |
309 | 309 | |
310 | | INLINE void snes_draw_tile( UINT8 planes, UINT8 layer, UINT32 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires ) |
| 310 | inline void snes_state::snes_draw_tile( UINT8 planes, UINT8 layer, UINT32 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires ) |
311 | 311 | { |
312 | 312 | UINT8 plane[8]; |
313 | 313 | INT16 ii, jj; |
r17389 | r17390 | |
390 | 390 | * Find the address in VRAM of the tile (x,y) |
391 | 391 | *********************************************/ |
392 | 392 | |
393 | | INLINE UINT32 snes_get_tmap_addr( UINT8 layer, UINT8 tile_size, UINT32 base, UINT32 x, UINT32 y ) |
| 393 | inline UINT32 snes_state::snes_get_tmap_addr( UINT8 layer, UINT8 tile_size, UINT32 base, UINT32 x, UINT32 y ) |
394 | 394 | { |
395 | 395 | UINT32 res = base; |
396 | 396 | x >>= (3 + tile_size); |
r17389 | r17390 | |
413 | 413 | * Update an entire line of tiles. |
414 | 414 | *********************************************/ |
415 | 415 | |
416 | | INLINE void snes_update_line( UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a, UINT8 color_depth, UINT8 hires, UINT8 offset_per_tile, UINT8 direct_colors ) |
| 416 | inline void snes_state::snes_update_line( UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a, UINT8 color_depth, UINT8 hires, UINT8 offset_per_tile, UINT8 direct_colors ) |
417 | 417 | { |
418 | 418 | UINT32 tmap, tile, xoff, yoff, charaddr, addr; |
419 | 419 | UINT16 ii = 0, vflip, hflip, pal, pal_direct, tilemap; |
r17389 | r17390 | |
598 | 598 | |
599 | 599 | #define MODE7_CLIP(x) (((x) & 0x2000) ? ((x) | ~0x03ff) : ((x) & 0x03ff)) |
600 | 600 | |
601 | | static void snes_update_line_mode7( UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a ) |
| 601 | void snes_state::snes_update_line_mode7( UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a ) |
602 | 602 | { |
603 | 603 | UINT32 tiled; |
604 | 604 | INT16 ma, mb, mc, md; |
r17389 | r17390 | |
823 | 823 | * Update sprite settings for next line. |
824 | 824 | *********************************************/ |
825 | 825 | |
826 | | static void snes_update_obsel( void ) |
| 826 | void snes_state::snes_update_obsel( void ) |
827 | 827 | { |
828 | 828 | snes_ppu.layer[SNES_OAM].charmap = snes_ppu.oam.next_charmap; |
829 | 829 | snes_ppu.oam.name_select = snes_ppu.oam.next_name_select; |
r17389 | r17390 | |
841 | 841 | * Build a list of the available obj in OAM ram. |
842 | 842 | *********************************************/ |
843 | 843 | |
844 | | static void snes_oam_list_build( void ) |
| 844 | void snes_state::snes_oam_list_build( void ) |
845 | 845 | { |
846 | 846 | UINT8 *oamram = (UINT8 *)snes_oam; |
847 | 847 | INT16 oam = 0x1ff; |
r17389 | r17390 | |
928 | 928 | * scanline |
929 | 929 | *********************************************/ |
930 | 930 | |
931 | | static int is_sprite_on_scanline( UINT16 curline, UINT8 sprite ) |
| 931 | int snes_state::is_sprite_on_scanline( UINT16 curline, UINT8 sprite ) |
932 | 932 | { |
933 | 933 | //if sprite is entirely offscreen and doesn't wrap around to the left side of the screen, |
934 | 934 | //then it is not counted. this *should* be 256, and not 255, even though dot 256 is offscreen. |
r17389 | r17390 | |
953 | 953 | * scanline. |
954 | 954 | *********************************************/ |
955 | 955 | |
956 | | static void snes_update_objects_rto( UINT16 curline ) |
| 956 | void snes_state::snes_update_objects_rto( UINT16 curline ) |
957 | 957 | { |
958 | 958 | int ii, jj, active_sprite; |
959 | 959 | UINT8 range_over, time_over; |
r17389 | r17390 | |
1067 | 1067 | * Update an entire line of sprites. |
1068 | 1068 | *********************************************/ |
1069 | 1069 | |
1070 | | static void snes_update_objects( UINT8 priority_oam0, UINT8 priority_oam1, UINT8 priority_oam2, UINT8 priority_oam3 ) |
| 1070 | void snes_state::snes_update_objects( UINT8 priority_oam0, UINT8 priority_oam1, UINT8 priority_oam2, UINT8 priority_oam3 ) |
1071 | 1071 | { |
1072 | 1072 | UINT8 pri, priority[4]; |
1073 | 1073 | UINT32 charaddr; |
r17389 | r17390 | |
1128 | 1128 | * Update Mode X line. |
1129 | 1129 | *********************************************/ |
1130 | 1130 | |
1131 | | static void snes_update_mode_0( UINT16 curline ) |
| 1131 | void snes_state::snes_update_mode_0( UINT16 curline ) |
1132 | 1132 | { |
1133 | 1133 | #if SNES_LAYER_DEBUG |
1134 | 1134 | if (debug_options.mode_disabled[0]) |
r17389 | r17390 | |
1142 | 1142 | snes_update_line(curline, SNES_BG4, 1, 4, SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0); |
1143 | 1143 | } |
1144 | 1144 | |
1145 | | static void snes_update_mode_1( UINT16 curline ) |
| 1145 | void snes_state::snes_update_mode_1( UINT16 curline ) |
1146 | 1146 | { |
1147 | 1147 | #if SNES_LAYER_DEBUG |
1148 | 1148 | if (debug_options.mode_disabled[1]) |
r17389 | r17390 | |
1165 | 1165 | } |
1166 | 1166 | } |
1167 | 1167 | |
1168 | | static void snes_update_mode_2( UINT16 curline ) |
| 1168 | void snes_state::snes_update_mode_2( UINT16 curline ) |
1169 | 1169 | { |
1170 | 1170 | #if SNES_LAYER_DEBUG |
1171 | 1171 | if (debug_options.mode_disabled[2]) |
r17389 | r17390 | |
1177 | 1177 | snes_update_line(curline, SNES_BG2, 1, 5, SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_MODE2, 0); |
1178 | 1178 | } |
1179 | 1179 | |
1180 | | static void snes_update_mode_3( UINT16 curline ) |
| 1180 | void snes_state::snes_update_mode_3( UINT16 curline ) |
1181 | 1181 | { |
1182 | 1182 | #if SNES_LAYER_DEBUG |
1183 | 1183 | if (debug_options.mode_disabled[3]) |
r17389 | r17390 | |
1189 | 1189 | snes_update_line(curline, SNES_BG2, 1, 5, SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_NONE, 0); |
1190 | 1190 | } |
1191 | 1191 | |
1192 | | static void snes_update_mode_4( UINT16 curline ) |
| 1192 | void snes_state::snes_update_mode_4( UINT16 curline ) |
1193 | 1193 | { |
1194 | 1194 | #if SNES_LAYER_DEBUG |
1195 | 1195 | if (debug_options.mode_disabled[4]) |
r17389 | r17390 | |
1201 | 1201 | snes_update_line(curline, SNES_BG2, 1, 5, SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_MODE4, 0); |
1202 | 1202 | } |
1203 | 1203 | |
1204 | | static void snes_update_mode_5( UINT16 curline ) |
| 1204 | void snes_state::snes_update_mode_5( UINT16 curline ) |
1205 | 1205 | { |
1206 | 1206 | #if SNES_LAYER_DEBUG |
1207 | 1207 | if (debug_options.mode_disabled[5]) |
r17389 | r17390 | |
1213 | 1213 | snes_update_line(curline, SNES_BG2, 1, 5, SNES_COLOR_DEPTH_2BPP, 1, SNES_OPT_NONE, 0); |
1214 | 1214 | } |
1215 | 1215 | |
1216 | | static void snes_update_mode_6( UINT16 curline ) |
| 1216 | void snes_state::snes_update_mode_6( UINT16 curline ) |
1217 | 1217 | { |
1218 | 1218 | #if SNES_LAYER_DEBUG |
1219 | 1219 | if (debug_options.mode_disabled[6]) |
r17389 | r17390 | |
1224 | 1224 | snes_update_line(curline, SNES_BG1, 2, 5, SNES_COLOR_DEPTH_4BPP, 1, SNES_OPT_MODE6, 0); |
1225 | 1225 | } |
1226 | 1226 | |
1227 | | static void snes_update_mode_7( UINT16 curline ) |
| 1227 | void snes_state::snes_update_mode_7( UINT16 curline ) |
1228 | 1228 | { |
1229 | 1229 | #if SNES_LAYER_DEBUG |
1230 | 1230 | if (debug_options.mode_disabled[7]) |
r17389 | r17390 | |
1250 | 1250 | * Draw the whole screen (Mode 0 -> 7). |
1251 | 1251 | *********************************************/ |
1252 | 1252 | |
1253 | | static void snes_draw_screens( UINT16 curline ) |
| 1253 | void snes_state::snes_draw_screens( UINT16 curline ) |
1254 | 1254 | { |
1255 | 1255 | switch (snes_ppu.mode) |
1256 | 1256 | { |
r17389 | r17390 | |
1278 | 1278 | * XNOR: ###...##...### ...###..###... |
1279 | 1279 | *********************************************/ |
1280 | 1280 | |
1281 | | static void snes_update_windowmasks( void ) |
| 1281 | void snes_state::snes_update_windowmasks( void ) |
1282 | 1282 | { |
1283 | 1283 | UINT16 ii, jj; |
1284 | 1284 | INT8 w1, w2; |
r17389 | r17390 | |
1352 | 1352 | * possibly be handy for some minor optimization |
1353 | 1353 | *********************************************/ |
1354 | 1354 | |
1355 | | static void snes_update_offsets( void ) |
| 1355 | void snes_state::snes_update_offsets( void ) |
1356 | 1356 | { |
1357 | 1357 | int ii; |
1358 | 1358 | for (ii = 0; ii < 4; ii++) |
r17389 | r17390 | |
1369 | 1369 | * color math. |
1370 | 1370 | *****************************************/ |
1371 | 1371 | |
1372 | | INLINE void snes_draw_blend( UINT16 offset, UINT16 *colour, UINT8 prevent_color_math, UINT8 black_pen_clip, int switch_screens ) |
| 1372 | inline void snes_state::snes_draw_blend( UINT16 offset, UINT16 *colour, UINT8 prevent_color_math, UINT8 black_pen_clip, int switch_screens ) |
1373 | 1373 | { |
1374 | 1374 | #if SNES_LAYER_DEBUG |
1375 | 1375 | if (debug_options.colormath_disabled) |
r17389 | r17390 | |
1497 | 1497 | * the optimized averaging algorithm. |
1498 | 1498 | *********************************************/ |
1499 | 1499 | |
1500 | | static void snes_refresh_scanline( running_machine &machine, bitmap_rgb32 &bitmap, UINT16 curline ) |
| 1500 | void snes_state::snes_refresh_scanline( running_machine &machine, bitmap_rgb32 &bitmap, UINT16 curline ) |
1501 | 1501 | { |
1502 | 1502 | UINT16 ii; |
1503 | 1503 | int x; |
r17389 | r17390 | |
1790 | 1790 | |
1791 | 1791 | SCREEN_UPDATE_RGB32( snes ) |
1792 | 1792 | { |
| 1793 | snes_state *state = screen.machine().driver_data<snes_state>(); |
1793 | 1794 | int y; |
1794 | 1795 | |
1795 | 1796 | /*NTSC SNES draw range is 1-225. */ |
1796 | 1797 | for (y = cliprect.min_y; y <= cliprect.max_y; y++) |
1797 | 1798 | { |
1798 | | snes_refresh_scanline(screen.machine(), bitmap, y + 1); |
| 1799 | state->snes_refresh_scanline(screen.machine(), bitmap, y + 1); |
1799 | 1800 | } |
1800 | 1801 | return 0; |
1801 | 1802 | } |
r17389 | r17390 | |
1866 | 1867 | when interlace is active. |
1867 | 1868 | *************************************************/ |
1868 | 1869 | |
1869 | | INLINE UINT32 snes_get_vram_address( running_machine &machine ) |
| 1870 | inline UINT32 snes_get_vram_address( running_machine &machine ) |
1870 | 1871 | { |
1871 | 1872 | snes_state *state = machine.driver_data<snes_state>(); |
1872 | 1873 | UINT32 addr = state->m_vmadd; |
r17389 | r17390 | |
1991 | 1992 | offset = 0x010c; |
1992 | 1993 | } |
1993 | 1994 | |
1994 | | return (snes_oam[offset] >> (snes_ram[OAMDATA] << 3)) & 0xff;; |
| 1995 | return (snes_oam[offset] >> (snes_ram[OAMDATA] << 3)) & 0xff; |
1995 | 1996 | } |
1996 | 1997 | |
1997 | 1998 | static WRITE8_HANDLER( snes_oam_write ) |