Difference between revisions of "Light pen driver"

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search
Line 41: Line 41:
 
         add hl,de
 
         add hl,de
 
l9cbd:
 
l9cbd:
         ld (0a410h),hl
+
         ld (0a410h),hl ;; detected 'position'
 
         pop bc
 
         pop bc
 
         ld a,082h
 
         ld a,082h
Line 97: Line 97:
  
 
sub_9cc1h:
 
sub_9cc1h:
         call sub_9c40h
+
         call sub_9c40h ;; detect
 
         ld a,0ffh
 
         ld a,0ffh
 
         cp h
 
         cp h
 
         ret z
 
         ret z
 +
 +
        ;; detected.
 
         ld de,00002h
 
         ld de,00002h
 
         call sub_9c94h
 
         call sub_9c94h
Line 120: Line 122:
 
         ld a,001h
 
         ld a,001h
 
         call 0bbdeh ;; gra set pen
 
         call 0bbdeh ;; gra set pen
         call sub_9cc1h
+
         call sub_9cc1h ;; get position
 
         ld a,0ffh
 
         ld a,0ffh
 
         cp h
 
         cp h
Line 144: Line 146:
 
         push bc
 
         push bc
 
         call sub_9d35h
 
         call sub_9d35h
         call sub_9c40h
+
         call sub_9c40h ;;detect
 
         pop bc
 
         pop bc
 
         ld a,0ffh
 
         ld a,0ffh
Line 172: Line 174:
 
         ld a,000h
 
         ld a,000h
 
         call 0bbdeh ;; gra set pen
 
         call 0bbdeh ;; gra set pen
         call 09d35h
+
         call sub_09d35h
 
         ld a,001h
 
         ld a,001h
 
         call 0bbdeh ;; gra set pen
 
         call 0bbdeh ;; gra set pen
Line 181: Line 183:
 
l9db4h:
 
l9db4h:
 
         push bc
 
         push bc
         call sub_9cc1h
+
         call sub_9cc1h ;; get position
 
         ld a,0ffh
 
         ld a,0ffh
 
         cp h
 
         cp h
Line 222: Line 224:
 
         ret
 
         ret
  
 +
sub_9dbeh:
 
         push hl
 
         push hl
 
         push de
 
         push de
Line 248: Line 251:
 
         pop hl
 
         pop hl
 
         ret
 
         ret
 +
 +
sub_9de6h:
 
         push hl
 
         push hl
 
         push de
 
         push de
Line 272: Line 277:
 
         pop hl
 
         pop hl
 
         ret
 
         ret
 +
 +
sub_9e08h:
 
         push de
 
         push de
 
         ld de,00002h
 
         ld de,00002h
Line 278: Line 285:
 
         push hl
 
         push hl
 
         ex de,hl
 
         ex de,hl
l9e52h:
 
 
         ld de,(0a416h)
 
         ld de,(0a416h)
 
         call sub_9c94h
 
         call sub_9c94h
Line 286: Line 292:
 
         ret
 
         ret
  
 +
sub_9e1fh:
 
         call 09c8ah
 
         call 09c8ah
 
         ld hl,(0a418h)
 
         ld hl,(0a418h)
Line 308: Line 315:
 
         ex de,hl
 
         ex de,hl
 
         pop hl
 
         pop hl
         call 09dbeh
+
         call sub_09dbeh
 
         call 0bbc0h ;; gra move absolute
 
         call 0bbc0h ;; gra move absolute
         call 09ed2h
+
         call sub_09ed2h
         call sub_9de6h
+
         call sub_09de6h
sub_9e98h:
+
 
         ld hl,(0a410h)
 
         ld hl,(0a410h)
 
         ld a,0ffh
 
         ld a,0ffh
Line 321: Line 327:
 
         ret z
 
         ret z
 
         jp l9e52h
 
         jp l9e52h
 +
 
l9ea9h:
 
l9ea9h:
         call 09eb7h
+
         call sub_09eb7h
 
         ld a,02fh
 
         ld a,02fh
 
         call 0bb1eh ;; km test key
 
         call 0bb1eh ;; km test key
Line 338: Line 345:
 
         ld hl,(0a410h)
 
         ld hl,(0a410h)
 
         jr l9e7ah
 
         jr l9e7ah
 +
 +
