;* Hardware-Offsets
CUSTOM:         EQU $00dff000
COPJMP1:        EQU $00000088
COP1LCH:        EQU $00000080

;* Notwendigste Offsets fuer Amiga-Exec

ALLOCMEM:       EQU -198
FREEMEM:        EQU -210
OPENLIBRARY:    EQU -552
CLOSELIBRARY:   EQU -414
GETMSG:         EQU -372
REPLYMSG:       EQU -378
FINDTASK:       EQU -294
WAITPORT:       EQU -384

;* Offsets fuer dos.library
OPEN:           EQU -30
CLOSE:          EQU -36
READ:           EQU -42
WRITE:          EQU -48
LOCK:           EQU -84
UNLOCK:         EQU -90
EXAMINE:        EQU -102
EXNEXT:         EQU -108
INFO:           EQU -114
CURRENTDIR:     EQU -126
IOERR:          EQU -132
PARENTDIR:      EQU -210

;* Offsets fuer Graphics.Library
OWNBLITTER:     EQU -456
DISOWNBLITTER:  EQU -462
INITGELS:       EQU -120
ADDBOB:         EQU -96
DOCOLLISION:    EQU -108
DRAWGLIST:      EQU -114
SORTGLIST:      EQU -150
LOADRGB4:       EQU -192
SETCOLLISION:   EQU -144
REMIBOB:        EQU -132

;* Offsets fuer Intuition.library
OPENSCREEN:     EQU -198                ; S.ARGS -> a0
CLOSESCREEN:    EQU -66                 ; ScreenInfo -> a0


START:
        bsr             OPENLIBS              ; Oeffne Libraries
	bsr 		INITTASK	      ; WBMessage or CLI
        bsr             OLDDISPLAY            ; Altes Display holen
        bsr             MAKESCREEN            ; Eroeffne Schirm (Intuition)

        lea             TESTPAL(pc),a0        ; FileName der Palette -> a0
        bsr             GETPALETTE            ; Setze Palette

        lea             TESTFILE(pc),a0       ; FileName -> a0
        moveq           #1,d0                 ; ID = 1
        bsr             GETOBJECT             ; Hole Object

        bsr             WAITONCLICK           ; Wait on Mouse

        moveq           #1,d0                 ; Setze ID
        bsr             REMARKBOB             ; Entferne Bob

        bsr             REMGELS               ; RemarkGels
        bsr             REMSCREEN             ; Schliee Screen!
        bsr             CLOSELIBS             ; Schliesse Libraries

	bra		EXITTASK	      ; Raus hier !
	
INITTASK:
	sub.l		a1,a1		      ; a1 = 0
	move.l	        4,a6		      ; ExecBase -> a6
	jsr		FINDTASK(a6)          ; Finde eigenen Task      
	
        move.l	        d0,a4		      ; TaskStruct -> a4
	tst.l		$ac(a4)		      ; CLI oder Workbench
	bne		SETNOCD		      ; CLI -> SetNoCD
	lea		$5c(a4),a0	      ; Zeiger auf Port -> a0
	jsr 	        WAITPORT(a6)	      ; Warte auf Signal !
	lea		$5c(a4),a0	      ; Zeiger auf MSGStruct 
	jsr	        GETMSG(a6)            ; Hole Message ab !
	move.l	        d0,MESSAGE	      ; Rette Message !
	move.l	        d0,a0                 ; Message -> a0
	tst.l	        28(a0)		      ; Test WorkbenchMSG
	beq     	SETNOCD               ; Keine Daten -> SetNoCd
	move.l	        36(a0),a0	      ; Hole Zeiger auf Daten
	move.l          (a0),d1		      ; Lock -> d1
	move.l          DOSBASE(pc),a6        ; DosBase -> a6
	jsr	        CURRENTDIR(a6)	      ; Setze CurrentDir
SETNOCD:	 
	 rts				      ; Back to Call !


EXITTASK:
	move.l	MESSAGE(pc),d1		      ; Message -> d1
	beq.s	EXITBACK		      ; Keine da -> ExitBack
	move.l	d1,a1			      ; Message -> a1
	move.l  4,a6			      ; ExecBase -> a6
	jsr	REPLYMSG(a6)		      ; Beantworte Message
EXITBACK:
	rts				      ; Back !!!

WAITONCLICK:
        lea             MYMOVE(pc),a0         ; MyMovePort -> a0
        move.w          MX(a0),d0             ; Hole X-Koordinate
        move.w          MY(a0),d1             ; Hole Y-Koordinate

        cmp.w           #254,d0               ; Test rechten Rand
        ble.s           NORIGHT               ;
        neg.w           MOVERX(a0)
NORIGHT:
        cmp.w           #0,d0                 ; Test linken Rand
        bge.s           NOLEFT                ;
        neg.w           MOVERX(a0)
NOLEFT:
        cmp.w           #190,d1               ; Test unteren Rand
        ble.s           NOBOTTOM              ;
        neg.w           MOVERY(a0)
NOBOTTOM:
        cmp.w           #12,d1                ; Test oberen Rand
        bge.s           NOTOP
        neg.w           MOVERY(a0)
NOTOP:

        add.w           MOVERX(a0),d0         ; Move X
        add.w           MOVERY(a0),d1         ; Move Y

        move.w          d0,MX(a0)             ; Koordinaten ablegen X
        move.w          d1,MY(a0)             ; Koordinaten ablegen Y

        moveq           #1,d2                 ; ID -> d2
        bsr             MOVEBOB               ; -> MoveBob

        bsr             DRAWBOB               ; Zeichne BOB's

        btst            #10,$00dff016
        bne.s           WAITONCLICK
        rts


