
 1000   .ti 81,BNApple //c buffering program 2.0 8/5/85 dcj
 1010  ;SAVE Buf.64K
 1020  ;--------------------------------
 1030  ; Dedicated to Allan B. Calhamer.
 1040  ;--------------------------------
 1050  Printer.ACIA.TxD     .eq $C098 (w)
 1060  Printer.ACIA.Status  .eq $C099 (r)
 1070  Printer.ACIA.Command .eq $C09A (r/w)
 1080  Printer.ACIA.Control .eq $C09B (r/w)
 1090  Modem.ACIA.RxD       .eq $C0A8 (r)
 1100  Modem.ACIA.Status    .eq $C0A9 (r)
 1110  Modem.ACIA.Command   .eq $C0AA (r/w)
 1120  Modem.ACIA.Control   .eq $C0AB (r/w)
 1130  Keyboard             .eq $C000 (r)
 1140  Store80              .eq $C001 (w) on
 1150  RAMRd                .eq $C003 (w) aux
 1160  RAMWrt               .eq $C005 (w) aux
 1170  AltZP                .eq $C009 (w) aux
 1180  Vid40                .eq $C00C (w)
 1190  SetAltChr            .eq $C00F (w) w/MouseText
 1200  Clear.Key.Strobe     .eq $C010 (r)
 1210  Text                 .eq $C051 (r)
 1220  Page1                .eq $C054 (r) main
 1230  Page2                .eq $C055 (r) aux
 1240  Hires                .eq $C057 (r) $2000-$3FFF too...
 1250  LCRAM2               .eq $C083 (r/w; write doesn't
 1260  LCRAM1               .eq $C08B  change write enable)
 1270  ;--------------------------------
 1280         .op 65C02
 1290         .or $2000
 1300         .tf /IIc.buf/Bufit64K/
 1310  dcj    SEI               close this can of worms...
 1320         LDA LCRAM2        1x...switches setup
 1330         LDA Text
 1340         LDA Page1
 1350         LDA Hires
 1360         STZ Store80
 1370         STZ RAMRd
 1380         STZ RAMWrt
 1390         STZ AltZP
 1400         STZ SetAltChr
 1410         STZ Vid40
 1420         LDX #0
 1430  .1     LDA #" "          clear 40 column screen
 1440         STA $400,X
 1450         STA $500,X
 1460         STA $600,X
 1470         STA $700,X
 1480         LDA Image,X       install Image in aux ZP/Stack
 1490         STA $00,X
 1500         INX
 1510         BNE .1
 1520         LDY #$0F
 1530  .2     LDA Msg,Y         put up a message
 1540         STA $50C,Y
 1550         DEY
 1560         BPL .2
 1570         LDA #%000.0.10.1.0         bop ACIAs
 1580         STA Printer.ACIA.Command
 1590    inc  LDA #%000.0.10.1.1         RTS' lo
 1600         STA Modem.ACIA.Command
 1610         LDA #%0.00.1.1110          9600 baud
 1620         STA Printer.ACIA.Control
 1630    inc  LDA #%0.00.1.1111          19200 baud!
 1640         STA Modem.ACIA.Control
 1650         LDA Modem.ACIA.RxD
 1660         JMP Scan          go 2 it
 1670  Msg    .AS 'A'           as in Apple
 1680         .AS -" //c buffer pgm"
 1690  Image  .ph $00
 1700  ;--------------------------------
 1710  ; buffer starts at first available location in //c aux bank
 1720  Receive.Adr.Hi      .da /IIc.Aux.Bank.Avail
 1730  Receive.Adr.Lo      .da IIc.Aux.Bank.Avail
 1740  Transmit.Adr.Hi     .da /IIc.Aux.Bank.Avail
 1750  Transmit.Adr.Lo     .da IIc.Aux.Bank.Avail
 1760  Byte.Counter.Lo     .da #$0000          indicates empty
 1770  Byte.Counter.Hi     .da /$0000
 1780  RTS.Bit             .da #%000.0.10.0.0  RTS' lo
 1790  ;--------------------------------
 1800  Scan   LDA Page1         access main text screen
 1810         INC $413          show we're alive
 1820         DEC $414
 1830         LDA Page2         back to aux
 1840         LDA Keyboard      scan keyboard
 1850         BPL Scan.Modem.Port
 1860         CMP #" "          space toggles RTS' (DTR2B) to //e
 1870         BNE .2
 1880         LDA Modem.ACIA.Command
 1890         AND #%000.0.10.0.0
 1900         BNE .1            =>It's ok, you can turn it off...
 1910         LDA RTS.Bit
 1920         BNE Scan.Modem.Port  =>don't do it! (yet)
 1930  .1     LDA Modem.ACIA.Command
 1940         EOR #%000.0.10.0.0
 1950         STA Modem.ACIA.Command
 1960         AND #%000.0.10.0.0
 1970         STA RTS.Bit
 1980  .2     BIT Clear.Key.Strobe
 1990  Scan.Modem.Port
 2000         LDY Modem.ACIA.Status
 2010         TYA
 2020         AND #%0000.0111   error bits mask
 2030         BEQ .1            =>error-free operation
 2040         TAX
 2050         LDA Page1         access main text screen
 2060         INC $4FF,X        indicate error...
 2070         LDA Page2         back to aux
 2080  .1     TYA
 2090         AND #%0000.1000   receive data reg full mask
 2100         BEQ Cant.Receive  =>not full
 2110         LDX Byte.Counter.Lo   received a byte,
 2120         LDY Byte.Counter.Hi   do we assert RTS' ?
 2130         CPX #BufLen-256
 2140         BNE .2            =>buffer not @ full-256
 2150         CPY /BufLen-256
 2160         BNE .2            =>buffer not @ full-256
 2170         LDA #%000.0.10.0.0   assert RTS'
 2180         TRB Modem.ACIA.Command
 2190  .2     INX               fig next byte count
 2200         BNE .3
 2210         INY
 2220  .3     CPX #BufLen       do we have room for it ?
 2230         BNE Room          =>buffer not full
 2240         CPY /BufLen
 2250  ; $402 indicator gone to fit into ZP (cause I wanna)
 2260         BEQ Cant.Receive  =>buffer is full!
 2270  Room   STX Byte.Counter.Lo
 2280         STY Byte.Counter.Hi
 2290         LDA Page1         access main text screen
 2300         INC $400          show we received a byte
 2310         LDA Page2         back to aux
 2320         LDY Receive.Adr.Hi
 2330         BIT LCRAM2        normally use LC bank 2
 2340         TYA
 2350         AND #$F0
 2360         CMP /$C000        if adr is in $CXXX range
 2370         BNE .1
 2380         BIT LCRAM1         use LC bank 1
 2390         TYA
 2400         ORA /$D000
 2410         TAY
 2420  .1     STY Receive.Adr.Lo+1
 2430         LDA Modem.ACIA.RxD
 2440         STA (Receive.Adr.Lo)
 2450         INC Receive.Adr.Lo  fig next receive adr
 2460         BNE Scan.Printer.Port
 2470         INC Receive.Adr.Hi
 2480         BNE Scan.Printer.Port
 2490         LDX #IIc.Aux.Bank.Avail
 2500         STX Receive.Adr.Lo
 2510  Cant.Receive
 2520  Scan.Printer.Port
 2530         LDA #%0011.0000   make transmit data reg empty and
 2540         AND Printer.ACIA.Status  Data Carrier Detect mask
 2550         CMP #%0001.0000   test empty and DCD' lo
 2560         BNE Cant.Transmit =>not empty or not ready
 2570         LDA Byte.Counter.Lo   printer can take another byte,
 2580         ORA Byte.Counter.Hi   do we have one ?
 2590         BEQ Cant.Transmit     =>buffer is empty!!!
 2600         LDX Byte.Counter.Lo   do we release RTS' ?
 2610         LDY Byte.Counter.Hi
 2620         CPX #BufLen-2048
 2630         BNE .1            =>buffer not @ full-2048
 2640         CPY /BufLen-2048
 2650         BNE .1            =>buffer not @ full-2048
 2660         LDA RTS.Bit
 2670         TSB Modem.ACIA.Command  release RTS' (maybe)
 2680  .1     STA $C073+5
 2690         LDA Byte.Counter.Lo     fig next byte count
 2700         BNE .2
 2710         DEC Byte.Counter.Hi
 2720  .2     DEC Byte.Counter.Lo
 2730         LDA Page1         access main text page
 2740         INC $427          show we printed a byte
 2750         LDA Page2         back to aux
 2760         LDY Transmit.Adr.Hi
 2770         BIT LCRAM2        normally use LC bank 2
 2780         TYA
 2790         AND #$F0
 2800         CMP /$C000        if adr in $CXXX range
 2810         BNE .4
 2820         BIT LCRAM1         use LC bank 1
 2830         TYA
 2840         ORA /$D000
 2850         TAY
 2860  .4     STY Transmit.Adr.Lo+1
 2870         LDA (Transmit.Adr.Lo)
 2880         STA Printer.ACIA.TxD
 2890         INC Transmit.Adr.Lo  fig next transmit adr
 2900         BNE Next
 2910         INC Transmit.Adr.Hi
 2920         BNE Next
 2930         LDX #IIc.Aux.Bank.Avail
 2940         STX Transmit.Adr.Lo
 2950  Cant.Transmit
 2960  Next   JMP Scan
 2970  IIc.Aux.Bank.Avail .eq *
 2980  BufLen .eq $10000-IIc.Aux.Bank.Avail
 2990   .lif

