Speed issues on Hardware

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andrew Davie

Going to dedicate this thread to trying to get the main game running without time overflow on hardware. Although I have "fabulous" timing calculations based on ARM cycles/line... it still overflows.

So this version is the first "quick and dirty test". I simply multiply the available cycles by 7/8ths. It runs OK on the emulators; hopefully someone can test on hardware for me.


Andrew Davie

#1
Whoops -- must post 120K versions for hardware testing.
Here 'tis...

SpiceWare

#2
Here you go - at least the skull is stable.

@JetSetIlly - I thought your Starpath Supercharger Demo video was neat with the TV, though something felt off that I couldn't place at the time.  Figured it out after watching this video: the bezel around your simulated CRT doesn't have the changing light reflections that are seen on a real display.


JetSetIlly

#3
I have tried to add bevel reflections but the experiment wasn't entirely successful.

It's more visible on some ROMs than others. California games and the ATeam game both demonstrate it to a certain extent. Most ROMs have no effect at all.

These videos are rubbish but it gives you an idea of where to look



My method is all wrong for it to be truly successful. Currently, I treat the rim of the screen separately to the reset of the image, and change the colour of the highlights according to what's on the screen.

It's slightly more visible if you turn on the "blue ambient light option" but it's still poor compared to what it could be.


But you're right, it's something that's missing. I'll go back to it one day if I have an idea about how to do it better.
https://github.com/JetSetIlly/Gopher2600
@JetSetIlly@mastodon.gamedev.place
@jetsetilly.bsky.social

Andrew Davie

Quote from: SpiceWare on 10 Jul 2026, 04:26 AMHere you go - at least the skull is stable.

Thanks for testing.  The skull uses a different kernel - and in any case doesn't try to push used cycles to the max.  Something is strange, though. I might go back to first principles and set a timer and actually display the # cycles per frame, and back-calculate from that. At the moment I'm using INTIM to tell me how many scanlines are unused in VB/OS and multiplying that by ARM cycles/line and then reducing a little bit. It should work, so I'm rather mystified.

I guess the first thing to really check is that the VBLANK is "well-formed" -- that might be as simple as doing *nothing* during the kernel and just seeing if the blank-ish screen is stable. At the moment I'm in the dark. We'll get there.


Andrew Davie

This version:  only uses up to 10,000 cycles of ARM time in VB/OS.

Normally there should be over 100,000 -- this version will be extremely intermittent in movement/gameplay, having just 10% or so of the CPU it needs. Everything is still running/active, though -- so it's an interesting test.

I'm just trying to confirm here that the issue is VB/OS running overtime.

Expected outcome:  stable.

JetSetIlly

#6
After a review of Gopher2600's ARM code, I've made a small correction to the MAM implementation. It will almost certainly make a difference to accuracy but it doesn't appear to fix these specific ROMs when compared to the hardware.

The MAM latches addresses in 128bit blocks. I had mistakenly set it to 128byte blocks. In practice that meant things like loops could be up to 32 instructions long as opposed to the correct four instructions long.

It's not a silver bullet but the new code is more correct. Code on github
https://github.com/JetSetIlly/Gopher2600
@JetSetIlly@mastodon.gamedev.place
@jetsetilly.bsky.social

Bomberman94

Quote from: Andrew Davie on 10 Jul 2026, 01:19 PMThis version:  only uses up to 10,000 cycles of ARM time in VB/OS.

Normally there should be over 100,000 -- this version will be extremely intermittent in movement/gameplay, having just 10% or so of the CPU it needs. Everything is still running/active, though -- so it's an interesting test.

I'm just trying to confirm here that the issue is VB/OS running overtime.

Expected outcome:  stable.

... almost stable: in general gameplay is fine with no screen jump but in some situations the screen jumps a bit: digging a rock and in the moment it turns into dust or a gem & when the worm runs over the screen and you do something in parallel (but not everytime!). Here's a screenshot and hey, it is great fun to play this!



SpiceWare

Quote from: Andrew Davie on 10 Jul 2026, 01:19 PMThis version:  only uses up to 10,000 cycles of ARM time in VB/OS.

Much better, only occasional screen jumps.

Quote from: JetSetIlly on 10 Jul 2026, 04:52 AMI have tried to add bevel reflections but the experiment wasn't entirely successful.

Color of the bezel could also be a factor, the lighter bezel of my C= 1084S might make it more obvious than a black bezel.

Andrew Davie

Thanks to those who have tested and provided feedback.

I'm now back at 75K cycles budgeted for OS/VB.

With the update from @JetSetIlly I was able to see time overflows happening, and tracked down at least one likely culprit. Also pointed to by @Bomberman94 regarding time overflows when mining the rocks.

The culprit at least for this particular time overflow was the generation of the particles when you hit a rock. The particle array is currently 42 entries. When inserting a particle, the code did a scan of the array to find a blank slot, and failing that the oldest particle to replace. That code was expensive - maxing out at 25,000 cyles worst-case. Yeah.  It happened when there were lots of particles already there, and lots more being generated. Every one of those generated ones would scan the list.

I replaced it - there's now a stack of available particles. We get one off the stack, and put old ones back on the stack. There's no scan. This means that we no longer kill off particles which are the oldest to guarantee a new one can be added -- but it doesn't seem to make a lot of difference.  The add particle function has now dropped off the profiler - negligible cost.

So, here's a binary with that fix added (and, the 75K cycle budget).  It doesn't overflow on Gopher -- I expect there will still be significant hardware issues on this one, but it's nice to find at least that problem.


SpiceWare

Quote from: Andrew Davie on 11 Jul 2026, 03:52 AMI expect there will still be significant hardware issues on this one

Yep.

JetSetIlly

You should probably increase the cycle regulator in Gopher2600 so that it starts to have problems. (image attached) If you solve the program for that configuration, there's a better chance it'll be okay on the hardware.


https://github.com/JetSetIlly/Gopher2600
@JetSetIlly@mastodon.gamedev.place
@jetsetilly.bsky.social

JetSetIlly

A good thing to add to these test binaries would be debugging information about the state of the MAMCR register

#define MAMCR *(unsigned char*)0xE01FC000

I would want to be sure the hardware is the same as the emulation. I would add something like

switch (MAMCR) {
case 0:
  // put a "0" on the screen
case 1:
  // put a "1" on the screen
case 2:
  // put a "2" on the screen
}

https://github.com/JetSetIlly/Gopher2600
@JetSetIlly@mastodon.gamedev.place
@jetsetilly.bsky.social

Andrew Davie

Quote from: JetSetIlly on 11 Jul 2026, 04:24 AMYou should probably increase the cycle regulator in Gopher2600 so that it starts to have problems. (image attached) If you solve the program for that configuration, there's a better chance it'll be okay on the hardware.

1.40 was a tough ask which I couldn't get working.
I do, however, have a working version at 1.25. It required a "radical" redesign by splitting the screen draw over OS and VB instead of doing it all in one go in OS.
It also means there must be waaaay less cycles than I expected. Which doesn't make sense to me.
In any case, the attached is the result and it will be good to get feedback.
It runs a bit slow.


Andrew Davie

Quote from: JetSetIlly on 11 Jul 2026, 04:43 AMA good thing to add to these test binaries would be debugging information about the state of the MAMCR register

The attached version displays "MAM n", where n is the contents of that register.