* Routine zeichnet BOB's
*
DRAWBOB:
        movea.l         GFXBASE(pc),a6        ; GFXBase -> a6
        movea.l         MYRASTPORT(pc),a1     ; RastPortPtr -> a1
        jsr             SORTGLIST(a6)         ; Sortiere GELS

        movea.l         MYVIEWPORT(pc),a0     ; ViewPortPtr -> a0
        movea.l         MYRASTPORT(pc),a1     ; RastPortPtr -> a1
        jsr             DRAWGLIST(a6)         ; Draw It !

        rts                                   ; Back to Call

* Routine bewegt Bob
* Parameter:
*       d0 = X-Koordinate
*       d1 = Y-Koordinate
*       d2 = ObjectID
MOVEBOB:
        bsr             SEARCHID              ; Suche ID

        move.w          d0,VS_X(a0)           ; Setze X-Koordinate
        move.w          d1,VS_Y(a0)           ; Setze Y-Koordinate
        rts                                   ; Back to Call !

* Routine enfernt Bob aus GELS-Liste und gibt belegten Speicher frei
* Input:
*       d0 = ID
REMARKBOB:
        move.w          d0,d2                 ; ID -> d2
        bsr             SEARCHID              ; Suche passende VSpriteStr.
        move.l          a0,-(a7)              ; Rette VSprite auf Stack

        movea.l         VS_VSBOB(a0),a0       ; BOB -> a0
        movea.l         MYRASTPORT(pc),a1     ; RastPortPtr -> a1
        movea.l         MYVIEWPORT(pc),a2     ; ViewPortPtr -> a2

        movea.l         GFXBASE(pc),a6        ; GFXBASE -> a6

        jsr             REMIBOB(a6)           ; Entferne BOB aus Liste

        movea.l         (a7)+,a0              ; VSprite vom Stack holen
        movea.l         VS_SUSEREXT(a0),a2    ; Zeiger auf eigene Infos -> a2

        move.l          a2,-(a7)              ; Rette Zeiger auf Stack
        movea.l         4,a6                  ; ExecBase -> a6
        movea.l         MAINMEM(a2),a1        ; Hole Pointer to ObjectMem -> a1
        move.l          MAINMEML(a2),d0       ; Laenge -> d0
        jsr             FREEMEM(a6)           ; Free It !

        movea.l         (a7),a2               ; Hole Pointer vom Stack
        movea.l         BSTRADR(a2),a1        ; Pointer -> a1
        move.l          #BOB_SIZEOF,d0        ; Laenge des Bereichs -> d0
        jsr             FREEMEM(a6)           ; Free It !

        movea.l         (a7),a2               ; Hole Pointer vom Stack
        movea.l         VSTRADR(a2),a1        ; Pointer -> a1
        move.l          #VS_SIZEOF,d0         ; Laenge des Bereichs -> d0
        jsr             FREEMEM(a6)           ; Free It !

        movea.l         (a7),a2               ; Hole Pointer vom Stack
        movea.l         BACKMEMADR(a2),a1     ; Pointer -> a1
        move.l          BACKMEML(a2),d0       ; Laenge des Bereichs -> d0
        jsr             FREEMEM(a6)           ; Free It !

        movea.l         (a7),a2               ; Hole Pointer vom Stack
        movea.l         BORDERMEMADR(a2),a1   ; Pointer -> a1
        move.l          BORDERLENGTH(a2),d0   ; Laenge des Bereichs -> d0
        jsr             FREEMEM(a6)           ; Free It !

        movea.l         (a7)+,a1              ; Hole Pointer vom Stack
        move.l          #MS_SIZEOF,d0         ; Laenge der eigenen Infos -> d0
        jsr             FREEMEM(a6)           ; Free It !
        rts

* Routine sucht nach ID und gibt Zeiger auf VSprite zurck
* Parameter:
*       d2   = ID
* Rueckgabe:
*       a0   = Zeiger auf VSprite
SEARCHID:
        movea.l         MYRASTPORT(pc),a0     ; RastPortPtr -> a0
        movea.l         RP_GELSINFO(a0),a0    ; Hole GelsInfo -> a0
        movea.l         GI_GELHEAD(a0),a0     ; Hole HeadVSprite

IDLOOP:
        movea.l         VS_SUSEREXT(a0),a1    ; UserExtension -> a1
        cmp.w           MYID(a1),d2           ; Test ID
        beq.s           IDFOUND               ; Gefunden -> IDFound
        movea.l         VS_NEXTVSPRITE(a0),a0 ; Hole Naechste VSprite
        bra.s           IDLOOP                ; -> Loop
IDFOUND:
        rts


* Routine liest Palette ein und setzt Farben im ViewPort
GETPALETTE:
        bsr             POWERLOAD             ; Lade Palette

        movea.l         GFXBASE(pc),a6        ; GFXBase -> a6
        movea.l         MEMPTR(pc),a1         ; DatenPtr -> a1
        move.l          MEMSIZE(pc),d0        ; Size -> d0
        lsr.l           #1,d0                 ; / 2 da Words
        movea.l         MYVIEWPORT(pc),a0     ; ViewPortPtr -> a0

        jsr             LOADRGB4(a6)          ; Setze FarbTabelle

        movea.l         4,a6                  ; ExecBase -> a6

        movea.l         MEMPTR(pc),a1         ; Pointer -> a1
        move.l          MEMSIZE(pc),d0        ; Groesse des Bereichs -> d0
        jsr             FREEMEM(a6)           ; Free It !

        rts                                   ; Back to Call !

* Routine liest Object ein und haengt es in GelsInfo ein
* Parameter:
*       a0 = Zeiger auf Filename
*       d0 = ID ( Nummer: WORD )
GETOBJECT:
        lea             IDBUFFER(pc),a1       ; ID Buffer -> a1
        move.w          d0,(a1)               ; ID retten
        bsr             POWERLOAD             ; Load a Object
        bsr             INITOBJECT            ; Initialisiere BOB
        rts                                   ; Back to Call !

