Re: [cc65] diskcmd.s error

From: <silverdr1wfmh.org.pl>
Date: 2009-07-05 21:26:01
On 2009-07-05, at 18:20, Ullrich von Bassewitz wrote:

>> OK. Set of sources sent to the personal mailbox.
>
> Thanks, I've had a look at it. The problem is caused by tricky  
> programming
> together with ld65 being too strict.

Being strict is not a bad thing in programming IMHO. It often helps  
finding nasty bugs, which would otherwise survive much longer.

> Here is the relevant line again:
>
>        jsr     isdisk          ; Disk unit?
>        bcs     success
>
> ; Is this channel already open?
>
>        ldy     opentab-FIRST_DRIVE,x
>        bne     isopen
>
> First, X is checked to contain the address of a disk on the bus, so  
> X is at
> least 8 (= first disk drive). Since the table "opentab" contains  
> just disks,
> an offset of 8 (= FIRST_DRIVE) is subtracted, so when X contains 8,  
> the first
> element of the table is addressed. The address calculation (get  
> address of
> opentab and subtract 8) is stored in the object file.

I see. I think now I know what you meant by "tricky programming" here.  
At first I was wondering what was tricky in my crude test code :-) but  
subtracting the offset from the base rather than the index (even if  
more or less ensured to be working) is what I understand as tricky.

> The table "opentab" is in the BSS segment. In your program, there is  
> nothing
> else in the BSS segment, so the table is at the start of the  
> segment. So the
> expression resolves to "get the address of the BSS segment and  
> subtract 8",
> which is an address that lies *outside* of the segment. And this is  
> what the
> linker doesn't like ...

Yes, and for a reason as I understand here.

>
> The error will go away by itself if you start adding uninitialized  
> variables
> or use more library modules. As a quick workaround, use
>
>        static char unused[8];
>
> at the top of your C module until your program grows larger.

Hm, I don't have the sources here at hand but would changing the  
diskcmd.s starting at line 49 to read more or less like:

	pha
	txa
	pha
	sec
	sbc #FIRST_DRIVE
	tax
	ldy opentab,x
	pla
	tax
	pla
	cpy #$00
	bne isopen

be a drop-in replacement fix, even if long, slow, etc?

Of course this should possibly be optimised, depending on how  
important preserving the registers values is (as I wrote I can't check  
the lib sources now) or whether not to use different registers, etc.

>
> Thanks for the report. This was an interesting one :-)
>

Thank you for checking this out. At least I feel better that:

a) it wasn't me doing something utterly stupid
b) I wasn't bothering you without a reason as it would certainly take  
me many times longer to find this out, if at all ;-)

Cordially,

-- 
SD!

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sun Jul 5 21:26:10 2009

This archive was generated by hypermail 2.1.8 : 2009-07-05 21:26:12 CEST