Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corruption of ESP in 16 bit Real Mode DOS programs #147

Open
EmoticonSmile opened this issue Oct 24, 2024 · 1 comment
Open

Corruption of ESP in 16 bit Real Mode DOS programs #147

EmoticonSmile opened this issue Oct 24, 2024 · 1 comment

Comments

@EmoticonSmile
Copy link

EmoticonSmile commented Oct 24, 2024

Some 16-bit Real Mode DOS programs use the upper portion of ESP as standby stack pointer for an alternative stack, specifically for graphics operations. However, SBEMU does not account for this and inadvertently corrupts the upper part of ESP.

ror esp,16 ; invoke graphic stack

; some graphic stuff, for example blit a sprite row
lodsw ; word from ds:[si] into ax, increment si by 2
ror eax,cl ; rotate eax right by x-pos mod 8 to adjust output
or es:[di],ah ; 1st byte to vmem
push di ; save di to clearstack
inc di
or es:[di],al ; 2nd byte to vmem
push di ; save di to clearstack
inc di
shr eax,16 ; overflow from the rotation to ah (side effect: clears upper 16 bits of eax)
or es:[di],ah ; 3rd byte to vmem
push di ; save di to clearstack

ror esp,16 ; restore standard sp and save clrscr stack pointer in upper 16 bit of esp

After a few seconds, programs that utilize this method freeze.

@EmoticonSmile EmoticonSmile changed the title Corruption of ESP in 16 bit Real Mode DOS Programs Corruption of ESP in 16 bit Real Mode DOS programs Oct 24, 2024
@volkertb
Copy link
Collaborator

Wow, well debugged. Think you could help with creating a PR for this? Or at least some pointers for those reading here who are knowledgeable to have a go at fixing this? Thanks! 🙏🏾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants