-
Notifications
You must be signed in to change notification settings - Fork 78
/
kernal_ld.txt
434 lines (284 loc) · 23.3 KB
/
kernal_ld.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
- C64 KERNAL API (Lee Davison)
-
- The almost completely commented C64 ROM disassembly. V1.01 Lee Davison 2012
-
- Corrections (typos as well as content), translations etc.
- welcome at: https://github.com/mist64/c64ref
-
----------------------------------------------
-
# This plain text file is formatted so that it can be automatically
# parsed in order to create cross-references etc.
# * Lines starting with "-" is top-level information. The first line
# is the title. Lines starting with "--" are separators.
# * Lines starting with "#" are internal comments.
# * Hex addresses start at column 0.
# * Symbols start at column 7.
# * The description starts at column 15.
# * All lines of the description until the first blank line are
# combined into the heading.
# * The remaining text is in MarkDown format.
# The encoding is UTF-8.
$FF81 initialise VIC and screen editor
$FF84 initialise SID, CIA and IRQ, unused
$FF87 RAM test and find RAM end
$FF8A restore default I/O vectors
This routine restores the default values of all system vectors used in KERNAL and
BASIC routines and interrupts.
$FF8D read/set vectored I/O
This routine manages all system vector jump addresses stored in RAM. Calling this
routine with the carry bit set will store the current contents of the RAM vectors
in a list pointed to by the X and Y registers. When this routine is called with
the carry bit clear, the user list pointed to by the X and Y registers is copied
to the system RAM vectors.
NOTE: This routine requires caution in its use. The best way to use it is to first
read the entire vector contents into the user area, alter the desired vectors and
then copy the contents back to the system vectors.
$FF90 control kernal messages
This routine controls the printing of error and control messages by the KERNAL.
Either print error messages or print control messages can be selected by setting
the accumulator when the routine is called.
FILE NOT FOUND is an example of an error message. PRESS PLAY ON CASSETTE is an
example of a control message.
Bits 6 and 7 of this value determine where the message will come from. If bit 7
is set one of the error messages from the KERNAL will be printed. If bit 6 is set
a control message will be printed.
$FF93 send secondary address after LISTEN
This routine is used to send a secondary address to an I/O device after a call to
the LISTEN routine is made and the device commanded to LISTEN. The routine cannot
be used to send a secondary address after a call to the TALK routine.
A secondary address is usually used to give set-up information to a device before
I/O operations begin.
When a secondary address is to be sent to a device on the serial bus the address
must first be ORed with $60.
$FF96 send secondary address after TALK
This routine transmits a secondary address on the serial bus for a TALK device.
This routine must be called with a number between 4 and 31 in the accumulator.
The routine will send this number as a secondary address command over the serial
bus. This routine can only be called after a call to the TALK routine. It will
not work after a LISTEN.
$FF99 read/set the top of memory
This routine is used to read and set the top of RAM. When this routine is called
with the carry bit set the pointer to the top of RAM will be loaded into XY. When
this routine is called with the carry bit clear XY will be saved as the top of
memory pointer changing the top of memory.
$FF9C read/set the bottom of memory
This routine is used to read and set the bottom of RAM. When this routine is
called with the carry bit set the pointer to the bottom of RAM will be loaded
into XY. When this routine is called with the carry bit clear XY will be saved as
the bottom of memory pointer changing the bottom of memory.
$FF9F scan the keyboard
This routine will scan the keyboard and check for pressed keys. It is the same
routine called by the interrupt handler. If a key is down, its ASCII value is
placed in the keyboard queue.
$FFA2 set timeout on serial bus
This routine sets the timeout flag for the serial bus. When the timeout flag is
set, the computer will wait for a device on the serial port for 64 milliseconds.
If the device does not respond to the computer's DAV signal within that time the
computer will recognize an error condition and leave the handshake sequence. When
this routine is called and the accumulator contains a 0 in bit 7, timeouts are
enabled. A 1 in bit 7 will disable the timeouts.
NOTE: The the timeout feature is used to communicate that a disk file is not found
on an attempt to OPEN a file.
$FFA5 input byte from serial bus
This routine reads a byte of data from the serial bus using full handshaking. the
data is returned in the accumulator. before using this routine the TALK routine,
$FFB4, must have been called first to command the device on the serial bus to
send data on the bus. if the input device needs a secondary command it must be sent
by using the TKSA routine, $FF96, before calling this routine.
Errors are returned in the status word which can be read by calling the READST
routine, $FFB7.
$FFA8 output a byte to serial bus
This routine is used to send information to devices on the serial bus. A call to
this routine will put a data byte onto the serial bus using full handshaking.
Before this routine is called the LISTEN routine, $FFB1, must be used to
command a device on the serial bus to get ready to receive data.
The accumulator is loaded with a byte to output as data on the serial bus. A
device must be listening or the status word will return a timeout. This routine
always buffers one character. So when a call to the UNLISTEN routine, $FFAE,
is made to end the data transmission, the buffered character is sent with EOI
set. Then the UNLISTEN command is sent to the device.
$FFAB command serial bus to UNTALK
This routine will transmit an UNTALK command on the serial bus. All devices
previously set to TALK will stop sending data when this command is received.
$FFAE command serial bus to UNLISTEN
This routine commands all devices on the serial bus to stop receiving data from
the computer. Calling this routine results in an UNLISTEN command being transmitted
on the serial bus. Only devices previously commanded to listen will be affected.
This routine is normally used after the computer is finished sending data to
external devices. Sending the UNLISTEN will command the listening devices to get
off the serial bus so it can be used for other purposes.
$FFB1 command devices on the serial bus to LISTEN
This routine will command a device on the serial bus to receive data. The
accumulator must be loaded with a device number between 4 and 31 before calling
this routine. LISTEN convert this to a listen address then transmit this data as
a command on the serial bus. The specified device will then go into listen mode
and be ready to accept information.
$FFB4 command serial bus device to TALK
To use this routine the accumulator must first be loaded with a device number
between 4 and 30. When called this routine converts this device number to a talk
address. Then this data is transmitted as a command on the Serial bus.
$FFB7 read I/O status word
This routine returns the current status of the I/O device in the accumulator. The
routine is usually called after new communication to an I/O device. The routine
will give information about device status, or errors that have occurred during the
I/O operation.
$FFBA set logical, first and second addresses
This routine will set the logical file number, device address, and secondary
address, command number, for other KERNAL routines.
the logical file number is used by the system as a key to the file table created
by the OPEN file routine. Device addresses can range from 0 to 30. The following
codes are used by the computer to stand for the following CBM devices:
| ADDRESS | DEVICE |
|---------|---------------------------|
| 0 | Keyboard |
| 1 | Cassette #1 |
| 2 | RS-232C device |
| 3 | CRT display |
| 4 | Serial bus printer |
| 8 | CBM Serial bus disk drive |
Device numbers of four or greater automatically refer to devices on the serial
bus.
A command to the device is sent as a secondary address on the serial bus after
the device number is sent during the serial attention handshaking sequence. If
no secondary address is to be sent Y should be set to $FF.
$FFBD set the filename
This routine is used to set up the file name for the OPEN, SAVE, or LOAD routines.
The accumulator must be loaded with the length of the file and XY with the pointer
to file name, X being th low byte. The address can be any valid memory address in
the system where a string of characters for the file name is stored. If no file
name desired the accumulator must be set to 0, representing a zero file length,
in that case XY may be set to any memory address.
$FFC0 open a logical file
This routine is used to open a logical file. Once the logical file is set up it
can be used for input/output operations. Most of the I/O KERNAL routines call on
this routine to create the logical files to operate on. No arguments need to be
set up to use this routine, but both the SETLFS, $FFBA, and SETNAM, $FFBD,
KERNAL routines must be called before using this routine.
$FFC3 close a specified logical file
This routine is used to close a logical file after all I/O operations have been
completed on that file. This routine is called after the accumulator is loaded
with the logical file number to be closed, the same number used when the file was
opened using the OPEN routine.
$FFC6 open channel for input
Any logical file that has already been opened by the OPEN routine, $FFC0, can be
defined as an input channel by this routine. the device on the channel must be an
input device or an error will occur and the routine will abort.
If you are getting data from anywhere other than the keyboard, this routine must be
called before using either the CHRIN routine, $FFCF, or the GETIN routine,
$FFE4. if you are getting data from the keyboard and no other input channels are
open then the calls to this routine and to the OPEN routine, $FFC0, are not needed.
When used with a device on the serial bus this routine will automatically send the
listen address specified by the OPEN routine, $FFC0, and any secondary address.
Possible errors are:
* 3 : file not open
* 5 : device not present
* 6 : file is not an input file
$FFC9 open channel for output
Any logical file that has already been opened by the OPEN routine, $FFC0, can be
defined as an output channel by this routine the device on the channel must be an
output device or an error will occur and the routine will abort.
If you are sending data to anywhere other than the screen this routine must be
called before using the CHROUT routine, $FFD2. if you are sending data to the
screen and no other output channels are open then the calls to this routine and to
the OPEN routine, $FFC0, are not needed.
When used with a device on the serial bus this routine will automatically send the
listen address specified by the OPEN routine, $FFC0, and any secondary address.
Possible errors are:
* 3 : file not open
* 5 : device not present
* 7 : file is not an output file
$FFCC close input and output channels
This routine is called to clear all open channels and restore the I/O channels to
their original default values. It is usually called after opening other I/O
channels and using them for input/output operations. The default input device is
0, the keyboard. The default output device is 3, the screen.
If one of the channels to be closed is to the serial port, an UNTALK signal is sent
first to clear the input channel or an UNLISTEN is sent to clear the output channel.
By not calling this routine and leaving listener(s) active on the serial bus,
several devices can receive the same data from the VIC at the same time. One way to
take advantage of this would be to command the printer to TALK and the disk to
LISTEN. This would allow direct printing of a disk file.
$FFCF input character from channel
This routine will get a byte of data from the channel already set up as the input
channel by the CHKIN routine, $FFC6.
If CHKIN, $FFC6, has not been used to define another input channel the data is
expected to be from the keyboard. the data byte is returned in the accumulator. the
channel remains open after the call.
Input from the keyboard is handled in a special way. first, the cursor is turned on
and it will blink until a carriage return is typed on the keyboard. all characters
on the logical line, up to 80 characters, will be stored in the BASIC input buffer.
then the characters can be returned one at a time by calling this routine once for
each character. when the carriage return is returned the entire line has been
processed. the next time this routine is called the whole process begins again.
$FFD2 output character to channel
This routine will output a character to an already opened channel. Use the OPEN
routine, $FFC0, and the CHKOUT routine, $FFC9, to set up the output channel
before calling this routine. If these calls are omitted, data will be sent to the
default output device, device 3, the screen. The data byte to be output is loaded
into the accumulator, and this routine is called. The data is then sent to the
specified output device. The channel is left open after the call.
NOTE: Care must be taken when using routine to send data to a 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 actually intended
destination channel must be closed by a call to the KERNAL close channel routine.
$FFD5 load RAM from a device
This routine will load data bytes from any input device directly into the memory
of the computer. It can also be used for a verify operation comparing data from a
device with the data already in memory, leaving the data stored in RAM unchanged.
The accumulator must be set to 0 for a load operation or 1 for a verify. If the
input device was OPENed with a secondary address of 0 the header information from
device will be ignored. In this case XY must contain the starting address for the
load. If the device was addressed with a secondary address of 1 or 2 the data will
load into memory starting at the location specified by the header. This routine
returns the address of the highest RAM location which was loaded.
Before this routine can be called, the SETLFS, $FFBA, and SETNAM, $FFBD,
routines must be called.
$FFD8 save RAM to a device
This routine saves a section of memory. Memory is saved from an indirect address
on page 0 specified by A, to the address stored in XY, to a logical file. The
SETLFS, $FFBA, and SETNAM, $FFBD, routines must be used before calling this
routine. However, a file name is not required to SAVE to device 1, the cassette.
Any attempt to save to other devices without using a file name results in an error.
NOTE: device 0, the keyboard, and device 3, the screen, cannot be SAVEd to. If
the attempt is made, an error will occur, and the SAVE stopped.
$FFDB set the real time clock
The system clock is maintained by an interrupt routine that updates the clock
every 1/60th of a second. The clock is three bytes long which gives the capability
to count from zero up to 5,184,000 jiffies - 24 hours plus one jiffy. At that point
the clock resets to zero. Before calling this routine to set the clock the new time,
in jiffies, should be in YXA, the accumulator containing the most significant byte.
$FFDE read the real time clock
This routine returns the time, in jiffies, in AXY. The accumulator contains the
most significant byte.
$FFE1 scan the stop key
If the STOP key on the keyboard is pressed when this routine is called the Z flag
will be set. All other flags remain unchanged. If the STOP key is not pressed then
the accumulator will contain a byte representing the last row of the keyboard scan.
The user can also check for certain other keys this way.
$FFE4 get character from input device
In practice this routine operates identically to the CHRIN routine, $FFCF,
for all devices except for the keyboard. If the keyboard is the current input
device this routine will get one character from the keyboard buffer. It depends
on the IRQ routine to read the keyboard and put characters into the buffer.
If the keyboard buffer is empty the value returned in the accumulator will be zero.
$FFE7 close all channels and files
This routine closes all open files. When this routine is called, the pointers into
the open file table are reset, closing all files. Also the routine automatically
resets the I/O channels.
$FFEA increment real time clock
This routine updates the system clock. Normally this routine is called by the
normal KERNAL interrupt routine every 1/60th of a second. If the user program
processes its own interrupts this routine must be called to update the time. Also,
the STOP key routine must be called if the stop key is to remain functional.
$FFED return X,Y organization of screen
This routine returns the x,y organisation of the screen in X,Y
$FFF0 read/set X,Y cursor position
This routine, when called with the carry flag set, loads the current position of
the cursor on the screen into the X and Y registers. X is the column number of
the cursor location and Y is the row number of the cursor. A call with the carry
bit clear moves the cursor to the position determined by the X and Y registers.
$FFF3 return the base address of the I/O devices
This routine will set XY to the address of the memory section where the memory
mapped I/O devices are located. This address can then be used with an offset to
access the memory mapped I/O devices in the computer.