* Routine installiert GelsInfo im Rastport und traegt Bob ein
* Input:
* Output:
*
GENERATEGELS:
        move.l          #GI_SIZEOF,d0         ; Groesse der Struktur -> d0
        bsr             GETMEM                ; Hole Speicher
        lea             GELSBASE(pc),a0       ; GelsBasePtr -> a0
        move.l          d0,(a0)               ; Rette Pointer to Gels

        move.l          #VS_SIZEOF,d0         ; Groesse der VS-Struktur -> d0
        bsr             GETMEM                ; Hole Speicher
        lea             HEADPTR(pc),a0        ; HeadPtr -> a0
        move.l          d0,(a0)               ; Rette Pointer HeadVs

        move.l          #VS_SIZEOF,d0         ; Groesse der VS-Struktur -> d0
        bsr             GETMEM                ; Hole Speicher
        lea             TAILPTR(pc),a0        ; TailPtr -> a0
        move.l          d0,(a0)               ; Rette Pointer TailVs

        movea.l         GELSBASE(pc),a2       ; GelsInfoPtr -> a2
        movea.l         HEADPTR(pc),a0        ; HeadPtr -> a0
        movea.l         TAILPTR(pc),a1        ; TailPtr -> a1
        lea             NEXTLINES(pc),a3      ; NextLinesBuffer -> a3
        lea             LASTCOLORS(pc),a4     ; LastColorsBuffer -> a4
        lea             MYCOLLTABLE(pc),a5    ; CollTableBuffer -> a5

        move.l          a3,GI_NEXTLINE(a2)    ; NextLineBuffer -> GelsInfo
        move.l          a4,GI_LASTCOLOR(a2)   ; LastColorBuffer -> GelsInfo
        move.l          a5,GI_COLLHANDLER     ; CollBuffer -> GelsInfo

        movea.l         GFXBASE(pc),a6        ; GFXBase -> a6
        jsr             INITGELS(a6)          ; Initilisiere GelsInfo

        movea.l         MYRASTPORT(pc),a0     ; RastPortPtr -> a0
        move.l          GELSBASE(pc),RP_GELSINFO(a0) ; GelsInfo -> RastPort

        rts

* Routine entfernt GelsInfo und gibt Speicher zurck
REMGELS:
        movea.l         4,a6                  ; ExecBase -> a6

        movea.l         MYRASTPORT(pc),a0     ; RastPortPtr -> a0
        movea.l         RP_GELSINFO(a0),a0    ; Get GelsInfoPtr -> a0

        move.l          a0,-(a7)              ; Lege GelsInfoPtr auf Stack

        movea.l         GI_GELHEAD(a0),a1     ; Hole HeadVSpritePtr
        move.l          #VS_SIZEOF,d0         ; Laenge des Berechs -> d0

        jsr             FREEMEM(a6)           ; Free It!

        movea.l         (a7),a0               ; Hole Pointer vom Stack
        movea.l         GI_GELTAIL(a0),a1     ; Hole TailVSpritePtr
        move.l          #VS_SIZEOF,d0         ; Laenge des Berechs -> d0

        jsr             FREEMEM(a6)           ; Free It !

        movea.l         (a7)+,a1              ; Hole Pointer -> a1
        move.l          #GI_SIZEOF,d0         ; Groesse des Bereichs -> d0

        jsr             FREEMEM(a6)           ; Free It !

        rts

* Routine initialisiert Objekt
INITOBJECT:
        lea             ISGELSINFO(pc),a0     ; GelsInfoFlag -> a0
        tst.w           (a0)                  ; Is FALSE ?
        bne.s           GELSINFOIS            ; Nein -> GelsInfoIs
        move.w          #-1,(a0)              ; Setze Flag = TRUE
        bsr             GENERATEGELS          ; Generiere GelsInfo
GELSINFOIS:
        move.l          #VS_SIZEOF,d0         ; Groesse der VSpriteStr. -> d0
        bsr             GETMEM                ; Hole Speicher !
        lea             MYVSPRITE(pc),a0      ; VSpriteSave -> a0
        move.l          d0,(a0)               ; Rette Adresse

        move.l          #BOB_SIZEOF,d0        ; Groesse der BOBStr. -> d0
        bsr             GETMEM                ; Hole Speicher !
        lea             MYBOB(pc),a0          ; BOBSave -> a0
        move.l          d0,(a0)               ; Rette Adresse

        movea.l         MEMPTR(pc),a0         ; Pointer to Object -> a0
        movea.l         MYVSPRITE(pc),a1      ; VSpritePtr -> a1
        movea.l         MYBOB(pc),a2          ; BOBPtr -> a2

        move.l          a1,BOB_BOBVSPRITE(a2) ; Zeiger auf VSprite in BOBStru.
        move.l          a2,VS_VSBOB(a1)       ; Zeiger auf BOB in VSpriteStru.

        move.w          22(a0),VS_HEIGHT(a1)  ; Hoehe des Objekts -> VSprite
        move.w          18(a0),VS_WIDTH(a1)   ; Breite des Objekts -> VSprite
        move.w          #5,VS_DEPTH(a1)       ; Tiefe des Objektes -> VSprite

        move.w          10(a0),d0             ; Hole IMAGE-Offset
        lea             0(a0,d0.w),a3         ; Adresse des Images -> a3
        move.l          a3,VS_IMAGEDATA(a1)   ; ADR des Images -> VSprite
        lea             24(a0),a3             ; ADR der Maske -> a3
        move.l          a3,VS_COLLMASK(a1)    ; Maske -> VSprite

        move.w          #6,VS_VSFLAGS(a1)     ; Setze VS_FLAGS

        move.w          #1,VS_MEMASK(a1)      ; Setze CollMask 1
        move.w          #1,VS_HITMASK(a1)     ; Setze CollMask 2

        move.b          #$ff,VS_PLANEPICK(a1) ;
        move.b          #$ff,VS_PLANEONOFF(a1) ;

        move.w          #MYBOBFLAGS,BOB_BOBFLAGS(a2) ; Setze BOBFlags

        lea             24(a0),a3             ; ADR der Maske -> a3
        move.l          a3,BOB_IMAGESHADOW(a2) ; Maske in BOB_Structure

        bsr             GENERATEBORDER        ; Generiere BorderMaske
        bsr             GENERATESAVE          ; Generiere BackGroundSpeicher
        bsr             GENERATEMYSTUFF       ; Generiere eigene Infos

        movea.l         GFXBASE(pc),a6        ; GFXBase -> a6
        movea.l         MYRASTPORT(pc),a1     ; RastPort -> a1
        movea.l         MYBOB(pc),a0          ; BOB -> a0
        jsr             ADDBOB(a6)            ; -> ADDBOB

        rts                                   ; Back to Call !


