Simion32's 65c816 Reference (HTML Help) [2.1 UPDATE]

Share and discuss all facets of DKC ROM hacking...

Simion32's 65c816 Reference (HTML Help) [2.1 UPDATE]

Postby Simion32 » December 24th, 2023, 9:12 am

A little something I've gathered together while getting ready for some in-depth DKC1/2/3 hacking. ;)

This is a pretty hefty document that I had to manually convert from *.hlp to *.chm since Windows 10/11 do not support the old help file format that was used back in the XP days.

I tried to give original credits but I might be wrong about who wrote the original documentation.

This was essentially dug up from a very old ASM tutorial on Aclmm's Board -- way back then, I found the document to be indispensable in hacking both SMW and DKC. I am sure I've captured the original usefulness.

I had to manually readjust the mono-spaced text and create links for all of the pages, which took a considerable amount of work. I hope you enjoy. :swanky:

So without adieu, here it is:
Simion32s65c816Reference(v2.1).zip
(45.32 KiB) Downloaded 820 times

Version 2.0 Downloaded 7 times.
Version 1.0 Downloaded 18 times.

For people with issues viewing the file:
Kingizor wrote:The fix appears to be to right click on the file, choose Properties and look for an "Unblock" button.
Sage of Discovery
Bananas received 337
Posts: 2747
Joined: 2008

Re: Simion32's 65c816 Reference (HTML Help)

Postby Simion32 » January 3rd, 2024, 3:40 pm

I've noticed that the original author messed up the XBA and said 16 bits instead of 8 when referring to the low and high bytes of the accumulator.

How I've missed that error, I have no idea. I won't be re-uploading though just for that. :P

You can also view this help file on Ubuntu Linux by installing xCHM. ;)
Sage of Discovery
Bananas received 337
Posts: 2747
Joined: 2008


Re: Simion32's 65c816 Reference (HTML Help)

Postby Simion32 » January 4th, 2024, 4:32 pm

I'm not sure what the problem is... :headache:

I only had one program to even make the CHM file and I'm not sure what's wrong.

Are you on Windows 11?

EDIT: It seems this is an OS issue: https://github.com/sumatrapdfreader/sum ... ssues/3486

EDIT2: It seems to me that you'll only be able to open it with a third-party CHM viewer. :shakehead:

I've been able to open it on the Windows 10 machine I develop on just fine. It even opens on my Linux machine here. Hmm.
Sage of Discovery
Bananas received 337
Posts: 2747
Joined: 2008

Re: Simion32's 65c816 Reference (HTML Help)

Postby Kingizor » January 5th, 2024, 1:19 am

It works fine for me with xCHM. I had it installed already for perusing some other chm file a while back, so I was quite surprised when you mentioned it. The only thing is that in xCHM it seems to use a non-mono font for everything by default which borks the formatting. Changing the regular font to a monospaced font seem to resolve that though. Wine has a 'hh' utility for reading chm files (and 'winhelp' for hlp), and the formatting appears fine there.

The Windows thing might be due to it being an untrusted file, which seems excessive for a known format that doesn't contain any executable components (as far as I know). The fix appears to be to right click on the file, choose Properties and look for an "Unblock" button. That seems to be the advice for Windows XP to 7, but it probably hasn't changed too much for later versions. It's also interesting if an untrusted attribute could be applied to a file extracted from an untrusted zip file, but that's probably a good thing. As for the zip file being untrusted, well I'd blame the plain http connection first but who knows.



Back when I was learning all of this, getting used to the different mnemonics was the biggest issue for me. There was a long retired site with a page that had a concise list of instructions and grouped similar ones which made it easy to follow. The "Opcode List" page in this file is a bit similar. The best resource for this stuff is the Eyes/Lichty book; "Programming the 65816" which has been distributed freely online by WDC in the past.

The MVP/MVN page here has a few issues:

Spoiler!
The Accumulator should be loaded with the number of bytes to copy.


Should be "number of bytes plus 1". If A is 0, it will transfer one byte, if A is 1 it will transfer 2, etc.

