From: Christian Groessler Date: Mon, 24 Jun 2013 23:27:47 +0000 (+0200) Subject: use first free IOCB for "GRAPHICS 0" call instead of using a hard-coded one X-Git-Tag: V2.15~223^2~79 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a03b3574b65a6167ac1207e66b83888eb0ca8465;p=cc65 use first free IOCB for "GRAPHICS 0" call instead of using a hard-coded one --- diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index 9e3026625..b9c20cc72 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -20,6 +20,7 @@ .import sram_init .if .defined(__ATARIXL__) .import scrdev + .import findfreeiocb .endif .include "zeropage.inc" @@ -181,11 +182,9 @@ _exit: jsr donelib ; Run module destructors sta APPMHI+1 - ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) - - ldx #$50 ; take any IOCB, hopefully free (@@@ fixme) + jsr findfreeiocb ; Reopen it in Graphics 0 lda #OPEN @@ -203,8 +202,10 @@ _exit: jsr donelib ; Run module destructors lda #0 sta ICBLH,x jsr CIOV_org - - +; add error checking here... + lda #CLOSE + sta ICCOM,x + jsr CIOV_org .endif diff --git a/libsrc/atari/shadow_ram_prepare.s b/libsrc/atari/shadow_ram_prepare.s index 5f1e90437..f8a7dbbf6 100644 --- a/libsrc/atari/shadow_ram_prepare.s +++ b/libsrc/atari/shadow_ram_prepare.s @@ -122,7 +122,17 @@ sramprep: ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) - ldx #$50 ; take any IOCB, hopefully free (@@@ fixme) + jsr findfreeiocb +.ifdef DEBUG ; only check in debug version, this shouldn't happen normally(tm) + beq iocbok + print_string "Internal error, no free IOCB!" + jsr delay + jsr delay + jsr delay + jsr restore ; restore stuff we've changed + jmp (DOSVEC) ; abort loading +iocbok: +.endif ; Reopen it in Graphics 0 lda #OPEN @@ -140,20 +150,18 @@ sramprep: lda #>screen_device_length sta ICBLH,x jsr CIOV_org - bpl okoko + bpl scrok +; shouldn't happen(tm) print_string "Internal error, aborting..." jsr delay jsr delay jsr delay - + jsr restore ; restore stuff we've changed jmp (DOSVEC) ; abort loading -okoko: - - - ; Now close it again; we don't need it anymore :) +scrok: ; now close it again -- we don't need it anymore lda #CLOSE sta ICCOM,x jsr CIOV_org @@ -266,6 +274,7 @@ no_copy: .endif rts +.include "findfreeiocb.inc" ; my 6502 fu is rusty, so I took a routine from the internet (http://www.obelisk.demon.co.uk/6502/algorithms.html) @@ -298,6 +307,21 @@ done: rts .endproc +; clean up after a fatal error + +restore:lda RAMTOP_save + sta RAMTOP + lda MEMTOP_save + sta MEMTOP + lda MEMTOP_save+1 + sta MEMTOP+1 + lda APPMHI_save + sta APPMHI + lda APPMHI_save+1 + sta APPMHI+1 + rts + + .byte "HERE ****************** HERE ***************>>>>>>" sramsize: