Re: [cc65] CLRCH necessary for the CBMs?

From: Spiro Trikaliotis <ml-cc651trikaliotis.net>
Date: 2009-12-10 10:13:10
Hello Uz,

* On Wed, Dec 09, 2009 at 01:54:42PM +0100 Ullrich von Bassewitz wrote:
 
> My first startup code, written millions of years ago, had a call to CLRCH in
> it, which then got cloned into all other Commodore startup files as well. The
> reason (as far as I remember) was to get a "clean" environment somehow. Is
> this call really necessary when starting a cc65 compiled program? Or can it
> even break something, like a redirection of output to the printer?

Perhaps you had read the following comment in the PRG for CHROUT:
 
 +-----------------------------------------------------------------------+
 | NOTE: Care must be taken when using this routine to send data to a    |
 | specific serial device since data will be sent to all open output     |
 | channels on the bus. Unless this is desired, all open output channels |
 | on the serial bus other than the intended destination channel must be |
 | closed by a call to the KERNAL CLRCHN routine.                        |
 +-----------------------------------------------------------------------+

Thus might be the reason why you added that call.

But: When you run a BASIC program (the "call stub"), the RUN command
also executes CLR (which, in turn, executes CLRCH(N)):

RUN command
00A87D  2  20 60 A6             jsr     LA660
[...]
00A660  2  20 E7 FF     LA660:  jsr     kCLALL
[...]
00F32F  2               KCLALL:
00F32F  2  A9 00                lda     #$00
00F331  2  85 98                sta     zLDTND                  ; set
number of open files to 0
00F333  2
00F333  2                       ; "fall through" to CLRCHN
[...]
00F333  2               KCLRCH:
00F333  2  A2 03                ldx     #FILE_SCREEN            ; device
address for screen (3)
[...]

Thus, whenever RUN is used to start a compiled program, CLRCH(N) is not
needed. This is true at least fo VIC-20 and C64. I expect any newer CBM
machine to behave the same.

Regards,
Spiro.

-- 
Spiro R. Trikaliotis                              http://cbm4win.sf.net/
http://www.trikaliotis.net/                     http://www.viceteam.org/
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu Dec 10 10:13:44 2009

This archive was generated by hypermail 2.1.8 : 2009-12-10 10:13:48 CET