Dotneteer / spectnetide

ZX Spectrum IDE with Visual Studio 2017 and 2019 integration
MIT License
206 stars 27 forks source link

Disp pragma and Relative jump #196

Closed neicv closed 4 years ago

neicv commented 4 years ago

.disp pragma not working as expected.

  1. Some block: .org #8000 .disp #1000 Some CODE

2. Some block: .org #8000 Some CODE .disp #1000

But anyway: Disp pragma and Relative jump not work correctly. Error Z0022: Relative jump distance should be between -128 and 127. -65500

disp3

Dotneteer commented 4 years ago

@neicv, Thanks for signing this issue! I will investigate it soon :-)

Dotneteer commented 4 years ago

Evgeny, thanks again for submitting these issues. I managed to find and fix them. Here I send you a private build so that you can test them. Please, rename the .vsix file to .zip.

Spect.Net.VsPackage.zip

Please, let me know how the fix works! Of course, if you find other bugs, or just have questions about SpectNetIDE, feel free to nofify me.

I plan to release these fixes in Preview 9.

Here is the summary about the fix:

Issue 1: the .disp pragma

The compiler works exactly as described in the specification. However, the Run program, Debug program, and Inject code commands filled the code into a wrong address.

According to the compiler specification the ORG pragma defines the address to place the code. Even if you set the DISP pragma, the code is to be loaded into the segment specified by ORG. The DISP pragma defines a displacement for the code address translation. It assumes that you use the displacement to move the code in the memory during runtime.

However, the code injector was faulty: it injected the code to the ORG+DISP address (as your screenshots indicated).

Here are the screenshoots that show the fixed state.

The original state without DISP compiles and injects as you expect:

devenv_8Osls831NS

When you add the DISP pragma right after the ORG #8040, from that point, all addresses are displaced with -#0020 bytes:

devenv_AHTSXTkBTA

When you place the .disp -#0020 pragma to the end of the code, it starts address displacement from that point on — however, you have no more code, so it has no effect:

devenv_KmOeB9thCi

Issue 2: the jr statement:

There was an issue in the compiler that made a wrong (signed) conversion of a displacement instead of an unsigned conversion. Now, it works properly.

neicv commented 4 years ago

Istvan, thx for answer! After fix: disp work fine!

But "jr" - not (сorrect me if I'm wrong, but before applying the directive .disp, the code must not be touched by it ?)

jr2

Dotneteer commented 4 years ago

Evgeny, you're right. Let me fix this error!

Dotneteer commented 4 years ago

Evgeny, here is the fix for the JR + DISP issue:

Spect.Net.VsPackage.zip

neicv commented 4 years ago

Hellou Istvan! Now work correctly thanks for fix it!

And thank you very much for your work!

Dotneteer commented 4 years ago

Evgeny, this is the strength of the community :-). Many issues and bugs in SpectNetIDE were fixed with the help of community members eager like you!

If you're happy with SpectNetIDE, please, star the project on Github.

I will close this issue when Preview 9 is released.

Dotneteer commented 4 years ago

Released in v2 Preview 9.