]> git.sur5r.net Git - cc65/blobdiff - libsrc/c128/c128-reu.s
poor man's _toascii routine, contributed by Fatih Aygun
[cc65] / libsrc / c128 / c128-reu.s
index a812fa85deaf0fac1e036ec5c8e42201c06f8b56..4f86f6aee387228dfc2581f80b98e99514d147a3 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
@@ -54,11 +55,10 @@ 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
@@ -78,39 +78,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