home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Compute! Gazette 1995 February
/
1995-02b.d64
/
lunar.src
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-09-20
|
3KB
|
171 lines
50 sys 700
100 *=$0a18 ; $1e52 for 128
110 ; set up init flight data
120 ldx #0
130 ilp lda ival,x
140 sta alt,x
150 inx
160 cpx #isz
170 bne ilp
180 ; big loop - recalculate, display
190 blp lda #$01
200 sta tog
210 ; wait until raster flyback
220 rpl lda $d012
230 cmp rst
240 sta rst
250 bcs rpl
260 lda $d011
270 bmi rpl
280 ; if no fuel, thrust = 0
290 zlp sed
300 lda #$30
310 ldx fue
320 bmi nof1
330 ; read keyboard, check 1 to 9
340 jsr $ffe4
350 cmp #$31
360 bcc noky
370 cmp #$3a
380 bcs noky
390 ; set new thrust values
400 nof1 sta th2
410 sta $04a8
420 and #$0f
430 sta th1
440 ldy #0
450 sec
460 sbc #5
470 bpl thx
480 ldy #$99
490 thx sta acc+1
500 sty acc
510 ; calculate accel, veloc, alt
520 noky ldx #5
530 fly clc
540 lda alt,x
550 adc alt+2,x
560 sta alt,x
570 dex
580 lda alt,x
590 adc alt+2,x
600 sta alt,x
610 lda #0
620 ldy alt+2,x
630 bpl pozz
640 lda #$99
650 pozz dex
660 adc alt,x
670 sta alt,x
680 dex
690 bpl fly
700 ; fuel = fuel - thrust
710 sec
720 lda fue+2
730 sbc th1
740 sta fue+2
750 lda fue+1
760 sbc #0
770 sta fue+1
780 lda fue
790 sbc #0
800 bpl gfu
810 ; set special value for no fuel
820 lda #$00
830 sta fue+2
840 sta fue+1
850 lda #$f0
860 gfu sta fue
870 dec tog
880 bpl noky
890 ; exit if landed/too high
900 lda alt
910 bmi exit
920 ldy alt+1
930 ; setup altitude display
940 jsr dig4
950 ldx #3
960 dgl1 lda dgs,x
970 sta $430,x
980 dex
990 bpl dgl1
1000 ; special code for "+/-" velocity
1010 ldy vel+1
1020 lda #$2b
1030 ldx vel
1040 bpl pvl
1050 sec
1060 lda #0
1070 sbc vel+1
1080 tay
1090 lda #0
1100 sbc vel
1110 tax
1120 lda #$2d
1130 pvl sta $0458
1140 txa
1150 ; setup velocity display
1160 jsr dig4
1170 ldx #2
1180 dgl2 lda dgs+1,x
1190 sta $459,x
1200 dex
1210 bpl dgl2
1220 lda fue
1230 ldy fue+1
1240 ; setup fuel display
1250 jsr dig4
1260 ldx #2
1270 dgl3 lda dgs+1,x
1280 sta $481,x
1290 dex
1300 bpl dgl3
1310 ; loop unless stop key pressed
1320 cld
1330 jsr $ffe1
1340 beq exit
1350 jmp blp
1360 ; exit back to basic
1370 exit cld
1380 rts
2000 ; this subroutine splits y/a
2010 ; into 4 decimal digits.
2020 ; note the re-entrant code.
2030 dig4 ldx #3
2040 pha
2050 tya
2060 jsr dig2
2070 pla
2080 dig2 pha
2090 and #$0f
2100 jsr dig1
2110 pla
2120 lsr a
2130 lsr a
2140 lsr a
2150 lsr a
2160 dig1 ora #$30
2170 sta dgs,x
2180 dex
2190 rts
3000 ; here are the initial flight
3010 ; parameters:
3020 ; altitude & velocy (3 bytes each)
3030 ival .byte $45,0,0, $99,$98,0
3040 ; accel & fuel (3 bytes each)
3050 .byte $99,$98,0, 8,0,0
3060 ; thrust as binary and ascii
3070 .byte 3,$33
4000 ; working variables, not loaded
4010 ; with the program.
4020 alt *=*+3 ; altitude
4030 vel *=*+3 ; velocity
4040 acc *=*+3 ; acceleration
4050 fue *=*+3 ; fuel
4060 th1 *=*+1 ; thrust binary
4070 th2 *=*+1 ; thrust ascii
4080 isz =*-alt ; size of init table
4090 rst *=*+1 ; raster tracker
4100 tog *=*+1 ; two-timing count
4110 dgs *=*+4 ; decimal digits