File: ras-drawplane.h

package info (click to toggle)
dgen 1.23-7
  • links: PTS
  • area: non-free
  • in suites: sarge
  • size: 2,168 kB
  • ctags: 3,086
  • sloc: ansic: 45,404; cpp: 4,405; sh: 1,960; makefile: 116
file content (98 lines) | stat: -rw-r--r-- 2,309 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  int xsize, ysize;
  int x, scan, w, xstart;
  static int sizes[4] = {32, 64, 64, 128};
  unsigned which;
  unsigned char *where, *scrolls, *tiles, *tile_line;
  int xoff, yoff, xoff_mask;
  int xscroll, yscroll;

#if PLANE == 0
  // Plane 0 is only where the window isn't
  // This should make Herzog Zwei split screen work perfectly, and clean
  // up those little glitches on Sonic 3's level select.
  if(reg[18] & 0x80) // Window goes down, plane 0 goes up! :)
    {
      if((line>>3) >= (reg[18]&0x1f)) return;
    } else { // Window goes up, plane 0 goes down
      if((line>>3) < (reg[18]&0x1f)) return;
    }
#endif

  xsize = sizes[ reg[16]       & 3] << 1;
  ysize = sizes[(reg[16] >> 4) & 3];
  
#if PLANE == 0
  yscroll = get_word(vsram);
  scrolls = vram + ((reg[13]<<10) & 0xfc00);
  tiles   = vram +  (reg[ 2]<<10);
#else // PLANE == 1
  yscroll = get_word(vsram+2);
  scrolls = vram + ((reg[13]<<10) & 0xfc00) + 2;
  tiles   = vram +  (reg[ 4]<<13);
#endif

  // Interlace?
  if(reg[12] & 2)
    yscroll >>= 1;

  // Offset for the line
  yscroll += line;

  // Wide or narrow?
  if(reg[12] & 1)
    {
      w = 40; xstart = -8;
    } else {
      w = 32; xstart = 24;
    }

  // How do we horizontal offset?
  switch(reg[11] & 3)
    {
    case 2: // per tile
      scrolls += (line & ~7) << 2;
      break;
    case 3: // per line
      scrolls += line << 2;
      break;
    default:
      break;
    }

  xscroll = get_word(scrolls);

  xoff_mask = xsize - 1;
  yoff = (yscroll>>3) & (ysize - 1);
  xoff = ((-(xscroll>>3) - 1)<<1) & xoff_mask;
  tile_line = tiles + xsize * yoff;
  scan = yscroll & 7;

  where = dest + (xstart + (xscroll & 7)) * Bpp;

  for(x = -1; x < w; ++x)
    {
#if PLANE == 0
      if(reg[17] & 0x80) // Don't draw where the window will be
	{
	  if(x >= ((reg[17]&0x1f) << 1)) goto skip;
	} else {
	  // + 1 so scroll layers in Sonic look right
	  if((x + 1) < ((reg[17]&0x1f) << 1)) goto skip;
	}
#endif
      which = get_word(tile_line + xoff);

#if (FRONT == 0) && (PLANE == 1)
      draw_tile_solid(which, scan, where);
#elif FRONT == 1
      if(which >> 15) draw_tile(which, scan, where);
#else
      if(!(which >> 15)) draw_tile(which, scan, where);
#endif

#if PLANE == 0
skip:
#endif
      where += Bpp_times8;
      xoff = (xoff + 2) & xoff_mask;
    }