1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
\r
4 * This file is part of Project 16.
\r
6 * Project 16 is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Project 16 is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
\r
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
\r
19 * Fifth Floor, Boston, MA 02110-1301 USA.
\r
26 #include "src/lib/modex16/16render.h"
\r
28 //TODO! ADD CLIPPING!!
\r
29 //memory management needs to be added
\r
31 //modexDrawBmpRegion (page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp)
\r
32 void modexDrawPBufRegion (page_t *page, int x, int y, int rx, int ry, int rw, int rh, planar_buf_t *p, boolean sprite)
\r
36 const int px=x;//-page->dx;
\r
37 const int py=y;//-page->dy;
\r
38 #define PEEE ((rw)/4)-rx
\r
40 #define PEEEE ((p->pwidth)*(ry))
\r
43 //printf("%d,%d p(%d,%d) r(%d,%d) rwh(%d,%d)\n", x, y, px, py, rx, ry, rw, rh);
\r
44 for(plane=0; plane < 4; plane++) {
\r
46 //printf("PEEE=%d ", PEEE);
\r
47 //printf("PEEEE=%d ", PEEEE);
\r
48 //printf("i=%d\n", i);
\r
49 modexSelectPlane(PLANE(plane+x));
\r
50 for(; y < py+rh; y++) {
\r
51 //for(px=0; px < p->width; px++) {
\r
52 //printf("%02X ", (int) p->plane[plane][i++]);
\r
53 // _fmemcpy(buff, &(p->plane[plane][i+=p->pwidth]), p->pwidth);
\r
54 // printf("buff %u==%s\n", y, *buff);
\r
55 _fmemcpy(page->data + (((page->width/4) * y) + (x / 4)), &(p->plane[plane][i+=p->pwidth]), (rw/4));
\r
57 //if(plane==3) IN_Ack();
\r
59 /*printf("y%d=%d ", plane, y);
\r
60 if(plane==3) printf("y%d=%d\n", plane, y);*/
\r
69 modexDrawPBuf(page_t *page, int x, int y, planar_buf_t *p, boolean sprite)
\r
74 const int px=x+page->dx;
\r
75 const int py=y+page->dy;
\r
78 // buff = _nmalloc(p->pwidth+1);
\r
79 // TODO Make this fast. It's SLOOOOOOW
\r
80 // for(plane=0; plane < 4; plane++) {
\r
82 // modexSelectPlane(PLANE(plane+x));
\r
83 // for(px = plane; px < p->width; px+=4) {
\r
85 // for(py=0; py<p->height/2; py++) {
\r
86 // //SELECT_ALL_PLANES();
\r
87 // if(!sprite || p->plane[offset])
\r
88 // page->data = &(p->plane[offset][i++]);
\r
89 // offset+=p->width;
\r
94 for(plane=0; plane < 4; plane++) {
\r
96 modexSelectPlane(PLANE(plane+x));
\r
97 for(; y < py+p->height; y++) {
\r
98 //for(px=0; px < p->width; px++) {
\r
99 //printf("%02X ", (int) p->plane[plane][i++]);
\r
100 // _fmemcpy(buff, &(p->plane[plane][i+=p->pwidth]), p->pwidth);
\r
101 // printf("buff %u==%s\n", y, *buff);
\r
102 // _fmemcpy(page->data + (((page->width/4) * (y+page->dy)) + ((x+page->dx) / 4)), buff, p->pwidth);
\r
103 _fmemcpy(page->data + (((page->width/4) * y) + (x / 4)), &(p->plane[plane][i+=p->pwidth]), p->pwidth);
\r
113 oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite)
\r
119 /* TODO Make this fast. It's SLOOOOOOW */
\r
120 for(plane=0; plane < 4; plane++) {
\r
121 modexSelectPlane(PLANE(plane+x));
\r
122 for(px = plane; px < bmp->width; px+=4) {
\r
124 for(py=0; py<bmp->height; py++) {
\r
125 if(!sprite || bmp->data[offset])
\r
126 page[PAGE_OFFSET(x+px, y+py)] = bmp->data[offset];
\r
127 offset+=bmp->width;
\r
133 //* normal versions *//
\r
135 modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp) {
\r
136 /* draw the region (the entire freakin bitmap) */
\r
137 modexDrawBmpRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);
\r
141 modexDrawBmpRegion(page_t *page, int x, int y,
\r
142 int rx, int ry, int rw, int rh, bitmap_t *bmp) {
\r
143 word poffset = (word) page->data + y*(page->width/4) + x/4;
\r
144 byte *data = bmp->data;//+bmp->offset;
\r
145 word bmpOffset = (word) data + ry * bmp->width + rx;
\r
148 byte plane = 1 << ((byte) x & 0x03);
\r
149 word scanCount = width/4 + (width%4 ? 1 :0);
\r
150 word nextPageRow = page->width/4 - scanCount;
\r
151 word nextBmpRow = (word) bmp->width - width;
\r
153 byte planeCounter = 4;
\r
156 MOV AX, SCREEN_SEG ; go to the VGA memory
\r
159 MOV DX, SC_INDEX ; point at the map mask register
\r
164 MOV DX, SC_DATA ; select the current plane
\r
168 ;-- begin plane painting
\r
169 MOV AX, height ; start the row counter
\r
170 MOV rowCounter, AX ;
\r
171 MOV DI, poffset ; go to the first pixel
\r
172 MOV SI, bmpOffset ; go to the bmp pixel
\r
174 MOV CX, width ; count the columns
\r
176 MOVSB ; copy the pixel
\r
177 SUB CX, 3 ; we skip the next 3
\r
178 ADD SI, 3 ; skip the bmp pixels
\r
179 LOOP SCAN_LOOP ; finish the scan
\r
181 MOV AX, nextPageRow
\r
182 ADD DI, AX ; go to the next row on screen
\r
184 ADD SI, AX ; go to the next row on bmp
\r
187 JNZ ROW_LOOP ; do all the rows
\r
188 ;-- end plane painting
\r
189 MOV AL, plane ; advance to the next plane
\r
191 AND AL, 0x0f ; mask the plane properly
\r
192 MOV plane, AL ; store the plane
\r
194 INC bmpOffset ; start bmp at the right spot
\r
197 JNZ PLANE_LOOP ; do all 4 planes
\r
202 modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp) {
\r
203 /* draw the whole sprite */
\r
204 modexDrawSpriteRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);
\r
208 modexDrawSpriteRegion(page_t *page, int x, int y,
\r
209 int rx, int ry, int rw, int rh, bitmap_t *bmp) {
\r
210 word poffset = (word)page->data + y*(page->width/4) + x/4;
\r
211 byte *data = bmp->data;//+bmp->offset;
\r
212 word bmpOffset = (word) data + ry * bmp->width + rx;
\r
215 byte plane = 1 << ((byte) x & 0x03);
\r
216 word scanCount = width/4 + (width%4 ? 1 :0);
\r
217 word nextPageRow = page->width/4 - scanCount;
\r
218 word nextBmpRow = (word) bmp->width - width;
\r
220 byte planeCounter = 4;
\r
223 MOV AX, SCREEN_SEG ; go to the VGA memory
\r
226 MOV DX, SC_INDEX ; point at the map mask register
\r
231 MOV DX, SC_DATA ; select the current plane
\r
235 ;-- begin plane painting
\r
236 MOV AX, height ; start the row counter
\r
237 MOV rowCounter, AX ;
\r
238 MOV DI, poffset ; go to the first pixel
\r
239 MOV SI, bmpOffset ; go to the bmp pixel
\r
241 MOV CX, width ; count the columns
\r
246 JNE DRAW_PIXEL ; draw non-zero pixels
\r
248 INC DI ; skip the transparent pixel
\r
252 MOVSB ; copy the pixel
\r
254 SUB CX, 3 ; we skip the next 3
\r
255 ADD SI, 3 ; skip the bmp pixels
\r
256 LOOP SCAN_LOOP ; finish the scan
\r
258 MOV AX, nextPageRow
\r
259 ADD DI, AX ; go to the next row on screen
\r
261 ADD SI, AX ; go to the next row on bmp
\r
264 JNZ ROW_LOOP ; do all the rows
\r
265 ;-- end plane painting
\r
267 MOV AL, plane ; advance to the next plane
\r
269 AND AL, 0x0f ; mask the plane properly
\r
270 MOV plane, AL ; store the plane
\r
272 INC bmpOffset ; start bmp at the right spot
\r
275 JNZ PLANE_LOOP ; do all 4 planes
\r
279 //* planar buffer versions *//
\r
281 modexDrawBmpPBuf(page_t *page, int x, int y, planar_buf_t *bmp) {
\r
282 /* draw the region (the entire freakin bitmap) */
\r
283 modexDrawBmpPBufRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);
\r
287 modexDrawBmpPBufRegion(page_t *page, int x, int y,
\r
288 int rx, int ry, int rw, int rh, planar_buf_t *bmp) {
\r
289 word poffset = (word) page->data + y*(page->width/4) + x/4;
\r
290 byte *data = *bmp->plane;//+bmp->offset;
\r
291 word bmpOffset = (word) data + ry * bmp->width + rx;
\r
293 word height = rh/4;
\r
294 byte plane = 1 << ((byte) x & 0x03);
\r
295 word scanCount = width/4 + (width%4 ? 1 :0);
\r
296 word nextPageRow = page->width/4 - scanCount;
\r
297 word nextBmpRow = (word) bmp->width - width;
\r
299 byte planeCounter = 4;
\r
302 MOV AX, SCREEN_SEG ; go to the VGA memory
\r
305 MOV DX, SC_INDEX ; point at the map mask register
\r
310 MOV DX, SC_DATA ; select the current plane
\r
314 ;-- begin plane painting
\r
315 MOV AX, height ; start the row counter
\r
316 MOV rowCounter, AX ;
\r
317 MOV DI, poffset ; go to the first pixel
\r
318 MOV SI, bmpOffset ; go to the bmp pixel
\r
320 MOV CX, width ; count the columns
\r
322 MOVSB ; copy the pixel
\r
323 SUB CX, 3 ; we skip the next 3
\r
324 ADD SI, 3 ; skip the bmp pixels
\r
325 LOOP SCAN_LOOP ; finish the scan
\r
327 MOV AX, nextPageRow
\r
328 ADD DI, AX ; go to the next row on screen
\r
330 ADD SI, AX ; go to the next row on bmp
\r
333 JNZ ROW_LOOP ; do all the rows
\r
334 ;-- end plane painting
\r
335 MOV AL, plane ; advance to the next plane
\r
337 AND AL, 0x0f ; mask the plane properly
\r
338 MOV plane, AL ; store the plane
\r
340 INC bmpOffset ; start bmp at the right spot
\r
343 JNZ PLANE_LOOP ; do all 4 planes
\r
348 modexDrawSpritePBuf(page_t *page, int x, int y, planar_buf_t *bmp) {
\r
349 /* draw the whole sprite */
\r
350 modexDrawSpritePBufRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);
\r
354 modexDrawSpritePBufRegion(page_t *page, int x, int y,
\r
355 int rx, int ry, int rw, int rh, planar_buf_t *bmp) {
\r
356 word poffset = (word)page->data + y*(page->width/4) + x/4;
\r
357 byte *data = *bmp->plane;//+bmp->offset;
\r
358 word bmpOffset = (word) data + ry * bmp->width + rx;
\r
360 word height = rh/4;
\r
361 byte plane = 1 << ((byte) x & 0x03);
\r
362 word scanCount = width/4 + (width%4 ? 1 :0);
\r
363 word nextPageRow = page->width/4 - scanCount;
\r
364 word nextBmpRow = (word) bmp->width - width;
\r
366 byte planeCounter = 4;
\r
369 MOV AX, SCREEN_SEG ; go to the VGA memory
\r
372 MOV DX, SC_INDEX ; point at the map mask register
\r
377 MOV DX, SC_DATA ; select the current plane
\r
381 ;-- begin plane painting
\r
382 MOV AX, height ; start the row counter
\r
383 MOV rowCounter, AX ;
\r
384 MOV DI, poffset ; go to the first pixel
\r
385 MOV SI, bmpOffset ; go to the bmp pixel
\r
387 MOV CX, width ; count the columns
\r
392 JNE DRAW_PIXEL ; draw non-zero pixels
\r
394 INC DI ; skip the transparent pixel
\r
398 MOVSB ; copy the pixel
\r
400 SUB CX, 3 ; we skip the next 3
\r
401 ADD SI, 3 ; skip the bmp pixels
\r
402 LOOP SCAN_LOOP ; finish the scan
\r
404 MOV AX, nextPageRow
\r
405 ADD DI, AX ; go to the next row on screen
\r
407 ADD SI, AX ; go to the next row on bmp
\r
410 JNZ ROW_LOOP ; do all the rows
\r
411 ;-- end plane painting
\r
413 MOV AL, plane ; advance to the next plane
\r
415 AND AL, 0x0f ; mask the plane properly
\r
416 MOV plane, AL ; store the plane
\r
418 INC bmpOffset ; start bmp at the right spot
\r
421 JNZ PLANE_LOOP ; do all 4 planes
\r