vice dissassembly with labels patch

fred

New Member
Oct 22, 2019
6
6
3
Hi,

I noticed that the vice monitor doesn't manage disassembly with labels correctly (xpet).

When not using labels, here is a typical disassembly:

after typing: "d 462", I get:

Code:
.C:0462  78          SEI
.C:0463  A9 FF       LDA #$FF
.C:0465  85 BB       STA $BB
.C:0467  A9 04       LDA #$04
.C:0469  85 BC       STA $BC
.C:046b  A0 00       LDY #$00
.C:046d  A9 FC       LDA #$FC
.C:046f  8D 4C E8    STA $E84C
.C:0472  C0 00       CPY #$00
.C:0474  D0 37       BNE $04AD
.C:0476  A9 DC       LDA #$DC
.C:0478  8D 4C E8    STA $E84C
.C:047b  E6 BB       INC $BB
.C:047d  A6 BB       LDX $BB
.C:047f  E0 FF       CPX #$FF
.C:0481  A9 00       LDA #$00
.C:0483  65 BC       ADC $BC
.C:0485  A0 00       LDY #$00
.C:0487  B1 BB       LDA ($BB),Y
.C:0489  AA          TAX
.C:048a  C9 FF       CMP #$FF
.C:048c  D0 01       BNE $048F
.C:048e  60          RTS
(C:$048f)
As this is hard to use, so I generated a label file for the code.

However, when loading labels, here is the screen content after typing a "d .main":

Code:
.C:0463  A9 FF       LDA #$FF
.C:0465  85 BB       STA .zsnd
.C:0467  A9 04       LDA #$04
.C:0469  85 BC       STA $BC
.C:046b  A0 00       LDY #$00
.C:046d   ._emit1:
.C:046d  A9 FC       LDA #$FC
.C:046f  8D 4C E8    STA .VIA_PCR
.C:0472  C0 00       CPY #$00
.C:0474  D0 37       BNE ._lead_wait1
.C:0476  A9 DC       LDA #$DC
.C:0478  8D 4C E8    STA .VIA_PCR
.C:047b  E6 BB       INC .zsnd
.C:047d  A6 BB       LDX .zsnd
.C:047f  E0 FF       CPX #$FF
.C:0481  A9 00       LDA #$00
.C:0483  65 BC       ADC $BC
.C:0485  A0 00       LDY #$00
.C:0487  B1 BB       LDA (.zsnd),Y
.C:0489  AA          TAX
.C:048a  C9 FF       CMP #$FF
.C:048c  D0 01       BNE .@continue
.C:048e  60          RTS
(C:$048f)
The following part have been scrolled out of the screen (which is unfortunate, as it is arguably the most important bit if I ask to disassemble "main").

Code:
.C:0462   .main:
.C:0462  78          SEI
This is a trivial issue, the disassembly command is counting the number of disassembled instruction, instead of counting the number of lines printed to screen. Locating the source of the error and correcting it took 5 minutes.

After correction, here is the result of typing "d .main" :

Code:
.C:0462   .main:
.C:0462  78          SEI
.C:0463  A9 FF       LDA #$FF
.C:0465  85 BB       STA .zsnd
.C:0467  A9 04       LDA #$04
.C:0469  85 BC       STA $BC
.C:046b  A0 00       LDY #$00
.C:046d   ._emit1:
.C:046d  A9 FC       LDA #$FC
.C:046f  8D 4C E8    STA .VIA_PCR
.C:0472  C0 00       CPY #$00
.C:0474  D0 37       BNE ._lead_wait1
.C:0476  A9 DC       LDA #$DC
.C:0478  8D 4C E8    STA .VIA_PCR
.C:047b  E6 BB       INC .zsnd
.C:047d  A6 BB       LDX .zsnd
.C:047f  E0 FF       CPX #$FF
.C:0481  A9 00       LDA #$00
.C:0483  65 BC       ADC $BC
.C:0485  A0 00       LDY #$00
.C:0487  B1 BB       LDA (.zsnd),Y
.C:0489  AA          TAX
.C:048a  C9 FF       CMP #$FF
(C:$048c)
(the .main label and the first instructions are still on screen)

However, the source code is hosted on sourceforge, using svn (while I appreciate the idea of using obsolete tools for retro computing, I feel that this lacks the purity of using SCCS)

I tried to create an account on sourceforge, but after having having me fill all the fields, the sucker showed me "System Error Client IP address you are attempting the registration from is blocked." for about 500 ms, and blanked the form.

I am not jumping through additional hoops.

If anyone cares, or have an account on SF, or knows the vice devs, here is the change to do to get proper disassembly with symbols on vice.

In mon_disassemble.h, change the mon_disassemble_instr() signature to:

Code:
extern unsigned mon_disassemble_instr(MON_ADDR addr, int *line_count );
In mon_disassemble.c, change mon_disassemble_instr() to:

Code:
unsigned mon_disassemble_instr(MON_ADDR addr, int *line_count /* Returns the number of lines printed */ )
{
    MEMSPACE mem;
    uint16_t loc;
    char *label;
    unsigned opc_size;

    mem = addr_memspace(addr);
    loc = addr_location(addr);

    if (line_count) { *line_count = 0; }

    /* Print the label for this location - if we have one */
    label = mon_symbol_table_lookup_name(mem, loc);
    if (label) {
        mon_out(".%s:%04x   %s:\n", mon_memspace_string[mem], loc, label);
        if (line_count) { (*line_count)++; }
    }

    /* Print the disassembled instruction */
    mon_out("%s\n", mon_disassemble_instr_interal(&opc_size, addr));
    if (line_count) { (*line_count)++; }

    return opc_size;
}
In mon_disassemble.c , change mon_disassemble_lines to:

Code:
void mon_disassemble_lines(MON_ADDR start_addr, MON_ADDR end_addr)
{
    MEMSPACE mem;
    long len, i, bytes;
    int limitlines = (end_addr == BAD_ADDR);
    int linesleft;
    static int last_known_yres = 25;

    len = mon_evaluate_address_range(&start_addr, &end_addr, FALSE, DEFAULT_DISASSEMBLY_SIZE);
    if (console_log) {
        last_known_yres = console_log->console_yres;
    }
    linesleft = last_known_yres - 1;

    if (len < 0) {
        log_error(LOG_ERR, "Invalid address range");
        return;
    }

    mem = addr_memspace(start_addr);
    dot_addr[mem] = start_addr;

    i = 0;
    while ((i <= len) || (limitlines == 1)) {
        int line_count; /* Number of lines printed by disassembly */
        bytes = mon_disassemble_instr(dot_addr[mem], &line_count);
        i += bytes;
        mon_inc_addr_location(&(dot_addr[mem]), bytes);
        if (mon_stop_output != 0) {
            break;
        }
        if (limitlines) {
            linesleft-=line_count;
            if (linesleft <= 0) { /* Slight bug is the last line is a label, we would scroll the first line out */
                break;
            }
        }
    }
}
Have a nice day!

--fred
 
  • Like
Reactions: Swift34
May 22, 2019
596
302
63
There are no VICE developers here; I'd suggest signing up on Lemon64's forums and talking to one of the guys there who contributes to VICE. I believe Tobias is your best bet, at least as an initial contact.
 
  • Like
Reactions: fred

fred

New Member
Oct 22, 2019
6
6
3
There are no VICE developers here; I'd suggest signing up on Lemon64's forums and talking to one of the guys there who contributes to VICE. I believe Tobias is your best bet, at least as an initial contact.
Thanks, just posted the same post over there, I'll see where it goes.