sub_09e98h:
 
         ld de,0ffech
 
         ld de,0ffech
 
         ld hl,00000h
 
         ld hl,00000h
Line 343: Line 352:
 
         ld a,001h
 
         ld a,001h
 
         call 0bbdeh ;; gra set pen
 
         call 0bbdeh ;; gra set pen
         call 09d35h
+
         call sub_09d35h
 
         ld a,000h
 
         ld a,000h
 
         call 0bbdeh ;; gra set pen
 
         call 0bbdeh ;; gra set pen
         call sub_9cc1h
+
         call sub_9cc1h ;; get position
 
         ld a,0ffh
 
         ld a,0ffh
 
         cp h
 
         cp h
Line 353: Line 362:
 
         pop de
 
         pop de
 
         ret
 
         ret
 +
 +
 
         ld hl,(0a41ah)
 
         ld hl,(0a41ah)
 
         ld de,(0a412h)
 
         ld de,(0a412h)
Line 366: Line 377:
 
         ld (l9e52h+1),hl
 
         ld (l9e52h+1),hl
 
         ret
 
         ret
 +
 +
 
         call sub_9e98h
 
         call sub_9e98h
 
l9f15h:
 
l9f15h:

Revision as of 12:37, 12 July 2025

        org 09c40h

sub_9c40h:
        call 0bd19h ;; mc wait flyback
        di
        ld bc,0f40eh
        out (c),c
        ld b,0f6h
        in a,(c)
        and 030h
        ld c,a
        or 0c0h
        out (c),a
        out (c),a
        inc b
        ld a,092h
        out (c),a
        push bc
        ld bc,0f649h ;; select keyboard line 9 (joystick)
        out (c),c
        out (c),c
        ld b,0f4h

;; loop reading joystick until input seen or timeout

        ld hl,0fa66h ;; timeout.
l9c68:
        in a,(c)
        cp 0fdh  ;; 11111101. Bits are '1' if 'no press', but '0' if pressed. checking joy 0 down.
        jr z,l9c79
        inc l
        jr nz,l9c68
        inc h
        jr nz,l9c68

        ld hl,0ffffh
        jr l9cbdh
l9c79:
        ld de,00420h
        add hl,de
l9cbd:
        ld (0a410h),hl ;; detected 'position'
        pop bc
        ld a,082h
        out (c),a
        dec b
        out (c),c
        ei
        ret

sub_9c8ah:
        call sub_9da6h ;; screen to buffer

        call sub_9ce4h

        call sub_9db2h ;; buffer to screen
        ret

sub_9c94:
        ld a,h
        ld c,l
        ld b,010h
        ld hl,00000h
l9cdbh:
        rl c
        rla
        adc hl,hl
        sbc hl,de
        jr nc,l9ce5h
        add hl,de
l9ce5h:
        ccf
        djnz l9cdbh
        rl c
        rla
        ld h,a
        ld l,c
        ret

sub_9caeh:
        ld a,l
        ld c,h
        ld b,010h
        ld hl,00000h
l9cf5h:
        srl c
        rra
        jr nc,l9cfbh
        add hl,de
l9cfbh:
        ex de,hl
        add hl,hl
        ex de,hl
        djnz l9cf5h
        ret

sub_9cc1h:
        call sub_9c40h ;; detect
        ld a,0ffh
        cp h
        ret z

        ;; detected.
        ld de,00002h
        call sub_9c94h
        ld de,00064h
        call sub_9caeh
        ld de,00084h
        call sub_9c94h
        ex de,hl
        ld hl,0018fh
        sbc hl,de
        ld (0a410h),hl
        ret

sub_9ce4:
        ld a,000h
        ld bc,01a1ah
        call 0bc32h ;; scr set ink
        call 0bc14h ;; scr clear
        ld a,001h
        call 0bbdeh ;; gra set pen
        call sub_9cc1h ;; get position
        ld a,0ffh
        cp h
        ret z
        ld de,0000ah
        and a
        sbc hl,de
        jr nc,$+3
        ld hl,00000h
        ld de,00000h
        call 0bbc0h ;; gra move absolute
        ld a,001h
        ld bc,01a1ah
        call 0bc32h ;; scr set ink
        ld a,000h
        ld bc,00000h
        call 0bc32h ;; scr set ink
        ld b,00ah
        call 0bd19h ;; mc wait flyback
        djnz $-4
        ld b,020h
