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

Add support for Z80 instruction sets #39

Closed
gilbertfrancois opened this issue Dec 13, 2023 · 8 comments · Fixed by #59
Closed

Add support for Z80 instruction sets #39

gilbertfrancois opened this issue Dec 13, 2023 · 8 comments · Fixed by #59
Labels
enhancement New feature or request

Comments

@gilbertfrancois
Copy link

gilbertfrancois commented Dec 13, 2023

The Zilog Z80 is a legendary 8-bit microprocessor renowned for its versatility and widespread use in the retro computing era. Introduced in the late 1970s, it became a cornerstone in various iconic systems of that time, notably the MSX, Amstrad CPC, Sinclair ZX80, ZX81, ZX Spectrum, Gameboy, Enterprise, Sam Coupe, and the CP/M-based computers like the Osborne 1 and Kaypro.

The Z80 assembly language continues to inspire a vibrant community of developers who craft remarkable games and applications for retro platforms. Despite the passage of time, these dedicated programmers harness the Z80's capabilities to create engaging content that captivates audiences on classic systems like the Sinclair ZX Spectrum, the Amstrad CPC, MSX and more.

Here are some references about the cpu and its instruction set:

@WillLillis WillLillis added the enhancement New feature or request label Dec 13, 2023
@WillLillis
Copy link
Collaborator

This sounds like a very cool thing to add to the project! From what I can tell, the majority of the work is going to be translating/condensing the documentation you linked into a .xml file for the instructions and another for the registers. I should have time to work on this in the next month or so, but if you want to get started sooner by all means open up a PR :)

@WillLillis
Copy link
Collaborator

Hi @gilbertfrancois . I had some free time today and got hover support and autocomplete for Z80 registers working in a development branch. Here's an example gif:

Z80_Registers

For now, the information provided for each register is the long-form description provided by the owner's manual. As this is quite lengthy, would it would be better to have a more concise description? Do you have any resources that would better reflect the information you'd like to see in a register hover response? If not, I can just use my best judgement to try and pare things down :) I'm planning on tackling instruction hover support next, but that may be a bit.

As a quick aside, I think I found a mistake in the owner's manual. On page 21 in Figure 2, row 2, B' is listed twice, when it seems like the second entry should hold C'. I'm not sure what to do with this information, but found it mildly interesting.

@gilbertfrancois
Copy link
Author

This is amazing! Well done and so swift. It looks really cool in the animated GIF.

The wikipedia page has a one sentence short summary of each register, which might be better suitable for an autocomplete hover menu. I agree that the description from the owner's manual is a bit lengthy. What do you think?

https://en.wikipedia.org/wiki/Zilog_Z80#Registers

You are right about the typo in the manual: the registers AF, BC, DE, HL have a shadow register, called A'F', B'C', D'E', H'L'. To answer your question: B'B' should be B'C'. The aforementioned wikipedia link has a better figure showing the registers.

For the instructions and opcodes, Grauw has a nice table of all (documented) instructions. Only the description is missing from that table. I might figure out the needed xml structure today and make a pull request later.

@WillLillis
Copy link
Collaborator

Thank you! Those Wikipedia descriptions seem a lot better for this use case. I'll pull those together into the xml soon (hopefully tomorrow).

The Grauw link looks very promising! After an initial read, it looks like all the entries in that table would map nicely to the the InstructionForm already used in the project for the x86 and x86_64 instructions. A few optional fields would have to be added to the struct's definition, and the xml parser would be tweaked accordingly, but that should be relatively easy. After all the information is parsed from the xml file, each instruction would contain a vector of 1 or more of these forms. Implementing it this way should also allow us to get signature help once #35 gets merged!

@WillLillis
Copy link
Collaborator

@gilbertfrancois Quick update here. I had initially set out a bit too ambitiously regarding parsing the various forms and their associated arguments for the Z80 instructions into distinct types. While I'll be able to go back and add this later if need be, for the purposes of hover display a string of the instruction signature should be just fine. I went through the branch and made this change, and actually made some significant progress! There's still a bit for me to iron out, and I'll need to wait for some of the pending PRs to go through so this branch can get updated with whatever fixes they need before merging, but the majority of the work for this feature is done. :) Thanks so much for your patience!

Hover support for instructions (kind of) working:
image

Autocomplete for instructions working:
image

Hover support for registers working:
image

Autocomplete for registers working:
image

@gilbertfrancois
Copy link
Author

gilbertfrancois commented Jul 1, 2024

Thank you @WillLillis for the great work. I've installed the latest master branch in neovim. Maybe a silly question, but how do I set the asm-lsp "flavour" to z80? It still defaults to x86 instructions in the autocomplete and popup panels.

@WillLillis
Copy link
Collaborator

Hey @gilbertfrancois! You should be able to set asm-lsp to work just with z80-related stuff by specifying it in your config file, .asm-lsp.toml. This can be placed at a given project's root directory, or inside the ~/.config/asm-lsp/ directory to set things globally. The following file should do the trick, but please let me know if you run into any issues :)

version = "0.1"

[assemblers]
gas = false
go = false
z80 = true

[instruction_sets]
x86 = false
x86_64 = false
z80 = true

@gilbertfrancois
Copy link
Author

Perfect. It works!

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

Successfully merging a pull request may close this issue.

2 participants