1 /*
2
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 */
19 /*
20 * $Source: n:/project/lib/src/2d/RCS/fl8clear.c $
21 * $Revision: 1.3 $
22 * $Author: kaboom $
23 * $Date: 1993/10/19 09:50:18 $
24 *
25 * Routines for clearing a flat 8 canvas.
26 *
27 * This file is part of the 2d library.
28 *
29 * $Log: fl8clear.c $
30 * Revision 1.3 1993/10/19 09:50:18 kaboom
31 * Replaced #include "grd.h" with new headers split from grd.h.
32 *
33 * Revision 1.2 1993/10/08 01:15:08 kaboom
34 * Changed quotes in #include liness to angle brackets for Watcom problem.
35 *
36 * Revision 1.1 1993/02/16 14:14:00 kaboom
37 * Initial revision
38 */
39
40 #include "cnvdat.h"
41 #include "lg.h"
42 #include <string.h>
43
44 /* clear a flat8 canvas. */
flat8_clear(long color)45 void flat8_clear(long color) {
46
47 uchar *p;
48 int h;
49 int w;
50 int row;
51 ushort short_val;
52 double double_stack, doub_vl;
53 uint firstbytes, middoubles, lastbytes, fb, md, lb;
54 uchar *dst;
55 double *dst_doub;
56 uint temp;
57
58 color &= 0x00ff;
59 p = grd_bm.bits;
60 h = grd_bm.h;
61 w = grd_bm.w;
62 row = grd_bm.row;
63
64 if (w >= 16) // only do doubles if at least two of them (16 bytes)
65 {
66 // get a 64 bit version of color in doub_vl
67 short_val = (uchar)color | color << 8;
68 color = (int)short_val | ((int)short_val) << 16;
69 *(int *)(&double_stack) = color;
70 *((int *)(&double_stack) + 1) = color;
71 doub_vl = double_stack;
72
73 lastbytes = w;
74 firstbytes = (intptr_t)p & 3;
75 if (firstbytes != 0) // check for boundary problems
76 lastbytes -= firstbytes;
77
78 middoubles = lastbytes >> 3;
79 lastbytes -= middoubles << 3;
80 } else {
81 lastbytes = w;
82 middoubles = 0;
83 }
84
85 fb = firstbytes, md = middoubles, lb = lastbytes;
86 while (h--) {
87 // MLA - inlined this code
88 memset(p, color, w);
89 /*{
90 firstbytes = fb,middoubles = md,lastbytes = lb;
91 dst = p;
92
93 if (middoubles)
94 {
95 // first get to a 4 byte boundary
96 while (firstbytes--) *(dst++) = color;
97 dst_doub = (double *) dst;
98
99 // now do doubles
100 while (middoubles--) *(dst_doub++) = doub_vl;
101 dst = (uchar *) dst_doub;
102 }
103
104 // do remaining bytes
105 while (lastbytes--) *(dst++) = color;
106 }*/
107
108 p += row;
109 }
110 }
111