User`s guide

CHAPTER9
MACHINE LANGUAGE PROGRAMS
Here is a list
of
disk-related Kemal ROM subroutines and a practical example
of
th
eir
use in a program which reads a sequential
file
into memory from disk. Note that most
require advance setup
of
one
or
more processor registers
or
memory locations, and all
ar
e
called with the assembly language
JSR command.
For a more complete description as to what each routine does and how parameters are
set for each routine, see the Programmer's Reference Guide for your specific computer.
Label
SETLFS
SETNAM
OPEN
CLOSE
CHKIN
CHKOUT
CLRCHN
CHRIN
CHROUT
START
NEXT
END
FNADR
LDA
LDX
LDY
JSR
LDA
LDX
LDY
JSR
JSR
LDX
JSR
JSR
BEQ
JSR
JMP
LDA
JSR
JSR
RTS
.
BYT
DISK-RELATED KERNAL SUBROUTINES
Address
Function
$FFBA
;SET LOGICAL, FIRST & SECOND ADDRESS
ES
$FFBD
;SET LENGTH & ADDRESS OF FILENAME
$FFCO
;OPEN LOGICAL FILE
$FFC3
;CLOSE LOGICAL FILE
$FFC6
;SELECT CHANNEL FOR INPUT
$FFC9
;SELECT CHANNEL
FOR OUTPUT
$FFCC
;CLEAR ALL CHANNELS &
RESTORE
DEFAULT
UO
$FFCF
;GET BYTE
FROM CURRENT INPUT DEVICE
SFFD2
;OUTPUT BYTE TO CURRENT OUTPUT
DEVICE
#4
;SET LENGTH & ADDRESS
#<FNADR
;OF FILE NAME, LOW
#>FNADR
;&
HIGH BYTES
SET
NAM
;FOR NAME SETTER
#3
;SET FILE NUMBER,
#8
;DISK DEVICE NUMBER,
#0
;AND SECONDARY ADDRESS
SETLFS
;AND SET THEM
OPEN
;OPEN
3,8,0,"TEST"
#3
CHKIN
;SELECT FILE 3
FOR INPUT
CHRIN
;
GET
NEXT BYTE FROM FILE
END
;UNTIL FINISH OR FAIL
CHROUT
;OUTPUT BYTE
TO
SCREEN
NEXT
;AND LOOP BACK FOR MORE
#3
;WHENOONE
CLOSE
;CLOSE
FILE
CLRCHN
;RESTORE DEFAULT UO
;BACK
TO
BASIC
"
TEST"
;STORE FILE NAME HERE
80
APPENDIX
A:
CHANGING
THE
DEVICE NUMBER
SOFTWARE METHOD
One way to temporarily change the device number
of
a disk drive
is
via a program.
When power is first turned on, the drive reads an
I/O location whose value
is
controlled
by a jumper on its circuit board, and writes the device number it reads there into memory
Jocations 119 and
120. Any time thereafter, you may write over that device number with
a new one, which
will
be
effective until
it
is changed again,
or
the 1541 is reset.
FORMAT FOR TEMPORARILY CHANGING THE DISK DEVICE NUMBER:
PRINT#
15
, "M-W"CHR$(119)CHR$(0)CHR$(2)CHR$
(device#+
32)CHR$(device # + 64)
EXAMPLE:
Here is a program that sets any device number from 8-11 :
10
INPUT'NEW
DEVICE NUMBER';DV
20
IF
DV<8
OR
DY>
11
THEN
10
30 OPEN
15
,8,15
40PRINT#15
, "
M-W"CHR$(
l I 9)CHR$(0)CHR$(2)CHR$(DV + 32)CHR$(DV + 64)
50CLOSE
15
Note:
If
you will be using two disk drives, and want to temporarily change the
device number
of
one, you will need to run the above program with the disk drive
whose device number
is
not to be changed turned
off
. After the program has been
run, you may tum that drive back on.
If
you need to connect more than two drives
at once, you will need to
1;1se
the hardware method .
of
changing device numbers,
although you may be able to get by in an emergency by unplugging the serial bus
cable from drives whose device number has already been set while changing others.
This
is
not recommended, however, as there
is
always danger
of
damaging
electronic devices when plugging in cables with the power on.
81