1 /*
2 BStone: A Source port of
3 Blake Stone: Aliens of Gold and Blake Stone: Planet Strike
4 
5 Copyright (c) 1992-2013 Apogee Entertainment, LLC
6 Copyright (c) 2013-2015 Boris I. Bendovsky (bibendovsky@hotmail.com)
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the
20 Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23 
24 
25 //
26 // Former D3_DASM2.ASM.
27 //
28 
29 
30 #include <cstdint>
31 
32 
33 enum DrawOptions {
34     DO_CEILING,
35     DO_FLOORING,
36     DO_CEILING_AND_FLOORING
37 }; // DrawOptions
38 
39 enum ShadingOptions {
40     SO_NONE,
41     SO_DEFAULT
42 }; // ShadingOptions
43 
44 
45 extern int mr_rowofs;
46 extern int mr_count;
47 extern int mr_xstep;
48 extern int mr_ystep;
49 extern int mr_xfrac;
50 extern int mr_yfrac;
51 extern int mr_dest;
52 
53 extern const uint8_t* shadingtable;
54 extern uint8_t* vga_memory;
55 
56 
57 uint8_t planepics[8192]; // 4k of ceiling, 4k of floor
58 
59 
generic_map_row(DrawOptions draw_options,ShadingOptions shading_options)60 static void generic_map_row(
61     DrawOptions draw_options,
62     ShadingOptions shading_options)
63 {
64     int xy_step = (mr_ystep << 16) | (mr_xstep & 0xFFFF);
65     int xy_frac = (mr_yfrac << 16) | (mr_xfrac & 0xFFFF);
66 
67     int screen_offset = mr_dest;
68 
69     for (int i = 0; i < mr_count; ++i) {
70         int xy = ((xy_frac >> 3) & 0x1FFF1F80) | ((xy_frac >> 25) & 0x7E);
71 
72         int pics_index = xy & 0xFFFF;
73 
74         if (draw_options == DO_CEILING ||
75             draw_options == DO_CEILING_AND_FLOORING)
76         {
77             uint8_t ceiling_index = planepics[pics_index + 0];
78 
79             uint8_t ceiling_pixel =
80                 (shading_options == SO_DEFAULT) ?
81                 shadingtable[ceiling_index] :
82                 ceiling_index;
83 
84             vga_memory[screen_offset] = ceiling_pixel;
85         }
86 
87         if (draw_options == DO_FLOORING ||
88             draw_options == DO_CEILING_AND_FLOORING)
89         {
90             uint8_t flooring_index = planepics[pics_index + 1];
91 
92             uint8_t flooring_pixel =
93                 (shading_options == SO_DEFAULT) ?
94                 shadingtable[flooring_index] :
95                 flooring_index;
96 
97             vga_memory[screen_offset + mr_rowofs] = flooring_pixel;
98         }
99 
100         ++screen_offset;
101         xy_frac += xy_step;
102     }
103 }
104 
MapLSRow()105 void MapLSRow()
106 {
107     generic_map_row(DO_CEILING_AND_FLOORING, SO_DEFAULT);
108 }
109 
F_MapLSRow()110 void F_MapLSRow()
111 {
112     generic_map_row(DO_FLOORING, SO_DEFAULT);
113 }
114 
C_MapLSRow()115 void C_MapLSRow()
116 {
117     generic_map_row(DO_CEILING, SO_DEFAULT);
118 }
119 
MapRow()120 void MapRow()
121 {
122     generic_map_row(DO_CEILING_AND_FLOORING, SO_NONE);
123 }
124 
F_MapRow()125 void F_MapRow()
126 {
127     generic_map_row(DO_FLOORING, SO_NONE);
128 }
129 
C_MapRow()130 void C_MapRow()
131 {
132     generic_map_row(DO_CEILING, SO_NONE);
133 }
134