/[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 354 - (show annotations)
Sun Jun 27 19:32:47 2010 UTC (9 years, 9 months ago) by Chema
File size: 67417 byte(s)
First tweaks after the BETA1 version

Changed the way rear view is patched, so no it is in obj3d.s before calling GLOBROT. Is much more efficient.

Also corrected an error with this, as only Z component was inverted, and not also X component. This also meant changes into stars.s which also had some errors in rear view...

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

  ViewVC Help
Powered by ViewVC 1.1.26