         nam   CC3IO
         ttl   os9 device driver

         ifp1
         use   defsfile
         endc

tylg     set   Drivr+Objct
atrv     set   ReEnt+rev
rev      set   $01

         mod   eom,name,tylg,atrv,start,size

u0000    rmb   1
u0001    rmb   1
u0002    rmb   1
u0003    rmb   1
u0004    rmb   1
u0005    rmb   1
u0006    rmb   3
u0009    rmb   2
u000B    rmb   1
u000C    rmb   1
u000D    rmb   1
u000E    rmb   2
u0010    rmb   6
u0016    rmb   2
u0018    rmb   1
u0019    rmb   1
u001A    rmb   1
u001B    rmb   1
u001C    rmb   1
u001D    rmb   1
u001E    rmb   1
u001F    rmb   1
u0020    rmb   2
u0022    rmb   1
u0023    rmb   1
u0024    rmb   1
u0025    rmb   1
u0026    rmb   1
u0027    rmb   1
u0028    rmb   1
u0029    rmb   1
u002A    rmb   1
u002B    rmb   1
u002C    rmb   1
u002D    rmb   2
u002F    rmb   1
u0030    rmb   1
u0031    rmb   1
u0032    rmb   1
u0033    rmb   1
u0034    rmb   1
u0035    rmb   1
u0036    rmb   1
u0037    rmb   4
u003B    rmb   1
u003C    rmb   11
u0047    rmb   1
u0048    rmb   2
u004A    rmb   6
u0050    rmb   6
u0056    rmb   1
u0057    rmb   9
u0060    rmb   1
u0061    rmb   1
u0062    rmb   1
u0063    rmb   1
u0064    rmb   1
u0065    rmb   1
u0066    rmb   1
u0067    rmb   25
u0080    rmb   2
u0082    rmb   22
u0098    rmb   13
u00A5    rmb   26
u00BF    rmb   7
u00C6    rmb   58
size     equ   .
         fcb   $07
name     equ   *
         fcs   /CC3IO/
         fcb   $10
start    equ   *
         lbra  Init
         lbra  Read
         lbra  Write
         lbra  GetStat
         lbra  SetStat
         ldx   <u00A5
         cmpu  <$20,x
         bne   L0045
         lbsr  L0614
         cmpu  <$20,x
         bne   L0045
         pshs  cc
         orcc  #IRQMask
         clra
         clrb
         std   <$20,x
         ldx   >$00E0
         stx   >$00B2
         puls  cc
L0045    ldb   #$0C
         lbra  L06EB
Init     ldx   <u00A5
         ldd   <$20,x
         bne   L00A3
         leax  >L02C0,pcr
         stx   >$00B2
         leax  >L0BCF,pcr
         stx   >$1017
         leax  >L0614,pcr
         pshs  x
         leax  >L06AE,pcr
         tfr   x,d
         ldx   <u00A5
         std   >$00C4,x
         puls  b,a
         std   >$00C2,x
         stu   <$20,x
         lbsr  L06AE
         lda   #$1E
         sta   <$61,x
         sta   <$29,x
         lda   #$03
         sta   <$62,x
         deca  
         sta   ,x
         inc   <$3C,x
         lda   #$01
         sta   <$3D,x
         lda   #$78
         sta   <$3E,x
         ldd   #$FFFF
         std   <$28,x
         std   <$2B,x
L00A3    ldd   #$0078
         std   <u0028,u
         ldd   <$26,y
         std   <u001F,u
         lbra  L0B16
ReaD    lda   <u0024,u
         lbne  L07B9
         leax  >u0080,u
         ldb   <u0034,u
         orcc  #$10
         cmpb  <u0033,u
         beq   L00D2
         abx   
         lda   ,x
         bsr   L00ED
         stb   <u0034,u
         andcc #$EE
         rts   
L00D2    lda   u0004,u
         sta   u0005,u
         andcc #$EF
         ldx   #$0000
         os9   F$Sleep  
         clr   u0005,u
         ldx   <u0050
         ldb   <$19,x
         beq   ReaD
         cmpb  #$04
         bcc   ReaD
         coma  
         rts   
L00ED    incb  
         cmpb  #$7F
         bls   L00F3
         clrb  
L00F3    rts   
L00F4    lsl   <u0001
         fcb   $02 
         clr   >$F8FF
         neg   <u0000
         lsl   <u0001
         neg   <u00BF
         eorb  >$FF00
         neg   <u0010
         subd  ,y
         bge   L010D
         std   ,y
         bra   L0115
L010D    ldd   ,y
         bpl   L0115
         clra  
         clrb  
         std   ,y
