0100 ;*******************************›0110 ;›0120 ; C-KEY›0130 ;    a control key utility›0140 ;    for all Atari 8-bits›0150 ;›0160 ; v1.5 06-10-91  by Doug Wokoun›0170 ;›0171 ; Program and source code is›0172 ; Copyright 1991 by Doug Wokoun›0173 ; See READ.ME file for›0174 ; conditions›0175 ;›0180 ;*******************************›0190 ;›0200 ; Equates›0210 DOSINI = $0C    ; reset key vec›0220 BRKKEY = $11    ; break key flag›0230 RTCLOK = $12    ; real-time clock›0240 ATRACT = $4D    ; attract timer›0250 VKEYBD = $0208  ; keyboard vector›0260 SDMCTL = $022F  ; DMA control›0270 MEMLO = $02E7   ; bottom of memory›0280 CRSINH = $02F0  ; cursor inhibit›0290 SSFLAG = $02FF  ; [un]lock output›0300 ICHID = $0340   ; device ID›0310 ICCOM = $0342   ; command byte›0320 ICBAL = $0344   ; filename address›0330 ICBAH = $0345›0340 ICBLL = $0348   ; transfer length›0350 ICAX1 = $034A   ; auxiliary byte 1›0360 CONSOL = $D01F  ; console buttons›0370 AUDF1 = $D200   ; frequency 1›0380 AUDC1 = $D201   ; control 1›0390 AUDCTL = $D208  ; audio control›0400 KBCODE = $D209  ; keyboard code›0410 SKCTL = $D20F   ; serial port ctl›0420 CIOV =  $E456   ; CIO vector›0430 COLDSV = $E477  ; cold start vec›0440 ;›0450     *=  $3800›0460 ;›0470 ; Print the program identification›0480 ; message always›0490 ;›0500     LDX #0      ; channel 0›0510     LDA #9      ; put text command›0520     STA ICCOM›0530     LDA # <MSG  ; message address›0540     STA ICBAL›0550     LDA # >MSG›0560     STA ICBAH›0570     LDA #255    ; message length›0580     STA ICBLL   ;  (overkill)›0590     JSR CIOV    ; print it›0600 ;›0610 ; Now to check to see if the›0620 ; program is already installed›0630 ; so we don't have a bunch of›0640 ; copies in memory...to do this›0650 ; we'll use the very accurate›0660 ; method of sampling one byte›0670 ; of code›0680 ;›0690     LDA VKEYBD  ; get address of›0700     STA 203     ;  current key›0710     LDA VKEYBD+1 ;  routine›0720     STA 204›0730     LDY #5      ; check 6th byte›0740     LDA (203),Y›0750     CMP #2      ; from 'AND #2'›0760     BNE NOTINS›0770 ; so I guess we can assume it's›0780 ; already loaded...exit stage›0790 ; right...›0800     RTS ›0810 ; in case it isn't loaded...›0820 NOTINS›0830 ; Plug values into program...›0840     CLC ›0850     LDA MEMLO›0860     STA $CB›0870     STA DOSINIT+24›0880     ADC #DOSINIT-START›0890     STA DOSINIT+4›0900     STA INSTALL+1›0910     LDA MEMLO+1›0920     STA $CC›0930     STA DOSINIT+29›0940     ADC #0›0950     STA DOSINIT+8›0960     STA INSTALL+2›0970     LDA DOSINI›0980     STA DOSINIT+1›0990     LDA DOSINI+1›1000     STA DOSINIT+2›1010 ;›1020 ; An improvement over previous›1030 ; versions, this one will not›1040 ; crash if you do a KEY command›1050 ; and then [RESET] in SpartaDOS.›1060 ; When reinstalling, it always›1070 ; gets the new VKEYBD address.›1080 ; KEY will still disable it until›1090 ; the next [RESET].  This loads›1100 ; registers for reinstallation.›1110 ;›1120     CLC ›1130     LDA MEMLO›1140     ADC #VEC-START+1›1150     STA V1+1›1160     LDA MEMLO+1›1170     ADC #0›1180     STA V1+2›1190     LDA V1+1›1200     ADC #1›1210     STA V2+1›1220     LDA V1+2›1230     ADC #0›1240     STA V2+2›1250 ;›1260 ; Now to actually move the bytes›1270 ; in the program since we have›1280 ; already modified it for›1290 ; relocation...since this version›1300 ; is larger than 255 bytes, I've›1310 ; traded my quickie copier for›1320 ; an industrial strength, 16-bit›1330 ; version...›1340 ;›1350     LDY #0›1360     LDA # <START›1370     STA $CD›1380     LDA # >START›1390     STA $CE›1400     LDA MEMLO›1410     STA $CB›1420     LDA MEMLO+1›1430     STA $CC›1440 COPY›1450     LDA ($CD),Y›1460     STA ($CB),Y›1470     INC $CB     ; bump the regs›1480     BNE C1›1490     INC $CC›1500 C1  INC $CD›1510     BNE C2›1520     INC $CE›1530 C2  LDA $CE     ; check if done›1540     CMP # >END+1›1550     BNE COPY›1560     LDA $CD›1570     CMP # <END+1›1580     BNE COPY›1590 ;›1600 ; The $cb-c register indicates›1610 ; where the new MEMLO should be›1620 ; so we copy that to MEMLO...›1630 ;›1640     LDA $CB›1650     STA MEMLO›1660     LDA $CC›1670     STA MEMLO+1›1680 ;›1690 ; It's finally time to install›1700 ; this thing...›1710 ;›1720     CLC ›1730     LDA INSTALL+1›1740     ADC #3›1750     STA INSTALL+1›1760     LDA INSTALL+2›1770     ADC #0›1780     STA INSTALL+2›1790 INSTALL›1800     JSR $FFFF   ; install›1810 ;›1820 ; Now, we've gotten the thing›1830 ; installed...let's let the user›1840 ; know that by this exquisite›1850 ; chirp sound...›1860 ;›1870     LDA #0›1880     STA AUDCTL›1890     LDA #3›1900     STA SKCTL›1910     LDA #239›1920     STA AUDC1›1930     LDA #16›1940     STA AUDF1›1950     LDA RTCLOK+2›1960     ADC #3›1970 DELAY1›1980     CMP RTCLOK+2›1990     BNE DELAY1›2000     LDA #12›2010     STA AUDF1›2020     LDA RTCLOK+2›2030     ADC #3›2040 DELAY2›2050     CMP RTCLOK+2›2060     BNE DELAY2›2070     LDA #0›2080     STA AUDC1›2090     RTS ›2100 MSG›2110     .BYTE "™Ã­ËÅÙºv1.5 06/10/91 by Doug Wokoun",155›2120 ;›2130 ;*******************************›2140 ;›2150 ; C-KEY›2160 ;    keypress routine›2170 ;›2180 ;*******************************›2190 ;›2200     *=  $4000›2210 ; Will be relocated above MEMLO›2220 ;›2230 START›2240     NOP ›2250     LDA CONSOL  ; check [SELECT]›2260     AND #2›2270     BEQ VEC›2280     LDA KBCODE›2290     CMP #190    ; ^S pressed?›2300     BNE NEXT1›2310     LDA #255›2320     STA SSFLAG  ; stop screen›2330     BMI EXIT›2340 NEXT1›2350     CMP #175    ; ^Q pressed?›2360     BNE NEXT2›2370     LDA #0›2380     STA SSFLAG  ; unstop screen›2390     BEQ EXIT›2400 NEXT2›2410     CMP #146    ; ^C pressed?›2420     BNE NEXT3›2430 ;›2440 ; Simulate the OS break key›2450 ; routine...by coding this massive›2460 ; routine here, the program works›2470 ; on 400/800 computers, which it›2480 ; wouldn't do if I used the›2490 ; vector at 566-7›2500 ;›2510     LDA #0›2520     STA BRKKEY›2530     STA SSFLAG›2540     STA CRSINH›2550     STA ATRACT›2560     PLA ›2570     RTI         ; end processing›2580 NEXT3›2590     CMP #254    ; SHIFT ^S?›2600     BNE NEXT4›2610 ;›2620 ; To disable the screen simply,›2630 ; I just flip the "standard›2640 ; playfield" bit in SDMCTL.  This›2650 ; should work fine in most cases,›2660 ; but if a narrow or wide screen›2670 ; is used, it won't quite work.›2680 ;›2690     LDA SDMCTL›2700     EOR #2›2710     STA SDMCTL›2720     CLC ›2730     BCC EXIT›2740 NEXT4›2750     CMP #232    ; SHIFT ^R?›2760     BNE NEXT5›2770     JMP COLDSV  ; jump to reboot›2780 NEXT5›2790     CMP #202    ; SHIFT ^P?›2800     BEQ PRSCR   ; print screen›2810 ;›2820 ; If we get here, the user has›2830 ; pressed a key that this routine›2840 ; doesn't process, so we send that›2850 ; to the keypress routine we stole›2860 ; the VKEYBD vector from...›2870 ;›2880 VEC JMP $FFFF›2890 ; We get here if the keypress was›2900 ; processed by the program.  Since›2910 ; we don't want the _real_ key›2920 ; routine to get the keypress, we›2930 ; exit the interrupt here...›2940 EXIT›2950     PLA ›2960     RTI ›2970 ;›2980 ; This is the routine to print›2990 ; the screen in mode 0›3000 ;›3010 PRSCR›3020 ;›3030 ; First, check to make sure we›3040 ; are in mode 0, otherwise we›3050 ; can't do this.›3060 ;›3070     LDA 87      ; DINDEX›3080     BNE EXIT›3090     LDA 123     ; SWPFLG›3100     BMI EXIT›3110 ;›3120 ; To make sure we don't crash›3130 ; the system, we have to store›3140 ; the system registers...›3150 ;›3160     CLI ›3170     TXA         ; hold registers›3180     PHA ›3190     TYA ›3200     PHA ›3210 ;›3220 ; First a little setup...›3230 ;›3240     LDA #24     ; line count›3250     STA 203›3260     LDA 88›3270     STA 204›3280     LDA 89›3290     STA 205›3300 ;›3310 ; We need a channel to use for›3320 ; out output, so we'll scan›3330 ; for one, and abort it we can't›3340 ; find one...›3350 ;›3360     LDX #$70›3370 SCAN›3380     LDA ICHID,X›3390     BMI CFOUND›3400     TXA ›3410     SEC ›3420     SBC #16›3430     BEQ PEXIT›3440     TAX ›3450     BNE SCAN›3460 CFOUND›3470 ;›3480 ; If we've gotten here, the scan›3490 ; routine found us a channel, and›3500 ; put it in the X register, so›3510 ; now we're ready to begin...›3520 ; -Open channel›3530     LDA #$1A    ; theres's a 'P'›3540     STA ICBAL,X ;  at $031A›3550     LDA #$03›3560     STA ICBAH,X›3570     STA ICCOM,X›3580     LDA #8      ; output mode›3590     STA ICAX1,X›3600     JSR CIOV›3610     CPY #1      ; error?›3620     BNE PEXIT   ; then just exit›3630 ;›3640 ; If we're here, we've managed›3650 ; to successfully open an output›3660 ; channel to the printer...›3670 ;›3680 ; Now we're ready...let's output›3690 ; 40 screen bytes to the printer!›3700 ;›3710 PRLN›3720     LDY #0      ; setup first›3730     LDA #11     ; put command›3740     STA ICCOM,X›3750 PRCH›3760     LDA #0›3770     STA ICBLL,X›3780     STA ICBLL+1,X›3790     LDA (204),Y ; get byte›3800     EOR #$80›3810     STA (204),Y ; video feedback›3820 ; Now we have to convert the›3830 ; ICODE value to ATASCII›3840     AND #$7F    ; clear inverse›3850     CMP #96›3860     BCS P2›3870     CMP #64›3880     BCS P1›3890     ADC #32›3900     BCC P2›3910 P1  SBC #64›3920 P2›3930 ; Now we have the ATASCII, and›3940 ; we output the thing›3950 ;›3960     STY 206›3970     JSR CIOV›3980     CPY #2›3990     LDY 206›4000     LDA (204),Y ; restore›4010     EOR #$80›4020     STA (204),Y›4030 ;›4040 ; Check for error...›4050 ;›4060     BCS PRDONE›4070 ;›4080 ; Next byte...›4090     INY ›4100     CPY #40›4110     BNE PRCH›4120 ;›4130 ; Now we have to append a CR›4140 ; to the end of it...›4150 ;›4160     LDA #155›4170     JSR CIOV›4180 ;›4190 ; Now we check to see if we need›4200 ; to do more lines...›4210 ;›4220     DEC 203›4230     BEQ PRDONE›4240 ;›4250 ; Guess this means we have to go›4260 ; back around another time...›4270 ;›4280     CLC ›4290     LDA 204›4300     ADC #40›4310     STA 204›4320     LDA 205›4330     ADC #0›4340     STA 205›4350     BCC PRLN›4360 PRDONE›4370 ; Here we are at the end...So›4380 ; we have to close the channel›4390 ; and relinquish control›4400 ;›4410     LDA #12     ; close command›4420     STA ICCOM,X›4430     JSR CIOV›4440 PEXIT›4450     PLA         ; restore regs›4460     TAY ›4470     PLA ›4480     TAX ›4490     PLA         ; exit›4500     RTI ›4510 ;›4520 ; This routine replaces the key›4530 ; routine after a system reset›4540 ; displaces it.›4550 ;›4560 DOSINIT›4570     JSR $FFFF›4580     LDA #0›4590     STA DOSINI›4600     LDA #0›4610     STA DOSINI+1›4620     LDA VKEYBD›4630 V1  STA $FFFF›4640     LDA VKEYBD+1›4650 V2  STA $FFFF›4660     LDA #0›4670     STA VKEYBD›4680     LDA #0›4690     STA VKEYBD+1›4700     RTS ›4710 END›4720 ;›4730     *=  $02E0›4740     .WORD $3800›