home *** CD-ROM | disk | FTP | other *** search
/ Compute! Gazette 1995 February / 1995-02b.d64 / lunar.src (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  3KB  |  171 lines

  1. 50 sys 700
  2. 100 *=$0a18  ; $1e52 for 128
  3. 110 ; set up init flight data
  4. 120  ldx #0
  5. 130 ilp lda ival,x
  6. 140  sta alt,x
  7. 150  inx
  8. 160  cpx #isz
  9. 170  bne ilp
  10. 180 ; big loop - recalculate, display
  11. 190 blp lda #$01
  12. 200  sta tog
  13. 210 ; wait until raster flyback
  14. 220 rpl lda $d012
  15. 230  cmp rst
  16. 240  sta rst
  17. 250  bcs rpl
  18. 260  lda $d011
  19. 270  bmi rpl
  20. 280 ; if no fuel, thrust = 0
  21. 290 zlp sed
  22. 300  lda #$30
  23. 310  ldx fue
  24. 320  bmi nof1
  25. 330 ; read keyboard, check 1 to 9
  26. 340  jsr $ffe4
  27. 350  cmp #$31
  28. 360  bcc noky
  29. 370  cmp #$3a
  30. 380  bcs noky
  31. 390 ; set new thrust values
  32. 400 nof1 sta th2
  33. 410  sta $04a8
  34. 420  and #$0f
  35. 430  sta th1
  36. 440  ldy #0
  37. 450  sec
  38. 460  sbc #5
  39. 470  bpl thx
  40. 480  ldy #$99
  41. 490 thx sta acc+1
  42. 500  sty acc
  43. 510 ; calculate accel, veloc, alt
  44. 520 noky ldx #5
  45. 530 fly clc
  46. 540  lda alt,x
  47. 550  adc alt+2,x
  48. 560  sta alt,x
  49. 570  dex
  50. 580  lda alt,x
  51. 590  adc alt+2,x
  52. 600  sta alt,x
  53. 610  lda #0
  54. 620  ldy alt+2,x
  55. 630  bpl pozz
  56. 640  lda #$99
  57. 650 pozz dex
  58. 660  adc alt,x
  59. 670  sta alt,x
  60. 680  dex
  61. 690  bpl fly
  62. 700 ; fuel = fuel - thrust
  63. 710  sec
  64. 720  lda fue+2
  65. 730  sbc th1
  66. 740  sta fue+2
  67. 750  lda fue+1
  68. 760  sbc #0
  69. 770  sta fue+1
  70. 780  lda fue
  71. 790  sbc #0
  72. 800  bpl gfu
  73. 810 ; set special value for no fuel
  74. 820  lda #$00
  75. 830  sta fue+2
  76. 840  sta fue+1
  77. 850  lda #$f0
  78. 860 gfu sta fue
  79. 870  dec tog
  80. 880  bpl noky
  81. 890 ; exit if landed/too high
  82. 900  lda alt
  83. 910  bmi exit
  84. 920  ldy alt+1
  85. 930 ; setup altitude display
  86. 940  jsr dig4
  87. 950  ldx #3
  88. 960 dgl1 lda dgs,x
  89. 970  sta $430,x
  90. 980  dex
  91. 990  bpl dgl1
  92. 1000 ; special code for "+/-" velocity
  93. 1010  ldy vel+1
  94. 1020  lda #$2b
  95. 1030  ldx vel
  96. 1040  bpl pvl
  97. 1050  sec
  98. 1060  lda #0
  99. 1070  sbc vel+1
  100. 1080  tay
  101. 1090  lda #0
  102. 1100  sbc vel
  103. 1110  tax
  104. 1120  lda #$2d
  105. 1130 pvl sta $0458
  106. 1140  txa
  107. 1150 ; setup velocity display
  108. 1160  jsr dig4
  109. 1170  ldx #2
  110. 1180 dgl2 lda dgs+1,x
  111. 1190  sta $459,x
  112. 1200  dex
  113. 1210  bpl dgl2
  114. 1220  lda fue
  115. 1230  ldy fue+1
  116. 1240 ; setup fuel display
  117. 1250  jsr dig4
  118. 1260  ldx #2
  119. 1270 dgl3 lda dgs+1,x
  120. 1280  sta $481,x
  121. 1290  dex
  122. 1300  bpl dgl3
  123. 1310 ; loop unless stop key pressed
  124. 1320  cld
  125. 1330  jsr $ffe1
  126. 1340  beq exit
  127. 1350  jmp blp
  128. 1360 ; exit back to basic
  129. 1370 exit cld
  130. 1380  rts
  131. 2000 ; this subroutine splits y/a
  132. 2010 ;  into 4 decimal digits.
  133. 2020 ;  note the re-entrant code.
  134. 2030 dig4 ldx #3
  135. 2040  pha
  136. 2050  tya
  137. 2060  jsr dig2
  138. 2070  pla
  139. 2080 dig2 pha
  140. 2090  and #$0f
  141. 2100  jsr dig1
  142. 2110  pla
  143. 2120  lsr a
  144. 2130  lsr a
  145. 2140  lsr a
  146. 2150  lsr a
  147. 2160 dig1 ora #$30
  148. 2170  sta dgs,x
  149. 2180  dex
  150. 2190  rts
  151. 3000 ; here are the initial flight
  152. 3010 ; parameters:
  153. 3020 ; altitude & velocy (3 bytes each)
  154. 3030 ival .byte $45,0,0, $99,$98,0
  155. 3040 ; accel & fuel (3 bytes each)
  156. 3050  .byte $99,$98,0, 8,0,0
  157. 3060 ; thrust as binary and ascii
  158. 3070  .byte 3,$33
  159. 4000 ; working variables, not loaded
  160. 4010 ;    with the program.
  161. 4020 alt *=*+3   ; altitude
  162. 4030 vel *=*+3   ; velocity
  163. 4040 acc *=*+3   ; acceleration
  164. 4050 fue *=*+3   ; fuel
  165. 4060 th1 *=*+1   ; thrust binary
  166. 4070 th2 *=*+1   ; thrust ascii
  167. 4080 isz =*-alt  ; size of init table
  168. 4090 rst *=*+1   ; raster tracker
  169. 4100 tog *=*+1   ; two-timing count
  170. 4110 dgs *=*+4   ; decimal digits
  171.