L0115    rts   
L0116    ldb   #$01
         pshs  u,y,x,b,a
         ldb   <u0063,u
         beq   L017E
         lda   <u0034,u
         bita  #$78
         beq   L0177
         clr   $01,s
         lda   #$01
         sta   <u0067,u
         lda   #$08
         ldb   #$03
         pshs  b,a
         leax  >L00F4,pcr
         leay  <u0056,u
L013A    bita  <u0034,u
         beq   L015D
         lslb  
         lslb  
         tst   <u0030,u
         beq   L0149
         incb  
         bra   L0154
L0149    tst   <u0031,u
         beq   L0154
         addb  #$02
         ldd   b,x
         bra   L0159
L0154    ldb   b,x
         sex   
         addd  ,y
L0159    std   ,y
         ldd   ,s
L015D    lsla  
         decb  
         cmpb  #$01
         bne   L0165
         leay  -$02,y
L0165    std   ,s
         bpl   L013A
         puls  b,a
         ldd   #$027F
         bsr   L0104
         leay  $02,y
         ldd   #$00BF
         bsr   L0104
L0177    lda   <u0065,u
         bne   L01B5
         lda   ,s
L017E    tst   <u0064,u
         beq   L01B7
         clr   <u0064,u
         cmpa  #$81
         bne   L0197
         ldb   <u0035,u
         bne   L01B5
         ldx   <u0020,u
         com   <$21,x
         bra   L01B5
L0197    cmpa  #$82
         bne   L01A0
         lbsr  L0604
         bra   L01B5
L01A0    cmpa  #$83
         bne   L01A9
         lbsr  L0614
         bra   L01B5
L01A9    cmpa  #$84
         bne   L01B7
         ldb   <u0035,u
         bne   L01B5
         com   <u0063,u
L01B5    clr   $01,s
L01B7    ldb   $01,s
         puls  pc,u,y,x,b,a
L01BB    pshs  x,b
         leax  <u003C,u
         tst   $02,x
         lbeq  L0258
         leas  -$05,s
         tfr   a,b
         tst   <u0063,u
         bne   L01E0
         ldb   #$05
         lda   $01,x
         anda  #$02
         sta   ,s
         beq   L01DA
         lslb  
L01DA    andb  $05,s
         tsta  
         beq   L01E0
         lsrb  
L01E0    clra  
         lsrb  
         rola  
         lsrb  
         std   $01,s
         bne   L0208
         lda   $05,x
         beq   L0256
         bsr   L025A
         beq   L01F4
         bsr   L0263
         beq   L023B
L01F4    dec   $05,x
         bne   L023B
         clra  
         clrb  
         sta   >u00C6,u
         std   $06,x
         std   $0A,x
         std   $0C,x
         std   $0E,x
         bra   L0256
L0208    lda   $02,x
         sta   $05,x
         bsr   L025A
         beq   L023B
         bsr   L0263
         inc   >$008A,x
         ldd   <$18,x
         std   <$12,x
         ldd   <$1A,x
         std   <$14,x
         pshs  u
         ldu   <u0020,u
         lda   <u0026,u
         beq   L0239
         ldb   <u0027,u
         clr   <u0026,u
         os9   F$Send   
         clr   >$008A,x
L0239    puls  u
L023B    ldd   $0C,x
         cmpa  #$FF
         beq   L0242
         inca  
L0242    cmpb  #$FF
         beq   L0247
         incb  
L0247    std   $0C,x
         ldd   $06,x
         cmpd  #$FFFF
         beq   L0254
         addd  #$0001
L0254    std   $06,x
L0256    leas  $05,s
L0258    puls  pc,x,b
L025A    ldd   $08,x
         eora  $03,s
         eorb  $04,s
         std   $05,s
         rts   
L0263    ldd   $0C,x
         tst   $05,s
         beq   L0279
         sta   $0E,x
         lda   $03,s
         bne   L0278
         lda   $0A,x
         cmpa  #$FF
         beq   L0276
         inca  
L0276    sta   $0A,x
L0278    clra  
L0279    tst   $06,s
         beq   L028D
         stb   $0F,x
         ldb   $04,s
         bne   L028C
         ldb   $0B,x
         cmpb  #$FF
         beq   L028A
         incb  
L028A    stb   $0B,x
L028C    clrb  
L028D    std   $0C,x
         ldd   $03,s
         std   $08,x
         ldd   $05,s
         rts   
L0296    lda   <u0063,u
         beq   L02B6
         clra  
         ldb   #$DF
         stb   $02,x
         ldb   ,x
         bitb  #$40
         bne   L02A7
         inca  
L02A7    ldb   #$BF
         stb   $02,x
         ldb   ,x
         bitb  #$40
         bne   L02B3
         ora   #$04
