DMACON  =$96
COLOR1  =$182
COP1LC  =$80
COPJMP1 =$88
BPLCON0 =$100
BPLCON1 =$102
BPLCON2 =$104
BPL1PTH =$0E0
BPL1PTL =$0E2
BPL1MOD =$108
BPL2MOD =$10A
DIWSTRT =$08E
DIWSTOP =$090
DDFSTRT =$092
DDFSTOP =$094
CIAAPRA =$BFE001

OpenLibrary=-30-522  ;Exec Library Base Offsets
Exit=-30-114
Forbid=-30-102
Permit=-30-108
AllocMem=-30-168
FreeMem=-30-180
LVOOpen=-30
LVORead=-42
LVOClose=-36
StartList=38 ;Graphics Base
ExecBase=4
CLsize=5000  ;Groesse der Copperliste
Background=$0233 ;Hintergrund-Farbe
Planesize=8000



; *******************************************************************
; *******************************************************************
; *******************************************************************



main: move.l #dosname,a1  ;DOS-LIB oeffnen
moveq #0,d0
move.l ExecBase,a6
jsr OpenLibrary(a6)
move.l d0,DosBase

move.l #Planesize,d0 ;Speicher fuer Bitplanes
move.l #$10002,d1
move.l ExecBase,a6
jsr AllocMem(a6)
move.l d0,Planeadr
beq fini

move.l #CLsize,d0  ;Speicher fuer Copperliste
move.l #$10002,d1
jsr AllocMem(a6)
move.l d0,CLadr
beq free1

move.l DosBase,a6 ;Bitplanes laden
move.l #pic_name,d1
move.l #1005,d2
jsr LVOOpen(a6)
move.l d0,filehandle
tst.l d0
beq free0
move.l filehandle,d1
move.l Planeadr,d2
move.l #Planesize,d3
jsr LVORead(a6)
move.l filehandle,d1
jsr LVOClose(a6)


move.l CLadr,a0  ;CopperListe initialisiert BPLxPT
move.l Planeadr,d1 ;
move.w #BPL1PTH,d3  ;1.Adr-Register der Bitplanes
move.w d3,(a0)+  ;BPLxPTH
addq.w #2,d3  ;naechstes Register
swap d1 ;
move.w d1,(a0)+ ;MOVE High,BPLxPTH
move.w d3,(a0)+ ;
addq.w #2,d3 ;
swap d1 ;
move.w d1,(a0)+ ;MOVE LOW,BPLxPTL

move.l #63,d6 ;Farbe Color1 bis 63
move.w #COLOR1,(a0)+
move.w #Background,(a0)+

cop:  move.l   d6,d0
   move.l   #28,d1
   jsr   waitc

   move.w   #COLOR1,(a0)+
   move.w   #$f00,(a0)+

   move.l   d6,d0
   move.l   #290,d1
   jsr   waitc

   move.w   #COLOR1,(a0)+
   move.w   d6,(a0)+

   move.l   d6,d0
   move.l   #320,d1
   jsr   waitc

   move.w   #COLOR1,(a0)+
   move.w   #$f00,(a0)+

   add.l #1,d6
   cmp.l #255,d6
   blt   cop

   move.l   #255,d0        ;End-Warten
   move.l   #28,d1
   jsr   waitc

   move.w   #COLOR1,(a0)+     ;End-Farbe
   move.w  #0,(a0)+

   move.l   #$fffffffe,(a0)+  ;endc



   move.l   ExecBase,a6
   jsr   Forbid(a6)     ;DMA und Taskswitching sperren
   move.l   #$dff000,a5
   move.w   #$03e0,DMACON(a5) ;DMA ausschalten
   move.l   CLadr,COP1LC(a5)  ;CopperListe installieren
   clr.w COPJMP1(a5)    ;Copper einschalten

   move.w   #$2981,DIWSTRT(a5)   ;Playfield
   move.w   #$f1c1,DIWSTOP(a5)   ;mit Standardwerten
   move.w   #$0038,DDFSTRT(a5)   ;des 320*256 Screens
   move.w   #$00d0,DDFSTOP(a5)   ;installieren.
   move.w   #%0001001000000000,BPLCON0(a5)   ;1 BitPlane

   clr.w BPLCON1(a5)    ;kein scrolling
   clr.w BPLCON2(a5)
   clr.w BPL1MOD(a5)    ;Modulo = 0
   clr.w BPL2MOD(a5)
   move.w   #$8380,DMACON(a5) ;DMA einschalten
   move.w   #Background,$df0180



   clr.l d1
