]> git.sur5r.net Git - cc65/commitdiff
Improved reu size detection.
authorMarco van den Heuvel <blackystardust68@yahoo.com>
Mon, 5 Mar 2018 23:01:55 +0000 (15:01 -0800)
committerMarco van den Heuvel <blackystardust68@yahoo.com>
Mon, 5 Mar 2018 23:01:55 +0000 (15:01 -0800)
libsrc/c128/emd/c128-reu.s
libsrc/c64/emd/c64-reu.s

index a858c591eefba3ce35c7438c9e11e30fb956df38..3b191c66637f7dc2df2182b06ace93f34ca08f2c 100644 (file)
@@ -92,17 +92,56 @@ INSTALL:
         cmp     REU_REUADDR             ; Check for presence of REU
         bne     nodevice
 
-        ldy     #>(128*4)               ; Assume 128KB
-        lda     REU_STATUS
-        and     #$10                    ; Check size bit
-        beq     @L1
-        ldy     #>(256*4)               ; 256KB when size bit is set
-@L1:    sty     pagecount+1
-
+; determine the size
+        php
+        sei
         ldy     #$FF
-        sty     curpage
-        sty     curpage+1               ; Invalidate the current page
-        txa                             ; X = A = EM_ERR_OK
+loop:
+        sty     window
+        jsr     reu_size_check_common
+        ldx     #%10110000
+        stx     REU_COMMAND
+        dey
+        cpy     #$FF
+        bne     loop
+        iny
+size_loop:
+        jsr     reu_size_check_common
+        ldx     #%10110001
+        stx     REU_COMMAND
+        cpy     window
+        bne     size_found
+        iny
+        bne     size_loop
+size_found:
+        plp
+        ldx     #$00
+        cpy     #$00                    ; too many pages, shave off 2
+        bne     pagecount_ok
+        dex
+        dex
+        dey
+pagecount_ok:
+        stx     pagecount
+        sty     pagecount+1
+        lda     #<EM_ERR_OK
+        ldx     #>EM_ERR_OK
+        rts
+
+; common REU setup for size check
+reu_size_check_common:
+        sty     REU_REUADDR+2
+        ldx     #<window
+        stx     REU_C64ADDR
+        ldx     #>window
+        stx     REU_C64ADDR+1
+        ldx     #$00
+        stx     REU_REUADDR
+        stx     REU_REUADDR+1
+        stx     REU_COUNT+1
+        stx     REU_CONTROL
+        inx
+        stx     REU_COUNT
         rts
 
 ; No REU found
index 0779505be9be5cdbde0348f89c25244f7d4b2bdc..5bbed2f3a48fcc71bd0dea7142aebfcf5d1c8348 100644 (file)
@@ -92,19 +92,59 @@ INSTALL:
         cmp     REU_REUADDR             ; Check for presence of REU
         bne     nodevice
 
-        ldy     #>(128*4)               ; Assume 128KB
-        lda     REU_STATUS
-        and     #$10                    ; Check size bit
-        beq     @L1
-        ldy     #>(256*4)               ; 256KB when size bit is set
-@L1:    sty     pagecount+1
-
+; determine the size
+        php
+        sei
         ldy     #$FF
-        sty     curpage
-        sty     curpage+1               ; Invalidate the current page
-        txa                             ; X = A = EM_ERR_OK
+loop:
+        sty     window
+        jsr     reu_size_check_common
+        ldx     #%10110000
+        stx     REU_COMMAND
+        dey
+        cpy     #$FF
+        bne     loop
+        iny
+size_loop:
+        jsr     reu_size_check_common
+        ldx     #%10110001
+        stx     REU_COMMAND
+        cpy     window
+        bne     size_found
+        iny
+        bne     size_loop
+size_found:
+        plp
+        ldx     #$00
+        cpy     #$00                    ; too many pages, shave off 2
+        bne     pagecount_ok
+        dex
+        dex
+        dey
+pagecount_ok:
+        stx     pagecount
+        sty     pagecount+1
+        lda     #<EM_ERR_OK
+        ldx     #>EM_ERR_OK
         rts
 
+; common REU setup for size check
+reu_size_check_common:
+        sty     REU_REUADDR+2
+        ldx     #<window
+        stx     REU_C64ADDR
+        ldx     #>window
+        stx     REU_C64ADDR+1
+        ldx     #$00
+        stx     REU_REUADDR
+        stx     REU_REUADDR+1
+        stx     REU_COUNT+1
+        stx     REU_CONTROL
+        inx
+        stx     REU_COUNT
+        rts
+
+
 ; No REU found
 
 nodevice: