Disassembly problem

feedback, questions and discussion relating to www.bbcmicro.co.uk
Post Reply
User avatar
Dave Footitt
Posts: 924
Joined: Thu Jun 22, 2006 10:31 am
Location: Abandoned Uranium Workings
Contact:

Disassembly problem

Post by Dave Footitt » Wed Jul 22, 2020 10:11 pm

Sorry if this has been reported before, but the disassembly doesn't seem to be working quite right...

eg on PaperBoy ( http://www.bbcmicro.co.uk/explore.php?id=535 ), in the file PROG the first bytes are A9 0C which disassembles to TAY #&0C which clearly isn't right, not sure if there are others?

User avatar
kieranhj
Posts: 921
Joined: Sat Sep 19, 2015 11:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Disassembly problem

Post by kieranhj » Wed Jul 22, 2020 11:12 pm

Yeah the library is a bit busted. That’s been filed as a bug, along with some others, on GitHub: https://github.com/shawty/BBCB_DFS_Catalog/issues/3
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

User avatar
richardtoohey
Posts: 3986
Joined: Thu Dec 29, 2011 5:13 am
Location: Tauranga, New Zealand
Contact:

Re: Disassembly problem

Post by richardtoohey » Thu Jul 23, 2020 4:18 am

I've fixed the TAY # entry to LDA #.

http://www.bbcmicro.co.uk/dfs/dfscat.js

You can find the opcode table starting here:

function d_dis(catalogIndex)

So about half-way down.

shawty says a new version is coming but if you spot any others that are tweaks like this one - let me know and I can (hopefully) fix.

I didn't know about this bit on bbcmicro.co.uk either! :D

User avatar
richardtoohey
Posts: 3986
Joined: Thu Dec 29, 2011 5:13 am
Location: Tauranga, New Zealand
Contact:

Re: Disassembly problem

Post by richardtoohey » Thu Jul 23, 2020 4:28 am

I've also had a stab at correcting the ZP issue: https://github.com/shawty/BBCB_DFS_Catalog/issues/4

But not 100% sure I've got this right.

If you look at the js link in my previous post - I've changed all the instruction mode 10 (ZP) opcodes.

Let me know if I've made it better or worse.

And if there are any other tweaks.

I'm not tackling this one right now: https://github.com/shawty/BBCB_DFS_Catalog/issues/5

Because (I think?) it's a bit of a can of worms in that if you are looking at a really-only-meant-to-be-6502 program you might get confused if it shows the Master opcodes. ??? is more meaningful if you are looking in a BBC mode. And to add a Master mode - that's a bit more work than tweaking op-codes.

Could prefix the master opcodes with m e.g. mPHX but for the more complex 2-or-3 byte opcodes they'd slurp up the next 2 or 3 bytes leading to more confusion when looking at BBC code? Or am I over-thinking it?

User avatar
Dave Footitt
Posts: 924
Joined: Thu Jun 22, 2006 10:31 am
Location: Abandoned Uranium Workings
Contact:

Re: Disassembly problem

Post by Dave Footitt » Thu Jul 23, 2020 11:49 pm

Many thanks Richard, the LDA one is certainly working for me now.

I was going to use EXMON which is great but having it online I can just paste into emacs is great =D>

User avatar
richardtoohey
Posts: 3986
Joined: Thu Dec 29, 2011 5:13 am
Location: Tauranga, New Zealand
Contact:

Re: Disassembly problem

Post by richardtoohey » Fri Jul 24, 2020 12:46 am

Let me know if you find any others.

Yes, it's a useful feature. I have to pinch myself every now-and-then to realise how far JavaScript has come (well, things like jsbeeb are prime examples of the amazing things you can do these days). It's come a long way from the days when all it was good for was simple form validation!

User avatar
Dave Footitt
Posts: 924
Joined: Thu Jun 22, 2006 10:31 am
Location: Abandoned Uranium Workings
Contact:

Re: Disassembly problem

Post by Dave Footitt » Sat Aug 01, 2020 10:16 pm

Possibly also a problem with the following bytes:

Code: Select all

b1 10 91 12

Which disassembles to:

Code: Select all

LDA (&9110,Y)
???
In b2 this disassembles as:

Code: Select all

b1 10 -> LDA (&10),Y
91 12 -> STA (&12),Y

User avatar
Dave Footitt
Posts: 924
Joined: Thu Jun 22, 2006 10:31 am
Location: Abandoned Uranium Workings
Contact:

Re: Disassembly problem

Post by Dave Footitt » Sun Aug 02, 2020 10:35 pm

Also AND immediate, disassembles incorrectly:

Code: Select all

29 0F -> AND &0F
Sorry if it seems like I'm moaning here - it's a really handy little tool, I think it would be great to get these little things ironed out 8)

User avatar
richardtoohey
Posts: 3986
Joined: Thu Dec 29, 2011 5:13 am
Location: Tauranga, New Zealand
Contact:

Re: Disassembly problem

Post by richardtoohey » Mon Aug 03, 2020 5:52 am

No worries - agree it will be good to get things fixed. :D

But if you can look at the code and let me know a fix that will probably make things happen quicker. I'm just tweaking code produced by others (standing on the shoulders of giants and all that!)

So let's have a quick look at the AND issue ...

http://www.bbcmicro.co.uk/dfs/dfscat.js

Code: Select all

