Decoded: Sopwith (1984) by David L. Clark
Source file: SWSYMBOL.C
Beginner friendly, line-by-line code walkthrough by MaiZure

SWSYMBOL.C contains game graphics stored as CGA bitfields in low resolution.

Original code:
http://davidlclark.com/page/sopwith-source-code

Original code with line numbers
http://www.maizure.org/projects/decoded-sopwith/SWSYMBOL_linenum.txt


NOTE ON CGA FORMAT IN SOPWITH
In low resolution (4 color), we need 2 bits to represent each pixel. 
00 = Black
01 = Cyan
10 = Magenta
11 = White
Each byte represents 4 consecutive pixels in row major. To represent the four
pixel row of (Black, Magenta, Cyan, White), we would create the following byte:
00 10 01 11 == 0x27.

As for the color, all allied buildings are generally cyan while enemies are
magenta. Changing the color of an object is as easy as inverting the color bits:
NOT Black == White
NOT Cyan == Magenta

Objects that move freely in Sopwith, such as bombs, appear to rotate in arbitrary
directions. Well the rotations aren't arbitrary, they can be in 16 distinct
angles. The game doesn't perform rotations in the general sense because the
operation was far too expensive in 1984. Instead, it simply stores separate
images for each angle and draws the approptiate one. As you probably know, you
don't need 16 separate images, if you can set a flag to draw pixels in different
orders (flipping, etc). So ultimately, bombs store 8 distinct images, one for
each angle, which can be flipped to produce the other 8 angles.

1     Include the main game header (sw.h)
2     BLANK
3     COMMENT
4     COMMENT
5     COMMENT
6     COMMENT
7     COMMENT
8     COMMENT
9     COMMENT
10    COMMENT
11    COMMENT
12    COMMENT
13    COMMENT
14    BLANK
15    COMMENT
16    COMMENT
17    COMMENT
18    BLANK
19    BLANK

BOMB GRAPHICS
20    Defines the bomb at 8 different angles of 8x8 pixels (16 bytes/angle)
21    BLANK
22    COMMENT
23    COMMENT
24    COMMENT
25    COMMENT
26    COMMENT
27    COMMENT
28    COMMENT
29    COMMENT
30    COMMENT
31    COMMENT
32    COMMENT
33    Bytes 0-9 of the bomb at angle 0 (0 degrees)
34    Bytes 10-15 of the bomb at angle 0 (0 degrees)
35    Bytes 0-9 of the bomb at angle 1 (22.5 degrees)
36    Bytes 10-15 of the bomb at angle 1 (22.5 degrees)
37    Bytes 0-9 of the bomb at angle 2 (45 degrees)
38    Bytes 10-15 of the bomb at angle 2 (45 degrees)
39    Bytes 0-9 of the bomb at angle 3 (67.5 degrees)
40    Bytes 10-15 of the bomb at angle 3 (67.5 degrees)
41    Bytes 0-9 of the bomb at angle 4 (90 degrees)
42    Bytes 10-15 of the bomb at angle 4 (0 degrees)
43    Bytes 0-9 of the bomb at angle 5 (112.5 degrees)
44    Bytes 10-15 of the bomb at angle 6 (0 degrees)
45    Bytes 0-9 of the bomb at angle 6 (135 degrees)
46    Bytes 10-15 of the bomb at angle 7 (0 degrees)
47    Bytes 0-9 of the bomb at angle 7 (157.5 degrees)
48    Bytes 10-15 of the bomb at angle 7 (0 degrees)
49    End of bomb graphics
50    BLANK

TARGET GRAPHICS
51    Defines the graphics for the four types of game targets Each is 16x16
      (64 bytes) with only 1 angle needed.
