kervinck / gigatron-rom

System, apps and tooling for the Gigatron TTL microcomputer
BSD 2-Clause "Simplified" License
229 stars 79 forks source link

Sound improvements for Racer #241

Closed lb3361 closed 1 year ago

lb3361 commented 1 year ago

These changes correspond to the Racerx_final.gt1 of https://forum.gigatron.io/viewtopic.php?p=3457#p3457. This standalone file suitable for ROMv5a and current DEVROM was produced using hacks provided in Racerx.diff. Maybe we should delete this file which is now useless. Following Marcel's demand that versioned source files never change, the patch does not modify Racer_vX.gcl but introduces a new one named Racer.gcl. Here is the full diff between these two files:

--- Racer_v2.gcl    2022-10-14 13:20:56.473337210 -0400
+++ Racer.gcl   2022-11-03 06:06:45.091475482 -0400
@@ -21,7 +21,6 @@
 XXX Move car forward when going faster
 XXX Finish line?
 XXX Background music score?
-XXX Crash sound effect?
 XXX Sprite acceleration?
 XXX Image compression?

@@ -66,7 +65,7 @@
 ] QPrintChar=

 { ControlRaceCar }
-[def
+[def _ControlRaceCar=*
   {Update time with actual elapsed frames}
   \frameCount, LastFrame- 255& \sysArgs7. Time+ [if<0 $7fff] Time=
   \frameCount, LastFrame=
@@ -83,15 +82,17 @@
   \buttonState, \buttonLeft&  [if=0 -$200 CarX+ CarX= -1 Steer=]

   {Speed control}
-  \buttonState, \buttonA& [if=0 {Accelerating}
+  { \buttonA | \buttonUp == 136 }
+  \buttonState, 136& 136^ [if<>0 {Accelerating}
     Speed $10+ Speed= {At 15 fps $10 means ~1s to reach the next speed level}
     $5ff Speed- [if<0 $5ff Speed=]
    else
-    -$108 Speed+ [if>=0 Speed 8- Speed=] {Slowly drop to very low speed}
+    Speed $40- [if>=0 Speed 8- Speed=] {Slowly drop to a halt}
   ]
-  \buttonState, \buttonB& [if=0 Speed $40- [if<0 0] Speed=] {Braking}
+  { \buttonB | \buttonDown == 68 }
+  \buttonState, 68& 68^ [if<>0 Speed $40- [if<=0 0] Speed=] {Braking}
   ret
-] ControlRaceCar=
+]

 {-----------------------------------------------------------------------+
@@ -156,19 +157,18 @@

 { PlayEngineSound }
 [def
-
-  {High key is Speed[7:14]}
-  $01fd {keyH} p= Speed Speed+ \vACH,
-  p. >p++ p. >p++ p. >p++ p. {Sound channel 1-4}
-
-  {Low key is Speed[0:6]}
-  $01fc {keyL} p= Speed 127&
-  p. >p++ p. >p++ p. >p++ p. {Sound channel 1-4}
-
-  10 \soundTimer. {Keep sound on a bit longer}
-
+_PlayEngineSound=*
+  push \SetEngineSoundMod! pop
+  \SYS_LSRW1_48 _sysFn=   
+  $1fc p= <Speed, 48!! p. {keyL=Speed[1:7]}
+  <p++ >Speed, p.         {KeyH=Speed[8:15]}
+
+_CopyChannel0=*
+  $1fa p= p; >p++ p: >p++ p: >p++ 255& p: { channel 3 always noise }
+  $1fc p= p; >p++ p: >p++ p: >p++ p:
+  10 \soundTimer.
   ret
-] PlayEngineSound=
+]

 {-----------------------------------------------------------------------+
 |}>_vLR++ ret{          RAM page 4                                      |
@@ -285,7 +285,7 @@
 ] PrintText=

 { DrawRoad }
-[def
+[def _DrawRoad=*
   $74d0 p=                      {array[48], in display memory but out of view}
   0 X=
   DX0 DX=
@@ -349,7 +349,17 @@
   tmp X- s.

   ret
-] DrawRoad=
+]
+
+[def _SetEngineSoundMod=*
+  $1fa p=
+  \buttonState, 136& 136^
+  [if<>0 $250 else $70] p:
+  ret
+]
+
+
+

 {-----------------------------------------------------------------------+
 |}>_vLR++ ret{          RAM page 6                                      |
@@ -393,16 +403,16 @@
     ]

     {Draw bending of the road}
-    DrawRoad!
+    \DrawRoad!

     {Drift and horizon movement}
     DDX 3<< HorizonDX= 1<< DriftX=

     {Car "physics" and driver input}
-    ControlRaceCar!
+    \ControlRaceCar!

     {Update pitch of engine sound}
-    PlayEngineSound!
+    \PlayEngineSound!

     {Draw race car}
     DrawRaceCar!
@@ -411,7 +421,7 @@
     DrawGrass!

     {Force end of game after 5m00s}
-    -17995 Time+ [if>0 Collision=]
+    -17995 Time+ [if>0 pop ret]

     {Draw current time}
     Time Value= $801 Pos= 63 Color= PrintTime!
@@ -428,6 +438,7 @@
 [def #3             #40 #20 #20 #63 #63 #20 #20 #40             #0] Car1=
 [def #2         #40 #20 #20 #20 #40 #40 #20 #20 #20 #40         #0] Car2=

+
 {-----------------------------------------------------------------------+
 |}$08a0 \vLR: ret{      RAM page 8                                      |
 +-----------------------------------------------------------------------}
@@ -496,6 +507,17 @@
   ret
 ] AdvanceCar=

+[def _PlayCrashSound=*
+  push
+  1 Delay=
+  64 [do i= \PlayCrashSoundHelper!
+         \CopyChannel0! Wait!
+         i 2- if<>0loop]
+  0 \soundTimer.
+  pop ret
+]
+
+
 {-----------------------------------------------------------------------+
 |}>_vLR++ ret{          RAM page 10                                     |
 +-----------------------------------------------------------------------}
@@ -513,8 +535,17 @@
   Car3 Sprite= DrawPixels!
   Car4 Sprite= DrawPixels!
   pop ret
+
+_PlayCrashSoundHelper=*
+  {This is here because there was space}
+  $1fc p= $17f _entropy& p:
+  $1fa p= 63 i- [if<0 0] 64+ p: 
+  ret
+
 ] DrawRaceCar=

+
+
 {-----------------------------------------------------------------------+
 |}>_vLR++ ret{          RAM page 12                                     |
 +-----------------------------------------------------------------------}
@@ -582,9 +613,10 @@
     `GAME`OVER #0 {GAME OVER}
   ] PrintText!

-  $111 s=
-  $20+ t=
   1 Delay=
+  Collision [if<>0 \PlayCrashSound!]
+
+  $111 s= $20+ t=
   s, 128& [if=0 +1 else -1] i= {Scroll direction}
   [do Wait!
     t, i- t.
@@ -635,7 +667,7 @@

   $7fff BestTime=
   0 Time= Value= HorizonX= DriftX= Speed=
-  Random= DX0= DDX= NextDDX= DrawRoad!
+  Random= DX0= DDX= NextDDX= \DrawRoad!
   DrawGrass!
   SetupHorizon!
   $1435 Pos=