maziac / DeZog

Visual Studio Code Debugger for Z80/ZX Spectrum.
MIT License
215 stars 34 forks source link

Internal debugger for ZX81 developments #128

Open stevexyz opened 1 month ago

stevexyz commented 1 month ago

Recently I was trying to come back to some ZX81 development, but discovered that for some reason current version of Zesarux is not working with DeZog. Unfortunately for ZX81 seems there are no other compatibilities, and I was wondering if it would be possible to extend the internal debugger to support also this machine. I think it would also greatly simplify the setup of the development environment needing just VSCode and Dezog, and even without init files if you find a ".p" file with the same name as ".asm" everything could be setup automatically (looking also for sld etc).

andrivet commented 1 month ago

There is a fork with what you need. This is explained in the Readme of DeZog: https://github.com/maziac/DeZog#fork (i am the author of the fork)

maziac commented 1 month ago

Yes, please try the fork and see if it fits your needs. I was also thinking of adding zx81 in the future, but with that fork I think there is little need for it...

andrivet commented 1 month ago

I was also thinking of making my fork more compatible with DeZog but I am not sure it is worth the effort. So many ideas, so many projects and not enough time.

stevexyz commented 1 month ago

WOW, this is the way!! The main limitation I see is related to the assembler, unfortunately way too simple for anything more than very basic programs, and surely very much underpowered for my needs (e.g. I’m trying to create a new version of the 1K Real Chess for ZX81). Without reimplementing things (standard undocumented instructions, powerful directives, etc), would it be possible to integrate a more powerful ready one as for example sjasmplus (https://github.com/z00m128/sjasmplus) or fasm/fasmg (https://github.com/jacobly0/fasmg-z80)?

andrivet commented 1 month ago

Post your question in the fork repository if it relates to the fork.

andrivet commented 1 month ago

I have backported my code for the ZX81 into the latest version of DeZog and submitted a PR. It does not use my own Z80 assembler but an external one so this should solve your problems @stevexyz . I do not know when Maziac will have the time to review the PR so in the meantime, you can use my (second) fork: https://github.com/andrivet/DeZog/tree/zx81-publish. I have published a VSIX under Releases.

maziac commented 1 month ago

Hi, thanks very much for the back port. I very much appreciate your work. As I already mentioned it will probably take some time until I can re-use your work. Here is my current plan for a "roadmap" just to give you an idea:

  1. dezog 3.4.0 (zxndma): in 1 week
  2. some other project: Time = ?
  3. dezog 3.5.0: zsimremote re-factored as web view: 2 months
  4. dezog 3.6.0: zx81 integration

My thoughts so far: The zsim is a z80 simulator. I.e. the ZX Spectrum additions are just additional HW simulations that can be enabled one by one. If you put the right "HW" together you get the ZX Spectrum (i.e. ula + keyboard + zxbeeper mainly). I would like to keep it the same for the zx81. I.e. rather than having a separate "zx81sim" I will try to set this inside the current "zsim". Maybe I'll add something like a "collection" (inside "zsim") where you can just type "zx81" or "zxspectrum" and it enables the defaults with the right HW for you.

maziac commented 3 weeks ago

I changed my plans/schedule and directly started with the zx81 development for dezog. Please check this release candidate dezog-3.5.0-rc1.vsix.zip The internal simulator (zsim) has been improved by zx81 features. Changes are:

Bildschirmfoto 2024-08-20 um 17 22 26

maziac commented 3 weeks ago

Here is the updated documentation: https://github.com/maziac/DeZog/blob/zx81/documentation/Usage.md https://github.com/maziac/DeZog/blob/zx81/documentation/Migration.md

For a zx81 project you could use the following launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "dezog",
            "request": "launch",
            "name": "zsim - ZX81-16K",
            "remoteType": "zsim",
            "zsim": {
                "preset": "zx81"
            },
            "commandsAfterLaunch": [],
            "history": {
                "reverseDebugInstructionCount": 1000000,
                "spotCount": 10,
                "codeCoverageEnabled": true
            },
            "startAutomatically": false,
            "rootFolder": "${workspaceFolder}",
            "load": "Mazogs.p81",
        }
         ]
}
andrivet commented 2 weeks ago

Very nice work. A few remarks:

ZX81_keyboard

maziac commented 2 weeks ago

"The frequency for the ZX81 is wrong, it should be 3.25 MHz, not 3.5." Good hint, will change it.

"The image of the keyboard is blurry (low resolution). I have recreated the keyboard in a vector format. I put a version below in SVG." That is great. If you put that in MIT license (or any free Common license) I would be happy to use it (of course with a credit).

" I can try to do the same for the ZX Spectrum if you find this useful." Yes, same for this. An SVG image would be great.

maziac commented 2 weeks ago

I'm adding a "zx81-hires" simulation for the "ulaScreen". It is working (the zx81 branch) but it does flicker a little bit. Especially the (ula) line counter seems to be off by 1 or 2, but not constant. Do you have any idea what could be wrong with the simulation (Zx81UlaHiscreen)? I must be missing some detail...

andrivet commented 2 weeks ago

Here is the ZX Spectrum keyboard in SVG.

48k_kbd

Both (ZX81 and ZX Spectrum keyboards SVG) are under CC BY-SA 4.0

For Zx81UlaHiscreen, I will look at it when I get some time.

maziac commented 2 weeks ago

The keyboard looks great!

"For Zx81UlaHiscreen, I will look at it when I get some time." I looked into the implementation of zxsp. Probably the timing is not as accurate as required. I will try to use the zxsp implementation.

maziac commented 2 weeks ago

Please check this commit for adding the keyboard files and the attribution: https://github.com/maziac/DeZog/commit/003bb1b57bf05fb0e5aca74acbce6516c15e0996

