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

SWDISP.C provides extended actions during drawing for individual object types.
Typically this is used to trigger additional effects, like sound.

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

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

1     COMMENT
2     COMMENT
3     BLANK
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    BLANK
17    COMMENT
18    COMMENT
19    COMMENT
20    COMMENT
21    COMMENT
22    COMMENT
23    COMMENT
24    COMMENT
25    COMMENT
26    Include the main game header (sw.h)
27    BLANK
28    BLANK
29    BLANK
30    Imports the world display list
31    Imports the object list
32    Imports the top object pointer
33    Imports the number of shot holes in the window
34    Imports the number of splattered birds on the window
35    Imports the splattered ox display flag
36    Imports the world splattered ox flag
37    Imports the graphic for a bullet hole
38    Imports the bird splat graphic
39    Imports the number of moves
40    BLANK
41    BLANK
42    BLANK
43    BLANK
44    BLANK
45    BLANK
46    BLANK

DISPLAY SCREEN SPLATTERS
47    Declares and defines dispplyr with 1 argument
48    Argument 1 is the input object pointer (player plane)
49    BLOCK START - dispplyr, during player draw, draw popups and play sound
50    If the player's plane has a shot hole..
51    Draw the shots on the screen
52    If the player's plane splatted a bird
53    Draw the splatted birds
54    Play the plane sound
55    BLOCK END - dispplyr
56    BLANK
57    BLANK
58    BLANK
59    BLANK
60    BLANK
61    BLANK

PLAY BOMB SOUNDS DURING DRAW
62    Declare and defines dispbomb with one argument
63    Argument 1 is a pointer to the bomb
64    BLOCK START - dispbomb, playing a bomb sound during draw
65    Declare a local object pointer
66    BLANK
67    If the bomb is valid and is falling...
68    Set the sound with positive falling speed
69    BLOCK END - dispbomb
70    BLANK
71    BLANK
72    BLANK
73    BLANK
74    BLANK

MISSILE AUXILLERY FUNCTION (NOP)
75    Declare and defines dispmiss with 1 argument
76    Argument 1 is a pointer to the missile
77    BLOCK START - dispmiss, not used
78    BLOCK END - dispmiss
79    BLANK
80    BLANK
81    BLANK
82    BLANK
83    BLANK

FLARE AUXILLERY FUNCTION (NOP)
84    Declare and defines dispburst with 1 arugment
85    Argument 1 is a pointer to the flare
86    BLOCK START - dispburst, not used
87    BLOCK END - dispburst
88    BLANK
89    BLANK
90    BLANK
91    BLANK
92    BLANK

PLAY EXPLOSION SOUNDS DURING DRAW
93    Declare and define dispexpl with 1 argument
94    Argument 1 is a pointer to the input object
95    BLOCK START - dispexpl, play the explosion sound
96    Declare a local pointer to an object
97    BLANK
98    If the explosion has occurred
99    Set the sound based on the number of explosions
100   BLOCK END - dispexpl
101   BLANK
102   BLANK
103   BLANK
104   BLANK
105   BLANK

PLAY PLANE SOUNDS DURING COMPUTER PLANE DRAW
106   Declare and define dispcomp with 1 arugment
107   Argument 1 is a pointer to the input computer plane
108   BLOCK START - dispcomp, plays the plane sound
109   Play the plane sound (see line 151)
110   BLOCK END - dispcomp
111   BLANK
112   BLANK
113   BLANK
114   BLANK

PLAY PLANE SOUNDS DURING MULTIPLAYER PLANE DRAW
115   Declare and define dispmult with 1 argument
116   Argument 1 is a pointer to the other player's plane
117   BLOCK START - dispmult, play the other player's plane sound
118   Play the plane sound
119   BLOCK END - dispmult
120   BLANK
121   BLANK
122   BLANK
123   BLANK

PLAY SHOOTING SOUNDS DURING TARGET DRAW
124   Declares and defines disptarg with 1 argument
125   Argument 1 is a pointer to the target object
126   BLOCK START - disptarg, plays sounds whenever a target is drawn
127   If the target is firing...
128   Play the shooting sound
129   BLOCK END - disptarg
130   BLANK
131   BLANK
132   BLANK
133   BLANK

BIRD FLOCK AUXILLERY FUNCTION (NOP)
134   Declares and defines dispflck with 1 argument
135   Argument 1 is a pointer to the flock of birds object
136   BLOCK START - dispflck, no action is performed
137   BLOCK END - dispflck
138   BLANK
139   BLANK
140   BLANK
141   BLANK

BIRD AUXILLERY FUNCTION (NOP)
142   Declares and defines dispbird with 1 argument
143   Argument 1 is a pointer to the bird object
144   BLOCK START - dispbird, no action is performed
145   BLOCK END - dispbird
146   BLANK
147   BLANK
148   BLANK
149   BLANK
150   BLANK

