Discussion
Loading...

Post

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Greg
Greg
@greg@icosahedron.website  ·  activity timestamp 6 months ago

Lately I've been working on trying to add some speed / performance hacks to #DOSBox. The idea is a bit similar to the old DOSIDLE.EXE / POWER.EXE TSRs: detect when the system is idle or busy-looping, and give up the rest of the CPU cycles until something interesting happens (next frame, next BIOS tick, whatever).

There are a bunch of timing sources on the IBM PC and it's tricky to get them all, but as a proof of concept - here's the delay loop from GORILLA.BAS:

'Rest:
' pauses the program
SUB Rest (t#)
s# = TIMER
t2# = MachSpeed * t# / SPEEDCONST
DO
LOOP UNTIL TIMER - s# > t2#
END SUB

So, it busy-loops until the timer tick. In DOSBox I modified the BIOS INT 1A handler so that if the emulated machine requests the time twice and the same tick comes up, it's probably spinning, so I take away all the remaining cycle budget and sleep instead. And it actually works! Host CPU usage drops significantly - or, if you put it in Turbo Mode, the game plays WAY faster!

Your browser does not support the video tag.
This video cannot be previewed
Open original
Recording of GORILLA,BAS in DOSBox with a debug window visible. Any time the game does a delay (e.g. banana flying through the air), the debug window shows the timing hack dumping all remaining cycles. Cycle budget is 3000 and sometimes it's saving 80-90% of that just by bailing out early.
  • Copy link
  • Flag this post
  • Block

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.1 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct