Commit 082af88
committed
fix(trek): integer decode for quadrant K/B/S counts (fixed-point hang)
EnterQuadrant decoded the packed quadrant code with float tricks:
K3=int(G*.01) : B3=int(G*.1)-10*K3 : S3=G-100*K3-10*B3
Fine under the float interpreter, fatal when transpiled to cc65 fixed-point:
16.16 RGC_MUL mangles .01/.1 (keeps ~2 fractional bits) and G/100 overflows
the 32-bit fixed range for G>=256, so K3 undercounts and S3 = G-100*K3-...
OVERcounts. FindEmpty() (retry-until-empty-sector) then tries to place more
stars than the 64-sector quadrant holds and spins forever — trek hung right
after the mission briefing on a real C64.
Decode with integer \ and MOD instead (G encodes K*100+B*10+S):
K3=G\100 : B3=(G\10) MOD 10 : S3=G MOD 10
Exact, no overflow, cheap — and behaviour-identical in the interpreter.
Lesson: integer logic wants integer ops, not float arithmetic, on 8-bit.1 parent a9ceae8 commit 082af88
1 file changed
Lines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
210 | 214 | | |
211 | 215 | | |
212 | 216 | | |
| |||
0 commit comments