52    BLANK
53    COMMENT
54    COMMENT
55    COMMENT
56    COMMENT
57    COMMENT
58    COMMENT
59    COMMENT
60    COMMENT
61    COMMENT
62    COMMENT
63    COMMENT
64    COMMENT
65    COMMENT
66    COMMENT
67    COMMENT
68    COMMENT
69    COMMENT
70    COMMENT
71    BLANK
72    BLANK
73    COMMENT
74    COMMENT
75    COMMENT
76    COMMENT
77    COMMENT
78    COMMENT
79    COMMENT
80    COMMENT
81    COMMENT
82    COMMENT
83    COMMENT
84    COMMENT
85    COMMENT
86    COMMENT
87    COMMENT
88    COMMENT
89    COMMENT
90    COMMENT
91    Bytes 0-9 of the HQ flag building
92    Bytes 10-19 of the HQ flag building
93    Bytes 20-29 of the HQ flag building
94    Bytes 30-39 of the HQ flag building
95    Bytes 40-49 of the HQ flag building
96    Bytes 50-59 of the HQ flag building
97    Bytes 60-63 of the HQ flag building
98    Bytes 0-9 of the factory building
99    Bytes 10-19 of the factory building
100   Bytes 20-29 of the factory building
101   Bytes 30-39 of the factory building
102   Bytes 40-49 of the factory building
103   Bytes 50-59 of the factory building
104   Bytes 60-63 of the factory building
105   Bytes 0-9 of the fuel tank
106   Bytes 10-19 of the fuel tank
107   Bytes 20-29 of the fuel tank
108   Bytes 30-39 of the fuel tank
109   Bytes 40-49 of the fuel tank
110   Bytes 50-59 of the fuel tank
111   Bytes 60-63 of the fuel tank
112   Bytes 0-9 of the tank
113   Bytes 10-19 of the tank
114   Bytes 20-29 of the tank
115   Bytes 30-39 of the tank
116   Bytes 40-49 of the tank
117   Bytes 50-59 of the tank
118   Bytes 60-63 of the tank
119   End of target graphics
120   BLANK

DESTROYED TARGET GRAPHICS
121   Defines the graphics for a destroyed target, 16x16, only 1 angle
122   BLANK
123   COMMENT
124   COMMENT
125   COMMENT
126   COMMENT
127   COMMENT
128   COMMENT
129   COMMENT
130   COMMENT
131   COMMENT
132   COMMENT
133   COMMENT
134   COMMENT
135   COMMENT
136   COMMENT
137   COMMENT
138   COMMENT
139   COMMENT
140   COMMENT
141   COMMENT
142   Bytes 0-9 of the destroyed target
143   Bytes 10-19 of the destroyed target
144   Bytes 20-29 of the destroyed target
145   Bytes 30-39 of the destroyed target
146   Bytes 40-49 of the destroyed target
147   Bytes 50-59 of the destroyed target
148   Bytes 60-63 of the destroyed target
149   End of destroyed target graphic definition
150   BLANK

EXPLOSION SHRAPNEL GRAPHICS
151   Defines 8 types of explosion shrapnel, each 8x8 for 16 bytes
152   BLANK
153   COMMENT
154   COMMENT
155   COMMENT
156   COMMENT
157   COMMENT
158   COMMENT
159   COMMENT
160   COMMENT
161   COMMENT
162   COMMENT
163   BLANK
164   COMMENT
165   COMMENT
166   COMMENT
167   COMMENT
168   COMMENT
169   COMMENT
170   COMMENT
171   COMMENT
172   COMMENT
173   COMMENT
174   BLANK
175   Bytes 0-9 of shrapnel type 0
176   Bytes 10-15 of shrapnel type 0
177   Bytes 0-9 of shrapnel type 1
178   Bytes 10-15 of shrapnel type 1
179   Bytes 0-9 of shrapnel type 2
180   Bytes 10-15 of shrapnel type 2
181   Bytes 0-9 of shrapnel type 3
182   Bytes 10-15 of shrapnel type 3
183   Bytes 0-9 of shrapnel type 4
184   Bytes 10-15 of shrapnel type 4
185   Bytes 0-9 of shrapnel type 5
186   Bytes 10-15 of shrapnel type 5
187   Bytes 0-9 of shrapnel type 6
188   Bytes 10-15 of shrapnel type 6
189   Bytes 0-9 of shrapnel type 7
190   Bytes 10-15 of shrapnel type 7
191   End of explosion shrapnel graphic definitions
192   BLANK

BIRD FLOCK GRAPHICS
193   Defines the graphics for flocks of birds, with 2 frames of 16x16 
194   BLANK
195   COMMENT
196   COMMENT
197   COMMENT
198   COMMENT
199   COMMENT
200   COMMENT
201   COMMENT
202   COMMENT
203   COMMENT
204   COMMENT
205   COMMENT
206   COMMENT
207   COMMENT
208   COMMENT
209   COMMENT
210   COMMENT
211   COMMENT
212   COMMENT
213   COMMENT
214   Bytes 0-9 of bird flock frame 0
215   Bytes 10-19 of bird flock frame 0
216   Bytes 20-29 of bird flock frame 0
217   Bytes 30-39 of bird flock frame 0
218   Bytes 40-49 of bird flock frame 0
219   Bytes 50-59 of bird flock frame 0
220   Bytes 60-63 of bird flock frame 0
221   Bytes 0-9 of bird flock frame 1
222   Bytes 10-19 of bird flock frame 1
223   Bytes 20-29 of bird flock frame 1
224   Bytes 30-39 of bird flock frame 1
225   Bytes 40-49 of bird flock frame 1
226   Bytes 50-59 of bird flock frame 1
227   Bytes 60-63 of bird flock frame 1
228   End of defition for bird flock graphics
229   BLANK

