Thread: Code issues
View Single Post
Old 22 March 2013, 13:12   #51
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,767
Code:
begin:

    movem.l     d0-d7/a0-a6,-(sp)               ; Backup the system registers
    jsr         closesys
;   jsr         mysys
;   jsr         restoresys

libfail:
    movem.l     (sp)+,d0-d7/a0-a6
    moveq.l     #0,d0                           ; No returncode to AmigaDOS
    rts

; First we backup the system and then take control

closesys:
    move.l      execbase,a6                     ; Address of execbase into a6
    lea         gfxlibraryname,a1               ; address of the gfx lib into a1
    moveq.l     #0,d0                           ; version of the library
    jsr         openlibrary(a6)                 ; Open the library, address is returned in d0
    move.l      d0,gfxbase                      ; store the address of the library
    move.l      d0,a6                           ; Graphics library base address into a6
    beq         libfail
Two things here:

1. When calling something like openlibrary, you have to compare the return value with 0. The system functions are not guaranteed to do that, so use a tst.l d0 before branching.

2. Look at how closesys is called, and then look at how the routine jumps back when openlibrary fails.
Thorham is offline  
 
Page generated in 0.04416 seconds with 11 queries