PLAY PLANE SOUNDS
151   Declares and defines plnsound with 1 argument
152   Argument 1 is a pointer to the plane object
153   BLOCK START - plnsound
154   Declare a local pointer to an object
155   BLANK
156   Point to the input object
157   If the plane is firing...
158   Play the plane sound.
159   Otherwise, the plane isn't firing so...
160   BLOCK START - switch on plane state
161   CASE plane is falling:
162   If the plane isn't moving downward (it must have hit something)
163   Play the sound for plane hitting
164   Otherwise, the plane is still falling..
165   Play the falling sound
166   End case for plane falling
167   BLANK
168   CASE plan is flying
169   Play the flying sound effect
170   End case for flying
171   BLANK
172   CASE plane is stalled or..
173   CASE plane is wounded or..
174   CASE plane is wounded and stalled..
175   Play the sound effect for plane hitting
176   End case for wounded
177   BLANK
178   CASE any other
179   End case for everyting else with no action
180   BLOCK END - switch on plane state
181   BLANK
182   BLOCK END - plnsound
183   BLANK
184   BLANK
185   BLANK
186   BLANK

DRAW AND UPDATE WORLD MINIMAP
187   Declares and defines dispwobj with 1 argument
188   Argument 1 is a pointer to a minimap display object
189   BLOCK START - dispwobj, draws the object on the minimap
190   Declares a local pointer to the input object (any mini visible type)
191   Declares a local pointer to the minimap array indexed by objects
192   Declare local variables for x, y and plot value
193   BLANK
194   Point to the input object
195   Point to the minimap object array element indexed by the object
196   BLANK
197   If the object is actively plotting to the map
198   Plot it's XOR to the map (clear it)
199   BLANK
200   If the objcet has finished..
201   Then it needs to draw nothing more
202   Otherwise, the object has been cleared, but is still around...do more..
203   Save the color byte (in the world map) by offsetting center by..
204   Object's world x position...
205   Scaled in to the minimap
206   and by the object's y position...
207   offset by its x position..
208   Scaled in to the minimap
209   With the object's color
210   BLANK
211   If black or white was plotted (then a drawing collision occurred)
212   Then increment the next xor cycle, skip it
213   Exit function, don't draw collisions
214   End if black or white
215   Commit the point to the world map
216   Don't set an XOR
217   BLOCK END - Calculate and draw to map
218   BLOCK END - dispwobj
219   BLANK
220   BLANK
221   Declare a static seed value
222   BLANK
223   Declare and define randsd with no arguments
224   BLOCK START - randsd, changes the random seed
225   Changes the random seed and if it has no meaningful value...
226   Reset the random seed to initial value
227   BLOCK END - randsd
228   BLANK
229   BLANK
230   BLANK

DRAW BULLET HOLES ON SCREEN
231   Declare and define dispwindshot with no arguments
232   BLOCK START - dispwindshot, draws bullet holes on screen
233   Declare a local object
234   BLANK
235   Set the object to dummy - no physical world interaction
236   Object dimensions are 16x16
237   Object color/team is cyan
238   Set the object sprite to bullet hole
239   BLOCK START - Draw bullet hole loop
240   Change the random seed
241   Draw the bullet hole at randomseed modulus screen width...
242   and at random position y modulus screen height (offset within screen)
243   and with the referenced object
244   BLOCK END - Draw bullet hole loop
245   BLOCK END - randsd
246   BLANK
247   BLANK
248   BLANK

DRAW SPLATTERED BIRD ON SCREEN
249   Declare and define dispsplaybird with no arguments
250   BLOCK START - dispsplatbird, draws bird splatters on screen
251   Declare a local object
252   BLANK
253   Set the object type to dummy - no world interaction
254   Set the object size to 32x32
255   Set the object color/team to magenta
256   Set the object graphic to bird splat
257   BLOCK START - Loop while drawing splattered birds
258   Change the random seed
259   Draw the object at x position based on seed modulus screen width
260   Draw the object at y position based on seed modulus screen height
261   Reference the object to draw
262   BLOCK END - Loop while drawing splattered birds
263   BLOCK END - dispsplatbird
264   BLANK
265   BLANK
266   BLANK
267   BLANK

DRAW SPLATTERED OXEN ON SCREEN (ALL MAGENTA)
268   Declare and define dispoxsplat with no arguments
269   BLOCK START - dispoxsplat, draw the splattered oxen (magenta screen)
270   Declare a local object pointer
271   Declare a local iterator
272   BLANK
273   Starting from the base address of the screen segment, 0xB800 ...
274   Set all of the even raster lines to 0xAA, which is 4 magenta pixels
275   Starting from the odd line address of the screen segment, 0xC800 ...
276   Set all of the odd raster lines to 0xAA, which is 4 magenta pixels
277   Reset the trigger ox splatter flag
278   Set the world ox splattered flag
279   BLANK
280   Set the object pointer to the head of the object list
281   Loop through all game objects
282   Set object draw/delete flag to 0 (prevents redraw over ox splatter)
283   BLOCK EOF - dispoxsplat
284   EOF