Space Harrier 2 (slightly faster edition)

Code & Logic Involvement

Debugging / Optimization only (Human wrote, AI analyzed/fixed)

Assets & Pipeline Involvement

None (Code-only or pure human assets)

Project Notes & Prompts

Space Harrier 2.
Claude has made it faster, but still not great unfortunately.

space_harrier_2_fast.dsk (195 KB)

5 Likes

Nice, thank you! It must mean the code was already optimized, altough I had a quick look and spotted a few misses.
At offset 2981, there is a call &0836:ret which could be replaced with a jp &0836.
A few lines below, at offset 2992 we see : ld de ,&9C00:add hl,de. There is obviously no point at adding 0 to the register L ! So better use : ld a,h:add &9C:ld h,a which avoids 16 bit overheads. Unless it’s self-modifying code of course, but it doesn’t seem to be the case here.
I wonder if your models are correctly trained for optimization, but I confess i’m ignorant with all this.

1 Like

Thanks!

I will pass that info to Claude and see what it says.

[EDIT] Yes it agrees, but said the following:

Both are right; they would just save about 7 µs per game loop at most, which is too small to see.

  • #2981, call #0836 : ret → jp #0836: saves 5 µs (call 5 + ret 3 against jp 3). This tail only runs for the original copy, which during play is now only the occasional full copy; menus, title and transitions still use it. My game-loop copy already ends with jp music.
  • #2992, ld de,#9C00 : add hl,de → ld a,h : add a,#9C : ld h,a: saves 2 µs (6 against 4). It’s safe: the low byte added is 0, so there’s never a carry out of L. A is free at that point, because the next instructions reload it with ld a,(#316B), and it isn’t self-modified. This is the original clear’s address calculation, which only runs on non-game-loop clears; my game-loop clear gets the address from the #E600 line table instead.

Against a game loop of about 80–95 ms, that’s under 0.01%. The game is full of patterns like these; they mostly sit outside the routines that cost frames.

1 Like

Yeah, I had put a breakpoint at 2981, and it’s called only when the player is hit, but it’s called many times, and it is code from the game loop. Tell this Claude guy he must do better :winking_face_with_tongue:

LOL yes, but in my opinion Claude is getting too good at this.

The game I’m working on is being written the old-fashioned way, but optimising old games is beyond my skill level, and it’s a bit of fun using Claude to do it. :slight_smile:

1 Like

Haha loved that :smiley:

1 Like