Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
bunker [2016/05/25 15:42]
ex_writer created
bunker [2016/05/26 20:06] (current)
ex_writer [Output]
Line 1: Line 1:
-====== Space Invaders Bunker ======+====== Space Invaders Bunker ​Snippet ​======
  
 The following (edited) code snippet is from Richard Degler'​s [[http://​www.ballyalley.com/​ml/​ml_source/​Space%20Invaders%20(197x)(Bally%20Mfg.%20Corp.)(proto)%5BDisassembly%5D.zip|disassembly]] [.zip] of the Bally Arcade Space Invaders prototype. The LOOP section demonstrates writing a single pattern (the bunker graphic) to the screen multiple times using the [[screen handler#​writp|WRITP]] UPI routine. The BUNKER section shows the referenced pattern block. The following (edited) code snippet is from Richard Degler'​s [[http://​www.ballyalley.com/​ml/​ml_source/​Space%20Invaders%20(197x)(Bally%20Mfg.%20Corp.)(proto)%5BDisassembly%5D.zip|disassembly]] [.zip] of the Bally Arcade Space Invaders prototype. The LOOP section demonstrates writing a single pattern (the bunker graphic) to the screen multiple times using the [[screen handler#​writp|WRITP]] UPI routine. The BUNKER section shows the referenced pattern block.
Line 55: Line 55:
 ===== Code Discussion ===== ===== Code Discussion =====
  
-In the [screen ​pattern hierarchy][[screen handler#​writp|WRITP]] is [position?], so it requires minimal preprocessing.+The first line loads register B with 4 for use as the loop counter. We want to draw the same bunker image four times along the bottom of the screen. Each will have identical y-coordinatesbut increasing x-coordinates (as we draw left to right), so the second line sets the initial value of register E to 10. As we'll see below, E will serve as storage for the x-coordinate when we call the pattern drawing routine.
  
-[pattern block requirements]+The third line marks the LOOP label, which is where the program will return again and again until B reaches 0. This also marks the point where we begin '​pre-loading'​ our registers with the arguments for our [[screen handler#​writp|WRITP]] call. WRITP is squarely in the middle of the [[screen write routines|screen writing routine]] hierarchy, meaning that it requires some housecleaning before we call it. 
 + 
 +Line 3 loads the address of the BUNKER ​pattern block in HL. WRITP assumes that the pattern size is stored //with the pattern block//, so the first two bytes at label BUNKER ($05, $0D) define the bunker graphic'​s width (5) and heigh (13) in bytes.  
 + 
 +Line 4 '​loads'​ the accumulator with the [[Magic Register]] settings for our pattern write. XOR A is a more efficient way to perform LD A,0 (though the former does change flags). In other words, we're sending a 0 to the Magic Register, indicating that we want to simply '​PLOP'​ the pattern onto the screen with no transformations. 
 + 
 +Line 5 load the y-coordinate that we'll use for for every bunker (65) in the D register, as required by WRITP. 
 + 
 +Lines 6 and 7 push the contents of DE and BC onto the stack to preserve their contents during the WRITP call. 
 + 
 +Line 8 finally invokes WRITP now that all the necessary pattern information is in place: the pattern'​s size, contents, position, and (lack of) transformations. 
 + 
 +Lines 10 and 11 pop the contents of BC and DE off the stack. 
 + 
 +Line 12 loads the value of the current x-coordinate from E to A, the following line adds 40 to that value, then line 14 puts the sum back into E. As a result, on the next iteration through the loop, the bunker'​s x-coordinate will be 40 pixels to the right of its previous location. 
 + 
 +The final line of the LOOP checks to see if B is zero. If not, the program proceeds to the beginning of LOOP; if so, program execution proceeds. 
 + 
 +[why choose WRITP vs. others] 
 + 
 +===== Output ===== 
 + 
 +{{bunker.png}}