/[projet1]/users/chema/Elite Clone/Universe/galaxy.s
Defence Force logotype

Contents of /users/chema/Elite Clone/Universe/galaxy.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 116 - (show annotations)
Wed Jun 24 17:51:28 2009 UTC (10 years, 9 months ago) by Chema
File size: 52840 byte(s)
Ok. Buy and sell is complete, including checking the cash. Had to add routines to handle long (4-byte) numbers.

Touched the sources so itoa is not called anymore, instead, there is an itoa2 function, which calls ltoa and works for unsigned numbers.
1 #define itoa itoa2
2
3 ; Functions to re-create galaxy and market of Elite
4 ; adapted from the TextElite C source
5
6
7 ; Attributes
8 #define A_FWBLACK 0
9 #define A_FWRED 1
10 #define A_FWGREEN 2
11 #define A_FWYELLOW 3
12 #define A_FWBLUE 4
13 #define A_FWMAGENTA 5
14 #define A_FWCYAN 6
15 #define A_FWWHITE 7
16 #define A_BGBLACK 16
17 #define A_BGRED 17
18 #define A_BGGREEN 18
19 #define A_BGYELLOW 19
20 #define A_BGBLUE 20
21 #define A_BGMAGENTA 21
22 #define A_BGCYAN 22
23 #define A_BGWHITE 23
24
25 ;typedef struct
26 ;{ char a,b,c,d;
27 ;} fastseedtype; /* four byte random number used for planet description */
28
29
30 ;typedef struct
31 ;{ int w0;
32 ; int w1;
33 ; int w2;
34 ;} seedtype; /* six byte random number used as seed for planets */
35
36
37
38 ;typedef struct
39 ;{
40 ; unsigned char x;
41 ; unsigned char y; /* One byte unsigned */
42 ; unsigned char economy; /* These two are actually only 0-7 */
43 ; unsigned char govtype;
44 ; unsigned char techlev; /* 0-16 i think */
45 ; unsigned char population; /* One byte */
46 ; unsigned int productivity; /* Two byte */
47 ; unsigned int radius; /* Two byte (not used by game at all) */
48 ; fastseedtype goatsoupseed;
49 ; char name[12];
50 ;} plansys ;
51
52
53 #define SYSX 0
54 #define SYSY 1
55 #define ECONOMY 2
56 #define GOVTYPE 3
57 #define TECHLEV 4
58 #define POPUL 5
59 #define PROD 6
60 #define RADIUS 8
61 #define SEED 10
62 #define NAME 14
63
64
65 #define SCR_MARKET 1
66 #define SCR_SYSTEM 2
67 #define SCR_GALAXY 3
68 #define SCR_CHART 4
69
70
71
72 ;typedef struct
73 ;{ /* In 6502 version these were: */
74 ; unsigned char baseprice; /* one byte */
75 ; signed char gradient; /* five bits plus sign */
76 ; unsigned char basequant; /* one byte */
77 ; unsigned char maskbyte; /* one byte */
78 ; unsigned char units; /* two bits */
79 ; unsigned char name[20]; /* longest="Radioactives" */
80 ; } tradegood ;
81
82
83 ; Following the original 6502 Elite, this is split into two tables and compressed a bit
84 ; so that the goods characteristics are stored in a 4-byte record.
85 ; However it is usually a good idea to keep everything into separate lists. This is how
86 ; I will do it. I am wasting 1 byte per record (17 bytes total), but will keep code smaller and easier
87 ; to follow. In addition, we can add more things if necessary.
88 ; Contets of the table are:
89
90 ;tradegood commodities[]=
91 ; {
92 ; {0x13,-0x02,0x06,0x01,0,"Food "},
93 ; {0x14,-0x01,0x0A,0x03,0,"Textiles "},
94 ; {0x41,-0x03,0x02,0x07,0,"Radioactives"},
95 ; {0x28,-0x05,0xE2,0x1F,0,"Slaves "},
96 ; {0x53,-0x05,0xFB,0x0F,0,"Liquor/Wines"},
97 ; {0xC4,+0x08,0x36,0x03,0,"Luxuries "},
98 ; {0xEB,+0x1D,0x08,0x78,0,"Narcotics "},
99 ; {0x9A,+0x0E,0x38,0x03,0,"Computers "},
100 ; {0x75,+0x06,0x28,0x07,0,"Machinery "},
101 ; {0x4E,+0x01,0x11,0x1F,0,"Alloys "},
102 ; {0x7C,+0x0d,0x1D,0x07,0,"Firearms "},
103 ; {0xB0,-0x09,0xDC,0x3F,0,"Furs "},
104 ; {0x20,-0x01,0x35,0x03,0,"Minerals "},
105 ; {0x61,-0x01,0x42,0x07,1,"Gold "},
106 ; {0xAB,-0x02,0x37,0x1F,1,"Platinum "},
107 ; {0x2D,-0x01,0xFA,0x0F,2,"Gem-Strones "},
108 ; {0x35,+0x0F,0xC0,0x07,0,"Alien Items "},
109 ; };
110
111
112
113
114
115 ; Some vars for loops, etc...
116 count .byt 0 ; used in genmarket & displaymarket
117 num .byt 0 ; used in infoplanet
118 index .byt 00 ; These two usedin gs_randomname
119 lowcase .byt 00
120
121
122 ; Digrams
123
124 _pairs0 .asc "ABOUSEITILETSTONLONUTHNO"
125 _pairs .asc "..LEXEGEZACEBISO"
126 .asc "USESARMAINDIREA."
127 .asc "ERATENBERALAVETI"
128 .asc "EDORQUANTEISRION" ;Dots should be nullprint characters
129
130
131 ; Goat soup dictionary
132
133 ; Call entry string
134 gs_init_str
135 .byt $0f
136 .asc " is "
137 .byt $17
138 .asc "."
139 .byt 0
140
141
142
143 ; initialize seed for current galaxy
144 init_seed
145 .(
146 ; Initialize seed for this galaxy
147 ldx #5
148 loop
149 lda _base0,x
150 sta _seed,x
151 dex
152 bpl loop
153
154 rts
155 .)
156
157
158 ;genmarket(signed char fluct)
159 ;/* Prices and availabilities are influenced by the planet's economy type
160 ; (0-7) and a random "fluctuation" byte that was kept within the saved
161 ; commander position to keep the market prices constant over gamesaves.
162 ; Availabilities must be saved with the game since the player alters them
163 ; by buying (and selling(?))
164 ;
165 ; Almost all operations are one byte only and overflow "errors" are
166 ; extremely frequent and exploited.
167 ;
168 ; Trade Item prices are held internally in a single byte=true value/4.
169 ; The decimal point in prices is introduced only when printing them.
170 ; Internally, all prices are integers.
171 ; The player's cash is held in four bytes.
172 ; */
173
174
175
176 _genmarket
177 .(
178 ;unsigned short i;
179 ;for(i=0;i<=lasttrade;i++)
180
181 lda #16
182 sta count
183 loop
184
185 ;{
186 ;signed int q;
187 ;signed int product = (system.economy)*(commodities[i].gradient);
188 ;signed int changing = fluct & (commodities[i].maskbyte);
189 ; q = (commodities[i].basequant) + changing - product;
190
191 lda #0
192
193 sta op1+1
194 sta op2+1
195
196 lda _hyp_system+ECONOMY
197 sta op1
198 ldx count
199 lda Gradients,x
200 bpl positive2
201 dec op2+1
202 positive2
203 sta op2
204 jsr mul16 ; SHOUDL USE FAST 8-BIT MULT FROM LIB3D!!
205
206
207 ldx count
208 lda Maskbytes,x
209 and _fluct
210 pha
211 clc
212 adc Basequants,x
213 sec
214 sbc op1
215
216 ;q = q&0xFF;
217 ;if(q&0x80) {q=0;}; /* Clip to positive 8-bit */
218
219 bpl positive
220 lda #0
221 positive
222
223 ;market.quantity[i] = (unsigned int)(q & 0x3F); /* Mask to 6 bits */
224 and #$3f
225 sta _quantities,x
226
227 ;q = (commodities[i].baseprice) + changing + product;
228 ;q = q & 0xFF;
229 ;market.price[i] = (unsigned int) (q*4);
230 pla ; get changing
231 clc
232 adc Baseprices,x
233 adc op1
234 ldy #0
235 sty tmp+1
236 asl
237 rol tmp+1
238 asl
239 rol tmp+1
240 sta tmp
241 txa
242 asl
243 tax
244 lda tmp
245 sta _prices,x
246 lda tmp+1
247 sta _prices+1,x
248
249 dec count
250 bpl loop
251
252 ;}
253
254 ;market.quantity[AlienItems] = 0; /* Override to force nonavailability */
255
256 ldx #16
257 lda #0
258 sta _quantities,x
259
260 ;return ;
261 rts
262 .)
263
264
265
266 ; tweak seed four times (usual way)
267 tweakseed4
268 .(
269 ; use reg Y as it is not touched in _tweakseed
270
271 ldy #4
272 loop2
273 jsr _tweakseed
274 dey
275 bne loop2
276
277 rts
278 .)
279 ;
280 ;void tweakseed()
281 ;{
282 ; unsigned int temp;
283 ; temp = ((seed).w0)+((seed).w1)+((seed).w2); /* 2 byte aritmetic */
284 ; (seed).w0 = (seed).w1;
285 ; (seed).w1 = (seed).w2;
286 ; (seed).w2 = temp;
287 ;}
288
289 _tweakseed
290 .(
291 lda _seed ; LO of seed.w0
292 clc
293 adc _seed+2; LO of seed.w1
294 sta tmp
295 lda _seed+1; HI of seed.w0
296 adc _seed+3; HI of seed.w1
297 sta tmp+1
298
299 lda _seed+4 ; LO of seed.w2
300 clc
301 adc tmp
302 sta tmp
303 lda _seed+5
304 adc tmp+1
305 sta tmp+1
306
307 ldx #1
308 loop
309 lda _seed+2,x
310 sta _seed,x
311
312 lda _seed+4,x
313 sta _seed+2,x
314
315 lda tmp,x
316 sta _seed+4,x
317
318 dex
319 bpl loop
320 rts
321
322 .)
323
324 ; Get info on a planet number
325
326 ;infoplanet(int num)
327 _infoplanet
328 .(
329 ; seed.w0=base0;
330 ; seed.w1=base1;
331 ; seed.w2=base2; /* Initialise seed for galaxy 1 */ ;
332 jsr init_seed
333
334 lda _dest_num
335 beq end
336 sta num
337
338 ; for (i=0;i<num;i++){
339 ; tweakseed();
340 ; tweakseed();
341 ;; tweakseed();
342 ; tweakseed();
343 ; }
344 ; Will use reg y, as it is not used in tweakseed
345 loop3
346 jsr tweakseed4
347 dec num
348 bne loop3
349 end
350 rts
351
352 ;}
353 .)
354
355 _search_planet
356 .(
357 ; Initialize seed for this galaxy
358 jsr init_seed
359
360 ; Loop creating systems
361 lda #$ff
362 sta num
363
364 loop3
365 inc num
366 jsr name_planet
367 jsr compare_names
368 beq found
369
370 jsr tweakseed4
371
372 lda num
373 cmp #$ff
374 beq notfound
375 bne loop3
376
377 found
378 lda num
379 sta _dest_num
380 jsr _infoplanet
381 jsr _makesystem
382
383 lda _current_screen
384 cmp #SCR_CHART
385 bne long
386 jsr _plot_chart
387 jmp print_distinfo
388 long
389 jsr _plot_galaxy
390 jmp print_distinfo
391
392 notfound
393 ;jsr perform_CRLF
394 ;jsr perform_CRLF
395 ;ldy #1
396 ;lda (sp),y
397 ;tax
398 ;dey
399 ;lda (sp),y
400 ;jsr print
401 ;jsr put_space
402 jsr prepare_area
403 lda #<str_notfound
404 ldx #>str_notfound
405 jsr printnl
406 jsr _infoplanet
407 jmp _makesystem
408
409 .)
410
411 prepare_area
412 .(
413 jsr clear_frame_data
414 ldy #(200-6*4)
415 ldx #12
416 jmp gotoXY
417 .)
418
419 print_distinfo
420 .(
421 jsr prepare_area
422 ;jsr put_space
423 lda #>_hyp_system+NAME
424 tax
425 lda #<_hyp_system+NAME
426 jsr print
427 jsr put_space
428 jmp print_distance ; This is jsr/rts
429 .)
430
431
432 compare_names
433 .(
434 ldy #0
435 lda (sp),y
436 sta st1+1
437 iny
438 lda (sp),y
439 sta st1+2
440 ldx #$ff
441 loop
442 inx
443 lda _hyp_system+NAME,x
444 st1
445 cmp $1234,x
446 bne notequal
447 cmp #0
448 bne loop
449
450 ; equal
451 lda #0
452 rts
453 notequal
454 lda #1
455 rts
456 .)
457
458
459
460 #define LONG_START_X 12
461 #define LONG_START_Y 16
462 #define LONG_END_X (239-LONG_START_X)
463 #define SCROLL_AMOUNT 40
464
465 clear_frame_data
466 .(
467 ; Clears the two lines of text
468 ; where data is printed on chart screens
469
470 ldx #10 ; ten lines
471 lda #<($a000+176*40)
472 sta tmp
473 lda #>($a000+176*40)
474 sta tmp+1
475 loopt
476 lda #$40
477 ldy #39
478 loopscans
479 sta (tmp),y
480 dey
481 bpl loopscans
482 clc
483 lda tmp
484 adc #40
485 sta tmp
486 bcc nocarry
487 inc tmp+1
488 nocarry
489 dex
490 bpl loopt
491
492 rts
493
494 .)
495
496 plot_frame_title
497 .(
498 ldx #13
499 lda #<$a000
500 sta tmp
501 lda #>$a000
502 sta tmp+1
503 ldy #0
504 loopt
505 lda #A_BGRED
506 sta (tmp),y
507 clc
508 lda tmp
509 adc #40
510 sta tmp
511 bcc nocarry
512 inc tmp+1
513 nocarry
514 dex
515 bne loopt
516
517 lda #A_BGCYAN
518 sta $a208
519
520 ldy #4
521 ldx #48
522 jsr gotoXY
523 lda _current_screen
524 cmp #SCR_CHART
525 bne long
526 lda #<str_short_chart
527 ldx #>str_short_chart
528 jmp print ; this is jsr/rts
529 long
530 lda #A_BGCYAN
531 sta $b680
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 rts
572
573 .)
574
575
576
577
578 scroll .byt 0
579 plot_galaxy_with_scroll
580 .(
581 jsr clr_hires
582 jsr plot_frame_title
583
584 lda scroll
585 beq right
586 lda #"<"
587 ldx #18
588 bne plotarrow
589 right
590 lda #">"
591 ldx #(240-18)
592 plotarrow
593 ldy #4
594 jsr gotoXY
595 jsr put_char
596
597
598 ; Initialize seed for this galaxy
599 jsr init_seed
600
601 ; Loop creating systems
602 lda #$ff
603 sta num
604
605 loop3
606 inc num
607
608 ; Plot a dot at system's position (X/2, Y/4)
609
610 ldx _seed+3 ; HI part of seed.w1 is sys X
611 ldy _seed+1 ; This is sys Y
612 jsr universe_to_long_chart
613
614 ; Is in range?
615 cpx #LONG_START_X
616 bcc postdraw
617 cpx #LONG_END_X
618 bcs postdraw
619
620
621 jsr pixel_address
622
623 ldy #0
624 lda (tmp0),y
625 ora tmp1
626 sta (tmp0),y
627
628 postdraw
629 jsr tweakseed4
630 lda num
631 cmp #$ff
632 bne loop3
633
634 end
635
636 ldx _cpl_system+SYSX
637 ldy _cpl_system+SYSY
638 jsr universe_to_long_chart
639
640 ; Is in range?
641 cpx #LONG_START_X
642 bcc postdraw2
643 cpx #LONG_END_X
644 bcs postdraw2
645
646 ; Draw big the cursor
647 lda plotY
648 pha
649 lda plotX
650 pha
651 sty plotY
652 stx plotX
653
654 lda #12 ;lda #6
655 ;jsr plot_cross
656 jsr plot_cross
657
658 ;lda #6
659 ;jsr plot_cross
660 pla
661 sta plotX
662 pla
663 sta plotY
664
665 postdraw2
666
667 ; Draw the cursor
668 lda #6
669 jsr plot_cross
670 rts
671
672 .)
673
674
675 universe_to_long_chart
676 .(
677 txa
678 ;lsr
679 clc
680 adc #LONG_START_X
681 ldx scroll
682 beq noscroll
683 sec
684 sbc #SCROLL_AMOUNT
685 noscroll
686 tax
687
688 tya
689 lsr
690 ;lsr
691 clc
692 adc #LONG_START_Y
693 tay
694
695 rts
696 .)
697
698
699 long_chart_to_universe
700 .(
701 txa
702 sec
703 sbc #LONG_START_X
704 ldx scroll
705 beq noscroll
706 clc
707 adc #SCROLL_AMOUNT
708 noscroll
709 tax
710
711 tya
712 sec
713 sbc #LONG_START_Y
714 asl
715 tay
716
717 rts
718 .)
719
720 ; Plot chart (short range chart)
721
722 names .dsb 24
723 col .byt 00
724 row .byt 00
725 plotX .byt 00
726 plotY .byt 00
727 ;temp_seed2 .dsb 6
728
729 #define SHORT_CENTRE_X $68
730 #define SHORT_CENTRE_Y $56
731
732 #ifdef 0
733 save_seed
734 .(
735
736 ; Save seed
737 ldx #5
738 loopsavseed
739 lda _seed,x
740 ;sta temp_seed2,x
741 dex
742 bpl loopsavseed
743 rts
744 .)
745
746 restore_seed
747 .(
748 ; restore seed
749 ldx #5
750 resseed
751 ;lda temp_seed2,x
752 sta _seed,x
753 dex
754 bpl resseed
755
756 rts
757
758 .)
759 #endif
760
761 in_range
762 .(
763 ; Check if in range. Need to do this in 16-bit signed arithmetic!
764
765 ; int dx = cseed.s3 - g_commander.cpl_coord.x;
766 ; int dy = cseed.s1 - g_commander.cpl_coord.y;
767
768 ; Prepare X and Y (so we can call in_range2 for other matters...)
769 lda _seed+3
770 sta tmp2
771 lda _seed+1
772 sta tmp2+1
773
774 +in_range2
775 ; if (abs(dx) < 0x14) {
776 ; if (abs(dy) < 0x26) {
777 lda #0
778 sta op1+1
779 lda tmp2 ; HI part of seed.w1 is sys X
780 sec
781 sbc _cpl_system+SYSX
782 sta tmp
783 sta op1
784 bcs nonegx
785 dec op1+1
786 nonegx
787 jsr abs
788
789 lda #0
790 sta op2+1
791 lda #$14
792 sta op2
793 jsr cmp16
794 bcc checkY
795 bcs end
796 checkY
797 lda #0
798 sta op1+1
799 lda tmp2+1 ; This is Y
800 sec
801 sbc _cpl_system+SYSY
802 sta op1
803 sta tmp+1
804 bcs nonegy
805 dec op1+1
806 nonegy
807 jsr abs
808
809 lda #$26
810 sta op2
811 jsr cmp16
812
813 end
814 rts
815 .)
816
817 _plot_chart
818 .(
819
820 ; jsr save_seed
821
822 ; init names
823 ldx #23
824 lda #0
825 loopnames
826 sta names,x
827 dex
828 bpl loopnames
829
830 jsr clr_hires
831 ldy #0
832 lda #6
833 sta (sp),y
834 jsr _ink
835
836
837 ; Plot title
838
839 jsr plot_frame_title
840
841 ; Draw fuel circle
842 ldy #0
843 lda #SHORT_CENTRE_X
844 sta (sp),y
845 iny
846 lda #0
847 sta (sp),y
848 iny
849 lda #SHORT_CENTRE_Y
850 sta (sp),y
851 iny
852 lda #0
853 sta (sp),y
854 iny
855 lda #1
856 sta (sp),y
857 lda #0
858 sta (sp),y
859 jsr _curset
860
861 lda #70
862 ldy #0
863 sta (sp),y
864 iny
865 iny
866 lda #1
867 sta (sp),y
868 jsr _circle
869
870
871 ; Initialize seed for this galaxy
872 jsr init_seed
873
874 ; Loop creating systems
875 lda #$ff
876 sta num
877
878 loop3
879 inc num
880
881 jsr in_range
882 bcs next
883
884
885 ; Ok it is in range, prepare where to place the name
886 ; int x = (dx*4) + SHORT_CENTRE_X;
887 ; int col = (x/8) + 1;
888 ; int y = (dy*2) + SHORT_CENTRE_Y;
889 ; int row = (y/8);
890
891 ldx _seed+3
892 ldy _seed+1
893 jsr universe_to_short_chart
894 stx plotX
895 sty plotY
896 txa
897 lsr
898 lsr
899 lsr
900 sta col
901 inc col
902
903 tya
904 lsr
905 lsr
906 lsr
907 sta row
908
909 ; if (names[row] != 0) {
910 ; row++;
911 ; if (names[row] != 0) {
912 ; row-=2;
913 ; }
914 ; }
915
916
917 ldx row
918 lda names,x
919 beq cont
920 inx
921 inc row
922 lda names,x
923 beq cont
924 dec row
925 dec row
926
927 cont
928
929 ; if (row >= 2 && row < 19 ) {
930 ; if ( names[row] == 0) {
931 ; // draw the name
932 ; names[row] = 0xff;
933 ; textmod = 0x80;
934 ; //g_bindex = 0;
935 ; g_xc = col;
936 ; g_yc = row;
937 ; christen_planet(cseed);
938 ; }
939
940 ldx row
941 cpx #2
942 bcc next
943 cpx #19
944 bcs next
945
946 lda names,x
947 bne noprint
948
949 ; Draw the name
950
951 ;ldx row
952 lda #$ff
953 sta names,x
954 jsr name_planet
955 lda col
956 asl
957 asl
958 asl
959 clc
960 adc #5
961 tax
962 lda row
963 asl
964 asl
965 asl
966 clc
967 adc #2
968 tay
969 jsr gotoXY
970 ;lda #<_hyp_system+NAME
971 ;ldx #>_hyp_system+NAME
972 ;jsr print
973 jsr gs_planet_name
974
975 noprint
976
977 ; plot the star
978 ; // bigstars
979 ; int size = 2+ (cseed.s5 & 1) + g_carry;
980 ; sun(x,y,size,0);
981 jsr box
982
983 next
984
985 jsr tweakseed4
986 lda num
987 cmp #$ff
988 beq end
989 jmp loop3
990
991 end
992 ; Draw the big cursor
993 lda #SHORT_CENTRE_X
994 sta plotX
995 lda #SHORT_CENTRE_Y
996 sta plotY
997 lda #12
998 jsr plot_cross
999
1000
1001 ; Draw the cursor
1002 ldx _hyp_system+SYSX
1003 ldy _hyp_system+SYSY
1004
1005 ; Check if in range
1006 stx tmp2
1007 sty tmp2+1
1008 jsr in_range2
1009 bcc inside
1010
1011 ldx #SHORT_CENTRE_X
1012 ldy #SHORT_CENTRE_Y
1013 jmp default
1014 inside
1015 ldx tmp2
1016 ldy tmp2+1
1017 jsr universe_to_short_chart
1018 default
1019 sty plotY
1020 stx plotX
1021 lda #6
1022 jsr plot_cross
1023
1024 ;jsr restore_seed
1025
1026 jsr _infoplanet
1027 jmp _makesystem ; This is jsr/rts
1028
1029 .)
1030
1031
1032
1033 box
1034 .(
1035 ; Draws a box at planet's position (plotX and plotY) with the
1036 ; size depending on the size of the planet
1037
1038 ; Get the size
1039 lda _seed+5
1040 and #1
1041 clc
1042 adc #1
1043 sta tmp2
1044
1045 lda plotY
1046 sec
1047 sbc tmp2
1048 sta plotY
1049
1050
1051 lda plotX
1052 sec
1053 sbc tmp2
1054 sta inipX+1
1055
1056
1057 lda tmp2
1058 asl
1059 sta tmp2
1060 sta looprows+1
1061
1062 looprows
1063 lda #0 ; SMC
1064 sta tmp3
1065
1066 inipX
1067 lda #0 ; SMC
1068 sta plotX
1069
1070 loopcols
1071 ldx plotX
1072 ldy plotY
1073 jsr pixel_address
1074 ldy #0
1075 lda (tmp0),y
1076 eor tmp1
1077 sta (tmp0),y
1078
1079 inc plotX
1080 dec tmp3
1081 bpl loopcols
1082
1083 inc plotY
1084 dec tmp2
1085 bpl looprows
1086
1087 rts
1088
1089 .)
1090
1091 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1092 ; plot_cross
1093 ; Draws (with eor) a cross (clipped) at
1094 ; current plotX, plotY position
1095 ; with size passed in reg A.
1096 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1097
1098 plot_cross
1099 .(
1100 sta cross_size
1101 ; init point X
1102 lda plotX
1103 sec
1104 sbc cross_size
1105 cmp #12
1106 bcs inside1
1107 lda #12
1108 inside1
1109 sta inic
1110
1111 lda plotX
1112 clc
1113 adc cross_size
1114 cmp #240
1115 bcc inside2
1116 lda #240
1117 inside2
1118 sta endc+1
1119
1120 ; horizontal arm
1121
1122 loophor
1123 ldy plotY
1124 ldx inic
1125 jsr pixel_address
1126 ldy #0
1127 lda (tmp0),y
1128 eor tmp1
1129 sta (tmp0),y
1130 inc inic
1131 lda inic
1132 endc
1133 cmp #0 ;SMC
1134 bne loophor
1135
1136 ; vertical arm
1137 lda plotY
1138 sec
1139 sbc cross_size
1140 cmp #6
1141 bcs inside3
1142 lda #6
1143 inside3
1144 sta inic
1145
1146 lda plotY
1147 clc
1148 adc cross_size
1149 cmp #200
1150 bcc inside4
1151 lda #199
1152 inside4
1153 sta endc2+1
1154
1155 loopver
1156 ldx plotX
1157 ldy inic
1158 jsr pixel_address
1159 ldy #0
1160 lda (tmp0),y
1161 eor tmp1
1162 sta (tmp0),y
1163 inc inic
1164 lda inic
1165 endc2
1166 cmp #0 ; SMC
1167 bne loopver
1168
1169 rts
1170
1171 cross_size .byt 0
1172 inic .byt 0
1173 .)
1174
1175 _move_cross_v
1176 .(
1177 ldy #0
1178 lda (sp),y
1179 sta amount+1
1180
1181 lda _current_screen
1182 cmp #SCR_CHART
1183 bne long
1184 lda #168
1185 bne save
1186 long
1187 lda #145
1188 save
1189 sta amount+3
1190
1191 ; erase
1192 lda #6
1193 jsr plot_cross
1194
1195 ; inc/dec Y
1196 clc
1197 lda plotY
1198 amount
1199 adc #0 ;SMC
1200 cmp #199 ; SMC
1201 bcs outside
1202 cmp #14
1203 bcc outside
1204 sta plotY
1205 outside
1206
1207 lda #6
1208 jsr plot_cross
1209 rts
1210
1211 .)
1212
1213 _move_cross_h
1214 .(
1215 ldy #0
1216 lda (sp),y
1217
1218 sta amount+1
1219 ; erase
1220 lda #6
1221 jsr plot_cross
1222
1223 ; inc/dec X
1224 clc
1225 lda plotX
1226 amount
1227 adc #0 ;SMC
1228 cmp #239
1229 bcs outside1
1230 cmp #12
1231 bcc outside2
1232 sta plotX
1233 jmp plot
1234 outside1
1235 lda _current_screen
1236 cmp #SCR_GALAXY
1237 bne plot
1238 lda scroll
1239 bne plot
1240 inc scroll
1241 lda plotX
1242 sec
1243 sbc #SCROLL_AMOUNT
1244 sta plotX
1245 jmp plot_galaxy_with_scroll
1246 outside2
1247 lda _current_screen
1248 cmp #SCR_GALAXY
1249 bne plot
1250 lda scroll
1251 beq plot
1252 dec scroll
1253 lda plotX
1254 clc
1255 adc #SCROLL_AMOUNT
1256 sta plotX
1257 jmp plot_galaxy_with_scroll
1258 plot
1259 lda #6
1260 jsr plot_cross
1261
1262 rts
1263
1264 .)
1265
1266
1267
1268 ; Convert coordinates in regs X,Y to universe coordinates in a
1269 ; short-range chart and back
1270
1271 universe_to_short_chart
1272 .(
1273 txa
1274 sec
1275 sbc _cpl_system+SYSX
1276 asl
1277 asl
1278 clc
1279 adc #SHORT_CENTRE_X
1280 tax
1281
1282 tya
1283 sec
1284 sbc _cpl_system+SYSY
1285 asl
1286 clc
1287 adc #SHORT_CENTRE_Y
1288 tay
1289
1290 rts
1291
1292 .)
1293
1294 short_chart_to_universe
1295 .(
1296 txa
1297 sec
1298 sbc #SHORT_CENTRE_X
1299 bmi by4
1300 clc
1301 bcc by4b
1302 by4
1303 sec
1304 ror
1305 sec
1306 ror
1307 jmp by4end
1308 by4b
1309 ror
1310 ror
1311 by4end
1312 clc
1313 adc _cpl_system+SYSX
1314 tax
1315
1316 tya
1317 sec
1318 sbc #SHORT_CENTRE_Y
1319 bmi by2
1320 clc
1321 bcc by2b
1322 by2
1323 sec
1324 by2b
1325 ror
1326 clc
1327 adc _cpl_system+SYSY
1328 tay
1329
1330 rts
1331 .)
1332
1333 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1334 ; snap_to_planet
1335 ; Finds a planet closest to a given coordinate (x,y)
1336 ; passed in the X and Y registers
1337 ; It is the next hyperspace destination
1338 ; result planet num is returned in reg a
1339 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1340 snap_to_planet
1341 .(
1342
1343 lda #$ff
1344 sta tmp1
1345
1346 lda _dest_num
1347 sta tmp1+1
1348
1349 stx tmp0 ; Cursor X
1350 sty tmp0+1 ; Cursor Y
1351
1352 ; Initialize seed for this galaxy
1353 jsr init_seed
1354
1355 ; Loop creating systems
1356 lda #$ff
1357 sta num
1358
1359 loop3
1360 inc num
1361
1362 lda _current_screen
1363 cmp #SCR_CHART
1364 bne nocheck
1365 jsr in_range ; BEWARE. In long-chart this should not be called!!
1366 bcs next
1367
1368 nocheck
1369 lda tmp0
1370 sec
1371 sbc _seed+3 ; Get X
1372 bpl noneg
1373 eor #$ff
1374 clc
1375 adc #1
1376 noneg
1377 cmp #10
1378 bcs next
1379 sta tmp
1380
1381 lda tmp0+1
1382 sec
1383 sbc _seed+1 ; Get Y
1384 bpl noneg2
1385 eor #$ff
1386 clc
1387 adc #1
1388 noneg2
1389 cmp #10
1390 bcs next
1391
1392 cmp tmp
1393 bcs ygreater
1394 clc
1395 adc tmp
1396 adc tmp
1397 jmp check
1398 ygreater
1399 asl
1400 clc
1401 adc tmp
1402 check
1403 lsr
1404 cmp tmp1
1405 bcs next
1406
1407
1408
1409 sta tmp1
1410 lda num
1411 sta tmp1+1
1412
1413 next
1414 jsr tweakseed4
1415 lda num
1416 cmp #$ff
1417 bne loop3
1418
1419 lda tmp1+1
1420 rts
1421
1422 .)
1423
1424
1425 _find_planet
1426 .(
1427
1428 ldx plotX
1429 ldy plotY
1430 lda _current_screen
1431 cmp #SCR_GALAXY
1432 bne short
1433 jsr long_chart_to_universe
1434 jmp snap
1435 short
1436 jsr short_chart_to_universe
1437 snap
1438 jsr snap_to_planet
1439 ldx tmp1
1440 cpx #$ff
1441 beq noplanet
1442 sta _dest_num
1443
1444 jsr _infoplanet
1445 jsr _makesystem
1446
1447 lda #6
1448 jsr plot_cross
1449 ldx _hyp_system+SYSX
1450 ldy _hyp_system+SYSY
1451 lda _current_screen
1452 cmp #SCR_GALAXY
1453 bne short2
1454 jsr universe_to_long_chart
1455 jmp snap2
1456 short2
1457 jsr universe_to_short_chart
1458 snap2
1459 stx plotX
1460 sty plotY
1461 lda #6
1462 jsr plot_cross
1463 jmp print_distinfo ; This is jsr/rts
1464
1465 noplanet
1466 rts
1467 .)
1468
1469 ; /**-Generate system info from seed **/
1470
1471 _makesystem
1472 .(
1473
1474 ;unsigned int pair1,pair2,pair3,pair4;
1475 ;unsigned int longnameflag;
1476
1477 ;system.x=((seed.w1)>>8);
1478 ;system.y=((seed.w0)>>8);
1479
1480 lda _seed+3 ; HI part of seed.w1
1481 sta _hyp_system+SYSX
1482 lda _seed+1
1483 sta _hyp_system+SYSY
1484
1485 ; system.govtype =(((seed.w1)>>3)&7); /* bits 3,4 &5 of w1 */
1486 lda _seed+2
1487 lsr
1488 lsr
1489 lsr
1490 and #7
1491 sta _hyp_system+GOVTYPE
1492
1493 ;system.economy =(((seed.w0)>>8)&7); /* bits 8,9 &A of w0 */
1494 lda _seed+1
1495 and #%00000111
1496 sta _hyp_system+ECONOMY
1497
1498 ;if (system.govtype <=1)
1499 ;{ system.economy = ((system.economy)|2);
1500 ;}
1501
1502 lda _hyp_system+GOVTYPE
1503 bpl nothing
1504 lda _hyp_system+ECONOMY
1505 ora #2
1506 sta _hyp_system+ECONOMY
1507 nothing
1508 ;system.techlev =(((seed.w1)>>8)&3)+((system.economy)^7);
1509 ;system.techlev +=((system.govtype)>>1);
1510 ;if (((system.govtype)&1)==1) system.techlev+=1;
1511 ;/* C simulation of 6502's LSR then ADC */
1512
1513 lda _hyp_system+ECONOMY
1514 eor #7
1515 sta tmp
1516 lda _seed+3
1517 and #3
1518 clc
1519 adc tmp
1520 sta tmp
1521 lda _hyp_system+GOVTYPE
1522 lsr
1523 adc tmp
1524 sta _hyp_system+TECHLEV
1525
1526 ;system.population = 4*(system.techlev) + (system.economy);
1527 ;system.population += (system.govtype) + 1;
1528
1529 ; sta _hyp_system+POPUL
1530 ; lda #0
1531 ; sta _hyp_system+POPUL+1
1532 ;
1533 ; asl _hyp_system+POPUL
1534 ; rol _hyp_system+POPUL+1
1535 ; clc
1536 ; asl _hyp_system+POPUL
1537 ; rol _hyp_system+POPUL+1
1538
1539 ; lda _hyp_system+POPUL
1540
1541 asl
1542 asl
1543
1544 clc
1545 adc _hyp_system+ECONOMY
1546 ; bne nocarry2
1547 ; inc _hyp_system+POPUL+1
1548 ;nocarry2
1549 ; sta _hyp_system+POPUL
1550
1551 ; lda _hyp_system+GOVTYPE
1552 ; clc
1553 ; adc _hyp_system+POPUL
1554 ; bne nocarry
1555 ; inc _hyp_system+POPUL+1
1556 ;nocarry
1557 clc
1558 adc _hyp_system+GOVTYPE
1559 clc
1560 adc #1
1561
1562 sta _hyp_system+POPUL
1563
1564 ;system.productivity = (((system.economy)^7)+3)*((system.govtype)+4);
1565 ;system.productivity *= (system.population)*8;
1566
1567 lda _hyp_system+ECONOMY
1568 eor #7
1569 clc
1570 adc #3
1571 sta op1
1572 lda #0
1573 sta op1+1
1574 sta op2+1
1575
1576 lda _hyp_system+GOVTYPE
1577 clc
1578 adc #4
1579 sta op2
1580
1581 jsr mul16uc
1582 ; 16-bit result in op1,op1+1
1583
1584 lda #0
1585 sta op2+1
1586
1587 lda _hyp_system+POPUL
1588
1589 ldx #3
1590 loop
1591 asl
1592 rol op2+1
1593 dex
1594 bne loop
1595
1596 sta op2
1597
1598 jsr mul16uc
1599
1600 lda op1
1601 sta _hyp_system+PROD
1602 lda op1+1
1603 sta _hyp_system+PROD+1
1604
1605
1606 ;system.radius = 256*((((seed.w2)>>8)&15)+11) + system.x;
1607
1608 lda _seed+5
1609 and #15
1610 clc
1611 adc #11
1612 sta _hyp_system+RADIUS+1
1613 lda _hyp_system+SYSX
1614 sta _hyp_system+RADIUS
1615
1616
1617 ;system.goatsoupseed.a = seed.w1 & 0xFF;;
1618 ;system.goatsoupseed.b = seed.w1 >>8;
1619 ;system.goatsoupseed.c = seed.w2 & 0xFF;
1620 ;system.goatsoupseed.d = seed.w2 >> 8;
1621 ldx #3
1622 loop3
1623 lda _seed+2,x
1624 sta _hyp_system+SEED,x
1625 dex
1626 bpl loop3
1627
1628 jmp name_planet ; This is jsr/rts
1629
1630 ;return;
1631 ;rts
1632 .)
1633
1634
1635 ; Generate planet's name
1636 ; Uses a temporal seed
1637 temp_seed .dsb 6
1638 ; Use temporal buffer for name
1639 temp_name .dsb 9
1640
1641 name_planet
1642 .(
1643
1644 ; Save seed
1645 ldx #5
1646 loop4
1647 lda _seed,x
1648 sta temp_seed,x
1649 dex
1650 bpl loop4
1651
1652 ;longnameflag=(seed.w0)&64;
1653 lda _seed
1654 and #64
1655 pha
1656
1657 ;pair1=2*(((seed.w2)>>8)&31); tweakseed();
1658 ;pair2=2*(((seed.w2)>>8)&31); tweakseed();
1659 ;pair3=2*(((seed.w2)>>8)&31); tweakseed();
1660 ;pair4=2*(((seed.w2)>>8)&31); tweakseed();
1661 ; /* Always four iterations of random number */
1662
1663 ldx #0
1664 stx loop2+1
1665 loop2
1666 ldx #00
1667
1668 lda _seed+5
1669 and #31
1670 asl
1671 sta tmp0,x
1672 jsr _tweakseed
1673
1674 inc loop2+1
1675 lda #4
1676 cmp loop2+1
1677 bne loop2
1678
1679 ;(system.name)[0]=pairs[pair1];
1680 ;(system.name)[1]=pairs[pair1+1];
1681 ;(system.name)[2]=pairs[pair2];
1682 ;(system.name)[3]=pairs[pair2+1];
1683 ;(system.name)[4]=pairs[pair3];
1684 ;(system.name)[5]=pairs[pair3+1];
1685 ; if(longnameflag) /* bit 6 of ORIGINAL w0 flags a four-pair name */
1686 ;{
1687 ;(system.name)[6]=pairs[pair4];
1688 ;(system.name)[7]=pairs[pair4+1];
1689 ;(system.name)[8]=0;
1690 ;}
1691 ;else (system.name)[6]=0;
1692
1693 ldy tmp0
1694 lda _pairs,y
1695 sta temp_name ;_hyp_system+NAME
1696 lda _pairs+1,y
1697 sta temp_name+1 ;_hyp_system+NAME+1
1698
1699 ldy tmp0+1
1700 lda _pairs,y
1701 sta temp_name+2; _hyp_system+NAME+2
1702 lda _pairs+1,y
1703 sta temp_name+3 ;_hyp_system+NAME+3
1704
1705 ldy tmp0+2
1706 lda _pairs,y
1707 sta temp_name+4 ;_hyp_system+NAME+4
1708 lda _pairs+1,y
1709 sta temp_name+5 ;_hyp_system+NAME+5
1710
1711 pla
1712 bne cont
1713 lda #0
1714 sta temp_name+6 ;_hyp_system+NAME+6
1715 beq end
1716 cont
1717
1718 ldy tmp0+3
1719 lda _pairs,y
1720 sta temp_name+6 ;_hyp_system+NAME+6
1721 lda _pairs+1,y
1722 sta temp_name+7 ;_hyp_system+NAME+7
1723
1724 lda #0
1725 sta temp_name+8 ;_hyp_system+NAME+8
1726
1727
1728 end
1729 ; restore seed
1730 ldx #5
1731 loop1
1732 lda temp_seed,x
1733 sta _seed,x
1734 dex
1735 bpl loop1
1736
1737 ; Copy name
1738 ldx #0
1739 ldy #0
1740
1741 loop3
1742 lda temp_name,x
1743 sta _hyp_system+NAME,y
1744 beq end2
1745 cmp #"."
1746 beq noincy
1747 iny
1748 noincy
1749 inx
1750 bpl loop3
1751
1752 end2
1753 rts
1754 .)
1755
1756
1757
1758
1759 ; Searches for a string. tmp0 holds pointer to base and x holds offset (in strings).
1760 search_string
1761 .(
1762 txa
1763 bne cont
1764 rts
1765 cont
1766 ldy #0
1767 loop
1768 lda (tmp0),y
1769 beq out ; Search for zero
1770 iny
1771 bne loop
1772
1773 out
1774 ; Found the end. Add length to pointer
1775 iny
1776 tya
1777 clc
1778 adc tmp0
1779 bcc nocarry
1780 inc tmp0+1
1781 nocarry
1782 sta tmp0
1783
1784 dex
1785 bne cont
1786
1787 rts
1788
1789 .)
1790
1791
1792 search_string_and_print
1793 .(
1794 jsr search_string
1795 jmp print2
1796 .)
1797
1798
1799 ; Prints the colonial type
1800
1801 _print_colonial
1802 .(
1803
1804 ;if (hyp_seed.s4 & 0x80) {
1805 ;// bug-eyed rabbits
1806
1807 lda _seed+4
1808 bpl humans
1809
1810 ;int ct = (hyp_seed.s5/4)&7;
1811 ;if (ct < 3) {
1812 ; text2buffer(FIERCE+ct);
1813 ; text2buffer(' ');
1814 ; textmod = NAME_CASE;
1815 ;}
1816
1817 lda _seed+5
1818 lsr
1819 lsr
1820 and #7
1821 cmp #3
1822 bcs cont1
1823
1824 ; Print Fierce
1825 tax
1826 lda #<Fierce
1827 sta tmp0
1828 lda #>Fierce
1829 sta tmp0+1
1830 jsr search_string_and_print
1831 jsr put_space
1832
1833 cont1
1834
1835 ;ct = (hyp_seed.s5/32);
1836 ;if (ct < 6) {
1837 ; text2buffer(CREATURE_TYPE+ct);
1838 ; text2buffer(' ');
1839 ; textmod = NAME_CASE;
1840 ;}
1841
1842 lda _seed+5
1843 lsr
1844 lsr
1845 lsr
1846 lsr
1847 lsr
1848 cmp #6
1849 bcs cont2
1850
1851 ; Print Type
1852 tax
1853 lda #<Type
1854 sta tmp0
1855 lda #>Type
1856 sta tmp0+1
1857 jsr search_string_and_print
1858 jsr put_space
1859
1860
1861 cont2
1862 ;ct = (hyp_seed.s3^hyp_seed.s1)&7;
1863 ;if (ct < 6) {
1864 ; text2buffer(BUG_EYED+ct);
1865 ; text2buffer(' ');
1866 ; textmod = NAME_CASE;
1867 ;}
1868
1869 lda _seed+3
1870 eor _seed+1
1871 and #7
1872 pha
1873 cmp #6
1874 bcs cont3
1875
1876 ; Print bug-eyed
1877 tax
1878 lda #<Bugeyed
1879 sta tmp0
1880 lda #>Bugeyed
1881 sta tmp0+1
1882 jsr search_string_and_print
1883 jsr put_space
1884
1885 cont3
1886
1887 ;ct += (hyp_seed.s5&3);
1888 ;ct &= 7;
1889 ;text2buffer(RODENT+ct);
1890 pla
1891 sta tmp
1892 lda _seed+5
1893 and #3
1894 clc
1895 ;adc _seed+5
1896 adc tmp
1897 and #7
1898
1899 ; Print race
1900 tax
1901 lda #<Race
1902 sta tmp0
1903 lda #>Race
1904 sta tmp0+1
1905 jmp search_string_and_print
1906
1907
1908 ; } else {
1909 ; text2buffer(HUMAN_COLONIAL);
1910 ; }
1911
1912
1913 humans
1914 lda #<HumanCol
1915 sta tmp0
1916 lda #>HumanCol
1917 sta tmp0+1
1918 jsr print2
1919 rts
1920
1921
1922
1923 .)
1924
1925
1926
1927
1928
1929
1930 ;; Let's go with my own version of goat_soup....
1931 ;; Should be consistent with TXTELITE...
1932
1933 ian_str
1934 .asc "ian"
1935 .byt 0
1936
1937
1938 gs_planet_name
1939 .(
1940 ; int i=1;
1941 ; putchar(psy->name[0]);//printf("%c",psy->name[0]);
1942 ; while(psy->name[i]!='\0') putchar(tolower(psy->name[i++]));//printf("%c",tolower(psy->name[i++]));
1943
1944 ldx #0
1945 firstloop
1946 lda _hyp_system+NAME,x
1947 cmp #"."
1948 bne printfirst
1949 inx
1950 bne firstloop
1951 printfirst
1952 ;stx savx+1
1953 jsr put_char
1954 savx
1955 ;ldx #0
1956 inx
1957 loop
1958 lda _hyp_system+NAME,x
1959 beq end
1960 cmp #"."
1961 beq noprint
1962 ora #$20 ; lowcase it
1963 stx savx2+1
1964 jsr put_char
1965 savx2
1966 ldx #0 ; again sfc
1967 noprint
1968 inx
1969 jmp loop
1970 end
1971 rts
1972 .)
1973
1974 gs_planet_nameian
1975 .(
1976 ; int i=1;
1977 ; printf("%c",psy->name[0]);
1978 ; while(psy->name[i]!='\0')
1979 ; { if((psy->name[i+1]!='\0') || ((psy->name[i]!='E') && (psy->name[i]!='I')))
1980 ; putchar(tolower(psy->name[i]));//printf("%c",tolower(psy->name[i]));
1981 ; i++;
1982 ; }
1983 ; printf("ian");
1984 ldx #0
1985 firstloop
1986 lda _hyp_system+NAME,x
1987 cmp #"."
1988 bne printfirst
1989 inx
1990 bne firstloop
1991 printfirst
1992 stx savx+1
1993 jsr put_char
1994 savx
1995 ldx #0
1996 inx
1997 loop
1998 lda _hyp_system+NAME,x
1999 beq end
2000 cmp #"."
2001 beq noprint
2002 ldy _hyp_system+NAME+1,x
2003 bne nocheck
2004 cmp #"I"
2005 beq noprint
2006 cmp #"E"
2007 beq noprint
2008 nocheck
2009 ora #$20 ; lowcase it
2010 stx savx2+1
2011 jsr put_char
2012 savx2
2013 ldx #0 ; again sfc
2014 noprint
2015 inx
2016 jmp loop
2017 end
2018
2019 ; print "ian"
2020 lda #<ian_str
2021 sta tmp0
2022 lda #>ian_str
2023 sta tmp0+1
2024 jsr print2
2025 rts
2026
2027 .)
2028
2029 gs_random_name
2030 .(
2031 ;int i;
2032 ;int len = gen_rnd_number() & 3;
2033 jsr _gen_rnd_number
2034 and #3
2035 sta index
2036 ;for(i=0;i<=len;i++)
2037 lda #0
2038 sta lowcase
2039 loop
2040 ;{ int x = gen_rnd_number() & 0x3e;
2041 jsr _gen_rnd_number
2042 and #$3e
2043 tay
2044 ; if(pairs0[x]!='.') printf("%c",pairs0[x]);
2045 lda _pairs0,y
2046 ;beq l1
2047 cmp #"."
2048 beq notthis
2049 ora lowcase
2050 l1
2051 ldx #$20
2052 stx lowcase
2053 jsr put_char
2054 notthis
2055 ; if(i && (pairs0[x+1]!='.')) printf("%c",pairs0[x+1]);
2056 lda index
2057 beq notthat
2058 iny
2059 lda _pairs0,y
2060 ;beq l2
2061 cmp #"."
2062 beq notthat
2063 ora lowcase
2064 l2
2065 ldx #$20
2066 stx lowcase
2067 jsr put_char
2068 notthat
2069
2070 dec index
2071 bpl loop
2072 ;}
2073
2074 rts
2075 .)
2076
2077 gs_jump_lo .byt <gs_planet_name,<gs_planet_nameian,<gs_random_name
2078 gs_jump_hi .byt >gs_planet_name,>gs_planet_nameian,>gs_random_name
2079
2080
2081
2082 #define gs_sourcep tmp6
2083
2084
2085 gs_index .byt 0
2086
2087 ; void goat_soup(const char *source,plansys * psy)
2088 ; {
2089 ; Pass parameters as pointer in x (hi) a (lo)
2090 goat_soup
2091 .(
2092
2093 sta gs_sourcep
2094 stx gs_sourcep+1
2095 lda #0
2096 sta gs_index
2097
2098 main_loop
2099
2100 ; unsigned char c;
2101 ; for(;;)
2102 ; {
2103 ; c=*(source); source++;
2104 ; if(c=='\0') break;
2105 ldy gs_index
2106 lda (gs_sourcep),y
2107 bne cont
2108 rts
2109 cont
2110 ; if(c<(unsigned char)0x80) putchar(c);//printf("%c",c);
2111
2112 ; This changed. It is a char if 32 or greater than 38... (though only up to 36 are used)
2113 ; if it is zero or negative (a token)
2114 ; bmi decode
2115 ; now is...
2116 bmi ischar
2117 beq ischar
2118 cmp #32
2119 beq ischar
2120 cmp #38
2121 bcc decode
2122
2123 ; If it is greater than 123 it is a string code
2124 cmp #123
2125 bcs code_str
2126
2127 ischar
2128 jsr decomp; put_char
2129 jmp next
2130 decode
2131 ; else
2132 ; {
2133 ; It is a code...
2134 ; if (c <=(unsigned char)0xA4)
2135 ; { int rnd = gen_rnd_number();
2136 ; goat_soup(desc_list[c-0x81].option[(rnd >= (unsigned char)0x33)+(rnd >= (unsigned char)0x66)+(rnd >= (unsigned char)0x99)+(rnd >= (unsigned char)0xCC)],psy);
2137 ; }
2138
2139 ; This has changed. It is a code allways if this is reached...
2140 ;cmp #$a5
2141 ;bcs code_str
2142
2143 pha
2144 jsr _gen_rnd_number
2145
2146 pha
2147 lda #0
2148 sta tmp
2149 pla
2150
2151 cmp #$33
2152 bcc next1
2153 inc tmp
2154 next1
2155 cmp #$66
2156 bcc next2
2157 inc tmp
2158 next2
2159 cmp #$99
2160 bcc next3
2161 inc tmp
2162 next3
2163 cmp #$cc
2164 bcc next4
2165 inc tmp
2166 next4
2167
2168 ; Multiply c-$81 by 5
2169 ; This also changed.
2170 ; It is just c-1 unless greater than 32
2171 pla
2172 cmp #32
2173 bcc less32
2174 sec
2175 sbc #1
2176 less32
2177 sec
2178 ;sbc #$81
2179 sbc #1
2180 sta tmp+1
2181 asl
2182 asl
2183 clc
2184 adc tmp+1
2185
2186 ; Add tmp
2187 adc tmp
2188
2189 ; Search for string
2190 tax
2191 lda #<desc_list
2192 sta tmp0
2193 lda #>desc_list
2194 sta tmp0+1
2195 jsr search_string
2196
2197 ; Prepare re-entrant call to goat_soup
2198
2199 lda gs_index
2200 pha
2201 lda gs_sourcep
2202 pha
2203 lda gs_sourcep+1
2204 pha
2205
2206 lda tmp0
2207 ldx tmp0+1
2208 jsr goat_soup
2209
2210 ; Recover previous params
2211 pla
2212 sta gs_sourcep+1
2213 pla
2214 sta gs_sourcep
2215 pla
2216 sta gs_index
2217
2218 jmp next
2219 code_str
2220 ; It is an string code
2221 ; else switch(c)
2222 ; { case 0xB0: /* planet name */
2223 ; {
2224 ; int i=1;
2225 ; putchar(psy->name[0]);//printf("%c",psy->name[0]);
2226 ; while(psy->name[i]!='\0') putchar(tolower(psy->name[i++]));//printf("%c",tolower(psy->name[i++]));
2227 ; } break;
2228 ; case 0xB1: /* <planet name>ian */
2229 ; {
2230 ; int i=1;
2231 ; printf("%c",psy->name[0]);
2232 ; while(psy->name[i]!='\0')
2233 ; { if((psy->name[i+1]!='\0') || ((psy->name[i]!='E') && (psy->name[i]!='I')))
2234 ; putchar(tolower(psy->name[i]));//printf("%c",tolower(psy->name[i]));
2235 ; i++;
2236 ; }
2237 ; printf("ian");
2238 ; } break;
2239 ; case 0xB2: /* random name */
2240 ; {
2241 ; int i;
2242 ; int len = gen_rnd_number() & 3;
2243 ; for(i=0;i<=len;i++)
2244 ; { int x = gen_rnd_number() & 0x3e;
2245 ; if(pairs0[x]!='.') putchar(pairs0[x]);//printf("%c",pairs0[x]);
2246 ; if(i && (pairs0[x+1]!='.')) putchar(pairs0[x+1]);//printf("%c",pairs0[x+1]);
2247 ; }
2248 ; } break;
2249 ; default: printf("<bad char in data [%X]>",c); return;
2250 ; } /* endswitch */
2251 ; Implement this as a jump table
2252 sec
2253 sbc #$7b
2254 tax
2255 lda gs_jump_lo,x
2256 sta jump+1
2257 lda gs_jump_hi,x
2258 sta jump+2
2259 jump
2260 jsr $1234 ; This is self-modified...
2261
2262 ; } /* endelse */
2263 ; } /* endwhile */
2264 ; } /* endfunc */
2265 ;
2266 ; /**+end **/
2267
2268 next
2269 inc gs_index
2270 jmp main_loop
2271 .)
2272
2273
2274 ;; Elite random function
2275
2276 ;int gen_rnd_number (void)
2277 ; This is inspired in the reverse engineered
2278 ; source of eliteagb
2279 _gen_rnd_number
2280 .(
2281 ;int A = (g_rand_seed.r0*2)|(*carry!=0);
2282 ;int X = A&0xff;
2283 ;A = (X + g_rand_seed.r2 + (A>0xff)); // carry from this used below
2284 ;g_rand_seed.r0 = A;
2285
2286 lda _rnd_seed
2287 rol ; It is commented that this is the exact code in original Elite, and not asl
2288 tax
2289 adc _rnd_seed+2
2290 sta _rnd_seed
2291
2292 ;g_rand_seed.r2 = X;
2293 txa
2294 sta _rnd_seed+2
2295
2296 ;A = (g_rand_seed.r1 + g_rand_seed.r3 + (A>0xff));
2297 ;*carry = (A>0xff);
2298 ;A&=0xff;
2299 lda _rnd_seed+1
2300 clc
2301 adc _rnd_seed+3
2302 ;X = g_rand_seed.r1;
2303 ldx _rnd_seed+1
2304
2305 ;g_rand_seed.r1 = A;
2306 ;g_rand_seed.r3 = X;
2307 sta _rnd_seed+1
2308 stx _rnd_seed+3
2309 ;return A;
2310 rts
2311
2312 .)
2313
2314
2315
2316 #define STR_DATA 0
2317 #define STR_DISTANCE 1
2318 #define STR_ECONOMY 2
2319 #define STR_GOV 3
2320 #define STR_TECH 4
2321 #define STR_GROSS 5
2322 #define STR_RADIUS 6
2323 #define STR_POP 7
2324 #define STR_KM 8
2325 #define STR_BILLION 9
2326 #define STR_LY 10
2327 #define STR_CR 11
2328 #define STR_MKT 12
2329 #define STR_PROD 13
2330 #define STR_UNIT 14
2331 #define STR_PRICE 15
2332 #define STR_QUANT 16
2333
2334
2335 diff
2336 .(
2337 lda tmp
2338 cmp tmp+1
2339 bcs ok
2340 pha
2341 lda tmp+1
2342 sta tmp
2343 pla
2344 sta tmp+1
2345
2346 ok
2347 lda tmp
2348 sec
2349 sbc tmp+1
2350 rts
2351
2352 .)
2353
2354
2355 print_distance
2356 .(
2357 lda _cpl_system+SYSX ; Current X pos
2358 sta tmp
2359 lda _hyp_system+SYSX
2360 sta tmp+1
2361 jsr diff
2362
2363 sta op1
2364
2365 lda _cpl_system+SYSY
2366 sta tmp
2367 lda _hyp_system+SYSY
2368 sta tmp+1
2369 jsr diff
2370
2371 sta sav_a+1
2372 ora op1
2373 beq same
2374
2375 ; Show distance as 4*sqrt(x*x+y*y/4)
2376 lda #0
2377 sta op1+1
2378 sta op2+1
2379 lda op1
2380 lsr
2381 sta op1
2382 sta op2
2383 jsr mul16
2384
2385 lda op1
2386 sta tmp
2387 lda op1+1
2388 sta tmp+1
2389 sav_a
2390 lda #0
2391 lsr
2392 lsr
2393 sta op1
2394 sta op2
2395 lda #0
2396 sta op1+1
2397 sta op2+1
2398 jsr mul16
2399
2400 clc
2401 lda tmp
2402 adc op1
2403 sta op1
2404 lda tmp+1
2405 adc op1+1
2406 sta op1+1
2407 jsr SqRoot
2408
2409 ; Print distance (at last!)
2410 ldx #STR_DISTANCE
2411 jsr printtitle
2412 lda op2
2413 asl
2414 rol op2+1
2415 asl
2416 rol op2+1
2417 asl
2418 rol op2+1
2419 sta op2
2420 jsr print_float
2421 ldx #STR_LY
2422 jsr printtail ; This is jsr/rts
2423 jsr perform_CRLF
2424 same
2425 rts
2426
2427 .)
2428
2429 _printsystem
2430 .(
2431
2432 ; Clear hires and draw frame
2433 jsr clr_hires
2434
2435 ; Print title: Data on <planetname>
2436 lda #1
2437 sta capson
2438
2439 ldx #STR_DATA
2440 jsr printtitle
2441 jsr gs_planet_name
2442 ;jsr print_planet_name
2443
2444 lda #0
2445 sta capson
2446
2447 jsr perform_CRLF
2448 jsr perform_CRLF
2449
2450 ; Print name
2451 ; Draw a line
2452 ; If distance <> 0 print distance
2453
2454 jsr print_distance
2455
2456 ; Print economy
2457 ldx #STR_ECONOMY
2458 jsr printtitle
2459 ldx _hyp_system+ECONOMY
2460 lda #<econnames
2461 sta tmp0
2462 lda #>econnames
2463 sta tmp0+1
2464 jsr search_string
2465 lda tmp0
2466 ldx tmp0+1
2467 jsr printnl
2468
2469 ; Print Government
2470 ldx #STR_GOV
2471 jsr printtitle
2472 ldx _hyp_system+GOVTYPE
2473 lda #<govnames
2474 sta tmp0
2475 lda #>govnames
2476 sta tmp0+1
2477 jsr search_string
2478 lda tmp0
2479 ldx tmp0+1
2480 jsr printnl
2481
2482 ; Print tech level
2483 ldx #STR_TECH
2484 jsr printtitle
2485 lda _hyp_system+TECHLEV
2486 sta op2
2487 lda #0
2488 sta op2+1
2489 jsr print_num
2490 jsr perform_CRLF
2491
2492 ; Print population
2493 ldx #STR_POP
2494 jsr printtitle
2495 lda _hyp_system+POPUL
2496 sta op2
2497 lda #0
2498 sta op2+1
2499 jsr print_float
2500 jsr put_space
2501 ldx #STR_BILLION
2502 jsr printtail
2503 jsr perform_CRLF
2504 jsr perform_CRLF
2505 jsr put_space
2506 lda #"("
2507 jsr put_char
2508 jsr _print_colonial
2509 lda #"s"
2510 jsr put_char
2511 lda #")"
2512 jsr put_char
2513 jsr perform_CRLF
2514
2515
2516 ; Print productivity
2517 ldx #STR_GROSS
2518 jsr printtitle
2519 lda _hyp_system+PROD
2520 sta op2
2521 lda _hyp_system+PROD+1
2522 sta op2+1
2523 jsr print_num
2524 ldx #STR_CR
2525 jsr printtail
2526 jsr perform_CRLF
2527
2528 ; Print radius
2529 ldx #STR_RADIUS
2530 jsr printtitle
2531 lda _hyp_system+RADIUS
2532 sta op2
2533 lda _hyp_system+RADIUS+1
2534 sta op2+1
2535 jsr print_num
2536 ldx #STR_KM
2537 jsr printtail
2538 jsr perform_CRLF
2539 jsr perform_CRLF
2540
2541 ; Goatsoup
2542 ldx #3
2543 loop
2544 lda _hyp_system+SEED,x
2545 sta _rnd_seed,x
2546 dex
2547 bpl loop
2548
2549 lda #<gs_init_str
2550 ldx #>gs_init_str
2551 jsr goat_soup
2552
2553 rts
2554
2555 .)
2556
2557
2558 print_planet_name
2559 .(
2560 ldx #0
2561 loop
2562 lda _current_name,x
2563 beq end
2564 cmp #"."
2565 beq noprint
2566 jsr put_char
2567 noprint
2568 inx
2569 jmp loop
2570 end
2571 rts
2572
2573 .)
2574
2575 #define START_X_LIST 1
2576
2577 //#define PACK
2578
2579 #ifdef PACK
2580
2581 mkstrslo
2582 .byt <(str_mktunit)
2583 .byt <(str_mktquant)
2584 .byt <(str_mktin)
2585 .byt <(str_mktlist)
2586 .byt <(str_mktunit)
2587 .byt <(str_mktprice)
2588 .byt <(str_mktsale)
2589 .byt <(str_mktcargo)
2590 mkstrshi
2591 .byt >(str_mktunit)
2592 .byt >(str_mktquant)
2593 .byt >(str_mktin)
2594 .byt >(str_mktlist)
2595 .byt >(str_mktunit)
2596 .byt >(str_mktprice)
2597 .byt >(str_mktsale)
2598 .byt >(str_mktcargo)
2599
2600 positionsX
2601 .byt 20*6, 26*6, 35*6, 2*6, 14*6, 20*6, 26*6, 35*6
2602
2603 #endif
2604
2605
2606 _displaymarket
2607 .(
2608 ; clear selection
2609 lda #$ff
2610 sta _cur_sel
2611
2612 ; Clear hires and draw frame
2613 jsr clr_hires
2614
2615 lda #1
2616 sta capson
2617
2618 jsr put_space
2619 jsr put_space
2620 ;lda #A_FWCYAN
2621 lda #(A_FWWHITE+A_FWCYAN*16+128)
2622 jsr put_code
2623 jsr print_planet_name ; jsr gs_planet_name
2624 jsr put_space
2625 ldx #STR_MKT
2626 jsr printtail
2627
2628 jsr perform_CRLF
2629 jsr perform_CRLF
2630
2631 lda #A_FWCYAN
2632 ;lda #(A_FWWHITE+A_FWCYAN*16+128)
2633 jsr put_code
2634
2635
2636 #ifdef PACK
2637 lda #0
2638 sta count
2639 loop
2640 ldx count
2641 lda positionsX,x
2642 tax
2643 jsr gotoX
2644 ldy count
2645 lda mkstrshi,y
2646 tax
2647 lda mkstrslo,y
2648 jsr print
2649
2650 ldx count
2651 cpx #2
2652 bne nothing
2653
2654 jsr perform_CRLF
2655 lda #A_FWCYAN
2656 jsr put_code
2657 nothing
2658 ldx count
2659 inx
2660 cpx #8
2661 bne loop
2662
2663 #else
2664 ldx #(20*6)
2665 jsr gotoX
2666
2667 lda #<str_mktunit
2668 ldx #>str_mktunit
2669 jsr print
2670
2671 ldx #(26*6)
2672 jsr gotoX
2673
2674 lda #<str_mktquant
2675 ldx #>str_mktquant
2676 jsr print
2677
2678 ldx #(35*6)
2679 jsr gotoX
2680
2681 lda #<str_mktin
2682 ldx #>str_mktin
2683 jsr print
2684
2685 jsr perform_CRLF
2686
2687 lda #A_FWCYAN
2688 jsr put_code
2689
2690
2691 lda #<str_mktlist
2692 ldx #>str_mktlist
2693 jsr print
2694
2695 ldx #(14*6)
2696 jsr gotoX
2697
2698 lda #<str_mktunit
2699 ldx #>str_mktunit
2700 jsr print
2701
2702 ldx #(20*6)
2703 jsr gotoX
2704
2705 lda #<str_mktprice
2706 ldx #>str_mktprice
2707 jsr print
2708
2709 ldx #(26*6)
2710 jsr gotoX
2711
2712 lda #<str_mktsale
2713 ldx #>str_mktsale
2714 jsr print
2715
2716 ldx #(35*6)
2717 jsr gotoX
2718
2719 lda #<str_mktcargo
2720 ldx #>str_mktcargo
2721 jsr print
2722
2723 #endif
2724 ;jsr perform_CRLF
2725
2726 lda #0
2727 sta capson
2728
2729 ;for(i=0;i<=lasttrade;i++)
2730 ; {
2731 ; Loop thru the 17 market items
2732 lda #0
2733 sta count
2734 loop2
2735 ;printf("\n");
2736 jsr perform_CRLF
2737
2738 jsr print_mkt_item
2739 inc count
2740 lda count
2741 cmp #17
2742 bne loop2
2743
2744 rts
2745 .)
2746
2747 print_mkt_item
2748 .(
2749 ;printf(Names[i]);
2750 lda #(A_FWGREEN+A_FWYELLOW*16+128)
2751 jsr put_code
2752
2753 ldx count
2754 lda #<Goodnames
2755 sta tmp0
2756 lda #>Goodnames
2757 sta tmp0+1
2758 jsr search_string_and_print
2759
2760 lda #(A_FWWHITE)
2761 jsr put_code
2762
2763 ldx #(16*6)
2764 jsr gotoX
2765
2766 ;printf(" %f",(float)prices[i]/10);
2767
2768 jsr punit
2769
2770 ldx #(18*6)
2771 jsr gotoX
2772 ;jsr put_space
2773 lda count
2774 asl
2775 tax
2776 lda _prices,x
2777 sta op2
2778 lda _prices+1,x
2779 sta op2+1
2780 ldx #5
2781 jsr print_float_tab
2782
2783 ;printf(" %d",quantities[i]);
2784 ;jsr put_space
2785 ldx #(27*6)
2786 jsr gotoX
2787
2788 ldx count
2789 lda _quantities,x
2790 jsr prstock
2791
2792 jsr put_space
2793
2794 ;printf(unitnames[Units[i]]);
2795
2796 jsr punit
2797
2798 ;printf(" %d",shipshold[i]);
2799
2800 ldx #(35*6)
2801 jsr gotoX
2802
2803 ldx count
2804 lda _shipshold,x
2805 jsr prstock
2806
2807 ;jsr punit
2808
2809 ; }
2810
2811 rts
2812 .)
2813
2814
2815 prstock
2816 .(
2817 beq nostock
2818 sta op2
2819 lda #0
2820 sta op2+1
2821 ldx #3
2822 jmp print_num_tab
2823 nostock
2824 jsr put_space
2825 jsr put_space
2826 lda #"-"
2827 jmp put_char ; this is jsr/rts
2828 .)
2829
2830 punit
2831 .(
2832 ldx count
2833 lda Units,x
2834 tax
2835 lda #<Unitnames
2836 sta tmp0
2837 lda #>Unitnames
2838 sta tmp0+1
2839 jmp search_string_and_print ; this is jsr/rts
2840 .)
2841
2842 print_float_tab
2843 .(
2844 stx tabs+1
2845 jsr itoa
2846 jsr stlen
2847 stx tmp
2848 sec
2849 tabs
2850 lda #00
2851 sbc tmp
2852
2853 tax
2854 loopsp
2855 jsr put_space
2856 dex
2857 bne loopsp
2858 jmp loop
2859
2860 +print_float
2861 jsr itoa
2862 +print_bufconv
2863 loop
2864 ldx #0
2865 text
2866 lda bufconv+1,x
2867 beq butone
2868 lda bufconv,x
2869 jsr put_char
2870 inx
2871 bne text
2872
2873 butone
2874 lda bufconv,x
2875 pha
2876 lda #"."
2877 jsr put_char
2878 pla
2879 jmp put_char ; This is jsr/rts
2880
2881 .)
2882
2883
2884 print_num_tab
2885 .(
2886 stx tabs+1
2887 jsr itoa
2888 jsr stlen
2889 stx tmp
2890 sec
2891 tabs
2892 lda #00
2893 sbc tmp
2894
2895 beq loop
2896 tax
2897 loopsp
2898 jsr put_space
2899 dex
2900 bne loopsp
2901 jmp loop
2902
2903 +print_num
2904 jsr itoa
2905 ;jsr utoa
2906 loop
2907 lda #<bufconv
2908 ldx #>bufconv
2909 jmp print
2910 .)
2911
2912
2913 stlen
2914 .(
2915 ldx #$ff
2916 loop
2917 inx
2918 lda bufconv,x
2919 bne loop
2920
2921 rts
2922 .)
2923
2924 printtitle
2925 .(
2926
2927 jsr perform_CRLF
2928
2929 lda #(A_FWGREEN+A_FWYELLOW*16+128)
2930 jsr put_code
2931 .)
2932 printtail
2933 .(
2934 lda #<str_data
2935 sta tmp0
2936 lda #>str_data
2937 sta tmp0+1
2938 jsr search_string_and_print
2939
2940 ;jmp put_space ; This is jsr/rts
2941 lda #A_FWWHITE
2942 jmp put_code
2943 ;rts
2944 .)
2945
2946 ;;; Selection of items
2947 ; Start at row 36 and add 6 per item
2948
2949 _cur_sel .byt $ff
2950
2951 get_p
2952 .(
2953 ldx _cur_sel
2954 lda #30
2955 clc
2956 loop
2957 adc #6
2958 dex
2959 bpl loop
2960
2961 tay
2962 ldx #0
2963 jmp gotoXY
2964 .)
2965
2966 remove_hilite
2967 .(
2968 lda _cur_sel
2969 cmp #$ff
2970 beq noerase
2971 jsr get_p
2972 lda #A_BGBLACK
2973 jmp put_code
2974 noerase
2975 rts
2976 .)
2977
2978 set_hilite
2979 .(
2980 jsr get_p
2981 lda #A_BGBLUE
2982 jmp put_code
2983 .)
2984
2985 _inc_sel
2986 .(
2987 jsr remove_hilite
2988 ldx _cur_sel
2989 inx
2990 cpx #17
2991 bne cont
2992 ldx #0
2993 cont
2994 jmp set_sel
2995 .)
2996
2997 _dec_sel
2998 .(
2999 jsr remove_hilite
3000 ldx _cur_sel
3001 dex
3002 bpl cont
3003 ldx #16
3004 cont
3005 jmp set_sel
3006 .)
3007
3008
3009 set_sel
3010 .(
3011 stx _cur_sel
3012 jsr set_hilite
3013 .)
3014 mkt_status
3015 .(
3016 ; Print player status:
3017 ; Cash & free cargo space
3018
3019 jsr prepare_area
3020
3021 lda #(A_FWCYAN|A_FWWHITE*16+128)
3022 jsr put_code
3023 ldx #>str_freespace
3024 lda #<str_freespace
3025 jsr print
3026 jsr put_space
3027 lda _holdspace
3028 sta op2
3029 lda #0
3030 sta op2+1
3031 ldx #3
3032 jsr print_num_tab
3033 jsr put_space
3034 ldx #>Unitnames
3035 lda #<Unitnames
3036 jsr printnl
3037 ; ldx #4
3038 ;loop
3039 ; jsr put_space
3040 ; dex
3041 ; bne loop
3042
3043 lda #(A_FWCYAN|A_FWWHITE*16+128)
3044 jsr put_code
3045 jsr put_space
3046 ldx #>str_cash
3047 lda #<str_cash
3048 jsr print
3049 jsr put_space
3050
3051 ldx #3
3052 loop
3053 lda _cash,x
3054 sta op1,x
3055 dex
3056 bpl loop
3057 jsr ltoa
3058 jsr print_bufconv
3059 jsr put_space
3060 ldx #>str_credits
3061 lda #<str_credits
3062 jmp print
3063
3064 .)
3065
3066
3067
3068 ; Check if we have enough cash to pay op2,op2+1 credits
3069 ; C=0 no cash, C=1, we have cash
3070 enough_cash
3071 .(
3072 lda _cash+3
3073 ora _cash+2
3074 bne havecash
3075 lda _cash+1
3076 sta op1+1
3077 lda _cash
3078 sta op1
3079 jmp cmp16
3080 havecash
3081 sec
3082 rts
3083 .)
3084
3085
3086 ; Pay the value in op2,op2+1
3087 dec_cash
3088 .(
3089 ; decrement cash
3090 ; 32-bit substraction here
3091 sec
3092 lda _cash
3093 sbc op2
3094 sta _cash
3095 lda _cash+1
3096 sbc op2+1
3097 sta _cash+1
3098 bcs nomore
3099 lda _cash+2
3100 sbc #0
3101 sta _cash+2
3102 bcs nomore
3103 dec _cash+3
3104 nomore
3105 rts
3106 .)
3107
3108
3109 ; Add op2,op2+1 credits to player
3110 inc_cash
3111 .(
3112 ; increment cash
3113 ; 32-bit addition here
3114 clc
3115 lda _cash
3116 adc op2
3117 sta _cash
3118 lda _cash+1
3119 adc op2+1
3120 sta _cash+1
3121 bcc nomore
3122 lda _cash+2
3123 adc #0
3124 sta _cash+2
3125 bcc nomore
3126 inc _cash+3
3127 nomore
3128 rts
3129 .)
3130
3131
3132 _buy
3133 .(
3134 ; check if there is something for sale
3135 ldx _cur_sel
3136 lda _quantities,x
3137 beq nosell
3138
3139 ; check for cash
3140 ; Get price in op2
3141 stx savx+1
3142 txa
3143 asl
3144 tax
3145 lda _prices,x
3146 sta op2
3147 lda _prices+1,x
3148 sta op2+1
3149 savx
3150 ldx #0 ;SMC
3151
3152 jsr enough_cash
3153 bcc nocash
3154
3155 ; check for cargo space
3156 lda Units,x
3157 bne space
3158 lda _holdspace
3159 beq nospace
3160 dec _holdspace
3161 space
3162
3163 dec _quantities,x
3164 inc _shipshold,x
3165
3166 jsr dec_cash
3167 jmp update_mkt
3168 nosell
3169 nospace
3170 nocash
3171 end
3172 rts
3173 .)
3174
3175 _sell
3176 .(
3177 ; check if there is something for sale
3178 ldx _cur_sel
3179 lda _shipshold,x
3180 beq nosell
3181
3182 lda Units,x
3183 bne space
3184 inc _holdspace
3185 space
3186 inc _quantities,x
3187 dec _shipshold,x
3188
3189 ; Get price in op2
3190 txa
3191 asl
3192 tax
3193 lda _prices,x
3194 sta op2
3195 lda _prices+1,x
3196 sta op2+1
3197
3198 jsr inc_cash
3199
3200 jmp update_mkt
3201
3202 nosell
3203 end
3204 rts
3205 .)
3206
3207 update_mkt
3208 .(
3209 jsr get_p
3210 lda Cursor_origin_x
3211 clc
3212 adc #6
3213 tax
3214 jsr gotoX
3215
3216 lda _cur_sel
3217 sta count
3218 jsr print_mkt_item
3219
3220 jmp mkt_status
3221 .)
3222
3223
3224
3225 ;;;; Changing galaxy
3226
3227 ;Rotate reg A left once. Carry is put in bit 0.
3228 crol
3229 .(
3230 asl
3231 adc #0
3232 rts
3233 .)
3234
3235 _enter_next_galaxy
3236 .(
3237 ldx #5
3238 loop
3239 lda _base0,x
3240 jsr crol
3241 sta _base0,x
3242 dex
3243 bpl loop
3244
3245 ldy _galaxynum
3246 iny
3247 cpy #9
3248 bne more
3249 ldy #1
3250 more
3251 sty _galaxynum
3252 lda _currentplanet
3253 sta _dest_num
3254 jsr _infoplanet
3255 jsr _makesystem
3256 rts
3257
3258 .)
3259
3260
3261
3262
3263
3264
3265

  ViewVC Help
Powered by ViewVC 1.1.26