SINGLE BIRD GRAPHICS
230   Defines the graphics for a single bird in 2 frames of 2 bytes each
231   BLANK
232   COMMENT
233   COMMENT
234   COMMENT
235   COMMENT
236   COMMENT
237   Both bird frames
238   End of single bird graphic definition
239   BLANK

OXEN GRAPHICS
240   Defines the graphics for oxen in 2 frames, alive and dead (16x16 each)
241   BLANK
242   COMMENT
243   COMMENT
244   COMMENT
245   COMMENT
246   COMMENT
247   COMMENT
248   COMMENT
249   COMMENT
250   COMMENT
251   COMMENT
252   COMMENT
253   COMMENT
254   COMMENT
255   COMMENT
256   COMMENT
257   COMMENT
258   COMMENT
259   COMMENT
260   COMMENT
261   Bytes 0-9 of Schrödinger's oxen
262   Bytes 10-19 of the living oxen
263   Bytes 20-29 of the living oxen
264   Bytes 30-39 of the living oxen
265   Bytes 40-49 of the living oxen
266   Bytes 50-59 of the living oxen
267   Bytes 60-63 of the living oxen
268   Bytes 0-9 of the dead oxen
269   Bytes 10-19 of the dead oxen
270   Bytes 20-29 of the dead oxen
271   Bytes 30-39 of the dead oxen
272   Bytes 40-49 of the dead oxen
273   Bytes 50-59 of the dead oxen
274   Bytes 60-63 of the dead oxen
275   End of defition for oxen graphics
276   BLANK

GHOST GRAPHICS
277   Defines graphics for the ghosts in 1 frame of 8x8 
278   BLANK
279   COMMENT
280   COMMENT
281   COMMENT
282   COMMENT
283   COMMENT
284   COMMENT
285   COMMENT
286   COMMENT
287   COMMENT
288   COMMENT
289   COMMENT
290   Bytes 0-9 of the ghost
291   Bytes 10-5 of the ghost
292   End of ghost graphic definition
293   BLANK

BULLET HOLE GRAPHICS
294   Defines graphics for the bullet hole. 16x16 in 1 frame
295   BLANK
296   COMMENT
297   COMMENT
298   COMMENT
299   COMMENT
300   COMMENT
301   COMMENT
302   COMMENT
303   COMMENT
304   COMMENT
305   COMMENT
306   COMMENT
307   COMMENT
308   COMMENT
309   COMMENT
310   COMMENT
311   COMMENT
312   COMMENT
313   COMMENT
314   COMMENT
315   Bytes 0-9 of the bullet hole
316   Bytes 10-19 of the bullet hole
317   Bytes 20-29 of the bullet hole
318   Bytes 30-39 of the bullet hole
319   Bytes 40-49 of the bullet hole
320   Bytes 50-59 of the bullet hole
321   Bytes 60-63 of the bullet hole
322   End of graphics for the bullet hole
323   BLANK

BIRD SPLATTER GRAPHICS
324   Defines the graphics for a bird splatter on the screen: 32x32, 256 bytes
325   BLANK
326   COMMENT
327   COMMENT
328   COMMENT
329   COMMENT
330   COMMENT
331   COMMENT
332   COMMENT
333   COMMENT
334   COMMENT
335   COMMENT
336   COMMENT
337   COMMENT
338   COMMENT
339   COMMENT
340   COMMENT
341   COMMENT
342   COMMENT
343   COMMENT
344   COMMENT
345   COMMENT
346   COMMENT
347   COMMENT
348   COMMENT
349   COMMENT
350   COMMENT
351   COMMENT
352   COMMENT
353   COMMENT
354   COMMENT
355   COMMENT
356   COMMENT
357   COMMENT
358   COMMENT
359   COMMENT
360   COMMENT
361   Bytes 0-9 of the bird splatter
362   Bytes 10-19 of the bird splatter
363   Bytes 20-29 of the bird splatter
364   Bytes 30-39 of the bird splatter
365   Bytes 40-49 of the bird splatter
366   Bytes 50-59 of the bird splatter
367   Bytes 60-69 of the bird splatter
368   Bytes 70-79 of the bird splatter
369   Bytes 80-89 of the bird splatter
370   Bytes 90-99 of the bird splatter
371   Bytes 100-109 of the bird splatter
372   Bytes 110-119 of the bird splatter
373   Bytes 120-129 of the bird splatter
374   Bytes 130-139 of the bird splatter
375   Bytes 140-149 of the bird splatter
376   Bytes 150-159 of the bird splatter
377   Bytes 160-169 of the bird splatter
378   Bytes 170-179 of the bird splatter
379   Bytes 180-189 of the bird splatter
380   Bytes 190-199 of the bird splatter
381   Bytes 200-209 of the bird splatter
382   Bytes 210-219 of the bird splatter
383   Bytes 220-229 of the bird splatter
384   Bytes 230-239 of the bird splatter
385   Bytes 240-249 of the bird splatter
386   Bytes 250-256 of the bird splatter
387   End of graphic defition for the bird splatter
388   BLANK

