]> git.sur5r.net Git - cc65/commitdiff
Added size checking routine contributed by Marco van den Heuvel.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 1 Feb 2010 07:07:24 +0000 (07:07 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 1 Feb 2010 07:07:24 +0000 (07:07 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@4565 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/c64/c64-georam.s

index 0e33b8d94bddac61cabc669a57fb53b59a2707ee..30a2882a06eaec1a377758f996136130f7075afc 100644 (file)
@@ -3,6 +3,9 @@
 ; problems when statically linked.
 ;
 ; Ullrich von Bassewitz, 2002-11-29
+;
+; GEORAM page size checking routine by
+; Marco van den Heuvel, 2010-01-21
 ;
 
        .include        "zeropage.inc"
@@ -47,7 +50,7 @@ GR_PAGE_HI      = $DFFF                 ; Page register high
 
 .data
 
-pagecount:      .word   2048            ; Currently fixed
+pagecount:      .res    2               ; Number of available pages
 
 .code
 
@@ -59,9 +62,89 @@ pagecount:      .word   2048            ; Currently fixed
 ;
 
 INSTALL:
-        lda     #<EM_ERR_OK
-        ldx     #>EM_ERR_OK
-;       rts                     ; Run into UNINSTALL instead
+       tya
+       pha
+               ldx     GR_WINDOW
+        cpx     GR_WINDOW
+        bne     @notpresent
+        inc     GR_WINDOW
+               cpx     GR_WINDOW
+               beq     @notpresent
+
+               lda     #4
+               jsr     check
+               cpy     GR_WINDOW
+               beq     @has64k
+               lda     #8
+               jsr     check
+               cpy     GR_WINDOW
+               beq     @has128k
+               lda     #16
+               jsr     check
+               cpy     GR_WINDOW
+               beq     @has256k
+               lda     #32
+               jsr     check
+               cpy     GR_WINDOW
+               beq     @has512k
+               lda     #64
+               jsr     check
+               cpy     GR_WINDOW
+               beq     @has1024k
+               lda     #128
+               jsr     check
+               cpy     GR_WINDOW
+               beq     @has2048k
+               ldx     #>16384
+        bne     @setok
+
+@has64k:
+               ldx     #>256
+               bne     @setok
+@has128k:
+               ldx     #>512
+               bne     @setok
+@has256k:
+               ldx     #>1024
+               bne     @setok
+@has512k:
+               ldx     #>2048
+               bne     @setok
+@has1024k:
+               ldx     #>4096
+               bne     @setok
+@has2048k:
+               ldx     #>8192
+               bne     @setok
+
+@notpresent:
+       pla
+       tay
+               lda     #<EM_ERR_NO_DEVICE
+               ldx     #>EM_ERR_NO_DEVICE
+       rts
+
+@setok:
+               lda     #0
+               sta     pagecount
+               stx     pagecount+1
+       pla
+       tay
+               lda     #<EM_ERR_OK
+               ldx     #>EM_ERR_OK
+       rts
+
+check:
+               ldx     #0
+               stx     GR_PAGE_LO
+               stx     GR_PAGE_HI
+               ldy     GR_WINDOW
+               iny
+               sta     GR_PAGE_HI
+               sty     GR_WINDOW
+               ldx     #0
+               stx     GR_PAGE_HI
+;      rts                     ; Run into UNINSTALL instead
 
 ; ------------------------------------------------------------------------
 ; UNINSTALL routine. Is called before the driver is removed from memory.
@@ -86,7 +169,7 @@ PAGECOUNT:
 ; The GeoRAM cartridge does not copy but actually map the window, so USE is
 ; identical to MAP.
 
-USE     = MAP            
+USE     = MAP
 
 ; ------------------------------------------------------------------------
 ; MAP: Map the page in a/x into memory and return a pointer to the page in