home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / MTSRC13.ZIP / MTROOP.ASM < prev    next >
Assembly Source File  |  1995-05-11  |  5KB  |  320 lines

  1. ; MTROOP.ASM - Mars Trooper
  2. ;
  3. ; Created by Misha Koshelev for the 256-byte game contest on
  4. ; rec.games.programmer
  5. ;
  6. ; To compile (in Turbo Assembler):
  7. ;   TASM /M MTROOP
  8. ;   TLINK /T MTROOP
  9. ;
  10. ; This code is FREEWARE, however, if you want to use it in a
  11. ; commercial or shareware product, please contact me before you do so.
  12.  
  13. .MODEL TINY
  14. .386
  15. .CODE
  16. ORG 100h
  17.  
  18. ; Registers used:
  19. ;   BP - The address of the player
  20. ;   BX - Number of loops before player runs out of oxygen
  21. ;   DX - 1950h for scrolling
  22.  
  23. ; Background attributes
  24. GroundAttr EQU (6*16)+6
  25. ScoreAttr EQU (2*16)+5
  26.  
  27. Start:
  28.  
  29. ; ***
  30. ; INITIALIZE
  31. ; ***
  32.  
  33. ; Initialize the random-number seed
  34. mov ah, 2ch
  35. int 21h
  36. mov [RandSeed], dx
  37.  
  38. ; Set the segment to the text mode graphics memory
  39. push word ptr 0b800h
  40. pop es
  41.  
  42. ; Clear the screen with a red foreground
  43. mov ax, 0619h
  44. xor cx, cx
  45. mov dx, 1950h
  46. mov bh, 4
  47. int 10h
  48.  
  49. ; Set the X coordinate to the default coordinate of the player
  50. mov bp, (12*160)+80
  51.  
  52. ; Set the number of loops until player dies to 128
  53. mov bx, 128
  54.  
  55. ; ***
  56. ; MAIN LOOP
  57. ; ***
  58.  
  59. @@MainLoop:
  60.  
  61. ; Scroll the screen up one line (saving and restoring bx)
  62. push bx
  63. mov ax, 0601h
  64. mov bh, GroundAttr
  65. xor cx, cx
  66. int 10h
  67. pop bx
  68.  
  69. ; ***
  70. ; DRAW THE PLAYER'S "SCORE"
  71. ; ***
  72.  
  73. ; Increase the number of cycles the player has gone through
  74. mov ax, Score
  75. inc ax
  76. mov Score, ax
  77.  
  78. ; If the player has gone through 4 score letters, then move him down
  79. ; one line
  80. mov cx, ax
  81. sub cx, 512
  82. cmp cx, LScore
  83. jle @@NoModY
  84. add bp, 160
  85. mov LScore, ax
  86. @@NoModY:
  87.  
  88. ; And draw the number of times the player has gone through
  89. ; 128 cycles (the "Score")
  90. mov di, 158
  91. shr ax, 7
  92. stosb
  93.  
  94. ; Draw the background for the "Score"
  95. mov al, ScoreAttr
  96. stosb
  97.  
  98. ; ***
  99. ; SET A RANDOM NUMBER OF CHARACTERS TO CLEAR AS PASSABLE ON THE LINE
  100. ; ***
  101.  
  102. ; Get a random number between 0 and 31
  103. @@GetRand:
  104. call GetRandom
  105. and cl, 31
  106.  
  107. ; Make sure it is greater than 3, and if it is not, then get
  108. ; another random number
  109. cmp cl, 3
  110. jle @@GetRand
  111.  
  112. ; Double CX
  113. shl cl, 1
  114.  
  115. ; Subtract it from the center to find the starting coordinate
  116. mov di, (24*160)+80
  117. push di        ; Save DI for later use
  118. sub di, cx
  119.  
  120. ; Set the color to the blank color (Black background, Blue foreground)
  121. xor ax, ax
  122. mov ah, 4
  123.  
  124. ; Draw the blank spaces
  125. rep stosw
  126.  
  127. ; ***
  128. ; DRAW (IF NECESSARY) A FILLUP HEART
  129. ; ***
  130.  
  131. ; If a random number between 0 and 11 is 0, draw a fillup heart
  132.  
  133. ; Restore DI so that it is equal to (24*160)+80
  134. pop di
  135.  
  136. ; First, set the character to draw (and save it for later use)
  137. mov ax, 0003h
  138. push ax
  139.  
  140. call GetRandom
  141.  
  142. and cl, 11
  143. jnz @@NoHeart
  144.  
  145. ; Find a random position for the heart (14 pixels from the center max),
  146. ; and draw it
  147. call GetRandom
  148.  
  149. and cl, 14
  150. shl cl, 1
  151.  
  152. add di, cx
  153.  
  154. ; And draw it
  155. stosb
  156.  
  157. @@NoHeart:
  158.  
  159. ; ***
  160. ; SHOW HOW MUCH OXYGEN THE PLAYER HAS LEFT
  161. ; ***
  162.  
  163. ; Draw hearts for every eight units of oxygen the player has left
  164.  
  165. ; Get the number of loops into CX
  166. mov cx, bx
  167.  
  168. ; Divide the number of hearts by 8
  169. shr cx, 3
  170.  
  171. ; If the number of hearts is 0, then make it 1 (so it is shown as 1 heart)
  172. jnz @@LifeOk
  173.  
  174. inc cx
  175.  
  176. @@LifeOk:
  177.  
  178. ; Set di to (0,0)
  179. xor di, di
  180.  
  181. ; Set the attribute to draw (character already set from last part)
  182. mov ah, 14h
  183.  
  184. ; And draw the hearts
  185. rep stosw
  186.  
  187. ; Decrease the amount of oxygen left
  188. dec bx
  189.  
  190. ; ***
  191. ; KEYBOARD HANDLING
  192. ; ***
  193.  
  194. ; Get the shift key status
  195. mov ah, 2
  196. int 16h
  197.  
  198. ; Check the shift keys and move the player accordingly
  199. rcr ax, 1
  200. jnc @@CheckLShift
  201. add bp, 2
  202.  
  203. @@CheckLShift:
  204. rcr ax, 1
  205. jnc @@DoneKeyCheck
  206. sub bp, 2
  207.  
  208. @@DoneKeyCheck:
  209.  
  210. ; ***
  211. ; DRAWING THE PLAYER
  212. ; ***
  213.  
  214. ; Restore AX (so al is 3)
  215. pop ax
  216.  
  217. ; If the player is going onto a heart, give him 64 more cycles
  218. cmp BYTE PTR es:[bp], al     ;(al == 3)
  219. jnz @@NotOnHeart
  220.  
  221. add bx, 64
  222.  
  223. @@NotOnHeart:
  224.  
  225. ; Draw the player
  226. mov BYTE PTR es:[bp], 1
  227.  
  228. ; ***
  229. ; TIMER
  230. ; ***
  231.  
  232. ; Wait for the timer (vertical retrace) 3 times
  233. mov cx, ax
  234.  
  235. ; Save DX (which is used for scrolling)
  236. push dx
  237.  
  238. ; Set DX to the vertical retrace register
  239. mov dx, 3dah
  240.  
  241. @@TimerLoop:
  242. @@Wait1:
  243. in al, dx
  244. test al, 8
  245. jnz @@Wait1
  246. @@Wait2:
  247. in al, dx
  248. test al, 8
  249. jz @@Wait2
  250.  
  251. loop @@TimerLoop
  252.  
  253. ; Restore DX
  254. pop dx
  255.  
  256. ; Erase the previous player
  257. mov BYTE PTR es:[bp], cl
  258.  
  259. ; ***
  260. ; LOGIC
  261. ; ***
  262.  
  263. ; If the player has run out of oxygen, quit
  264. cmp bx, cx              ; Note: CX is 0
  265. jz @@EndProg
  266.  
  267. ; If the player has too much oxygen, quit (because his air tank burst)
  268. ; (this happens when the player has reached two rows of hearts)
  269. cmp bx, 1280
  270. jge @@EndProg
  271.  
  272. ; If the player is on a square he should not touch, quit
  273. cmp BYTE PTR es:[bp+1], GroundAttr
  274. jnz @@MainLoop
  275.  
  276. ; Exit
  277. @@EndProg:
  278.  
  279. ; ***
  280. ; DESTRUCTION
  281. ; ***
  282.  
  283. ; Clear the screen
  284. mov ax, 0003h
  285. int 10h
  286.  
  287. ; And show the score
  288. mov ax, Score
  289. shr ax, 7
  290. xor di, di
  291. stosb
  292.  
  293. ret
  294.  
  295. ; GetRandom - Returns a random byte. RandSeed must first be set to a random
  296. ; word.
  297. GetRandom PROC NEAR
  298.    mov cx, [RandSeed]
  299.    imul cx, 13A7h
  300.    inc cx
  301.    mov [RandSeed], cx
  302.  
  303.    mov cl, ch
  304.    mov ch, 0
  305.  
  306.    ret
  307. GetRandom ENDP
  308.  
  309. ; The variable in which the number of loops gone through is stored
  310. ; (a kind of score)
  311. Score DW 8320
  312.  
  313. ; The last score letter at which the player was moved down
  314. LScore DW 0
  315.  
  316. ; A random seed
  317. RandSeed DW ?
  318.  
  319. END Start
  320.