]> git.sur5r.net Git - cc65/blobdiff - libsrc/c64/c64-vdc.s
As a test, remove the SYS header from the startup code and use the one
[cc65] / libsrc / c64 / c64-vdc.s
index 3e324e5d9891883c858b6adb41051f3fa465fd1b..be1626b1eb649c18cb3674f3af374f6e1a0df409 100644 (file)
@@ -3,6 +3,10 @@
 ; (based on code by Ullrich von Bassewitz)
 ; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl>
 ; 06,20.12.2002
+;
+; VDC test added by
+; Marco van den Heuvel, 2010-01-22
+;
 
        .include        "zeropage.inc"
 
 ; Driver signature
 
         .byte   $65, $6d, $64           ; "emd"
-        .byte   $00                     ; EM API version number
+        .byte   EMD_API_VERSION                ; EM API version number
 
 ; Jump table.
 
         .word   INSTALL
-        .word   DEINSTALL
+        .word   UNINSTALL
         .word   PAGECOUNT
         .word   MAP
        .word   USE
@@ -67,46 +71,60 @@ window:             .res    256                ; memory window
 ;
 
 INSTALL:
-       ; do test for VDC presence here???
-
-       ldx     #VDC_CSET       ; determine size of RAM...
-       jsr     vdcgetreg
-       sta     tmp1
-       ora     #%00010000
-       jsr     vdcputreg       ; turn on 64k
-
-       jsr     settestadr1     ; save original value of test byte
-       jsr     vdcgetbyte
-       sta     tmp2
-
-       lda     #$55            ; write $55 here
-       ldy     #ptr1
-       jsr     test64k         ; read it here and there
-       lda     #$aa            ; write $aa here
-       ldy     #ptr2
-       jsr     test64k         ; read it here and there
-
-       jsr     settestadr1
-       lda     tmp2
-       jsr     vdcputbyte      ; restore original value of test byte
+        ldx     #0
+        ldy     #0
+               lda     #VDC_CSET       ; determine size of RAM...
+               sta     VDC_ADDR_REG
+
+@L0:    bit     VDC_ADDR_REG
+        bmi     @present
+        inx
+        bne     @L0
+        iny
+        bne     @L0
+       lda     #<EM_ERR_NO_DEVICE
+       ldx     #>EM_ERR_NO_DEVICE
+       rts
 
-       lda     ptr1            ; do bytes match?
-       cmp     ptr1+1
-       bne     @have64k
-       lda     ptr2
-       cmp     ptr2+1
-       bne     @have64k
+@present:
+       ldx     #VDC_CSET       ; determine size of RAM...
+       jsr     vdcgetreg
+       sta     tmp1
+       ora     #%00010000
+       jsr     vdcputreg       ; turn on 64k
+
+       jsr     settestadr1     ; save original value of test byte
+       jsr     vdcgetbyte
+       sta     tmp2
+
+       lda     #$55            ; write $55 here
+       ldy     #ptr1
+       jsr     test64k         ; read it here and there
+       lda     #$aa            ; write $aa here
+       ldy     #ptr2
+       jsr     test64k         ; read it here and there
+
+       jsr     settestadr1
+       lda     tmp2
+       jsr     vdcputbyte      ; restore original value of test byte
+
+       lda     ptr1            ; do bytes match?
+       cmp     ptr1+1
+       bne     @have64k
+       lda     ptr2
+       cmp     ptr2+1
+       bne     @have64k
 
        ldx     #VDC_CSET
        lda     tmp1
-       jsr     vdcputreg       ; restore 16/64k flag
-       jmp     @endok          ; and leave default values for 16k
+       jsr     vdcputreg       ; restore 16/64k flag
+       jmp     @endok          ; and leave default values for 16k
 
 @have64k:
-       lda     #<256
-       ldx     #>256
-       sta     pagecount
-       stx     pagecount+1
+       lda     #<256
+       ldx     #>256
+       sta     pagecount
+       stx     pagecount+1
 @endok:
        lda     #<EM_ERR_OK
         ldx     #>EM_ERR_OK
@@ -141,11 +159,11 @@ settestadr2:
        jmp     vdcsetsrcaddr
 
 ; ------------------------------------------------------------------------
-; DEINSTALL routine. Is called before the driver is removed from memory.
+; UNINSTALL routine. Is called before the driver is removed from memory.
 ; Can do cleanup or whatever. Must not return anything.
 ;
 
-DEINSTALL:
+UNINSTALL:
        ;on C128 restore font and clear the screen?
         rts
 
@@ -255,7 +273,7 @@ COPYFROM:
        jsr     setup
        beq     @L2                     ; Skip if no full pages
 
-; Copy full pages 
+; Copy full pages
 
 @L1:    jsr     transferin
         inc     ptr1+1
@@ -265,7 +283,7 @@ COPYFROM:
 
 ; Copy the remainder of the page
 
-@L2:    ldy     #EM_COPY_COUNT
+@L2:    ldy     #EM_COPY::COUNT
         lda     (ptr3),y                ; Get bytes in last page
         beq     @L4
         sta    tmp1
@@ -273,11 +291,7 @@ COPYFROM:
 ; Transfer the bytes in the last page
 
        ldy     #0
-       ldx     #VDC_DATA
-       stx     VDC_ADDR_REG
-@L3:   bit     VDC_ADDR_REG
-       bpl     @L3
-       lda     VDC_DATA_REG
+@L3:   jsr     vdcgetbyte
        sta     (ptr2),y
        iny
        dec     tmp1
@@ -295,7 +309,7 @@ COPYTO:
        jsr     setup
        beq     @L2                     ; Skip if no full pages
 
-; Copy full pages 
+; Copy full pages
 
 @L1:    jsr     transferout
         inc     ptr1+1
@@ -305,7 +319,7 @@ COPYTO:
 
 ; Copy the remainder of the page
 
-@L2:    ldy     #EM_COPY_COUNT
+@L2:    ldy     #EM_COPY::COUNT
         lda     (ptr3),y                ; Get bytes in last page
         beq     @L4
         sta    tmp1
@@ -313,12 +327,8 @@ COPYTO:
 ; Transfer the bytes in the last page
 
        ldy     #0
-       ldx     #VDC_DATA
-       stx     VDC_ADDR_REG
-@L3:   bit     VDC_ADDR_REG
-       bpl     @L3
-       lda     (ptr2),y
-       sta     VDC_DATA_REG
+@L3:   lda     (ptr2),y
+       jsr     vdcputbyte
        iny
        dec     tmp1
        lda     tmp1
@@ -368,21 +378,21 @@ setup:
        sta     ptr3
         stx     ptr3+1                  ; Save the passed em_copy pointer
 
-        ldy     #EM_COPY_OFFS
+        ldy     #EM_COPY::OFFS
         lda     (ptr3),y
         sta     ptr1
-        ldy     #EM_COPY_PAGE
+        ldy     #EM_COPY::PAGE
         lda     (ptr3),y
         sta     ptr1+1                  ; From
 
-        ldy     #EM_COPY_BUF
+        ldy     #EM_COPY::BUF
         lda     (ptr3),y
         sta     ptr2
         iny
         lda     (ptr3),y
         sta     ptr2+1                  ; To
 
-       ldy     #EM_COPY_COUNT+1
+       ldy     #EM_COPY::COUNT+1
         lda     (ptr3),y                ; Get number of pages
         sta     tmp1
        rts