L02B3    sta   <u0065,u
L02B6    clrb  
         comb  
         stb   $02,x
         ldb   ,x
         comb  
         andb  #$0F
         rts   
L02C0    ldu   >$00A5
         ldy   <u0020,u
         lbeq  L03EB
         lda   <u001B,u
         beq   L02D4
         deca  
         sta   <u001B,u
L02D4    ldb   <$23,y
         beq   L02EB
         lda   $06,y
         bpl   L02E3
         lda   u0002,u
         ora   u000E,u
         bne   L0303
L02E3    lda   #$00
         lbsr  L0720
         clr   <$23,y
L02EB    ldb   u0001,u
         beq   L0303
         decb  
         stb   u0001,u
         bne   L0303
         lda   u0002,u
         ora   u000E,u
         beq   L02FE
         inc   u0001,u
         bra   L0303
L02FE    lda   #$02
         lbsr  L0720
L0303    lda   <u0063,u
         bne   L031D
         lda   <u003B,u
         beq   L031D
         deca  
         bne   L031A
         pshs  y,x
         lbsr  L08C8
         puls  y,x
         lda   <u0060,u
L031A    sta   <u003B,u
L031D    ldx   #$FF00
         clra  
         clrb  
         std   <u0034,u
         lbsr  L0296
         lbsr  L01BB
         tstb  
         lbne  L03EB
         clr   $02,x
         lda   ,x
         coma  
         anda  #$7F
         lbeq  L03D3
         pshs  x
         lbsr  L0405
         puls  x
         lbmi  L03D3
         lbsr  L02B6
         lbne  L03D3
         cmpa  <u0027,u
         bne   L0367
         ldb   <u0029,u
         lbeq  L03EB
         decb  
         beq   L0362
L035C    stb   <u0029,u
         lbra  L03EB
L0362    ldb   <u0062,u
         bra   L0375
L0367    sta   <u0027,u
         ldb   <u0062,u
         tst   <u0035,u
         bne   L035C
         ldb   <u0061,u
L0375    stb   <u0029,u
         lbsr  L0116
         beq   L03E8
         ldb   #$01
         stb   >u00BF,u
         ldu   <u0020,u
         ldb   <u0033,u
         leax  >u0080,u
         abx   
         lbsr  L00ED
         cmpb  <u0034,u
         beq   L0399
         stb   <u0033,u
L0399    sta   ,x
         beq   L03B9
         cmpa  u000D,u
         bne   L03A9
         ldx   u0009,u
         beq   L03C6
         sta   $08,x
         bra   L03C6
L03A9    ldb   #$03
         cmpa  u000B,u
         beq   L03B5
         ldb   #$02
         cmpa  u000C,u
         bne   L03B9
L03B5    lda   u0003,u
         bra   L03CA
L03B9    lda   <u0024,u
         beq   L03C6
         ldb   <u0025,u
         clr   <u0024,u
         bra   L03CE
L03C6    ldb   #$01
         lda   u0005,u
L03CA    beq   L03EB
         clr   u0005,u
L03CE    os9   F$Send   
         bra   L03EB
L03D3    clra  
         ldb   <u0036,u
         bne   L03E8
         clrb  
         std   <u0026,u
         coma  
         sta   <u0028,u
         comb  
         sta   <u002A,u
         std   <u002B,u
L03E8    clr   <u0036,u
L03EB    ldu   <u00A5
         lda   <u0066,u
         anda  <u0067,u
         beq   L0403
         lda   u0002,u
         ora   u000E,u
         bne   L0403
         lda   #$03
         lbsr  L0720
         clr   <u0067,u
L0403    clrb  
         rts   
L0405    clra  
         clrb  
         std   <u0030,u
         std   <u0032,u
         coma  
         comb  
         std   <u002D,u
         sta   <u002F,u
         deca  
         sta   $02,x
L0418    lda   ,x
         coma  
         anda  #$7F
         beq   L042C
         ldb   #$FF
L0421    incb  
         lsra  
         bcc   L0428
         lbsr  L04CA
L0428    cmpb  #$06
         bcs   L0421
L042C    inc   <u0032,u
         orcc  #$01
         rol   $02,x
         bcs   L0418
         lbsr  L0527
         bmi   L04AB
         cmpa  <u0028,u
         bne   L0442
         inc   <u0035,u
L0442    sta   <u0028,u
         beq   L0466
         suba  #$1A
         bhi   L0466
         adda  #$1A
         ldb   <u0031,u
         bne   L0495
         adda  #$40
         ldb   <u0030,u
         ldy   <u0020,u
         eorb  <$21,y
         andb  #$01
         bne   L0495
         adda  #$20
         bra   L0495
