call 0bd19h ;; mc wait flyback
        di
        ld bc,0f40eh;; we want to select AY register 14
        out (c),c
        ld b,0f6h
        and 030h
        ld c,a
        or 0c0h  ;; AY control select register.
        out (c),a
        out (c),a ;; BUG? No need . This should set AY control to do this twice0 to also be compatible with Plus.
        inc b
        ld a,092h
        out (c),a
        push bc
        ld bc,0f649h ;; AY read from register and select keyboard line 9 (joystick)
        out (c),c
        out (c),c ;; BUG? No need to do this twice.
        ld (0a410h),hl ;; detected 'position' or 'ffff' for not detected
        pop bc
        ;; BUG: For compatibility with Plus this should set AY control to 0 via Port F6xx.
        ld a,082h
        out (c),a
        call 0bd19h ;; mc wait flyback
        
        ;; BUG? this is jumping back to the 0x0a in     LD B,0ah
        ;; djnz $-4
        djnz l9d1e
        ld b,020h;; number of lines
l9d65h:
        push bc
        call sub_9d35h;; draw lines
        call sub_9c40h ;;detect
        pop bc
        ret
l9d91h:
        ld de,0ffech;; -20
        ld hl,00000h
        call 0bbc3h  ;; gra move relative
        ld a,000h
        call 0bbdeh ;; gra set pen
        call sub_09d35h;; lines
        ld a,001h
        call 0bbdeh ;; gra set pen
        ld de,0ffech;; -20
        ld hl,00000h
        call 0bbc3h ;; gra move relative
        call 0bbf9h ;; gra line relative
        ld de,(0a416h)
        ld hl,0ffech;; -20
        call 0bbc3h ;; gra move relative
        pop bc
        push hl
        push de
        call 09e08hsub_09e08h
        ld (0a414h),hl
        ld de,05398h
sub_9e1fh:
        call 09c8ahsub_9c8ah
        ld hl,(0a418h)
        ld (0a420h),hl
        nop
        nop
sub_0a028h:
        ld a,013h
        ld (la124h0a124h),a
        ld a,00eh
        ld (0a0e2h),a
        ld a,(la133h0a133h)
        bit 1,a
        jr z,la083h
        ld a,000h
        ld (la124h0a124h),a
        ld a,007h
        ld (0a0e2h),a
la083h:
        call 0bd28h ;; mc reset printer
 
        ld de,00000h
        ld hl,00000h
        ld (0a12dh),de
sub_a050h:
        ld a,000h
        ld (0a12ch),a
        ld a,000h
        call 0bd2bh ;; mc print char
        ld a,(la133h0a133h)
        bit 0,a
        jr z,la0f4hla0b4h
        ld a,002h
        call 0bd2bh ;; mc print char
        call 0bd2bh ;; mc print char
        jr la0f9h
la0f4hla0b4h:
        ld a,001h
        call 0bd2bh ;; mc print char
        ld a,(0a12ch)
        call 0bd2bh ;; mc print char
sub_a0ffh:
        call sub_a115h
        inc hl
        ld a,h
        cp 001h
        jp nz,la050hsub_a10dh:sub_a050h
        ld a,l
        cp 090h
        jp nz,la050hsub_a050h
        ld a,00ah
sub_a115h:        call 0bd2bh;; mc print char
        ld a,02fh
        call 0bb1eh ;; km test key
sub_a11dh:
        ret nz
        ld hl,(0a12dh)
        ld de,0000eh
la124h:
        add hl,de
        ld (0a12dh),hl
        ld de,(0a12dh)
        ld a,d
la133h:
        cp 002h
        jp nz,la050hsub_a050h
        ld a,e
        cp 084h
        jp nz,la050hsub_a050h
        ret
 
sub_a0ffh:
        ld b,a
        call 0bb99h ;; txt get paper
        ld (0a12ch),hl
        ret
 
sub_a10dh:
        ld (0a12fh),hl
        ld (0a131h),de
        ret
 
sub_a115h:
        ld hl,(0a12fh)
        ld de,(0a131h)
        ret
 
sub_a11dh:
        call sub_a0ffh
        call sub_a115h
        call 0bbf0h ;; gra test absolute
        ret
 
la10ch:
        nop
        add a,h
        nop
        nop
la18bh:
        nop
        nop
        nop
        nop
sub_a154h:
        call 0bc11h ;; scr get mode
        cp 000h
        ld (0a254h),a
        call 0bbc6h ;; gra ask cursor
        ld (la250h0a250h),hl        ld (la250h0a250h+2),de
la1b7h:
        call 0bb99h ;; txt get paper
        ld (la1f9h0a1f9h),a
        ld bc,00000h
        ld (0a24ch),bc
        ld (0a24eh),bc
        call 0a210hsub_a210
        ld a,02fh
        call 0bb1eh ;; km test key
        ld bc,05398h
        add hl,bc
        ld (la1aah0a1aah),hl
        ld de,(055e0h)
        ld hl,(0a24eh)
        ld bc,057e4h
        add hl,bc
        ld (la1b7h0a1b7h),hl
        ld hl,(05a2ch)
la1f9h:
        ret z
        jp la18bh
sub_a1efh:
        push de
        push hl
        pop bc
        pop hl
la237h:
        pop de
        cp 000h
        jr nz,la248h
        ld (la250h0a250h),hl        ld (la250h0a250h+2),de
        push bc
        call 0a210hsub_0a210h
        pop bc
la248h:
        ld hl,(la257h0a257h)
        ld de,(0a255h)
        ret
la250hsub_a210:        ld hl,(la250h0a250h)        ld de,(la250h0a250h+2)la257h:
        call 0bbeah ;; gra plot absolute
        ld hl,(0a24ch)
        ld bc,05398h
        add hl,bc
        ld de,(la250h0a250h+2)        ld (la237h0a237h),hl
        ld (05648h),de
        ld hl,(0a24ch)
        ld bc,057e4h
        add hl,bc
        ld de,(la250h0a250h)        ld (la248h+10a249),hl
        ld (05a94h),de
        ret
la24ch:
        or b
        ld (bc),a
        jr nz,la295h
        inc b
la295h:
        jr nz,$+3
        cp h