GENERATEMYSTUFF:
        move.l          #MS_SIZEOF,d0         ; Groesse meiner Struktur -> d0
        bsr             GETMEM                ; Hole Speicher
        movea.l         d0,a0                 ; Adresse -> a0
        move.l          a0,VS_SUSEREXT(a1)    ; Pointer in Vsprite ablegen

        move.w          IDBUFFER(pc),MYID(a0) ; ID ablegen

        move.l          MEMPTR(pc),MAINMEM(a0) ; HauptSpeicher eintragen
        move.l          MEMSIZE(pc),MAINMEML(a0) ; Laenge eintragen

        move.l          MYVSPRITE(pc),VSTRADR(a0) ; ADR der VS-Struc. ablegen
        move.l          MYBOB(pc),BSTRADR(a0) ; ADR der BOB-Struc. ablegen

        move.l          MYSAVE(pc),BACKMEMADR(a0) ; ADR des BackGrounds eintr.
        move.l          MYSAVEL(pc),BACKMEML(a0) ; Laenge des BackGrounds eintr.

        move.l          MYBORDER(pc),BORDERMEMADR(a0) ; ADR des Borders eintr.
        move.l          MYBORDERL(pc),BORDERLENGTH(a0) ; Laenge des Borders eintr

        rts

GENERATESAVE:
        move.w          18(a0),d0             ; Breite in Worten -> d0
        lsl.w           #1,d0                 ; * 2 fuer Anzahl in Bytes
        mulu            22(a0),d0             ; * ObjectHoehe
        mulu            #5,d0                 ; Mal Planes
        lea             MYSAVEL(pc),a3        ; SaveLength -> a3
        move.l          d0,(a3)               ; Rette Laenge
        bsr             GETCHIPMEM            ; Hole ChipMem
        lea             MYSAVE(pc),a3         ; MySaveSave -> a3
        move.l          d0,(a3)               ; Rette Adresse des Buffers
        move.l          d0,BOB_SAVEBUFFER(a2) ; Adresse -> BOBStructure
        rts                                   ; Back to Call !

GENERATEBORDER:
        move.w          18(a0),d0             ; Breite in Worten -> d0
        lsl.w           #1,d0                 ; * 2 fuer Anzahl in Bytes
        ext.l           d0                    ; LangWortErweiterung
        lea             MYBORDERL(pc),a3      ; BorderLength -> a3
        move.l          d0,(a3)               ; Rette Laenge

        bsr             GETCHIPMEM            ; Hole ChipMem
        lea             MYBORDER(pc),a3       ; MyBorderSave -> a3
        move.l          d0,(a3)               ; Rette BorderAdresse

        movea.l         d0,a3                 ; Adresse -> a3
        move.w          18(a0),d7             ; Breite in Worten -> d7
        subq.w          #1,d7                 ; DEC LoopCounter
BORDERLOOP:
        move.w          #$ffff,(a3)+          ; Setze BorderMaske
        dbra            d7,BORDERLOOP         ; -> Loop

        move.l          MYBORDER(pc),VS_BORDERLINE(a1) ; Adresse -> VSprite
        rts

* Routine holt Dateilaenge des Objects und laedt es ins ChipMem
POWERLOAD:
        move.l          a0,-(a7)              ; FileNamePointer -> Stack

        bsr             GETLENGTH             ; Hole Laenge des Files
        tst.l           d0                    ; Test d0
        bmi             WRONG                 ; Is neg -> Wrong
        lea             MEMSIZE(pc),a0        ; Memsize -> a0
        move.l          d0,(a0)               ; Rette Size
        bsr             GETCHIPMEM            ; Hole Speicher !
        lea             MEMPTR(pc),a0         ; MemPtr -> a0
        move.l          d0,(a0)               ; Rette Base of Mem

        movea.l         (a7)+,a0              ; FileName -> a0
        bsr             OPENFILE              ; Open File
        bsr             GETFILE               ; Read File
        bsr             CLOSEFILE             ; Close File
        rts                                   ; Back to Call !

* Routine liest File
* Input:
*       Handle = ActHandle
*       Buffer = MemPtr
*       Length = MemSize
* Output:
GETFILESET:     REG d0-a6
GETFILE:
        movem.l         GETFILESET,-(a7)      ; Save Regs on Stack

        movea.l         DOSBASE(pc),a6        ; DosBase -> a6

        move.l          ACTHANDLE(pc),d1      ; Handle -> d1
        move.l          MEMPTR(pc),d2         ; Buffer -> d2
        move.l          MEMSIZE(pc),d3        ; Size -> d3

        jsr             READ(a6)              ; Read It!

        move.l          MEMSIZE(pc),d1        ; Size -> d1
        cmp.l           d0,d1                 ; Is Readed Length = Requ. Length
        bne             WRONG                 ; Nein -> Wrong

        movem.l         (a7)+,GETFILESET      ; Get Regs from Stack
        rts                                   ; Back to Call !


