vsariola / c64-cheat-sheets

5 stars 0 forks source link

Missing unintended opcodes #1

Closed bergfried closed 3 weeks ago

bergfried commented 1 month ago

First of all, thank you very much for this very handy cheat sheet!

You might want to have a look at https://csdb.dk/release/?id=226987 (or any newer version) which seems to be very detailed when it comes to unintended opcodes. Given the information presented in that document, I would like to see the following information added to the cheat sheet:

It would be great if you could incorporate the changes proposed above in some way or the other as I really like the compact way you present the instructions.

vsariola commented 1 month ago

Wow! I almost forgot the existence of this; haven't done C64 stuff for ages, but I'll try to incorporate the information that you listed into the cheat sheet :)

bergfried commented 1 month ago

Thank you for the very quick reply! Looking at the current cheat sheet version, I just noticed a few more things, so I have some ideas but I am not sure whether they will help or are good at all:

EDIT:

Again, just ideas I have never really tested, but maybe they inspire you.

bergfried commented 1 month ago

Few more things:

Adding a "Touch" column to NOPs (as suggested earlier) might be unnecessary because the locations they will touch can be derived from the addressing mode column header, as they will touch the target locations accordingly, as if using a load instruction and then discarding the result.

(By the way, all opcodes, including the official ones, tend to touch more memory then just the current instruction's location and target locations. So, one might just as well point this out in general. Or maybe not because it was never pointed out before and the cheat sheet works well so far.)

Given all that, I just sketched out how a new NOP section might look like:

Illegal `NOP` instructions

1 byte      2 bytes             3 bytes
(implied)   #00   $00   $00,X   $0000   $0000,X
-----------------------------------------------
1A                      14              1C
3A          80          34              3C
5A          82          54              5C
7A          89    04    74              7C
DA          C2    44    D4              DC
FA          E2    64    F4      0C      FC
2           2     3     4       4       4*

* add one cycle if page boundary crossed
NOP behaves like LDA but discards the result.
Opcodes 0C and 1C sometimes also known as TOP.
Opcodes 80, 04 and 14 sometimes also known as DOP.

Pros:

Cons:

Now for the JAM opcodes:

Illegal JAM instruction opcodes

02 12 22 32 42 52
62 72 92 B2 D2 F2

JAM freezes the CPU.

Note: According to page 104 of 118, JAM is not known by any other mnemonic to any of the assemblers listed. Therefore, it should be okay to leave out alternatives like HLT or KIL.

Ideally, the cheat sheet will cover all 256 opcodes.

EDIT: I changed the sketch a bit. Also, I think I have found a suitable "Function" for NOPs: $ because it is like $ ⇒ A for LDA but discards the result (like SBC versus CMP). No flags. However, it might not make much sense for the "(implied)" addressing mode which the official NOP also belongs to, other than for symmetry reasons.

vsariola commented 1 month ago

Regarding the NOPs: does any assembler actually recognize the instruction mnemonics?

vsariola commented 1 month ago

I started making the changes in another branch, have a look at the draft here

  • The normal SBC ($E9) has an unintended twin ($EB). Given the current layout, it should probably appear in a new line between AXS and AXA.

This is now in the normal table, with a mark that its actually unintended

  • If the then-smaller "Jumps and Calls" section has still enough space, you might want to add an explicit line for the normal NOP ($EA) instruction. (You might still want to keep the NOP for the key.) However, this might occupy some more space so not sure.

Did not as I don't find it quite appropriate to call a NOP a jump or a call. I just kept it where it is, but now it is near the other illegal NOPs so people looking for a NOP should find it.

  • Maybe you can move the key to the upper-right corner of the page. Maybe the flags in the P-register can be explained in a single (albeit long) line somewhere at the bottom of the page.

I'm sure I'd be able to squeeze the P-register description, but since it seems to fit like it was, didn't change it.

  • A bit controversial, but maybe you can move the BIT instruction from "Flag Manipulation" to "Logical and Arithmetic" between CPY and DEC. [EDIT: I just noticed that it should not be controversial but mandatory! Why? Because the opcodes aggree! The BIT opcodes ($24, $2C) resemble two CPY opcodes (namely $C4, $CC) better than any of the unconditional flag operations.] This would make the "Flag Manipulation" section just as small as the "Branches" section but it would also make "Logical and Arithmetic" a bit bigger.

I agree with this in principle, but now it messes the space so I'd rather not if possible :)

  • Then, maybe you can move "Flag Manipulation" to the lower-left corner where "Branches" then used to be. The area where the key currently is can probably be used to store the "Illegal NOP Instructions" section, and just above it, maybe where "Flag Manipulation" currently is, you can put the "Illegal JAM instruction opcodes" section. If you are lucky, this leaves a tiny area at the top of the current "Flag Manipulation" section where you can still put the key.

"Illegal JAMs" and "Illegal NOPs" tables are there.

  • In order to distinguish the sections for illegal opcodes mentioned above, the current "Illegal Instruction" section should be renamed to something like "Illegal Logic and Arithmetic Instructions".

Done.

bergfried commented 1 month ago

Regarding the NOPs: does any assembler actually recognize the instruction mnemonics?

I just tested it, and ACME, for example, translates all NOPs and DOPs and TOPs just fine:

nop         ; EA       (the official NOP)
nop #$ee    ; 80 EE
nop $ee     ; 04 EE
nop $ee,x   ; 14 EE
nop $eeee   ; 0C EE EE
nop $eeee,x ; 1C EE EE
dop #$ee    ; 80 EE
dop $ee     ; 04 EE
dop $ee,x   ; 14 EE
top $eeee   ; 0C EE EE
top $eeee,x ; 1C EE EE

Of course, ACME prefers using certain opcodes when creating its output. This is no different from other instructions like SBC #imm which has as an unintended twin (as mentioned earlier), or ANC #imm where ACME prefers $0B over $2B while the cheat sheet lists both (as it should). And just like the cheat sheet lists all ANC opcodes, it should also list all unintended NOP opcodes, I think.

(Just now, I am imagining someone creating self-modyfing code that produces various different NOPs as a by-product of some computations. Of course, for something like that, you want to know all the different opcodes for NOPs!)

vsariola commented 1 month ago

Of course, ACME prefers using certain opcodes when creating its output. This is no different from other instructions like SBC #imm which has as an unintended twin (as mentioned earlier), or ANC #imm where ACME prefers $0B over $2B while the cheat sheet lists both (as it should). And just like the cheat sheet lists all ANC opcodes, it should also list all unintended NOP opcodes, I think.

I went through the cheat sheet and painfully checked with Inkscape's find functionality that every hex opcode 00 - FF is now mentioned somewhere, so I think all opcodes (including all NOPs/TOPs/DOPs/JAMs) are there. Please report back any errors you find from the draft

bergfried commented 1 month ago

I have to admit that I do not like the idea of mixing intended opcodes with unintended ones. The fact that the unintended one works just the same as the official one is really just pure luck. On the other hand, it's a cheat sheet, not a super official document, and I do understand the idea behind that, so I guess it's just fine. :)

