Jump to content
IGNORED

Introducing Structured Extended BASIC and TiCodEd


SteveB

Recommended Posts

8 hours ago, SteveB said:

No, this is in the upcomming version 1.3 I am currently working on. I will join the source-next line when

  • the last command is a THEN
  • the last command is a ELSE
  • the last command is a ::
  • the last command is a .. and remove the .. inbetween

is this the desired behaviour?

 

In my development-version 1.3 alpha it gets translated to:


100 IF MOUSE=1 THEN MOUSE=0::MFLAG=1:: CALL LINK("MCLR"):: CALL DELSPRITE(#1):: GOSUB cursor
110 ELSE mouseon

As I do a sequential read and do not know the next line the .. after the GOSUB is needed, then it works like


100 IF MOUSE=1 THEN MOUSE=0::MFLAG=1:: CALL LINK("MCLR"):: CALL DELSPRITE(#1):: GOSUB cursor  ELSE mouseon

I will send you a private message when I am in a beta-state with 1.3, also to test the CASE and BEGIN-END feature, if you like.

 

Steve

Yes that is exactly the desired behavior. Thank you! I would love to give 1.3 a whirl.

Link to comment
Share on other sites

While you're at it, would it also be possible to fix the issue of the underscore in labels? As it is currently, an underscore within a label like mouse_on breaks the translation of the label to a line number.

Another suggestion for a future update would be the addition of the IN statement:

 

IF X IN[1,2,3,4] THEN 350

becomes

IF X=1 OR X=2 OR X=3 OR X=4 THEN 350

Obviously a huge improvement in readability. Can you tell I'm a fan of Pascal? ?

Edited by Vorticon
  • Like 1
Link to comment
Share on other sites

Pascal is somehow my digital native language, even though I started with TI BASIC / Extended BASIC in 1983. I congratulated Niklas Wirth on the 50th anniversary of his "child" Pascal and he sent a nice "thank you" mail. Something to keep ...

 

The underscore will be in the next release, not sure yet about the IN Statement. 

  • Like 3
Link to comment
Share on other sites

7 hours ago, SteveB said:

Pascal is somehow my digital native language, even though I started with TI BASIC / Extended BASIC in 1983. I congratulated Niklas Wirth on the 50th anniversary of his "child" Pascal and he sent a nice "thank you" mail. Something to keep ...

 

The underscore will be in the next release, not sure yet about the IN Statement. 

Same story here. Started with TI Basic (did not even own XB) then took Pascal in college in the early 80's and was totally hooked. Most of my recent work has been with Turbo Pascal 3 under CP/M.

  • Like 5
Link to comment
Share on other sites

I started working on this program as a TiCodEd experiment. I got more than I bargained for.
Initially I thought the way to calculate days alive would be with loops to count partial years and full years, but that quickly became cumbersome, so I went to stackoverflow to see what the best algorithm was to use. It seems many languages have a Julian date function built in, so to calculate days alive you just convert a standard date to a Julian equivalent, then subtract the beginning and ending Julian dates. Fortunately, the formula for doing that is just one heavy line of calculations. Having one line with a mathematical formula sure does beat lots of IF's and Loops.
 
Then I went to look at leap years someone had lived through, again, looking at the official Microsoft rules for what is a leap year, lead to nested if's and Senior_Falcon came up with another of those perfect mathematical algorithms, which was not only fast, small and delivered perfect results.
 
As this was going on, I was also abusing TICodEd. I got what I thought was an error on the line to calculate Julian Date. I sent it off to Steve, because I was able to copy the same code in to Classic99 and it worked. Tursi must have some secret sauce in the paste menu option that deals with Unicode.
 
Steve did a bit of digging, and found that the original code I copied in to TiCodEd (from wikipedia) had Unicode characters mixed in. The tell was the - sign showed up in red, the minus sign should show up as blue in calculations.
 
Also, since RXB is delivered with Classic99, I went ahead and made that my default XB, as the editing functions, debugging and fonts are much improved over standard XB.
 
days.png.af8c6e899413ca46396143bb54fd7088.png
 
// ldom 08-09-2021 - dhe

// setup screen
call clear
call screen(7)

print "** Calculate Days Alive **"
print ""
print "Enter dates like MM-DD-YYYY"
print ""
input "     Birth date:":birth$
input "Date of passing:":pass$

b_month=val(seg$(birth$,1,2))
b_day=val(seg$(birth$,4,2))
b_year=val(seg$(birth$,7,4))

p_month=val(seg$(pass$,1,2))
p_day=val(seg$(pass$,4,2))
p_year=val(seg$(pass$,7,4))

//print b_month;b_day;b_year
//print p_month;p_day;p_year


// convert birthday to julian date
call jnd_calc(b_year,b_month,b_day,bjnd)
call jnd_calc(p_year,p_month,p_day,pjnd)

//print bjnd
//print pjnd

// easily calculate number of days alive, by subtracting julian dates
print ""
print "Number of days lived:";int(pjnd-bjnd)

print ""
print "Leap Years: "
// check if they lived in a leap year!
z=0 // set to false
for i=b_year to p_year
  call isleap(i,z)
  if z=1 then print i;
  z=0  // set back to false
next i
print ""

call quit
end

sub jnd_calc(Y,M,D,z)
  z = (1461*(Y+4800+(M-14)/12))/4+(367*(M-2-12*((M-14)/12)))/12-(3*((Y+4900+(M-14)/12)/100))/4+D-32075
// formula to calc julian date from wikipedia
subend

sub isleap(Y,LY)
  LY=-((Y/4)=INT(Y/4))+((Y/100)=INT(Y/100))-((Y/400)=INT(Y/400))
// a perfect algorithum @senior_falcon - atariage.
subend

sub quit
  print ""
  print "Press any key to quit"
  loop1:
    call key(5,k,s)
    if s=0 then loop1
subend

// initially I tried to look at the number of years - whole and parts and calculate total number of days.
// that quickly become a task, I looked at how real programmers do it. Most modern languages use
// a julian subroutine. https://en.wikipedia.org/wiki/Julian_day

// perfect algorithum by @senior_falcon - atariage explination:
// If LY=1 then it is a leap year, if 0 then it is not a leap year. To explain:
// -((Y/4)=INT(Y/4)) returns a value of 1 if true and 0 if false, so if the year is divisible by 4 then LY=1.
// Then ((Y/100)=INT(Y/100))  returns a value of -1 if true and 0 if false, so if the year is divisible by 100 then 1 is subtracted from LY, making it 0.
// Then -((Y/400)=INT(Y/100)) returns a value of 1 if the year is divisible by 400
//
// (Edit) This is a tiny bit more compact:
// 20 LY=((Y AND 3)>0)-((Y/100)<>INT(Y/100))-((Y/400)=INT(Y/400))
//
// It is also, unfortunate TI Basic does not include a MOD function - fortunately, @InsaneMultitasker to the rescue
//      DEF MOD(XX)=YR-INT(YR/XX)*XX

 

  • Like 3
Link to comment
Share on other sites

23 hours ago, dhe said:
Steve did a bit of digging, and found that the original code I copied in to TiCodEd (from wikipedia) had Unicode characters mixed in. The tell was the - sign showed up in red, the minus sign should show up as blue in calculations.

I haven't found a way to convert all unicode chars to their ASCII counterpart, so I just added a check for non-7-bit ASCII characters. With the next release you will at least get an error pointing to the "* UNRECOGNIZED CHARACTER".

 

Thank you for the nice example. I now know how many days I lived ... 

Link to comment
Share on other sites

So, as a learning experience I was going to try and use TICodEd to import the basic program TI-Trek PHD5002 (If I remember correctly) - So looking at the code, makes my eye's bleed. I don't know if this code was converted from existing code with a program, or just entered by hand, or what... But I've never seen code this bad, especially note line 4380 - it jumps to a return... uh... why not just if {something} return...

 

  

// REM   TI-TREK
// REM  TEXAS INSTRUMENTS 4/14/80
// ldom 08.17.2021
CALL CLEAR
130 K1=100
140 A=1
150 C1=1000
160 B=3
170 J=8
180 C=0
190 I=5
200 DEF RM(Z)=A+INT(RND*Z)
210 DEF CT(Z)=INT(Z+.5)
220 DEF MH(Z)=Z+SIN(D)
230 DEF MV(Z)=Z-COS(D)
240 DEF L1(Z)=(Z>22)+(Z<B)
250 DEF L2(Z)=(Z>20)+(Z<A)
260 DEF T$=SEG$(K$,A,A)
270 PRINT TAB(10);"99/4  BASIC": :TAB(12);"TI-TREK": :TAB(7);"TEXAS INSTRUMENTS": :TAB(8);"COPYRIGHT  1980": : : : : : : :
280 PRINT "WILL YOU USE SPEECH";
290 INPUT K$
300 RANDOMIZE
310 O=C
320 IF T$<>"Y" THEN 390
330 OPEN #1:"DSK1.TREKSAY",RELATIVE,INTERNAL,INPUT,FIXED 255
340 O=A
350 U=1
360 GOSUB 5300
370 U=3
380 GOSUB 5300
390 DIM P(5),S(20),T(20),R(20),G(8,5)
400 DG=57.2957795
410 FOR U=9 TO 14
420 READ V,M$
430 X=(U*J)+24
440 CALL CHAR(X,M$)
450 CALL COLOR(U,V,2)
460 NEXT U
470 CALL CHAR(132,"5A8140EF243E815A")
480 CALL CHAR(124,"0000381038000000")
490 CALL CHAR(K1,"0000000000000000")
500 CALL CHAR(140,"FFFFFFFFFFFFFFFF")
510 E=96
520 R(A)=E
530 F=C
540 PRINT:"LEVEL OF DIFFICULTY:":"1-EASY,5-HARD";
550 INPUT DIF
560 IF DIF<A THEN 550
570 IF DIF>5 THEN 550
580 FOR U=A TO J
590 FOR V=A TO I
600 W=RM(12)
610 W=W*ABS(W<(5+DIF))
620 F=F+W
630 G(U,V)=C1+(K1*W)+(1010*INT(.15+RND))+RM(9)
640 NEXT V
650 NEXT U
660 U=29
670 GOSUB 5300
680 CALL CLEAR
690 TM=(11-DIF)*F
700 H=.5+RND
710 GOSUB 4070
720 RW=12
730 CL=24
740 M$="TORP"
750 GOSUB 2510
760 M=RM(J)
770 N=RM(I)
780 M$="PWR"
790 GOSUB 5280
800 M$="FOES"
810 GOSUB 5280
820 M$="TIME"
830 GOSUB 5280
840 GOSUB 2010
850 K=S(A)
860 L=T(A)
870 X=S(A)
880 Y=T(A)
890 IF T$="W" THEN 4460
900 CALL HCHAR(21,A,32,128)
910 M$="COMMAND?"
920 RW=22
930 GOSUB 2500
940 O1=14
950 GOSUB 2330
960 U=A+POS("MDFTVWLSCQ",T$,A)
970 ON U GOTO 900,1150,3870,4890,980,4780,3270,2890,1510,2550,5350
980 V=ABS(TP>C)
990 IF TP>C THEN 1110
1000 M$="NO TORPEDOS LEFT"
1010 RW=24
1020 GOSUB 2500
1030 GOTO 900
1040 M$="ANGLE IN DEGREES?"
1050 RW=RW+A
1060 GOSUB 2500
1070 O1=22
1080 GOSUB 2330
1090 D=VAL(K$)/DG
1100 RETURN
1110 GOSUB 1040
1120 IF V>A THEN 4820
1130 GOSUB 1560
1140 GOTO 4490
1150 M$="MOVE HOW FAR?"
1160 RW=RW+A
1170 GOSUB 2500
1180 O1=18
1190 GOSUB 2330
1200 ML=VAL(K$)
1210 GOSUB 1040
1220 U=7
1230 GOSUB 5300
1240 X=S(A)
1250 Y=T(A)
1260 FOR W=A TO ML
1270 X=MH(X)
1280 Y=MV(Y)
1290 IF L1(CT(X))+L2(CT(Y))THEN 1400
1300 CALL GCHAR(Y,X,V)
1310 IF V=E THEN 1270
1320 IF V<>K1 THEN 1400
1330 CALL HCHAR(L,K,K1)
1340 K=X
1350 L=Y
1360 CALL HCHAR(Y,X,R(A))
1370 CALL SOUND(-20,180,I)
1380 NEXT W
1390 GOTO 1450
1400 M$="EMERGENCY STOP!"
1410 ML=W
1420 CALL SOUND(-250,4000,4,-2,3)
1430 RW=22
1440 GOSUB 2500
1450 S(A)=CT(K)
1460 T(A)=CT(L)
1470 EP=EP-(10*W)
1480 TM=TM-2*ML
1490 GOSUB 4090
1500 GOTO 4490
1510 E=228-E
1520 R(A)=E
1530 CALL HCHAR(T(A),S(A),E)
1540 TM=TM-A
1550 GOTO 900
1560 TP=TP-V
1570 TM=TM-(A+V)
1580 U=19
1590 GOSUB 5300
1600 FOR W=A TO V
1610 X=S(A)
1620 Y=T(A)
1630 U=700
1640 X=MH(X)
1650 Y=MV(Y)
1660 IF L1(CT(X))+L2(CT(Y))THEN 1950
1670 CALL GCHAR(Y,X,Z1)
1680 IF Z1<>K1 THEN 1740
1690 CALL HCHAR(Y,X,128)
1700 CALL SOUND(50,U,5)
1710 U=U*1.02
1720 CALL HCHAR(Y,X,K1)
1730 GOTO 1640
1740 IF Z1=E THEN 1630
1750 IF Z1=104 THEN 1790
1760 U=23
1770 GOSUB 5300
1780 EP=EP-INT(EP/(3+RND))
1790 CALL HCHAR(Y,X,136)
1800 CALL SOUND(200,-7,A)
1810 CALL HCHAR(Y,X,124)
1820 CALL SOUND(50,-8,7)
1830 CALL HCHAR(Y,X,K1)
1840 FOR Y1=A TO N1
1850 IF(S(Y1)=CT(X))+(T(Y1)=CT(Y))>-2 THEN 1930
1860 G(M,N)=G(M,N)-10^(2-(R(Y1)-104)/J)
1870 F=F+(R(Y1)=104)
1880 R(Y1)=K1
1890 IF Z1<>104 THEN 1970
1900 U=21
1910 GOSUB 5300
1920 GOTO 1970
1930 NEXT Y1
1940 STOP
1950 U=25
1960 GOSUB 5300
1970 D=D+T1/DG
1980 NEXT W
1990 GOSUB 4090
2000 RETURN
2010 G(M,N)=G(M,N)-C1*INT(G(M,N)/C1)
2020 W=INT(G(M,N))
2030 FOR U=A TO 20
2040 CALL HCHAR(U,B,K1,20)
2050 NEXT U
2060 Y=A
2070 V=E
2080 GOSUB 2200
2090 V=96
2100 FOR P1=2 TO C STEP-1
2110 U=INT(W/(10^P1))
2120 W=W-(10^P1)*U
2130 V=V+J
2140 FOR X=A TO U
2150 GOSUB 2190
2160 NEXT X
2170 NEXT P1
2180 GOTO 2270
2190 R(Y)=V
2200 S(Y)=4+INT(18*RND)
2210 T(Y)=2+INT(18*RND)
2220 CALL GCHAR(T(Y),S(Y),Z1)
2230 IF Z1<>K1 THEN 2200
2240 CALL HCHAR(T(Y),S(Y),V)
2250 Y=Y+A
2260 RETURN
2270 M$="QUAD("&STR$(M)&","&STR$(N)&")"
2280 RW=3
2290 CL=24
2300 GOSUB 2510
2310 N1=Y-A
2320 RETURN
2330 R1=RW
2340 K$=""
2350 U1=C
2360 CALL KEY(C,Q1,T1)
2370 IF T1<=C THEN 2360
2380 IF Q1=32 THEN 2360
2390 IF Q1<>J THEN 2420
2400 CALL HCHAR(R1,O1,32,U1)
2410 GOTO 2340
2420 IF Q1=13 THEN 2470
2430 K$=K$&CHR$(Q1)
2440 CALL HCHAR(R1,O1+U1,Q1)
2450 U1=U1+A
2460 GOTO 2360
2470 IF R1=19 THEN 2490
2480 IF LEN(K$)=0 THEN 2340
2490 RETURN
2500 CL=4
2510 FOR I1=A TO LEN(M$)
2520 CALL HCHAR(RW,(CL+I1-1),ASC(SEG$(M$,I1,1)))
2530 NEXT I1
2540 RETURN
2550 FOR Y=A TO J
2560 M$=""
2570 FOR X=A TO I
2580 ON A+INT(G(Y,X)/C1)GOTO 2590,2640,2620
2590 K$="00"&STR$(G(Y,X))
2600 K$=SEG$(K$,LEN(K$)-2,B)
2610 GOTO 2650
2620 K$="?1?"
2630 GOTO 2650
2640 K$="   "
2650 M$=M$&K$&"!"
2660 NEXT X
2670 RW=2*Y-A
2680 CL=B
2690 GOSUB 2510
2700 CALL HCHAR((2*Y),B,45,20)
2710 NEXT Y
2720 FOR W=17 TO 20
2730 CALL HCHAR(W,B,32,20)
2740 NEXT W
2750 M$="PRESS ENTER"
2760 RW=18
2770 GOSUB 2500
2780 R1=19
2790 O1=10
2800 GOSUB 2340
2810 FOR W=A TO 20
2820 CALL HCHAR(W,B,K1,20)
2830 NEXT W
2840 FOR W=A TO N1
2850 IF R(W)=K1 THEN 2870
2860 CALL HCHAR(T(W),S(W),R(W))
2870 NEXT W
2880 GOTO 850
2890 Q1=M+(M<>A)
2900 R1=M-(M<>J)
2910 S1=N+(N<>A)
2920 T1=N-(N<>I)
2930 FOR W=B TO 22
2940 CALL VCHAR(A,W,32,20)
2950 NEXT W
2960 CALL VCHAR(A,10,33,15)
2970 CALL VCHAR(A,16,33,15)
2980 FOR W=5 TO 15 STEP 5
2990 CALL HCHAR(W,B,95,20)
3000 NEXT W
3010 M$="LONG RANGE SCAN"
3020 RW=16
3030 CL=6
3040 GOSUB 2510
3050 M$=CHR$(E)&" "&STR$(M)&","&STR$(N)
3060 RW=6
3070 CL=11
3080 GOSUB 2510
3090 FOR X=S1 TO T1
3100 CL=12+6*(X-N)
3110 FOR Y=Q1 TO R1
3120 G(Y,X)=G(Y,X)-C1*INT(G(Y,X)/C1)
3130 RW=6+5*(Y-M)
3140 U=96
3150 V=INT(G(Y,X))
3160 FOR W=2 TO C STEP-1
3170 A1=INT(V/(10^W))
3180 V=V-(10^W)*A1
3190 U=U+J
3200 M$=STR$(A1)&" "&CHR$(U)
3210 RW=RW+A
3220 GOSUB 2510
3230 NEXT W
3240 NEXT Y
3250 NEXT X
3260 GOTO 2720
3270 M$="DEST ROW?"
3280 RW=23
3290 GOSUB 2500
3300 O1=14
3310 GOSUB 2330
3320 S1=VAL(T$)
3330 IF(S1<A)+(S1>J)=0 THEN 3380
3340 M$="OUTSIDE PATROL BOUNDARY"
3350 RW=22
3360 GOSUB 2500
3370 GOTO 900
3380 M$="DEST COL?"
3390 RW=24
3400 GOSUB 2500
3410 GOSUB 2330
3420 T1=VAL(T$)
3430 IF(T1<A)+(T1>I)THEN 3340
3440 IF(S1<>M)+(T1<>N)THEN 3490
3450 M$="ALREADY HERE"
3460 RW=22
3470 GOSUB 2500
3480 GOTO 850
3490 W=SQR(((S1-M)^2)+((T1-N)^2))
3500 EP=INT(EP-200*(A+RND)*W)
3510 TM=TM-INT(5*W)
3520 M=S1
3530 N=T1
3540 GOSUB 4090
3550 V=330
3560 U=27
3570 GOSUB 5300
3580 FOR W=A TO 20
3590 CALL SOUND(-1000,V,4)
3600 CALL VCHAR(A,(2+W),140,20)
3610 V=V*1.02
3620 NEXT W
3630 CALL SOUND(30,V,3,-3,1)
3640 CALL HCHAR(10,7,136,12)
3650 M$=" WARP "
3660 CALL SOUND(-200,4000,5,-6,2)
3670 CL=10
3680 RW=CL
3690 GOSUB 2510
3700 IF RND>.1 THEN 3830
3710 U=9
3720 GOSUB 5300
3730 M$="MAGNETIC STORM"
3740 CL=6
3750 RW=12
3760 GOSUB 2510
3770 M$="BLOWN OFF COURSE"
3780 CL=I
3790 RW=14
3800 GOSUB 2510
3810 M=RM(J)
3820 N=RM(I)
3830 CALL SOUND(10,-2,1)
3840 K$="W"
3850 H=.5+RND
3860 GOTO 840
3870 Q1=S(A)+(S(A)<>A)
3880 R1=S(A)-(S(A)<>22)
3890 S1=T(A)+(T(A)<>A)
3900 T1=T(A)-(T(A)<>20)
3910 FOR X=Q1 TO R1
3920 FOR Y=S1 TO T1
3930 CALL GCHAR(Y,X,Z1)
3940 IF Z1=112 THEN 4030
3950 NEXT Y
3960 NEXT X
3970 M$="NOT AT BASE"
3980 ROW=24
3990 GOSUB 2500
4000 U=13
4010 GOSUB 5300
4020 GOTO 850
4030 GOSUB 4070
4040 U=11
4050 GOSUB 5300
4060 GOTO 850
4070 TP=20
4080 EP=8000
4090 RW=10
4100 CL=29
4110 CALL HCHAR(21,A,32,128)
4120 M$=STR$(TP)
4130 GOSUB 5250
4140 IF EP>C THEN 4160
4150 EP=C
4160 M$=STR$(EP)
4170 GOSUB 5250
4180 M$=STR$(F)
4190 GOSUB 5250
4200 IF F>C THEN 4330
4210 M$="CONGRATULATIONS!!"
4220 RW=22
4230 GOSUB 2500
4240 M$="ALL ENEMY SHIPS DESTROYED!"
4250 RW=23
4260 GOSUB 2500
4270 M$="YOU HAVE SAVED THE GALAXY!"
4280 RW=24
4290 GOSUB 2500
4300 U=35
4310 GOSUB 5300
4320 GOTO 5350
4330 IF TM>C THEN 4350
4340 TM=C
4350 M$=STR$(TM)
4360 GOSUB 5250
4370 IF EP<=C THEN 4690
4380 IF TM>C THEN 4450
4390 U=33
4400 GOSUB 5300
4410 M$="TIME EXPIRED"
4420 RW=22
4430 GOSUB 2500
4440 GOTO 4740
4450 RETURN
4460 IF G(M,N)/K1<A THEN 900
4470 U=5
4480 GOSUB 5300
4490 W=INT(G(M,N)/K1)
4500 IF W<A THEN 900
4510 M$="ALERT! FOES FIRING!    "
4520 K$=""
4530 RW=24
4540 GOSUB 2500
4550 U=17
4560 GOSUB 5300
4570 V=3-(E-96)/18
4580 FOR U=1 TO W
4590 GOSUB 4650
4600 CALL SOUND(100,-1,30)
4610 NEXT U
4620 EP=EP-INT(W*H*V*(50+10*DIF))
4630 GOSUB 4090
4640 GOTO 850
4650 CALL SCREEN(7)
4660 CALL SOUND(400,-6,A)
4670 CALL SCREEN(4)
4680 RETURN
4690 M$="ENERGY GONE"
4700 RW=22
4710 GOSUB 2500
4720 U=31
4730 GOSUB 5300
4740 M$="GAME OVER, YOU LOST"
4750 RW=23
4760 GOSUB 2500
4770 GOTO 5350
4780 V=3
4790 IF V<TP THEN 4810
4800 V=TP
4810 GOTO 990
4820 M$="INC ANGLE?"
4830 RW=RW+A
4840 GOSUB 2500
4850 O1=18
4860 GOSUB 2330
4870 T1=VAL(K$)
4880 GOTO 1130
4890 RW=23
4900 E=96
4910 R(A)=E
4920 CALL HCHAR(T(A),S(A),E)
4930 M$="HOW MUCH POWER?"
4940 GOSUB 2500
4950 O1=20
4960 GOSUB 2330
4970 W=VAL(K$)
4980 TM=TM-B
4990 EP=EP-W
5000 V=INT(G(M,N)/K1)
5010 U=15
5020 GOSUB 5300
5030 IF V<>0 THEN 5050
5040 GOSUB 4650
5050 FOR X=1 TO V
5060 Y=(50+50*DIF)*(H+(RND/2))
5070 IF Y>W THEN 5190
5080 W=W-Y
5090 Q=A
5100 Q=Q+A
5110 IF R(Q)<>104 THEN 5100
5120 R(Q)=K1
5130 G(M,N)=G(M,N)-K1
5140 F=F-A
5150 CALL HCHAR(T(Q),S(Q),136)
5160 GOSUB 4650
5170 CALL HCHAR(T(Q),S(Q),K1)
5180 NEXT X
5190 M$=STR$(INT(W))&" WASTED"
5200 RW=24
5210 CL=8
5220 GOSUB 2510
5230 GOSUB 4090
5240 GOTO 4490
5250 IF LEN(M$)>=4 THEN 5280
5260 M$=" "&M$
5270 GOTO 5250
5280 RW=RW+2
5290 GOTO 2510
5300 IF O=C THEN 5340
5310 INPUT #1,REC U:M$
5320 INPUT #1,REC U+1:K$
5330 CALL SAY("",M$,"",K$)
5340 RETURN
5350 M$="PLAY AGAIN(Y/N)?"
5360 RW=21
5370 GOSUB 2500
5380 O1=21
5390 GOSUB 2330
5400 IF T$="Y" THEN 510
5410 IF O=C THEN 5430
5420 CLOSE #1
5430 STOP
5440 DATA 16,"0040EF243E000000"
5450 DATA 9,"0000037F3060F000"
5460 DATA 6,"001899BDFF9918E7"
5470 DATA 12,"00105428D6285410"
5480 DATA 15,"0000001038100000"
5490 DATA 9,"815A3C66663C5A81" 

 

Link to comment
Share on other sites

1 hour ago, dhe said:

So, as a learning experience I was going to try and use TICodEd to import the basic program TI-Trek PHD5002 (If I remember correctly) - So looking at the code, makes my eye's bleed. I don't know if this code was converted from existing code with a program, or just entered by hand, or what... But I've never seen code this bad, especially note line 4380 - it jumps to a return... uh... why not just if {something} return...

 

Asking machines to generate code can lead to some funny looking code.  Trans-pilers that convert from a language to C for example make C code that no human would write.

 

One could explain the line 4380 by invoking structured programming where all sub-routines have one entry and one exit.

So although BASIC was built to allow free jumping anywhere it is not possible in a structured program.

So if this was translated from a structured syntax program then this is a correct rendering I think.

Link to comment
Share on other sites

14 hours ago, TheBF said:

Asking machines to generate code can lead to some funny looking code.  Trans-pilers that convert from a language to C for example make C code that no human would write.

 

One could explain the line 4380 by invoking structured programming where all sub-routines have one entry and one exit.

So although BASIC was built to allow free jumping anywhere it is not possible in a structured program.

So if this was translated from a structured syntax program then this is a correct rendering I think.

I am actually working on some kind of import of XB code in TiCodEd, but I will restrict it to remove line numbers and assist in naming the labels for all used "destination lines". The free jumping makes any further translation a hopeless case. You may also use TiCodEd just as a fancy editor for any XB capable of writing tokenized programs to a FIAD. 

 

On the other side I designed TiCodEd to create maintainable XB code. There should never be a lock-in to SXB, you should always be able to continue any project in XB at any time. This is much easier when you design the language yourself. A trans-piler for Pascal to C needs to fit both ends, at the price of readability. I've seen awful C code there...

  • Like 2
Link to comment
Share on other sites

16 hours ago, dhe said:

But I've never seen code this bad, especially note line 4380 - it jumps to a return... uh... why not just if {something} return...

Except for the CALL SAY this is all TI BASIC and not Extended BASIC. IIRC in TI BASIC there is no "IF .. THEN RETURN", you can only give a line number.

  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...

It looks like the CASE statement cannot appear in an IF statement:

IF C=1 THEN
   CASE X OF
        1: PRINT X
        2: PRINT X+1
   ENDCASE

 becomes

690 ON -(X=1)-2*(X=2) GOSUB 20000, 20010

and completely ignores the previous IF statement.

 

One additional note about the CASE statement: since it translates into an ON GOSUB, one cannot use GOTO statements in the body of the structure as these will jump out of the associated subroutine and if done often enough will result in a stack overflow.

Link to comment
Share on other sites

This one caught my attention just at a glance:

4790 IF V<TP THEN 4810
4800 V=TP
4810 GOTO 990

So why not IF V<TP then 990

Also XB is much better at this then TI Basic ever would be 

4790 IF V<TP THEN 990 ELSE V=TP :: GOTO 990

 

Single line code kind of sucks a you end up with thousands of lines of code.

Link to comment
Share on other sites

30 minutes ago, RXB said:

This one caught my attention just at a glance:


4790 IF V<TP THEN 4810
4800 V=TP
4810 GOTO 990

So why not IF V<TP then 990

Also XB is much better at this then TI Basic ever would be 

4790 IF V<TP THEN 990 ELSE V=TP :: GOTO 990

 

Single line code kind of sucks a you end up with thousands of lines of code.

So you want convenient syntax AND optimization too? :)

Just kidding. 

 

I think it can be hard to do both in a single pass. (?)

I have new found respect for code generating programs after my recent research project. 

 

  • Like 3
Link to comment
Share on other sites

On 9/11/2021 at 1:20 PM, Vorticon said:

It looks like the CASE statement cannot appear in an IF statement:

I checked and was just about writing why it is impossible to fix I had the right idea. It will be fixed in the next beta due this weekend.

 

But I found a even more severe limitation I need to check and perhaps fix: You can't use CASE in a BEGIN/END block yet. I need a bright moment to fix this one ...

 

Concerning the "ON GOSUB" limitation with the GOTO ... With the set of language extensions in the current TiCodEd / SXB beta there is no need for GOTO anymore. The last case where a GOTO is needed was the IF-THEN-ELSE line-length limitation made it necessary to jump around a set of statements if it was to large to fit on one line. With the upcomming BEGIN/END this is solved in a smart way. 

  • Like 3
Link to comment
Share on other sites

  • 4 weeks later...
  • 2 weeks later...
I've always struggled understanding other people's code (OPC). So I decided to take on commenting TI Trek as a growth experience.
 
I'd never have been able to finish without TICodEd. In every game I ever code there has always been some slight of hand, figuring out the slight of hand used in TI Trek was the key to everything.
 
What's the trick?
 
TI Trek was meant to be played on an unexpanded TI in Basic - so memory was tight. You can see that in short variable names A, N1.
 
The Galaxy in TI Trek consists of a grid of 8x10 quadrants. Each quadrant consists of a 20x20 grid on sectors.
 
The straightforward approach would be to initialize an array Galaxy(8,10,20,20) - to track each object. - that a big chunk of memory considering each array has a floating point number eating up eight bytes.
 
So the track was to have a Galaxy Array (8,10) - then the author (would like to know who it was) - stored a number like 1218, corresponding to:
   QTY    Thing
      1 - The Captain Doesn't know what is in this Quadrant yet.
      2 - Foes (Klingons)
      1 - Base
      8 - Stars
 
The slight downside to this approach is each time you warp into a new quadrant things move around on you.
 
The code has been modified slightly from the original, mainly to allow for figuring how it worked.
 
Words alone do not express, how much easier it was to document the code with labels vs line numbers and also, just a few renaming of variables - instead of RM(Z) - f_RM(Z) to let you know you are looking at a function and S(X) vs a_S(X) to let you know you are dealing with an array.
 
The code included a couple of neat tricks, one that I had to stare at for a few minutes was:
F=F+(a_R(Y1)=104)         // F=F+0 unless a_R(Y1)=Klingon(104) then F=F-1
 
Other oddities stumbled upon, there was an array and a variable defined but never used - quickly found by going to the variables tab in TICodEd. Also the input error checking needs to be improved - there are areas you can blow out of the program with a bad argument error.
 
Partially I can blame the poor structure on limitations of Basic, I think a big part goes back to this code, which would have probably been written 1979 - and 'spaghetti code' was the order of the day.
 
Attached is the commented TICodED version - only labels no line numbers.
 
 

titrek.pdf

  • Like 3
  • Thanks 2
Link to comment
Share on other sites

sxb file.

 

I don't actually have a copy of the manual.

It's PHD5002 - the manual I referenced was from my copy of the cyc compilation.

If anyone has the manual, and would be willing to upload it here I would appreciate it.

 

Initially I'd thought about clean up the code and targeting RXB. I think I'll wait and target Strange Basic, I think that would be pretty kewl!

 

I have updated my linkedin profile, with unofficial maintainer of TI-Trek - I'm waiting for the job offers to pour in. ?

titrek.sxb

ti-trek1.pdf

Edited by dhe
add a ti-trek manual in PDF
  • Haha 3
Link to comment
Share on other sites

Hi Folks, 

 

the new version of TiCodEd is out now. What started as 1.3 ended as 2.0, as it now includes a true SXB highlighter instead of using the Visual Basic one, you can now export to HTML to get a formatted source for printing. Search & Replace have been reworked. The sprite editor evolved into a charset editor with three charsets, one for XB, one for XB256 and one free to use. Use CALL AUTOCHAR in your program to generate a SUB-Routine defining all CALL CHAR from XB and CALL LOAD(“CHAR2”...) from the XB256 charset or can be referenced manually in your code. No need for cut & paste anymore. 8x8 and 16x16 patterns can be animated and changed while the animation runs. The SXB language has been extended with a CASE statement, an IN[...] function and BEGIN-END blocks to extend your IF-THEN-ELSE beyond the line-limit of XB (creating GOSUB/RETURN). You can also control an emulator to load, run or compile your code via keyboard emulation (provided it knows FIAD and TIFILES, like Classic99).


Initiated by @oddemann and very much supported by @Airshack there is also an 88 page long TiCodEd Beginners Manual included now, explaining the use of TiCodEd, the features of Structured Extended Basic and how to compile and build your own module image to run in an emulator or with a card like FinalGROM on the real iron, alongside with the updated short manual.

 

You may download TiCodEd for Windows (64 and 32bit) and MacOS at http://lizardware.de/.

 

Enjoy and spread the word!

 

SteveB
 

  • Like 8
  • Thanks 1
Link to comment
Share on other sites

2 hours ago, Vorticon said:

Frankly, this project has matured to the point where I see little reason for the XB programmer not to use it for development when working under emulation.

 

And at this stage of maturity it is a good target for it's own compiler. :) 

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...