<pre>
;; Dissassembled and commented from MCPEN.BIN
 
        org 09c40h
        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        out (c),a  ;; AY control select register.
        out (c),a
        out (c),a ;; BUG. Should be out (c),c to be compatible with Plus.
        inc b
        ld a,092h
        out (c),a
        push bc
        ld bc,0f649h ;; AY control read from register and select keyboard line 9 (joystick)        out (c),c
        out (c),c
        out (c),c ;; BUG? No need to do this twice.
        ld b,0f4h
;; loop reading joystick until input seen or timeout
        ld hl,0fa66h ;; timeoutis 0-FA66 because it counts up from this starting point.                     ;; timeout is 59A loops.
l9c68:
        in a,(c)
        inc h
        jr nz,l9c68
              ;; timeout. not detected
        ld hl,0ffffh
        jr l9cbdh
l9c79:
        ;; detected.
        ld de,00420h
        add hl,de
l9cbd:
        ld (0a410hdata_0a410h),hl ;; detected 'position'or 'ffff' for not detected
        pop bc
        ld a,082h
        out (c),a
        dec b
        out (c),c;; Set AY control inactive.
        ei
        ret
        ret
;; HL = HL/DE
sub_9c94:
        ld a,h
        ld c,l
        ld b,010h;; 16 bits.
        ld hl,00000h
l9cdbh:
        ret
;; HL = HL * DE
sub_9caeh:
        ld a,l
        ld c,h
        ld b,010h;; 16 bits
        ld hl,00000h
l9cf5h:
        ;; detected.
        ld de,00002h
        call sub_9c94h;; HL = HL/DE
        ld de,00064h
        call sub_9caeh;; HL = HL*DE
        ld de,00084h
        call sub_9c94h;; HL = HL/DE
        ex de,hl
        ld hl,0018fh
        sbc hl,de
        ld (0a410hdata_0a410),hl
        ret
sub_9ce4sub_9ce4h:
        ld a,000h
        ld bc,01a1ah
        and a
        sbc hl,de
                ;; BUG? This is jumping just after 0x021 of LD HL and then executing two nops before LD DE,0000h        ;;jr nc,$+32        jr nc,l9d06
        ld hl,00000h
l9d06:
        ld de,00000h
        call 0bbc0h ;; gra move absolute
        call 0bc32h ;; scr set ink
        ld b,00ah
l9d1e:
        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
sub_9d35h:
        ld bc,(0a418hdata_0a418)
l9d79h:
        push bc
        ld hl,00014h
        call 0bbf9h ;; gra line relative
        ld de,(0a416hdata_0a416)
        ld hl,0ffech
        call 0bbc3h ;; gra move relative
        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
        ld bc,(0a420hdata_0a420)
l9db4h:
        push bc
        ld a,0ffh
        cp h
        jr nz,l9ddahsub_9d9ah
        ld de,00000h
        ld hl,00014h
        call 0bbf9h ;; gra line relative
        ld de,(0a416hdata_0a416)        ld hl,0ffech;; -20
        call 0bbc3h ;; gra move relative
        pop bc
        djnz l9db4h
        ld hl,0ffffh
        ld (0a410hdata_0a410),hl
        ret
l9ddahsub_9d9ah:
        pop bc
        ld (0a410hdata_0a410),hl
        call 0bbc6h ;; gra ask cursor
        ld (0a412hdata_0a412),de
        ret
        push hl
        push de
        call 09e08hsub_09e08h        ld (0a414hdata_0a414),hl
        ld de,05398h
        ld b,004h
l9e0bh:
        push bc
        ld hl,(0a414hdata_0a414)
        ld c,b
        ld b,000h
l9e2dh:
        push bc
        ld hl,(0a414hdata_0a414)
        ld c,b
        ld b,000h
        push de
        ld de,00002h
        call sub_9c94h;; HL = HL/DE
        pop de
        push hl
        ex de,hl
        ld de,(0a416hdata_0a416)        call sub_9c94h;; HL = HL/DE
        ex de,hl
        pop hl
sub_9e1fh:
        call 09c8ahsub_9c8ah        ld hl,(0a418hdata_0a418)        ld (0a420hdata_0a420h),hl        ld hl,(0a410hdata_0a410)
        ld a,0ffh
        cp h
        ret z
        ld (0a41chdata_a41c),hl        ld de,(0a412hdata_0a412)        ld (0a41ahdata_a41a),de
l9e7ah:
        ld de,0000ah
l9e85h:
        push hl
        ld hl,(0a412hdata_a412)
        add hl,de
        ex de,hl
        call sub_09dbeh
        call 0bbc0h ;; gra move absolute
sub_9e52h:
        call sub_09ed2h
        call sub_09de6h
        ld hl,(0a410hdata_a410)
        ld a,0ffh
        cp h
        call 0bb1eh ;; km test key
        ret z
        jp l9e52hsub_9e52h