l9d65h:
        push bc
        call sub_9d35h
        call sub_9c40h ;;detect
        pop bc
        ld a,0ffh
        cp h
        jr nz,l9d91h
        djnz l9d65h
        ret

sub_9d35h:
        ld bc,(0a418h)
l9d79h:
        push bc
        ld de,00000h
        ld hl,00014h
        call 0bbf9h ;; gra line relative
        ld de,(0a416h)
        ld hl,0ffech
        call 0bbc3h ;; gra move relative
        pop bc
        djnz l9d79h
        ret
l9d91h:
        ld de,0ffech
        ld hl,00000h
        call 0bbc3h  ;; gra move relative
l9d9ah:
        ld a,000h
        call 0bbdeh ;; gra set pen
        call sub_09d35h
        ld a,001h
        call 0bbdeh ;; gra set pen
        ld de,0ffech
        ld hl,00000h
        call 0bbc3h ;; gra move relative
        ld bc,(0a420h)
l9db4h:
        push bc
        call sub_9cc1h ;; get position
        ld a,0ffh
        cp h
        jr nz,l9ddah
        ld de,00000h
        ld hl,00014h
        call 0bbf9h ;; gra line relative
        ld de,(0a416h)
        ld hl,0ffech
        call 0bbc3h ;; gra move relative
        pop bc
        djnz l9db4h
        ld hl,0ffffh
        ld (0a410h),hl
        ret
l9ddah:
        pop bc
        ld (0a410h),hl
        call 0bbc6h ;; gra ask cursor
        ld (0a412h),de
        ret

;; screen to buffer
;; c000->5bfe length 3fd0
sub_9da6h:
        ld bc,03fd0h
        ld hl,0c000h
        ld de,05bfeh
        ldir
        ret

;; buffer to screen
;; 5bfe->c000 length 3fd0

sub_9db2h:
        ld bc,03fd0h
        ld hl,05bfeh
        ld de,0c000h
        ldir
        ret

sub_9dbeh:
        push hl
        push de
        call 09e08h
        ld (0a414h),hl
        ld de,05398h
        ld b,004h
l9e0bh:
        push bc
        ld hl,(0a414h)
        ld c,b
        ld b,000h
        inc hl
        and a
        sbc hl,bc
        ld b,00bh
l9e18h:
        ld a,(hl)
        ld (de),a
        inc de
        call 0bc29h ;; scr prev line
        djnz l9e18h
        pop bc
        djnz l9e0bh
        pop de
        pop hl
        ret

sub_9de6h:
        push hl
        push de
        ld de,05398h
        ld b,004h
l9e2dh:
        push bc
        ld hl,(0a414h)
        ld c,b
        ld b,000h
        inc hl
        and a
        sbc hl,bc
        ld b,00bh
l9e3ah:
        ld a,(de)
        ld (hl),a
        inc de
        call 0bc29h ;; scr prev line
        djnz l9e3ah
        pop bc
        djnz l9e2dh
        pop de
        pop hl
        ret

sub_9e08h:
        push de
        ld de,00002h
        call sub_9c94h
        pop de
        push hl
        ex de,hl
        ld de,(0a416h)
        call sub_9c94h
        ex de,hl
        pop hl
        call 0bc1dh ;; scr dot position
        ret

sub_9e1fh:
        call 09c8ah
        ld hl,(0a418h)
        ld (0a420h),hl
        ld hl,(0a410h)
        ld a,0ffh
        cp h
        ret z
        ld (0a41ch),hl
        ld de,(0a412h)
        ld (0a41ah),de
l9e7ah:
        ld de,0000ah
        and a
        sbc hl,de
        jr nc,l9e85h
        ld hl,00000h
l9e85h:
        push hl
        ld hl,(0a412h)
        add hl,de
        ex de,hl
        pop hl
        call sub_09dbeh
        call 0bbc0h ;; gra move absolute
        call sub_09ed2h
        call sub_09de6h
        ld hl,(0a410h)
        ld a,0ffh
        cp h
        jr nz,l9ea9h
        ld a,02fh
        call 0bb1eh ;; km test key
        ret z
        jp l9e52h

