Classic Computer Magazine Archive COMPUTE! ISSUE 11 / APRIL 1981 / PAGE 110

THE OSI® GAZETTE

OSI C1P Control Functions

C. A. Stewart
Adrian, MI

In a previous issue of COMPUTE! a basic poke version of my control function was published. Since that time I have discovered a method to implement a RUN command with a single key stroke much like the PET run key.

The main routine resides in page 2 in this revision (I used page 0 in my previous version but the added functions required relocation) and the one key screen clear resides in page 0. Refer to figure #1 (Flow chart) for discussion of the program functions.

In normal operations locations #536 and #537 contain vectors set by system ROM to the input routine $FFBA in typical 6502 hi/lo order i.e. $BA in location #536 and $FF in location #537. (Note for new computerist the symbol $ in machine language signifies HEX number, not string and the symbol # signifies a decimal number). By changing the vectors in these locations we force the system into our routine first and then return control to the ROM, to implement in this example we poke #536 with #128 and #537 with #002 (POKE536, 128 : POKE537, 2) in one command line! It should be noted that a break warm start will require this poke command line since a warm start re-initializes these vectors.

A useful basic program for HEX to DEC and DEC to HEX is included in listing #3 for readers without tables or a TI HEX calculator.

When the routine starts we go to the input subroutine $0280 which jumps to $FFBA (input a character) and compare to the following.

Control L Load command
Control S Save command
Control A Run Command
Escape Key List command
Rubout Key Screen Clear

If any of the comparisons are true then the appropriate subroutine in ROM is called, otherwise normal program operation continues. I chose Control A for the Run function for two reasons. First the logical choice, Control r, is utilized for a remove in the cursor control package I have in ROM and because of its location next to the control key. The command keys can be changed to whatever the user requires by replacing the compare data with the appropriate key numbers. Control A = $01 and follows thru with control Z = #26. (see graphics manual.)

Listing #1 is the machine language routine. Listing #2 is the BASIC poke program. The machine language screen clear is callable in BASIC via the USR function. To use load and run, code erases itself, leaving the machine code in page 0 and 2, and doesn't require any normal usable memory.

D8            PHA
D9            LDA #$20 ; LOAD SPACE CHR
DB            LDX #$00 ; LOAD ACCX W/0
DD   HERE     STA $D000, X ; STORE SPACE CH
R ON SCREEN
E0            STA $D100, X
E3            STA $D200, X
E6            STA $D300, X
E9            INX        ; INC X
EA            BNE HERE   ; BRANCH TO $DD I
F NOT EQUAL TO 0
EC            PLA
ED            RTS
280        JSR $FFBA ; JUMP TO INPUT SUBROUTINE $FEED ON C4P
283        CMP #$0C ; COMPARE TO CONT L
285        BNE CONT S ; BRANCH TO CONTROL S
287        JSR $FF8B ; EXCUTE LOAD COMMAND
28A CONT S CMP #$13 ; COMPARE TO CONTROL S
28C        BNE RUB ;
28E        JSR $FF96 ; EXCUTE SAVE COMMAND
291 RUB    CMP #$7F ; COMPARE TO RUBOUT
293        BNE ESC ;
295        JMP $D8 ; EXCUTE SCREEN CLEAR
298 ESC    CMP #$1B ; COMPARE W/ESCAPE
29A        BNE RUN ;
29C        JMP $A4B5 ; EXCUTE LIST
29F RUN    CMP #$01 ; COMPARE W/CONT A2A1 BNE END   ;
2A3 JSR $A477 ; INITALIZE ROUTINE
2A6 JSR $A5C2 ; RUN ROUTINE
2A9 END RTS   ;

Listing 1

10 REM MACHINE LANG SUBROUTINE FOR OSI C1P/C4P
20 REM CHARLES A. STEWART
30 REM 3033 MARVIN DR.
40 REM ADRIAN, MICH 49221
60 FOR X = 640TO681 : READA : POKEX, A : NEXT
65 REM FOR C4P LINE 70 CHANGE 186, 255 TO 237, 254
70 DATA32, 186, 255, 201, 12, 208, 3, 32, 139, 255, 201
80 DATA19, 208, 3, 32, 150, 255, 201, 127, 208, 3, 76
90 DATA216, 0, 201, 27, 208, 3, 76, 181, 164
100 DATA201, 1, 208, 6, 32, 119, 164, 32, 194, 165, 96
110 FORX = 216TO237 : READA : POKEX, A : NEXT
120 DATA72, 169, 32, 162, 0, 157, 0, 208, 157, 0, 209, 157, 0, 210
130 DATA157, 0, 211, 232, 208, 241, 104, 96
150 POKE11, 216 : POKE12, 0 : POKE536, 128 : POKE537, 2
160 PRINT " * CONTROL VERSION #1" : PRINT " * BY CHARLES A. STEWART"
165 PRINT : PRINT
170 PRINT "ESC LISTS" : PRINT "RUBOUT GIVES SCREEN CLEAR
180 PRINT "CONTROL S = SAVE" : PRINT "CONTROL L = LOAD
185 PRINT "CONTROL A RUNS PROGRAM
200 NEW