l9ea9h:
        call 0bb1eh ;; km test key
        ret z
        ld hl,(0a41chdata_a41c)        ld de,(0a41ahdata_a41a)
        call 0bbc0h ;; gra move absolute
        ld hl,(0a410hdata_a410)        ld de,(0a412hdata_a412)        ld a,(0a41ehdata_a41e)
        call 0bbdeh ;; gra set pen
        ld (0a41chdata_a41c),hl        ld (0a41ahdata_a41a),de
        call 0bbf6h ;; gra line absolute
        ld hl,(0a410h)
        cp h
        ret nz
l9ef5h:
        pop de
        ret
sub_9eb7h:        ld hl,(0a41ahdata_a41a)        ld de,(0a412hdata_a412)l9efeh:
        and a
        sbc hl,de
        ret z
        jp p,09ecbhl9ecbh 
        ld hl,l9f15h
        jp 09ecehl09eceh l9ecbh:        ld hl,09ed2hsub_9ed2hl9f0ehl9eceh:
        ld (l9e52h+1),hl
        ret
sub_9ed2h:
        call sub_9e98h
l9f15h:
        ld de,0ffech
        ld hl,00000h
        call 0bbc3h ;; gra move relative
        ld bc,(0a420hdata_a420)l9f22h:
        push bc
        ld de,00000h
        ld a,0ffh
        cp h
        jp nz,l9efehsub_9efehsub_9ef5h:        ld hl,(0a422hdata_a422)        ld (0a410hdata_a410),hl        jp l9d9ahsub_9d9ah sub_9efeh:        ld (0a422hdata_a422),hl        ld de,(0a416hdata_a416)
        ld hl,0ffech
        call 0bbc3h ;; gra move relative
        djnz l9f22h
        ld hl,0ffffh
        ld (0a410hdata_a410),hl
        ret
 
sub_9f82h:
        call sub_9e98h
        ld bc,(0a420hdata_a420)
l9f5ch:
        push bc
        ld a,0ffh
        cp h
        jp z,l9ef5hsub_9ef5h         ld (0a422hdata_0a422),hl        ld de,(0a416hdata_a416)
        ld hl,00000h
        and a
        call 0bbc3h ;; gra move relative
        jp l9f0eh
        nop        nopdb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0        nopdb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0        nopdb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0        nopdb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0        nopdb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0        nopdb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0        nopdb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0        nop        nop;; screen dump to printer.        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nopla050hsub_0a028h:        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        ld a,013h;; INC instruction        ld (la124hla124),a
        ld a,00eh
        ld (0a0e2hla0e1+1),a        ld a,(la133hdata_a133)
        bit 1,a
        jr z,la083h
        ld a,000h ;; NOP instruction        ld (la124hla124),a
        ld a,007h
        ld (0a0e2hla0e1+1),a
la083h:
        call 0bd28h ;; mc reset printer
 
        ld de,00000h
        ld hl,00000h
        ld (0a12dhdata_a12d),desub_a050h:
        ld a,000h
        ld (0a12chdata_a12c),a;; accumulated pixels.         ld de,(0a12dhdata_a12d)        call sub_a10dh;; store current graphics position 
        call 0bbf0h ;; gra test absolute
        ld de,00001h
        call sub_a11dh;; get pixel
        ld de,00002h
        call sub_a11dh;; get pixel
        ld de,00004h
        call sub_a11dh;; get pixel
        ld de,00008h
        call sub_a11dh;; get pixel
        ld de,00010h
        call sub_a11dh;; get pixel
        ld de,00020h
        call sub_a11dh;; get pixel
        ld de,00040h
        call sub_a0ffh;; get pixel
la0c9h:
        call 0bd2eh ;; mc busy printer
        jr c,la0c9h
        call 0bd28h ;; mc reset printer
        ld a,01bh   ;; ESC
        call 0bd2bh ;; mc print char
        ld a,04bh  ;; K
        call 0bd2bh ;; mc print char
        ld a,000h  ;; number of columns low byte
        call 0bd2bh ;; mc print char
        ld a,(la133hdata_a133)
        bit 0,a
        jr z,la0f4hla0b4h        ld a,002h  ;; number of columns high byte?
        call 0bd2bh ;; mc print char
         ld a,(0a12chdata_a12c);; pixel data
        call 0bd2bh ;; mc print char
        jr la0f9h
la0f4hla0b4h:        ld a,001h  ;; number of columns high byte?
        call 0bd2bh ;; mc print char
la0f9h:
        ld a,(0a12chdata_a12c);; pixel data
        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,00ahsub_a115h:  ;; next line        call 0bd2bh;; mc print char         ld a,02fh ;; 47 - space
        call 0bb1eh ;; km test key
sub_a11dh:
        ret nz
        ld hl,(0a12dhdata_a12d)la0e1:
        ld de,0000eh
la124h:
        add hl,de
        ld (0a12dhdata_a12d),hl
        ld hl,00000h
        call sub_a10dh
        ld de,(0a12dhdata_a12d)
        ld a,d
la133h:
        cp 002h
        jp nz,la050hsub_a050h
        ld a,e
        cp 084h
        jp nz,la050hsub_a050h
        ret
 