Zeile16:move.l $dff004,d2     ;auf Rasterzeile 16 warten
   and.l #$0001ff00,d2
   cmp.l #$00001000,d2
   bne.s Zeile16

   move.b   d1,d2
   move.l   #190,d6
   move.l   CLadr,a4
   add.l #12,a4
   lea   sinus,a3    ;Adr der Sinustabelle

change:  move.b   31(a4),7(a4)      ;Farben des Nachfolgers
   move.b   47(a4),23(a4)     ;uebernehmen
   move.b   15(a4),d5
   move.b   d2,15(a4)
   move.b   d5,d2

   move.b   #168,d5
   sub.b d1,d5
   move.b   sinuscount,d0
   add.b d6,d0
   and.w #$3f,d0
   move.b   0(a3,d0.w),d0
   add.b d0,d5
   ori.b #$1,d5
   move.b   d5,9(a4)    ;linke Schranke
   add.b #64,d5
   move.b   d5,17(a4)      ;rechte Schranke

   add.l #24,a4
   dbra  d6,change      ;jede Zeile


   cmp.b #100,d1
   bne   h1
   move.b   #-1,d3         ;Richtung nach links
h1: cmp.b #0,d1
   bne   h2
   move.b   #1,d3       ;Richtung nach rechts

h2: move.b  d1,d0
   lsl.b #1,d0
   move.b   d0,7(a4)
   not.b d0
   move.b   d0,23(a4)
   add.b d3,d1
   add.b #1,sinuscount     ;Tabelle um 1 verschieben

   btst  #6,CIAAPRA     ;linke Maustaste ???
   bne   Zeile16


               ;PRG verlassen
   move.l   ExecBase,a6
   move.l   #$dff000,a5
   move.l   #GRname,a1
   clr.l d0
   jsr   OpenLibrary(a6)
   move.l   d0,a3
   move.l   StartList(a3),COP1LC(a5);alte Copperliste installieren
   clr.w COPJMP1(a5)
   move.w   #$83e0,DMACON(a5)
   move.l   ExecBase,a6
   jsr   Permit(a6)
        rts
free0: move.l  ExecBase,a6    ;Speicher freigeben
   move.l   CLadr,a1
   move.l   #CLsize,d0
   jsr   FreeMem(a6)
free1: move.l  ExecBase,a6
   move.l   Planeadr,a1
   move.l   #Planesize,d0
   jsr   FreeMem(a6)
   move.l   DosBase,a6
   jsr   Exit(a6)
fini: rts

waitc: lsr  #1,d1
   ori   #1,d1
   asl   #8,d0
   or.l  d1,d0
   move.w   d0,(a0)+
   move.w   #$fffe,d1
   move.w   d1,(a0)+
   rts



      blk   0,2
GRname:     dc.b  "graphics.library",0
      blk   0,2
dosname:    dc.b  'dos.library',0
      blk   0,2
pic_name: dc.b 'kickstart.plane',0
      blk   0,2
even
DosBase:    dc.l  0
Planeadr: dc.l 0
CLadr:   dc.l  0
filehandle:     dc.l 0
sinuscount: dc.b  0
sinus:   dc.b  0,1,2,4,5,6,7,8,9,9,10,11,11,12,12,12,12,12,12
   dc.b  11,11,10,10,9,8,7,6,5,4,3,2,1,-1,-2,-3,-4,-5,-6
   dc.b  -7,-8,-9,-10,-10,-11,-11,-12,-12,-12,-12,-12,-12
   dc.b  -11,-11,-10,-9,-9,-8,-7,-6,-5,-4,-2,-1

