1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123
\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 const int prw = rw/4;
\r
47 #define PE (p->pwidth)
\r
48 if(rh<p->height) prh = (PE*(ry-4));
\r
49 else if(rh==p->height) prh = (PE*(ry));
\r
52 //printf("%d,%d p(%d,%d) r(%d,%d) rwh(%d,%d)\n", x, y, px, py, rx, ry, rw, rh);
\r
53 for(plane=0; plane < 4; plane++) {
\r
55 modexSelectPlane(PLANE(plane-1));
\r
56 for(; y < py+rh; y++) {
\r
57 _fmemcpy(page->data + (((page->width/4) * (y)) + ((x) / 4)), &(p->plane[plane][i]), prw);
\r
68 modexDrawPBuf(page_t *page, int x, int y, planar_buf_t *p, boolean sprite)
\r
70 modexDrawPBufRegion (page, x, x, 0, 0, p->width, p->height, p, sprite);
\r
75 const int px=x+page->dx;
\r
76 const int py=y+page->dy;
\r
79 // buff = _nmalloc(p->pwidth+1);
\r
80 // TODO Make this fast. It's SLOOOOOOW
\r
81 // for(plane=0; plane < 4; plane++) {
\r
83 // modexSelectPlane(PLANE(plane+x));
\r
84 // for(px = plane; px < p->width; px+=4) {
\r
86 // for(py=0; py<p->height/2; py++) {
\r
87 // //SELECT_ALL_PLANES();
\r
88 // if(!sprite || p->plane[offset])
\r
89 // page->data = &(p->plane[offset][i++]);
\r
90 // offset+=p->width;
\r
95 for(plane=0; plane < 4; plane++) {
\r
97 modexSelectPlane(PLANE(plane-1));
\r
98 for(; y < py+p->height; y++) {
\r
99 //for(px=0; px < p->width; px++) {
\r
100 //printf("%02X ", (int) p->plane[plane][i++]);
\r
101 // _fmemcpy(buff, &(p->plane[plane][i+=p->pwidth]), p->pwidth);
\r
102 // printf("buff %u==%s\n", y, *buff);
\r
103 // _fmemcpy(page->data + (((page->width/4) * (y+page->dy)) + ((x+page->dx) / 4)), buff, p->pwidth);
\r
104 _fmemcpy(page->data + (((page->width/4) * y) + (x / 4)), &(p->plane[plane][i+=p->pwidth]), p->pwidth);
\r
115 oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite)
\r
121 /* TODO Make this fast. It's SLOOOOOOW */
\r
122 for(plane=0; plane < 4; plane++) {
\r
123 modexSelectPlane(PLANE(plane+x));
\r
124 for(px = plane; px < bmp->width; px+=4) {
\r
126 for(py=0; py<bmp->height; py++) {
\r
127 if(!sprite || bmp->data[offset])
\r
128 page[PAGE_OFFSET(x+px, y+py)] = bmp->data[offset];
\r
129 offset+=bmp->width;
\r
135 //* normal versions *//
\r
137 modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp) {
\r
138 /* draw the region (the entire freakin bitmap) */
\r
139 modexDrawBmpRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);
\r
143 modexDrawBmpRegion(page_t *page, int x, int y,
\r
144 int rx, int ry, int rw, int rh, bitmap_t *bmp) {
\r
145 word poffset = (word) page->data + y*(page->width/4) + x/4;
\r
146 byte *data = bmp->data;//+bmp->offset;
\r
147 word bmpOffset = (word) data + ry * bmp->width + rx;
\r
150 byte plane = 1 << ((byte) x & 0x03);
\r
151 word scanCount = width/4 + (width%4 ? 1 :0);
\r
152 word nextPageRow = page->width/4 - scanCount;
\r
153 word nextBmpRow = (word) bmp->width - width;
\r
155 byte planeCounter = 4;
\r
158 MOV AX, SCREEN_SEG ; go to the VGA memory
\r
161 MOV DX, SC_INDEX ; point at the map mask register
\r
166 MOV DX, SC_DATA ; select the current plane
\r
170 ;-- begin plane painting
\r
171 MOV AX, height ; start the row counter
\r
172 MOV rowCounter, AX ;
\r
173 MOV DI, poffset ; go to the first pixel
\r
174 MOV SI, bmpOffset ; go to the bmp pixel
\r
176 MOV CX, width ; count the columns
\r
178 MOVSB ; copy the pixel
\r
179 SUB CX, 3 ; we skip the next 3
\r
180 ADD SI, 3 ; skip the bmp pixels
\r
181 LOOP SCAN_LOOP ; finish the scan
\r
183 MOV AX, nextPageRow
\r
184 ADD DI, AX ; go to the next row on screen
\r
186 ADD SI, AX ; go to the next row on bmp
\r
189 JNZ ROW_LOOP ; do all the rows
\r
190 ;-- end plane painting
\r
191 MOV AL, plane ; advance to the next plane
\r
193 AND AL, 0x0f ; mask the plane properly
\r
194 MOV plane, AL ; store the plane
\r
196 INC bmpOffset ; start bmp at the right spot
\r
199 JNZ PLANE_LOOP ; do all 4 planes
\r
204 modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp) {
\r
205 /* draw the whole sprite */
\r
206 modexDrawSpriteRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);
\r
210 modexDrawSpriteRegion(page_t *page, int x, int y,
\r
211 int rx, int ry, int rw, int rh, bitmap_t *bmp) {
\r
212 word poffset = (word)page->data + y*(page->width/4) + x/4;
\r
213 byte *data = bmp->data;//+bmp->offset;
\r
214 word bmpOffset = (word) data + ry * bmp->width + rx;
\r
217 byte plane = 1 << ((byte) x & 0x03);
\r
218 word scanCount = width/4 + (width%4 ? 1 :0);
\r
219 word nextPageRow = page->width/4 - scanCount;
\r
220 word nextBmpRow = (word) bmp->width - width;
\r
222 byte planeCounter = 4;
\r
225 MOV AX, SCREEN_SEG ; go to the VGA memory
\r
228 MOV DX, SC_INDEX ; point at the map mask register
\r
233 MOV DX, SC_DATA ; select the current plane
\r
237 ;-- begin plane painting
\r
238 MOV AX, height ; start the row counter
\r
239 MOV rowCounter, AX ;
\r
240 MOV DI, poffset ; go to the first pixel
\r
241 MOV SI, bmpOffset ; go to the bmp pixel
\r
243 MOV CX, width ; count the columns
\r
248 JNE DRAW_PIXEL ; draw non-zero pixels
\r
250 INC DI ; skip the transparent pixel
\r
254 MOVSB ; copy the pixel
\r
256 SUB CX, 3 ; we skip the next 3
\r
257 ADD SI, 3 ; skip the bmp pixels
\r
258 LOOP SCAN_LOOP ; finish the scan
\r
260 MOV AX, nextPageRow
\r
261 ADD DI, AX ; go to the next row on screen
\r
263 ADD SI, AX ; go to the next row on bmp
\r
266 JNZ ROW_LOOP ; do all the rows
\r
267 ;-- end plane painting
\r
269 MOV AL, plane ; advance to the next plane
\r
271 AND AL, 0x0f ; mask the plane properly
\r
272 MOV plane, AL ; store the plane
\r
274 INC bmpOffset ; start bmp at the right spot
\r
277 JNZ PLANE_LOOP ; do all 4 planes
\r
281 //* planar buffer versions *//
\r
283 modexDrawBmpPBuf(page_t *page, int x, int y, planar_buf_t *bmp) {
\r
284 /* draw the region (the entire freakin bitmap) */
\r
285 modexDrawBmpPBufRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);
\r
289 modexDrawBmpPBufRegion(page_t *page, int x, int y,
\r
290 int rx, int ry, int rw, int rh, planar_buf_t *bmp) {
\r
291 word poffset = (word) page->data + y*(page->width/4) + x/4;
\r
292 byte *data = bmp->plane[0];
\r
293 word bmpOffset = (word) data + ry * bmp->width + rx;
\r
296 byte plane = 1 << ((byte) x & 0x03);
\r
297 word scanCount = width/4 + (width%4 ? 1 :0);
\r
298 word nextPageRow = page->width/4 - scanCount;
\r
299 word nextBmpRow = (word) bmp->width - width;
\r
301 byte planeCounter = 4;
\r
304 MOV AX, SCREEN_SEG ; go to the VGA memory
\r
307 MOV DX, SC_INDEX ; point at the map mask register
\r
312 MOV DX, SC_DATA ; select the current plane
\r
316 ;-- begin plane painting
\r
317 MOV AX, height ; start the row counter
\r
318 MOV rowCounter, AX ;
\r
319 MOV DI, poffset ; go to the first pixel
\r
320 MOV SI, bmpOffset ; go to the bmp pixel
\r
322 MOV CX, width ; count the columns
\r
333 MOVSB ; copy the pixel
\r
335 SUB CX, 3 ; we skip the next 3
\r
336 ADD SI, 3 ; skip the bmp pixels
\r
337 LOOP SCAN_LOOP ; finish the scan
\r
339 MOV AX, nextPageRow
\r
340 ADD DI, AX ; go to the next row on screen
\r
342 ADD SI, AX ; go to the next row on bmp
\r
345 JNZ ROW_LOOP ; do all the rows
\r
346 ;-- end plane painting
\r
348 MOV AL, plane ; advance to the next plane
\r
350 AND AL, 0x0f ; mask the plane properly
\r
351 MOV plane, AL ; store the plane
\r
353 INC bmpOffset ; start bmp at the right spot
\r
356 JNZ PLANE_LOOP ; do all 4 planes
\r
361 modexDrawSpritePBuf(page_t *page, int x, int y, planar_buf_t *bmp) {
\r
362 /* draw the whole sprite */
\r
363 modexDrawSpritePBufRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);
\r
367 modexDrawSpritePBufRegion(page_t *page, int x, int y,
\r
368 int rx, int ry, int rw, int rh, planar_buf_t *bmp) {
\r
369 word poffset = (word)page->data + y*(page->width/4) + x/4;
\r
370 byte *data = bmp->plane[0];
\r
371 word bmpOffset = (word) data + ry * bmp->width + rx;
\r
374 byte plane = 1 << ((byte) x & 0x03);
\r
375 word scanCount = width/4 + (width%4 ? 1 :0);
\r
376 word nextPageRow = page->width/4 - scanCount;
\r
377 word nextBmpRow = (word) bmp->width - width;
\r
379 byte planeCounter = 4;
\r
382 MOV AX, SCREEN_SEG ; go to the VGA memory
\r
385 MOV DX, SC_INDEX ; point at the map mask register
\r
390 MOV DX, SC_DATA ; select the current plane
\r
394 ;-- begin plane painting
\r
395 MOV AX, height ; start the row counter
\r
396 MOV rowCounter, AX ;
\r
397 MOV DI, poffset ; go to the first pixel
\r
398 MOV SI, bmpOffset ; go to the bmp pixel
\r
400 MOV CX, width ; count the columns
\r
405 JNE DRAW_PIXEL ; draw non-zero pixels
\r
407 INC DI ; skip the transparent pixel
\r
411 MOVSB ; copy the pixel
\r
413 SUB CX, 3 ; we skip the next 3
\r
414 ADD SI, 3 ; skip the bmp pixels
\r
415 LOOP SCAN_LOOP ; finish the scan
\r
417 MOV AX, nextPageRow
\r
418 ADD DI, AX ; go to the next row on screen
\r
420 ADD SI, AX ; go to the next row on bmp
\r
423 JNZ ROW_LOOP ; do all the rows
\r
424 ;-- end plane painting
\r
426 MOV AL, plane ; advance to the next plane
\r
428 AND AL, 0x0f ; mask the plane properly
\r
429 MOV plane, AL ; store the plane
\r
431 INC bmpOffset ; start bmp at the right spot
\r
434 JNZ PLANE_LOOP ; do all 4 planes
\r
438 void modexDrawChar(page_t *page, int x/*for planar selection only*/, word t, word col, word bgcol, word addr)
\r
440 /* vertical drawing routine by joncampbell123.
\r
442 * optimize for VGA mode X planar memory to minimize the number of times we do I/O write to map mask register.
\r
443 * so, we enumerate over columns (not rows!) to draw every 4th pixel. bit masks are used because of the font bitmap.
\r
445 * NTS: addr defines what VGA memory address we use, "x" is redundant except to specify which of the 4 pixels we select in the map mask register. */
\r
453 m1 = 0x80; // left half
\r
454 m2 = 0x08; // right half
\r
455 for (colm=0;colm < 4;colm++) {
\r
457 modexSelectPlane(PLANE(plane));
\r
458 for (row=0;row < 8;row++) {
\r
459 fontbyte = romFontsData.l[row];
\r
460 vga_state.vga_graphics_ram[drawaddr ] = (fontbyte & m1) ? col : bgcol;
\r
461 vga_state.vga_graphics_ram[drawaddr+1] = (fontbyte & m2) ? col : bgcol;
\r
462 drawaddr += page->width >> 2;
\r
467 if ((++plane) == 4) {
\r