L0466    ldb   #$03
         mul   
         lda   <u0030,u
         beq   L0471
         incb  
         bra   L0478
L0471    lda   <u0031,u
         beq   L0478
         addb  #$02
L0478    ldx   <u0020,u
         lda   <$22,x
         beq   L0484
         cmpb  #$11
         ble   L04A9
L0484    cmpb  #$4C
         blt   L048D
         inc   <u0033,u
         subb  #$06
L048D    leax  >L05A2,pcr
         lda   b,x
         bmi   L04AC
L0495    ldb   <u0033,u
         beq   L04A6
         cmpa  #$3F
         bls   L04A4
         cmpa  #$5B
         bcc   L04A4
         ora   #$20
L04A4    ora   #$80
L04A6    andcc #$F7
         rts   
L04A9    orcc  #$08
L04AB    rts   
L04AC    inc   <u0036,u
         inc   <u0064,u
         bra   L04A6
L04B4    pshs  b,a
         clrb  
         orcc  #$01
         inca  
L04BA    rolb  
         deca  
         bne   L04BA
         bra   L04C2
         pshs  b,a
L04C2    orb   <u0034,u
         stb   <u0034,u
         puls  pc,b,a
L04CA    pshs  b,a
         cmpb  #$03
         bne   L04D9
         lda   <u0032,u
         cmpa  #$03
         blt   L04D9
         bsr   L04B4
L04D9    lslb  
         lslb  
         lslb  
         addb  <u0032,u
         cmpb  #$33
         bne   L04EA
         inc   <u0033,u
         ldb   #$04
         bra   L04C2
L04EA    cmpb  #$34
         bne   L04F5
         inc   <u0031,u
         ldb   #$02
         bra   L04C2
L04F5    cmpb  #$37
         bne   L0500
         com   <u0030,u
         ldb   #$01
         bra   L04C2
L0500    pshs  x
         leax  <u002D,u
         bsr   L050B
         puls  x
         puls  pc,b,a
L050B    pshs  a
         lda   ,x
         bpl   L0517
         stb   ,x
         ldb   #$01
         puls  pc,a
L0517    lda   $01,x
         bpl   L0521
         stb   $01,x
         ldb   #$02
         puls  pc,a
L0521    stb   $02,x
         ldb   #$03
         puls  pc,a
L0527    pshs  y,x,b
         ldb   <u0026,u
         beq   L0561
         leax  <u002A,u
         pshs  b
L0533    leay  <u002D,u
         ldb   #$03
         lda   ,x
         bmi   L0552
L053C    cmpa  ,y
         bne   L0546
         clr   ,y
         com   ,y
         bra   L0552
L0546    leay  $01,y
         decb  
         bne   L053C
         lda   #$FF
         sta   ,x
         dec   <u0026,u
L0552    leax  $01,x
         dec   ,s
         bne   L0533
         leas  $01,s
         ldb   <u0026,u
         beq   L0561
         bsr   L058A
L0561    leax  <u002D,u
         lda   #$03
L0566    ldb   ,x+
         bpl   L057A
         deca  
         bne   L0566
         ldb   <u0026,u
         beq   L0586
         decb  
         leax  <u002A,u
         lda   b,x
         bra   L0584
L057A    tfr   b,a
         leax  <u002A,u
         bsr   L050B
         stb   <u0026,u
L0584    puls  pc,y,x,b
L0586    orcc  #$08
         puls  pc,y,x,b
L058A    leax  <u002A,u
         bsr   L0595
         leax  $01,x
         bsr   L0595
         leax  -$01,x
L0595    lda   ,x
         bpl   L05A1
         ldb   $01,x
         bmi   L05A1
         sta   $01,x
         stb   ,x
L05A1    rts   
L05A2    nega  
         neg   $00,x
         inc   <u001C
         sync  
         dec   <u001A
         nop   
         lsl   <u0018
         fcb   $10 
         rol   <u0019
         fcb   $11 
         bra   L05D3
         bra   L05E5
         leax  ,x++
         leay  $01,y
         inc   >$3222
         neg   <u0033
         bls   L063E
         pshs  y,b
         neg   <u0035
         bcs   L05C6
L05C6    pshu  y,b,a
         neg   <u0037
         beq   L062A
         fcb   $38 8
         bvc   L062A
         rts   
         bvs   L062F
         abx   
L05D3    bpl   L05D5
L05D5    rti   
         bmi   L0657
         bge   L0616
         fcb   $7B  
         blt   L061A
         clrb  
         bgt   L061E
         tst   >$2F3F
         incb  
         tst   <u000D
         tst   <u0082
         subd  #$8405
         com   <u001B
         leay  -$0D,y
         puls  y,x,a
         pshs  y,x,b,a