andrivet commented 2 weeks ago

👍 perfect, thanks

maziac commented 2 weeks ago

I was just thinking: The keypress boxes are now not aligned anymore with the svg. Is there a way that I could directly use some svg id of the keys to get the size and draw the button press highlight with the size of the svg element. Not sure how to do that or integrate it with the html/js... Maybe it is also possible to add the 'onClick' directly to the svg. Would be more straightforward then to overlay it with html elements for the key presses.

andrivet commented 2 weeks ago

I don’t think it is possible. What I can do is to modify the SVG to place keys exactly where they where in the PNG.

maziac commented 2 weeks ago

You don't have to. I probably have to adjust just a few offsets.

andrivet commented 2 weeks ago

And why not adding the QL like Spectrum keyboard, and the ZX80 one! Half joking…. One day, i am a little busy these days.

maziac commented 2 weeks ago

Could you please have a look. Seems the newline key is a little bit off the right margin. Bildschirmfoto 2024-08-27 um 22 08 46 I have changed the css so that it displays a red border around the available space.

ped7g commented 2 weeks ago

How about source level debug (SLD) data? I have on sjasmplus open issue #232 about what virtual device to use for zx80/81, and I'm not deeply familiar with these machines, but it still feels to me like classic ZXSPECTRUM48 should cover this use case too?

Maziac: I guess you will test DeZog with SLD for the ZX81? Let me know in case you are missing anything on sjasmplus side, and if you have some recommendation which sj virtual device to use for ZX80/81, so I close this thing and put it off my mind. :) TY.

andrivet commented 2 weeks ago

@ped7g use NOSLOT64K, it works for the ZX81

maziac commented 2 weeks ago

Yes, agree.

andrivet commented 2 weeks ago

This should be better: ZX81_keyboard

I can do the same for the Spectrum if you need it.

maziac commented 1 week ago

Everything fine, thanks. Both keyboards work now.

andrivet commented 1 week ago

I see you have solved the flickering in HiRes mode. I played with it a little (with PacMan in Pseudo HiRes for example), it works nicely.

maziac commented 1 week ago

Flickering is almost solved, but there is still a little bit remaining in Battlestar Galactica. Ist's non-hires, but if you play that with either hires or normal, there is sometimes still a little flicker.

maziac commented 1 week ago

I have analyzed this a bit. After starting Galactica there is sometimes a little flickering when the 2nd or 3rd screen is created. The screen is a dfile in collapsed format although this is using 16k or more. Bildschirmfoto 2024-09-02 um 18 39 59 I'm not sure how this can happen. Maybe I'm initializing something wrong.

For a collapsed dfile I would think that some flickering is OK, because to extend a line there is some copying within the dfile required. But the question is: why is the dfile collapsed?

maziac commented 1 week ago

OK, found it. It was hack I did for one game. Removed it and no flickering anymore.

maziac commented 1 week ago

I would like to simulate the memory mirroring as well. But I have not found any good documentation. Do you know what is mirrored? I think the ROM is mirrored at 0x2000, anything else?

andrivet commented 1 week ago

This is highly dependent on the RAMPack that is installed. A ZX81 with a classical 16K RAMPack mirrors the ROM at 0x2000, and the RAM (0x4000, 0x5FFF) at 0x8000.

Some RAMpacks are decoding the 0x2000-0x3FFF space to add 8K of RAM. Some are also decoding higher addresses. to add even more RAM (data only). Some (64K RAMpacks) are even doing bank switching and allow replacing (after booting) the ROM by RAM. Here is for example the Manual of such (complex) RAMPack: https://archive.org/details/byte-back/Byte-Back%20UM-64%20manual/mode/2up

The number of variants is huge (see for example https://www.timexsinclair.com/blog/ram-packs-and-memory-expansion-for-the-zx81-and-ts1000/). You can even combine some (like 16K + 32K)

andrivet commented 1 week ago

I can check on the actual hardware if you think it is important. I have some Sinclair 16K RAMpacks somewhere. I should also receive a Memotech 32K RAMpack but I do not know when (I bought two ZX81 some days ago on eBay).

maziac commented 6 days ago

Thanks for the info. Probably it's not required to do tests on this (but thanks for the offer).

I was tinkering a little bit with the charset, i.e. replacing the original charset in dezog with a custom one to get better graphics for games and I'm pleased with the results, e.g.: image

Do you know if there have been RAM packs around that allowed to change the charset with custom fonts? I.e. that put the charset in the RAM area. The UM-64 above can copy the ROM to RAM, but the manual says changing the characters is not possible "the user cannot alter the character generator". I.e. probably the ULA access is still routed elsewhere.

andrivet commented 6 days ago

The architecture of the ZX81 is unusual. It has two address busses:

There are however UDG (User defined graphics) extensions. They work by replacing the display routine in a way similar to WRX16 (high-resolution) tricks.

There is also the CHR$(128) trick. The ROM contains only the graphics of the first 64 chars (+ the inverted ones) and they are defined at the end of the ROM. So if you use a higher code (>= 128), and if there is RAM at the right address, the ULA will use the graphics you defined.

andrivet commented 3 days ago

I see that some (true) hires programs are not working properly. It is probably not trivial to make them work. They are also not working correctly in emulators like ZEsarUX. They do display correctly in the EightyOne emulator and in the iOS ZX81 emulator.

The program (Shogun from Dr. Beep) : SHOGUN.P.zip

In EightyOne:

Screenshot 2024-09-08 at 15 34 13

In DeZog:

Screenshot 2024-09-08 at 15 36 04
andrivet commented 3 days ago

ZEsarUX does display correctly with the right option activated (WRX):

Screenshot 2024-09-08 at 16 35 52
maziac commented 3 days ago

Good catch. I will have a look.