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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 327 - (show annotations)
Mon May 24 19:13:37 2010 UTC (9 years, 10 months ago) by Chema
File size: 66834 byte(s)
Solved snapping to planet in short range chart. Added fuel cricle in long range chart
1
2 #include "main.h"
3
4 #define itoa itoa2
5
6 ; Functions to re-create galaxy and market of Elite
7 ; adapted from the TextElite C source
8
9 ;typedef struct
10 ;{ char a,b,c,d;
11 ;} fastseedtype; /* four byte random number used for planet description */
12
13
14 ;typedef struct
15 ;{ int w0;
16 ; int w1;
17 ; int w2;
18 ;} seedtype; /* six byte random number used as seed for planets */
19
20
21
22 ;typedef struct
23 ;{
24 ; unsigned char x;
25 ; unsigned char y; /* One byte unsigned */
26 ; unsigned char economy; /* These two are actually only 0-7 */
27 ; unsigned char govtype;
28 ; unsigned char techlev; /* 0-16 i think */
29 ; unsigned char population; /* One byte */
30 ; unsigned int productivity; /* Two byte */
31 ; unsigned int radius; /* Two byte (not used by game at all) */
32 ; fastseedtype goatsoupseed;
33 ; char name[12];
34 ;} plansys ;
35
36
37
38
39 ;typedef struct
40 ;{ /* In 6502 version these were: */
41 ; unsigned char baseprice; /* one byte */
42 ; signed char gradient; /* five bits plus sign */
43 ; unsigned char basequant; /* one byte */
44 ; unsigned char maskbyte; /* one byte */
45 ; unsigned char units; /* two bits */
46 ; unsigned char name[20]; /* longest="Radioactives" */
47 ; } tradegood ;
48
49
50 ; Following the original 6502 Elite, this is split into two tables and compressed a bit
51 ; so that the goods characteristics are stored in a 4-byte record.
52 ; However it is usually a good idea to keep everything into separate lists. This is how
53 ; I will do it. I am wasting 1 byte per record (17 bytes total), but will keep code smaller and easier
54 ; to follow. In addition, we can add more things if necessary.
55 ; Contets of the table are
56
57 ;tradegood commodities[]=
58 ; {
59 ; {0x13,-0x02,0x06,0x01,0,"Food "},
60 ; {0x14,-0x01,0x0A,0x03,0,"Textiles "},
61 ; {0x41,-0x03,0x02,0x07,0,"Radioactives"},
62 ; {0x28,-0x05,0xE2,0x1F,0,"Slaves "},
63 ; {0x53,-0x05,0xFB,0x0F,0,"Liquor/Wines"},
64 ; {0xC4,+0x08,0x36,0x03,0,"Luxuries "},
65 ; {0xEB,+0x1D,0x08,0x78,0,"Narcotics "},
66 ; {0x9A,+0x0E,0x38,0x03,0,"Computers "},
67 ; {0x75,+0x06,0x28,0x07,0,"Machinery "},
68 ; {0x4E,+0x01,0x11,0x1F,0,"Alloys "},
69 ; {0x7C,+0x0d,0x1D,0x07,0,"Firearms "},
70 ; {0xB0,-0x09,0xDC,0x3F,0,"Furs "},
71 ; {0x20,-0x01,0x35,0x03,0,"Minerals "},
72 ; {0x61,-0x01,0x42,0x07,1,"Gold "},
73 ; {0xAB,-0x02,0x37,0x1F,1,"Platinum "},
74 ; {0x2D,-0x01,0xFA,0x0F,2,"Gem-Strones "},
75 ; {0x35,+0x0F,0xC0,0x07,0,"Alien Items "},
76 ; };
77
78
79
80 ; initialize seed for current galaxy
81 init_seed
82 .(
83 ; Initialize seed for this galaxy
84 ldx #5
85 loop
86 lda _base0,x
87 sta _seed,x
88 dex
89 bpl loop
90
91 rts
92 .)
93
94
95
96 ; jump()
97 ; jumps to dest_num and hyp_system. I guess those should be consistent. Normaly you would
98 ; call infoplanet to find the seed and then makesystem to create the system data
99 ; so these two should be fused and jump just use the current hyp_system...
100
101 _jump
102 .(
103 ldx #25
104 loop
105 lda _hyp_system,x
106 sta _cpl_system,x
107 dex
108 bpl loop
109
110 lda _dest_num
111 sta _currentplanet
112
113 ; Randomize price fluctuation
114 jsr _gen_rnd_number
115 sta _fluct
116
117 ; Generate the market
118 ; and show it
119 jmp _genmarket
120 ;jmp _displaymarket
121
122 .)
123
124
125
126 ;genmarket(signed char fluct)
127 ;/* Prices and availabilities are influenced by the planet's economy type
128 ; (0-7) and a random "fluctuation" byte that was kept within the saved
129 ; commander position to keep the market prices constant over gamesaves.
130 ; Availabilities must be saved with the game since the player alters them
131 ; by buying (and selling(?))
132 ;
133 ; Almost all operations are one byte only and overflow "errors" are
134 ; extremely frequent and exploited.
135 ;
136 ; Trade Item prices are held internally in a single byte=true value/4.
137 ; The decimal point in prices is introduced only when printing them.
138 ; Internally, all prices are integers.
139 ; The player's cash is held in four bytes.
140 ; */
141
142
143
144 _genmarket
145 .(
146 ;unsigned short i;
147 ;for(i=0;i<=lasttrade;i++)
148
149 lda #16
150 sta count2
151 loop
152
153 ;{
154 ;signed int q;
155 ;signed int product = (system.economy)*(commodities[i].gradient);
156 ;signed int changing = fluct & (commodities[i].maskbyte);
157 ; q = (commodities[i].basequant) + changing - product;
158
159 lda #0
160
161 sta op1+1
162 sta op2+1
163
164 lda _hyp_system+ECONOMY
165 sta op1
166 ldx count2
167 lda Gradients,x
168 bpl positive2
169 dec op2+1
170 positive2
171 sta op2
172 jsr mul16 ; SHOUDL USE FAST 8-BIT MULT FROM LIB3D!!
173
174
175 ldx count2
176 lda Maskbytes,x
177 and _fluct
178 pha
179 clc
180 adc Basequants,x
181 sec
182 sbc op1
183
184 ;q = q&0xFF;
185 ;if(q&0x80) {q=0;}; /* Clip to positive 8-bit */
186
187 bpl positive
188 lda #0
189 positive
190
191 ;market.quantity[i] = (unsigned int)(q & 0x3F); /* Mask to 6 bits */
192 and #$3f
193 sta _quantities,x
194
195 ;q = (commodities[i].baseprice) + changing + product;
196 ;q = q & 0xFF;
197 ;market.price[i] = (unsigned int) (q*4);
198 pla ; get changing
199 clc
200 adc Baseprices,x
201 adc op1
202 ldy #0
203 sty tmp+1
204 asl
205 rol tmp+1
206 asl
207 rol tmp+1
208 sta tmp
209 txa
210 asl
211 tax
212 lda tmp
213 sta _prices,x
214 lda tmp+1
215 sta _prices+1,x
216
217 dec count2
218 bpl loop
219
220 ;}
221
222 ;market.quantity[AlienItems] = 0; /* Override to force nonavailability */
223
224 ldx #16
225 lda #0
226 sta _quantities,x
227
228 ;return ;
229 rts
230 .)
231
232
233
234 ; tweak seed four times (usual way)
235 tweakseed4
236 .(
237 ; use reg Y as it is not touched in _tweakseed
238
239 ldy #4
240 loop2
241 jsr _tweakseed
242 dey
243 bne loop2
244
245 rts
246 .)
247 ;
248 ;void tweakseed()
249 ;{
250 ; unsigned int temp;
251 ; temp = ((seed).w0)+((seed).w1)+((seed).w2); /* 2 byte aritmetic */
252 ; (seed).w0 = (seed).w1;
253 ; (seed).w1 = (seed).w2;
254 ; (seed).w2 = temp;
255 ;}
256
257 _tweakseed
258 .(
259 lda _seed ; LO of seed.w0
260 clc
261 adc _seed+2; LO of seed.w1
262 sta tmp
263 lda _seed+1; HI of seed.w0
264 adc _seed+3; HI of seed.w1
265 sta tmp+1
266
267 lda _seed+4 ; LO of seed.w2
268 clc
269 adc tmp
270 sta tmp
271 lda _seed+5
272 adc tmp+1
273 sta tmp+1
274
275 ldx #1
276 loop
277 lda _seed+2,x
278 sta _seed,x
279
280 lda _seed+4,x
281 sta _seed+2,x
282
283 lda tmp,x
284 sta _seed+4,x
285
286 dex
287 bpl loop
288 rts
289
290 .)
291
292 ; Get info on a planet number
293
294 ;infoplanet(int num)
295 _infoplanet
296 .(
297 ; seed.w0=base0;
298 ; seed.w1=base1;
299 ; seed.w2=base2; /* Initialise seed for galaxy 1 */ ;
300 jsr init_seed
301
302 lda _dest_num
303 beq end
304 sta num
305
306 ; for (i=0;i<num;i++){
307 ; tweakseed();
308 ; tweakseed();
309 ;; tweakseed();
310 ; tweakseed();
311 ; }
312 ; Will use reg y, as it is not used in tweakseed
313 loop3
314 jsr tweakseed4
315 dec num
316 bne loop3
317 end
318 rts
319
320 ;}
321 .)
322
323 _search_planet
324 .(
325 ; Initialize seed for this galaxy
326 jsr init_seed
327
328 ; Loop creating systems
329 lda #$ff
330 sta num
331
332 loop3
333 inc num
334 jsr name_planet
335 jsr compare_names
336 beq found
337
338 jsr tweakseed4
339
340 lda num
341 cmp #$ff
342 beq notfound
343 bne loop3
344
345 found
346 lda num
347 sta _dest_num
348 jsr _infoplanet
349 jsr _makesystem
350
351 lda _current_screen
352 cmp #SCR_CHART
353 bne long
354 jsr _plot_chart
355 jmp print_distinfo
356 long
357 jsr _plot_galaxy
358 jmp print_distinfo
359
360 notfound
361 jsr prepare_area
362 lda #<str_notfound
363 ldx #>str_notfound
364 jsr printnl
365 jsr SndBell2
366 jsr _infoplanet
367 jmp _makesystem
368
369 .)
370
371 prepare_area
372 .(
373 jsr clear_frame_data
374 jsr instructions
375 ldy #(200-6*4)
376 ldx #12
377 jmp gotoXY
378 .)
379
380 print_distinfo
381 .(
382 jsr SndBell2
383 jsr prepare_area
384 ;jsr put_space
385 lda #>_hyp_system+NAME
386 tax
387 lda #<_hyp_system+NAME
388 jsr print
389 jsr put_space
390 jmp print_distance ; This is jsr/rts
391 .)
392
393
394 compare_names
395 .(
396 ; ldy #0
397 ; lda (sp),y
398 ; sta st1+1
399 ; iny
400 ; lda (sp),y
401 ; sta st1+2
402 ldx #$ff
403 loop
404 inx
405 lda _hyp_system+NAME,x
406 st1
407 cmp str_buffer,x
408 bne notequal
409 cmp #0
410 bne loop
411
412 ; equal
413 lda #0
414 rts
415 notequal
416 lda #1
417 rts
418 .)
419
420
421
422 #define LONG_START_X 12
423 #define LONG_START_Y 16
424 #define LONG_END_X (239-LONG_START_X)
425 #define SCROLL_AMOUNT 40
426
427 clear_frame_data
428 .(
429 ; Clears the two lines of text
430 ; where data is printed on chart screens
431
432 ldx #10 ; ten lines
433 lda #<($a000+176*40)
434 sta tmp
435 lda #>($a000+176*40)
436 sta tmp+1
437 loopt
438 lda #$40
439 ldy #39
440 loopscans
441 sta (tmp),y
442 dey
443 bpl loopscans
444 clc
445 lda tmp
446 adc #40
447 sta tmp
448 bcc nocarry
449 inc tmp+1
450 nocarry
451 dex
452 bpl loopt
453
454 rts
455
456 .)
457
458
459 draw_red_frame
460 .(
461
462 ; Clear hires and draw frame
463 jsr clr_hires
464
465 ldx #13
466 lda #<$a000
467 sta tmp
468 lda #>$a000
469 sta tmp+1
470 ldy #0
471 loopt
472 lda #A_BGRED
473 sta (tmp),y
474 clc
475 lda tmp
476 adc #40
477 sta tmp
478 bcc nocarry
479 inc tmp+1
480 nocarry
481 dex
482 bne loopt
483
484 lda #A_BGCYAN
485 sta $a208
486
487 lda #(A_FWWHITE+A_FWCYAN*16+128) ;(A_FWGREEN+A_FWYELLOW*16+128)
488 jsr put_code
489 jsr put_space
490 jmp put_space
491 ;rts
492 .)
493
494 plot_frame_title
495 .(
496 jsr draw_red_frame
497 inc capson
498
499 lda _current_screen
500 cmp #SCR_CHART
501 bne long
502 lda #<str_short_chart
503 ldx #>str_short_chart
504 jmp print ; this is jsr/rts
505 long
506 lda #A_BGCYAN
507 sta $b680
508
509 lda #<$a230
510 sta tmp
511 lda #>$a230
512 sta tmp+1
513 ldx #(128/2)
514 loop2
515 lda #$03
516 ldy #0
517 sta (tmp),y
518 lda #$06
519 ldy #40
520 sta (tmp),y
521
522 lda tmp
523 clc
524 adc #80
525 sta tmp
526 bcc nocarry2
527 inc tmp+1
528 nocarry2
529
530 dex
531 bne loop2
532 lda #<str_galactic_chart
533 ldx #>str_galactic_chart
534 jsr print
535 jsr put_space
536 lda _galaxynum
537 clc
538 adc #48
539 jmp put_char ; This is jsr/rts
540
541 .)
542
543
544 ; Plot galaxy (long range chart)
545
546 _plot_galaxy
547 .(
548 lda #0 ; No scroll
549 sta scroll
550 ; Prepare player's position and calculate
551 ; if we need scroll
552 ldx _hyp_system+SYSX
553 ldy _hyp_system+SYSY
554 cpx #(LONG_END_X-LONG_START_X)
555 bcc nodanger
556 inc scroll
557 nodanger
558 jsr universe_to_long_chart
559 sty plotY
560 stx plotX
561
562 ; Is in range?
563 ;cpx #LONG_START_X
564 ;bcc noscroll
565 cpx #LONG_END_X
566 bcc noscroll
567 inc scroll
568 noscroll
569 jsr plot_galaxy_with_scroll
570
571 ; Print instructions
572 jsr instructions
573
574 jsr _infoplanet
575 jmp _makesystem
576 ;rts
577
578 .)
579
580
581
582 plot_galaxy_with_scroll
583 .(
584 ;jsr clr_hires
585 jsr plot_frame_title
586 dec capson
587
588
589 lda scroll
590 beq right
591 lda #"<"
592 ldx #12
593 bne plotarrow
594 right
595 lda #">"
596 ldx #(240-18)
597 plotarrow
598 ldy #4
599 jsr gotoXY
600 jsr put_char
601
602
603 ; Initialize seed for this galaxy
604 jsr init_seed
605
606 ; Loop creating systems
607 lda #$ff
608 sta num
609
610 loop3
611 inc num
612
613 ; Plot a dot at system's position (X/2, Y/4)
614
615 ldx _seed+3 ; HI part of seed.w1 is sys X
616 ldy _seed+1 ; This is sys Y
617 jsr universe_to_long_chart
618
619 ; Is in range?
620 cpx #LONG_START_X
621 bcc postdraw
622 cpx #LONG_END_X
623 bcs postdraw
624
625
626 jsr pixel_address_real
627 ora (tmp0),y
628 sta (tmp0),y
629
630 postdraw
631 jsr tweakseed4
632 lda num
633 cmp #$ff
634 bne loop3
635
636 end
637
638 ldx _cpl_system+SYSX
639 ldy _cpl_system+SYSY
640 jsr universe_to_long_chart
641
642 ; Is in range?
643 cpx #LONG_START_X
644 bcc postdraw2
645 cpx #LONG_END_X
646 bcs postdraw2
647
648 ; Draw big the cursor
649 lda plotY
650 pha
651 lda plotX
652 pha
653 sty plotY
654 stx plotX
655
656 lda #12
657 jsr plot_cross
658
659 ; Draw fuel circle
660 ldy #0
661 lda plotX
662 sta cx
663 sty cx+1
664 lda plotY
665 sta cy
666 sty cy+1
667 lda _fuel
668 lsr
669 lsr
670 sta rad
671 sty rad+1
672 jsr _circleMidpoint
673
674
675 pla
676 sta plotX
677 pla
678 sta plotY
679
680 postdraw2
681
682 ; Draw the cursor
683 lda #6
684 jsr plot_cross
685
686 rts
687
688 .)
689
690
691 universe_to_long_chart
692 .(
693 txa
694 ;lsr
695 clc
696 adc #LONG_START_X
697 ldx scroll
698 beq noscroll
699 sec
700 sbc #SCROLL_AMOUNT
701 noscroll
702 tax
703
704 tya
705 lsr
706 ;lsr
707 clc
708 adc #LONG_START_Y
709 tay
710
711 rts
712 .)
713
714
715 long_chart_to_universe
716 .(
717 txa
718 sec
719 sbc #LONG_START_X
720 ldx scroll
721 beq noscroll
722 clc
723 adc #SCROLL_AMOUNT
724 noscroll
725 tax
726
727 tya
728 sec
729 sbc #LONG_START_Y
730 asl
731 tay
732
733 rts
734 .)
735
736 ; Plot chart (short range chart)
737
738 #define SHORT_CENTRE_X $68
739 #define SHORT_CENTRE_Y $56
740
741 #ifdef 0
742 save_seed
743 .(
744
745 ; Save seed
746 ldx #5
747 loopsavseed
748 lda _seed,x
749 ;sta temp_seed2,x
750 dex
751 bpl loopsavseed
752 rts
753 .)
754
755 restore_seed
756 .(
757 ; restore seed
758 ldx #5
759 resseed
760 ;lda temp_seed2,x
761 sta _seed,x
762 dex
763 bpl resseed
764
765 rts
766
767 .)
768 #endif
769
770 in_range
771 .(
772 ; Check if in range. Need to do this in 16-bit signed arithmetic!
773
774 ; int dx = cseed.s3 - g_commander.cpl_coord.x;
775 ; int dy = cseed.s1 - g_commander.cpl_coord.y;
776
777 ; Prepare X and Y (so we can call in_range2 for other matters...)
778 lda _seed+3
779 sta tmp2
780 lda _seed+1
781 sta tmp2+1
782
783 +in_range2
784 ; if (abs(dx) < 0x14) {
785 ; if (abs(dy) < 0x26) {
786 lda #0
787 sta op1+1
788 lda tmp2 ; HI part of seed.w1 is sys X
789 sec
790 sbc _cpl_system+SYSX
791 sta op1
792 bcs nonegx
793 dec op1+1
794 jsr abs
795 nonegx
796
797 lda #0
798 sta op2+1
799 lda #$14
800 sta op2
801 jsr cmp16
802 ;bcs end
803 bpl end
804
805 checkY
806 lda #0
807 sta op1+1
808 lda tmp2+1 ; This is Y
809 sec
810 sbc _cpl_system+SYSY
811 sta op1
812 bcs nonegy
813 dec op1+1
814 jsr abs
815 nonegy
816 lda #0
817 sta op2+1
818 lda #$26
819 sta op2
820 jmp cmp16 ; This is jsr/rts
821
822 end
823 rts
824 .)
825
826 _plot_chart
827 .(
828
829 ; jsr save_seed
830 ; init names
831 ldx #23
832 lda #0
833 loopnames
834 sta names,x
835 dex
836 bpl loopnames
837
838 jsr clr_hires
839 ;ldy #0
840 ;lda #6
841 ;sta (sp),y
842 ;jsr _ink
843
844 ; Plot title
845 jsr plot_frame_title
846 dec capson
847 ; Print instructions
848 jsr instructions
849
850 ; Draw fuel circle
851 ldy #0
852 lda #SHORT_CENTRE_X
853 sta cx
854 sty cx+1
855 lda #SHORT_CENTRE_Y
856 sta cy
857 sty cy+1
858 lda _fuel
859 sta rad
860 sty rad+1
861 jsr _circleMidpoint
862
863 ; Initialize seed for this galaxy
864 jsr init_seed
865
866 ; Loop creating systems
867 lda #$ff
868 sta num
869
870 loop3
871 inc num
872
873 jsr in_range
874 bpl next
875
876
877 ; Ok it is in range, prepare where to place the name
878 ; int x = (dx*4) + SHORT_CENTRE_X;
879 ; int col = (x/8) + 1;
880 ; int y = (dy*2) + SHORT_CENTRE_Y;
881 ; int row = (y/8);
882
883 ldx _seed+3
884 ldy _seed+1
885 jsr universe_to_short_chart
886 stx plotX
887 sty plotY
888 txa
889 lsr
890 lsr
891 lsr
892 sta col
893 inc col
894
895 tya
896 lsr
897 lsr
898 lsr
899 sta row
900
901 ; if (names[row] != 0) {
902 ; row++;
903 ; if (names[row] != 0) {
904 ; row-=2;
905 ; }
906 ; }
907
908
909 ldx row
910 lda names,x
911 beq cont
912 inx
913 inc row
914 lda names,x
915 beq cont
916 dec row
917 dec row
918
919 cont
920
921 ; if (row >= 2 && row < 19 ) {
922 ; if ( names[row] == 0) {
923 ; // draw the name
924 ; names[row] = 0xff;
925 ; textmod = 0x80;
926 ; //g_bindex = 0;
927 ; g_xc = col;
928 ; g_yc = row;
929 ; christen_planet(cseed);
930 ; }
931
932 ldx row
933 cpx #2
934 bcc next
935 cpx #19
936 bcs next
937
938 lda names,x
939 bne noprint
940
941 ; Draw the name
942
943 ;ldx row
944 lda #$ff
945 sta names,x
946 jsr name_planet
947 lda col
948 asl
949 asl
950 asl
951 clc
952 adc #5
953 tax
954 lda row
955 asl
956 asl
957 asl
958 clc
959 adc #2
960 tay
961 jsr gotoXY
962 ;lda #<_hyp_system+NAME
963 ;ldx #>_hyp_system+NAME
964 ;jsr print
965 jsr gs_planet_name
966
967 noprint
968
969 ; plot the star
970 ; // bigstars
971 ; int size = 2+ (cseed.s5 & 1) + g_carry;
972 ; sun(x,y,size,0);
973 jsr box
974
975 next
976
977 jsr tweakseed4
978 lda num
979 cmp #$ff
980 beq end
981 jmp loop3
982
983 end
984 ; Draw the big cursor
985 lda #SHORT_CENTRE_X
986 sta plotX
987 lda #SHORT_CENTRE_Y
988 sta plotY
989 lda #12
990 jsr plot_cross
991
992
993 ; Draw the cursor
994 ldx _hyp_system+SYSX
995 ldy _hyp_system+SYSY
996
997 ; Check if in range
998 stx tmp2
999 sty tmp2+1
1000 jsr in_range2
1001 bmi inside
1002
1003 ldx #SHORT_CENTRE_X
1004 ldy #SHORT_CENTRE_Y
1005 jmp default
1006 inside
1007 ldx tmp2
1008 ldy tmp2+1
1009 jsr universe_to_short_chart
1010 default
1011 sty plotY
1012 stx plotX
1013 lda #6
1014 jsr plot_cross
1015
1016 ;jsr restore_seed
1017
1018 jsr _infoplanet
1019 jmp _makesystem ; This is jsr/rts
1020
1021 .)
1022
1023
1024
1025 box
1026 .(
1027 ; Draws a box at planet's position (plotX and plotY) with the
1028 ; size depending on the size of the planet
1029
1030 ; Get the size
1031 lda _seed+5
1032 and #1
1033 clc
1034 adc #1
1035 sta tmp2
1036
1037 lda plotY
1038 sec
1039 sbc tmp2
1040 sta plotY
1041
1042
1043 lda plotX
1044 sec
1045 sbc tmp2
1046 sta inipX+1
1047
1048
1049 lda tmp2
1050 asl
1051 sta tmp2
1052 sta looprows+1
1053
1054 looprows
1055 lda #0 ; SMC
1056 sta tmp3
1057
1058 inipX
1059 lda #0 ; SMC
1060 sta plotX
1061
1062 loopcols
1063 ldx plotX
1064 ldy plotY
1065 jsr pixel_address_real
1066 eor (tmp0),y
1067 sta (tmp0),y
1068
1069 inc plotX
1070 dec tmp3
1071 bpl loopcols
1072
1073 inc plotY
1074 dec tmp2
1075 bpl looprows
1076
1077 rts
1078
1079 .)
1080
1081 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1082 ; plot_cross
1083 ; Draws (with eor) a cross (clipped) at
1084 ; current plotX, plotY position
1085 ; with size passed in reg A.
1086 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1087
1088 plot_cross
1089 .(
1090 sta cross_size
1091 ; init point X
1092 lda plotX
1093 sec
1094 sbc cross_size
1095 cmp #12
1096 bcs inside1
1097 lda #12
1098 inside1
1099 sta inic
1100
1101 lda plotX
1102 clc
1103 adc cross_size
1104 cmp #240
1105 bcc inside2
1106 lda #240
1107 inside2
1108 sta endc+1
1109
1110 ; horizontal arm
1111
1112 loophor
1113 ldy plotY
1114 ldx inic
1115 jsr pixel_address_real
1116 eor (tmp0),y
1117 sta (tmp0),y
1118 inc inic
1119 lda inic
1120 endc
1121 cmp #0 ;SMC
1122 bne loophor
1123
1124 ; vertical arm
1125 lda plotY
1126 sec
1127 sbc cross_size
1128 cmp #6
1129 bcs inside3
1130 lda #6
1131 inside3
1132 sta inic
1133
1134 lda plotY
1135 clc
1136 adc cross_size
1137 cmp #200
1138 bcc inside4
1139 lda #199
1140 inside4
1141 sta endc2+1
1142
1143 loopver
1144 ldx plotX
1145 ldy inic
1146 jsr pixel_address_real
1147 eor (tmp0),y
1148 sta (tmp0),y
1149 inc inic
1150 lda inic
1151 endc2
1152 cmp #0 ; SMC
1153 bne loopver
1154
1155 rts
1156
1157 cross_size .byt 0
1158 inic .byt 0
1159 .)
1160
1161 _move_cross_v
1162 .(
1163 ;ldy #0
1164 ;lda (sp),y
1165 sta amount+1
1166
1167 lda _current_screen
1168 cmp #SCR_CHART
1169 bne long
1170 lda #168
1171 bne save
1172 long
1173 lda #145
1174 save
1175 sta amount+3
1176
1177 ; erase
1178 lda #6
1179 jsr plot_cross
1180
1181 ; inc/dec Y
1182 clc
1183 lda plotY
1184 amount
1185 adc #0 ;SMC
1186 cmp #199 ; SMC
1187 bcs outside
1188 cmp #14
1189 bcc outside
1190 sta plotY
1191 outside
1192
1193 lda #6
1194 jsr plot_cross
1195 rts
1196
1197 .)
1198
1199 _move_cross_h
1200 .(
1201 ;ldy #0
1202 ;lda (sp),y
1203
1204 sta amount+1
1205 ; erase
1206 lda #6
1207 jsr plot_cross
1208
1209 ; inc/dec X
1210 clc
1211 lda plotX
1212 amount
1213 adc #0 ;SMC
1214 cmp #239
1215 bcs outside1
1216 cmp #12
1217 bcc outside2
1218 sta plotX
1219 jmp plot
1220 outside1
1221 lda _current_screen
1222 cmp #SCR_GALAXY
1223 bne plot
1224 lda scroll
1225 bne plot
1226 inc scroll
1227 lda plotX
1228 sec
1229 sbc #SCROLL_AMOUNT
1230 sta plotX
1231 jmp plot_galaxy_with_scroll
1232 outside2
1233 lda _current_screen
1234 cmp #SCR_GALAXY
1235 bne plot
1236 lda scroll
1237 beq plot
1238 dec scroll
1239 lda plotX
1240 clc
1241 adc #SCROLL_AMOUNT
1242 sta plotX
1243 jmp plot_galaxy_with_scroll
1244 plot
1245 lda #6
1246 jsr plot_cross
1247
1248 rts
1249
1250 .)
1251
1252
1253
1254 ; Convert coordinates in regs X,Y to universe coordinates in a
1255 ; short-range chart and back
1256
1257 universe_to_short_chart
1258 .(
1259 txa
1260 sec
1261 sbc _cpl_system+SYSX
1262 asl
1263 asl
1264 clc
1265 adc #SHORT_CENTRE_X
1266 tax
1267
1268 tya
1269 sec
1270 sbc _cpl_system+SYSY
1271 asl
1272 clc
1273 adc #SHORT_CENTRE_Y
1274 tay
1275
1276 rts
1277
1278 .)
1279
1280 short_chart_to_universe
1281 .(
1282 txa
1283 sec
1284 sbc #SHORT_CENTRE_X
1285 bmi by4b
1286 lsr
1287 lsr
1288 jmp by4end
1289 by4b
1290 sec
1291 ror
1292 sec
1293 ror
1294 by4end
1295
1296 clc
1297 adc _cpl_system+SYSX
1298 tax
1299
1300 tya
1301 sec
1302 sbc #SHORT_CENTRE_Y
1303 bmi by2
1304 clc
1305 bcc by2b
1306 by2
1307 sec
1308 by2b
1309 ror
1310 clc
1311 adc _cpl_system+SYSY
1312 tay
1313
1314 rts
1315 .)
1316
1317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1318 ; snap_to_planet
1319 ; Finds a planet closest to a given coordinate (x,y)
1320 ; passed in the X and Y registers
1321 ; It is the next hyperspace destination
1322 ; result planet num is returned in reg a
1323 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1324 snap_to_planet
1325 .(
1326
1327 lda #$ff
1328 sta tmp1
1329
1330 lda _dest_num
1331 sta tmp1+1
1332
1333 stx tmp0 ; Cursor X
1334 sty tmp0+1 ; Cursor Y
1335
1336 ; Initialize seed for this galaxy
1337 jsr init_seed
1338
1339 ; Loop creating systems
1340 lda #$ff
1341 sta num
1342
1343 loop3
1344 inc num
1345
1346 lda _current_screen
1347 cmp #SCR_CHART
1348 bne nocheck
1349 jsr in_range ; BEWARE. In long-chart this should not be called!!
1350 bpl next
1351
1352 nocheck
1353 lda tmp0
1354 sec
1355 sbc _seed+3 ; Get X
1356 bpl noneg
1357 eor #$ff
1358 clc
1359 adc #1
1360 noneg
1361 cmp #10
1362 bcs next
1363 sta tmp
1364
1365 lda tmp0+1
1366 sec
1367 sbc _seed+1 ; Get Y
1368 bpl noneg2
1369 eor #$ff
1370 clc
1371 adc #1
1372 noneg2
1373 cmp #10
1374 bcs next
1375
1376 cmp tmp
1377 bcs ygreater
1378 clc
1379 adc tmp
1380 adc tmp
1381 jmp check
1382 ygreater
1383 asl
1384 clc
1385 adc tmp
1386 check
1387 lsr
1388 cmp tmp1
1389 bcs next
1390
1391 sta tmp1
1392 lda num
1393 sta tmp1+1
1394
1395 next
1396 jsr tweakseed4
1397 lda num
1398 cmp #$ff
1399 bne loop3
1400
1401 lda tmp1+1
1402 rts
1403
1404 .)
1405
1406
1407 _find_planet
1408 .(
1409
1410 ldx plotX
1411 ldy plotY
1412 lda _current_screen
1413 cmp #SCR_GALAXY
1414 bne short
1415 jsr long_chart_to_universe
1416 jmp snap
1417 short
1418 jsr short_chart_to_universe
1419 snap
1420 jsr snap_to_planet
1421 ldx tmp1
1422 cpx #$ff
1423 beq noplanet
1424 sta _dest_num
1425
1426 jsr _infoplanet
1427 jsr _makesystem
1428
1429 lda #6
1430 jsr plot_cross
1431 ldx _hyp_system+SYSX
1432 ldy _hyp_system+SYSY
1433 lda _current_screen
1434 cmp #SCR_GALAXY
1435 bne short2
1436 jsr universe_to_long_chart
1437 jmp snap2
1438 short2
1439 jsr universe_to_short_chart
1440 snap2
1441 stx plotX
1442 sty plotY
1443 lda #6
1444 jsr plot_cross
1445 jmp print_distinfo ; This is jsr/rts
1446
1447 noplanet
1448 rts
1449 .)
1450
1451 ; /**-Generate system info from seed **/
1452
1453 _makesystem
1454 .(
1455
1456 ;unsigned int pair1,pair2,pair3,pair4;
1457 ;unsigned int longnameflag;
1458
1459 ;system.x=((seed.w1)>>8);
1460 ;system.y=((seed.w0)>>8);
1461
1462 lda _seed+3 ; HI part of seed.w1
1463 sta _hyp_system+SYSX
1464 lda _seed+1
1465 sta _hyp_system+SYSY
1466
1467 ; system.govtype =(((seed.w1)>>3)&7); /* bits 3,4 &5 of w1 */
1468 lda _seed+2
1469 lsr
1470 lsr
1471 lsr
1472 and #7
1473 sta _hyp_system+GOVTYPE
1474
1475 ;system.economy =(((seed.w0)>>8)&7); /* bits 8,9 &A of w0 */
1476 lda _seed+1
1477 and #%00000111
1478 sta _hyp_system+ECONOMY
1479
1480 ;if (system.govtype <=1)
1481 ;{ system.economy = ((system.economy)|2);
1482 ;}
1483
1484 lda _hyp_system+GOVTYPE
1485 bpl nothing
1486 lda _hyp_system+ECONOMY
1487 ora #2
1488 sta _hyp_system+ECONOMY
1489 nothing
1490 ;system.techlev =(((seed.w1)>>8)&3)+((system.economy)^7);
1491 ;system.techlev +=((system.govtype)>>1);
1492 ;if (((system.govtype)&1)==1) system.techlev+=1;
1493 ;/* C simulation of 6502's LSR then ADC */
1494
1495 lda _hyp_system+ECONOMY
1496 eor #7
1497 sta tmp
1498 lda _seed+3
1499 and #3
1500 clc
1501 adc tmp
1502 sta tmp
1503 lda _hyp_system+GOVTYPE
1504 lsr
1505 adc tmp
1506 sta _hyp_system+TECHLEV
1507
1508 ;system.population = 4*(system.techlev) + (system.economy);
1509 ;system.population += (system.govtype) + 1;
1510
1511 ; sta _hyp_system+POPUL
1512 ; lda #0
1513 ; sta _hyp_system+POPUL+1
1514 ;
1515 ; asl _hyp_system+POPUL
1516 ; rol _hyp_system+POPUL+1
1517 ; clc
1518 ; asl _hyp_system+POPUL
1519 ; rol _hyp_system+POPUL+1
1520
1521 ; lda _hyp_system+POPUL
1522
1523 asl
1524 asl
1525
1526 clc
1527 adc _hyp_system+ECONOMY
1528 ; bne nocarry2
1529 ; inc _hyp_system+POPUL+1
1530 ;nocarry2
1531 ; sta _hyp_system+POPUL
1532
1533 ; lda _hyp_system+GOVTYPE
1534 ; clc
1535 ; adc _hyp_system+POPUL
1536 ; bne nocarry
1537 ; inc _hyp_system+POPUL+1
1538 ;nocarry
1539 clc
1540 adc _hyp_system+GOVTYPE
1541 clc
1542 adc #1
1543
1544 sta _hyp_system+POPUL
1545
1546 ;system.productivity = (((system.economy)^7)+3)*((system.govtype)+4);
1547 ;system.productivity *= (system.population)*8;
1548
1549 lda _hyp_system+ECONOMY
1550 eor #7
1551 clc
1552 adc #3
1553 sta op1
1554 lda #0
1555 sta op1+1
1556 sta op2+1
1557
1558 lda _hyp_system+GOVTYPE
1559 clc
1560 adc #4
1561 sta op2
1562
1563 jsr mul16uc
1564 ; 16-bit result in op1,op1+1
1565
1566 lda #0
1567 sta op2+1
1568
1569 lda _hyp_system+POPUL
1570
1571 ldx #3
1572 loop
1573 asl
1574 rol op2+1
1575 dex
1576 bne loop
1577
1578 sta op2
1579
1580 jsr mul16uc
1581
1582 lda op1
1583 sta _hyp_system+PROD
1584 lda op1+1
1585 sta _hyp_system+PROD+1
1586
1587
1588 ;system.radius = 256*((((seed.w2)>>8)&15)+11) + system.x;
1589
1590 lda _seed+5
1591 and #15
1592 clc
1593 adc #11
1594 sta _hyp_system+RADIUS+1
1595 lda _hyp_system+SYSX
1596 sta _hyp_system+RADIUS
1597
1598
1599 ;system.goatsoupseed.a = seed.w1 & 0xFF;;
1600 ;system.goatsoupseed.b = seed.w1 >>8;
1601 ;system.goatsoupseed.c = seed.w2 & 0xFF;
1602 ;system.goatsoupseed.d = seed.w2 >> 8;
1603 ldx #3
1604 loop3
1605 lda _seed+2,x
1606 sta _hyp_system+SEED,x
1607 dex
1608 bpl loop3
1609
1610 jmp name_planet ; This is jsr/rts
1611
1612 ;return;
1613 ;rts
1614 .)
1615
1616
1617 ; Generate planet's name
1618
1619 name_planet
1620 .(
1621
1622 ; Save seed
1623 ldx #5
1624 loop4
1625 lda _seed,x
1626 sta temp_seed,x
1627 dex
1628 bpl loop4
1629
1630 ;longnameflag=(seed.w0)&64;
1631 lda _seed
1632 and #64
1633 pha
1634
1635 ;pair1=2*(((seed.w2)>>8)&31); tweakseed();
1636 ;pair2=2*(((seed.w2)>>8)&31); tweakseed();
1637 ;pair3=2*(((seed.w2)>>8)&31); tweakseed();
1638 ;pair4=2*(((seed.w2)>>8)&31); tweakseed();
1639 ; /* Always four iterations of random number */
1640
1641 ldx #0
1642 stx loop2+1
1643 loop2
1644 ldx #00
1645
1646 lda _seed+5
1647 and #31
1648 asl
1649 sta tmp0,x
1650 jsr _tweakseed
1651
1652 inc loop2+1
1653 lda #4
1654 cmp loop2+1
1655 bne loop2
1656
1657 ;(system.name)[0]=pairs[pair1];
1658 ;(system.name)[1]=pairs[pair1+1];
1659 ;(system.name)[2]=pairs[pair2];
1660 ;(system.name)[3]=pairs[pair2+1];
1661 ;(system.name)[4]=pairs[pair3];
1662 ;(system.name)[5]=pairs[pair3+1];
1663 ; if(longnameflag) /* bit 6 of ORIGINAL w0 flags a four-pair name */
1664 ;{
1665 ;(system.name)[6]=pairs[pair4];
1666 ;(system.name)[7]=pairs[pair4+1];
1667 ;(system.name)[8]=0;
1668 ;}
1669 ;else (system.name)[6]=0;
1670
1671 ldy tmp0
1672 lda _pairs,y
1673 sta temp_name ;_hyp_system+NAME
1674 lda _pairs+1,y
1675 sta temp_name+1 ;_hyp_system+NAME+1
1676
1677 ldy tmp0+1
1678 lda _pairs,y
1679 sta temp_name+2; _hyp_system+NAME+2
1680 lda _pairs+1,y
1681 sta temp_name+3 ;_hyp_system+NAME+3
1682
1683 ldy tmp0+2
1684 lda _pairs,y
1685 sta temp_name+4 ;_hyp_system+NAME+4
1686 lda _pairs+1,y
1687 sta temp_name+5 ;_hyp_system+NAME+5
1688
1689 pla
1690 bne cont
1691 lda #0
1692 sta temp_name+6 ;_hyp_system+NAME+6
1693 beq end
1694 cont
1695
1696 ldy tmp0+3
1697 lda _pairs,y
1698 sta temp_name+6 ;_hyp_system+NAME+6
1699 lda _pairs+1,y
1700 sta temp_name+7 ;_hyp_system+NAME+7
1701
1702 lda #0
1703 sta temp_name+8 ;_hyp_system+NAME+8
1704
1705
1706 end
1707 ; restore seed
1708 ldx #5
1709 loop1
1710 lda temp_seed,x
1711 sta _seed,x
1712 dex
1713 bpl loop1
1714
1715 ; Copy name
1716 ldx #0
1717 ldy #0
1718
1719 loop3
1720 lda temp_name,x
1721 sta _hyp_system+NAME,y
1722 beq end2
1723 cmp #"."
1724 beq noincy
1725 iny
1726 noincy
1727 inx
1728 bpl loop3
1729
1730 end2
1731 rts
1732 .)
1733
1734
1735
1736
1737 ; Searches for a string. tmp0 holds pointer to base and x holds offset (in strings).
1738 search_string
1739 .(
1740 txa
1741 bne cont
1742 rts
1743 cont
1744 ldy #0
1745 loop
1746 lda (tmp0),y
1747 beq out ; Search for zero
1748 iny
1749 bne loop
1750
1751 out
1752 ; Found the end. Add length to pointer
1753 iny
1754 tya
1755 clc
1756 adc tmp0
1757 bcc nocarry
1758 inc tmp0+1
1759 nocarry
1760 sta tmp0
1761
1762 dex
1763 bne cont
1764
1765 rts
1766
1767 .)
1768
1769
1770 search_string_and_print
1771 .(
1772 jsr search_string
1773 jmp print2
1774 .)
1775
1776
1777 ; Prints the colonial type
1778
1779 _print_colonial
1780 .(
1781
1782 ;if (hyp_seed.s4 & 0x80) {
1783 ;// bug-eyed rabbits
1784
1785 lda _seed+4
1786 bpl humans
1787
1788 ;int ct = (hyp_seed.s5/4)&7;
1789 ;if (ct < 3) {
1790 ; text2buffer(FIERCE+ct);
1791 ; text2buffer(' ');
1792 ; textmod = NAME_CASE;
1793 ;}
1794
1795 lda _seed+5
1796 lsr
1797 lsr
1798 and #7
1799 cmp #3
1800 bcs cont1
1801
1802 ; Print Fierce
1803 tax
1804 lda #<Fierce
1805 sta tmp0
1806 lda #>Fierce
1807 sta tmp0+1
1808 jsr search_string_and_print
1809 jsr put_space
1810
1811 cont1
1812
1813 ;ct = (hyp_seed.s5/32);
1814 ;if (ct < 6) {
1815 ; text2buffer(CREATURE_TYPE+ct);
1816 ; text2buffer(' ');
1817 ; textmod = NAME_CASE;
1818 ;}
1819
1820 lda _seed+5
1821 lsr
1822 lsr
1823 lsr
1824 lsr
1825 lsr
1826 cmp #6
1827 bcs cont2
1828
1829 ; Print Type
1830 tax
1831 lda #<Type
1832 sta tmp0
1833 lda #>Type
1834 sta tmp0+1
1835 jsr search_string_and_print
1836 jsr put_space
1837
1838
1839 cont2
1840 ;ct = (hyp_seed.s3^hyp_seed.s1)&7;
1841 ;if (ct < 6) {
1842 ; text2buffer(BUG_EYED+ct);
1843 ; text2buffer(' ');
1844 ; textmod = NAME_CASE;
1845 ;}
1846
1847 lda _seed+3
1848 eor _seed+1
1849 and #7
1850 pha
1851 cmp #6
1852 bcs cont3
1853
1854 ; Print bug-eyed
1855 tax
1856 lda #<Bugeyed
1857 sta tmp0
1858 lda #>Bugeyed
1859 sta tmp0+1
1860 jsr search_string_and_print
1861 jsr put_space
1862
1863 cont3
1864
1865 ;ct += (hyp_seed.s5&3);
1866 ;ct &= 7;
1867 ;text2buffer(RODENT+ct);
1868 pla
1869 sta tmp
1870 lda _seed+5
1871 and #3
1872 clc
1873 ;adc _seed+5
1874 adc tmp
1875 and #7
1876
1877 ; Print race
1878 tax
1879 lda #<Race
1880 sta tmp0
1881 lda #>Race
1882 sta tmp0+1
1883 jmp search_string_and_print
1884
1885
1886 ; } else {
1887 ; text2buffer(HUMAN_COLONIAL);
1888 ; }
1889
1890
1891 humans
1892 lda #<HumanCol
1893 sta tmp0
1894 lda #>HumanCol
1895 sta tmp0+1
1896 jsr print2
1897 rts
1898
1899
1900
1901 .)
1902
1903
1904
1905
1906 ;; Let's go with my own version of goat_soup....
1907 ;; Should be consistent with TXTELITE...
1908
1909
1910 gs_planet_name
1911 .(
1912 ; int i=1;
1913 ; putchar(psy->name[0]);//printf("%c",psy->name[0]);
1914 ; while(psy->name[i]!='\0') putchar(tolower(psy->name[i++]));//printf("%c",tolower(psy->name[i++]));
1915
1916 ldx #0
1917 firstloop
1918 lda _hyp_system+NAME,x
1919 cmp #"."
1920 bne printfirst
1921 inx
1922 bne firstloop
1923 printfirst
1924 ;stx savx+1
1925 jsr put_char
1926 savx
1927 ;ldx #0
1928 inx
1929 loop
1930 lda _hyp_system+NAME,x
1931 beq end
1932 cmp #"."
1933 beq noprint
1934 ora #$20 ; lowcase it
1935 stx savx2+1
1936 jsr put_char
1937 savx2
1938 ldx #0 ; again sfc
1939 noprint
1940 inx
1941 jmp loop
1942 end
1943 rts
1944 .)
1945
1946 gs_planet_nameian
1947 .(
1948 ; int i=1;
1949 ; printf("%c",psy->name[0]);
1950 ; while(psy->name[i]!='\0')
1951 ; { if((psy->name[i+1]!='\0') || ((psy->name[i]!='E') && (psy->name[i]!='I')))
1952 ; putchar(tolower(psy->name[i]));//printf("%c",tolower(psy->name[i]));
1953 ; i++;
1954 ; }
1955 ; printf("ian");
1956 ldx #0
1957 firstloop
1958 lda _hyp_system+NAME,x
1959 cmp #"."
1960 bne printfirst
1961 inx
1962 bne firstloop
1963 printfirst
1964 stx savx+1
1965 jsr put_char
1966 savx
1967 ldx #0
1968 inx
1969 loop
1970 lda _hyp_system+NAME,x
1971 beq end
1972 cmp #"."
1973 beq noprint
1974 ldy _hyp_system+NAME+1,x
1975 bne nocheck
1976 cmp #"I"
1977 beq noprint
1978 cmp #"E"
1979 beq noprint
1980 nocheck
1981 ora #$20 ; lowcase it
1982 stx savx2+1
1983 jsr put_char
1984 savx2
1985 ldx #0 ; again sfc
1986 noprint
1987 inx
1988 jmp loop
1989 end
1990
1991 ; print "ian"
1992 lda #<ian_str
1993 sta tmp0
1994 lda #>ian_str
1995 sta tmp0+1
1996 jsr print2
1997 rts
1998
1999 .)
2000
2001 gs_random_name
2002 .(
2003 ;int i;
2004 ;int len = gen_rnd_number() & 3;
2005 jsr _gen_rnd_number
2006 and #3
2007 sta index
2008 ;for(i=0;i<=len;i++)
2009 lda #0
2010 sta lowcase
2011 loop
2012 ;{ int x = gen_rnd_number() & 0x3e;
2013 jsr _gen_rnd_number
2014 and #$3e
2015 tay
2016 ; if(pairs0[x]!='.') printf("%c",pairs0[x]);
2017 lda _pairs0,y
2018 ;beq l1
2019 cmp #"."
2020 beq notthis
2021 ora lowcase
2022 l1
2023 ldx #$20
2024 stx lowcase
2025 jsr put_char
2026 notthis
2027 ; if(i && (pairs0[x+1]!='.')) printf("%c",pairs0[x+1]);
2028 lda index
2029 beq notthat
2030 iny
2031 lda _pairs0,y
2032 ;beq l2
2033 cmp #"."
2034 beq notthat
2035 ora lowcase
2036 l2
2037 ldx #$20
2038 stx lowcase
2039 jsr put_char
2040 notthat
2041
2042 dec index
2043 bpl loop
2044 ;}
2045
2046 rts
2047 .)
2048
2049
2050
2051 #define gs_sourcep tmp6
2052
2053
2054 gs_index .byt 0
2055
2056 ; void goat_soup(const char *source,plansys * psy)
2057 ; {
2058 ; Pass parameters as pointer in x (hi) a (lo)
2059 goat_soup
2060 .(
2061
2062 sta gs_sourcep
2063 stx gs_sourcep+1
2064 lda #0
2065 sta gs_index
2066
2067 main_loop
2068
2069 ; unsigned char c;
2070 ; for(;;)
2071 ; {
2072 ; c=*(source); source++;
2073 ; if(c=='\0') break;
2074 ldy gs_index
2075 lda (gs_sourcep),y
2076 bne cont
2077 rts
2078 cont
2079 ; if(c<(unsigned char)0x80) putchar(c);//printf("%c",c);
2080
2081 ; This changed. It is a char if 32 or greater than 38... (though only up to 36 are used)
2082 ; if it is zero or negative (a token)
2083 ; bmi decode
2084 ; now is...
2085 bmi ischar
2086 beq ischar
2087 cmp #32
2088 beq ischar
2089 cmp #38
2090 bcc decode
2091
2092 ; If it is greater than 123 it is a string code
2093 cmp #123
2094 bcs code_str
2095
2096 ischar
2097 jsr decomp; put_char
2098 jmp next
2099 decode
2100 ; else
2101 ; {
2102 ; It is a code...
2103 ; if (c <=(unsigned char)0xA4)
2104 ; { int rnd = gen_rnd_number();
2105 ; goat_soup(desc_list[c-0x81].option[(rnd >= (unsigned char)0x33)+(rnd >= (unsigned char)0x66)+(rnd >= (unsigned char)0x99)+(rnd >= (unsigned char)0xCC)],psy);
2106 ; }
2107
2108 ; This has changed. It is a code allways if this is reached...
2109 ;cmp #$a5
2110 ;bcs code_str
2111
2112 pha
2113 jsr _gen_rnd_number
2114
2115 pha
2116 lda #0
2117 sta tmp
2118 pla
2119
2120 cmp #$33
2121 bcc next1
2122 inc tmp
2123 next1
2124 cmp #$66
2125 bcc next2
2126 inc tmp
2127 next2
2128 cmp #$99
2129 bcc next3
2130 inc tmp
2131 next3
2132 cmp #$cc
2133 bcc next4
2134 inc tmp
2135 next4
2136
2137 ; Multiply c-$81 by 5
2138 ; This also changed.
2139 ; It is just c-1 unless greater than 32
2140 pla
2141 cmp #32
2142 bcc less32
2143 sec
2144 sbc #1
2145 less32
2146 sec
2147 ;sbc #$81
2148 sbc #1
2149 sta tmp+1
2150 asl
2151 asl
2152 clc
2153 adc tmp+1
2154
2155 ; Add tmp
2156 adc tmp
2157
2158 ; Search for string
2159 tax
2160 lda #<desc_list
2161 sta tmp0
2162 lda #>desc_list
2163 sta tmp0+1
2164 jsr search_string
2165
2166
2167 ; Prepare re-entrant call to goat_soup
2168
2169 lda gs_index
2170 pha
2171 lda gs_sourcep
2172 pha
2173 lda gs_sourcep+1
2174 pha
2175
2176 lda tmp0
2177 ldx tmp0+1
2178 jsr goat_soup
2179
2180 ; Recover previous params
2181 pla
2182 sta gs_sourcep+1
2183 pla
2184 sta gs_sourcep
2185 pla
2186 sta gs_index
2187
2188 jmp next
2189 code_str
2190 ; It is an string code
2191 #ifdef 0
2192 ; else switch(c)
2193 ; { case 0xB0: /* planet name */
2194 ; {
2195 ; int i=1;
2196 ; putchar(psy->name[0]);//printf("%c",psy->name[0]);
2197 ; while(psy->name[i]!='\0') putchar(tolower(psy->name[i++]));//printf("%c",tolower(psy->name[i++]));
2198 ; } break;
2199 ; case 0xB1: /* <planet name>ian */
2200 ; {
2201 ; int i=1;
2202 ; printf("%c",psy->name[0]);
2203 ; while(psy->name[i]!='\0')
2204 ; { if((psy->name[i+1]!='\0') || ((psy->name[i]!='E') && (psy->name[i]!='I')))
2205 ; putchar(tolower(psy->name[i]));//printf("%c",tolower(psy->name[i]));
2206 ; i++;
2207 ; }
2208 ; printf("ian");
2209 ; } break;
2210 ; case 0xB2: /* random name */
2211 ; {
2212 ; int i;
2213 ; int len = gen_rnd_number() & 3;
2214 ; for(i=0;i<=len;i++)
2215 ; { int x = gen_rnd_number() & 0x3e;
2216 ; if(pairs0[x]!='.') putchar(pairs0[x]);//printf("%c",pairs0[x]);
2217 ; if(i && (pairs0[x+1]!='.')) putchar(pairs0[x+1]);//printf("%c",pairs0[x+1]);
2218 ; }
2219 ; } break;
2220 ; default: printf("<bad char in data [%X]>",c); return;
2221 ; } /* endswitch */
2222 #endif
2223 ; Implement this as a jump table
2224 sec
2225 sbc #$7b
2226 tax
2227 lda gs_jump_lo,x
2228 sta jump+1
2229 lda gs_jump_hi,x
2230 sta jump+2
2231 jump
2232 jsr $1234 ; This is self-modified...
2233
2234 ; } /* endelse */
2235 ; } /* endwhile */
2236 ; } /* endfunc */
2237 ;
2238 ; /**+end **/
2239
2240 next
2241 inc gs_index
2242 jmp main_loop
2243 .)
2244
2245
2246
2247
2248 #define STR_DATA 0
2249 #define STR_DISTANCE 1
2250 #define STR_ECONOMY 2
2251 #define STR_GOV 3
2252 #define STR_TECH 4
2253 #define STR_GROSS 5
2254 #define STR_RADIUS 6
2255 #define STR_POP 7
2256 #define STR_KM 8
2257 #define STR_BILLION 9
2258 #define STR_LY 10
2259 #define STR_CR 11
2260 #define STR_MKT 12
2261 #define STR_PROD 13
2262 #define STR_UNIT 14
2263 #define STR_PRICE 15
2264 #define STR_QUANT 16
2265
2266
2267 diff
2268 .(
2269 lda tmp
2270 cmp tmp+1
2271 bcs ok
2272 pha
2273 lda tmp+1
2274 sta tmp
2275 pla
2276 sta tmp+1
2277
2278 ok
2279 lda tmp
2280 sec
2281 sbc tmp+1
2282 rts
2283
2284 .)
2285
2286
2287 print_distance
2288 .(
2289 lda _cpl_system+SYSX ; Current X pos
2290 sta tmp
2291 lda _hyp_system+SYSX
2292 sta tmp+1
2293 jsr diff
2294
2295 sta op1
2296
2297 lda _cpl_system+SYSY
2298 sta tmp
2299 lda _hyp_system+SYSY
2300 sta tmp+1
2301 jsr diff
2302
2303 sta sav_a+1
2304 ora op1
2305 beq same
2306
2307 ; Show distance as 4*sqrt(x*x+y*y/4)
2308 lda #0
2309 sta op1+1
2310 sta op2+1
2311 lda op1
2312 lsr
2313 sta op1
2314 sta op2
2315 jsr mul16
2316
2317 lda op1
2318 sta tmp
2319 lda op1+1
2320 sta tmp+1
2321 sav_a
2322 lda #0
2323 lsr
2324 lsr
2325 sta op1
2326 sta op2
2327 lda #0
2328 sta op1+1
2329 sta op2+1
2330 jsr mul16
2331
2332 clc
2333 lda tmp
2334 adc op1
2335 sta op1
2336 lda tmp+1
2337 adc op1+1
2338 sta op1+1
2339 jsr SqRoot
2340
2341 ; Print distance (at last!)
2342 ldx #STR_DISTANCE
2343 jsr printtitle
2344 lda op2
2345 asl
2346 rol op2+1
2347 asl
2348 rol op2+1
2349 asl
2350 rol op2+1
2351 sta op2
2352 lda op2
2353 sta _dest_dist
2354 lda op2+1
2355 sta _dest_dist+1
2356 jsr print_float
2357 ldx #STR_LY
2358 jsr printtail ; This is jsr/rts
2359 jsr perform_CRLF
2360 same
2361 rts
2362
2363 .)
2364
2365 _printsystem
2366 .(
2367 jsr draw_red_frame
2368 inc capson
2369
2370 ldx #STR_DATA
2371 jsr printtail
2372 jsr pr_colon
2373
2374 jsr gs_planet_name
2375
2376 dec capson
2377
2378 jsr perform_CRLF
2379 jsr perform_CRLF
2380
2381 ; Print name
2382 ; Draw a line
2383 ; If distance <> 0 print distance
2384
2385 jsr print_distance
2386
2387 ; Print economy
2388 ldx #STR_ECONOMY
2389 jsr printtitle
2390 ldx _hyp_system+ECONOMY
2391 lda #<econnames
2392 sta tmp0
2393 lda #>econnames
2394 sta tmp0+1
2395 jsr search_string
2396 lda tmp0
2397 ldx tmp0+1
2398 jsr printnl
2399
2400 ; Print Government
2401 ldx #STR_GOV
2402 jsr printtitle
2403 ldx _hyp_system+GOVTYPE
2404 lda #<govnames
2405 sta tmp0
2406 lda #>govnames
2407 sta tmp0+1
2408 jsr search_string
2409 lda tmp0
2410 ldx tmp0+1
2411 jsr printnl
2412
2413 ; Print tech level
2414 ldx #STR_TECH
2415 jsr printtitle
2416 lda _hyp_system+TECHLEV
2417 sta op2
2418 lda #0
2419 sta op2+1
2420 jsr print_num
2421 jsr perform_CRLF
2422
2423 ; Print population
2424 ldx #STR_POP
2425 jsr printtitle
2426 lda _hyp_system+POPUL
2427 sta op2
2428 lda #0
2429 sta op2+1
2430 jsr print_float
2431 jsr put_space
2432 ldx #STR_BILLION
2433 jsr printtail
2434 jsr perform_CRLF
2435 jsr perform_CRLF
2436 jsr put_space
2437 lda #"("
2438 jsr put_char
2439 jsr _print_colonial
2440 lda #"s"
2441 jsr put_char
2442 lda #")"
2443 jsr put_char
2444 jsr perform_CRLF
2445
2446
2447 ; Print productivity
2448 ldx #STR_GROSS
2449 jsr printtitle
2450 lda _hyp_system+PROD
2451 sta op2
2452 lda _hyp_system+PROD+1
2453 sta op2+1
2454 jsr print_num
2455 ldx #STR_CR
2456 jsr printtail
2457 jsr perform_CRLF
2458
2459 ; Print radius
2460 ldx #STR_RADIUS
2461 jsr printtitle
2462 lda _hyp_system+RADIUS
2463 sta op2
2464 lda _hyp_system+RADIUS+1
2465 sta op2+1
2466 jsr print_num
2467 ldx #STR_KM
2468 jsr printtail
2469 jsr perform_CRLF
2470 jsr perform_CRLF
2471
2472 ; Goatsoup
2473 ldx #3
2474 loop
2475 lda _hyp_system+SEED,x
2476 sta _rnd_seed,x
2477 dex
2478 bpl loop
2479
2480 inc print2buffer
2481 lda #0
2482 sta buffercounter
2483 lda #<gs_init_str
2484 ldx #>gs_init_str
2485 jsr goat_soup
2486 dec print2buffer
2487 jsr print_goatsoup
2488 rts
2489
2490 .)
2491
2492
2493 print_planet_name
2494 .(
2495 ldx #0
2496 loop
2497 lda _cpl_system+NAME,x
2498 beq end
2499 cmp #"."
2500 beq noprint
2501 jsr put_char
2502 noprint
2503 inx
2504 jmp loop
2505 end
2506 rts
2507
2508 .)
2509
2510 #define START_X_LIST 1
2511
2512
2513 _displaymarket
2514 .(
2515 ; clear selection
2516 lda #$ff
2517 sta _cur_sel
2518 jsr draw_red_frame
2519 inc capson
2520
2521 jsr print_planet_name ; jsr gs_planet_name
2522 jsr put_space
2523 ldx #STR_MKT
2524 jsr printtail
2525
2526 jsr perform_CRLF
2527 jsr perform_CRLF
2528
2529 lda #A_FWCYAN
2530 ;lda #(A_FWWHITE+A_FWCYAN*16+128)
2531 jsr put_code
2532
2533 lda #0
2534 sta count2
2535 loop
2536 ldx count2
2537 lda positionsX,x
2538 tax
2539 jsr gotoX
2540 ldy count2
2541 lda mkstrshi,y
2542 tax
2543 lda mkstrslo,y
2544 jsr print
2545
2546 ldx count2
2547 cpx #2
2548 bne nothing
2549
2550 jsr perform_CRLF
2551 lda #A_FWCYAN
2552 jsr put_code
2553 ldx count2
2554 nothing
2555 inx
2556 stx count2
2557 cpx #8
2558 bne loop
2559
2560 ;jsr perform_CRLF
2561
2562 dec capson
2563
2564 ;for(i=0;i<=lasttrade;i++)
2565 ; {
2566 ; Loop thru the 17 market items
2567 lda #0
2568 sta count2
2569 loop2
2570 ;printf("\n");
2571 jsr perform_CRLF
2572
2573 jsr print_mkt_item
2574 inc count2
2575 lda count2
2576 cmp #17
2577 bne loop2
2578
2579 ; Print instructions
2580 jmp instructions
2581 ;rts
2582 .)
2583
2584 print_mkt_item
2585 .(
2586 ;printf(Names[i]);
2587 lda #(A_FWGREEN+A_FWYELLOW*16+128)
2588 jsr put_code
2589
2590 ldx count2
2591 lda #<Goodnames
2592 sta tmp0
2593 lda #>Goodnames
2594 sta tmp0+1
2595 jsr search_string_and_print
2596
2597 lda #(A_FWWHITE)
2598 jsr put_code
2599
2600 ldx #(16*6)
2601 jsr gotoX
2602
2603 ;printf(" %f",(float)prices[i]/10);
2604
2605 jsr punit
2606
2607 ldx #(18*6)
2608 jsr gotoX
2609 ;jsr put_space
2610 lda count2
2611 asl
2612 tax
2613 lda _prices,x
2614 sta op2
2615 lda _prices+1,x
2616 sta op2+1
2617 ldx #5
2618 jsr print_float_tab
2619
2620 ;printf(" %d",quantities[i]);
2621 ;jsr put_space
2622 ldx #(27*6)
2623 jsr gotoX
2624
2625 ldx count2
2626 lda _quantities,x
2627 jsr prstock
2628
2629 jsr put_space
2630
2631 ;printf(unitnames[Units[i]]);
2632
2633 jsr punit
2634
2635 ;printf(" %d",shipshold[i]);
2636
2637 ldx #(35*6)
2638 jsr gotoX
2639
2640 ldx count2
2641 lda _shipshold,x
2642 jsr prstock
2643
2644 ;jsr punit
2645
2646 ; }
2647
2648 rts
2649 .)
2650
2651
2652 prstock
2653 .(
2654 beq nostock
2655 sta op2
2656 lda #0
2657 sta op2+1
2658 ldx #3
2659 jmp print_num_tab
2660 nostock
2661 jsr put_space
2662 jsr put_space
2663 lda #"-"
2664 jmp put_char ; this is jsr/rts
2665 .)
2666
2667 punit
2668 .(
2669 ldx count2
2670 lda Units,x
2671 tax
2672 lda #<Unitnames
2673 sta tmp0
2674 lda #>Unitnames
2675 sta tmp0+1
2676 jmp search_string_and_print ; this is jsr/rts
2677 .)
2678
2679 print_float_tab
2680 .(
2681 stx tabs+1
2682 jsr itoa
2683 jsr stlen
2684 stx tmp
2685 sec
2686 tabs
2687 lda #00
2688 sbc tmp
2689
2690 tax
2691 loopsp
2692 jsr put_space
2693 dex
2694 bne loopsp
2695 jmp loop
2696
2697 +print_float
2698 jsr itoa
2699 +print_bufconv
2700 loop
2701 ldx #0
2702 text
2703 lda bufconv+1,x
2704 beq butone
2705 lda bufconv,x
2706 jsr put_char
2707 inx
2708 bne text
2709
2710 butone
2711 lda bufconv,x
2712 pha
2713 lda #"."
2714 jsr put_char
2715 pla
2716 jmp put_char ; This is jsr/rts
2717
2718 .)
2719
2720
2721 print_num_tab
2722 .(
2723 stx tabs+1
2724 jsr itoa
2725 jsr stlen
2726 stx tmp
2727 sec
2728 tabs
2729 lda #00
2730 sbc tmp
2731
2732 beq loop
2733 tax
2734 loopsp
2735 jsr put_space
2736 dex
2737 bne loopsp
2738 jmp loop
2739
2740 +print_num
2741 jsr itoa
2742 ;jsr utoa
2743 loop
2744 lda #<bufconv
2745 ldx #>bufconv
2746 jmp print
2747 .)
2748
2749
2750 stlen
2751 .(
2752 ldx #$ff
2753 loop
2754 inx
2755 lda bufconv,x
2756 bne loop
2757
2758 rts
2759 .)
2760
2761 printtitle
2762 .(
2763
2764 jsr perform_CRLF
2765
2766 lda #(A_FWGREEN+A_FWYELLOW*16+128)
2767 jsr put_code
2768 jsr printtail
2769 jmp pr_colon
2770
2771 ;lda #A_FWWHITE
2772 ;jmp put_code
2773
2774 .)
2775 printtail
2776 .(
2777 lda #<str_data
2778 sta tmp0
2779 lda #>str_data
2780 sta tmp0+1
2781 jmp search_string_and_print
2782 .)
2783
2784 ;;; Selection of items
2785 ; Start at row 30 and add 6 per item
2786
2787 get_p
2788 .(
2789 ldx _cur_sel
2790 lda _current_screen
2791 cmp #SCR_MARKET
2792 bne notmarket
2793 lda #24
2794 .byt $2C
2795 notmarket
2796 lda #12
2797 clc
2798 loop
2799 adc #6
2800 dex
2801 bpl loop
2802
2803 tay
2804 ldx #0
2805 jmp gotoXY
2806 .)
2807
2808 remove_hilite
2809 .(
2810 lda _cur_sel
2811 cmp #$ff
2812 beq noerase
2813 jsr get_p
2814 lda #A_BGBLACK
2815 jmp put_code
2816 noerase
2817 rts
2818 .)
2819
2820 set_hilite
2821 .(
2822 jsr get_p
2823 lda #A_BGBLUE
2824 jmp put_code
2825 .)
2826
2827 _inc_sel
2828 .(
2829 jsr remove_hilite
2830 ldx _cur_sel
2831 inx
2832 lda _current_screen
2833 cmp #SCR_MARKET
2834 bne notmarket
2835 cpx #17
2836 bne cont
2837 ldx #0
2838 beq cont
2839 notmarket
2840 cmp #SCR_LOADSAVE
2841 bne notsave
2842 cpx #8
2843 bne cont
2844 ldx #0
2845 beq cont
2846 notsave
2847 cpx equip_items
2848 bne cont
2849 ldx #0
2850 cont
2851 jmp set_sel
2852 .)
2853
2854 _dec_sel
2855 .(
2856 jsr remove_hilite
2857 ldx _cur_sel
2858 dex
2859 bpl cont
2860 lda _current_screen
2861 cmp #SCR_MARKET
2862 bne notmarket
2863 ldx #16
2864 bne cont
2865 notmarket
2866 cmp #SCR_LOADSAVE
2867 bne notsave
2868 ldx #7
2869 bne cont
2870 notsave
2871 ldx equip_items
2872 dex
2873 cont
2874 jmp set_sel
2875 .)
2876
2877
2878 set_sel
2879 .(
2880 stx _cur_sel
2881 jsr set_hilite
2882 jsr SndPoc
2883 lda _current_screen
2884 cmp #SCR_LOADSAVE
2885 bne mkt_status
2886 rts
2887 .)
2888 mkt_status
2889 .(
2890 ; Print player status
2891 ; Cash & free cargo space
2892
2893 jsr prepare_area
2894
2895 lda _current_screen
2896 cmp #SCR_MARKET
2897 bne notmarket
2898
2899 lda #(A_FWCYAN|A_FWWHITE*16+128)
2900 jsr put_code
2901 ldx #>str_freespace
2902 lda #<str_freespace
2903 jsr print
2904 jsr put_space
2905 lda _holdspace
2906 sta op2
2907 lda #0
2908 sta op2+1
2909 ldx #3
2910 jsr print_num_tab
2911 jsr put_space
2912 ldx #>Unitnames
2913 lda #<Unitnames
2914 jsr printnl
2915 notmarket
2916 lda #(A_FWCYAN|A_FWWHITE*16+128)
2917 jsr put_code
2918 jsr put_space
2919 ldx #>str_cash
2920 lda #<str_cash
2921 jsr print
2922 jsr put_space
2923
2924 ; jmp pr_cash is not necessary
2925 ; as it is right beyond this routine
2926
2927 #ifdef HAVE_MISSIONS
2928 jsr pr_cash
2929
2930 lda MissionCargo
2931 beq end
2932 cmp _holdspace
2933 bcc roomok
2934 beq roomok
2935
2936 ldx #>str_missionspace
2937 lda #<str_missionspace
2938 jmp print
2939 /*
2940 lda Missioncargo
2941 sta op2
2942 lda #0
2943 sta op2+1
2944 ldx #3
2945 jmp print_num_tab
2946 */
2947
2948 roomok
2949 ldx #>str_missionspaced
2950 lda #<str_missionspaced
2951 jmp print
2952
2953 end
2954 rts
2955 #endif
2956
2957 .)
2958
2959 pr_cash
2960 .(
2961
2962 ldx #3
2963 loop
2964 lda _cash,x
2965 sta op1,x
2966 dex
2967 bpl loop
2968 jsr ltoa
2969 jsr print_bufconv
2970 jsr put_space
2971 ldx #>str_credits
2972 lda #<str_credits
2973 jmp printnl
2974 .)
2975
2976
2977 ; Check if we have enough cash to pay op2,op2+1 credits
2978 ; C=0 no cash, C=1, we have cash
2979 enough_cash
2980 .(
2981 lda _cash+3
2982 ora _cash+2
2983 bne havecash
2984 lda _cash+1
2985 sta op1+1
2986 lda _cash
2987 sta op1
2988 jmp cmp16
2989 havecash
2990 sec
2991 rts
2992 .)
2993
2994
2995 ; Pay the value in op2,op2+1
2996 dec_cash
2997 .(
2998 ; decrement cash
2999 ; 32-bit substraction here
3000 sec
3001 lda _cash
3002 sbc op2
3003 sta _cash
3004 lda _cash+1
3005 sbc op2+1
3006 sta _cash+1
3007 bcs nomore
3008 lda _cash+2
3009 sbc #0
3010 sta _cash+2
3011 bcs nomore
3012 dec _cash+3
3013 nomore
3014 rts
3015 .)
3016
3017
3018 ; Add op2,op2+1 credits to player
3019 inc_cash
3020 .(
3021 ; increment cash
3022 ; 32-bit addition here
3023 clc
3024 lda _cash
3025 adc op2
3026 sta _cash
3027 lda _cash+1
3028 adc op2+1
3029 sta _cash+1
3030 bcc nomore
3031 lda _cash+2
3032 adc #0
3033 sta _cash+2
3034 bcc nomore
3035 inc _cash+3
3036 nomore
3037 rts
3038 .)
3039
3040
3041 _buy
3042 .(
3043 ; check if there is something for sale
3044 ldx _cur_sel
3045 cpx #$ff
3046 beq nobuy
3047 lda _quantities,x
3048 beq nobuy
3049
3050 ; check for cash
3051 ; Get price in op2
3052 stx savx+1
3053 txa
3054 asl
3055 tax
3056 lda _prices,x
3057 sta op2
3058 lda _prices+1,x
3059 sta op2+1
3060 savx
3061 ldx #0 ;SMC
3062
3063 jsr enough_cash
3064 bcc nocash
3065
3066 ; check for cargo space
3067 lda Units,x
3068 bne space
3069 lda _holdspace
3070 beq nospace
3071 dec _holdspace
3072 space
3073
3074 dec _quantities,x
3075 inc _shipshold,x
3076
3077 jsr dec_cash
3078 jsr SndPocLow
3079 jmp update_mkt
3080 nospace
3081 jsr prepare_area
3082 lda #<str_nospace
3083 ldx #>str_nospace
3084 jmp print
3085 +nocash
3086 jsr prepare_area
3087 lda #<str_nocash
3088 ldx #>str_nocash
3089 jmp print
3090 nobuy
3091 end
3092 rts
3093 .)
3094
3095 _sell
3096 .(
3097 ; check if there is something for sale
3098 ldx _cur_sel
3099 cpx #$ff
3100 beq nosell
3101 lda _shipshold,x
3102 beq nosell
3103
3104 lda Units,x
3105 bne space
3106 inc _holdspace
3107 space
3108 inc _quantities,x
3109 dec _shipshold,x
3110
3111 ; Get price in op2
3112 txa
3113 asl
3114 tax
3115 lda _prices,x
3116 sta op2
3117 lda _prices+1,x
3118 sta op2+1
3119
3120 jsr inc_cash
3121 jsr SndPocLow
3122 jmp update_mkt
3123
3124 nosell
3125 end
3126 rts
3127 .)
3128
3129 update_mkt
3130 .(
3131 jsr get_p
3132 lda Cursor_origin_x
3133 clc
3134 adc #6
3135 tax
3136 jsr gotoX
3137
3138 lda _cur_sel
3139 sta count2
3140 jsr print_mkt_item
3141
3142 jmp mkt_status
3143 .)
3144
3145
3146 ;;;; Information screen
3147 _displayinfo
3148 .(
3149 jsr draw_red_frame
3150 inc capson
3151 lda #<str_commander
3152 ldx #>str_commander
3153 jsr print
3154 jsr put_space
3155 lda #<_name
3156 ldx #>_name
3157 jsr printnl
3158 dec capson
3159 jsr perform_CRLF
3160 jsr perform_CRLF
3161
3162 lda #<str_present
3163 ldx #>str_present
3164 jsr print
3165 jsr pr_sys
3166 jsr pr_colon
3167 ldy #3
3168 loop
3169 jsr put_space
3170 dey
3171 bne loop
3172 jsr print_planet_name
3173 jsr perform_CRLF
3174 lda #<str_hyper
3175 ldx #>str_hyper
3176 jsr print
3177 jsr pr_sys
3178 jsr pr_colon
3179 lda #<_hyp_system+NAME
3180 ldx #>_hyp_system+NAME
3181 jsr printnl
3182
3183 lda #A_FWCYAN
3184 jsr put_code
3185 lda #<str_fuel
3186 ldx #>str_fuel
3187 jsr print
3188 jsr pr_colon
3189 lda _fuel
3190 sta op2
3191 lda #0
3192 sta op2+1
3193 jsr print_float
3194 lda #<str_ly
3195 ldx #>str_ly
3196 jsr printnl
3197
3198 lda #A_FWCYAN
3199 jsr put_code
3200 lda #<str_cash
3201 ldx #>str_cash
3202 jsr print
3203 jsr pr_colon
3204 jsr pr_cash
3205 jsr perform_CRLF
3206
3207 lda #<str_status
3208 ldx #>str_status
3209 jsr print
3210 jsr pr_colon
3211 jsr get_statstr
3212 jsr print2
3213 jsr perform_CRLF
3214
3215 lda #<str_rating
3216 ldx #>str_rating
3217 jsr print
3218 jsr pr_colon
3219 jsr get_ratstr
3220 jsr print2
3221 jsr perform_CRLF
3222
3223 ; Print equipment
3224 jsr perform_CRLF
3225
3226 lda #A_FWCYAN
3227 jsr put_code
3228
3229 inc capson
3230 lda #<str_equipment
3231 ldx #>str_equipment
3232 jsr print
3233 jsr pr_colon
3234 dec capson
3235 jsr perform_CRLF
3236
3237 lda _equip
3238 sta op1
3239 lda _equip+1
3240 sta op1+1
3241 ldx #2
3242 loope
3243 lsr op1+1
3244 ror op1
3245 bcc no_fit
3246
3247 ; Fitted, print it
3248 stx savx+1
3249 lda #<str_equip
3250 sta tmp0
3251 lda #>str_equip
3252 sta tmp0+1
3253 ldy #5
3254 loopsp
3255 jsr put_space
3256 dey
3257 bne loopsp
3258 jsr search_string_and_print
3259 jsr perform_CRLF
3260 savx
3261 ldx #0 ; SMC
3262
3263 no_fit
3264 inx
3265 cpx #16
3266 bne loope
3267
3268 #ifdef HAVE_MISSIONS
3269 ; If mission has been briefed, then check for short
3270 ; description
3271 lda _mission
3272 bmi ret
3273 and #%11
3274 beq ret
3275
3276 ldx #12
3277 ldy #160
3278 jsr gotoXY
3279 ;lda #(A_FWMAGENTA)
3280 ;jsr put_code
3281 ;lda #<str_missiondesctitle
3282 ;ldx #>str_missiondesctitle
3283 ;jsr print
3284 ;jsr perform_CRLF
3285 lda MissionSummary
3286 ldx MissionSummary+1
3287 jmp print
3288 #endif
3289 ret
3290 rts
3291 .)
3292
3293 pr_colon
3294 .(
3295 lda #<str_colon
3296 ldx #>str_colon
3297 jmp print
3298 ;lda #A_FWWHITE
3299 ;jmp put_code
3300 .)
3301 pr_sys
3302 .(
3303 jsr put_space
3304 lda #<str_system
3305 ldx #>str_system
3306 jmp print
3307 .)
3308
3309 get_statstr
3310 .(
3311 lda #<str_clean
3312 sta tmp0
3313 lda #>str_clean
3314 sta tmp0+1
3315
3316 ldx #0
3317 lda _legal_status
3318 beq end
3319 inx
3320 cmp #50
3321 bcc end
3322 inx
3323 end
3324 jmp search_string
3325 .)
3326
3327
3328 ; Rating
3329 rat_lo .byt <$0008, <$0010, <$0020, <$0040, <$0080, <$0200, <$0a00, <$1900
3330 rat_hi .byt >$0008, >$0010, >$0020, >$0040, >$0080, >$0200, >$0a00, >$1900
3331
3332 #define NUM_RATINGS 9
3333
3334 get_ratstr
3335 .(
3336 lda #<str_harmless
3337 sta tmp0
3338 lda #>str_harmless
3339 sta tmp0+1
3340
3341 ldx #0
3342 lda _score
3343 sta op1
3344 lda _score+1
3345 sta op1+1
3346
3347 ldx #(NUM_RATINGS-2)
3348 loop
3349 lda rat_lo,x
3350 sta op2
3351 lda rat_hi,x
3352 sta op2+1
3353 jsr cmp16
3354 bcs end
3355 dex
3356 bpl loop
3357
3358 end
3359 inx
3360 jmp search_string
3361 .)
3362
3363 ;equip_items .byt 0
3364 ;equip_flags .word 00
3365 _displayequip
3366 .(
3367 ; initialize number of possible equip items
3368 lda #0
3369 sta equip_items
3370 sta equip_flags
3371 sta equip_flags+1
3372
3373 ; clear selection
3374 lda #$ff
3375 sta _cur_sel
3376
3377 ; Clear hires and draw frame
3378 jsr draw_red_frame
3379 inc capson
3380
3381 lda #<str_selleq
3382 ldx #>str_selleq
3383 jsr printnl
3384 jsr perform_CRLF
3385 dec capson
3386
3387 ; Loop thru the equip items (16 max, but only 14 implemented for now)
3388 lda #0
3389 sta count2
3390 loop2
3391 ; Check planet techlevel
3392 tax
3393 lda _cpl_system+TECHLEV
3394 cmp eq_tech,x
3395 bcc noitem
3396 inc equip_items
3397 jsr print_equ_item
3398 jsr perform_CRLF
3399 sec
3400 noitem
3401 ror equip_flags+1
3402 ror equip_flags
3403 inc count2
3404 lda count2
3405 cmp #14
3406 bne loop2
3407
3408 ldx #2 ; Items not implemented
3409 loop
3410 lsr equip_flags+1
3411 ror equip_flags
3412 dex
3413 bne loop
3414
3415 ; Print instructions
3416 jmp instructions
3417 ;rts
3418 .)
3419
3420
3421 print_equ_item
3422 .(
3423 lda #(A_FWGREEN+A_FWYELLOW*16+128)
3424 jsr put_code
3425
3426 ldx count2
3427
3428 lda #<str_equip
3429 sta tmp0
3430 lda #>str_equip
3431 sta tmp0+1
3432 jsr search_string_and_print
3433
3434 lda #(A_FWWHITE)
3435 jsr put_code
3436
3437 ldx #(16*6)
3438 jsr gotoX
3439
3440 ldx #(239-8*6)
3441 jsr gotoX
3442 lda count2
3443 bne cont
3444 jsr fuel_price
3445 jmp cont2
3446 cont
3447 tax
3448 lda priceseqLO,x
3449 sta op2
3450 lda priceseqHI,x
3451 sta op2+1
3452 cont2
3453 ldx #7
3454 jsr print_float_tab
3455
3456 rts
3457 .)
3458
3459
3460 ; Calculate price for fuel and store in op2, op2+1
3461 ; to get 7.0 LY of travel...
3462
3463 fuel_price
3464 .(
3465 lda #70
3466 sec
3467 sbc _fuel
3468 asl ; Fuel is 0.2 Cr/LY
3469 sta op2
3470 lda #0
3471 sta op2+1
3472 rts
3473 .)
3474
3475 ;; Buy new equipment
3476 buy_equip
3477 .(
3478 ldx _cur_sel
3479 cpx #$ff
3480 bne valid
3481 rts
3482 valid
3483 ; check if there is something for sale
3484 ldx _cur_sel
3485 bne nofuel
3486 ; It is fuel, calculate price
3487 jsr fuel_price
3488 jmp cont
3489 nofuel
3490 ; check for cash
3491 ; Get price in op2
3492 lda priceseqLO,x
3493 sta op2
3494 lda priceseqHI,x
3495 sta op2+1
3496 cont
3497 jsr enough_cash
3498 bcs cash
3499 jmp nocash
3500 cash
3501
3502
3503 ; Need flag position
3504 jsr find_flag_equip
3505
3506 ; Check if it is fuel or missile
3507 lda tmp0
3508 and #%11
3509 beq normal
3510
3511 ; Fuel or missile?
3512 ror
3513 bcc missile
3514
3515 lda #70
3516 cmp _fuel
3517 beq alreadyfit
3518
3519 ; Buy fuel
3520 ;lda #70
3521 sta _fuel
3522 jmp payfor
3523 missile
3524 ; Buy missile
3525 ; Can we fit a missile?
3526 ; Do we have room for it?
3527
3528 lda _missiles_left
3529 cmp _p_maxmissiles
3530 bcs alreadyfit
3531 inc _missiles_left
3532 jmp payfor
3533
3534 normal
3535 ; Remove fuel and missile
3536 lsr tmp0+1
3537 ror tmp0
3538 lsr tmp0+1
3539 ror tmp0
3540
3541 ; Can our ship fit this item?
3542
3543 ; Do we have it equipped already?
3544
3545 lda tmp0
3546 and _equip
3547 bne alreadyfit
3548 lda tmp0+1
3549 and _equip+1
3550 bne alreadyfit
3551
3552 jsr upgrade_lasers
3553 bcs setflag
3554
3555 ; Not lasers...
3556
3557 lda tmp0
3558 and #%00001000 ; Large cargo bay
3559 bne nocargo
3560 lda _holdspace
3561 clc
3562 adc #10
3563 sta _holdspace
3564 ;jmp setflag
3565 nocargo
3566 ; Should not arrive here?
3567
3568 setflag
3569 lda tmp0
3570 ora _equip
3571 sta _equip
3572 lda tmp0+1
3573 ora _equip+1
3574 sta _equip+1
3575
3576 payfor
3577 jsr dec_cash
3578 jsr SndPocLow
3579 jmp _displayequip
3580 alreadyfit
3581 jsr prepare_area
3582 lda #<str_equipped
3583 ldx #>str_equipped
3584 jmp print
3585 nofit
3586 end
3587 rts
3588 .)
3589
3590 sell_laser
3591 .(
3592 ; Do we have pulse lasers?
3593 lda _equip
3594 and #%1
3595 beq nopulse
3596 lda _equip
3597 and #%11111110
3598 sta _equip
3599 ldx #2
3600 bne doit
3601 nopulse
3602 ; Do we have beam lasers?
3603 lda _equip+1
3604 and #%1
3605 beq nobeam
3606 lda _equip+1
3607 and #%11111110
3608 sta _equip+1
3609 ldx #10
3610 bne doit
3611 nobeam
3612 ; Then it should be military
3613 lda _equip+1
3614 and #%11111101
3615 sta _equip+1
3616 ldx #11
3617 doit
3618 lda op2
3619 pha
3620 lda op2+1
3621 pha
3622 lda priceseqLO,x
3623 sta op2
3624 lda priceseqHI,x
3625 sta op2+1
3626 jsr inc_cash
3627 pla
3628 sta op2+1
3629 pla
3630 sta op2
3631 rts
3632 .)
3633
3634 upgrade_lasers
3635 .(
3636 jsr sell_laser
3637
3638 ; And add it to our equipment
3639 lda tmp0+1
3640 and #%00000001 ; Beam laser?
3641 beq nobeam
3642
3643 ; Update laser damage
3644 lda _missiles+1
3645 ora #(BEAM_LASER*8)
3646 sta _missiles+1
3647
3648 sec
3649 rts
3650 nobeam
3651 lda tmp0+1
3652 and #%00000010 ; Military laser?
3653 beq nomil
3654
3655 ; Update laser damage
3656 lda _missiles+1
3657 ora #(MILITARY_LASER*8)
3658 sta _missiles+1
3659
3660 sec
3661 rts
3662 nomil
3663 lda tmp0
3664 and #%00000001 ; Pulse laser?
3665 beq nopulse
3666
3667 ; Update laser damage
3668 lda _missiles+1
3669 ora #(PULSE_LASER*8)
3670 sta _missiles+1
3671 sec
3672 rts
3673 nopulse
3674
3675 clc
3676 rts
3677 .)
3678
3679
3680 find_flag_equip
3681 .(
3682
3683 lda equip_flags+1
3684 sta tmp
3685 lda equip_flags
3686
3687 ldx #1
3688 stx tmp0
3689 dex
3690 stx tmp0+1
3691
3692 ldy #16
3693 ;ldx #0
3694 loop
3695 lsr tmp
3696 ror
3697 bcc no_item
3698 ; This item exists
3699 cpx _cur_sel
3700 beq end
3701 inx
3702 no_item
3703 asl tmp0
3704 rol tmp0+1
3705 dey
3706 bne loop
3707 end
3708 rts
3709 .)
3710
3711
3712 ;;;; Changing galaxy
3713
3714
3715 ;Rotate reg A left once. Carry is put in bit 0.
3716 ;crol
3717 ;.(
3718 ; asl
3719 ; adc #0
3720 ; rts
3721 ;.)
3722
3723 _enter_next_galaxy
3724 .(
3725 ldx #5
3726 loop
3727 lda _base0,x
3728 ;jsr crol
3729 asl
3730 adc #0
3731 sta _base0,x
3732 dex
3733 bpl loop
3734
3735 ldy _galaxynum
3736 iny
3737 cpy #9
3738 bne more
3739 ldy #1
3740 more
3741 sty _galaxynum
3742 lda _currentplanet
3743 sta _dest_num
3744 jsr _infoplanet
3745 jsr _makesystem
3746 rts
3747
3748 .)
3749
3750
3751
3752 _displayloadsave
3753 .(
3754 ; Load directory
3755 ; Sector to read
3756 lda #NUM_SECT_OVL+OVERLAY_INIT
3757 ldy #0
3758 sta (sp),y
3759 tya
3760 iny
3761 sta (sp),y
3762
3763 ; Address of buffer
3764 iny
3765 lda #<_disk_buffer
3766 sta (sp),y
3767 lda #>_disk_buffer
3768 iny
3769 sta (sp),y
3770
3771 jsr _init_disk
3772 jsr _sect_read
3773 jsr _init_irq_routine
3774
3775 ; clear selection
3776 lda #$ff
3777 sta _cur_sel
3778
3779 ; Clear hires and draw frame
3780
3781 jsr draw_red_frame
3782 inc capson
3783
3784 ldx #>str_loadsavetitle
3785 lda #<str_loadsavetitle
3786 jsr printnl
3787
3788 jsr perform_CRLF
3789 dec capson
3790
3791 ; Loop thru the 8 slots
3792 lda #0
3793 sta count2
3794 loop2
3795 jsr print_slot
3796 inc count2
3797 lda count2
3798 cmp #8
3799 bne loop2
3800
3801 ; Print instrcutions
3802 jmp instructions
3803 ;rts
3804 .)
3805
3806 ps_count
3807 .byt 00
3808 ps_st
3809 .(
3810 lda #0
3811 sta ps_count
3812 loop
3813 lda _disk_buffer,x
3814 beq end1
3815 jsr put_code
3816 inc ps_count
3817 inx
3818 bne loop
3819 end1
3820 inx
3821 lda _disk_buffer,x
3822 beq end1
3823 rts
3824
3825 .)
3826
3827
3828 fill_spaces
3829 .(
3830 sec
3831 sbc ps_count
3832 tax
3833 loopfill1
3834 jsr put_space
3835 dex
3836 bpl loopfill1
3837 rts
3838 .)
3839
3840 print_slot
3841 .(
3842 lda count2
3843 asl
3844 asl
3845 asl
3846 asl
3847 asl
3848 tax
3849 lda _disk_buffer,x
3850 beq emptyslot
3851 ; Print slot info
3852 lda #(A_FWGREEN+A_FWYELLOW*16+128)
3853 jsr put_code
3854 ; Commander...
3855 inx
3856 jsr ps_st
3857 stx savex1+1
3858 lda #"."
3859 jsr put_code
3860 lda #12
3861 jsr fill_spaces
3862
3863 ldx #>str_sysslot
3864 lda #<str_sysslot
3865 jsr print
3866 savex1
3867 ldx #0 ; SMC
3868
3869 jsr ps_st
3870 stx saveme+1
3871 lda #"."
3872 jsr put_code
3873 lda #7
3874 jsr fill_spaces
3875
3876 ldx #>str_galslot
3877 lda #<str_galslot
3878 jsr print
3879 saveme
3880 ldx #0 ;SMC
3881 lda _disk_buffer,x
3882 clc
3883 adc #"0"
3884 jsr put_code
3885
3886 ; META
3887 jmp perform_CRLF
3888 emptyslot
3889 lda #(A_FWWHITE+A_FWCYAN*16+128)
3890 jsr put_code
3891 ldx #>str_loadsaveempty
3892 lda #<str_loadsaveempty
3893 jmp printnl
3894 .)
3895
3896
3897 slot_sector
3898 .byt NUM_SECT_OVL+OVERLAY_INIT+1
3899 .byt NUM_SECT_OVL+OVERLAY_INIT+1
3900 .byt NUM_SECT_OVL+OVERLAY_INIT+1
3901 .byt NUM_SECT_OVL+OVERLAY_INIT+1
3902 .byt NUM_SECT_OVL+OVERLAY_INIT+1
3903 .byt NUM_SECT_OVL+OVERLAY_INIT+2
3904 .byt NUM_SECT_OVL+OVERLAY_INIT+2
3905 .byt NUM_SECT_OVL+OVERLAY_INIT+2
3906
3907 slot_offset
3908 .byt (__commander_data_end-__commander_data_start)*1-1
3909 .byt (__commander_data_end-__commander_data_start)*2-1
3910 .byt (__commander_data_end-__commander_data_start)*3-1
3911 .byt (__commander_data_end-__commander_data_start)*4-1
3912 .byt (__commander_data_end-__commander_data_start)*5-1
3913 .byt (__commander_data_end-__commander_data_start)*1-1
3914 .byt (__commander_data_end-__commander_data_start)*2-1
3915 .byt (__commander_data_end-__commander_data_start)*3-1
3916
3917
3918 do_loadsave
3919 .(
3920 jsr prepare_area
3921 ;lda #(A_FWRED)
3922 ;jsr put_code
3923 ldx #>str_doloadsave
3924 lda #<str_doloadsave
3925 jsr printnl
3926
3927 readloop
3928 jsr ReadKeyNoBounce
3929 beq readloop
3930
3931 cmp #"S"
3932 bne notsave
3933 ; Save slot
3934 jsr save_slot
3935 jmp info
3936 notsave
3937 cmp #"L"
3938 bne notload
3939 ;Load slot
3940 jsr load_slot
3941 beq quit
3942 jmp info
3943 notload
3944 cmp #"Q"
3945 bne readloop
3946 quit
3947 jmp prepare_area
3948 ;rts
3949 .)
3950
3951
3952 dir_entry
3953 .(
3954 lda _cur_sel
3955 asl
3956 asl
3957 asl
3958 asl
3959 asl
3960 tax
3961 rts
3962 .)
3963
3964 set_dparms
3965 .(
3966 ldy #0
3967 sta (sp),y
3968 tya
3969 iny
3970 sta (sp),y
3971
3972 ; Address of buffer
3973 iny
3974 lda #<_disk_buffer
3975 sta (sp),y
3976 lda #>_disk_buffer
3977 iny
3978 sta (sp),y
3979
3980 rts
3981 .)
3982
3983 save_slot
3984 .(
3985
3986 ; Update directory
3987 jsr dir_entry
3988
3989 ; Set entry as used
3990 lda #$ff
3991 sta _disk_buffer,x
3992
3993 inx
3994 ldy #0
3995 loop1
3996 lda _name,y
3997 sta _disk_buffer,x
3998 beq end1
3999 iny
4000 inx
4001 bne loop1
4002 end1
4003
4004 inx
4005 ldy #0
4006 loop2
4007 lda _cpl_system+NAME,y
4008 cmp #"."
4009 beq skip
4010 sta _disk_buffer,x
4011 skip
4012 cmp #0
4013 beq end2
4014 iny
4015 inx
4016 bne loop2
4017 end2
4018
4019 inx
4020 lda _galaxynum
4021 sta _disk_buffer,x
4022
4023 ; write dir to disk
4024 jsr _init_disk
4025
4026 lda #NUM_SECT_OVL+OVERLAY_INIT
4027 jsr set_dparms
4028 jsr _sect_write
4029
4030 ; Load correct sector in buffer
4031 ldx _cur_sel
4032 lda slot_sector,x
4033 jsr set_dparms
4034 jsr _sect_read
4035
4036 ; Copy data to buffer
4037 ldx _cur_sel
4038 lda slot_offset,x
4039 tay
4040 ldx #(__commander_data_end-__commander_data_start)-1
4041 loop
4042 lda __commander_data_start,x
4043 sta _disk_buffer,y
4044 dey
4045 dex
4046 bpl loop
4047
4048 ; Save buffer
4049 ldx _cur_sel
4050 lda slot_sector,x
4051 jsr set_dparms
4052 jsr _sect_write
4053
4054 jmp _init_irq_routine
4055 ;rts
4056 .)
4057
4058
4059 load_slot
4060 .(
4061 ; Check in directory if slot is used
4062 jsr dir_entry
4063 lda _disk_buffer,x
4064 beq cannot
4065
4066 ; Load correct sector in buffer
4067 jsr _init_disk
4068
4069 ldx _cur_sel
4070 lda slot_sector,x
4071 jsr set_dparms
4072 jsr _sect_read
4073
4074 ; Copy data to buffer
4075 ldx _cur_sel
4076 lda slot_offset,x
4077 tay
4078 ldx #(__commander_data_end-__commander_data_start)-1
4079 loop
4080 lda _disk_buffer,y
4081 sta __commander_data_start,x
4082 dey
4083 dex
4084 bpl loop
4085
4086 ; Go to current planet
4087 jsr InitPlayerPos
4088
4089 ; Initialize ship
4090 ;jsr NewPlayerShip
4091 jsr InitPlayerShip
4092
4093 ; Load mission code and initialize mission
4094 jsr load_mission
4095 jsr OnGameLoaded
4096
4097 jsr _init_irq_routine
4098
4099 ; return with Z=0
4100 lda #1
4101 cannot
4102 rts
4103 .)
4104
4105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4106 ;Print goatsoup correctly
4107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4108
4109 print_goatsoup
4110 .(
4111
4112 ; Initialize stuff
4113 lda #0
4114 sta counter
4115 8 tax
4116 loop
4117 jsr get_word ; Jumps over spaces until a char is found. Returns pos in string in reg X. Z=1 if end of string (0) is reached
4118 beq end
4119 jsr get_word_length ; Returns length of current word in tmp
4120 lda tmp
4121 sec ; Add the trailing space
4122 adc counter
4123 sta counter
4124 cmp #38
4125 bcc fits
4126 ; Does not fit
4127 stx savex+1
4128 lda tmp
4129 sta counter
4130 inc counter ;Add the trailing space
4131 jsr perform_CRLF
4132 savex
4133 ldx #0 ;SMC
4134 fits
4135 jsr write_word
4136
4137 jmp loop
4138 end
4139 rts
4140
4141 counter .byt 0
4142 .)
4143
4144
4145 write_word
4146 .(
4147 loop
4148 lda str_buffer,x
4149 beq end
4150 cmp #" "
4151 beq end
4152 jsr put_char ; Does this preserve reg X?
4153 inx
4154 bne loop ; This should be allways true, as strings are no longer than 255 bytes
4155 end
4156 jsr put_space ; Does this preserve reg X?
4157 rts
4158 .)
4159
4160 get_word
4161 .(
4162 loop
4163 lda str_buffer,x
4164 beq end
4165 cmp #" "
4166 bne end
4167 inx
4168 bne loop ; This should be allways true, as strings are no longer than 255 bytes
4169 end
4170 rts
4171 .)
4172
4173 get_word_length
4174 .(
4175 lda #0
4176 sta tmp
4177 stx end+1
4178 loop
4179 lda str_buffer,x
4180 beq end
4181 cmp #" "
4182 beq end
4183 inc tmp
4184 inx
4185 bne loop ; This should be allways true, as strings are no longer than 255 bytes
4186 end
4187 ldx #0 ;SMC
4188 rts
4189
4190 .)
4191
4192
4193 /*
4194 #define SCR_FRONT 0
4195 #define SCR_INFO 1
4196 #define SCR_MARKET 2
4197 #define SCR_SYSTEM 3
4198 #define SCR_GALAXY 4
4199 #define SCR_CHART 5
4200 #define SCR_EQUIP 6
4201 #define SCR_LOADSAVE 7
4202 */
4203
4204 instructions
4205 .(
4206 jsr savpos
4207 ldx #0
4208 ldy #200-6
4209 jsr gotoXY
4210 lda #(A_FWMAGENTA)
4211 jsr put_code
4212 ldx _current_screen
4213 dex
4214 dex
4215 bpl inst
4216 rts
4217 inst
4218 lda #<str_instr
4219 sta tmp0
4220 lda #>str_instr
4221 sta tmp0+1
4222 jsr search_string_and_print
4223 jmp restorepos
4224 .)
4225
4226
4227 savpos
4228 .(
4229 lda Cursor_origin_x
4230 sta PX+1
4231 lda Cursor_origin_y
4232 sta PY+1
4233 rts
4234 +restorepos
4235 PX
4236 ldx #0
4237 PY
4238 ldy #0
4239 jmp gotoXY
4240 .)
4241
4242 ; Alarm message when in text screens
4243 alarm
4244 .(
4245 stx savx+1
4246 jsr savpos
4247
4248 ldx #0
4249 ldy #200-6
4250 jsr gotoXY
4251
4252 ; Clear line
4253 ldy #239
4254 lda #$40
4255 loop
4256 sta (screen),y
4257 dey
4258 bne loop ; Leaves 1 scan without clearing, but that does not matter
4259
4260 lda #(A_FWRED)
4261 jsr put_code
4262 inc capson
4263 savx
4264 ldx #0 ;SMC
4265 lda #<str_alarm
4266 sta tmp0
4267 lda #>str_alarm
4268 sta tmp0+1
4269 jsr search_string_and_print
4270 dec capson
4271 jmp restorepos
4272 .)
4273
4274
4275
4276

  ViewVC Help
Powered by ViewVC 1.1.26