L05F3    stb   $06,s
         ldx   <u0024
         lda   $0D,x
         ldb   #$09
         mul   
         ldy   <u0080
         leax  d,y
         stx   $07,s
         rts   
L0604    pshs  u,y,x,b,a
         leas  <-$11,s
         ldb   #$09
         bsr   L05F3
         stx   $09,s
         sty   $07,s
         bra   L0626
L0614    pshs  u,y,x,b,a
L0616    leas  <-$11,s
         ldb   #$F7
         bsr   L05F3
         leay  -$09,y
         sty   $09,s
         leax  -$09,x
         stx   $07,s
L0626    ldx   <u00A5
         ldu   <$20,x
         lbeq  L06A8
L062F    ldx   u0001,u
         stx   $0B,s
         stx   $0F,s
         ldd   ,x
         std   $0D,s
L0639    ldx   $0F,s
L063B    ldb   $04,s
         leax  b,x
         cmpx  $09,s
         bne   L0645
         ldx   $07,s
L0645    stx   $0F,s
         ldd   ,x
         cmpd  $0D,s
         bne   L063B
         ldu   $02,x
         beq   L063B
         cmpx  $0B,s
         beq   L06A3
         lda   <u001E,u
         beq   L0639
         ldx   <u0016,u
         beq   L069A
         lda   u0003,u
         beq   L069A
         ldy   <u0048
         lda   a,y
         beq   L069A
         clrb  
         tfr   d,y
         lda   >$00AC,y
         leay  <$30,y
         cmpa  #$02
         bhi   L067F
         ldb   #$02
         lda   b,y
         bra   L0682
L067F    lda   a,y
         clrb  
L0682    stb   ,s
L0684    cmpa  ,x
         beq   L069A
         decb  
         bmi   L068F
         lda   b,y
         bra   L0684
L068F    ldb   ,s
         lda   b,y
         ldx   <$3D,x
         bne   L0684
         bra   L0639
L069A    ldx   <u00A5
         stu   <$20,x
         clr   >$00BF,x
L06A3    inc   <u0023,u
         bsr   L06AE
L06A8    leas  <$11,s
         clrb  
         puls  pc,u,y,x,b,a
L06AE    pshs  x
         ldd   <u0028,u
         ldx   <u00A5
         sta   <$3B,x
         sta   <$60,x
         stb   <$3E,x
         ldb   <u002B,u
         stb   <$66,x
         lda   u0006,u
         sta   $0B,x
         clra  
         puls  pc,x
WriTE    ldb   <u002C,u
         bne   L0746
         sta   <u001F,u
         cmpa  #$20
         bcc   L06E9
         cmpa  #$1E
         bcc   L0735
         cmpa  #$1B
         beq   L0739
         cmpa  #$05
         beq   L0739
         cmpa  #$07
         lbeq  L0BCF
L06E9    ldb   #$03
L06EB    lda   <u001F,u
         ldx   <u00A5
         stu   $0C,x
L06F2    pshs  a
         clra  
         cmpu  <$20,x
         bne   L06FC
         inca  
L06FC    sta   $0A,x
         leax  <$68,x
         lda   <u001D,u
         ldx   a,x
         puls  a
         beq   L0731
         leax  b,x
         ldb   <u001D,u
         beq   L0713
         jmp   ,x
L0713    incb  
         stb   >$100E
         jsr   ,x
L0719    pshs  cc
         clr   >$100E
         puls  pc,cc
L0720    pshs  u,y,x
         ldu   <u0020,u
L0725    ldb   #$0F
         ldx   <u00A5
         bsr   L06F2
         puls  pc,u,y,x
L072D    pshs  u,y,x
         bra   L0725
L0731    comb
         ldb   #E$MNF
         rts
L0735    cmpa  #$1E
         beq   L0744
L0739    leax  <L06E9,pcr
         ldb   #$01
         stx   <u002D,u
         stb   <u002C,u
L0744    clrb
         rts
L0746    ldx   <u0031,u
         sta   ,x+
         stx   <u0031,u
         decb
         stb   <u002C,u
         bne   L0744
         clrb
         ldx   <u00A5
         cmpu  <$20,x
         bne   L075E
         incb
L075E    stb   $0A,x
         stu   $0C,x
         ldx   <u002F,u
         stx   <u0031,u
         ldb   <u001D,u
         beq   L0770
         jmp   [<u002D,u]
L0770    incb
         stb   u000E,u
         jsr   [<u002D,u]
         bra   L0719

