[net.micro.cbm] kernal routines wanted

lesmem@ark.UUCP (Marco Lesmeister) (03/13/86)

Hello again, here am I to ask another question to the net, which
helped me so much through all my rough times.

This time it's about the kernal routines.
(I'm into machine-code the last time)

For instance :
		The kernal routine to output one character is CHROUT
		and is located at $FFD2.
		I already knew that.
		I also know that you have to put the ASCII-code for
		the character you want to print in the accumulator.

		I found this out by just looking at listings in
		magazins and listings from the net.

My question is this :
			Can someone post some kernal routines that
			are handy or absolutely needed to make the
			life of a machine-code programmer easier ?

			Maybe someone would post some hints or so
			that he or she found were very usefull to
			him or her at the time he or she learned
			to program in machine-code.
			( The programming itself is no problem,
			  but the kernal has so much secrets for
			  me that I want to find out. )


				Thanks in advance,
				Marco Lesmeister,

	Vrije Universiteit (Free University), Amsterdam, The Netherlands

brown@nicmad.UUCP (03/21/86)

In article <695@ark.UUCP> lesmem@vu44.UUCP (Lesmeister Marco) writes:
>My question is this :
>			Can someone post some kernal routines that
>			are handy or absolutely needed to make the
>			life of a machine-code programmer easier ?
>
>			Maybe someone would post some hints or so
>			that he or she found were very usefull to
>			him or her at the time he or she learned
>			to program in machine-code.
>			( The programming itself is no problem,
>			  but the kernal has so much secrets for
>			  me that I want to find out. )

I know this may be a stupid question, but I'll ask it anyway:

Did you purchase a copy of the C64 Programmer's Reference Guide?
If not, I suggest that you do, as it contains the complete list of the
user kernal subroutines.  It has been very handy for me.  There are other
books out there, but it is very good.

Other people can give you lists of actual rom entry points, but I don't
recommend using them if you will be distributing your code.  The kernal
rom can, and has, change(d).
-- 

              ihnp4------\
            harvard-\     \
Mr. Video      seismo!uwvax!nicmad!brown
              topaz-/     /
             decvax------/

jay@garfield.UUCP (04/04/86)

I am posting this for a friend


Date: Mon, 24 Mar 86 14:23:19 nst

re:kernal routines wanted

Marco Lesmeister recently posted a letter inquiring about the use of kernal
routines on the C-64. This is a topic I'm fairly familiar with, and is prob-
ably of general interest to all netters who dabble in machine language.
  The best way to learn *all* the kernal routines? Get the Commodore 64
programmer's reference guide. The kernal jump table is fully laid out, with
explanations for the routines, setups needed, and registers used for passing/
returning parameters. I don't know how easy it is to find one in the Nether-
lands, but there must be a few copies over there somewhere.
  The *easiest* way to learn all the *important* kernal routines? Pick up a
copy of next month's Transactor magazine (described many articles ago by some-
one as "the" magazine for Commodore users). I know that there are subscribers
all over North America, and some also in Europe (I once saw mention of 1 in
Amsterdam - that wouldn't be you, would it, Marco?). Volume 7, issue 1 (which
I'm *almost* sure is next month's) will be devoted entirely to the theme of
kernal routines. I know for a fact that there will be some good stuff in it,
geared both to those who are proficient in M-L and those who are absolute 
beginners.

Enough plugging: here's a summary of all you'll need to know to make the 64
do any i/o you want it to do (it assumes familiarity with Basic conventions
for filenames, secondary addresses, etc.)

Name     Address             Hint
------------------------------------------------------------------------------
chrout   $ffd2 (65490)       print the ascii char in .a to *any* device that
				has been selected by chkout (screen is default)

chkout   $ffc9 (65481)       file number in .x becomes output file.
				eg: ldx #4 : jsr chkout is the same as cmd 4.

chkin    $ffc6 (65478)       file number in .x becomes input file. default
				is keyboard.

setlfs   $ffba (65466)       set filnum, device, and secondary address *before*
				opening a file. pass the numbers in .a,.x,.y

setnam   $ffbd (65469)       set filename *before* opening file. length of name
				in .a, pointer to it in .x, .y as lo,hi bytes.
				NB: "test" is a bad file name. "0:test,s,w" or
				    "0:test,p,r" are better, with drive and
				    file type included as part of the name.

open     $ffc0 (65472)       open a file once setnam and setlfs have been
				called. for things like "open 15,8,15" or
				"open 4,4" set the length of the name to 0.

