
 1000         .LIST OFF
 1010  *--------------------------------
 1020  *                SCM80
 1030  *  Patches for S-C Macro Assembler V1.0
 1040  *        for Videx Videoterm Card
 1050  *
 1060  * Date: 7/10/82
 1070  *
 1080  * Don Taylor
 1090  * infoTool corporation
 1100  * Drawer 809, Poulsbo, WA  98370
 1110  *
 1120  * To assemble this file:
 1130  *
 1140  *      1.  Set SLOTNUM to slot number of videx card
 1150  *
 1160  *      2.  Set LCVERSION flag for
 1170  *            .EQ 1 for Language card version ($D000)
 1180  *            .EQ 0 for Standard version ($1000)
 1190  *
 1200  *      3.  Assemble as usual
 1210  *
 1220  *      4.  Use VAL LENGTH to get length in hex
 1230  *
 1240  *      5.  BSAVE SCM80, A$4000, L$LENGTH
 1250  *
 1260  *--------------------------------
 1270  *
 1280  SLOTNUM             .EQ 3    VIDEX slot
 1290  LCVERSION           .EQ 1    SCM80 version
 1300  PATCH.AREA          .EQ $3200
 1310  LC.PATCH.AREA       .EQ $F400
 1320  *
 1330  *--------------------------------
 1340         .DO LCVERSION
 1350  SCM.BASE   .EQ $D000
 1360         .ELSE
 1370  SCM.BASE   .EQ $1000
 1380         .FIN
 1390  *--------------------------------
 1400  *  Program Constants
 1410  *--------------------------------
 1420  MON.CSW             .EQ $36
 1430  MON.KSW             .EQ $38
 1440  MON.A1L             .EQ $3C
 1450  MON.A2L             .EQ $3E
 1460  MON.A4L             .EQ $42
 1470  SCM.POINTER         .EQ $58
 1480  SCM.CURR.CHAR       .EQ $61
 1490  SCM.ED.BEGLIN       .EQ $80
 1500  NEW.CH              .EQ $98
 1510  NEW.CV              .EQ $99
 1520  SCM.WBUF            .EQ $200
 1530  DOS.COLD.ENTRY      .EQ $3D3
 1540  DOS.IOHOOK          .EQ $3EA
 1550  FLAGS               .EQ $7F8  VIDEX Flag Byte
 1560  KEYBOARD            .EQ $C000
 1570  KEYSTROBE           .EQ $C010
 1580  SCM.WARM.ENTRY      .EQ SCM.BASE+$003
 1590  SCM.SHIFT.FLAG      .EQ SCM.BASE+$016
 1600  SCM.SYM.TABLE       .EQ SCM.BASE+$01D
 1610  SCM.TEST.DOS        .EQ SCM.BASE+$31E
 1620  SCM.RDL.EOL         .EQ SCM.BASE+$35E
 1630  SCM.RDL3            .EQ SCM.BASE+$3C3
 1640  SCM.ESC.TABLE       .EQ SCM.BASE+$467
 1650  SCM.ESC.L           .EQ SCM.BASE+$483
 1660  SCM.RDKEY.NO.CASE   .EQ SCM.BASE+$520
 1670  SCM.RDKEY.WITH.CASE .EQ SCM.BASE+$4CA
 1680  SCM.SPC             .EQ SCM.BASE+$D92
 1690  MON.MOVE            .EQ $FE2C
 1700  MON.OUTPORT         .EQ $FE95
 1710  MON.COUT            .EQ $FDED
 1720  MON.RTS             .EQ $FF58
 1730  *--------------------------------
 1740         .OR $4000
 1750  START1     .EQ *
 1760  *--------------------------------
 1770  MOVE.CODE
 1780         LDA #HERE
 1790         STA MON.A1L
 1800         LDA /HERE
 1810         STA MON.A1L+1
 1820         LDA #THERE
 1830         STA MON.A2L
 1840         LDA /THERE
 1850         STA MON.A2L+1
 1860  *--------------------------------
 1870         .DO LCVERSION
 1880         BIT $C083    Unprotect language card RAM
 1890         BIT $C083
 1900         LDA #LC.PATCH.AREA
 1910         STA MON.A4L
 1920         LDA /LC.PATCH.AREA
 1930         STA MON.A4L+1
 1940         .ELSE
 1950         LDA #$33     Modify symbol table address
 1960         STA SCM.SYM.TABLE
 1970         LDA #PATCH.AREA
 1980         STA MON.A4L
 1990         LDA /PATCH.AREA
 2000         STA MON.A4L+1
 2010         .FIN
 2020  *--------------------------------
 2030         LDY #0
 2040         JSR MON.MOVE
 2050  INSTALL.PATCHES
 2060         LDA #$EA     "NOP-OUT" unused code:
 2070         STA SCM.BASE+$343
 2080         STA SCM.BASE+$344
 2090         STA SCM.BASE+$028
 2100         STA SCM.BASE+$029
 2110         STA SCM.BASE+$02A
 2120         LDX #9
 2130  .1     STA SCM.BASE+$298,X
 2140         DEX
 2150         BPL .1
 2160         LDX #14
 2170  .2     STA SCM.BASE+$4DE,X
 2180         DEX
 2190         BPL .2
 2200         LDX #48
 2210  .3     STA SCM.BASE+$B35,X
 2220         DEX
 2230         BPL .3
 2240         LDA #$20              Install Videx during a
 2250         STA SCM.BASE+$295     cold start
 2260         LDA #INSTALL.VECTORS
 2270         STA SCM.BASE+$296
 2280         LDA /INSTALL.VECTORS
 2290         STA SCM.BASE+$297
 2300         LDA #HOME    Patch clear screen routine
 2310         STA SCM.BASE+$2A6
 2320         LDA /HOME
 2330         STA SCM.BASE+$2A7
 2340         LDA #NEW.WARM.ENTRY   Set up warm start so
 2350         STA SCM.BASE+$309     VIDEX card stays in..
 2360         LDA /NEW.WARM.ENTRY
 2370         STA SCM.BASE+$30A
 2380         LDA #$10     Patch Escape Routine
 2390         STA SCM.BASE+$486
 2400         LDY #27
 2410  .4     LDA NEW.ESC.TABLE,Y
 2420         STA SCM.ESC.TABLE,Y
 2430         DEY
 2440         BPL .4
 2450         LDA #$18     Modify MON.RDKEY jump addr
 2460         STA SCM.BASE+$4D9
 2470         LDA #$4C     Patch jump to new DISP LINE
 2480         STA SCM.BASE+$B32
 2490         LDA #NEW.E.DISP.LINE
 2500         STA SCM.BASE+$B33
 2510         LDA /NEW.E.DISP.LINE
 2520         STA SCM.BASE+$B34
 2530         LDA #80      Patch E.INPUT Routine
 2540         STA SCM.BASE+$CA8
 2550         STA SCM.BASE+$CAC
 2560         LDA #NEW.CH
 2570         STA SCM.BASE+$CB1
 2580         LDA #NEW.CV
 2590         STA SCM.BASE+$CB3
 2600         LDA #VTAB
 2610         STA SCM.BASE+$CB5
 2620         LDA /VTAB
 2630         STA SCM.BASE+$CB6
 2640         LDA #SLOTNUM     Install VIDEX in hook
 2650         JSR MON.OUTPORT
 2660         JSR DOS.IOHOOK
 2670         LDA #$8D         Send CR to get VIDEX warm
 2680         JSR MON.COUT     entry point in DOS hook,
 2690         LDY #8           then find warm entry address
 2700         JSR SCM.TEST.DOS
 2710         LDY #1
 2720         LDA (SCM.POINTER),Y
 2730         STA FAKE.COUT+1   Save warm entry as normal
 2740         INY               VIDEX COUT entry
 2750         LDA (SCM.POINTER),Y
 2760         STA FAKE.COUT+2
 2770         LDA #COUT         Hook in new I/O routines
 2780         STA MON.CSW
 2790         LDA /COUT
 2800         STA MON.CSW+1
 2810         LDA #RDKEY
 2820         STA MON.KSW
 2830         LDA /RDKEY
 2840         STA MON.KSW+1
 2850         JSR DOS.IOHOOK
 2860  *--------------------------------
 2870         .DO LCVERSION
 2880         BIT $C080    Write protect RAM
 2890         JMP DOS.COLD.ENTRY
 2900         .ELSE
 2910         RTS
 2920         .FIN
 2930  *--------------------------------
 2940  *
 2950  NEW.ESC.TABLE
 2960         .DA HOME-1
 2970         .DA ADVNCE-1
 2980         .DA BS-1
 2990         .DA LF-1
 3000         .DA UP-1
 3010         .DA CLREOL-1
 3020         .DA CLREOP-1
 3030         .DA MON.RTS-1
 3040         .DA MON.RTS-1
 3050         .DA UP-1
 3060         .DA BS-1
 3070         .DA ADVNCE-1
 3080         .DA SCM.ESC.L-1
 3090         .DA LF-1
 3100  *--------------------------------
 3110  *  New routines to bind into the
 3120  *  S-C Macro assembler
 3130  *--------------------------------
 3140  LENGTH1             .EQ *-START1
 3150  HERE                .EQ *
 3160         .DO LCVERSION
 3170         .OR $F400
 3180         .ELSE
 3190         .OR $3200
 3200         .FIN
 3210         .TA HERE
 3220  START2              .EQ *
 3230  *--------------------------------
 3240  NEW.WARM.ENTRY
 3250         JSR INSTALL.VECTORS
 3260         JMP SCM.WARM.ENTRY
 3270  *
 3280  INSTALL.VECTORS
 3290         LDA #COUT
 3300         STA MON.CSW
 3310         LDA /COUT
 3320         STA MON.CSW+1
 3330         LDA #RDKEY
 3340         STA MON.KSW
 3350         LDA /RDKEY
 3360         STA MON.KSW+1
 3370         JSR DOS.IOHOOK
 3380         RTS
 3390  *
 3400  NEW.E.DISP.LINE
 3410         LDA SCM.ED.BEGLIN
 3420         STA NEW.CV
 3430         LDA #0
 3440         STA NEW.CH
 3450         JSR VTAB
 3460         JSR SCM.SPC
 3470         INC NEW.CH
 3480         INC NEW.CH
 3490         LDX #0
 3500  .1     LDA SCM.WBUF,X
 3510         BEQ .5
 3520         ORA #$80
 3530         CMP #$A0     Control char?
 3540         BCS .2       No..
 3550         AND #$7F     Flag it as inverse
 3560  .2     LDY NEW.CH
 3570         CPY #80      End of screen line?
 3580         BCC .4       No..
 3590         LDY #0       Set CH to beg of line
 3600         STY NEW.CH
 3610         LDY NEW.CV
 3620         CPY #23
 3630         BCS .3
 3640         INC NEW.CV   No..
 3650         BNE .4       ..Always
 3660  .3     DEC SCM.ED.BEGLIN
 3670  .4     JSR MON.COUT
 3680         INC NEW.CH
 3690         INX
 3700         BNE .1       ..Always
 3710  .5     JMP CLREOP
 3720  *
 3730  NEW.E.ZAP
 3740         LDA #0       EOL mark
 3750         STA SCM.WBUF,X
 3760         JSR CLREOL
 3770         RTS
 3780  *--------------------------------
 3790  *  Monitor Replacement Routines
 3800  *--------------------------------
 3810  *
 3820  HOME   LDA #$8C     Send Form Feed Char
 3830         JMP MON.COUT
 3840  *
 3850  CLREOL LDA #$9D     Send CLEAREOL char
 3860         JMP MON.COUT
 3870  *
 3880  CLREOP LDA #$8B     Send CLEAREOS char
 3890         JMP MON.COUT
 3900  *
 3910  ADVNCE LDA #$9C     Non-destructive space
 3920         JMP MON.COUT
 3930  *
 3940  BS     LDA #$88     Backspace
 3950         JMP MON.COUT
 3960  *
 3970  LF     LDA #$8A     Linefeed
 3980         JMP MON.COUT
 3990  *
 4000  UP     LDA #$9F     Reverse Linefeed
 4010         JMP MON.COUT
 4020  *--------------------------------
 4030         .DO LCVERSION
 4040  RDKEY  LDA KEYBOARD
 4050         BPL RDKEY
 4060         STA KEYSTROBE
 4070         ORA #$80
 4080         CMP #$81     Shift lock?
 4090         BNE .1
 4100         JSR UNPROTECT.LC.RAM
 4110         LSR SCM.SHIFT.FLAG
 4120         BPL .2       Return with errant key
 4130  .1     CMP #$9A     Shift unlock?
 4140         BNE .3       No, return with key
 4150         JSR UNPROTECT.LC.RAM
 4160         SEC
 4170         ROR SCM.SHIFT.FLAG
 4180  .2     BIT $C080    Reprotect LC RAM
 4190         LDA #$96     Return with errant key
 4200  .3     RTS
 4210  *
 4220  UNPROTECT.LC.RAM
 4230         BIT $C083    Enable Bank 2
 4240         BIT $C083
 4250         RTS
 4260         .ELSE
 4270  RDKEY  LDA KEYBOARD
 4280         BPL RDKEY
 4290         STA KEYSTROBE
 4300         ORA #$80
 4310         CMP #$81     Shift lock?
 4320         BNE .1
 4330         LSR SCM.SHIFT.FLAG
 4340         BPL .2       Return with errant key
 4350  .1     CMP #$9A     Shift unlock?
 4360         BNE .3       No, return with key
 4370         SEC
 4380         ROR SCM.SHIFT.FLAG
 4390  .2     LDA #$96     Return with errant key
 4400  .3     RTS
 4410         .FIN
 4420  *--------------------------------
 4430  *
 4440  VTAB   LDA #$9E     Send GOTOXY char
 4450         JSR MON.COUT
 4460         CLC          Create ASCII x-posn
 4470         LDA NEW.CH
 4480         ADC #160
 4490         JSR MON.COUT
 4500         CLC          Create ASCII y-posn
 4510         LDA NEW.CV
 4520         ADC #160
 4530         JMP MON.COUT
 4540  *
 4550  COUT
 4560         PHA            Test for inverse
 4570         PLA
 4580         BMI FAKE.COUT  Not inverse: Take as is
 4590         ORA #$80       Restore to "Normal" Apple ASCII
 4600         CMP #$A0       Control char?
 4610         BCS .1         No..
 4620         ORA #$40       Yes: Make it printable
 4630  .1     TAY            Save char
 4640         LDA FLAGS+SLOTNUM
 4650         PHA            Save flag byte
 4660         ORA #1         Switch in alt char set
 4670         STA FLAGS+SLOTNUM
 4680         TYA            Get char back
 4690         JSR FAKE.COUT
 4700         PLA            Restore flag byte
 4710         STA FLAGS+SLOTNUM
 4720         RTS
 4730  FAKE.COUT
 4740         JMP $FFFF      Address will be fixed later..
 4750  *--------------------------------
 4760  LENGTH2             .EQ *-START2
 4770  THERE               .EQ HERE+LENGTH2-1
 4780  LENGTH              .EQ LENGTH1+LENGTH2
 4790  *--------------------------------
 4800         .EN