l9ea9h:
        call sub_09eb7h
        ld a,02fh
        call 0bb1eh ;; km test key
        ret z
        ld hl,(0a41ch)
        ld de,(0a41ah)
        call 0bbc0h ;; gra move absolute
        ld hl,(0a410h)
        ld de,(0a412h)
        ld a,(0a41eh)
        call 0bbdeh ;; gra set pen
        ld (0a41ch),hl
        ld (0a41ah),de
        call 0bbf6h ;; gra line absolute
        ld hl,(0a410h)
        jr l9e7ah

sub_09e98h:
        ld de,0ffech
        ld hl,00000h
        call 0bbc3h ;; gra move relative
        ld a,001h
        call 0bbdeh ;; gra set pen
        call sub_09d35h
        ld a,000h
        call 0bbdeh ;; gra set pen
        call sub_9cc1h ;; get position
        ld a,0ffh
        cp h
        ret nz
l9ef5h:
        pop de
        ret


        ld hl,(0a41ah)
        ld de,(0a412h)
l9efeh:
        and a
        sbc hl,de
        ret z
        jp p,09ecbh
        ld hl,l9f15h
        jp 09eceh
        ld hl,09ed2h
l9f0eh:
        ld (l9e52h+1),hl
        ret


        call sub_9e98h
l9f15h:
        ld de,0ffech
        ld hl,00000h
        call 0bbc3h ;; gra move relative
        ld bc,(0a420h)
l9f22h:
        push bc
        ld de,00000h
        ld hl,00014h
        call 0bbf9h ;; gra line relative
        call sub_9cc1h
        ld a,0ffh
        cp h
        jp nz,l9efeh
        ld hl,(0a422h)
        ld (0a410h),hl
        jp l9d9ah
        ld (0a422h),hl
        ld de,(0a416h)
        ld hl,0ffech
        call 0bbc3h ;; gra move relative
        pop bc
        djnz l9f22h
        ld hl,0ffffh
        ld (0a410h),hl
        ret
        call sub_9e98h
        ld bc,(0a420h)
l9f5ch:
        push bc
        ld de,00000h
        ld hl,00014h
        call 0bbf9h ;; gra line relative
        call sub_9cc1h
        ld a,0ffh
        cp h
        jp z,l9ef5h
        ld (0a422h),hl
        ld de,(0a416h)
        ld hl,00000h
        and a
        sbc hl,de
        push hl
        pop de
        ld hl,0ffech
        call 0bbc3h ;; gra move relative
        pop bc
        djnz l9f5ch
        ld hl,00000h
        ld de,00014h
        call 0bbc3h ;; gra move relative
        jp l9f0eh
        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
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
la050h:
        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
        ld (la124h),a
        ld a,00eh
        ld (0a0e2h),a
        ld a,(la133h)
        bit 1,a
        jr z,la083h
        ld a,000h
        ld (la124h),a
        ld a,007h
        ld (0a0e2h),a
la083h:
        call 0bd28h ;; mc reset printer
        ld de,00000h
        ld hl,00000h
        ld (0a12dh),de
        ld a,000h
        ld (0a12ch),a
        ld de,(0a12dh)
        call sub_a10dh
        call 0bbf0h ;; gra test absolute
        ld de,00001h
        call sub_a11dh
        ld de,00002h
        call sub_a11dh
        ld de,00004h
        call sub_a11dh
        ld de,00008h
        call sub_a11dh
        ld de,00010h
        call sub_a11dh
        ld de,00020h
        call sub_a11dh
        ld de,00040h
        call sub_a0ffh
la0c9h:
        call 0bd2eh ;; mc busy printer
        jr c,la0c9h
        call 0bd28h ;; mc reset printer
        ld a,01bh
        call 0bd2bh ;; mc print char
        ld a,04bh
        call 0bd2bh ;; mc print char
        ld a,000h
        call 0bd2bh ;; mc print char
        ld a,(la133h)
        bit 0,a
        jr z,la0f4h
        ld a,002h
        call 0bd2bh ;; mc print char
        ld a,(0a12ch)
        call 0bd2bh ;; mc print char
        jr la0f9h