;; accumulate pixels
sub_a0ffh:
        ld b,a
 
        call 0bb99h ;; txt get paper
        cp b       ;; was the colour read the same as the paper?
        ret z
         ;; any pixel which is not the same as the paper will be considered foreground        ;; and the printer will draw a dot. Any pixel the same as the paper will        ;; be considered background and no dot is drawn by the printer.         ;; pixel is set to foreground. accumulate it into the pixel data so far        ld hl,(0a12chdata_a12c)
        add hl,de
        ld (0a12chdata_a12c),hl
        ret
 sub_a10dh:        ld (0a12fhdata_a12f),hl        ld (0a131hdata_a131),de
        ret
 sub_a115h:        ld hl,(0a12fhdata_a12f)        ld de,(0a131hdata_a131)
        ret
 sub_a11dh:        call sub_a0ffh;; accumulate a pixel for printing.        call sub_a115h;; get current X/Y graphics position        inc de         ;; increment X to next pixel accross screen.la124:
        inc de
        inc de        call sub_a10dh;; set current X/Y graphics position
        call 0bbf0h ;; gra test absolute
        ret
        nopdata_a12c:        add a,hdb 00hdata_a12d:        ld (bc)db 84h,a02h        nopdata_a12f:        nop        ld cdb 00h,000h00h        nopdata_a131:        nopdw 000eh        nopdata_a133:         nopdb 00h        nopdata_a134:        nopdb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nop        nopla18bhsub_a154h:        nop        nop        nop        nop        nop        nop        nop        nop        nop
        call 0bc11h ;; scr get mode
        cp 000h
        ld a,b
la1aah:
        ld (0a254hdata_a254),a
        call 0bbc6h ;; gra ask cursor
        ld (la250hdata_a250),hl        ld (la250hdata_a250+2),de
la1b7h:
        call 0bb99h ;; txt get paper
        ld (la1f9hpen_cmp+1),a
        ld bc,00000h
        ld (0a24chdata_a24c),bc        ld (0a24ehdata_a24e),bc        call 0a210hsub_a210la18bh:        ld a,02fh ;; 47 - space
        call 0bb1eh ;; km test key
        ret nz
        ld hl,(0a24ehdata_a24e)
        inc hl
        inc hl
        ld hl,00000h
la1deh:
        ld (0a24ehdata_a24e),hl
        ld bc,05398h
        add hl,bc
        ld (la1aahbuffer_addr3+2),hl;; +2 to skip ED,53buffer_addr3:
        ld de,(055e0h)
        ld hl,(0a24ehdata_a24e)
sub_a1efh:
        ld bc,057e4h
        add hl,bc
        ld (la1b7hbuffer_addr4+1),hl;; +1 to skip 22buffer_addr4:
        ld hl,(05a2ch)
la1f9h:        ld (la257hdata_a257),hl        ld (0a255hdata_a255),de
        ld bc,00000h
        ld a,(0a254hdata_a254)
        ld c,a
        ex de,hl
        dec hl
        call sub_a1efh
        ld hl,(0a24ehdata_a24e)        ld de,(0a24chdata_a24c)
        inc hl
        inc hl
        ret z
        jp la18bh
 
sub_a1efh:
        push de
        push hl
        pop bc
        pop hl
la237h:
        pop de
pen_cmp:
        cp 000h
        jr nz,la248h
        ld (la250hdata_a250),hl        ld (la250h+2data_a252),de
        push bc
        call 0a210hsub_0a210h
        pop bc
la248h:
        ld hl,(la257hdata_a257)        ld de,(0a255hdata_a255)
        ret
la250hsub_a210:        ld hl,(la250hdata_a250)        ld de,(la250h+2data_a252)la257h:
        call 0bbeah ;; gra plot absolute
        ld hl,(0a24chdata_a24c)
        inc hl
        inc hl
        ld hl,00000h
la267h:
        ld (0a24chdata_a24c),hl
        ld bc,05398h
        add hl,bc
        ld de,(la250h+2data_a252)        ld (la237hbuffer_addr1+2),hl;; +2 to skip ED, 53buffer_addr1:
        ld (05648h),de
        ld hl,(0a24chdata_a24c)
        ld bc,057e4h
        add hl,bc
        ld de,(la250hdata_a250)        ld (la248hbuffer_addr+12),hl;; +2 to skip ED, 53buffer_addr2:
        ld (05a94h),de
        ret
        or b
        ld (bc),a
        ld c,b
        ld (bc),a
        cp (hl)
        nop
        jr nz,la295h
        inc b
la295h:
        jr nz,$+3
        cp h
;;Data areadata_a24c:        defw 02b0hdata_a24e:        defw 0248hdata_a250:        defw 0behdata_a252:        defw 0120hdata_a254:        defb 04hdata_a255:        defw 0120hdata_a257:        defw 0bch  ;; detected light pen positiondata_a410:        defw 0data_a412:        defw 0;; memory/buffer addressdata_a414:        defw 0data_a416:        defw 0data_a418:        defw 0 ;; gra x,y positiondata_a41a:        defw 0data_a41c:         defw 0;; graphics pendata_a41e:        defb 0        defb 0data_a420:        defw 0        end</pre>
[[Category:Source code]]