* Routine schliet File
* Input:
*       Handle = ActHandle
CLOSEFILESET:   REG d0-a6
CLOSEFILE:
        movem.l         CLOSEFILESET,-(a7)    ; Save Regs on Stack

        movea.l         DOSBASE(pc),a6        ; DosBase -> a6

        move.l          ACTHANDLE(pc),d1      ; Handle -> d1
        jsr             CLOSE(a6)             ; Close It!

        movem.l         (a7)+,CLOSEFILESET    ; Get Regs from Stack
        rts

* Routine oeffnet File
* Input:
*       a0 = Pointer to Filename
* Output:
*       Handle -> Acthandle
*       Handle -> d0
OPENFILESET:    REG d1-a6
OPENFILE:
        movem.l         OPENFILESET,-(a7)     ; Save Regs on Stack

        movea.l         DOSBASE(pc),a6        ; DosBase -> a6

        move.l          a0,d1                 ; Name of File -> d1
        move.l          #1005,d2              ; Mode_Old -> d2
        jsr             OPEN(a6)              ; Open It!
        tst.l           d0                    ; Test, ob erfolgreich
        beq             WRONG                 ; Nein -> Wrong

        lea             ACTHANDLE(pc),a0      ; ActHandle -> a0
        move.l          d0,(a0)               ; Lege Handle ab

        movem.l         (a7)+,OPENFILESET     ; Get Regs from Stack
        rts                                   ; Back to Call !


* Routine holt Laenge eines Files
GETLENGTH:
        movea.l         DOSBASE(pc),a6        ; DosBase -> a6

        move.l          a0,d1                 ; Pointer -> d1
        moveq           #-2,d2                ; Modu fuer Lock -> d2
        jsr             LOCK(a6)              ; Get Lock !
        tst.l           d0                    ; Test ob erfolgreich
        beq             LENGTHERROR           ; Nein -> Lengtherror
        lea             LOCKPTR(pc),a0        ; LockPtr -> a0
        move.l          d0,(a0)

        move.l          d0,d1                 ; Lock -> d1
        lea             FILEINFODATA(pc),a0   ; FileInfoDataBase -> a0
        move.l          a0,d2                 ; Base (a0) -> d2

        jsr             EXAMINE(a6)           ; Examine It !
        tst.l           d0                    ; Test, ob erfolgreich
        beq             LENGTHERROR           ; Nein -> Lengtherror

        move.l          LOCKPTR(pc),d1        ; Lock -> d1
        jsr             UNLOCK(a6)            ; UnLock It!

        lea             FILEINFODATA(pc),a0   ; FileInfoDataBase -> a0
        move.l          124(a0),d0            ; Laenge des File -> d0

        rts                                   ; Back to Call !

LENGTHERROR:
        moveq           #-1,d0                ; Set ErrorFlag !
        rts                                   ; Back to Call

* Routine allociert ChipMemory
GETCHIPMEMSET:  REG d1-a6
GETCHIPMEM:
        movem.l         GETCHIPMEMSET,-(a7)   ; Save Regs on Stack

        move.l          #$00010003,d1         ; MemType = (CHIP+CLEAR+PUBLIC)
        movea.l         4,a6                  ; Execbase -> a6
        jsr             ALLOCMEM(a6)          ; Get Memory for File !
        tst.l           d0                    ; Test ob erfolgreich
        beq             WRONG                 ; Nein -> Wrong

        movem.l         (a7)+,GETCHIPMEMSET   ; Get Reg from Stack
        rts                                   ; Back to Call !

* Routine allociert beliebigen Speicher
GETMEMSET:      REG d1-a6
GETMEM:
        movem.l         GETMEMSET,-(a7)       ; Save Regs on Stack

        move.l          #$00010001,d1         ; MemType = (CLEAR+PUBLIC)
        movea.l         4,a6                  ; Execbase -> a6
        jsr             ALLOCMEM(a6)          ; Get Memory for File !
        tst.l           d0                    ; Test ob erfolgreich
        beq             WRONG                 ; Nein -> Wrong

        movem.l         (a7)+,GETMEMSET       ; Get Reg from Stack
        rts                                   ; Back to Call !


* Routine eroeffnet Screen mittels Intuition ( Igitt !!! )
MAKESCREEN:
        movea.l         INTBASE(pc),a6        ; IntuitionBase -> a6

        lea             SCRDATA(pc),a0        ; Daten des Scr -> a0
        jsr             OPENSCREEN(a6)        ; Open It!
        tst.l           d0                    ; Is it open ?
        beq             WRONG                 ; Nein -> ErrorMsg
        lea             SCREENBASE(pc),a0     ; ScreenBasePtr -> a0
        move.l          d0,(a0)               ; Rette ScreenPtr
        lea             MYVIEWPORT(pc),a0     ; ViewPortAblage -> a0
        lea             MYRASTPORT(pc),a1     ; RastPortAblage -> a1
        add.l           #44,d0                ; Offset auf ViewPort addieren
        move.l          d0,(a0)               ; ViewPortPtr retten
        add.l           #40,d0                ; Offset auf RastPort addieren
        move.l          d0,(a1)               ; RastPortPtr retten
        rts                                   ; Back to Call!


* Routine schliet geoeffneten Screen
REMSCREEN:
        movea.l         INTBASE(pc),a6        ; IntBase -> a6

        movea.l         SCREENBASE(pc),a0     ; ScreenBase -> a0
        jsr             CLOSESCREEN(a6)       ; Close It!

        rts                                   ; Back to Call!