Please report back any errors you find from the draft

I'm trying, but first, I need to try and install the font you use. But even without having installed the font yet, I think I`m going to like the new layout.

vsariola commented 1 month ago

6510_assembly_instructions.pdf

This PDF version should have fonts embedded.

vsariola commented 1 month ago

I have to admit that I do not like the idea of mixing intended opcodes with unintended ones. The fact that the unintended one works just the same as the official one is really just pure luck. On the other hand, it's a cheat sheet, not a super official document, and I do understand the idea behind that, so I guess it's just fine. :)

How about just putting a dagger and something like "† illegal opcode EB works identical to E9", so no EB in the table?

vsariola commented 1 month ago

6510_assembly_instructions.pdf

Here's a version with the latest minor tweaks; this time the EB is removed from the table and just mentioned in the dagger.

bergfried commented 1 month ago

Thank you for the drafts. I would like to comment on them later, but I am too busy right now.

bergfried commented 1 month ago

I am sorry for the late reply.

I went through the cheat sheet and painfully checked with Inkscape's find functionality that every hex opcode 00 - FF is now mentioned somewhere, so I think all opcodes (including all NOPs/TOPs/DOPs/JAMs) are there.

Thank you very much. I also just checked by throwing some shell magic at it:

$ diff <(printf '%.2X\n' {0..255}) <(sed -r -n -e 's#.*>([0-9A-F]{2})</tspan.*#\1#p' 6510_assembly_instructions.svg | sort)  
12d11
< 0B
44d42
< 2B
236d233
< EB

So only 0B, 2B and EB could not be found automatically, and these are exactly the opcodes that are present but formatted in a different way (which is why they could not be found automatically). So all good. :)

I have to admit that I do not like the idea of mixing intended opcodes with unintended ones. The fact that the unintended one works just the same as the official one is really just pure luck. On the other hand, it's a cheat sheet, not a super official document, and I do understand the idea behind that, so I guess it's just fine. :)

Well, on second thought, I still prefer not mixing intended opcodes and illegal ones very much, and the additional reason that now came to mind is that, for consistency reasons, you would also need to mention that $1A, $3A, $5A, $7A, $DA and $FA all work the same as $EA aka NOP. Also, I have tried it out (see the attached draft), and I think the illegal SBC fits just perfectly, space-wise, opcode-wise and all.

Anyway, as mentioned above, I took the liberty and time to create a draft (PDF, SVG in ZIP) based on your most recent draft.

It comes with the following changes:

Regarding NOP: The first time I tried to use the cheat sheet, I failed to locate NOP on it because I did not expect it to be mentioned only in the key! I remember the key used to explain the details of a periodic table on the wall at school. The element that was used for the key certainly appeared in the full table again. I have seen this pattern everywhere else, so I do not see why the cheat sheet should deviate from it.

Regarding the font change, please have a look at #2 where I explain it in detail.

bergfried commented 1 month ago

I just noticed that there is a superfluous whitespace character right after the comma in AND $, N ⇒ C, the function description of ANC, and it should be removed, I think.

vsariola commented 1 month ago

Just so you know that all these have been mostly addressed in my latest version, but the font change (#2) made everything misaligned, so I'll return to this issue when the font change is sorted out.

vsariola commented 3 weeks ago

I will close this issue also, as all opcodes & illegal NOPs/DOPs/TOPs, JAMs and SBC2 are now documented in the cheat sheet. Also I believe the alignment issues mentioned here or in the other issue have been resolved (or, at least attempted to be resolved), but if there's still remaining issues (e.g. alignments), let's open further specific issues to discuss those, so it's easier to find them later.

bergfried commented 3 weeks ago

Sorry for the late reply. The new version 0.2.0 looks very good. Thank you very much!