Boot 64 For 128
Mike Tranchemontagne
Most Commodore 128 owners know that their computer can automatically load and run any 128 program from disk. This easy-to-use program adds the same convenience for Commodore 64 programs as well, allowing the 128 to load and run any 64 program automatically when you boot the system. A disk drive is required.
The Commodore 128 has many outstanding features, not the least of which is its ability to run thousands of excellent Commodore 64 programs and games. The 128 can automatically load and run any program written for 128 mode or CP/M mode. Although there are programs for the 64 that automatically run after loading from disk, it's still necessary to type in a command like LOAD "PROGRAM", 8, 1 to activate the disk drive in 64 mode. "Boot 64 For 128" automates this process so that you can load and run any Commodore 64 program simply by putting the disk in the drive and turning on the computer. This feature is ideal for younger members of the family or infrequent computer users. Even experienced programmers will appreciate the extra convenience it affords.
Creating An Autoboot Disk
Type in Programs 1, 2, and 3, and save copies of all three programs. For the boot sector created by Program 2 to work properly, you must use the filename 128BOOT64 when saving Program 1. To create an autobooting disk for 64 mode, follow these three steps:
1. Select the disk which will contain the 64 program you want to load and run automatically. Load Program 2, insert the disk in the drive, and run the program. When Program 2 is finished, the disk contains a 128 boot sector that will cause the computer to load and run a program named 128BOOT64. (You do not need to save Program 2 on the target disk.)
2. Load Program 1 and save it on the disk. Remember, you must save this program with the file-name 128BOOT64.
3. Load the 64 program which you want to load and run automatically; then save it on the disk using the filename BOOT64. You must save the program with this filename.
Once you've performed all three steps, place the disk in the drive and reboot by turning the power off and on or by pressing the reset switch. If the computer does not load and run the desired program, check Programs 1 and 2 for typing errors and repeat the process. Keep in mind that the process won't work unless you use the filenames noted above.
Autobooting ML Programs
With this technique, you can load and run any Commodore 64 BASIC program. The same is true of any machine language program that runs like BASIC. For instance, SpeedScript, COMPUTE!'s word processor, ordinarily starts with LOAD"SPEEDSCRIPT", 8 and RUN. To autoboot and run SpeedScript, simply save SpeedScript to disk with the filename BOOT64 as described in Step 3.
You can also autoboot and start a machine language program that normally loads with ,8,1 and starts with SYS instead of RUN. Program 3 is a very short BASIC loader which loads an ML program into memory, then activates it with SYS. As listed, the program loads and starts DOS 5.1, the DOS Wedge program supplied on the 1541/1571 Test/Demo disk. To load a different ML program, replace the name DOS 5.1 in line 20 with the filename of your program, and replace the address 52224 in line 30 with the correct SYS address for the program. When that's done, perform steps 1 and 2 as described earlier; then save Program 3 on the disk with the filename BOOT64. Of course, you must also copy the ML program to the same disk, using the filename you specified in line 20 of Program 3.
How Autobooting Works
When you turn on the 128 (or reboot by pressing the reset button), the computer automatically performs several checks to determine which mode it will operate in. If an autostart cartridge is plugged into the cartridge port, the cartridge takes control. If the Commodore key is pressed, the computer enters 64 mode. If the STOP key is pressed, the 128 enters the built-in machine language monitor.
If none of these conditions applies, the 128 looks on sector 0 of track 1 of the current disk (known as the boot sector) to see whether it contains a boot header. If no boot header is found, the computer simply starts BASIC, which produces the familiar READY prompt. However, if the boot header information is present, the 128 automatically loads and runs the program indicated in the boot sector. This process works equally well with a 1571 or 1541 disk drive.
In 128 mode, the 128 can switch to 64 mode by performing the command GO64. However, there is no provision for loading and running a program after you enter 64 mode. To achieve the same effect, this program creates a boot sector that tells the computer to load and run the program 128BOOT64. That program, in turn, stores a short machine language program and cartridge-identifier bytes in the special memory area where Commodore 64 autostarting cartridges normally reside. The ML program causes the computer (now in 64 mode) to perform a normal reset. When the reset occurs, the computer detects the cartridge-identifier bytes, concludes that a cartridge is present, and runs the ML routine found at the cartridge start address. This program, in turn, uses the dynamic keyboard technique to load and run a program named BOOT64 from disk. The process may seem complicated, but it all happens very quickly, and you need not understand the details in order to take advantage of it.
For instructions on entering these listings, please refer to "COMPUTE!'s Guide to Typing In Programs" in this issue of COMPUTE!.
Program 1: 128BOOT64
10 A = 32768: PRINT "(SWITCH {SPACE40 COLUMN DISPLAY) "
20 READ D$: IF D$ = "-1" THEN GO64
30 POKE A, DEC (D$):A = A + 1: GO TO 20
40 DATA 09, 80, 5E, FE, C3, C2, C, D, 38, 30
50 DATA 8E, 16, D0, 20, A3, FD, 20, 50, FD
60 DATA 20, 15, FD, 20, 5B, FF, 58
70 DATA 20, 53, E4, 20, BF, E3, 20, 22, E4
80 DATA A2, FB, 9A
90 DATA A2, 00, BD, 41, 80, F0, 06
100 DATA 20, D2, FF, E8, D0, F5
110 DATA A9, 0D, 8D, 77, 02, 8D, 78, 02
120 DATA A9, 02, 85, C6
130 DATA 4C, 74, A4
140 DATA 0D, 4C, 4F, 41, 44, 22, 42, 4F, 4F, 54, 36, 34, 22, 2C, 38
150 DATA 0D, 0D, 0D, 0D, 0D, 52, 55, 4E, 91, 91, 91, 91, 91, 91, 91, 0, -1
Program 2: Boot sector Maker
10 REM PROGRAM 2, CREATE BOOT SECTOR FOR 128BOOT64
20 DCLEAR: OPEN 15, 8, 15: OPEN 2, 8, 2, "#": PRINT# 15, "B-P:2, 0"
30 READ D$: D = DEC(D$): IF D>255 THEN 50
40 PRINT# 2, CHR$(D); : GOTO \ 0
50 PRINT# 15, "U2;2, 0, 1, 0"
60 PRINT DS$ : CLOSE 2 : CLOSE 15
70 DATA 43, 42, 4D, 00, 00, 00, 00, 31, 32, 38, 42, 4F, 4F, 54, 36, 34, 00, 00, A2, 18
80 DATA A0, 0B, 4C, A5, AF, 52, 55, 4E, 22, 31, 32, 38, 42, 4F, 4F, 54, 36, 34, 00, 100
Program 3: ML Loader
10 REM C64 ML PROG LOADER EXAMPLE
20 IF A = 0 THEN A = 1: LOAD "DOS 5.1", 8, 1
30 SA = 52224: REM START ADDRESS
40 SYS SA
Extended Keyboard Use on the C-128 in C-64 Mode
Dave Kline 07/01/00 McGraw/Hill
Because extra registers are present in the C-64 mode on the C-128, you
can use the C-128 extended keyboard in C-64 mode. A routine using the three
extra keyscan lines at location $D02F follows. This routine wedges itself
into the IRQ interrupt routine by diverting the IRQ vector at $0314/$0315
to point to the code. Note that to scan a given column in the key matrix
(say, that connected to the K0 line), the output line is held low (logical
zero); matrix columns that are not being scanned should have their
respective output lines held high (logical one). (This is merely a
Commodore convention; another manufacturer's system might scan a keyboard
similarly but would reverse the process -- scanned key matrix column output
lines would be held high, while unscanned ones would be held low.)
This ML routine can be entered with the C-128's monitor but is executed
while in C-64 mode. The routine is called by SYS51968. To deactivate,
press RUN-STOP/RESTORE. (Note, other routines that use this memory area
while cause conflicts.)
SEI ; DISABLE INTERRUPTS.
LDY #$CB ; DIRECT IRQ VECTOR TO CODE AT $CBOD.
LDX #$0D
STY $0315
STX $0314
CLI ; ENABLE INTERRUPTS.
RTS ; RETURN TO CALLER.
$CB0D
LDX #$F8 ; %1111 1000
STX $D02F ; ALL 3 EXTENDED KB OUTPUT LINES ACTIVE.
LDA #$FF
STA $DC00 ; CIA #1'S DDR SET FOR ALL 8 LINES AS INPUTS.
CMP $DC01 ; NOT = $FF? KEY HELD DOWN,
BNE $CB22 ; SO PROCESS IT.
STA $D02F ; ELSE ALL KB OUTPUT LINES INACTIVE.
JMP $EA31 ; JUMP TO NORMAL IRQ HANDLER CODE.
$CB22
LDA #$FB ; %1111 10111 ... K2'S COLUMN SCANNED FIRST.
STA $D02F
LDX #$00 ; ZERO SHIFT/CTRL/CBM FLAG.
STX $028D
LDY #$08 ; COUNTER ... 8 ROWS TO TEST.
LDA $DC01 ; READ INPUT PORT.
CMP $DC01 ; VALUE CHANGING?
BNE $CB2E ; YES, LOOP AGAIN FOR ANOTHER READ.
CMP #$FF ; ANY KEYS IN THIS COLUMN DEPRESSED?
BNE $CB44 ; YES, PROCESS KEYSTROKE.
CLC ; CLEAR .C TO PREPARE FOR ADD.
TXA ; GET KEY NUMBER (INDEX) AND
ADC #$08 ; ADD 8 SINCE WE CAN SKIP THIS COLUMN.
TAX ; PUT INDEX BACK WHERE IT BELONGS.
ROR $D02F ; NOW K1 HELD LOW (%1111 1101).
BNE $CB2C ; ZERO? NO WAY! WE'RE FORCING A JUMP
; TO $CB2C TO SCAN THE NEXT COLUMN.
$CB44
LSR ; PROCESS KEYSTROKE ... SHIFT BITS INTO .C .
BCC $CB50 ; IF .C = 0 KEY STRUCK, SO WE QUIT SCANNING.
INX ; BUMP KEY INDEX COUNTER.
DEY ; DECREMENT ROW COUNTER.
BNE $CB44 ; 8 ROWS DONE? NO, THEN LOOP AGAIN.
ROR $D02F ; PREPARE TO SCAN NEXT COLUMN. (KN=0)
LDA $CB69,X ; LOOK UP C-64 KEYCODE FROM TABLE.
BPL $CB5C ; IF HI-BIT (#7) SET, IT'S <SHIFT>ED,
LDY #$01 ; SO WE SET SHIFT FLAG.
STY $028D
AND #$7F ; AND LOP OFF BIT#7 TO GET TRUE C-64 KEYCODE.
STA $CB ; SAVE KEYCODE.
LDX $FF
STX $D02F ; DEACTIVATE EXTENDED KEYSCAN LINES.
JSR $EADD ; CONVERT KEYCODE TO ASCII BYTE, PLACE IN BUFFER.
JMP $EA7E ; RESTORE REGISTER CONTENTS & RETURN FROM IRQ.
$CB69 40 23 2C 87 07 82 02 40 40 28 28 40 01 13 20 08
$CB79 40 1B 10 40 3B 0B 18 38 40
Or copy this BASIC program:
10 for x=49152t049185:read z:pokex,z:ck=ck+z:next
15 for x=x to 49285:poke x,peek(x+10770):next
20 poke49258,117:poke49259,192
25 for x=xt049454:read z:pokex,z:ck=ck+z:next
30 ifck<>26162thenprint"error in data lines...":end
35 print"it's magic1 128 keypad keys now active. "
40 print"[no scroll] and cursor keys, too.":sys49152:new
45 data 120,169,23,141,20,3,169,192,141,21,3,169,24,141,38,3,169,193,141,39
50 data 3,88,96,32,234,255,173,216,192,240,3,206,216,192,240,6,32,39,193,76
55 data 154,234,168,32,13,193,208,6,142,47,208,76,38,235,169,254,141,47,208
60 data 162,8,72,173,1,220,205,1,220,208,248,74,144,21,200,192,25,208,5,104
65 data 162,255,208,221,202,208,240,56,104,42,141,47,208,208,221,104,185
70 data 245,192,170,41,127,160,255,140,47,208,201,1,208,20,32,13,193,208
75 data 251,169,0,240,8,173,34,193,73,1,141,34,193,76,148,192,200,217,129
80 data 235,208,250,132,203,32,39,193,138,76,228,234,255,56,53,255,50,52,55
85 data 49,255,43,45,255,13,54,57,51,255,48,46,145,17,157,29,1,169,0,141,47
90 data 208,174,1,220,224,255,96,32,202,241,72,169,5,141,216,192,169,0,208
95 data 247,104,96,72,169,0,141,34,193,104,96
Here's standard keyboard matrix of Commodore 64