GetStat  sta   <u001F,u
         cmpa  #SS.EOF
         beq   L07B7
         ldx   $06,y
         cmpa  #SS.ComSt
         beq   L07A0
         cmpa  #SS.JOY
         beq   SSJOY
         cmpa  #SS.Mouse
         lbeq  SSMouse
         cmpa  #SS.RDY
         beq   SSRDY
         cmpa  #SS.KySns
         beq   SSKySns
         cmpa  #$92
         beq   L07CE
         ldb   #$06
         lbra  L06EB
L07A0    lda   u0006,u
         clrb
         std   $06,x
         rts
SSRDY    ldb   <u0033,u
         cmpb  <u0034,u
         beq   L07B9
         bhi   L07B2
         addb  #$80
L07B2    subb  <u0034,u
         stb   $02,x
L07B7    clrb
         rts
L07B9    comb
         ldb   #$F6
         rts

SSKySns  ldy   <u00A5
         clrb
         cmpu  <$20,y
         bne   L07CA
         ldb   <$34,y
L07CA    stb   $01,x
         clrb
         rts
L07CE    ldb   >$1009
         clra
         stb   $04,x
         rts

SSJOY    clrb
         pshs  y,x,cc
         ldy   <D.CCMem
         cmpu  <$20,y
         beq   L07EA
         clra
         std   $04,x
         std   $06,x
         sta   $01,x
         bra   L0830
L07EA    orcc  #IRQMask
         lda   #$FF
         sta   $FF02
         lda   $FF00
         coma
         ldy   $04,x
         bne   L07FE
         anda  #$05
         bra   L0801
L07FE    anda  #$0A
         lsra
L0801    lsra
         bcc   L0806
         ora   #$01
L0806    sta   $01,x
         lda   $FF03
         ora   #$08
         ldy   $04,x
         bne   L0814
         anda  #$F7
L0814    sta   $FF03
         lda   $FF01
         anda  #$F7
         bsr   L0832
         std   $04,x
         lda   $FF01
         ora   #$08
         bsr   L0832
         pshs  b,a
         ldd   #$003F
         subd  ,s++
         std   $06,x
L0830    puls  pc,y,x,cc

L0832    sta   $FF01
         lda   #$7F
         ldb   #$40
         bra   L0846
L083B    lsrb
         cmpb  #$01
         bhi   L0846
         lsra
         lsra
         tfr   a,b
         clra
         rts
L0846    pshs  b
         sta   $FF20
         tst   $FF00
         bpl   L0854
         adda  ,s+
         bra   L083B
L0854    suba  ,s+
         bra   L083B

SSMouse  pshs  u,y,x
         ldx   <D.CCMem
         cmpu  <$20,x
         beq   L0875
         ldy   ,s
         ldb   #32                     size of mouse packet
L0867    clr   ,-s                     make room on stack
         decb
         bne   L0867
         leax  ,s                      point X at mouse packet
         bsr   L08B8
         leas  <32,s                   clean up stack
         puls  pc,u,y,x
L0875    lda   <$63,x
         bne   L0897
         lda   <$60,x
         bne   L089F
         pshs  u,y,x
         bsr   L08CA
         puls  u,y,x
         lda   <$66,x
         anda  <$67,x
         beq   L089F
         lda   #$03
         lbsr  L072D
         clr   <$67,x
         bra   L089F
L0897    lda   <$3D,x
         ora   #$40
         sta   <$3D,x
L089F    lda   #$01
         lbsr  L072D
         leax  <$3C,x
         ldy   ,s
         bsr   L08B8
         pshs  cc
         lda   $01,x
         anda  #$7F
         sta   $01,x
         puls  cc
         puls  pc,u,y,x
L08B8    ldu   $04,y
         ldy   <D.Proc
         ldb   P$Task,y
         clra
         ldy   #32
         os9   F$Move
         rts
L08C8    ldx   <u00A5
L08CA    leax  <$3C,x
         clra
         ldb   <$17,x
         tfr   d,y
         ldb   #$03
         lda   $01,x
         pshs  y,x,b,a
         ldd   #$FFFF
         pshs  b,a
         pshs  b,a
         ldx   #$FF00
         lda   <$23,x
         ldb   <$20,x
         pshs  b,a
         anda  #$F7
         sta   <$23,x
         lda   $01,x
         ldb   $03,x
         pshs  b,a
         orb   #$08
         lda   $08,s
         anda  #$02
         bne   L0900
         andb  #$F7
L0900    stb   $03,x
         leay  >L09A7,pcr
         ldb   $0D,s
         bne   L090E
         leay  >L0832,pcr