* Routine eroeffnet alle wichtigen Libraries
OPENLIBS:
        movea.l         4,a6                  ; ExecBase -> a6

        moveq           #0,d0                 ; No Version of Lib.
        lea             DOSNAME(pc),a1        ; Pointer to Dosname -> a1
        jsr             OPENLIBRARY(a6)       ; Open Lib !
        lea             DOSBASE(pc),a1        ; DosBasePtr -> a1
        move.l          d0,(a1)               ; Rette DosBase

        moveq           #0,d0                 ; No Version of Lib.
        lea             GFXNAME(pc),a1        ; Pointer to GFXname -> a1
        jsr             OPENLIBRARY(a6)       ; Open Lib !
        lea             GFXBASE(pc),a1        ; GFXBasePtr -> a1
        move.l          d0,(a1)               ; Rette GFXBase

        moveq           #0,d0                 ; No Version of Lib.
        lea             INTNAME(pc),a1        ; Pointer to Intname -> a1
        jsr             OPENLIBRARY(a6)       ; Open Lib !
        lea             INTBASE(pc),a1        ; IntBasePtr -> a1
        move.l          d0,(a1)               ; Rette IntBase

        rts

* Kleiner ErrorAbfang
WRONG:
        movea.l         4,a6
        lea             DOSNAME(pc),a1        ;
        moveq           #0,d0
        jsr             OPENLIBRARY(a6)
        movea.l         d0,a6
        moveq           #-1,d1                ; General Error
        jsr             (a6)
        rts

* Routine schliet geoeffnte Libraries
CLOSELIBS:

        movea.l         4,a6                  ; ExecBase -> a6

        movea.l         INTBASE(pc),a1        ; IntBase -> a1
        jsr             CLOSELIBRARY(a6)      ; Close It!

        movea.l         DOSBASE(pc),a1        ; DOSBase -> a1
        jsr             CLOSELIBRARY(a6)      ; Close It!

        movea.l         GFXBASE(pc),a1        ; GFXBase -> a1
        jsr             CLOSELIBRARY(a6)      ; Close It!

        rts                                   ; Back to Call !

* Routine stellt altes Display wieder her
OLDDISPLAY:

        movea.l         GFXBASE(pc),a3        ; Library.Base -> a3
        lea             CUSTOM,a4             ; CustomBase -> a3
        move.l          38(a3),COP1LCH(a4)    ; Set CopperPointer
        clr.w           COPJMP1(a4)           ; Strobe it
        move.w          #$8060,$00dff096      ; DMA on
        rts                                   ; Back to Call!


********************************************************************************
*                              Datenbereich                                    *
********************************************************************************
********************************************************************************
*                              Library-Namen                                   *
********************************************************************************
                EVEN
DOSNAME:        DC.B "dos.library",0
                EVEN
GFXNAME:        DC.B "graphics.library",0
                EVEN
INTNAME:        DC.B "intuition.library",0

********************************************************************************
*                              Library-Pointer                                 *
********************************************************************************
                EVEN
DOSBASE:        DC.L 0                  ; Save for DosBase
GFXBASE:        DC.L 0                  ; Save for GFXBase
INTBASE:        DC.L 0                  ; Save for IntuitionBase

********************************************************************************
*                         Daten der SpeicherListe                              *
********************************************************************************
MEMPTR:         DS.L 1                  ; Save fr MemoryBlock
MEMSIZE:        DS.L 1                  ; Save for Size of Block
********************************************************************************
*                       Daten fuer Grafik-System                               *
********************************************************************************
SCREENBASE:     DS.L 1                  ; Save fuer PTR to Screen
MYVIEWPORT:     DS.L 1                  ; Save fuer PTR to ViewPort
MYRASTPORT:     DS.L 1                  ; Save fuer PTR to RastPort
GELSBASE:       DS.L 1                  ; Reserved for GELSInfoBase
HEADPTR:        DS.L 1                  ; Save fuer PTR to HeadVspriteStructure
TAILPTR:        DS.L 1                  ; Save fuer PTR to TailVSpriteStructure
MYVSPRITE:      DS.L 1                  ; Save fuer PTR to VSpriteStructure
MYBOB:          DS.L 1                  ; Save fuer PTR to BOBStructure
MYBORDER:       DS.L 1                  ; Save fuer BorderAdr
MYBORDERL:      DS.L 1                  ; Laenge des Borders
MYSAVE:         DS.L 1                  ; Save fuer BackGroundAdress
MYSAVEL:        DS.L 1                  ; Laenge des BackGroundBuffers
IDBUFFER:       DS.W 1                  ; Save fuer ID des Objekts
********************************************************************************
*                               Flags                                          *
********************************************************************************
ISGELSINFO:     DC.W 0                  ; Flag ob Gelsinfo schon installiert
********************************************************************************
*                            Daten fuer DOS                                    *
********************************************************************************
LOCKPTR:        DS.L 1                  ; Reserved for temp. Lock
ACTHANDLE:      DS.L 1                  ; Reserved for temp. FileHandle
********************************************************************************
*                           Daten fuer Task                                    *
********************************************************************************
MESSAGE:	DS.L 1
********************************************************************************
*                              Filenamen                                       *
********************************************************************************
                EVEN
TESTFILE:       DC.B "DEMO.OBJ",0
                EVEN
TESTPAL:        DC.B "DEMO.PAL",0
********************************************************************************
*                          Daten fuer Objekt-Bewegung                          *
********************************************************************************
                EVEN
MYMOVE:
                DC.W 100,100
                DC.W 4,4
********************************************************************************
*                               ScreenDaten                                    *
********************************************************************************
                EVEN
SCRDATA:
                DC.W 0,0                ; X and Y-Position
                DC.W 320,256            ; Breite,Hoehe
                DC.W 5                  ; Bitplanes
                DC.B 0                  ; Color00
                DC.B 1                  ; Color01
                DC.W $4002              ; Modi ( Genlock + Sprites )
                DC.W 15                 ; Custom-Screen
                DC.L 0                  ; Zeichensatz normal
                DC.L SCRTITLE           ; Pointer to ScreenTitle
                DC.L 0                  ; Keine Gadgets
                DC.L 0                  ; Keine Bitmap

                EVEN