The difference between MVP and MVN instructions is the direction in which the data is transferred.


This on its own isn't wrong per se, but it's a bit vague.

Code: Select all
do { *(destbank|Y++) = *(srcbank|X++); } while (A--); // MVN
do { *(destbank|Y--) = *(srcbank|X--); } while (A--); // MVP

This means at the beginning of the transfer, X and Y point to the start of the source and destination for MVN and increment on each iteration, whereas for MVP X and Y start at the end and decrement instead. Banks don't get crossed either, but that's a whole other set of problems. The idea is that data can be moved even if source and destination overlap, a bit like memmove.

eg.
; Transfers 5 bytes from $80:8000 -> $90:8000
A: 0005 X: 8000 Y: 8000 MVP $80, $90


Lies! Well...misleading. The example causes 6 bytes to be moved counting down, not 5 up as we might expect:

[$90:8000] = [$80:8000]
[$90:7FFF] = [$80:7FFF]
[$90:7FFE] = [$80:7FFE]
[$90:7FFD] = [$80:7FFD]
[$90:7FFC] = [$80:7FFC]
[$90:7FFB] = [$80:7FFB]


There are a few ops that store their arguments backwards when assembled, so MVN $80 $90 would end up as $54 $90 $80. I imagine most disassemblers would make an effort to hide that fact from users though.

Another quirk of MVN and MVP is that they replace the DB register with the destination bank register which isn't mentioned here. I am aware of precisely one game that can crash if emulators don't implement this.....DKC3! It only happens when you reach the first signpost in Krack Shot Kroc. Strange, huh?


Haven't really noticed anything else wrong. It may have benefited from a brief summary of flags, internal registers (i.e. those used in phb or phd), addressing modes, etc, but it does a good job at providing a summary of all the available opcodes. Probably not worth the effort it would take to fix anything, but chm should be a bit more accessible to Windows users at least.
Trailblazer
Bananas received 77
Posts: 249
Joined: 2010

Re: Simion32's 65c816 Reference (HTML Help)

Postby Simion32 » January 5th, 2024, 9:12 am

I'll work on an updated version.

Thanks for the input, Kingizor. :)
Sage of Discovery
Bananas received 337
Posts: 2747
Joined: 2008

Re: Simion32's 65c816 Reference (HTML Help) [UPDATED!!]

Postby Simion32 » January 8th, 2024, 9:38 am

Document UPDATED!!

I've added registers, flags, addressing modes, and memory mappings to the document, along with several error fixes along with the MVP/MVN instruction details Kingizor provided.

I'd call it complete now, but you never know... ;)
Sage of Discovery
Bananas received 337
Posts: 2747
Joined: 2008

Re: Simion32's 65c816 Reference (HTML Help) [UPDATED!!]

Postby Simion32 » January 8th, 2024, 5:37 pm

I've already found another minor error: The pcrlong addressing mode should say "16 bits" and not "24 bits".

Still just a minor error though, I won't be reuploading just for that. :P
Sage of Discovery
Bananas received 337
Posts: 2747
Joined: 2008

Re: Simion32's 65c816 Reference (HTML Help) [UPDATED!!]

Postby Mattrizzle » January 9th, 2024, 11:25 am

It also doesn't work for me in Windows 7 either. The right pane is always blank, just like rainbow's screenshot.

Of course, the original hlp version still works in 7 :roll: ...
Veteran Venturer
Bananas received 222
Posts: 559
Joined: 2008

Re: Simion32's 65c816 Reference (HTML Help) [UPDATED!!]

Postby Simion32 » January 9th, 2024, 11:31 am

Kingizor wrote:The fix appears to be to right click on the file, choose Properties and look for an "Unblock" button.


:scratch:

EDIT: I've updated the memory mappings section, fixed a few errors, and added a troubleshooting note to the beginning of the contents list.
Sage of Discovery
Bananas received 337
Posts: 2747
Joined: 2008


Return to ROM Hacking

Who is online

Users browsing this forum: No registered users and 8 guests