ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
screen_eob_segacd.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef KYRA_SCREEN_EOB_SEGACD_H
23 #define KYRA_SCREEN_EOB_SEGACD_H
24 
25 #ifdef ENABLE_EOB
26 
27 #define SEGA_PERFORMANCE true
28 #define SEGA_USE_MEMPOOL true
29 
30 #include "kyra/graphics/screen_eob.h"
31 
32 #if SEGA_USE_MEMPOOL
33 #include "common/memorypool.h"
34 #endif
35 
36 namespace Kyra {
37 
38 class SegaRenderer {
39 public:
40  enum Plane {
41  kPlaneA = 0,
42  kPlaneB = 1,
43  kWindowPlane = 2
44  };
45 
46  enum WindowMode {
47  kWinToLeft = 0,
48  kWinToTop = 0,
49  kWinToRight = 1,
50  kWinToBottom = 1
51  };
52 
53  enum HScrollMode {
54  kHScrollFullScreen = 0,
55  kHScroll8PixelRows,
56  kHScroll1PixelRows
57  };
58 
59  enum VScrollMode {
60  kVScrollFullScreen = 0,
61  kVScroll16PixelStrips
62  };
63 
64 public:
65  SegaRenderer(Screen_EoB *screen);
66  ~SegaRenderer();
67 
68  void setResolution(int w, int h);
69  void setPlaneTableLocation(int plane, uint16 addr);
70  // The hardware allows/demands separate modification of the vertical and horizontal properties.
71  // To allow this without making another function the w/h parameters can be set to -1 which will
72  // keep the existing value for that property.
73  void setupPlaneAB(int pixelWidth, int pixelHeigth);
74  // The hardware allows/demands separate modification of the vertical and horizontal properties.
75  // To allow this without making another function the blockX/Y parameters can be set to -1 which
76  // will keep the existing value for that property.
77  void setupWindowPlane(int blockX, int blockY, int horizontalMode, int verticalMode);
78  void setHScrollTableLocation(int addr);
79  void setSpriteTableLocation(int addr);
80  void setPitch(int pitch);
81  void setHScrollMode(int mode);
82  void setVScrollMode(int mode);
83 
84  void loadToVRAM(const void *data, uint16 dataSize, uint16 addr);
85  void loadStreamToVRAM(Common::SeekableReadStream *in, uint16 addr, bool compressedData = false);
86  void memsetVRAM(int addr, uint8 val, int len);
87  void fillRectWithTiles(int vramArea, int x, int y, int w, int h, uint16 nameTblEntry, bool incr = false, bool topToBottom = false, const uint16 *patternTable = 0);
88  void writeUint16VSRAM(int addr, uint16 value);
89  void writeUint8VRAM(int addr, uint8 value);
90  void writeUint16VRAM(int addr, uint16 value);
91  void clearPlanes();
92 
93  void render(int destPageNum, int renderLeft = -1, int renderTop = -1, int renderWidth = -1, int renderHeight = -1, bool spritesOnly = false);
94 private:
95  void renderPlanePart(int plane, uint8 *dstBuffer, int x1, int y1, int x2, int y2);
96  void renderPlaneTile(uint8 *dst, int destX, const uint16 *nameTable, int vScrollLSBStart, int vScrollLSBEnd, int hScrollTableIndex, uint16 pitch);
97  void renderSpriteTile(uint8 *dst, uint8 *mask, int x, int y, uint16 tile, uint8 pal, bool vflip, bool hflip, bool prio);
98 #if SEGA_PERFORMANCE
99  template<bool hflip, bool oddStart, bool oddEnd> void renderLineFragmentM(uint8 *dst, uint8 *mask, const uint8 *src, int start, int end, uint8 pal);
100  template<bool hflip, bool oddStart, bool oddEnd> void renderLineFragmentD(uint8 *dst, const uint8 *src, int start, int end, uint8 pal);
101  typedef void(SegaRenderer::*renderFuncM)(uint8*, uint8*, const uint8*, int, int, uint8);
102  typedef void(SegaRenderer::*renderFuncD)(uint8*, const uint8*, int, int, uint8);
103  const renderFuncM *_renderLineFragmentM;
104  const renderFuncD *_renderLineFragmentD;
105 #else
106  template<bool hflip> void renderLineFragment(uint8 *dst, uint8 *mask, const uint8 *src, int start, int end, uint8 pal);
107 #endif
108 
109  void initPrioRenderTask(uint8 *dst, uint8 *mask, const uint8 *src, int start, int end, uint8 pal, bool hflip);
110  void clearPrioChain();
111 
112  struct SegaPlane {
113  SegaPlane() : blockX(0), blockY(0), w(0), h(0), mod(0), nameTable(0), nameTableSize(0) {}
114  int blockX, blockY;
115  uint16 w, h, mod;
116  uint16 *nameTable;
117  uint16 nameTableSize;
118  };
119 
120  SegaPlane _planes[3];
121  uint8 *_vram;
122  uint16 *_vsram;
123  uint16 *_hScrollTable;
124  uint16 *_spriteTable;
125  uint8 *_spriteMask;
126  uint8 _hScrollMode;
127  uint8 _vScrollMode;
128  uint16 _pitch;
129  uint16 _numSpritesMax;
130 
131  struct PrioTileRenderObj {
132  PrioTileRenderObj(PrioTileRenderObj *chainEnd, uint8 *dst, uint8 *mask, const uint8 *src, int start, int end, uint8 pal, bool hflip) :
133  _pred(chainEnd), _next(0), _dst(dst), _mask(mask), _src(src), _start(start), _end(end), _pal(pal), _hflip(hflip) {
134  if (_pred)
135  _pred->_next = this;
136  }
137  uint8 *_dst;
138  uint8 *_mask;
139  const uint8 *_src;
140  int _start;
141  int _end;
142  uint8 _pal;
143  bool _hflip;
144  PrioTileRenderObj *_pred;
145  PrioTileRenderObj *_next;
146  };
147 
148 #if SEGA_USE_MEMPOOL
149  Common::ObjectPool<PrioTileRenderObj> _prioRenderMemPool;
150 #endif
151  PrioTileRenderObj *_prioChainStart, *_prioChainEnd;
152  uint16 _screenW, _screenH, _blocksW, _blocksH;
153  Screen_EoB *_screen;
154 };
155 
156 class SegaAnimator {
157 public:
158  SegaAnimator(SegaRenderer *renderer);
159  ~SegaAnimator();
160 
161  void initSprite(int id, int16 x, int16 y, uint16 nameTbl, uint16 hw);
162  void clearSprites();
163  void moveMorphSprite(int id, uint16 nameTbl, int16 addX, int16 addY);
164  void moveSprites(int id, uint16 num, int16 addX, int16 addY);
165  void moveSprites2(int id, uint16 num, int16 addX, int16 addY);
166 
167  void update();
168 
169 private:
170  struct Sprite {
171  int16 x;
172  int16 y;
173  uint16 nameTbl;
174  uint16 hw;
175  };
176 
177  uint16 *_tempBuffer;
178  Sprite *_sprites;
179  SegaRenderer *_renderer;
180  bool _needUpdate;
181 };
182 
183 class ScrollManager {
184 public:
185  ScrollManager(SegaRenderer *renderer);
186  ~ScrollManager();
187 
188  void setVScrollTimers(uint16 destA, int incrA, int delayA, uint16 destB, int incrB, int delayB);
189  void setHScrollTimers(uint16 destA, int incrA, int delayA, uint16 destB, int incrB, int delayB);
190  void updateScrollTimers();
191  void fastForward();
192 
193 private:
194  struct ScrollTimer {
195  ScrollTimer() : _offsCur(0), _offsDest(0), _incr(0), _delay(0), _timer(0) {}
196  int16 _offsCur;
197  int16 _offsDest;
198  int16 _incr;
199  int16 _delay;
200  int16 _timer;
201  };
202 
203  ScrollTimer *_vScrollTimers;
204  ScrollTimer *_hScrollTimers;
205  SegaRenderer *_renderer;
206 };
207 
208 } // End of namespace Kyra
209 
210 #endif // ENABLE_EOB
211 
212 #endif
Definition: stream.h:745
Definition: memorypool.h:139
Definition: detection.h:27