SCRTITLE:       DC.B "   ASSAGE ENTERTAINMENT SOFTWARE",0

********************************************************************************
*                             FileInfoDaten                                    *
********************************************************************************
                CNOP 0,4
FILEINFODATA:
                DS.B 260

********************************************************************************
*                             GelsInfoDaten                                    *
********************************************************************************
                EVEN
NEXTLINES:      DS.W 8                  ; LineBuffer der GelsInfo
LASTCOLORS:     DS.W 8                  ; ColorBuffer der GelsInfo
MYCOLLTABLE:    DS.L 16                 ; Adressen der CollisionsRoutinen
                EVEN
VPFIRST:        DS.B 58                 ; Erste VSprite-Structure
VPLAST:         DS.B 58                 ; Letzte VSprite-Structure

********************************************************************************
*                              Meine Offsets                                   *
********************************************************************************
                RSRESET
MYID:           RS.W 1                  ; IDNumber des BOBs
MAINMEM:        RS.L 1                  ; Zeiger auf ObjectDaten
MAINMEML:       RS.L 1                  ; Laenge der Daten
BSTRADR:        RS.L 1                  ; Zeiger auf BOBStructure
VSTRADR:        RS.L 1                  ; Zeiger auf VSpriteStructure
BACKMEMADR:     RS.L 1                  ; Zeiger auf Speicher fuer Background
BACKMEML:       RS.L 1                  ; Groesse des Speichers
BORDERMEMADR:   RS.L 1                  ; Zeiger auf BorderImage
BORDERLENGTH:   RS.L 1                  ; Laenge des BorderImages
MS_SIZEOF:      RS.W 0                  ; End und Laengen-Kennung

                RSRESET
MX:             RS.W 1                  ; Koordinate des Objects X
MY:             RS.W 1                  ; Koordinate des Objects Y
MOVERX:         RS.W 1                  ; Mover X
MOVERY:         RS.W 1                  ; Mover Y
MM_SIZEOF:      RS.W 0                  ; End und LaengenKennung

********************************************************************************
*                         Offsets fuer AmigaDOS                                *
********************************************************************************

                RSRESET
TMPRAS:         RS.B 0
TR_RASPTR:      RS.L 1
TR_SIZE:        RS.L 1
TR_SIZEOF:      RS.W 0
                RSRESET
GELSINFO:       RS.B 0
GI_SPRRSRVD:    RS.B 1
GI_FLAGS:       RS.B 1
GI_GELHEAD:     RS.L 1
GI_GELTAIL:     RS.L 1
GI_NEXTLINE:    RS.L 1
GI_LASTCOLOR:   RS.L 1
GI_COLLHANDLER: RS.L 1
GI_LEFTMOST:    RS.W 1
GI_RIGHTMOST:   RS.W 1
GI_TOPMOST:     RS.W 1
GI_BOTTOMMOST:  RS.W 1
GI_FIRSTBLISSOBJ:RS.L 1
GI_LASTBLISSOBJ:RS.L 1
GI_SIZEOF:      RS.W 0


RPB_FRST_DOT:   EQU 0
RPF_FRST_DOT:   EQU 1<<0
RPB_ONE_DOT:    EQU 1
RPF_ONE_DOT:    EQU 1<<1
RPB_DBUFFER:    EQU 2
RPF_DBUFFER:    EQU 1<<2
RPB_AREAOUTLINE:EQU 3
RPF_AREAOUTLINE:EQU 1<<3
RPB_NOCROSSFILL:EQU 5
RPF_NOCROSSFILL:EQU 1<<5
RP_JAM1:        EQU 0
RP_JAM2:        EQU 1
RP_COMPLEMENT:  EQU 2
RP_INVERSVID:   EQU 4
RPB_TXSCALE:    EQU 0
RPF_TXSCALE:    EQU 1<<0
                RSRESET
RASTPORT:       RS.B 0
RP_LAYER:       RS.L 1
RP_BITMAP:      RS.L 1
RP_AREAPTRN:    RS.L 1
RP_TMPRAS:      RS.L 1
RP_AREAINFO:    RS.L 1
RP_GELSINFO:    RS.L 1
RP_MASK:        RS.B 1
RP_FGPEN:       RS.B 1
RP_BGPEN:       RS.B 1
RP_AOLPEN:      RS.B 1
RP_DRAWMODE:    RS.B 1
RP_AREAPTSZ:    RS.B 1
RP_DUMMY:       RS.B 1
RP_LINPATCNT:   RS.B 1
RP_FLAGS:       RS.W 1
RP_LINEPTRN:    RS.W 1
RP_CP_X:        RS.W 1
RP_CP_Y:        RS.W 1
RP_MINTERMS:    RS.B 8
RP_PENWIDTH:    RS.W 1
RP_PENHEIGHT:   RS.W 1
RP_FONT:        RS.L 1
RP_ALGOSTYLE:   RS.B 1
RP_TXFLAGS:     RS.B 1
RP_TXHEIGHT:    RS.W 1
RP_TXWIDTH:     RS.W 1
RP_TXBASELINE:  RS.W 1
RP_TXSPACING:   RS.W 1
RP_RP_USER:     RS.L 1
RP_LONGRESERVED:RS.B 8

RP_WORDRESERVED:RS.B 14
RP_RESERVED:    RS.B 8
RP_SIZEOF:      RS.W 0
                RSRESET
