OSDN Git Service

wwww
[proj16/16.git] / 16 / v2 / source / MAPED / MODE13H.C
1 /*\r
2 Copyright (C) 1998 BJ Eirich (aka vecna)\r
3 This program is free software; you can redistribute it and/or\r
4 modify it under the terms of the GNU General Public License\r
5 as published by the Free Software Foundation; either version 2\r
6 of the License, or (at your option) any later version.\r
7 This program is distributed in the hope that it will be useful,\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
10 See the GNU General Public Lic\r
11 See the GNU General Public License for more details.\r
12 You should have received a copy of the GNU General Public License\r
13 along with this program; if not, write to the Free Software\r
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
15 */\r
16 \r
17 #include <string.h>\r
18 #include <malloc.h>\r
19 \r
20 #include "mode13h.h"\r
21 #include "vdriver.h"\r
22 \r
23 // ================================= Data ====================================\r
24 \r
25 char *screenr;                      // realscr\r
26 char startline=16;                  // virtual scroll around 240 vert. pixels\r
27 extern unsigned char* translucency_table; //zero\r
28 \r
29 extern void *valloc(int amount, char*, int);\r
30 extern int  vfree(void *);\r
31 extern void CheckTimerStuff(); // in maped.c\r
32 \r
33 // ================================= Code ====================================\r
34 \r
35 \r
36 void SetMode(int mode)\r
37 {\r
38   REGISTERS r;\r
39   SET_AX(r, mode);\r
40   INTERRUPT(0x10, r);\r
41 }\r
42 \r
43 int Mode13hShutdown()\r
44 {\r
45   SetMode(0x3);\r
46   vfree(screen);\r
47   screen=0;\r
48   return 0;\r
49 }\r
50 \r
51 int Mode13hShowPage()\r
52 { int rows;\r
53   char *s,*d;\r
54 \r
55   CheckTimerStuff();\r
56 \r
57   s=screen+(16*tsx)+16;\r
58   d=screenr;\r
59   rows=sy;\r
60 \r
61   for (; rows; rows--)\r
62   {\r
63     memcpy(d,s,sx);\r
64     s+=tsx;\r
65     d+=sx;\r
66   }\r
67 \r
68   return 0;\r
69 }\r
70 \r
71 int Mode13hCopySprite(int x, int y, int width, int height, char *src)\r
72 { char *d;\r
73 \r
74   d=screen+(y*tsx)+x;\r
75   for (; height; height--)\r
76   {\r
77     memcpy(d,src,width);\r
78     src+=width;\r
79     d+=tsx;\r
80   }\r
81 \r
82   return 0;\r
83 }\r
84 \r
85 int Mode13hCCopySprite(int x,int y,int width,int height,char *src)\r
86 { int cx1,cy1,cx2,cy2;\r
87   char *s,*d;\r
88   int xl,yl,xs,ys;\r
89 \r
90   xl=width;\r
91   yl=height;\r
92   xs=ys=0;\r
93 \r
94   cx1=0;\r
95   cy1=0;\r
96   cx2=tsx-1;\r
97   cy2=tsy-1;\r
98 \r
99   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
100     return 0;\r
101 \r
102   if (x+xl > cx2) xl=cx2-x+1;\r
103   if (y+yl > cy2) yl=cy2-y+1;\r
104 \r
105   if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }\r
106   if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }\r
107 \r
108   s=src;\r
109   if (xs+ys) s+=(ys*width)+xs;\r
110   d=screen+(y*tsx)+x;\r
111 \r
112   for (; yl; yl--)\r
113   {\r
114     memcpy(d,s,xl);\r
115     s+=width;\r
116     d+=tsx;\r
117   }\r
118 \r
119   return 0;\r
120 }\r
121 \r
122 int Mode13hTCCopySprite(int x,int y,int width,int height,char *src)\r
123 { int cx1,cy1,cx2,cy2;\r
124   char *s,*d;\r
125   int xl,yl,xs,ys;\r
126   char c;\r
127 \r
128   xl=width;\r
129   yl=height;\r
130   xs=ys=0;\r
131 \r
132   cx1=0;\r
133   cy1=0;\r
134   cx2=tsx-1;\r
135   cy2=tsy-1;\r
136 \r
137   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
138     return 0;\r
139 \r
140   if (x+xl > cx2) xl=cx2-x+1;\r
141   if (y+yl > cy2) yl=cy2-y+1;\r
142 \r
143   if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }\r
144   if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }\r
145 \r
146   s=src+(ys*width)+xs;\r
147   d=screen+(y*tsx)+x;\r
148 \r
149   for (; yl; yl--)\r
150   {\r
151     for (x=0; x<xl; x++)\r
152     {\r
153       c=s[x];\r
154       if (c)\r
155         d[x]=c;\r
156     }\r
157     s+=width;\r
158     d+=tsx;\r
159   }\r
160 \r
161   return 0;\r
162 }\r
163 \r
164 int Mode13hTCopySprite(int x, int y, int width, int height, char *src)\r
165 { char *d;\r
166   char c;\r
167 \r
168   d=screen+(y*tsx)+x;\r
169   for (; height; height--)\r
170   {\r
171     for (x=0; x<width; x++)\r
172     {\r
173       c=src[x];\r
174       if (c)\r
175         d[x]=c;\r
176     }\r
177     src+=width;\r
178     d+=tsx;\r
179   }\r
180 \r
181   return 0;\r
182 }\r
183 \r
184 int Mode13hCopyTile(int x, int y, char *src)\r
185 { int h;\r
186   char *d;\r
187 \r
188   h=16;\r
189   d=screen+(y*tsx)+x;\r
190   for (; h; h--)\r
191   {\r
192     memcpy(d, src, 16);\r
193     src+=16;\r
194     d+=tsx;\r
195   }\r
196 \r
197   return 0;\r
198 }\r
199 \r
200 int Mode13hVLine(int x, int y, int length, char color)\r
201 { int cx1,cy1,cx2,cy2;\r
202   char *d;\r
203 \r
204   cx1=0;\r
205   cy1=0;\r
206   cx2=tsx-1;\r
207   cy2=tsy-1;\r
208 \r
209   if (x>cx2 || y>cy2 || x<cx1 || y+length<cy1)\r
210     return 0;\r
211 \r
212   if (y+length > cy2) length=cy2-y+1;\r
213   if (y<cy1) { length-=(cy1-y); y=cy1; }\r
214 \r
215   d=screen+(y*tsx)+x;\r
216   for (; length; length--)\r
217   {\r
218     *d=color;\r
219     d+=tsx;\r
220   }\r
221 \r
222   return 0;\r
223 }\r
224 \r
225 int Mode13hHLine(int x, int y, int width, char color)\r
226 { int cx1,cy1,cx2,cy2;\r
227   char *d;\r
228 \r
229   cx1=0;\r
230   cy1=0;\r
231   cx2=tsx-1;\r
232   cy2=tsy-1;\r
233 \r
234   if (x>cx2 || y>cy2 || x+width<cx1 || y<cy1)\r
235     return 0;\r
236 \r
237   if (x+width > cx2) width=cx2-x+1;\r
238   if (x<cx1) { width-=(cx1-x); x=cx1; }\r
239 \r
240   d=screen+(y*tsx)+x;\r
241   memset(d,color,width);\r
242 \r
243   return 0;\r
244 }\r
245 \r
246 int Mode13hFilledBox(int x, int y, int width, int height, char c)\r
247 {\r
248   for (; height; height--,y++)\r
249     Mode13hHLine(x, y, width, c);\r
250 \r
251   return 0;\r
252 }\r
253 \r
254 int Mode13hColorGrid(int x, int y, char c)\r
255 { char *d;\r
256 \r
257   if (x<0 || x>336 || y<0 || y>256) return 0;\r
258   d=screen+(y*tsx)+x;\r
259   for (y=0; y<8; y++)\r
260   {\r
261     d[0]=c; d[2]=c; d[4]=c; d[6]=c;\r
262     d[8]=c; d[10]=c; d[12]=c; d[14]=c;\r
263 \r
264     d+=(tsx+1);\r
265 \r
266     d[0]=c; d[2]=c; d[4]=c; d[6]=c;\r
267     d[8]=c; d[10]=c; d[12]=c; d[14]=c;\r
268 \r
269     d+=(tsx-1);\r
270   }\r
271 \r
272   return 0;\r
273 }\r
274 \r
275 int Mode13hClearScreen()\r
276 {\r
277   memset(screen,0,76032);\r
278   return 0;\r
279 }\r
280 \r
281 int Mode13hCopySpriteLucentClip(int x, int y, int width, int height, unsigned char *src)\r
282 {\r
283  int cx1,cy1,cx2,cy2;\r
284   unsigned char *s,*d,c;\r
285   int xl,yl,xs,ys;\r
286 \r
287   cx1=0;\r
288   cy1=0;\r
289   cx2=tsx-1;\r
290   cy2=tsy-1;\r
291 \r
292   xl=width;\r
293   yl=height;\r
294   xs=ys=0;\r
295   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
296     return 1;\r
297   if (x+xl > cx2) xl=cx2-x+1;\r
298   if (y+yl > cy2) yl=cy2-y+1;\r
299   if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }\r
300   if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }\r
301 \r
302   s=src;\r
303   if (ys) s+=(ys*width); // only perform mul if necessary ;)\r
304   if (xs) s+=xs;\r
305   d=screen+(y*tsx)+x;\r
306 \r
307   for (; yl; yl--)\r
308   {\r
309     for (x=0; x<xl; x++)\r
310     {\r
311       c=s[x];\r
312       if (c)\r
313         d[x]=translucency_table[d[x]|(c<<8)];\r
314     }\r
315     s+=width;\r
316     d+=tsx;\r
317   }\r
318   return 1;\r
319 }\r
320 \r
321 void InitMode13h()\r
322 {\r
323   SetMode(0x13);\r
324 \r
325   screenr=(char *) 0xA0000;\r
326   screen=(char *) valloc(352*(216+16),"Screen",0);\r
327   //memset(screen,0,95744);\r
328 \r
329   sx=320;  sy=200;\r
330   tsx=352; tsy=216;\r
331   tx=20;   ty=13;\r
332 \r
333   // Mode successfuly set, now lets set up the driver.\r
334   ShutdownVideo=&Mode13hShutdown;\r
335   ShowPage=&Mode13hShowPage;\r
336   CopySprite=&Mode13hCopySprite;\r
337   CCopySprite=&Mode13hCCopySprite;\r
338   TCCopySprite=&Mode13hTCCopySprite;\r
339   TCopySprite=&Mode13hTCopySprite;\r
340   CopyTile=&Mode13hCopyTile;\r
341   FilledBox=&Mode13hFilledBox;\r
342   VLine=&Mode13hVLine;\r
343   HLine=&Mode13hHLine;\r
344   ColorGrid=&Mode13hColorGrid;\r
345   ClearScreen=&Mode13hClearScreen;\r
346   CopySpriteLucentClip=&Mode13hCopySpriteLucentClip;\r
347 \r
348   map_scroll_x =\r
349   map_scroll_y = 2;\r
350 }\r