la0f4h:
        ld a,001h
        call 0bd2bh ;; mc print char
la0f9h:
        ld a,(0a12ch)
        call 0bd2bh ;; mc print char
sub_a0ffh:
        call sub_a115h
        inc hl
        inc hl
        call sub_a10dh
        ld a,h
        cp 001h
        jp nz,la050h
sub_a10dh:
        ld a,l
        cp 090h
        jp nz,la050h
        ld a,00ah
sub_a115h:
        call 0bd2bh
        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 hl,00000h
        call sub_a10dh
        ld de,(0a12dh)
        ld a,d
la133h:
        cp 002h
        jp nz,la050h
        ld a,e
        cp 084h
        jp nz,la050h
        ret
        ld b,a
        call 0bb99h ;; txt get paper
        cp b
        ret z
        ld hl,(0a12ch)
        add hl,de
        ld (0a12ch),hl
        ret
        ld (0a12fh),hl
        ld (0a131h),de
        ret
        ld hl,(0a12fh)
        ld de,(0a131h)
        ret
        call sub_a0ffh
        call sub_a115h
        inc de
        inc de
        call sub_a10dh
        call 0bbf0h ;; gra test absolute
        ret
        nop
        add a,h
        ld (bc),a
        nop
        nop
        ld c,000h
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
la18bh:
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        call 0bc11h ;; scr get mode
        cp 000h
        jr nz,la19dh
        ld b,004h
la19dh:
        cp 001h
        jr nz,la1a3h
        ld b,002h
la1a3h:
        cp 002h
        jr nz,la1a9h
        ld b,001h
la1a9h:
        ld a,b
la1aah:
        ld (0a254h),a
        call 0bbc6h ;; gra ask cursor
        ld (la250h),hl
        ld (la250h+2),de
la1b7h:
        call 0bb99h ;; txt get paper
        ld (la1f9h),a
        ld bc,00000h
        ld (0a24ch),bc
        ld (0a24eh),bc
        call 0a210h
        ld a,02fh
        call 0bb1eh ;; km test key
        ret nz
        ld hl,(0a24eh)
        inc hl
        inc hl
        ld a,004h
        cp h
        jr nz,la1deh
        ld hl,00000h
la1deh:
        ld (0a24eh),hl
        ld bc,05398h
        add hl,bc
        ld (la1aah),hl
        ld de,(055e0h)
        ld hl,(0a24eh)
sub_a1efh:
        ld bc,057e4h
        add hl,bc
        ld (la1b7h),hl
        ld hl,(05a2ch)
la1f9h:
        ld (la257h),hl
        ld (0a255h),de
        ld bc,00000h
        ld a,(0a254h)
        ld c,a
        ex de,hl
        add hl,bc
        ex de,hl
        call sub_a1efh
        and a
        ex de,hl
        sbc hl,bc
        ex de,hl
        call sub_a1efh
        inc hl
        inc hl
        call sub_a1efh
        dec hl
        dec hl
        call sub_a1efh
        ld hl,(0a24eh)
        ld de,(0a24ch)
        inc hl
        inc hl
        and a
        sbc hl,de
        ret z
        jp la18bh
        push de
        push hl
        push bc
        call 0bbf0h ;; gra test absolute
        pop bc
        pop hl
la237h:
        pop de
        cp 000h
        jr nz,la248h
        ld (la250h),hl
        ld (la250h+2),de
        push bc
        call 0a210h
        pop bc
la248h:
        ld hl,(la257h)
        ld de,(0a255h)
        ret
la250h:
        ld hl,(la250h)
        ld de,(la250h+2)
la257h:
        call 0bbeah ;; gra plot absolute
        ld hl,(0a24ch)
        inc hl
        inc hl
        ld a,004h
        cp h
        jr nz,la267h
        ld hl,00000h
la267h:
        ld (0a24ch),hl
        ld bc,05398h
        add hl,bc
        ld de,(la250h+2)
        ld (la237h),hl
        ld (05648h),de
        ld hl,(0a24ch)
        ld bc,057e4h
        add hl,bc
        ld de,(la250h)
        ld (la248h+1),hl
        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

        end