L090E    ldb   $09,s
         andb  #$01
         beq   L091C
         lda   ,s
         ora   #$08
         jsr   ,y
         std   $06,s
L091C    ldb   $09,s
         andb  #$02
         beq   L092A
         lda   ,s
         anda  #$F7
         jsr   ,y
         std   $04,s
L092A    puls  b,a
         sta   $01,x
         stb   $03,x
         puls  b,a
         stb   <$20,x
         sta   <$23,x
         ldx   $06,s
         ldd   ,s
         bmi   L0945
         tst   $09,s
         bne   L0945
         lda   #$0A
         mul
L0945    cmpd  <$18,x
         beq   L0953
         std   <$18,x
         lda   #$01
         sta   <$2B,x
L0953    ldd   $02,s
         bmi   L0959
         bsr   L096B
L0959    cmpd  <$1A,x
         beq   L0967
         std   <$1A,x
         lda   #$01
         sta   <$2B,x
L0967    leas  $04,s
         puls  pc,y,x,b,a
L096B    tst   $0B,s
         bne   L0973
         lda   #$03
         mul
         rts
L0973    pshs  a
         lda   #$09
         pshs  a
         lda   #$03
         mul
         pshs  b,a
         lda   $03,s
         ldb   #$03
         mul
         exg   b,a
         addd  ,s++
L0987    clr   $01,s
         cmpa  #$0A
         bcs   L0991
         inc   $01,s
         suba  #$0A
L0991    lsr   $01,s
         rolb
         rola
         dec   ,s
         bne   L0987
         cmpb  #$BF
         beq   L09A3
         cmpa  #$0A
         bcs   L09A3
         addb  #$01
L09A3    clra
         leas  $02,s
         rts

* X = base of CC h/w addr ($FF00)
* A = value to place in $FF01
L09A7    pshs  cc
         sta   $01,x                   place in $FF01
         lda   #$FF
         sta   <$20,x                  set up cassette port
         lda   #$5A                    delay loop
L09B2    deca
         bne   L09B2
         ldd   #$0329
         pshs  a
         lda   #$02
         orcc  #FIRQMask+IRQMask
         sta   <$20,x                  set cassette port again
L09C1    lda   ,x                      get byte at $FF00
         bmi   L09D3
         decb                          B initially $29
         bne   L09C1
         dec   ,s                      ,S initially $03
         bpl   L09C1
         puls  a
         ldd   #639                    just assume highest
         puls  pc,cc
L09D3    puls  a
         decb
         pshs  b,a                     push hi-res count
         ldd   #640
         subd  ,s++                    subtract count from 640
         bcc   L09E3
         clra
         clrb
         puls  pc,cc
L09E3    cmpd  #639
         bcs   L09EC
         ldd   #639
L09EC    puls  pc,cc

SetStat  sta   <u001F,u
         ldx   $06,y
         cmpa  #$28
         lbeq  L0B05
         cmpa  #$92
         lbeq  L0AE5
         cmpa  #$27
         lbeq  L0ADA
         cmpa  #$98
         lbeq  L0BB1
         cmpa  #$1A
         beq   L0A2E
         cmpa  #$8A
         beq   L0A43
         cmpa  #$1B
         beq   L0A6B
         cmpa  #$89
         beq   L0A7E
         cmpa  #$94
         lbeq  L0AAD
         cmpa  #$29
         bne   L0A29
         ldx   $03,y
         stx   u0001,u
L0A29    ldb   #$09
         lbra  L06EB
L0A2E    pshs  cc
         lda   <u0034,u
         suba  <u0033,u
         pshs  a
         bsr   L0A5A
         tst   ,s+
         bne   L0A65
         std   <u0024,u
         puls  pc,cc
L0A43    pshs  cc
         bsr   L0A5A
         ldx   <u00A5
         cmpu  <$20,x
         bne   L0A55
         tst   >$00C6,x
         bne   L0A61
L0A55    std   <u0026,u
         puls  pc,cc
L0A5A    orcc  #$50
         lda   $05,y
         ldb   $05,x
         rts
L0A61    clr   >$00C6,x
L0A65    puls  cc
         os9   F$Send
         rts
L0A6B    lda   $05,y
         cmpa  <u0024,u
         bne   L0AE3
         clr   <u0024,u
         cmpa  <u0026,u
         bne   L0AE3
         clr   <u0026,u
         rts
L0A7E    ldd   $04,x
         cmpa  #$FF
         beq   L0A87
         sta   <u0028,u
L0A87    cmpb  #$FF
         beq   L0A8E
         stb   <u0029,u
L0A8E    ldd   $06,x
         std   <u002A,u
         ldy   <u00A5
         cmpu  <$20,y
         bne   L0AAB
         stb   <$66,y
         ldd   <u0028,u
         sta   <$60,y
         sta   <$3B,y
         stb   <$3E,y
