0100 ;.OPT NOLIST
0110  .OPT NOEJECT
0120 ;
0130 BASE=$6000
0140 ;
0150 ;CHAR EQUATES
0160 ;
0170 LF=10
0180 CR=13
0190 ESC=$1B
0200 SPACE=$20
0210 CNTL=$5E
0220 CLS=$7D
0230 EOL=$9B
0240 ;
0250 ;80 COL COMMANDS
0260 ;
0270 XCH80=$50
0280 LMG80=$60
0290 LMH80=$70
0300 YCR80=$80
0310 SGR80=$99
0320 PAG80=$9A
0330 RMG80=$A0
0340 RMH80=$B0
0350 GET80=$C0
0360 CUR80=$C1
0370 RST80=$C2
0380 PST80=$C3
0390 CLR80=$C4
0400 LIS80=$D0
0410 SCR80=$D2
0420 SCB80=$D3
0430 GRF80=$D4
0440 ICM80=$D5
0450 PAL80=$D7
0460 CRS80=$D9
0470 MCF80=$DB
0480 PNT80=$DD
0490 ;
0500 ;MEMORY EQUATES
0510 ;
0520 DOSINI=$0C
0530 ICDNOZ=$21
0540 ICCOMZ=$22
0550 ICAX1Z=$2A
0560 ICAX2Z=$2B
0570 ICIDNO=$2E
0580 LMARGN=$52
0590 RMARGN=$53
0600 VCP=$54
0610 HCP=$55
0620 IN=$CC
0630 CDTMV3=$21C
0640 SDMCTL=$22F
0650 KEYDEL=$2D9
0660 KEYREP=$2DA
0670 DVSTAT=$2EA
0680 CRSINH=$2F0
0690 CHBAS=$2F4
0700 LISTF=$2FE
0710 SFLAG=$2FF
0720 HATABS=$31A
0730 ICDNO=$341
0740 ICCOM=$342
0750 PAL=$D014
0760 IRQEN=$D20E
0770 SKSTAT=$D20F
0780 PORTA=$D300
0790 PACTL=$D302
0800 DMACTL=$D400
0810 WSYNC=$D40A
0820 VCOUNT=$D40B
0830 NMIEN=$D40E
0840 ;
0850  *=BASE-2
0860 ;
0870  .WORD CEND-BEGIN ;RELOCATER INFO
0880 ;
0890 BEGIN JSR ERTS ;DOSINI VECTOR
0900  JMP CINIT ;RELOCATER JUMP
0910 ;
0920 PAUX1 .BYTE 0
0930 PAUX2 .BYTE 0
0940 ;
0950 READ JSR DISAB;DISABLE IRQ INTS
0960  LDA #GET80
0970  JSR CINP ;REQUEST, GET CHAR
0980  PHA ;SAVE CHAR
0990  JSR INPUT ;GET CURS
1000  JSR CURCK ;CHECK FOR X>$4F
1010  PLA ;RESTORE CHAR
1020  JMP ENAB
1030 ;
1040 CINP JSR CMD
1050 INPUT LDA #00 ;TIME CRITICAL CODE
1060  TAX ;MUST NOT CROSS A
1070  LDY #31 ;PAGE BOUNDARY
1080  STA DATIN
1090 IN0 LDA PORTA ;4
1100  AND INMSK ;4
1110  BEQ IN01 ;3 IF A 0, 2 IF NOT
1120  DEX
1130  BNE IN0
1140  DEY ;TIMEOUT LOOPS
1150  BNE IN0
1160  SEC ;NO RESPONSE
1170  RTS
1180 IN01 LDX #08
1190  LDY #12 ;2
1200 IN1 DEY
1210  BNE IN1 ;5*Y-1
1220  NOP ;2
1230 IN10 LDY #15 ;2 MAIN DLY COUNT
1240 IN2 DEY
1250  BNE IN2 ;5*Y-1
1260  LDA PORTA ;4 GET BYTE
1270  AND INMSK ;4 GET BIT
1280  CLC ;2
1290  BEQ IN25 ;0=3,1=2
1300  SEC ;1=2
1310 IN25 BCC IN26 ;0=3,1=2
1320 IN26 DEX ;2 DEC COUNT
1330  BMI IN3 ;2 (3 DONE)
1340  ROR DATIN ;6 SHIFT IN BIT
1350  BCC IN10 ;3 ALWAYS
1360 IN3 LDY #15 ;DELAY 1/2 BIT
1370 IN33 DEY
1380  BNE IN33
1390  LDA DATIN ;GET CHAR (Y=0)
1400  BCC I5 ;RETURN IF CHAR
1410  BPL I0 ;HORIZ WITH NO VERT
1420  AND #$7F ;CLEAR UPPER FLAG
1430  CMP #$51 ;TEST HORIZ/VERT
1440  BCC I00 ;HORIZONTAL
1450  AND #$1F ;CLEAR MID FLAG
1460  BCS I01 ;SAVE VERT
1470 I00 JSR I0 ;SAVE HORIZ
1480  BCC INPUT ;GET VERT
1490 I0 INY ;OFFSET FOR HORIZ
1500 I01 STA VCP,Y ;CURS POSITION
1510  STA VCS,Y ;CURS SHADOW
1520  CLC ;INDICATE RESPONSE
1530 I5 RTS
1540 ;
1550 CURCK LDA HCP ;CHECK HORIZ CURSOR
1560  CMP #$50 ;FOR >$4F
1570  BCC I5 ;IF NOT
1580  LDA #CUR80 ;GO GET REAL VALUE
1590  JSR CINP
1600  JMP I0 ;AND STORE IT (Y=0)
1610 ;
1620 CMD SEC ;THIS CODE MUST NOT
1630  BCS OUT ;CROSS A PAGE BOUNDARY
1640 OUTPUT CLC ;CMD FLAG=0 FOR CHAR
1650 OUT LDY #00
1660  JSR SEND ;SEND START BIT
1670  LDX #08 ;SETUP BIT COUNT OF 9
1680  NOP
1690  NOP
1700  NOP ;2+2+2+2=8
1710 OUT0 ROR A ;PUT BIT INTO CARRY
1720  BCS HI
1730  BCC LO ;2+3=5 CYCLES TO LO
1740 LO LDY #00 ;5+2 CYCLES TO JSR
1750  JSR SEND ;SEND A 0
1760  BCC OUT1 ;3 CYCLES
1770 HI LDY OUTMS ;3+4 CYCLES TO JSR
1780  JSR SEND ;SEND A 1
1790  BCS OUT1 ;3 CYCLES
1800 OUT1 DEX ;NEXT BIT 2 CYC
1810  BPL OUT0 ;MORE 3 OR 2 CYC
1820  BMI OUT2 ;SEND STOP BIT 3 CYC
1830 OUT2 LDY OUTMS ;SEND A 1
1840  BNE OUT3
1850 OUT3 JSR SEND ;2+3+4+3=12
1860  RTS
1870 SEND STY PORTA ;OUTPUT BIT
1880  LDY #12 ;TIMER FOR 15.7KB
1890 S1 DEY
1900  BNE S1 ;5*Y-1 CYCLES
1910  BEQ S2 ;3
1920 S2 NOP
1930  NOP
1940  NOP
1950  NOP ;2+2+2+2=8
1960 S3 RTS ;6 CYCLES
1970 ;
1980 COM LDA ICCOMZ ;GET COM BYTE
1990  CMP #$14 ;CHECK DEBUG OUT
2000  BNE COM1 ;TRY NEXT XIO
2010  LDA ICAX2Z ;GET AUX 2
2020 COMSD JSR DISAB ;STOP INTERRUPTS
2030  JSR CMD ;GO SEND
2040  JMP ENAB ;ENABLE AND NORM EXIT
2050 COM1 CMP #$15 ;TEST VALID
2060  BNE COM2 ;NEXT
2070  LDA ICAX2Z ;GET AUX 2
2080  BNE COMBR ;GO DO BURST
2090  STA MODE ;MAKE NORMAL
2100  LDA #SCR80 ;GET CMD
2110  BNE COMSD ;GO SEND
2120 COMBR STA MODE ;MAKE BURST
2130  LDA #SCB80 ;GET CMD
2140  BNE COMSD ;GO SEND
2150 COM2 CMP #$16 ;CHECK DEBUG IN
2160  BNE COM3 ;NEXT
2170  LDA ICAX2Z ;GET BYTE TO SEND
2180  JSR DISAB
2190  JSR CINP ;REQUEST, GET CHAR
2200  STA DVSTAT+1 ;FOR NOW
2210  JMP ENAB
2220 COM3 CMP #$19 ;CHECK 80/40
2230  BNE COM4
2240  JMP XIO19 ;DO IT
2250 COM4 RTS
2260 ;
2270 PCOM LDA ICCOMZ ;GET CMD
2280  CMP #$17 ;TEST VALID
2290  BNE S3 ;NO MORE FOR NOW
2300  LDA ICAX2Z ;GET AUX 2
2310  CMP #08 ;CHECK RESERVED
2320  BCS S3 ;NO GOOD
2330  AND #03 ;CHECK 3 AND 7
2340  EOR #03
2350  BEQ S3 ;NOT ALLOWED
2360  LDA ICAX1Z ;GET AUX1
2370  CMP #08 ;CHECK UPPER LIMIT
2380  BCS S3 ;NO GOOD
2390  STA PAUX1
2400  LDA ICAX2Z ;GET AUX 2
2410  STA PAUX2
2420  JMP EXIT
2430 ;
2440 WRITE LDY SFLAG ;CHECK CNTL 1
2450  BNE WRITE ;IF ON
2460  JSR DISAB
2470  LDY DEV ;ARE WE SCREEN?
2480  BEQ WR2 ;YES
2490  PHA
2500  LDA #00
2510  STA DEV
2520  LDA #SCR80
2530  JSR CMD
2540  PLA
2550 WR2 LDY LISTF ;CHECK LIST FLAG
2560  CPY LISTS
2570  BEQ WR3
2580  STY LISTS ;SAVE NEW VALUE
2590  PHA
2600  TYA
2610  BEQ WR25
2620  LDA #01 ;FORCE LSB
2630 WR25 ORA #LIS80
2640  JSR CMD ;SEND NEW VALUE
2650  PLA
2660 WR3 JSR ALIGN ;SET PARMS
2670  LDY CHBAS ;CHECK CHAR SET
2680  CPY CHSH
2690  BEQ WR5
2700  CPY #$E0
2710  BNE WR4
2720  STY CHSH
2730  PHA
2740  LDA #GRF80
2750 WR35 JSR CMD
2760  PLA
2770  JMP WR5
2780 WR4 CPY #$CC
2790  BNE WR5
2800  STY CHSH
2810  PHA
2820  LDA #ICM80
2830  BNE WR35
2840 WR5 LDY CRSINH ;CHECK CURS FLAG
2850  CPY CRSS
2860  BEQ WR6
2870  STY CRSS
2880  PHA
2890  TYA
2900  BEQ WR55
2910  LDA #01
2920 WR55 EOR #CRS80 ;CURSOR ON/OFF
2930  JSR CMD
2940  PLA
2950 WR6 JSR OUTPUT ;SEND CHAR
2960  LDA MODE ;TEST FOR BURST
2970  BNE WWAT ;IF SO
2980  JSR INPUT ;GET NEW CURSOR
2990  JSR CURCK ;CHECK FOR X>$4F
3000  JMP ENAB
3010 WWAT JSR ENAB ;ENABLE INTS
3020  LDY #25 ;OR SUCH
3030  JSR S1
3040 WW1 LDA PORTA
3050  AND INMSK
3060  BEQ WW1
3070 WW2 LDY #01
3080  RTS
3090 ;
3100 POPEN STX TIOCB
3110  LDX ICDNOZ
3120  JSR MATRIX
3130  BCS HANDGO
3140  LDY SDMCTL
3150  BNE WW2
3160  LDA #PST80
3170  JSR DISAB
3180  JSR CINP ;REQUEST, GET CHAR
3190  BNE POP1
3200  LDA #139 ;NOBODY HOME
3210 POP1 JSR ENAB
3220  TAY
3230  RTS
3240 ;
3250 HANDGO LDA ICDNOZ
3260  STX ICDNOZ
3270  PHA
3280  LDA ICCOMZ
3290  AND #08
3300  TAX
3310  JSR HAND
3320  PLA
3330  STA ICDNOZ
3340  RTS
3350 ;
3360 PWRT TAY ;SAVE CHAR
3370  STX TIOCB
3380  LDA ICDNO,X
3390  TAX
3400  JSR MATRIX
3410  TYA
3420  BCC PWP
3430  STA TCHAR ;SAVE CHAR FOR CALL
3440  LDY TIOCB ;GET UNIT #
3450  LDA ICDNO,Y
3460  PHA ;SAVE UNIT #
3470  TXA ;GET NEW VALUE
3480  STA ICDNO,Y ;REPLACE WITH NEW
3490  STA ICDNOZ ;AND ZERO PAGE
3500  LDX #06
3510  JSR HAND ;GO PRINT
3520  PLA ;RESTORE UNIT #
3530  LDX TIOCB ;GET POINTER
3540  STA ICDNO,X ;RESTORE OLD
3550  STA ICDNOZ
3560  RTS
3570 PWP LDY DEV ;CHECK OUTPUT DEV
3580  BNE PW0
3590  PHA
3600  LDY SDMCTL
3610  BEQ PW2
3620 PW1 LDY VCOUNT
3630  CPY #129
3640  BNE PW1
3650 PW2 JSR DISAB
3660  LDA #PNT80
3670  STA DEV
3680  JSR CMD
3690  JSR ENAB
3700  PLA ;RESTORE CHAR
3710 PW0 TAY ;SAVE CHAR
3720  LDA PAUX2 ;GET CNTL
3730  ROR A ;CHECK NO XLATE
3740  TYA ;RESTORE CHAR
3750  BCS DOIT ;DONT XLATE
3760  CMP #EOL ;CHECK EOL
3770  BNE XLATE ;XLATE IF NOT
3780  LDA #CR ;REPLACE WITH CR
3790  JSR DOIT ;SEND
3800  LDA PAUX2 ;GET CNTL
3810  AND #04 ;CHECK NO APPEND
3820  BNE WGDS ;DONT APPEND
3830  LDA #LF ;GET LF
3840  BNE DOIT ;SEND
3850 XLATE LDA PAUX2 ;GET CNTL
3860  CMP #02 ;CHECK LIGHT XLATE
3870  TYA ;RESTORE CHAR
3880  BCC DOIT ;DONE WITH XLATE
3890  AND #$7F ;REMOVE MSB
3900  CMP #$20 ;CHECK ASCII CHAR
3910  BCS DOIT ;GO PRINT ASCII
3920  PHA ;SAVE CHAR
3930  LDA #CNTL ;GET "CNTL" CHAR
3940  JSR DOIT ;SEND
3950  PLA ;RESTORE CHAR
3960  ORA #$40 ;MAKE ALPHA
3970 DOIT LDY SDMCTL
3980  BEQ DO1
3990 DO0 LDY VCOUNT
4000  CPY #129
4010  BNE DO0
4020 DO1 JSR DISAB
4030  JSR OUTPUT
4040  JSR ENAB
4050 WAIT LDY #25 ;FOR NOW
4060  JSR S1
4070  LDY #02
4080 W0 LDX #255 ;FOR NOW
4090  STX CDTMV3 ;SETUP VBLANK COUNT
4100 W1 LDA PORTA
4110  AND INMSK
4120  BNE WGDS ;AVAILABLE
4130  LDA CDTMV3 ;CHECK COUNTDOWN
4140  BNE W1
4150  DEY
4160  BNE W0
4170 WTMO LDY #138 ;DO TIMEOUT
4180  BNE WRTS ;COULD DO BRKKEY ALSO
4190 WGDS LDY #01
4200 WRTS RTS
4210 ;
4220 MATRIX CPX #02
4230  BEQ PNEXT
4240  BCS POVER
4250  LDA PAUX1
4260  LSR A
4270 POVER RTS
4280 PNEXT LDA #03
4290  CMP PAUX1
4300  BCC POVER
4310  LDA PAUX1
4320  AND #02
4330  BEQ POVER
4340  DEX
4350  RTS
4360 ;
4370 HAND LDA $E431,X
4380  PHA
4390  LDA $E430,X
4400  PHA
4410  LDA TCHAR ;RESTORE CHAR
4420  LDX TIOCB ;GET IOCB POINTER
4430  RTS ;CALL PRINTER HANDLER
4440 ;
4450 FORCOM LDA ICCOMZ
4460  CMP #$18
4470  BEQ XIO18
4480  RTS
4490 ;
4500 CINIT LDA #00
4510  STA TOGGLE
4520  JSR JINIT
4530  LDA #$50
4540  LDY #02
4550  JSR FSET
4560  LDA #$53
4570  JSR FIND
4580  LDA HATABS+1,X
4590  STA TEMPSV
4600  LDA HATABS+2,X
4610  STA TEMPSV+1
4620  LDA #$45
4630  JSR FIND
4640  LDA HATABS+1,X
4650  STA IN
4660  LDA HATABS+2,X
4670  STA IN+1
4680  LDY #15
4690 C003 LDA (IN),Y
4700  STA TMTAB,Y
4710  DEY
4720  BPL C003
4730  LDA #FORCOM-1&$FF
4740  STA TMTAB+10
4750  LDA #FORCOM-1/256
4760  STA TMTAB+11
4770  LDA SKSTAT
4780  AND #08
4790  BEQ C004
4800 XIO18 LDA #$45
4810  LDY #00
4820  JSR FSET
4830  LDA #$53
4840  LDY #01
4850  JSR FSET
4860  LDA #WRITE-1&$FF
4870  STA $346
4880  LDA #WRITE-1/256
4890  STA $347
4900 EOPEN LDX #00
4910  JSR FESUB
4920  LDA ICAX1Z ;GET AUX 1
4930  AND #32 ;CHECK CLEAR BIT
4940  BNE C005 ;DONT DO RESET
4950  LDA #00
4960  LDX #06
4970 C0035 STA VCS,X
4980  DEX
4990  BPL C0035
5000  LDA #$E0
5010  STA CHSH
5020  LDA #$4F
5030  STA RMARGS
5040  STA COMPOS
5050  JSR DISAB
5060 IO00 LDA #RST80 ;RESET 80 COL
5070  JSR CINP ;REQUEST, GET CHAR
5080  BCC IO01 ;GOT IT
5090  JSR JTOGL ;SWITCH PORTS
5100  BNE IO00 ;DO IT AGAIN
5110 IO01 LDA PAL ;CHECK COMPUTER TYPE
5120  AND #$0E
5130  BNE IOP1
5140  LDA #PAL80
5150  JSR CMD ;SET 80 COL TO 50HZ
5160 IOP1 JMP ENAB
5170 ;
5180 XIO19 LDX #06
5190  JSR FESUB
5200  LDA #$53
5210  JSR FIND
5220  LDA TEMPSV
5230  STA HATABS+1,X
5240  LDA TEMPSV+1
5250  STA HATABS+2,X
5260  LDA TMTAB+6
5270  STA $346
5280  LDA TMTAB+7
5290  STA $347
5300 C004 LDA #$45
5310  LDY #03
5320  JSR FSET
5330  JMP EXIT
5340 C005 LDA #SCR80 ;IN CASE A PRINT
5350  JMP COMSD ;HAS OCCURED
5360 ;
5370 EDTAB .WORD EOPEN-1 ;OPEN
5380  .WORD EXIT-1 ;CLOSE
5390  .WORD EGET-1 ;GET LINE OF TEXT
5400  .WORD WRITE-1 ;PUT (NO CURS)
5410  .WORD EXIT-1 ;STATUS
5420  .WORD COM-1 ;SPECIAL (CMD OUT)
5430  JMP EXIT ;INIT
5440  .BYTE 0
5450 ;
5460 PRTAB .WORD POPEN-1 ;OPEN
5470  .WORD EXIT-1 ;CLOSE
5480  .WORD ERTS-1 ;GET
5490  .WORD PWRT-1 ;PUT
5500  .WORD POPEN-1 ;STATUS
5510  .WORD PCOM-1 ;SPECIAL
5520  JMP EXIT ;INIT
5530  .BYTE 0
5540 ;
5550 SCTAB .WORD SOPEN-1 ;OPEN
5560  .WORD EXIT-1 ;CLOSE
5570  .WORD SREAD-1 ;GET-LOCATE
5580  .WORD SWRIT-1 ;PUT-PLOT
5590  .WORD EXIT-1 ;STATUS
5600  .WORD ERTS-1 ;SPECIAL
5610 SCT1 JMP EXIT ;INIT
5620  .BYTE 0
5630 ;
5640 TMTAB .WORD EXIT-1,EXIT-1
5650  .WORD EXIT-1,EXIT-1
5660  .WORD EXIT-1,EXIT-1
5670  JMP EXIT
5680  .BYTE 0
5690 ;
5700 SOPEN LDA ICAX2Z
5710  AND #08
5720  BEQ SCT1
5730  LDA ICAX1Z
5740  AND #16
5750  BNE SCT1
5760  LDA #00 ;SEND 0
5770  JSR DISAB
5780  JSR OUTPUT
5790  JSR INPUT
5800  LDA #SGR80 ;SET GRAPHICS
5810  JSR CMD
5820  LDA PAL
5830  AND #$0E
5840  BNE SOP1
5850  LDA #PAG80
5860  JSR CMD
5870 SOP1 LDA #CLR80 ;FILL WITH 0 SENT
5880  JSR CINP ;REQUEST, GET CHAR
5890  LDA #01
5900  JMP COMBR
5910 ;
5920 SREAD JSR DISAB
5930  JSR ALIGN ;SET PARMS
5940  JSR READ ;GET CHAR
5950  CMP #EOL ;CHECK EOL
5960  BNE SCT1 ;RETURN NORMAL
5970  LDA #SPACE ;REPLACE WITH SPACE
5980  BNE SCT1 ;RETURN NORMAL
5990 ;
6000 SWRIT PHA ;SAVE CHAR
6010  LDA #ESC ;FORCE PRINT
6020  JSR WRITE
6030  PLA ;RESTORE CHAR
6040  JMP WRITE ;SEND IT
6050 ;
6060 EGET LDA COMPOS
6070  BEQ EBACK
6080  LDA HCP
6090  STA HCPS
6094  STA HCPE
6100 EG1 JSR KCALL ;GET KB BYTE
6110  CMP #EOL
6120  BEQ EGBAK
6130  JSR WRITE ;SEND TO 80 COL
6132  LDY HCP ;THIS CODE IS FOR
6134  CPY HCPE ;SPECIAL CASE LINES
6140  BCC EG1 ;DONT UPDATE IF LESS
6142  STY HCPE
6144  BCS EG1
6150 EGBAK STY KSTAT ;SAVE STATUS
6160  CPY #$80 ;CHECK STAT
6170  BCS EBA0 ;DO EOL IF EOF/BREAK
6180  JSR DISAB ;DISAB FOR CMD
6190  LDA #00
6200  STA COMPOS
6210  LDA MODE
6220  BEQ EG2
6230  LDA #00
6240  BEQ EG3
6250 EG2 LDA HCPS
6260 EG3 JSR CMD ;X CURS TO OLD VAL
6270  LDA #MCF80 ;Y CURS TO FIRST
6280  JSR CMD
6290 EBACK JSR READ ;GO GET A CHAR
6300  CMP #EOL
6310  BNE EGXT ;NOT DONE YET
6312  LDY HCP
6314  CPY HCPE ;CHECK RIGHTMOST
6315  BCS EBA0 ;CURSOR POSITION
6316  LDA #SPACE ;IF NOT THERE
6318  BNE EGXT ;THEN FAKE SPACE
6320 EBA0 STA COMPOS ;SET NON 0
6330  JSR WRITE
6340  LDA #EOL ;RETURN WITH EOL
6350 EGXT LDY KSTAT ;GET STATUS
6360  RTS
6370 ;
6380 KCALL LDA $E425
6390  PHA
6400  LDA $E424
6410  PHA
6420  RTS
6430 ;
6440 DISAB LDY #00
6450  STY NMIEN
6460  SEI
6470  RTS
6480 ;
6490 ENAB LDY #$C0
6500  STY NMIEN
6510  CLI
6520 EXIT LDY #01
6530 ERTS RTS
6540 ;
6550 VCS .BYTE 0
6560 HCS .BYTE 0
6570 DEV .BYTE 0
6580 LMARGS .BYTE 0
6590 LISTS .BYTE 0
6600 MODE .BYTE 0
6610 CRSS .BYTE 0
6620 ;
6630 CHSH .BYTE 0
6640 RMARGS .BYTE 0
6650 COMPOS .BYTE 0
6660 ;
6670 DATIN .BYTE 0
6680 HCPS .BYTE 0
6685 HCPE .BYTE 0
6690 KSTAT .BYTE 0
6700 INMSK .BYTE 0
6710 OUTMS .BYTE 0
6720 TOGGLE .BYTE 0
6730 TIOCB .BYTE 0
6740 TCHAR .BYTE 0
6750 ;
6760 TEMPSV .WORD 0
6770 ;
6780 INMST .BYTE 02,$20
6790 OUTMT .BYTE 01,$10
6800 ;
6810 FETAB .BYTE 0,0,0,$4F,24,3
6820  .BYTE 62,0,2,39,30,6
6830 ;
6840 LOOKUP .BYTE "ESP"
6850 LOWAD .BYTE EDTAB&$FF,SCTAB&$FF,PRTAB&$FF,TMTAB&$FF
6860 ;
6870 ALIGN LDY HCP ;GET HCURS
6880  CPY HCS ;COMPARE TO SHADOW
6890  BEQ A1 ;NO CHANGE
6900  STY HCS ;SAVE NEW VALUE
6910  PHA ;SAVE CHAR
6920  TYA
6930  CMP #$50
6940  BCC A00
6950  LSR A
6960  LSR A
6970  LSR A
6980  LSR A
6990  ORA #XCH80
7000  PHA
7010  TYA
7020  AND #$0F
7030  JSR CMD
7040  PLA
7050 A00 JSR CMD ;SEND NEW CURSOR
7060  PLA
7070 A1 LDY VCP ;GET VCURS
7080  CPY #25 ;CHECK UPPER LIMIT
7090  BCC A15
7100  LDY #24 ;STATUS LINE
7110 A15 CPY VCS ;COMPARE TO SHADOW
7120  BEQ A2 ;NO CHANGE
7130  STY VCS ;SAVE NEW VALUE
7140  PHA ;SAVE CHAR
7150  TYA
7160  ORA #YCR80 ;SET CMD BIT
7170  JSR CMD ;SEND NEW CURSOR
7180  PLA
7190 A2 LDY LMARGN
7200  CPY RMARGN
7210  BCC A24
7220  LDY #00
7230  STY LMARGN
7240 A24 CPY LMARGS
7250  BEQ A3
7260  STY LMARGS
7270  PHA
7280  TYA
7290  AND #$0F
7300  ORA #LMG80
7310  JSR CMD
7320  LDA LMARGN
7330  LSR A
7340  LSR A
7350  LSR A
7360  LSR A
7370  BEQ A25
7380  ORA #LMH80
7390  JSR CMD
7400 A25 PLA
7410 A3 LDY RMARGN
7420  CPY RMARGS
7430  BEQ A4
7440  STY RMARGS
7450  PHA
7460  TYA
7470  AND #$0F
7480  ORA #RMG80
7490  JSR CMD
7500  LDA RMARGN
7510  LSR A
7520  LSR A
7530  LSR A
7540  LSR A
7550  CMP #04
7560  BEQ A35
7570  ORA #RMH80
7580  JSR CMD
7590 A35 PLA
7600 A4 RTS
7610 ;
7620 FESUB LDA FETAB,X
7630  STA SDMCTL
7640  STA DMACTL
7650  LDA FETAB+1,X
7660  STA VCP
7670  LDA FETAB+2,X
7680  STA HCP
7690  STA LMARGN
7700  LDA FETAB+3,X
7710  STA RMARGN
7720  LDA FETAB+4,X
7730  STA KEYDEL
7740  LDA FETAB+5,X
7750  STA KEYREP
7760  RTS
7770 ;
7780 FIND LDX #00
7790 F1 CMP HATABS,X
7800  BEQ F2
7810  INX
7820  INX
7830  INX
7840  BNE F1
7850 ;
7860 FSET JSR FIND
7870 SET LDA LOWAD,Y
7880  STA HATABS+1,X
7890  LDA #EDTAB/256
7900  STA HATABS+2,X
7910 F2 RTS
7920 ;
7930 JTOGL LDA #01
7940  EOR TOGGLE
7950  STA TOGGLE
7960 JINIT LDX TOGGLE
7970  LDY INMST,X
7980  STY INMSK
7990  LDY OUTMT,X
8000  STY OUTMS
8010  LDA #$FF
8020  STA PORTA
8030  LDX #$38
8040  STX PACTL
8050  STY PORTA
8060  LDX #$3C
8070  STX PACTL
8080  RTS
8090 ;
8100 CEND=*
8110 ;
8120  .END