MISSILE GRAPHICS
389   Declares the missile graphics at all 16 angles at 8x8
390   BLANK
391   COMMENT
392   BLANK
393   BLANK
394   COMMENT
395   COMMENT
396   COMMENT
397   COMMENT
398   COMMENT
399   COMMENT
400   COMMENT
401   COMMENT
402   COMMENT
403   COMMENT
404   Bytes 0-9 of the missile at angle 0 (0 degrees)
405   Bytes 10-15 of the missile at angle 0 (0 degrees)
406   Bytes 0-9 of the missile at angle 1 (22.5 degrees)
407   Bytes 10-15 of the missile at angle 1 (22.5 degrees)
408   Bytes 0-9 of the missile at angle 2 (45 degrees)
409   Bytes 10-15 of the missile at angle 2 (45 degrees)
410   Bytes 0-9 of the missile at angle 3 (67.5 degrees)
411   Bytes 10-15 of the missile at angle 3 (67.5 degrees)
412   Bytes 0-9 of the missile at angle 4 (90 degrees)
413   Bytes 10-15 of the missile at angle 4 (90 degrees)
414   Bytes 0-9 of the missile at angle 5 (112.5 degrees)
415   Bytes 10-15 of the missile at angle 5 (112.5 degrees)
416   Bytes 0-9 of the missile at angle 6 (135 degrees)
417   Bytes 10-15 of the missile at angle 6 (135 degrees)
418   Bytes 0-9 of the missile at angle 7 (157.5 degrees)
419   Bytes 10-15 of the missile at angle 7 (157.5 degrees)
420   Bytes 0-9 of the missile at angle 8 (180 degrees)
421   Bytes 10-15 of the missile at angle 8 (180 degrees)
422   Bytes 0-9 of the missile at angle 9 (202.5 degrees)
423   Bytes 10-15 of the missile at angle 9 (202.5 degrees)
424   Bytes 0-9 of the missile at angle 10 (225 degrees)
425   Bytes 10-15 of the missile at angle 10 (225 degrees)
426   Bytes 0-9 of the missile at angle 11 (247.5 degrees)
427   Bytes 10-15 of the missile at angle 11 (247.5 degrees)
428   Bytes 0-9 of the missile at angle 12 (270 degrees)
429   Bytes 10-15 of the missile at angle 12 (270 degrees)
430   Bytes 0-9 of the missile at angle 13 (292.5 degrees)
431   Bytes 10-15 of the missile at angle 13 (292.5 degrees)
432   Bytes 0-9 of the missile at angle 14 (315 degrees)
433   Bytes 10-15 of the missile at angle 14 (315 degrees)
434   Bytes 0-9 of the missile at angle 15 (337.5 degrees)
435   Bytes 10-15 of the missile at angle 15 (337.5 degrees)
436   End of missile graphics definition
437   BLANK

FLARE GRAPHICS
438   Defines the graphics for flares. Two frames at 8x8
439   BLANK
440   BLANK
441   COMMENT
442   BLANK
443   COMMENT
444   COMMENT
445   COMMENT
446   COMMENT
447   COMMENT
448   COMMENT
449   COMMENT
450   COMMENT
451   COMMENT
452   COMMENT
453   Bytes 0-9 of frame 0 of the flare
454   Bytes 10-15 of frame 0 of the flare
455   Bytes 0-9 of frame 1 of the flare
456   Bytes 10-15 of frame 1 of the flare
457   End of flare graphics definition
458   BLANK