]> git.sur5r.net Git - cc65/blobdiff - libsrc/c64/c64-reu.s
fix comments
[cc65] / libsrc / c64 / c64-reu.s
index 1ff966e58a5629d7316a4cd21c596a220a5425b0..59dbb791337f76019034c4dcedb53c782af7c682 100644 (file)
@@ -1,5 +1,6 @@
 ;
-; Extended memory driver for the Commodore REU
+; Extended memory driver for the Commodore REU. Driver works without
+; problems when statically linked.
 ;
 ; Ullrich von Bassewitz, 2002-11-29
 ;
 ; 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
         .word   COMMIT
        .word   COPYFROM
         .word   COPYTO
@@ -52,19 +54,18 @@ OP_COPYTO       = $EC
 ; ------------------------------------------------------------------------
 ; Data.
 
-.data
+.bss
 pagecount:      .res    2               ; Number of pages available
-curpage:        .word   $FFFF           ; Current page number (invalid)
+curpage:        .res    2               ; Current page number
 
-.bss
 window:         .res    256             ; Memory "window"
 
 reu_params:     .word  $0000           ; Host address, lo, hi
-               .word   $0000           ; Exp  address, lo, hi
+               .word   $0000           ; Exp  address, lo, hi
                 .byte  $00             ; Expansion  bank no.
                        .word   $0000           ; # bytes to move, lo, hi
-                       .byte   $00             ; Interrupt mask reg.
-                       .byte   $00             ; Adress control reg.
+                       .byte   $00             ; Interrupt mask reg.
+                       .byte   $00             ; Adress control reg.
 
 .code
 
@@ -76,39 +77,41 @@ reu_params:     .word       $0000           ; Host address, lo, hi
 ;
 
 INSTALL:
+        ldx     #$00                    ; High byte of return code
         lda     #$55
         sta     REU_REUADDR
         cmp     REU_REUADDR             ; Check for presence of REU
         bne     nodevice
-        lda     #$AA
+        asl     a                       ; A = $AA
         sta     REU_REUADDR
         cmp     REU_REUADDR             ; Check for presence of REU
         bne     nodevice
 
-        ldx     #>(128*4)               ; Assume 128KB
+        ldy     #>(128*4)               ; Assume 128KB
         lda     REU_STATUS
         and     #$10                    ; Check size bit
         beq     @L1
-        ldx     #>(256*4)               ; 256KB when size bit is set
-@L1:    stx     pagecount+1
+        ldy     #>(256*4)               ; 256KB when size bit is set
+@L1:    sty     pagecount+1
 
-        lda     #<EM_ERR_OK
-        ldx     #>EM_ERR_OK
+        ldy     #$FF
+        sty     curpage
+        sty     curpage+1               ; Invalidate the current page
+        txa                             ; X = A = EM_ERR_OK
         rts
 
 ; No REU found
 
 nodevice:
-        lda     #<EM_ERR_NO_DEVICE
-        ldx     #>EM_ERR_NO_DEVICE
-        rts
+        lda     #EM_ERR_NO_DEVICE
+;       rts                             ; Run into UNINSTALL instead
 
 ; ------------------------------------------------------------------------
-; 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:
         rts
 
 
@@ -123,8 +126,8 @@ PAGECOUNT:
 
 ; ------------------------------------------------------------------------
 ; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) are assumed to be
-; dirty and must be saved into secondary storage if this is necessary.
+; a/x.  The contents of the currently mapped page (if any) may be discarded
+; by the driver.
 ;
 
 MAP:    sta     curpage
@@ -137,6 +140,15 @@ MAP:    sta     curpage
         ldx     #>window                ; Return the window address
 done:   rts
 
+; ------------------------------------------------------------------------
+; USE: Tell the driver that the window is now associated with a given page.
+                                       
+USE:    sta     curpage
+        stx     curpage+1               ; Remember the page
+        lda     #<window
+        ldx     #>window                ; Return the window
+        rts
+
 ; ------------------------------------------------------------------------
 ; COMMIT: Commit changes in the memory window to extended storage.
 
@@ -153,11 +165,11 @@ common: sty     tmp1
         sty     REU_C64ADDR+1
 
         ldy     #0
-        sty     REU_COUNT+0
         sty     REU_REUADDR+0
         sta     REU_REUADDR+1
         stx     REU_REUADDR+2
 
+        sty     REU_COUNT+0
         ldy     #1
         sty     REU_COUNT+1             ; Move 256 bytes
         bne     transfer1               ; Transfer 256 bytes into REU
@@ -212,7 +224,7 @@ transfer:
 
         ldy    $01             ; Save the value of the c64 control port...
         tya                    ;
-        ora    #$03            ; Turn on lower 3 bits to bank out ROMs, I/O.
+        and     #$F8            ; Disable ROMs and I/O.
        sei                     ;
         sta    $01
         lda     REU_TRIGGER     ; Don't change $FF00