getin    $ffe4 (65508)       returns in .a the ascii value of the next char
				from a file, usually the keyboard unless
				chkin has been called.

chrin    $ffcf (65487)       when the keyboard is used, it acts much like the
				BASIC input statement. keep calling it and
				processing the chars that come back in .a
				until a <CR> is encountered. you are supposed
				to be able to read from disk with this, but it
				sometimes acts up. use getin instead.

clrchn   $ffcc (65484)       remember this one! this tells the computer to
				set i/o back to the keyboard/screen, and
				clears the serial bus for future operations.
				despite it's fierce looking name it won't
				harm anything, the files all remain open.
				it's always a good idea to call it *before*
				doing a chkin or chkout, and *after* you
				have finished with the printer, disk, etc.
				not doing so can result in unexpected errors &
				lockups. something like the BASIC 
				print#4,"string1" : print#5,"string2" will
				require clrchn to be called after the first
				command.

readst   $ffb7 (65463)    Returns in .a the number (if any) of an i/o error. It
                          has 2 uses: check for device not present, etc. when
                          opening a file (eg jsr readst : bne <error routine>)
                          and detecting end-of-file (eg jsr readst : and #64 :
                          bne <file close routine>). As you can see, the 64 bit
                          is set on eof.

close    $ffc3 (65475)    Closes the file whose number is in .a.

scnkey   $ff9f (65439)    Returns in .x the ascii value of current key down.
                          You can use this to check the keyboard while the
                          interrupts are disabled, or to bypass the slowness of
                          the key repeating on the 64 (enabled with "poke 650,
                          128"). 255 is returned if no key down.

stop     $ffe1 (65505)    Scan stop key. Usage- jsr stop : bne <nostop> or
                          jsr stop : beq <stop routine>.

restor   $ff8a (65418)    Restores the i/o vectors to their original state.
                          I find it a *great* help in one situation: loading
                          software with fastloading programs/cartridges. If the
                          program loads one big section then runs it and locks
                          up, sys 65418 before running to disable the fastload
                          utility. (Hint: if your fast cartridge won't load a
                          program, find and write down the peeks of locations
                          816 & 817. Then sys 64738 to reset the machine and
                          turn off all speciial functions. If you poke 816 and
                          817 with their old values, you can re-enable the
                          drive speeder uppers alone, which will give you a
                          better chance of the program working.)

load     $ffd5 (65493)    Use: .a must contain a zero for load, or 1 for a
                          verify. The filename and 3 file parameters must have
                          already been set with setnam & setlfs. If the second-
                          ary address from setlfs was zero, a load "---",8 will
                          be done. Any non-zero value for sec.add. will result
                          in a load"---",8,1. Hint: use short M-L routines to
                          avoid the contortions necessary to do multiple loads
                          (eg of spritefiles) from Basic. Calling load from M-L
                          will not restart the Basic program.

save     $ffd8 (65496)    This is the only one whose parameters I *always* have
                          to look up. You can save any section of memory using
                          it. Lots of setup: tell it what name to use first
                          with setnam, then the device #, etc. with setlfs.
                          When save is called, .x and .y contain a pointer (lo-
                          byte, hi-byte) to the *end* of the save (I always
                          save an extra char or two, just to be on the safe
                          side). A similar pointer exists to the *start* of the
                          save. This pointer can be anywhere within the first
                          256 bytes of memory that don't interfere with the
                          system. The .a must then contain the address of that
                          z-page pointer (ie if the pointer is at $fa,$fb as
                          mine usually are, lda #$fa before doing the save).


Avoid the following routines like the plague: the ones described above call
them whenever necessary, so you don't have to worry about them unless you get
into advanced topics (like vector trapping to redirect output to several dev-
ices simultaneously). By the time you can write such a program to do that, you
will also have a handle on these. Until then, *forget them*.
------------
acptr  $ffa5
ciout  $ffa8
clall  $ffe7 (personal dislike)
iobase $fff3
ioinit $ff84
listen $ffb1
second $ff93
settmo $ffa2
talk   $ffb4
tksa   $ff96
unlsn  $ffae
untlk  $ffab
------------

DISCLAIMER: I don't claim to represent Commodore or the Transactor. The above
            opinions are exclusively my own (although I frequently
            force them on other people I know). #;-)

In deference to those who, like myself, read most news at home with a 300-baud
modem, I won't include the usual signature file (it's on net.sources, in 2
parts).  #%-).

John Russell (john13@garfield)