L0AAB    clrb
         rts
L0AAD    ldy   <u00A5
         cmpu  <$20,y
         bne   L0AD8
         ldd   $06,x
         cmpd  #$FFFF
         beq   L0AC1
         std   <$61,y
L0AC1    ldd   $04,x
         cmpa  #$01
         lbgt  L0B01
         sta   <$53,y
         tstb
         beq   L0B01
         cmpb  #$02
         lbgt  L0B01
         stb   <$3D,y
L0AD8    clrb
         rts
L0ADA    ldd   $04,x
         beq   L0AE0
         ldb   #$FF
L0AE0    stb   <u0022,u
L0AE3    clrb
         rts
L0AE5    ldd   $04,x
         cmpd  #$0002
         bhi   L0B01
         lda   <u0098
         anda  #$EF
         bitb  #$02
         beq   L0AF7
         ora   #$10
L0AF7    sta   <u0098
         stb   >$1009
         inc   <u0023,u
         clrb
         rts
L0B01    comb
         ldb   #E$IllArg
         rts
L0B05    ldd   $06,x
         eora  u0006,u
         anda  #$80
         bne   L0B01
         lda   $06,x
         bsr   L0B16
         lbcc  L0A29
         rts
L0B16    sta   u0006,u
         bmi   L0B2A
         pshs  u,y,a
         lda   #$02
         sta   <u001D,u
         leax  >L0B9E,pcr
         bsr   L0B48
         puls  u,y,a
         rts
L0B2A    pshs  u,y
         clra
         sta   <u001D,u
         leax  >L0BAA,pcr
         lda   #$80
         bsr   L0B48
         bcc   L0B42
         leax  >L0BA4,pcr
         lda   #$80
         bsr   L0B48
L0B42    puls  u,y
         bcs   L0B47
L0B46    clrb
L0B47    rts
L0B48    ldb   <u002F,u
         bne   L0B46
         pshs  u
         ldu   <u00A5
         bita  <u0024,u
         puls  u
         bne   L0B76
         tsta
         bpl   L0B5C
         clra
L0B5C    pshs  y,a
         bsr   L0B7B
         bcc   L0B66
         puls  y,a
         bra   L0B47
L0B66    puls  a
         ldx   <u00A5
         leax  <$68,x
         sty   a,x
         puls  y
         cmpa  #$02
         bgt   L0B46
L0B76    ldb   #$00
         lbra  L06EB
L0B7B    ldd   <u0050
         pshs  u,x,b,a
         ldd   <u004A
         std   <u0050
         lda   #Systm+Objct
         os9   F$Link
         ldx   2,s
         bcc   L0B91
         ldu   <u004A
         os9   F$Load
L0B91    puls  u,x,b,a
         std   <u0050
         lbcs  L0731
         rts
         coma  
         clra  
         fcb   $38 8
         suba  >$5644
         asra  
         rola  
         fcb   $4E N
         andb  <u0047
         fcb   $52 R
         rora  
         rola  
         fcb   $4E N
         andb  <u0057
         rol   $0E,s
         lsra  
         rola  
         jmp   [,s]
L0BB1    ldd   #$1000
         subd  $06,x
         lble  L0B01
         cmpd  #$1000
         lbge  L0B01
         tfr   d,y
         ldd   $04,x
         stb   >$101B
         ldb   #$01
         anda  #$3F
         bra   L0BD9
L0BCF    inc   >$101C
         ldd   #$3C20
         ldy   #$0080
L0BD9    lsla  
         lsla  
         lbeq  L0B46
         ora   #$02
         pshs  x,b,a
         ldx   #$FF00
         lda   $01,x
         ldb   $03,x
         pshs  b,a
         anda  #$F7
         andb  #$F7
         sta   $01,x
         stb   $03,x
         leax  <$20,x
         lda   $03,x
         pshs  a
         ora   #$08
         sta   $03,x
L0BFF    ldb   $04,s
L0C01    lda   $03,s
         bsr   L0C29
         lda   #$02
         bsr   L0C29
         decb  
         bne   L0C01
         ldb   >$101C
         bne   L0C16
         ldb   >$101B
         bne   L0BFF
L0C16    clr   >$101C
         puls  a
         sta   $03,x
         leax  <-$20,x
         puls  b,a
         sta   $01,x
         stb   $03,x
         clrb  
         puls  pc,x,b,a
L0C29    pshs  y
         sta   ,x
L0C2D    leay  -$01,y
         bne   L0C2D
         puls  pc,y
         emod
eom      equ   *