function d_dis(catalogIndex)
{
  var fileItem = catalog[catalogIndex];
  var fileData = getFileData(catalogIndex);
	
  var l = new String;
  var text = new String;

  var ops = new Array();
  var amode = new Array();

  var a = 0;
  var addr = 0;
  var i = 0;
  var j = 0;

  ops[0x00] = ['BRK   ', 5];
  ops[0x01] = ['ORA X,', 7];
  ops[0x05] = ['ORA ' ,10];
  ops[0x06] = ['ASL ' ,10];
  ops[0x08] = ['PHP '  , 5];
  ops[0x09] = ['ORA '  , 4];
  ops[0x0A] = ['ASL A' , 0];
  ops[0x0D] = ['ORA '  , 1];
  ops[0x0E] = ['ASL '  , 1];

  ops[0x10] = ['BPL '  , 9];
  ops[0x11] = ['ORA (' , 8];
  ops[0x15] = ['ORA '  ,11];
  ops[0x16] = ['ASL '  ,11];
  ops[0x18] = ['CLC '  , 5];
  ops[0x19] = ['ORA '  , 3];
  ops[0x1D] = ['ORA '  , 2];
  ops[0x1E] = ['ORA '  , 1];

  ops[0x20] = ['JSR '  , 1];
  ops[0x21] = ['AND X,', 7];
  ops[0x24] = ['BIT ' ,10];
  ops[0x25] = ['AND ' ,10];
  ops[0x26] = ['ROL ' ,10];
  ops[0x28] = ['PLP '  , 5];
  ops[0x29] = ['AND '  , 4];
So opcode 0x29 is set up to AND, instruction mode 4 ... let's look a bit further down in the code and ...

Code: Select all

/*
 0 A
 1 abs
 2 abs,X
 3 abs,Y
 4 #
 5 impl
 6 ind
 7 X,ind
 8 ind,Y
 9 rel
10 zpg
11 zpg,X
12 zpg,Y
*/
4 is immediate mode ... going by that code comment ... let's peek at &A9 because I know that's immediate ...

Code: Select all

  ops[0xA9] = ['LDA #' , 4];
So looks like I need to change the 0x29 line to:

Code: Select all

  ops[0x29] = ['AND # '  , 4];
i.e. plonk the # in there.

And a quick look at 0xB1 ...

Code: Select all

  ops[0xB1] = ['LDA (' , 8];
Looks like mode 8, ind,Y according to the list above. But from what you are saying, it looks like zpg,Y would be better? So instruction mode 12? We could try the line like this instead:

Code: Select all

  ops[0xB1] = ['LDA (' , 12];
Dig out me old AUG ... and scratch my head a bit because (indirect),Y is definitely the right addressing mode but the instruction only uses 2 bytes - B1 + 1 byte address.

I've not made any changes yet, just thinking aloud.

User avatar
Dave Footitt
Posts: 924
Joined: Thu Jun 22, 2006 10:31 am
Location: Abandoned Uranium Workings
Contact:

Re: Disassembly problem

Post by Dave Footitt » Mon Aug 03, 2020 9:23 am

richardtoohey wrote:
Mon Aug 03, 2020 5:52 am
No worries - agree it will be good to get things fixed. :D
Definitely, although I'm not very good with javascript myself but happy to bounce ideas back and forth.
richardtoohey wrote:
Mon Aug 03, 2020 5:52 am
So looks like I need to change the 0x29 line to:

Code: Select all

  ops[0x29] = ['AND # '  , 4];
i.e. plonk the # in there.
Yep looks good to me!
richardtoohey wrote:
Mon Aug 03, 2020 5:52 am
And a quick look at 0xB1 ...

Code: Select all

  ops[0xB1] = ['LDA (' , 8];
Looks like mode 8, ind,Y according to the list above. But from what you are saying, it looks like zpg,Y would be better? So instruction mode 12? We could try the line like this instead:
The mode (&zp),Y expects the LSB of the address in zero page, so that's true it is only 2 bytes - and it can only be done with the Y register. Earlier on in the code the mode '12' is also specified for X which doesn't make sense:

Code: Select all

ops[0xB6] = ['LDX '  ,12];
So I think it's probably better to fix "mode 8" so it only fetches one more byte in the disassembly if that makes sense?

User avatar
richardtoohey
Posts: 3986
Joined: Thu Dec 29, 2011 5:13 am
Location: Tauranga, New Zealand
Contact:

Re: Disassembly problem

Post by richardtoohey » Mon Aug 03, 2020 10:32 pm

Thanks.

I think the next step is probably to make a test SSD with a binary file that has all the opcodes in them and then we can work through all of them to make sure all opcodes & addressing modes are working correctly.

I'll dig out the AUG and have a go. My 6502 knowledge is a bit rusty ... &A9 is LDA# is about all that stuck!

User avatar
Dave Footitt
Posts: 924
Joined: Thu Jun 22, 2006 10:31 am
Location: Abandoned Uranium Workings
Contact:

Re: Disassembly problem

Post by Dave Footitt » Tue Aug 04, 2020 3:56 pm

richardtoohey wrote:
Mon Aug 03, 2020 10:32 pm
I think the next step is probably to make a test SSD with a binary file that has all the opcodes in them and then we can work through all of them to make sure all opcodes & addressing modes are working correctly.
Great stuff - if you want a hand with anything let me know, seems the sort of thing we could get a good test suite written for and run those tests if anything changes, to give a degree of confidence.

I use this site quite often as it gives you the addressing modes and their opcodes, eg for LDA:

http://www.obelisk.me.uk/6502/reference.html#LDA

Post Reply

Return to “the complete BBC games archive”