AREAINFO:       RS.B 0
AI_VCTRTBL:     RS.L 1
AI_VCTRPTR:     RS.L 1
AI_FLAGTBL:     RS.L 1
AI_FLAGPTR:     RS.L 1
AI_COUNT:       RS.W 1
AI_MAXCOUNT:    RS.W 1
AI_FIRSTX:      RS.W 1
AI_FIRSTY:      RS.W 1
AI_SIZEOF:      RS.W 0
ONE_DOTN:       EQU 1
ONE_DOT:        EQU $00000002
FRST_DOTN:      EQU 0
FRST_DOT:       EQU 1

SUSERFLAGS:     EQU $000000ff
VSB_VSPRITE:    EQU 0
VSF_VSPRITE:    EQU 1<<0
VSB_SAVEBACK:   EQU 1
VSF_SAVEBACK:   EQU 1<<1
VSB_OVERLAY:    EQU 2
VSF_OVERLAY:    EQU 1<<2
VSB_MUSTDRAW:   EQU 3
VSF_MUSTDRAW:   EQU 1<<3
VSB_BACKSAVED:  EQU 8
VSF_BACKSAVED:  EQU 1<<8
VSB_BOBUPDATE:  EQU 9
VSF_BOBUPDATE:  EQU 1<<9
VSB_GELGONE:    EQU 10
VSF_GELGONE:    EQU 1<<10
VSB_VSOVERFLOW: EQU 11
VSF_VSOVERFLOW: EQU 1<<11
BUSERFLAGS:     EQU $000000ff
BB_SAVEBOB:     EQU 0
BF_SAVEBOB:     EQU 1<<0
BB_BOBISCOMP:   EQU 1
BF_BOBISCOMP:   EQU 1<<1
BB_BWAITING:    EQU 8
BF_BWAITING:    EQU 1<<8
BB_BDRAWN:      EQU 9
BF_BDRAWN:      EQU 1<<9
BB_BOBSAWAY:    EQU 10
BF_BOBSAWAY:    EQU 1<<10
BB_BOBNIX:      EQU 11
BF_BOBNIX:      EQU 1<<11
BB_SAVEPRESERVE:EQU 12
BF_SAVEPRESERVE:EQU 1<<12
BB_OUTSTEP:     EQU 13
BF_OUTSTEP:     EQU 1<<13
ANFRACSIZE:     EQU 6
ANIMHALF:       EQU $00000020
RINGTRIGGER:    EQU $00000001

MYBOBFLAGS:     EQU 0
MYVSPRFLAGS:    EQU VSB_SAVEBACK+VSB_OVERLAY

                RSRESET
VS:             RS.B 0
VS_NEXTVSPRITE: RS.L 1
VS_PREVVSPRITE: RS.L 1
VS_DRAWPATH:    RS.L 1
VS_CLEARPATH:   RS.L 1
VS_OLDY:        RS.W 1
VS_OLDX:        RS.W 1
VS_VSFLAGS:     RS.W 1
VS_Y:           RS.W 1
VS_X:           RS.W 1
VS_HEIGHT:      RS.W 1
VS_WIDTH:       RS.W 1
VS_DEPTH:       RS.W 1
VS_MEMASK:      RS.W 1
VS_HITMASK:     RS.W 1
VS_IMAGEDATA:   RS.L 1
VS_BORDERLINE:  RS.L 1
VS_COLLMASK:    RS.L 1
VS_SPRCOLORS:   RS.L 1
VS_VSBOB:       RS.L 1
VS_PLANEPICK:   RS.B 1
VS_PLANEONOFF:  RS.B 1
VS_SUSEREXT:    RS.L 1
VS_SIZEOF:      RS.W 0

                RSRESET
BOB:            RS.B 0
BOB_BOBFLAGS:   RS.W 1
BOB_SAVEBUFFER: RS.L 1
BOB_IMAGESHADOW:RS.L 1
BOB_BEFORE:     RS.L 1
BOB_AFTER:      RS.L 1
BOB_BOBVSPRITE: RS.L 1
BOB_BOBCOMP:    RS.L 1
BOB_DBUFFER:    RS.L 1
BOB_BUSEREXT:   RS.L 1
BOB_SIZEOF:     RS.W 0

                RSRESET
AC:             RS.B 0
AC_COMPFLAGS:   RS.W 1
AC_TIMER:       RS.W 1
AC_TIMESET:     RS.W 1
AC_NEXTCOMP:    RS.L 1
AC_PREVCOMP:    RS.L 1
AC_NEXTSEQ:     RS.L 1
AC_PREVSEQ:     RS.L 1
AC_ANIMCROUTINE:RS.L 1
AC_YTRANS:      RS.W 1
AC_XTRANS:      RS.W 1
AC_HEADOB:      RS.L 1
AC_ANIMBOB:     RS.L 1
AC_SIZE:        RS.W 0
                RSRESET
AO:             RS.B 0
AO_NEXTOB:      RS.L 1
AO_PREVOB:      RS.L 1
AO_CLOCK:       RS.L 1
AO_ANOLDY:      RS.W 1
AO_ANOLDX:      RS.W 1
AO_ANY:         RS.W 1
AO_ANX:         RS.W 1
AO_YVEL:        RS.W 1
AO_XVEL:        RS.W 1
AO_XACCEL:      RS.W 1
AO_YACCEL:      RS.W 1
AO_RINGYTRANS:  RS.W 1
AO_RINGXTRANS:  RS.W 1
AO_ANIMOROUTINE:RS.L 1
AO_HEADCOMP:    RS.L 1
AO_AUSEREXT:    RS.W 0
AO_SIZEOF:      RS.W 0
                RSRESET
DBP:            RS.B 0
DBP_BUFY:       RS.W 1
DBP_BUFX:       RS.W 1
DBP_BUFPATH:    RS.L 1
DBP_BUFBUFFER:  RS.L 1
DBP_BUFPLANES:  RS.L 1
DBP_SIZEOF:     RS.W 0
