]> git.sur5r.net Git - cc65/blobdiff - libsrc/cbm610/cbm610-ram.s
no TGI_ERR_NO_MEM or TGI_ERR_NO_IOCB anymore: replaced by TGI_ERR_NO_RES
[cc65] / libsrc / cbm610 / cbm610-ram.s
index 79a496df3150d6e645a371f904c7179f2d34890d..ccdcb4290505f2aa172591ccd5c2ea486da0a4d0 100644 (file)
@@ -1,7 +1,8 @@
 ;
-; Extended memory driver for the CBM610 additional RAM banks
+; Extended memory driver for the CBM610 additional RAM banks. Driver works
+; without problems when linked statically.
 ;
-; Ullrich von Bassewitz, 2002-12-09        !!! UNTESTED !!!
+; Ullrich von Bassewitz, 2002-12-09, 2003-12-20
 ;
 
        .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
@@ -43,10 +44,9 @@ OFFS    = 2
 ; ------------------------------------------------------------------------
 ; Data.
 
-.data
-curpage:        .byte  $FF             ; Current page number (invalid)
-
 .bss
+curpage:        .res    1               ; Current page number
+
 window:         .res    256             ; Memory "window"
 pagecount:     .res    1               ; Number of available pages
 
@@ -62,24 +62,30 @@ pagecount:  .res    1               ; Number of available pages
 
 INSTALL:
                lda     #$FF
+        sta     curpage                 ; Invalidate the current page
+        sta     pagecount               ; Assume all memory available
 
-       ldx     UsrMemTop+2
-       cpx     #RAMBANK                ; Top of memory in bank 2?
+        sec
+        jsr     $FF99                   ; MEMTOP
+
+               cmp     #RAMBANK                ; Top of memory in bank 2?
         bne     @L1                     ; No: We can use all the memory
-        clc
-        adc     UsrMemTop+1
-@L1:    sta     pagecount
+        txa
+        sub     #OFFS
+        tya
+        sbc     #$00
+        sta     pagecount
 
-        lda     #<EM_ERR_OK
+@L1:    lda     #<EM_ERR_OK
         ldx     #>EM_ERR_OK
-        rts
+;       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
 
 
@@ -111,12 +117,11 @@ MAP:    sta     curpage                   ; Remember the new page
         sta     IndReg
 
         ldy     #$00
-@L1:    lda     (ptr1),y
-        sta     window,y
-        iny
+@L1:    .repeat 2
         lda     (ptr1),y
         sta     window,y
         iny
+        .endrepeat
         bne     @L1
 
         stx     IndReg
@@ -153,12 +158,11 @@ COMMIT: lda     curpage                   ; Get the current page
         sta     IndReg
 
         ldy     #$00
-@L1:    lda     window,y
-        sta     (ptr1),y
-        iny
+@L1:    .repeat 2
         lda     window,y
         sta     (ptr1),y
         iny
+        .endrepeat
         bne     @L1
 
         stx     IndReg
@@ -262,27 +266,27 @@ COPYTO: jsr     setup
 setup:  sta     ptr3
         stx     ptr3+1                  ; Save the passed em_copy pointer
 
-        ldy     #EM_COPY_OFFS
+        ldy     #EM_COPY::OFFS
         lda     (ptr3),y
         add     #OFFS
         sta     ptr1
-        ldy     #EM_COPY_PAGE
+        ldy     #EM_COPY::PAGE
         lda     (ptr3),y
         adc     #$00
         sta     ptr1+1
 
-        ldy     #EM_COPY_COUNT
+        ldy     #EM_COPY::COUNT
         lda     (ptr3),y
         sta     ptr2
         iny
         lda     (ptr3),y
         sta     ptr2+1                  ; Get count into ptr2
 
-        ldy     #EM_COPY_BUF+1
-        lda     (ptr1),y
+        ldy     #EM_COPY::BUF+1
+        lda     (ptr3),y
         tax
         dey
-        lda     (ptr1),y                ; Get the buffer pointer into a/x
+        lda     (ptr3),y                ; Get the buffer pointer into a/x
 
         ldy     #RAMBANK
         sty     IndReg