From 9b332497fd3cc93be3e7aa2ff9de3faba3ebe504 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Fri, 8 Apr 2016 13:39:50 -0400 Subject: [PATCH] ksp: some more work on this project --- TODO | 1 - ksp/Makefile | 9 ++++- ksp/c/Makefile | 10 ++++-- ksp/c/ksp_launch.c | 86 +++++++++++++++++++++++++++++++++++++++++++++ ksp/c/ksp_vab.c | 10 +++--- ksp/ksp.dsk | Bin 143360 -> 143360 bytes ksp/ship.table | 70 ++++++++++++++++++++++++++++++++++++ ksp/ship_test.bas | 34 ++++++++++++++++++ ksp/vab.bas | 42 ++++++++++++++++++++++ 9 files changed, 253 insertions(+), 9 deletions(-) create mode 100644 ksp/c/ksp_launch.c create mode 100644 ksp/ship.table create mode 100644 ksp/ship_test.bas create mode 100644 ksp/vab.bas diff --git a/TODO b/TODO index 94def001..539e8e91 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ - pcx2hgr: error checking complain if not 140x160 or 140x192 diff --git a/ksp/Makefile b/ksp/Makefile index fbc43d74..e1719998 100644 --- a/ksp/Makefile +++ b/ksp/Makefile @@ -1,12 +1,19 @@ PCX2HGR = ../hgr-utils/pcx2hgr DOS33 = ../dos33fs-utils/dos33 +TXT2BAS = ../asoft_basic-utils/tokenize_asoft all: ksp.dsk -ksp.dsk: LOADING.HGR SQUAD.HGR TITLE.HGR +basic: VAB.BAS + +VAB.BAS: vab.bas + $(TXT2BAS) < vab.bas > VAB.BAS + +ksp.dsk: LOADING.HGR SQUAD.HGR TITLE.HGR VAB.BAS $(DOS33) -y ksp.dsk SAVE B LOADING.HGR $(DOS33) -y ksp.dsk SAVE B SQUAD.HGR $(DOS33) -y ksp.dsk SAVE B TITLE.HGR + $(DOS33) -y ksp.dsk SAVE A VAB.BAS LOADING.HGR: loading.pcx diff --git a/ksp/c/Makefile b/ksp/c/Makefile index d418b9da..e7fe8cb7 100644 --- a/ksp/c/Makefile +++ b/ksp/c/Makefile @@ -2,7 +2,13 @@ CC = gcc CFLAGS = -Wall -O2 LFLAGS = -all: ksp_loading ksp_vab +all: ksp_launch ksp_loading ksp_vab + +ksp_launch: ksp_launch.o + $(CC) $(LFLAGS) -o ksp_launch ksp_launch.o + +ksp_launch.o: ksp_launch.c + $(CC) $(CFLAGS) -c ksp_launch.c ksp_loading: ksp_loading.o $(CC) $(LFLAGS) -o ksp_loading ksp_loading.o @@ -18,5 +24,5 @@ ksp_vab.o: ksp_vab.c clean: - rm -f *~ *.o ksp_loading ksp_vab + rm -f *~ *.o ksp_launch ksp_loading ksp_vab diff --git a/ksp/c/ksp_launch.c b/ksp/c/ksp_launch.c new file mode 100644 index 00000000..a328c573 --- /dev/null +++ b/ksp/c/ksp_launch.c @@ -0,0 +1,86 @@ +#include +#include + +/* http://wiki.kerbalspaceprogram.com/wiki/Tutorial:Advanced_Rocket_Design */ + +/* Also, high school physics (thanks Mr. Brennen) */ + + +/* TODO: want 2d-vectors at least */ + +int main(int argc, char **argv) { + + double capsule_mass=1.0; + + double engine_isp=270.0; /* s */ + double engine_mass=1.5; /* tons */ + double engine_thrust=168.0; /* kN */ + double fuel_flow_rate; + + double tank_mass=0.5; /* tons */ + double fuel_mass=4.0; /* tons */ + + double gravity=9.8; /* m/s^2 */ + + double rocket_velocity=0.0; /* m/s */ + double rocket_acceleration=0.0; /* m/s^2 */ + double rocket_altitude=0.0; /* m */ + + double deltav,twr; + double total_mass,empty_mass; + + double time=0.0; /* s */ + + total_mass=engine_mass+tank_mass+fuel_mass+capsule_mass; + empty_mass=total_mass-fuel_mass; + + deltav=engine_isp*gravity*log(total_mass/empty_mass); + + twr=engine_thrust/(total_mass*gravity); + + fuel_flow_rate=(engine_thrust)/(engine_isp*gravity); + + printf("DeltaV=%lf m/s\n",deltav); + printf("Thrust/weight=%lf\n",twr); + printf("Fuel flow rate=%lf, time=%lfs\n", + fuel_flow_rate,fuel_mass/fuel_flow_rate); + + for(time=0.0;time<500.0;time++) { + printf("Time: %lf\n",time); + printf("\tFuel left: %lf\n",fuel_mass); + if (fuel_mass<0.1) { + fuel_mass=0.0; + rocket_acceleration=-gravity; + rocket_velocity=rocket_velocity+rocket_acceleration*1.0; + rocket_altitude=rocket_altitude+ + (rocket_velocity*1.0)+ + 0.5*rocket_acceleration+1.0*1.0; + if (rocket_altitude<0.0) { + printf("CRASH!\n"); + break; + } + } + else { + rocket_acceleration=(engine_thrust/total_mass)-gravity; + rocket_velocity=rocket_velocity+rocket_acceleration*1.0; + rocket_altitude=rocket_altitude+ + (rocket_velocity*1.0)+ + 0.5*rocket_acceleration+1.0*1.0; + fuel_mass=fuel_mass-fuel_flow_rate; + total_mass=engine_mass+tank_mass+fuel_mass+capsule_mass; + } + printf("\tRocket acceleration: %lf g\n",rocket_acceleration/gravity); + printf("\tRocket velocity: %lf m/s\n",rocket_velocity); + printf("\tRocket altitude: %lf m\n",rocket_altitude); + } + + return 0; +} + +/* Notes */ + +/* Once altitude above 100m stop drawing ground */ +/* Once above 20k no more drag? */ +/* Once above 2100m/s sideways, orbit? */ +/* Once above 40k draw stars? */ +/* Kerbal neutral 0-1G, smiles 1-2G, frowns > 2G or -velocity? */ diff --git a/ksp/c/ksp_vab.c b/ksp/c/ksp_vab.c index f1798df0..e448e2f0 100644 --- a/ksp/c/ksp_vab.c +++ b/ksp/c/ksp_vab.c @@ -53,11 +53,11 @@ int main(int argc, char **argv) { printf("Available:\n"); printf("1. Jebediah\tPilot\tS ***\tC ***\n"); printf("2. Valentina\tPilot\tS ***\tC ***\n"); - printf("3. Kai\tEngineer\s ***\tC ***\n"); - printf("4. Kuroshin\tEngineer\s ***\tC ***\n"); - printf("5. Desktop\tScientist\s ***\tC ***\n"); - printf("6. Slashdot\tPilot\s ***\tC ***\n"); - printf("7. Zurgtroyd\tPilot\s ***\tC ***\n"); + printf("3. Kai\tEngineer\t ***\tC ***\n"); + printf("4. Kuroshin\tEngineer\t ***\tC ***\n"); + printf("5. Desktop\tScientist\t ***\tC ***\n"); + printf("6. Slashdot\tPilot\t ***\tC ***\n"); + printf("7. Zurgtroyd\tPilot\t ***\tC ***\n"); printf("Select three astronauts\n"); // highlight and say correct? diff --git a/ksp/ksp.dsk b/ksp/ksp.dsk index 989bef44ad3364f614a93141773697ab380f6415..880900eea9b3a314fa285c6d0f8eed792f82159a 100644 GIT binary patch delta 2446 zcmeHI-EY%Y6h9|U$i0sH!Q?ibgo80?YmqnEaT3y$2~u!N+BBtc00p6aX&=07L(^V1 zO-l=%_QEEO48pW8#2)s5iVD@_!4OhWkP6yH5HNMHsUU3=(lo>aAC*?duAQ{NhWG;} ztZU2XcYo*jckSP~9=u2fFOpGjyX}1%XSjljN0Un+NOc@ZE~zL3N_n5IX&SWBSQU|# zve{qJAwgGGfuvH-RU5_HL0~QO3(Xu>c{nnrbab5 zN`Lk547*V*4Byc!v(d5$oTt;X%yh3ixxBhDJi9~o|1dl>$r&Ex<86nOp? z^27&hUIUTv@MT;#qR>V}I21O*s@~q7U^j+p=wOl%45cd$VLYxcizeRdOdLw9or$e! z7$A$`!^Cba@o^Y7l2+KKGpWy#jW7uBkQZQ^Y^a(VXQ%F5SUt8DLyZ;;*h5}q(=3S1 zjz~nU4vn!Q8kEUPj1h^d(MWB~QH_}D4)~3{T;sSoZt-dL8N1KE2rn%zV&$9@5J+qa_6R^rUi;`>yyQqfk5$@ zW&6kKHcdC$J_~Pq#=Kk9J-!eEEH0f+V@I)(PvQ)#)@R>tL?Iw>4W2U-Cn{5CkDobP z9D1}#;6SSL{5XDW|FQ8i3<#o+u@96`!b6@Wu5?7gMV=6`rzE_97_`4#h^fbI@AF86 zQcE93gy#C@h9Cqn=m~Nx^J^Pl!$5QCgDpsG@gz>uQp>B1CV3^FG*9wN0ZFLR&LPLy z-U~?TY~fu*lS!5ArI+y+-!oaLEHn`4s!*Ry_jbXq}#}^N>#W#*E9_)%q#}y8xYKnqm zxqDnO<+ws)=GX5dUH)`Roax3 zmSy&Jrt@;=x>R~~D$}iiMl0|c^wXaiZB73Mxi6W?%T_MgZCWb|a;yG?(WZ33dU^?l zEqIRp4nwJmK5oHwdi7r!t9mW9nkg$CsSaf>xk#_Wa1OqpH^IuarrIhwn5163>v>)4 z%(R?KW_m4ot(kR-tm~f2B!3`?lP!Chp1%$81+GdlV z(2bKlu#j)Wk=!Z0?7-oeT7zT!BMuyPVb-TL_$j^_xAs5}AH;kmUvNrv!CQRG-D1s5 zcPeB4cdbfCu0wGo4)GEWoA5rr5Y3FUUK2j$6|8-*Jll9j`6W1FI-=M%>57U&nSac| zm?DO`isH-R2fob_G7*Dwyoy^>FwOscw-zgxU6->~IIr5-nKkF}5FnmmEB6)7M=Whg z2?eMT2?rjI=d!h8?Sqv#Y%2AHz0-PZF iMIus>7XzXo)`|6ELlZP%lc)OQ$)LCPW4VIYlK%h?X^E)- delta 574 zcmX|-PfQb05XRs4cDG&HSGGXgU5UH+=U`$u)aZp9YK-Az{CCnA4q6F;h(;0)M5qEc z(74JA!9x=jNG}?TK4}RNJQ$6YVqIv0M2^@X7g0H=bsM8I$z3(XOT+IZ0=x=NLbJ1vNY|kCtlUA!HU3A>@UJ z5#s41qBe(1)Pq4I9_zE=i|~iof)qZN)9EOk~``XVWmXK?jV7S`agd2%W>$g?0Q<)>#}x=QV`5< zSNOhjn3$rGN?97jL{9}iLsn8sdx_qcPpB!m;ioj*RQBX3yo^OOo#@c1F6lC7SO4vtfJ0VG~Gpb+( ZY*8V1K@GUGCHB6-isE*PU>n#x_y=*|!B diff --git a/ksp/ship.table b/ksp/ship.table new file mode 100644 index 00000000..23a980e0 --- /dev/null +++ b/ksp/ship.table @@ -0,0 +1,70 @@ +# Number of shapes +3 +# "Engine" +START +RT +DN +RT +DN +RT +DN +LT +LT +LT +LT +LT +LT +UP +RT +UP +RT +UP +RT +STOP +# "Fuel Tank" +START +NUP +NUP +NUP +RT +RT +RT +DN +DN +DN +DN +DN +DN +LT +LT +LT +LT +LT +LT +UP +UP +UP +UP +UP +UP +RT +RT +RT +STOP +# "Flame" +START +NUP +RT +RT +DN +LT +DN +LT +LT +UP +LT +UP +RT +RT +STOP + diff --git a/ksp/ship_test.bas b/ksp/ship_test.bas new file mode 100644 index 00000000..165e6311 --- /dev/null +++ b/ksp/ship_test.bas @@ -0,0 +1,34 @@ + 5 EO = 0 + 10 HIMEM: 8135 + 20 POKE 232,199: POKE 233,31 + 30 FOR L = 8135 TO 8175: READ B: POKE L,B: NEXT L + 35 HGR : ROT= 0: SCALE= 2 + 40 GOTO 150 + 90 END + 100 DATA 3,0,8,0,18,0,33,0,53,53 + 101 DATA 53,63,63,63,44,44,44,0,0,40 + 102 DATA 45,54,54,54,63,63,63,36,36,36 + 103 DATA 45,5,0,40,53,55,63,60,44,5 + 104 DATA 0 + 150 GOSUB 2000 + 200 REM + 300 GET A$ + 305 IF A$ = "Q" THEN GOTO 1000 + 310 IF A$ = " " THEN EO = 1 + 320 IF A$ = "A" THEN R = R - 8 + 325 IF A$ = "D" THEN R = R + 8 + 330 IF R < 0 THEN R = 56 + 335 IF R > 63 THEN R = 0 + 337 GOSUB 2000 + 340 ROT= R + 800 GOSUB 2000 + 900 GOTO 200 +1000 END +2000 REM DRAW SHIP +2010 XDRAW 1 AT 140,50 +2020 XDRAW 2 AT 140,62 +2030 XDRAW 2 AT 140,74 +2040 XDRAW 1 AT 140,86 +2050 HCOLOR= 5 +2060 IF EO = 1 THEN DRAW 3 AT 140,92 +2070 RETURN diff --git a/ksp/vab.bas b/ksp/vab.bas new file mode 100644 index 00000000..b0b02635 --- /dev/null +++ b/ksp/vab.bas @@ -0,0 +1,42 @@ + 10 HIMEM: 8135 + 20 POKE 232,199: POKE 233,31 + 30 FOR L = 8135 TO 8175: READ B: POKE L,B: NEXT L + 35 HGR : ROT= 0: SCALE= 2 + 40 GOTO 150 + 90 END + 100 DATA 3,0,8,0,18,0,33,0,53,53 + 101 DATA 53,63,63,63,44,44,44,0,0,40 + 102 DATA 45,54,54,54,63,63,63,36,36,36 + 103 DATA 45,5,0,40,53,55,63,60,44,5 + 104 DATA 0 + 150 XDRAW 1 AT 140,20 + 155 Y=18 + 200 HOME + 205 INVERSE : VTAB 21: HTAB 8 + 207 PRINT "VEHICLE ASSEMBLY BUILDING" + 208 NORMAL + 220 PRINT "HOW MANY STAGES? (1-3)"; + 225 INPUT S + 230 FOR I = 1 TO S + 240 PRINT "HOW MANY STACKS, STAGE ";I;" (1-3)"; + 245 INPUT T + 247 ST(I) = T + 260 PRINT "HOW MANY FUEL TANKS PER STACK, STAGE ";I;" (1-2)"; + 265 INPUT F + 267 FT(I) = F + 268 FOR J = 1 TO F + 270 XDRAW 2 AT 140, Y+13*J + 272 IF T >1 THEN XDRAW 2 AT 126, Y+13*J + 274 IF T >2 THEN XDRAW 2 AT 154, Y+13*J + 278 NEXT J + 279 Y=Y+13*F + 280 PRINT "HOW MANY ENGINES, STAGE ";I;" (1-";T;")"; + 285 INPUT E + 287 EN(I) = E + 290 XDRAW 1 AT 140, Y+8 + 292 IF E >1 THEN XDRAW 1 AT 126, Y+8 + 294 IF E >2 THEN XDRAW 1 AT 154, Y+8 + 297 Y=Y+6 + 300 NEXT I + 510 PRINT "HOW MANY STRUTS? (1-20000)"; + 520 INPUT ST