Previous 15994 Revisions Next

r5394 Monday 10th August, 2009 at 09:53:00 UTC by Fabio Priuli
[SNES] simplified window masking code and moved some more regs to PPU struct
[src/mame/includes]snes.h
[src/mame/machine]snes.c
[src/mame/video]snes.c

src/mame/machine/snes.c
r5393r5394
497497            return snes_ppu.ppu2_open_bus;
498498      case OPHCT:      /* Horizontal counter data by ext/soft latch */
499499         {
500            /* FIXME: need to handle STAT78 reset */
501            if( read_ophct )
500            if (read_ophct)
502501            {
503502               snes_ppu.ppu2_open_bus &= 0xfe;
504503               snes_ppu.ppu2_open_bus |= (snes_ppu.beam.latch_horz >> 8) & 0x01;
r5393r5394
512511         }
513512      case OPVCT:      /* Vertical counter data by ext/soft latch */
514513         {
515            /* FIXME: need to handle STAT78 reset */
516            if( read_opvct )
514            if (read_opvct)
517515            {
518516               snes_ppu.ppu2_open_bus &= 0xfe;
519517               snes_ppu.ppu2_open_bus |= (snes_ppu.beam.latch_vert >> 8) & 0x01;
r5393r5394
529527         value = snes_ram[offset] & 0xc0; // 0x80 & 0x40 are Time Over / Range Over Sprite flags, set by the video code
530528         // 0x20 - Master/slave mode select. Little is known about this bit. We always seem to read back 0 here.
531529         value |= (snes_ppu.ppu1_open_bus & 0x10);
530         value |= (snes_ppu.ppu1_version & 0x0f);
532531         snes_ram[offset] = value;   // not sure if this is needed...
533532         snes_ppu.ppu1_open_bus = value;
534533         return snes_ppu.ppu1_open_bus;
535534      case STAT78:   /* PPU status flag and version number */
536         /* FIXME: need to reset OPHCT and OPVCT */
535         read_ophct = 0;
536         read_opvct = 0;
537537         value = snes_ram[offset];
538538         value &= ~0x40;   // clear 'latched counters' flag
539539         value |= (snes_ppu.ppu1_open_bus & 0x20);
540         value |= (snes_ppu.ppu2_version & 0x0f);
540541         snes_ram[offset] = value;   // not sure if this is needed...
541542         snes_ppu.ppu2_open_bus = value;
542543         return snes_ppu.ppu2_open_bus;
r5393r5394
989990         cgram_address = (cgram_address + 1) % (SNES_CGRAM_SIZE - 2);
990991         break;
991992      case W12SEL:   /* Window mask settings for BG1-2 */
993         if (data != snes_ram[offset])
994         {
995            snes_ppu.layer[0].window1_invert = data & 0x01;
996            snes_ppu.layer[0].window1_enabled = data & 0x02;
997            snes_ppu.layer[0].window2_invert = data & 0x04;
998            snes_ppu.layer[0].window2_enabled = data & 0x08;
999            snes_ppu.layer[1].window1_invert = data & 0x10;
1000            snes_ppu.layer[1].window1_enabled = data & 0x20;
1001            snes_ppu.layer[1].window2_invert = data & 0x40;
1002            snes_ppu.layer[1].window2_enabled = data & 0x80;
1003            snes_ppu.update_windows = 1;
1004         }
1005         break;
9921006      case W34SEL:   /* Window mask settings for BG3-4 */
1007         if (data != snes_ram[offset])
1008         {
1009            snes_ppu.layer[2].window1_invert = data & 0x01;
1010            snes_ppu.layer[2].window1_enabled = data & 0x02;
1011            snes_ppu.layer[2].window2_invert = data & 0x04;
1012            snes_ppu.layer[2].window2_enabled = data & 0x08;
1013            snes_ppu.layer[3].window1_invert = data & 0x10;
1014            snes_ppu.layer[3].window1_enabled = data & 0x20;
1015            snes_ppu.layer[3].window2_invert = data & 0x40;
1016            snes_ppu.layer[3].window2_enabled = data & 0x80;
1017            snes_ppu.update_windows = 1;
1018         }
1019         break;
9931020      case WOBJSEL:   /* Window mask settings for objects */
1021         if (data != snes_ram[offset])
1022         {
1023            snes_ppu.layer[4].window1_invert = data & 0x01;
1024            snes_ppu.layer[4].window1_enabled = data & 0x02;
1025            snes_ppu.layer[4].window2_invert = data & 0x04;
1026            snes_ppu.layer[4].window2_enabled = data & 0x08;
1027            snes_ppu.colour.window1_invert = data & 0x10;
1028            snes_ppu.colour.window1_enabled = data & 0x20;
1029            snes_ppu.colour.window2_invert = data & 0x40;
1030            snes_ppu.colour.window2_enabled = data & 0x80;
1031            snes_ppu.update_windows = 1;
1032         }
1033         break;
9941034      case WH0:      /* Window 1 left position */
1035         if (data != snes_ram[offset])
1036         {
1037            snes_ppu.window1_left = data;
1038            snes_ppu.update_windows = 1;
1039         }
1040         break;
9951041      case WH1:      /* Window 1 right position */
1042         if (data != snes_ram[offset])
1043         {
1044            snes_ppu.window1_right = data;
1045            snes_ppu.update_windows = 1;
1046         }
1047         break;
9961048      case WH2:      /* Window 2 left position */
1049         if (data != snes_ram[offset])
1050         {
1051            snes_ppu.window2_left = data;
1052            snes_ppu.update_windows = 1;
1053         }
1054         break;
9971055      case WH3:      /* Window 2 right position */
1056         if (data != snes_ram[offset])
1057         {
1058            snes_ppu.window2_right = data;
1059            snes_ppu.update_windows = 1;
1060         }
1061         break;
9981062      case WBGLOG:   /* Window mask logic for BG's */
1063         if (data != snes_ram[offset])
1064         {
1065            snes_ppu.layer[0].wlog_mask = data & 0x03;
1066            snes_ppu.layer[1].wlog_mask = (data & 0x0c) >> 2;
1067            snes_ppu.layer[2].wlog_mask = (data & 0x30) >> 4;
1068            snes_ppu.layer[3].wlog_mask = (data & 0xc0) >> 6;
1069            snes_ppu.update_windows = 1;
1070         }
1071         break;
9991072      case WOBJLOG:   /* Window mask logic for objects */
1000         if( data != snes_ram[offset] )
1073         if (data != snes_ram[offset])
1074         {
1075            snes_ppu.layer[4].wlog_mask = data & 0x03;
1076            snes_ppu.colour.wlog_mask = (data & 0x0c) >> 2;
10011077            snes_ppu.update_windows = 1;
1078         }
10021079         break;
10031080      case TM:      /* Main screen designation */
10041081         snes_ppu.main_bg_enabled[0] = data & 0x01;
r5393r5394
16691746   snes_ppu.beam.current_horz = 0;
16701747   snes_ppu.beam.last_visible_line = 240;
16711748   snes_ppu.mode = 0;
1749   snes_ppu.ppu1_version = 1;   // 5C77 chip version number, read by STAT77, only '1' is known
1750   snes_ppu.ppu2_version = 3;   // 5C78 chip version number, read by STAT78, only '2' & '3' encountered so far.
16721751   cgram_address = 0;
16731752   vram_read_offset = 2;
16741753   joy1l = joy1h = joy2l = joy2h = joy3l = joy3h = 0;
src/mame/includes/snes.h
r5393r5394
425425      UINT8 mosaic_enabled;   // actually used only for layers 0->3!
426426      UINT8 main_window_enabled;
427427      UINT8 sub_window_enabled;
428      UINT8 window1_enabled, window1_invert;
429      UINT8 window2_enabled, window2_invert;
430      UINT8 wlog_mask;
428431      struct
429432      {
430433         UINT16 horizontal;
r5393r5394
434437         UINT16 tile_vert;
435438         UINT16 shift_vert;
436439      } offset;
437   } layer[5];
440   } layer[5];   // this is for the BG1 - BG2 - BG3 - BG4 - OBJ layers
438441   struct
439442   {
443      UINT8 window1_enabled, window1_invert;
444      UINT8 window2_enabled, window2_invert;
445      UINT8 wlog_mask;
446   } colour;   // this is for the color (which is 'seen' as a layer by the window masking code)
447   struct
448   {
440449      UINT8 address_low;
441450      UINT8 address_high;
442451      UINT8 saved_address_low;
r5393r5394
489498
490499   UINT8 main_bg_enabled[5];   // these would probably better fit the layer struct, but it would make worse the code in snes_update_mode_X()
491500   UINT8 sub_bg_enabled[5];
492   UINT8 ppu1_open_bus;
493   UINT8 ppu2_open_bus;
501   UINT8 ppu1_open_bus, ppu2_open_bus;
502   UINT8 ppu1_version, ppu2_version;
503   UINT8 window1_left, window1_right, window2_left, window2_right;
494504
495505   UINT16 mosaic_table[16][4096];
496506   UINT8 clipmasks[6][SNES_SCR_WIDTH + 8];
src/mame/video/snes.c
r5393r5394
577577   INT16 ma, mb, mc, md;
578578   INT32 xc, yc, tx, ty, sx, sy, hs, vs, xpos, xdir, x0, y0;
579579   UINT8 priority = priority_a;
580   UINT8 colour = 0;
580   UINT8 colour = 0, window_enabled = 0;
581581   UINT16 *mosaic_x, *mosaic_y;
582582
583583#ifdef MAME_DEBUG
r5393r5394
682682         colour &= 0x7f;
683683      }
684684
685      colour &= snes_ppu.clipmasks[layer][xpos];
685      window_enabled = (screen == MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
686      if (window_enabled)
687         colour &= snes_ppu.clipmasks[layer][xpos];
686688
687689      /* Draw pixel if appropriate */
688690      if (scanlines[screen].zbuf[xpos] <= priority && colour > 0)
r5393r5394
980982 *********************************************/
981983static void snes_update_windowmasks(void)
982984{
983   UINT16 ii;
985   UINT16 ii, jj;
984986   INT8 w1, w2;
985987
986988   snes_ppu.update_windows = 0;      /* reset the flag */
987989
988   for( ii = 0; ii < SNES_SCR_WIDTH; ii++ )
990   for (ii = 0; ii < SNES_SCR_WIDTH; ii++)
989991   {
990      /* update bg 1 */
991      snes_ppu.clipmasks[0][ii] = 0xff;
992      w1 = w2 = -1;
993      if( snes_ram[W12SEL] & 0x2 )
992      /* update bg 1, 2, 3, 4 & obj */
993      /* jj = layer */
994      for (jj = 0; jj < 5; jj++)
994995      {
995         if( (ii < snes_ram[WH0]) || (ii > snes_ram[WH1]) )
996            w1 = 0;
997         else
998            w1 = 1;
999         if( snes_ram[W12SEL] & 0x1 )
1000            w1 = !w1;
1001      }
1002      if( snes_ram[W12SEL] & 0x8 )
1003      {
1004         if( (ii < snes_ram[WH2]) || (ii > snes_ram[WH3]) )
1005            w2 = 0;
1006         else
1007            w2 = 1;
1008         if( snes_ram[W12SEL] & 0x4 )
1009            w2 = !w2;
1010      }
1011      if( w1 >= 0 && w2 >= 0 )
1012      {
1013         switch( snes_ram[WBGLOG] & 0x3 )
996         snes_ppu.clipmasks[jj][ii] = 0xff;
997         w1 = w2 = -1;
998         if (snes_ppu.layer[jj].window1_enabled)
1014999         {
1015            case 0x0:   /* OR */
1016               snes_ppu.clipmasks[0][ii] = w1 | w2 ? 0x00 : 0xff;
1017               break;
1018            case 0x1:   /* AND */
1019               snes_ppu.clipmasks[0][ii] = w1 & w2 ? 0x00 : 0xff;
1020               break;
1021            case 0x2:   /* XOR */
1022               snes_ppu.clipmasks[0][ii] = w1 ^ w2 ? 0x00 : 0xff;
1023               break;
1024            case 0x3:   /* XNOR */
1025               snes_ppu.clipmasks[0][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1026               break;
1000            if ((ii < snes_ppu.window1_left) || (ii > snes_ppu.window1_right))
1001               w1 = 0;
1002            else
1003               w1 = 1;
1004            if (snes_ppu.layer[jj].window1_invert)
1005               w1 = !w1;
10271006         }
1028      }
1029      else if( w1 >= 0 )
1030         snes_ppu.clipmasks[0][ii] = w1 ? 0x00 : 0xff;
1031      else if( w2 >= 0 )
1032         snes_ppu.clipmasks[0][ii] = w2 ? 0x00 : 0xff;
1033
1034      /* update bg 2 */
1035      snes_ppu.clipmasks[1][ii] = 0xff;
1036      w1 = w2 = -1;
1037      if( snes_ram[W12SEL] & 0x20 )
1038      {
1039         if( (ii < snes_ram[WH0]) || (ii > snes_ram[WH1]) )
1040            w1 = 0;
1041         else
1042            w1 = 1;
1043         if( snes_ram[W12SEL] & 0x10 )
1044            w1 = !w1;
1045      }
1046      if( snes_ram[W12SEL] & 0x80 )
1047      {
1048         if( (ii < snes_ram[WH2]) || (ii > snes_ram[WH3]) )
1049            w2 = 0;
1050         else
1051            w2 = 1;
1052         if( snes_ram[W12SEL] & 0x40 )
1053            w2 = !w2;
1054      }
1055      if( w1 >= 0 && w2 >= 0 )
1056      {
1057         switch( snes_ram[WBGLOG] & 0xc )
1007         if (snes_ppu.layer[jj].window2_enabled)
10581008         {
1059            case 0x0:   /* OR */
1060               snes_ppu.clipmasks[1][ii] = w1 | w2 ? 0x00 : 0xff;
1061               break;
1062            case 0x4:   /* AND */
1063               snes_ppu.clipmasks[1][ii] = w1 & w2 ? 0x00 : 0xff;
1064               break;
1065            case 0x8:   /* XOR */
1066               snes_ppu.clipmasks[1][ii] = w1 ^ w2 ? 0x00 : 0xff;
1067               break;
1068            case 0xc:   /* XNOR */
1069               snes_ppu.clipmasks[1][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1070               break;
1009            if ((ii < snes_ppu.window2_left) || (ii > snes_ppu.window2_right))
1010               w2 = 0;
1011            else
1012               w2 = 1;
1013            if (snes_ppu.layer[jj].window2_invert)
1014               w2 = !w2;
10711015         }
1072      }
1073      else if( w1 >= 0 )
1074         snes_ppu.clipmasks[1][ii] = w1 ? 0x00 : 0xff;
1075      else if( w2 >= 0 )
1076         snes_ppu.clipmasks[1][ii] = w2 ? 0x00 : 0xff;
1077
1078      /* update bg 3 */
1079      snes_ppu.clipmasks[2][ii] = 0xff;
1080      w1 = w2 = -1;
1081      if( snes_ram[W34SEL] & 0x2 )
1082      {
1083         if( (ii < snes_ram[WH0]) || (ii > snes_ram[WH1]) )
1084            w1 = 0;
1085         else
1086            w1 = 1;
1087         if( snes_ram[W34SEL] & 0x1 )
1088            w1 = !w1;
1089      }
1090      if( snes_ram[W34SEL] & 0x8 )
1091      {
1092         if( (ii < snes_ram[WH2]) || (ii > snes_ram[WH3]) )
1093            w2 = 0;
1094         else
1095            w2 = 1;
1096         if( snes_ram[W34SEL] & 0x4 )
1097            w2 = !w2;
1098      }
1099      if( w1 >= 0 && w2 >= 0 )
1100      {
1101         switch( snes_ram[WBGLOG] & 0x30 )
1016         if (w1 >= 0 && w2 >= 0)
11021017         {
1103            case 0x0:   /* OR */
1104               snes_ppu.clipmasks[2][ii] = w1 | w2 ? 0x00 : 0xff;
1105               break;
1106            case 0x10:   /* AND */
1107               snes_ppu.clipmasks[2][ii] = w1 & w2 ? 0x00 : 0xff;
1108               break;
1109            case 0x20:   /* XOR */
1110               snes_ppu.clipmasks[2][ii] = w1 ^ w2 ? 0x00 : 0xff;
1111               break;
1112            case 0x30:   /* XNOR */
1113               snes_ppu.clipmasks[2][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1114               break;
1018            switch (snes_ppu.layer[jj].wlog_mask)
1019            {
1020               case 0x00:   /* OR */
1021                  snes_ppu.clipmasks[jj][ii] = w1 | w2 ? 0x00 : 0xff;
1022                  break;
1023               case 0x01:   /* AND */
1024                  snes_ppu.clipmasks[jj][ii] = w1 & w2 ? 0x00 : 0xff;
1025                  break;
1026               case 0x02:   /* XOR */
1027                  snes_ppu.clipmasks[jj][ii] = w1 ^ w2 ? 0x00 : 0xff;
1028                  break;
1029               case 0x03:   /* XNOR */
1030                  snes_ppu.clipmasks[jj][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1031                  break;
1032            }
11151033         }
1034         else if( w1 >= 0 )
1035            snes_ppu.clipmasks[jj][ii] = w1 ? 0x00 : 0xff;
1036         else if( w2 >= 0 )
1037            snes_ppu.clipmasks[jj][ii] = w2 ? 0x00 : 0xff;
11161038      }
1117      else if( w1 >= 0 )
1118         snes_ppu.clipmasks[2][ii] = w1 ? 0x00 : 0xff;
1119      else if( w2 >= 0 )
1120         snes_ppu.clipmasks[2][ii] = w2 ? 0x00 : 0xff;
11211039
1122      /* update bg 4 */
1123      snes_ppu.clipmasks[3][ii] = 0xff;
1124      w1 = w2 = -1;
1125      if( snes_ram[W34SEL] & 0x20 )
1126      {
1127         if( (ii < snes_ram[WH0]) || (ii > snes_ram[WH1]) )
1128            w1 = 0;
1129         else
1130            w1 = 1;
1131         if( snes_ram[W34SEL] & 0x10 )
1132            w1 = !w1;
1133      }
1134      if( snes_ram[W34SEL] & 0x80 )
1135      {
1136         if( (ii < snes_ram[WH2]) || (ii > snes_ram[WH3]) )
1137            w2 = 0;
1138         else
1139            w2 = 1;
1140         if( snes_ram[W34SEL] & 0x40 )
1141            w2 = !w2;
1142      }
1143      if( w1 >= 0 && w2 >= 0 )
1144      {
1145         switch( snes_ram[WBGLOG] & 0xc0 )
1146         {
1147            case 0x0:   /* OR */
1148               snes_ppu.clipmasks[3][ii] = w1 | w2 ? 0x00 : 0xff;
1149               break;
1150            case 0x40:   /* AND */
1151               snes_ppu.clipmasks[3][ii] = w1 & w2 ? 0x00 : 0xff;
1152               break;
1153            case 0x80:   /* XOR */
1154               snes_ppu.clipmasks[3][ii] = w1 ^ w2 ? 0x00 : 0xff;
1155               break;
1156            case 0xc0:   /* XNOR */
1157               snes_ppu.clipmasks[3][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1158               break;
1159         }
1160      }
1161      else if( w1 >= 0 )
1162         snes_ppu.clipmasks[3][ii] = w1 ? 0x00 : 0xff;
1163      else if( w2 >= 0 )
1164         snes_ppu.clipmasks[3][ii] = w2 ? 0x00 : 0xff;
1165
1166      /* update objects */
1167      snes_ppu.clipmasks[4][ii] = 0xff;
1168      w1 = w2 = -1;
1169      if( snes_ram[WOBJSEL] & 0x2 )
1170      {
1171         if( (ii < snes_ram[WH0]) || (ii > snes_ram[WH1]) )
1172            w1 = 0;
1173         else
1174            w1 = 1;
1175         if( snes_ram[WOBJSEL] & 0x1 )
1176            w1 = !w1;
1177      }
1178      if( snes_ram[WOBJSEL] & 0x8 )
1179      {
1180         if( (ii < snes_ram[WH2]) || (ii > snes_ram[WH3]) )
1181            w2 = 0;
1182         else
1183            w2 = 1;
1184         if( snes_ram[WOBJSEL] & 0x4 )
1185            w2 = !w2;
1186      }
1187      if( w1 >= 0 && w2 >= 0 )
1188      {
1189         switch( snes_ram[WOBJLOG] & 0x3 )
1190         {
1191            case 0x0:   /* OR */
1192               snes_ppu.clipmasks[4][ii] = w1 | w2 ? 0x00 : 0xff;
1193               break;
1194            case 0x1:   /* AND */
1195               snes_ppu.clipmasks[4][ii] = w1 & w2 ? 0x00 : 0xff;
1196               break;
1197            case 0x2:   /* XOR */
1198               snes_ppu.clipmasks[4][ii] = w1 ^ w2 ? 0x00 : 0xff;
1199               break;
1200            case 0x3:   /* XNOR */
1201               snes_ppu.clipmasks[4][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1202               break;
1203         }
1204      }
1205      else if( w1 >= 0 )
1206         snes_ppu.clipmasks[4][ii] = w1 ? 0x00 : 0xff;
1207      else if( w2 >= 0 )
1208         snes_ppu.clipmasks[4][ii] = w2 ? 0x00 : 0xff;
1209
12101040      /* update colour window */
12111041      /* FIXME: Why is the colour window different to the other windows? *
12121042         * Have I overlooked something or done something wrong? */
12131043      snes_ppu.clipmasks[5][ii] = 0xff;
12141044      w1 = w2 = -1;
1215      if( snes_ram[WOBJSEL] & 0x20 )
1045      if (snes_ppu.colour.window1_enabled)
12161046      {
12171047         /* Default to mask area inside */
1218         if( (ii < snes_ram[WH0]) || (ii > snes_ram[WH1]) )
1048         if ((ii < snes_ppu.window1_left) || (ii > snes_ppu.window1_right))
12191049            w1 = 0;
12201050         else
12211051            w1 = 1;
12221052         /* If mask area is outside then swap */
1223         if( snes_ram[WOBJSEL] & 0x10 )
1053         if (snes_ppu.colour.window1_invert)
12241054            w1 = !w1;
12251055      }
1226      if( snes_ram[WOBJSEL] & 0x80 )
1056      if (snes_ppu.colour.window2_enabled)
12271057      {
1228         /* Default to mask area inside */
1229         if( (ii < snes_ram[WH2]) || (ii > snes_ram[WH3]) )
1058         if ((ii < snes_ppu.window2_left) || (ii > snes_ppu.window2_right))
12301059            w2 = 0;
12311060         else
12321061            w2 = 1;
1233         /* If mask area is outside then swap */
1234         if( snes_ram[WOBJSEL] & 0x40 )
1062         if (snes_ppu.colour.window2_invert)
12351063            w2 = !w2;
12361064      }
12371065      if( w1 >= 0 && w2 >= 0 )
12381066      {
1239         switch( snes_ram[WOBJLOG] & 0xc )
1067         switch (snes_ppu.colour.wlog_mask)
12401068         {
12411069            case 0x0:   /* OR */
12421070               snes_ppu.clipmasks[5][ii] = w1 | w2 ? 0xff : 0x00;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team