/[projet1]/users/chema/TINE/tineloop.s
Defence Force logotype

Contents of /users/chema/TINE/tineloop.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 266 - (show annotations)
Mon Feb 8 22:12:53 2010 UTC (9 years, 8 months ago) by Chema
File size: 31288 byte(s)
many small changes and bug huntings. Newest line routine, removed clearing the laser vertices from the main loop...
1 ; main loop and other high-level functions
2
3 #include "ships.h"
4 #include "params.h"
5 #include "tine.h"
6 #include "main.h"
7
8 invert .byt 00
9 frame_time .byt 00
10
11
12 // select where the space for object records starts...
13 #define OBS ($fffa-MAXOBJS*ObjSize)
14 #echo Object records start at
15 #print OBS
16 #echo
17
18 _init_tine
19 .(
20 lda #<OBS ;Object records
21 ldy #>OBS
22 jsr Init3D
23
24 jsr INITSTAR
25 jmp _GenerateTables ;; /* For Wireframe*/
26
27 .)
28
29
30 LoadDefaultCommander
31 .(
32 ldx #(_default_commander_end - _default_commander)-1
33 loop
34 lda _default_commander,x
35 sta _name,x
36 dex
37 bpl loop
38
39 ldx #7
40 stx _dest_num
41
42 rts
43 .)
44
45 init_view_ship
46 .(
47 jsr _EmptyObj3D
48 ; Create our ship
49 lda #0
50 sta _PosX
51 sta _PosX+1
52 sta _PosY
53 sta _PosY+1
54 sta _PosZ
55 sta _PosZ+1
56 lda #<_PosX
57 sta tmp0
58 lda #>_PosX
59 sta tmp0+1
60 lda #SHIP_DEBRIS ;)
61 jsr AddSpaceObject
62
63 ; Create the ship to watch
64 lda #<4100
65 sta _PosZ
66 lda #>4100
67 sta _PosZ+1
68 jsr _gen_rnd_number
69 and #%1111
70 clc
71 adc #15
72 sta shiptype+1
73 jsr AddSpaceObject
74 lda #$60
75 sta screen
76 lda #$a0
77 sta screen+1
78 shiptype
79 ldx #0 ; SMC
80 jmp name_ship
81 .)
82
83 init_intro
84 .(
85 jsr _DoubleBuffOff
86 jsr clr_hires
87 jsr load_frame
88 jsr set_ink2
89 jsr _DoubleBuffOn
90 jmp init_view_ship
91 .)
92
93 animate
94 .(
95 ldx #0
96 stx frame_time
97 jsr CalcView
98 jsr SortVis
99 jsr clr_hires2
100 jsr DrawAllVis ;Draw objects
101 jsr print_inflight_message
102 jsr dump_buf
103
104 ldx #1
105 jsr SetCurOb
106 sec
107 jsr Pitch
108 clc
109 jsr Yaw
110 clc
111 jsr Roll
112 clc
113 jsr Roll
114
115 inc frame_number
116
117 lda frame_number
118 cmp #30
119 bcs nonearer
120 ldx #0
121 jsr SetCurOb
122 lda #32
123 jmp MoveForwards
124 nonearer
125 cmp #(30+150)
126 bcc keep
127 cmp #(30+150+30)
128 bcc further
129 lda #0
130 sta frame_number
131 jmp init_view_ship
132 further
133 ldx #0
134 jsr SetCurOb
135 lda #$e0
136 jmp MoveForwards
137
138 keep
139 rts
140 .)
141
142 end_intro
143 .(
144 lda #0
145 sta message_delay
146 jsr _DoubleBuffOff
147 ; KLUDGE
148 lda #0
149 sta RADOBJ+1
150 jsr save_frame
151 jmp _EmptyObj3D
152 .)
153
154 /*
155 _init_screen
156 .(
157 ldx #2
158 jsr flight_message
159 jsr init_intro
160
161 lda #0
162 sta frame_number
163 loop
164 jsr animate
165 ; Check keyboard press
166 jsr ReadKeyNoBounce
167 cmp #"Y"
168 bne noY
169 ;jsr LoadSavedCommander
170 jmp end
171 noY
172 cmp #"N"
173 bne loop
174 jsr LoadDefaultCommander
175 end
176 ;jsr SndPic
177 jsr NewPlayerShip
178 jsr InitPlayerShip
179 jmp end_intro
180
181 .)
182
183 */
184
185 _init_screen2
186 .(
187
188 jsr LoadDefaultCommander
189 jsr NewPlayerShip
190 ;jsr InitPlayerShip
191
192 ldx #3
193 jsr flight_message
194
195 jsr init_intro
196
197 lda #0
198 sta frame_number
199 loop
200 jsr animate
201 ; Check keyboard press
202 jsr ReadKeyNoBounce
203 cmp #" "
204 bne loop
205 ;jsr SndPic
206 jmp end_intro
207 .)
208
209
210
211 init_front_view
212 .(
213 lda #0
214 sta yawing
215 sta pitching
216 sta rolling
217
218 jsr patch_invert_code
219
220 jsr clr_hires
221 jsr load_frame
222
223 jsr set_ink2
224
225 +_patch_launch_msg
226 lda #0 ;SMC
227 bne nomsg
228
229 ldx #6*8
230 ldy #40
231 jsr gotoXY
232 ldx #>str_launch
233 lda #<str_launch
234 jsr print
235 jsr wait
236 nomsg
237 lda #1
238 sta _patch_launch_msg+1
239
240 jsr _DoubleBuffOn
241
242 ;jmp _FirstFrame ; Let the program flow...
243 .)
244 _FirstFrame
245 .(
246 jsr update_all_controls
247
248 lda #PDIST_MASSLOCK
249 sta _planet_dist
250
251 lda #0
252 sta frame_time
253 sta counter
254
255 jsr clr_hires2
256
257 lda invert
258 beq noinvert
259 jsr invertZ
260 noinvert
261
262 ldx VOB ;Calculate view
263 jsr SetRadar
264 jsr CalcView
265 jsr SortVis ;Sort objects
266 jsr DrawAllVis ;Draw objects
267 jsr DrawRadar
268 jsr set_compass
269 jsr set_planet_distance
270
271 lda invert
272 beq noinvert2
273 jsr invertZ
274 noinvert2
275
276 jsr PatchLaserDraw
277 jsr clear_vertex
278 jmp dump_buf
279 .)
280
281
282 frame_number .byt 0
283 player_in_control .byt $0
284 escape_pod_launched .byt 0
285 attr_changed .byt 0
286
287 invertZ
288 .(
289 ldx VOB
290 jsr GetObj
291 clc
292 adc #ObjMat
293 bcc cont
294 iny
295 cont
296 sta tmp0
297 sty tmp0+1
298
299 ldy #6
300 ldx #3
301 loop
302 sec
303 lda #0
304 sbc (tmp0),y
305 sta (tmp0),y
306 iny
307 dex
308 bne loop
309
310 rts
311 .)
312
313
314 set_planet_distance
315 .(
316 ; Check distance to planet
317 ldx VOB
318 jsr SetCurOb
319 ldx #2 ;Planet
320 jsr substract_positions
321 jsr getnorm ; Calc distance as A=abs(x)|abs(y)|abs(z)
322 lda op1+1 ; Get high byte
323 sta _planet_dist
324 rts
325 .)
326
327
328 wait
329 .(
330 lda #0
331 sta counter
332 loop
333 lda counter
334 cmp #25
335 bcc loop
336 rts
337 .)
338
339 dock
340 .(
341 ; Docking ship... must call docking sequence
342 lda _current_screen
343 cmp #SCR_FRONT
344 beq l1
345 jsr frontview
346 l1
347 lda invert
348 beq l2
349 jsr rearview
350 l2
351 jsr _DoubleBuffOff
352 jsr save_frame
353 dec _docked
354
355 ldx #6*8;12
356 ldy #40
357 jsr gotoXY
358 ldx #>str_land
359 lda #<str_land
360 jsr print
361 ; This prints the wrong name... the destination hypersystem
362 ; jsr gs_planet_name
363 jsr wait
364 jsr wait
365 jsr info
366 jmp _TineLoop
367 .)
368
369 _TineLoop
370 .(
371 lda _docked
372 beq loop
373 jsr ProcessKeyboard
374 jmp _TineLoop
375
376 loop
377 ; If we have changed ink color, put it back to white
378 +_patch_set_ink
379 nop
380 nop
381 nop
382
383 ; Call ship tactics
384 jsr _Tactics
385
386 ; If distance with planet is short, then dock player
387 lda _planet_dist
388 cmp #06
389 bcc dock
390
391 ; Process user's controls
392 jsr ProcessKeyboard
393
394 ; Trick to invert object's Z in case of rear view
395 +_patch_invertZa
396 jsr invertZ
397
398 ; Set the radar
399 ldx VOB
400 jsr SetCurOb
401 jsr SetRadar
402
403 ; Calculate visible ships
404 jsr CalcView
405 jsr SortVis
406
407 ; If not in front view, don't draw
408 lda _current_screen
409 cmp #SCR_FRONT
410 bne nodraw
411
412 ; Prepare counter for frame time and get last value
413 lda counter
414 sta frame_time
415 ldx #0
416 stx counter
417
418 ; If too high, skip frame
419 cmp #MAXFRAMETIME2
420 bcs nodraw
421
422 ; Move the stars, even if not drawing, as they are fake
423 jsr move_stars
424
425 ;****** START OF DRAWING SECTION ******
426 ; Clear the off-screen buffer
427 jsr clr_hires2
428
429 ; Draw all objects
430 jsr DrawAllVis
431
432 ; Plot the starfield, the crosshair and any lasers (ours and from others)
433 jsr PlotStars
434 jsr _DrawCrosshair
435 jsr _Lasers
436
437 +_patch_laser_fired
438 nop
439 nop
440 nop
441
442 ; Print any HUD message
443 lda message_delay
444 beq nomessage
445 dec message_delay
446 jsr print_inflight_message
447 nomessage
448
449 #ifdef DBGVALUES
450 jsr print_dbgval
451 #endif
452
453 ; Print either front or rear view message on top
454 ; This should be in a subroutine to keep code structured,
455 ; but...
456 dec print2dbuffer
457 ldx #(15*6)
458 ldy #0
459 jsr gotoXY
460
461 +_patch_invert_msg
462 lda #<str_frontview
463 ldx #>str_frontview
464
465 jsr print
466 inc print2dbuffer
467
468 ; Everything drawn, now dump the buffer
469 jsr dump_buf
470
471 ;****** END OF DRAWING SECTION ******
472
473 ; Here we update radar and compass. This is outside the drawing section
474 ; because we are not double buffering, but if we are not drawing we should not
475 ; update these also
476
477 lda frame_number
478 lsr
479 bcc nodraw
480
481 ; Erase & Draw radar
482 jsr EraseRadar
483 jsr DrawRadar
484
485 ; Update compass
486 lda _planet_dist
487 cmp #PDIST_TOOFAR2
488 bcs nocompass
489 jsr update_compass
490 jmp endcompass
491 nocompass
492 jsr clear_compass
493 endcompass
494
495
496 ; If not drawing (screens different than front/rear views, or frame skipping)
497 ; jump here.
498
499 nodraw
500 ; Trick to invert object's Z in case of rear view
501 +_patch_invertZb
502 jsr invertZ
503
504 ; If player is in control, check collisions
505 lda player_in_control
506 beq cont
507 jsr _CheckHits ; Should be called after DrawAllVis!!!!
508
509 ; Dampen rotations
510 jsr damp
511 lda #0
512 sta yawing
513 sta pitching
514 sta rolling
515
516 ; If in front view, perform rolls
517 lda _current_screen
518 cmp #SCR_FRONT
519 bne cont
520 jsr dorolls
521 cont
522
523 ; Move other ships
524 jsr _MoveShips
525
526 ; Perform timely checks
527 ; Seldom checks. Every 32 frames
528
529 lda frame_number
530 and #%11111
531 bne qchecks
532 lda message_delay
533 bne noenmsg
534
535 ; "Energy Low" message
536 lda _energy+1
537 cmp #30
538 bcs noenmsg
539 ldx #STR_ENERGY_LOW
540 jsr flight_message
541 noenmsg
542
543 lda bounty_am
544 ora bounty_am+1
545 beq nomsgbounty
546 jsr flight_message_bounty
547 lda #0
548 sta bounty_am
549 sta bounty_am+1
550 nomsgbounty
551
552 qchecks
553 ; More often checks. Every 8 frames, basically
554 lda frame_number
555 and #%111
556 beq checkthings
557 jmp cont2
558
559 checkthings
560 ; Check escape pod
561 lda escape_pod_launched
562 beq next
563
564 lda player_in_control
565 ora message_delay
566 bne next
567
568 dec player_in_control
569 inc escape_pod_launched
570 jmp dock
571 next
572
573 ; Calculate planet distance
574 jsr set_planet_distance
575
576 ; Setup planet distance light indicator
577 jsr planet_light
578
579 ; Start with energy and shields: recharge
580 lda _energy+1
581 bmi no_energy
582 beq no_energy
583
584 cmp _p_maxenergy
585 bcs noinc_energy
586 inc _energy+1
587 ;bne done_energy ; branches allways
588 noinc_energy
589 ; If redirecting power to lasers, don't recharge
590 lda _ptla
591 bne done_energy
592
593 lda _front_shield
594 cmp #22
595 beq done_front
596 inc _front_shield
597 cmp #21
598 beq done_front
599 ; If redirecting power to shields, double recharge
600 lda _ptsh
601 beq done_front
602 inc _front_shield
603 done_front
604 lda _rear_shield
605 cmp #22
606 beq done_rear
607 inc _rear_shield
608 cmp #21
609 beq done_rear
610 ; If redirecting power to shields, double recharge
611 lda _ptsh
612 beq done_rear
613 inc _rear_shield
614 done_rear
615 jsr update_shields_panel
616 done_energy
617 jmp locking
618 no_energy
619
620 ; We should be dead here
621
622 ; Check message has been displayed for some time
623 ; and that we are not in control of the ship
624 lda message_delay
625 ora player_in_control
626 bne locking
627
628 ; Return from main loop here.
629 rts
630
631
632 locking
633 ; Locking computer
634 lda player_in_control
635 beq notarget
636 lda _missile_armed
637 bpl notarget ; Nothing to do if already locked or unarmed
638 jsr FindTarget
639 lda _ID
640 beq notarget
641 sta _missile_armed
642
643 ; Print Target Locked message
644 ldx #STR_TARGET_LOCKED
645 jsr flight_message
646 jsr update_missile_panel
647 notarget
648
649 ; Cooling lasers. If redirecting power to shields, don't cool
650 lda _ptsh
651 bne notemp
652 ldx LaserTemperature
653 beq notemp
654 dex
655 beq nodoubl
656 ; If redirecting power to laser cooling, double cooling
657 lda _ptla
658 beq nodoubl
659 dex
660 nodoubl
661 stx LaserTemperature
662 donelaser
663 jsr update_temperature_panel
664 notemp
665 lda _ecm_counter
666 beq noecm
667 dec _ecm_counter
668 bne noecm
669 jsr update_ecm_panel
670 noecm
671
672 ; ...
673
674 cont2
675 ; Check for new encounters
676 lda frame_number
677 ;and #%1111111
678 bne cont3
679 jsr random_encounter
680 cont3
681
682 ; Increment the counter of frames
683 inc frame_number
684
685 ; Update everything that needs be
686 jsr update_speed_panel
687 jsr update_energy_panel
688 nofr
689 jmp loop
690
691 .)
692
693 str_rearview
694 .asc "Rear View"
695 .byt 0
696
697 str_frontview
698 .asc "Front View"
699 .byt 0
700
701
702 #ifdef DBGVALUES
703 dbg1 .word $0000
704 dbg2 .word $0000
705 dbg3 .word $0000
706
707
708 // DEBUGGING
709
710 print_dbgval
711 .(
712
713 lda _current_screen
714 cmp #SCR_FRONT
715 beq doit
716 jmp end
717 doit
718 dec print2dbuffer
719
720 #ifdef 0
721 ; Debug our energy value
722 ;lda _energy+1
723 ;sta dbg1
724 ;lda #0
725 ;sta dbg1+1
726
727 ; Debug a_y
728 ;lda a_y
729 ;sta dbg2
730 ;lda #0
731 ;sta dbg2+1
732
733 ; Debug ship pos
734 ldx #1
735 jsr GetShipPos
736 ldx #5
737 loop
738 lda _PosX,x
739 sta dbg1,x
740 dex
741 bpl loop
742 #endif
743 lda frame_time
744 sta op2
745 lda #0
746 sta op2+1
747 ldx #0
748 ldy #0
749 jsr gotoXY
750 ldx #5
751 jsr print_num_tab
752 #ifdef 0
753 lda dbg1
754 sta op2
755 lda dbg1+1
756 sta op2+1
757 ldx #47
758 ldy #0
759 jsr gotoXY
760 ldx #5
761 jsr print_num_tab
762
763 lda dbg2
764 sta op2
765 lda dbg2+1
766 sta op2+1
767 ldx #47+48
768 ldy #0
769 jsr gotoXY
770 ldx #5
771 jsr print_num_tab
772
773 lda dbg3
774 sta op2
775 lda dbg3+1
776 sta op2+1
777 ldx #47+48+48
778 ldy #0
779 jsr gotoXY
780 ldx #5
781 jsr print_num_tab
782
783
784 lda _speed+1
785 sta op2
786 lda #0
787 sta op2+1
788 ldx #47+48+48+48
789 ldy #0
790 jsr gotoXY
791 ldx #5
792 jsr print_num_tab
793 #endif
794 inc print2dbuffer
795
796 end
797 rts
798 .)
799 #endif
800
801 ;; Now the keyboard map table
802 #define MAX_KEY 23+5
803 user_keys
804 .byt "2", "3", "4", "5", "6", "7", "0", "R", "H", "J", "1"
805 .byt "S", "X", "N", "M", "A", "T", "F", "U", "E", "P", "B", "V", $1b
806 .byt 1,2,3,4,13
807 key_routh
808 .byt >(info), >(sysinfo), >(short_chart), >(gal_chart), >(market), >(equip), >(loadsave), >(splanet), >(galhyper), >(jumphyper), >(frontview)
809 .byt >(keydn), >(keyup), >(keyl), >(keyr), >(sele), >(target), >(fireM), >(unarm), >(ecm_on), >(power_redir), >(energy_bomb), >(rearview), >(launch_pod)
810 .byt >(keydn), >(keyl), >(keyup), >(keyr), >(sele)
811 key_routl
812 .byt <(info), <(sysinfo), <(short_chart), <(gal_chart), <(market), <(equip), <(loadsave), <(splanet), <(galhyper), <(jumphyper), <(frontview)
813 .byt <(keydn), <(keyup), <(keyl), <(keyr), <(sele), <(target), <(fireM), <(unarm), <(ecm_on), <(power_redir), <(energy_bomb), <(rearview), <(launch_pod)
814 .byt <(keydn), <(keyl), <(keyup), <(keyr), <(sele)
815
816
817 /* M= byte 3 val 1
818 N= byte 1 val 2
819 X= byte 1 val 64
820 S= byte 7 val 64
821 A= byte 7 val 32
822 Q= byte 2 val 64
823 W= byte 7 val 128
824 O= byte 6 val 4
825 L= byte 8 val 2
826 B= byte 3 val 4 */
827
828 #define NUM_SIM_KEYS 8
829 tab_ship_control_byte
830 .byt 2,0,0,6,6,1,6,5,7;,2
831 tab_ship_control_val
832 .byt 1,2,64,64,32,64,128,4,2;,4
833
834 tab_ship_control_routh
835 .byt >yawr,>yawl,>pitchup,>pitchdn,>fireL,>rolll,>rollr,>accel,>deccel;,>fireM
836 tab_ship_control_routl
837 .byt <yawr,<yawl,<pitchup,<pitchdn,<fireL,<rolll,<rollr,<accel,<deccel;,<fireM
838
839
840 ShipControl
841 .(
842 lda _current_screen
843 cmp #SCR_FRONT
844 bne noship
845 ldx #NUM_SIM_KEYS
846 bne loop ; allways branches
847 noship
848 ldx #3
849 loop
850 lda tab_ship_control_byte,x
851 tay
852 lda tab_ship_control_val,x
853 and KeyBank,y
854 beq skip
855 stx savx+1
856 lda tab_ship_control_routl,x
857 sta _smc_rout+1
858 lda tab_ship_control_routh,x
859 sta _smc_rout+2
860 _smc_rout
861 jsr $1234
862 savx
863 ldx #0
864 skip
865 dex
866 bpl loop
867 rts
868 .)
869
870
871 ProcessKeyboard
872 .(
873 lda player_in_control
874 beq end
875
876 jsr ShipControl
877
878 lda _current_screen
879 cmp #SCR_CHART
880 beq cross
881 cmp #SCR_GALAXY
882 bne cont1
883 cross
884 jsr MoveCross
885 cont1
886 jsr ReadKeyNoBounce
887 beq end
888
889
890 ; Ok a key was pressed, let's check
891 ldx #MAX_KEY
892 loop
893 cmp user_keys,x
894 beq found
895 dex
896 bpl loop
897 bmi end
898
899 found
900 lda key_routl,x
901 sta _smc_routine+1
902 lda key_routh,x
903 sta _smc_routine+2
904
905 cont
906 cpx #8
907 bcs skip
908
909 ; No market or equip or save if not docked
910 lda _docked
911 bne isdock
912 cpx #4
913 beq end
914 cpx #5
915 beq end
916 cpx #6
917 beq end
918 ; No planet search either
919 ;cpx #7
920 ;beq end
921
922 isdock
923 cpx #7 ; Hack with planet search
924 beq skip
925 lda double_buff
926 beq skip
927 stx savx+1
928 jsr _DoubleBuffOff
929 jsr save_frame
930 savx
931 ldx #0 ; SMC
932
933 skip
934
935 _smc_routine
936 ; Call the routine
937 jsr $1234 ; SMC
938
939 end
940 lda _current_screen
941 cmp #SCR_FRONT
942 bne ret
943
944 lda #0
945 ldx #7
946 loopb
947 sta KeyBank,x
948 dex
949 bpl loopb
950 ret
951 rts
952 .)
953
954
955 ; KEEP CONSECUTIVE
956 a_y .byt 0
957 a_p .byt 0
958 a_r .byt 0
959
960 ; KEEP CONSECUTIVE
961 yawing .byt 0
962 pitching .byt 0
963 rolling .byt 0
964
965 #define MAXR 8
966 #define MINR $f8
967
968
969 ParamInc
970 .(
971 lda a_y,x
972 bpl doinc
973 lda #0
974 sta a_y,x
975 beq end
976 doinc
977 inc a_y,x
978 lda #MAXR
979 cmp a_y,x
980 bpl end
981 sta a_y,x
982 end
983 lda #1
984 sta yawing,x
985 rts
986 .)
987
988 ParamDec
989 .(
990 lda a_y,x
991 bmi doinc
992 beq doinc
993 lda #0
994 sta a_y,x
995 beq end
996 doinc
997 dec a_y,x
998 lda #MINR
999 cmp a_y,x
1000 bmi end
1001 sta a_y,x
1002 end
1003 lda #1
1004 sta yawing,x
1005 rts
1006 .)
1007
1008 yawr
1009 .(
1010 ldx #0
1011 jmp ParamInc
1012 .)
1013 yawl
1014 .(
1015 ldx #0
1016 jmp ParamDec
1017 .)
1018 pitchdn
1019 .(
1020 ldx #1
1021 jmp ParamDec
1022 .)
1023 pitchup
1024 .(
1025 ldx #1
1026 jmp ParamInc
1027 .)
1028 rolll
1029 .(
1030 ldx #2
1031 jmp ParamDec
1032 .)
1033 rollr
1034 .(
1035 ldx #2
1036 jmp ParamInc
1037 .)
1038
1039
1040 accel
1041 ; Accelerate
1042 lda #1
1043 .byt $2C
1044 deccel
1045 lda #$ff
1046 sta _accel+1
1047 rts
1048
1049 target
1050 .(
1051 lda _missiles_left
1052 beq no_arm
1053 lda _missile_armed
1054 bne no_arm
1055 ; Arm missile and start target procedure
1056 ;jsr SndBell1
1057 jsr SndPoc
1058 ldx #STR_TARGET_ARMED
1059 jsr flight_message
1060 dec _missile_armed ; This sets it to $ff
1061 jsr update_missile_panel
1062 no_arm
1063 rts
1064 .)
1065 unarm
1066 .(
1067 ; This could simply set it to 0
1068 ; and save memory and CPU, but as it also may
1069 ; produce some sfx and panel changes, it may be worth a check
1070 lda _missile_armed
1071 beq no_unarm
1072 jsr SndPocLow
1073 ldx #STR_TARGET_UNARMED
1074 jsr flight_message
1075 lda #UNARMED ; Set it to 0
1076 sta _missile_armed
1077 jsr update_missile_panel
1078 no_unarm
1079 rts
1080 .)
1081 fireM
1082 .(
1083 ; Shoud this be defered to LaunchMissile??
1084 lda _missiles_left
1085 beq nolock
1086 lda _missile_armed
1087 beq nolock
1088 bmi nolock
1089
1090 ; Missile is locked, fire it
1091 sta AITarget
1092 ldx #1
1093 jsr SetCurOb
1094 jsr LaunchMissile
1095 jsr SndMissile
1096 beq nolock
1097 dec _missiles_left
1098 jmp update_missile_panel
1099 nolock
1100 rts
1101 .)
1102 fireL
1103 .(
1104 lda invert
1105 beq dofire
1106 rts
1107 dofire
1108 jmp FireLaser
1109 .)
1110
1111 energy_bomb
1112 .(
1113 ; Player launches energy bomb
1114 ; Check if equipped
1115 lda _equip
1116 and #%100000
1117 bne equipped
1118 dorts
1119 rts
1120
1121 equipped
1122 ; It needs energy
1123 lda _energy+1
1124 cmp #21+5 ; Some securiy margin
1125 bcc dorts
1126 sec
1127 sbc #20
1128 sta _energy+1
1129 ; Remove equip
1130 lda _equip
1131 and #%11011111
1132 sta _equip
1133
1134 ; Activate bomb
1135
1136 ldx #2 ; 0 and 1 are radar and player
1137 jsr SetCurOb
1138
1139 jsr GetNextOb
1140 cpx #0
1141 beq end
1142 loop
1143 sta POINT ;Object pointer
1144 sty POINT+1
1145
1146 ; Get ship ID byte...
1147 ldy #ObjID
1148 lda (POINT),y
1149
1150 and #%01111111
1151 beq next ; a planet, as sun or a moon
1152
1153 cmp #SHIP_CONSTRICTOR
1154 beq next
1155 cmp #SHIP_COUGAR
1156 beq next
1157
1158 ; Ok, not protected, so make it explode, if it is not
1159 ; already exploding, hyperspacing or docking
1160 lda _flags,x
1161 and #(IS_EXPLODING|IS_HYPERSPACING|IS_DOCKING)
1162 bne next
1163
1164 lda _flags,x
1165 and #%11110000 ; Remove older flags...
1166 ora #IS_EXPLODING
1167 sta _flags,x
1168 lda #0
1169 sta _ttl,x
1170 next
1171 jsr GetNextOb
1172 cpx #0
1173 bne loop
1174 end
1175 rts
1176 .)
1177
1178
1179
1180 ecm_on
1181 .(
1182 ; player sets ECM on.
1183 ; Check if he has ECM equipped
1184 lda _equip
1185 and #%10000
1186 beq noecm
1187 ; It needs energy
1188 lda _energy+1
1189 cmp #6+2 ; Some security margin
1190 bcc noecm
1191 sec
1192 sbc #5
1193 sta _energy+1
1194 jmp SetECMOn
1195 noecm
1196 rts
1197 .)
1198 ; P
1199 power_redir
1200 .(
1201 lda #SCR_FRONT
1202 cmp _current_screen
1203 beq doredir
1204 rts
1205 doredir
1206 jsr SndPic
1207 lda _ptla
1208 beq step2
1209 lda #0
1210 sta _ptla
1211 lda #1
1212 sta _ptsh
1213 jmp update_redirection
1214 step2
1215 lda _ptsh
1216 beq step3
1217 lda #0
1218 sta _ptsh
1219 jmp update_redirection
1220 step3
1221 lda #0
1222 sta _ptsh
1223 lda #1
1224 sta _ptla
1225 jmp update_redirection
1226 .)
1227 ;V
1228 rearview
1229 .(
1230 lda #SCR_FRONT
1231 cmp _current_screen
1232 beq lookrear
1233 rts
1234 lookrear
1235 lda invert
1236 eor #$ff
1237 sta invert
1238
1239 jsr clear_vertex
1240 jsr patch_invert_code
1241 jsr update_compass
1242 jmp INITSTAR
1243 .)
1244
1245 ;H
1246 galhyper
1247 .(
1248 lda #SCR_FRONT
1249 cmp _current_screen
1250 bne global_end
1251 lda invert
1252 bne global_end
1253
1254 ; Test if we have the Galactic Hyperspace equipped
1255 lda _equip
1256 and #%10000000
1257 beq global_end
1258
1259 ; If too close to planet cannot jump
1260 lda _planet_dist
1261 cmp #PDIST_MASSLOCK
1262 bcs canjump
1263 ldx #STR_MASS_LOCKED
1264 jmp flight_message
1265 canjump
1266 ; Should start sequence, but not perform the jump right now...
1267 jsr init_hyper_seq
1268 bcc dojump
1269 ldx #STR_PATH_LOCKED
1270 jmp flight_message
1271
1272 dojump
1273 ; Remove Galactic Hyperspace
1274 lda _equip
1275 and #%01111111
1276 sta _equip
1277 jmp do_galjump
1278 +global_end
1279 rts
1280 .)
1281
1282 ;J
1283 jumphyper
1284 .(
1285 lda #SCR_FRONT
1286 cmp _current_screen
1287 bne global_end
1288
1289 lda invert
1290 bne global_end
1291
1292 ; Compare current_planet with dest_planet too see if it is a "bad jump"
1293 ; and simply ignore
1294 lda _dest_num
1295 cmp _currentplanet
1296 bne good
1297 rts
1298 good
1299 ; Compare distance and check it is not a "hyperspace range?"
1300 ; 16-bit unsigned comparison... inlined
1301 lda _fuel ; op1-op2
1302 cmp _dest_dist
1303 lda #0
1304 sbc _dest_dist+1
1305 .(
1306 bvc ret ; N eor V
1307 eor #$80
1308 ret
1309 .)
1310 bcs endjump
1311 ; Cannot jump
1312 ldx #STR_HYPRANGE
1313 jmp flight_message
1314
1315 endjump
1316 ; If too close to planet cannot jump
1317 lda _planet_dist
1318 cmp #PDIST_MASSLOCK
1319 bcs canjump
1320 ldx #STR_MASS_LOCKED
1321 jmp flight_message
1322 canjump
1323 ; Should start sequence, but not perform the jump right now...
1324 jsr init_hyper_seq
1325 bcc dojump
1326 ldx #STR_PATH_LOCKED
1327 jmp flight_message
1328
1329 dojump
1330 jmp do_jump
1331 .)
1332 ;1
1333 frontview
1334 .(
1335 lda #SCR_FRONT
1336 cmp _current_screen
1337 beq nothing
1338 sta _current_screen
1339
1340 lda _docked
1341 beq notdocked
1342 lda #0
1343 sta invert
1344
1345 ; Exit to space...
1346 jsr CreateEnvironment
1347 ; We update the _docked variable AFTER CreateEnvironment, so it can be used
1348 ; to decide if we are exitting hyper or leaving planet.
1349 inc _docked ; docked is either ff or 0, this gets it back to 0,
1350 lda #0
1351 sta _patch_launch_msg+1
1352
1353 #ifdef RAMSAVE
1354 ldx #(__commander_data_end-__commander_data_start)-1
1355 loop
1356 lda __commander_data_start,x
1357 sta _default_commander,x
1358 dex
1359 bpl loop
1360 #endif
1361
1362 notdocked
1363 jmp init_front_view ; This is jsr/rts
1364 nothing
1365 rts
1366 .)
1367 ;2
1368 info
1369 .(
1370 jsr SndPic
1371 lda #SCR_INFO
1372 sta _current_screen
1373 jmp _displayinfo
1374 .)
1375 ;3
1376 sysinfo
1377 .(
1378 jsr SndPic
1379 lda #SCR_SYSTEM
1380 sta _current_screen
1381 jmp _printsystem
1382 .)
1383 ;4
1384 short_chart
1385 .(
1386 jsr SndPic
1387 lda #SCR_CHART
1388 sta _current_screen
1389 jmp _plot_chart
1390 .)
1391 ;5
1392 gal_chart
1393 .(
1394 jsr SndPic
1395 lda #SCR_GALAXY
1396 sta _current_screen
1397 jmp _plot_galaxy
1398 .)
1399 ;6
1400 market
1401 .(
1402 jsr SndPic
1403 lda #SCR_MARKET
1404 sta _current_screen
1405 jmp _displaymarket
1406 .)
1407 ;7
1408 equip
1409 .(
1410 jsr SndPic
1411 lda #SCR_EQUIP
1412 sta _current_screen
1413 jmp _displayequip
1414 .)
1415 ;0
1416 loadsave
1417 .(
1418 jsr SndPic
1419 lda #SCR_LOADSAVE
1420 sta _current_screen
1421 jmp _displayloadsave
1422 .)
1423 ;R
1424 splanet
1425 .(
1426 lda _current_screen
1427 cmp #SCR_GALAXY
1428 beq doit
1429 ; cmp #SCR_CHART
1430 ; beq doit
1431 rts
1432 doit
1433 jsr SndPic
1434 ; ask for planet and search it
1435 jsr prepare_area
1436 lda #(A_FWGREEN+A_FWYELLOW*16+128)
1437 jsr put_code
1438 lda #<str_searchplanet
1439 ldx #>str_searchplanet
1440 jsr print
1441 lda #A_FWWHITE
1442 jsr put_code
1443 jsr gets
1444 jmp _search_planet ; This is jsr/rts
1445 .)
1446
1447 launch_pod
1448 .(
1449 lda #SCR_FRONT
1450 cmp _current_screen
1451 beq doit1
1452 ret
1453 rts
1454 doit1
1455
1456 ; Look front
1457 lda invert
1458 beq nothing2
1459 eor #$ff
1460 sta invert
1461 jsr update_compass
1462 jsr INITSTAR
1463 nothing2
1464 lda _equip
1465 and #%100 ; Escape Pod
1466 beq ret
1467
1468 inc player_in_control
1469 dec escape_pod_launched
1470
1471 ; Clear legal status
1472 lda #0
1473 sta _legal_status
1474
1475 ; Empty player's cargo
1476 ldx #16
1477 lda #0
1478 loop
1479 sta _shipshold,x
1480 dex
1481 bpl loop
1482
1483 lda #20
1484 sta _holdspace
1485
1486 ; Empty equipment
1487 lda #01
1488 sta _equip
1489 lda #00
1490 sta _equip+1
1491 /*
1492 lda _equip
1493 and #%10 ; Large cargo bay
1494 beq nocargo
1495 lda _holdspace
1496 clc
1497 adc #10
1498 sta _holdspace
1499 nocargo
1500 */
1501 ; clears hyperspace destination
1502 lda _currentplanet
1503 sta _dest_num
1504 jsr _infoplanet
1505 jsr _makesystem
1506
1507 ; Launch us
1508 ldx #1
1509 jsr SetCurOb
1510 lda #DEBRIS ; Anything would do...
1511 jsr LaunchShipFromOther
1512 ; Set it as view object
1513 stx VOB
1514 lda #0
1515 sta _speed,x
1516
1517 ; Push it a bit
1518 jsr SetCurOb
1519 lda #10
1520 jsr MoveSide
1521
1522 ; Inform player
1523 ldx #STR_PODLAUNCHED
1524 jmp flight_message
1525 .)
1526
1527 ;;;; END OF TABLE
1528
1529
1530
1531 do_jump
1532 .(
1533 ; Remove fuel
1534 lda _fuel
1535 sec
1536 sbc _dest_dist
1537 sta _fuel
1538 lda _fuel+1
1539 sbc _dest_dist+1
1540 sta _fuel+1
1541
1542 ; Perform the jumping
1543 +tailjump
1544 jsr _jump
1545 ; Clear legal status a bit
1546 lda _legal_status
1547 lsr
1548 sta _legal_status
1549 ; Erase radar and compass and create environment
1550 jsr EraseRadar
1551 jsr clear_compass
1552 jsr CreateEnvironment
1553 ; Draw first frame
1554 jmp _FirstFrame
1555 ;rts
1556 .)
1557
1558 do_galjump
1559 .(
1560 jsr _enter_next_galaxy
1561 lda #0
1562 sta _legal_status
1563 jmp tailjump
1564 .)
1565
1566 check_scr
1567 .(
1568 lda _current_screen
1569 ;cmp #SCR_GALAXY
1570 ;beq retnz
1571 ;cmp #SCR_CHART
1572 ;beq retnz
1573 cmp #SCR_MARKET
1574 beq retz
1575 cmp #SCR_EQUIP
1576 beq retz
1577 cmp #SCR_LOADSAVE
1578 beq retz
1579
1580 sec
1581 rts
1582 retz
1583 clc
1584 rts
1585
1586 .)
1587
1588 keydn
1589 .(
1590 jsr check_scr
1591 bcc do
1592 rts
1593 do
1594 jmp _dec_sel
1595
1596 .)
1597
1598
1599 keyup
1600 .(
1601 jsr check_scr
1602 bcc do
1603 rts
1604 do
1605 jmp _inc_sel
1606
1607 .)
1608
1609
1610 keyl
1611 .(
1612 lda _current_screen
1613 cmp #SCR_EQUIP
1614 beq ret
1615 cmp #SCR_LOADSAVE
1616 beq ret
1617 jsr check_scr
1618 bcc do
1619 ret
1620 rts
1621 do
1622 jmp _sell
1623
1624 .)
1625
1626
1627 keyr
1628 .(
1629 lda _current_screen
1630 cmp #SCR_EQUIP
1631 beq ret
1632 cmp #SCR_LOADSAVE
1633 beq ret
1634 jsr check_scr
1635 bcc do
1636 ret
1637 rts
1638 do
1639 jmp _buy
1640
1641 .)
1642
1643 sele
1644 .(
1645 lda _current_screen
1646 cmp #SCR_GALAXY
1647 beq doit2
1648 cmp #SCR_CHART
1649 beq doit2
1650 cmp #SCR_EQUIP
1651 beq bequip
1652 cmp #SCR_LOADSAVE
1653 bne ret
1654 ; Jump to load/save
1655 jmp do_loadsave
1656 bequip
1657 ; Jump to acquire equipment
1658 jmp buy_equip
1659 ret
1660 rts
1661 doit2
1662 jmp _find_planet
1663 .)
1664
1665
1666 #ifdef TABBEDROLLS
1667 tab_rolls_fast .byt 0,1,1,1,2,2,3,4,6
1668 tab_rolls_slow .byt 0,1,1,1,1,2,2,2,3
1669
1670 tab_rolls .byt 0,1,1,1,2,2,3,4,6
1671 dorolls
1672 .(
1673 .(
1674 ; Transform a_whatever in rot_whatever
1675 lda a_y
1676 bpl notneg
1677 lda #0
1678 sec
1679 sbc a_y
1680 tax
1681 lda tab_rolls,x
1682 ora #%10000000
1683 bmi store
1684 notneg
1685 tax
1686 lda tab_rolls,x
1687
1688 store
1689 sta _roty+1
1690 .)
1691
1692 .(
1693 ; Transform a_whatever in rot_whatever
1694 lda a_p
1695 bpl notneg
1696 lda #0
1697 sec
1698 sbc a_p
1699 tax
1700 lda tab_rolls,x
1701 ora #%10000000
1702 bmi store
1703 notneg
1704 tax
1705 lda tab_rolls,x
1706 store
1707 sta _rotx+1
1708 .)
1709
1710 .(
1711 ; Transform a_whatever in rot_whatever
1712 lda a_r
1713 bpl notneg
1714 lda #0
1715 sec
1716 sbc a_r
1717 tax
1718 lda tab_rolls,x
1719 ora #%10000000
1720 bmi store
1721 notneg
1722 tax
1723 lda tab_rolls,x
1724 store
1725 sta _rotz+1
1726 .)
1727
1728 rts
1729 .)
1730
1731 #else
1732 dorolls
1733 .(
1734 .(
1735 ; Transform a_whatever in rot_whatever
1736 lda a_y
1737 bpl notneg
1738 lda #0
1739 sec
1740 sbc a_y
1741 ora #%10000000
1742 bmi store
1743 notneg
1744 store
1745 sta _roty+1
1746 .)
1747
1748 .(
1749 ; Transform a_whatever in rot_whatever
1750 lda a_p
1751 bpl notneg
1752 lda #0
1753 sec
1754 sbc a_p
1755 ora #%10000000
1756 bmi store
1757 notneg
1758 store
1759 sta _rotx+1
1760 .)
1761
1762 .(
1763 ; Transform a_whatever in rot_whatever
1764 lda a_r
1765 bpl notneg
1766 lda #0
1767 sec
1768 sbc a_r
1769 ora #%10000000
1770 bmi store
1771 notneg
1772 store
1773 sta _rotz+1
1774 .)
1775
1776 rts
1777 .)
1778
1779
1780
1781 #endif
1782
1783
1784
1785 MoveCross
1786 .(
1787 lda pitching
1788 beq next1
1789 lda a_p
1790 beq next1
1791 jsr _move_cross_v
1792 lda #0
1793 sta a_p
1794 next1
1795 lda yawing
1796 beq next2
1797 lda a_y
1798 beq next2
1799 jsr _move_cross_h
1800 lda #0
1801 sta a_y
1802 next2
1803 rts
1804 .)
1805
1806 damp
1807 .(
1808 ldx #2
1809 loop
1810 lda yawing,x
1811 bne end
1812 lda a_y,x
1813 bmi neg
1814 beq end
1815 dec a_y,x
1816 bpl end
1817 neg
1818 inc a_y,x
1819 end
1820 dex
1821 bpl loop
1822 rts
1823 .)
1824
1825
1826
1827 init_hyper_seq
1828 .(
1829
1830 ; Check if path is locked (collision danger)
1831 jsr FindTarget
1832 lda _ID
1833 beq pathfree
1834
1835 ; path is locked!
1836 ;return with C=1
1837 sec
1838 rts
1839
1840 pathfree
1841
1842 lda #20
1843 sta co
1844 loop
1845 ldx #1
1846 jsr SetCurOb
1847 lda #50
1848 jsr MoveForwards
1849
1850 ldx #1
1851 jsr CalcView
1852 jsr SortVis
1853 ;jsr clr_hires2
1854 jsr DrawAllVis ;Draw objects
1855
1856 lda #20
1857 sta g_theta
1858 jsr move_stars
1859 jsr PlotStars
1860 ;jsr _DrawCrosshair
1861
1862 jsr dump_buf
1863
1864 dec co
1865 bne loop
1866
1867 ; Return with C=0 to continue jump
1868 clc
1869 rts
1870
1871 co .byt $00
1872 .)
1873
1874
1875 ViewPlayerShip
1876 .(
1877 ; Look front
1878 lda invert
1879 beq nothing2
1880 eor #$ff
1881 sta invert
1882 jsr update_compass
1883 jsr INITSTAR
1884 nothing2
1885
1886 ; Make it still
1887 lda #0
1888 sta _speed+1
1889 sta _rotx+1
1890 sta _roty+1
1891 sta _rotz+1
1892 sta _accel+1
1893 sta a_y
1894 sta a_p
1895 sta a_r
1896 lda #$ff
1897 sta _energy+1
1898 lda _flags+1
1899 and #%11110000 ; Remove older flags...
1900 ora #IS_EXPLODING
1901 sta _flags+1
1902
1903 ; Delay explosion a bit
1904 lda #3
1905 sta _ttl+1
1906
1907 ldx #1
1908 jsr SetCurOb
1909 lda #DEBRIS ; Anything would do...
1910 jsr LaunchShipFromOther
1911
1912 ; Set it as view object
1913 stx VOB
1914
1915 ; make it rotate and move
1916 ;lda #4
1917 ;sta _rotz,x
1918 ;lda #2
1919 ;sta _speed,x
1920
1921 ; Push it a bit
1922 jsr SetCurOb
1923 lda #$9c ; -100
1924 jmp MoveForwards
1925 ;rts
1926 .)
1927
1928
1929
1930
1931 patch_invert_code
1932 .(
1933 lda invert
1934 beq setnops
1935 ; Some code patches
1936 lda #$20 ; jsr opcode
1937 sta _patch_invertZa
1938 sta _patch_invertZb
1939 lda #<invertZ
1940 sta _patch_invertZa+1
1941 sta _patch_invertZb+1
1942 lda #>invertZ
1943 sta _patch_invertZa+2
1944 sta _patch_invertZb+2
1945
1946 lda #<str_rearview
1947 ldx #>str_rearview
1948 jmp end
1949 setnops
1950 lda #$ea ; nop opcode
1951 ldx #2
1952 loop
1953 sta _patch_invertZa,x
1954 sta _patch_invertZb,x
1955 dex
1956 bpl loop
1957
1958 lda #<str_frontview
1959 ldx #>str_frontview
1960 end
1961 ; Patch front/rear view message
1962 sta _patch_invert_msg+1
1963 stx _patch_invert_msg+3
1964 rts
1965 .)
1966
1967 PatchLaserDraw
1968 .(
1969 ; Pacth main loop code
1970 lda #$ea ; nop opcode
1971 sta _patch_laser_fired
1972 sta _patch_laser_fired+1
1973 sta _patch_laser_fired+2
1974 rts
1975 .)
1976
1977
1978 clear_vertex
1979 .(
1980 ; Clear vertices where lasers start/end in each object
1981 ldx #(MAXSHIPS)
1982 lda #0
1983 loopcl
1984 sta _vertexXLO-1,x
1985 sta _vertexXHI-1,x
1986 sta _vertexYLO-1,x
1987 sta _vertexYHI-1,x
1988 dex
1989 bne loopcl
1990 rts
1991 .)
1992
1993 VOB .byt 00 ;View object
1994
1995 ;Pattern table
1996 #define SOLID 0
1997 #define DITHER1 1
1998 #define DITHER2 2
1999 #define ZIGS 3
2000 #define ZAGS 4
2001 #define ZIGZAG 5
2002 #define CROSSSM 6
2003 #define BRICK 7
2004 #define SQUARES 8
2005 #define INVSQ 9
2006 #define HOLES 10
2007 #define HSTRIPES 11
2008 #define VSTRIPES 12
2009
2010
2011
2012 ONEDOT
2013 .byt DEBRIS ;Debris object
2014 .byt 1 ;Number of points
2015 .byt 1 ;Number of faces
2016 .byt 0,0,0 ;Normal (unused)
2017 ; Point list
2018 .byt 0
2019 .byt 0
2020 .byt 0
2021 ; Face list
2022 .byt 1 ;Number of vertices
2023 .byt 0 ;Fill pattern
2024 .byt 0 ;Vertices
2025
2026
2027 ONEPLANET
2028 .byt PLANET ;Sun or planet Object
2029 .byt 1 ;Number of points
2030 .byt 1 ;Number of faces
2031 .byt 0,0,0 ;Normal (unused)
2032 ; Point list
2033 .byt 0
2034 .byt 0
2035 .byt 0
2036 ; Face list
2037 .byt 1 ;Number of vertices
2038 .byt SOLID ;Fill pattern
2039 .byt 0 ;Vertices
2040
2041 ONEMOON
2042 .byt MOON ;Moon Object
2043 .byt 1 ;Number of points
2044 .byt 1 ;Number of faces
2045 .byt 0,0,0 ;Normal (unused)
2046 ; Point list
2047 .byt 0
2048 .byt 0
2049 .byt 0
2050 ; Face list
2051 .byt 1 ;Number of vertices
2052 .byt SOLID ;Fill pattern
2053 .byt 0 ;Vertices
2054
2055
2056
2057

  ViewVC Help
Powered by ViewVC 1.1.26