Figure #1

Listing 2

10 REM CHARLES A. STEWART
20 REM 3033 MARVIN DR.
30 REM ADRIAN MI 49221
40 REM 517-265-4798
50 REM NOVEMBER 22, 1980
60 REM DEC TO HEX AND HEX TO DEC CONVERSON PROGRAM
100 DIMA$(16), S$(16)  :  FORX = 1 TO 16 : READA$(X)  :  READS$(X) : NEXT
110 DATA 0000, 0, 0001, 1, 0010, 2, 0011, 3, 0100, 4, 0101, 5, 0110, 6
120 DATA 0111, 7, 1000, 8, 1001, 9, 1010, A, 1011, B, 1100, C, 1101, D, 1110, E
130 DATA 1111, F
135 S$ = "0123456789ABCDEF"
140 POKE 11,  0 : POKE12, 253 : X = 0 : Y = 0 : W = 0  : Q = 0 : I = 0 : E$ = "0"
150 FOR X = OTO40 : PRINT : NEXT : PRINT "A > DECIMAL TO HEX" : PRINT
160 PRINT "B > HEX TO DECIMAL" : PRINT : PRINT "YOUR SELECTION" : X = USR(X)
170 IFPEEK(531) = 65THENPRINT "DEC TO HEX CONVERSION" : GOTO3010
180 IFPEEK(531) = 66THENPRINT"HEX TO DEC CONVERSION" : GOTO2010
190 GOTO150
2010 PRINT : INPUT "HEX NUMBER" I$ : IFLEN(I$))4THEN2010
2020 IF LEN(I$)< > 4THEN1$ = E$ + I$ : GOTO2020
2040 FOR X = 1 TO 4 : FOR Y = 1 TO 16
2050 IFMID$(I$, X, 1) = MID$(S$, Y, 1) THENB$(X) = A$(Y)
2060 NEXT Y : NEXT X
2070 B1$ = B$ (1) + B$(2) + B$(3) + B$(4)
2080 PRINT : PRINT I$" IN BINARY = " PRINTB1$
2100 X = 1 : W = 0 : Q = LEN(B1$) : I = 0
2120 Y$ = MID$(D1$, Q, 1) : Y = VAL(Y$)  :  I = Y * X : W = W + I : X = X * 2
2130 Q = Q  1  : IFQ < > 0GOTO2120  /
2140 PRINT : PRINTI$" IN DECIMAL = " ; W
2150 PRINT : PRINT "TYPE ANY KEY TO CONTINUE" : X = USR(X) : GOTO2010
3010 PRINT : INPUT "DECIMAL NUMBER"; I$ : I = VAL(I$) : Y$ = " " Y = 65536
3012 Y = Y/2
3015 IFI>65535THENPRINT : PRINT"TOO LARGE " : GOTO2150
3030 X = INT(I/Y) : IFX = 0THENY$ = Y$ + "0" GOTO 3050
3040 Y$ = Y$ + "1" : I = I  Y
3050 Y = Y/2 : IFINT(Y) = 0THEN3200
3060 GOTO3030
3200 PRINT  : PRINT$ "IN BINARY = " PRINTY$
3210 X = 2 : Y = 4
3215 RE$ = " "
3220 A$ = MID$(Y$, X, Y) : FOR W = 1 TO 16 : IFA$ = A$(W)THENRE$ = RE$ + S$(W) : GOTO3240
3230 NEXT W
3240 X = X + 4 : IF X> 14THENGOTO3260
3250 GOTO3220
3260 PRINT : PRINTI$" IN HEX=" ; RE$
3265 PRINT "TYPE ANY KEY TO CONTINUE" : X = USR(X) : GOTO3010
OK

Listing 3