home *** CD-ROM | disk | FTP | other *** search
/ Amiga GigaPD 3 / Amiga_GigaPD_v3_3of3.iso / amiga-magazin / ungepackt / mai_94 / disk2 / voxelspace / quelltext / voxelspa.s next >
Text File  |  1993-06-25  |  22KB  |  1,082 lines

  1. ; Voxelspace Source
  2. ; 1994 Magna Media / Amiga Magazin
  3. ; von Gⁿrkan Demirci
  4. ; und Christoph Stahl
  5. ;
  6. ; (ASM-ONE source)
  7.  
  8. ; Linker Mausknopf = Verlassen
  9. ; Rechter Mausknopf= HohenΣndern
  10.  
  11. ; Benutzte Kennungen
  12. ;--------------------
  13. ; STRK    =    Struktur
  14. ; INFO    =    Informations Struktur
  15. ; CPU    =    Rechentabellen
  16. ; BUF    =    Arbeitsspeicher
  17. ; HARD    =    Hardwareroutinen
  18. ; INI    =    Initialisierungsroutinen
  19. ; RAM    =    Speicherroutinen
  20. ; SUB    =    Unterfunktionen
  21. ; BEOB    =    Beobachter
  22. ; CALC    =    Variable Gr÷▀en
  23. ; MODE    =    Modus werte
  24.  
  25. ; Beobachter
  26. BEOB_Radius1    =    40
  27. BEOB_Radius2    =    200
  28. BEOB_Winkel    =    70        ;(0-360)
  29. ; Blickkreis
  30. MODE_Punkte    =    %01        ;(%00=032, %01=064, %10=128, %11=256)
  31. MODE_Geraden    =    %10        ;(%00=128, %01=256, %10=512, %11=1024)
  32. ; Bildschirm
  33. MODE_Spalten    =    %01        ;(%00=040, %01=080, %10=160, %11=320)
  34. MODE_Bild    =    %01        ;(%00=128, %01=256, %10=512, %11=1024)
  35. MODE_Farbe    =    %00        ;(%00=016, %01=032, %10=064, %11=256)
  36. ; Perspektive
  37. MODE_Hohe    =    %01        ;(%00=  1, %01=  4, %10=  8, %11= 16)
  38. PERS_FluchtX    =    216
  39. PERS_FluchtY    =    256+128
  40. PERS_Obenstart    =    128+32
  41. PERS_Obenend    =    128+32+200
  42. PERS_Untenstart    =    128
  43. PERS_Untenend    =    128+200
  44.  
  45.  
  46.  
  47.     IF    MODE_Hohe=%00
  48.         CALC_Hohe=1
  49.     ENDIF
  50.     IF    MODE_Hohe=%01
  51.         CALC_Hohe=4
  52.     ENDIF
  53.     IF    MODE_Hohe=%10
  54.         CALC_Hohe=8
  55.     ENDIF
  56.     IF    MODE_Hohe=%11
  57.         CALC_Hohe=16
  58.     ENDIF
  59.     IF    MODE_Spalten=%00
  60.         CALC_Spalten=40
  61.         CALC_draw=$ff00
  62.         CALC_roll=8
  63.     ENDIF
  64.     IF    MODE_Spalten=%01
  65.         CALC_Spalten=80
  66.         CALC_draw=$f000
  67.         CALC_roll=4
  68.     ENDIF
  69.     IF    MODE_Spalten=%10
  70.         CALC_Spalten=160
  71.         CALC_draw=$c000
  72.         CALC_roll=2
  73.     ENDIF
  74.     IF    MODE_Spalten=%11
  75.         CALC_Spalten=320
  76.         CALC_draw=$8000
  77.         CALC_roll=1
  78.     ENDIF
  79.     IF    MODE_Punkte=%00
  80.         CALC_Punkte=32
  81.         CALC_Pshift=5
  82.     ENDIF
  83.     IF    MODE_Punkte=%01
  84.         CALC_Punkte=64
  85.         CALC_Pshift=6
  86.     ENDIF
  87.     IF    MODE_Punkte=%10
  88.         CALC_Punkte=128
  89.         CALC_Pshift=7
  90.     ENDIF
  91.     IF    MODE_Punkte=%11
  92.         CALC_Punkte=256
  93.         CALC_Pshift=8
  94.     ENDIF
  95.     IF    MODE_Geraden=%00
  96.         CALC_Geraden=128
  97.         CALC_Gshift=7
  98.     ENDIF
  99.     IF    MODE_Geraden=%01
  100.         CALC_Geraden=256
  101.         CALC_Gshift=8
  102.     ENDIF
  103.     IF    MODE_Geraden=%10
  104.         CALC_Geraden=512
  105.         CALC_Gshift=9
  106.     ENDIF
  107.     IF    MODE_Geraden=%11
  108.         CALC_Geraden=1024
  109.         CALC_Gshift=10
  110.     ENDIF
  111.     IF    MODE_Bild=%00
  112.         CALC_Bild=128
  113.         CALC_Shift=8
  114.         CALC_Mask=%111111101111111
  115.     ENDIF
  116.     IF    MODE_Bild=%01
  117.         CALC_Bild=256
  118.         CALC_Shift=9
  119.         CALC_Mask=%11111111011111111
  120.     ENDIF
  121.     IF    MODE_Bild=%10
  122.         CALC_Bild=512
  123.         CALC_Shift=10
  124.         CALC_Mask=%1111111110111111111
  125.     ENDIF
  126.     IF    MODE_Bild=%11
  127.         CALC_Bild=1024
  128.         CALC_Shift=11
  129.         CALC_Mask=%111111111101111111111
  130.     ENDIF
  131.     IF    MODE_FARBE=%00
  132.         CALC_FARBE=16
  133.         NAME_FARBE=0
  134.     ENDIF
  135.     IF    MODE_FARBE=%01
  136.         CALC_FARBE=32
  137.         NAME_FARBE=32
  138.     ENDIF
  139.     IF    MODE_FARBE=%10
  140.         CALC_FARBE=64
  141.         NAME_FARBE=64
  142.     ENDIF
  143.     IF    MODE_FARBE=%11
  144.         CALC_FARBE=256
  145.         NAME_FARBE=96
  146.     ENDIF
  147.  
  148.  
  149. **********************************************************
  150.  
  151. Programmstart
  152.  
  153. ; Programm Kopf
  154. ;---------------
  155. ; Speicher reservieren.
  156. ; Datenstrukturen initialisieren.
  157. ; Hardwarezustand speichern.
  158. ; Hardwarezustand aktivieren.
  159.  
  160.         jsr    RAM_reservieren
  161.         bmi    .error1
  162.  
  163.         jsr    INI_Datenstrukturen
  164.         bmi    .error2
  165.  
  166.         jsr    HARD_Speichern
  167.  
  168.         jsr    HARD_Aktivieren
  169.  
  170.         lea    $dff002,a6
  171.         move.l    #Interrupt,[$6C].W
  172.         move.w    #$c020,$DFF09a
  173. ; Schleife 1
  174. ;------------
  175. ; Bildspeicher l÷schen.
  176. ; Mausbewegung abfragen.
  177. ; Beobachterrichtung berechnen.
  178. ; Beobachterposition berechnen.
  179. ; Bildberechnen.
  180. ; Bild wechseln.
  181. ; Meldung an Schleife 2.  (Interrupt)
  182.  
  183. .Schleife1
  184.         jsr    SUB_Clrscreen
  185.         jsr    SUB_Maus
  186.         jsr    SUB_BEOB_Hohe
  187.         jsr    SUB_BEOB_Richtung
  188.         jsr    SUB_BEOB_Position
  189.         jsr    MAIN
  190.         jsr    SUB_Chgscreen
  191.         jsr    SUB_Schleife2meldung
  192.  
  193.         btst    #6,$bfe001
  194.         bne.w    .Schleife1
  195.  
  196.  
  197. ; Programm abbruch
  198. ;------------------
  199. ; Hardwarezustand zurⁿcksetzen.
  200. ; Speicher freigeben.
  201.  
  202.         jsr    HARD_Laden
  203.         jsr    RAM_freigeben
  204. .QUIT        moveq    #0,d0
  205.         rts
  206. .error1        moveq    #0,d0
  207.         rts
  208. .error2        jsr    RAM_freigeben
  209.         bra.s    .error1
  210.  
  211. ****************************************************************
  212.  
  213. ; Schleife 2 ( Verticalblank interrupt )
  214. ; Bei einem neuen Bildaufbau, wechselt diese Routine
  215. ; das Bild auf das schon berechnete Bild.
  216.  
  217. Interrupt
  218.         movem.l    d0-d7/a0-a5,-(a7)
  219.         tst.b    Bildwechseln
  220.         beq.s    .nichtwechseln
  221.         sf    Bildwechseln
  222.         BSR    SUB_SetScreen
  223. .nichtwechseln    movem.l    (a7)+,d0-d7/a0-a5
  224.         move.w    #$0020,$DFF09C
  225.         rte
  226. Bildwechseln    dc.b    0
  227.         even
  228.  
  229. ****************************************************************
  230. ; Hauproutine
  231. ; Diese Routine berechnet das Voxelspace Bild.
  232.  
  233. MAIN
  234.         move.l    STRK_CPU_Blickkreis(PC),a0
  235.         move.l    STRK_CPU_Offnungswinkel(PC),a1
  236.         move.l    STRK_INFO_Landschaft(PC),a2
  237.         lea    CALC_BILD(a2),a3
  238.         move.l    STRK_CPU_Perspektive(PC),a4
  239.         add.l    Hohenoffset(PC),a4
  240.         move.l    STRK_CPU_Rasterwerte(PC),a5
  241.  
  242.         move.w    BEOB_Richtung(PC),d0
  243.         sub.w    #CALC_Geraden*BEOB_winkel/360/2,d0
  244.         and.w    #CALC_Geraden-1,d0
  245.         mulu    #CALC_Punkte*4,d0        ;Blickgeraden Offset
  246.  
  247.         movem.w    BEOB_Position(PC),d1/d2
  248.         moveq    #CALC_SHIFT,d7
  249.         lsl.l    d7,d2
  250.         or.w    d1,d2                ;Beobachter position
  251.         move.l    #CALC_MASK,d1            ;▄berlauf Maske
  252.  
  253.         move.w    #CALC_Spalten-1,d7        ;Anzahl Spalten
  254.  
  255.  
  256.         move.l    STRK_BUF_Screen(PC),d6
  257.         add.l    Screenoffset(PC),d6
  258.         add.l    #40*255*4-40,d6
  259.  
  260. .busy3        btst    #6,(a6)
  261.         bne.s    .busy3
  262.         move.l    #-1,$44-2(a6)
  263.         move.w    #2,$42-2(a6)
  264.         move.w    #38,$66-2(a6)
  265.         move.w    #38,$62-2(a6)
  266.         clr.w    $60-2(a6)
  267.  
  268.         move.w    #CALC_draw,d5
  269. .GeradenSchleife
  270.         movem.l    d2/a0,-(a7)
  271.         add.l    (a1)+,d0            ;Geraden Offset
  272.         and.l    #[CALC_Geraden-1]*CALC_Punkte*4,d0
  273.         add.l    d0,a0
  274.         move.l    #$ff00,d3
  275.         moveq    #1,d4                ;H÷healt
  276.  
  277.         swap    d7
  278.         move.w    #CALC_Punkte-1,d7
  279. .busy2        btst    #6,(a6)
  280.         bne.s    .busy2
  281.         move.l    d6,$54-2(a6)
  282.         move.l    d6,$4c-2(a6)
  283.         move.w    d5,$74-2(a6)
  284.  
  285. .PunkteSchleife
  286.         add.w    #$100,d3
  287.         add.l    (a0)+,d2
  288.         and.l    d1,d2
  289.         move.b    (a2,d2.l),d3
  290.         move.b    (a4,d3.l),d3            ;H÷heneu
  291.         dbne    d7,.PunkteSchleife
  292.         beq.s    .Spalteok
  293.         sub.b    d4,d3                ;H÷healt,H÷hene
  294.         dbcc    d7,.PunkteSchleife
  295.         bcs.s    .Spalteok
  296.         add.b    d3,d4
  297.         swap    d4
  298.         clr.w    d4
  299.         move.b    (a3,d2.l),d4            ;Farbe
  300.         lsl.w    #3,d4
  301. .busy        btst    #6,(a6)
  302.         bne.s    .busy
  303.         move.l    (a5,d4.w),$48-2(a6)        ;Farbe
  304.         move.w    4(a5,d4.w),$40-2(a6)
  305.         clr.w    d4
  306.         move.b    d3,d4
  307.         lsl.w    #3,d4
  308.         move.w    6(a5,d4.w),$58-2(a6)        ;H÷he
  309.         swap    d4
  310.         addq.b    #1,d4                ;H÷healt
  311.         beq.s    .Spalteok
  312.         dbf    d7,.PunkteSchleife
  313. .Spalteok    movem.l    (a7)+,d2/a0
  314.         ror.w    #CALC_roll,d5
  315.         cmp.w    #CALC_draw,d5
  316.         bne.s    .cc
  317.         addq.l    #2,d6
  318. .cc        swap    d7
  319.         dbf    d7,.GeradenSchleife
  320.         rts
  321.  
  322.  
  323. ****************************************************************
  324.  
  325. ; Unterfunktionen
  326. ;-----------------
  327. ; SUB_Clrscreen
  328. ; SUB_Chgscreen
  329. ; SUB_Schleife2meldung
  330. ; SUB_Setscreen
  331. ; SUB_Maus
  332. ; SUB_BEOB_Position
  333. ; SUB_BEOB_Richtung
  334.  
  335. ; Diese Routine l÷scht das aktuelle Screen.
  336. SUB_Clrscreen
  337.         move.l    Screenoffset(PC),d0
  338.         add.l    STRK_BUF_screen(PC),d0
  339. .busy        btst    #6,(a6)
  340.         bne.s    .busy
  341.         move.l    #$1000000,$40-2(a6)
  342.         clr.w    $66-2(a6)
  343.         move.l    d0,$54-2(a6)
  344.         move.w    #255*4*64+40/2,$58-2(a6)
  345.         rts
  346.  
  347. ; Diese Routine erh÷ht den Screenoffset um ein Bild.
  348. ; Bei einem ⁿberlauf, wird das erste Screen wieder benutzt.
  349. ; Insgesammt werden drei Screens benutzt.
  350. SUB_Chgscreen
  351.         move.l    Screenoffset(PC),d0
  352.         add.l    #255*40*4,d0
  353.         cmp.l    #255*40*4*3,d0
  354.         blt.s    .keinuberlauf
  355.         clr.l    d0
  356. .keinuberlauf    move.l    d0,Screenoffset
  357.         rts
  358.  
  359. ; Diese Routine setzt die Meldung in einem Flag, damit
  360. ; die Interruptroutine feststellen kann, ob ein
  361. ; Bildwechsel statt finden soll.
  362. SUB_Schleife2meldung
  363.         st    Bildwechseln
  364.         rts
  365.  
  366. ; Diese Routine setzt die Screenpointer in der Copperliste.
  367. SUB_Setscreen
  368.         move.l    Screenoffset(PC),d0
  369.         sub.l    #40*255*4,d0
  370.         bpl.s    .keinuberlauf
  371.         move.l    #40*255*4*2,d0
  372. .keinuberlauf    add.l    STRK_BUF_screen(PC),d0
  373.         move.l    d0,a0
  374.         move.l    PTR_screen(PC),a1
  375.         addq.w    #2,a1
  376.         moveq    #3,d1
  377. .loop        move.l    a0,d0
  378.         move.w    d0,4(a1)
  379.         swap    d0
  380.         move.w    d0,(a1)
  381.         addq.w    #8,a1
  382.         add.w    #40,a0
  383.         dbf    d1,.loop
  384.         rts
  385. Screenoffset    dc.l    0
  386. PTR_screen    dc.l    0                ;pointer of copper
  387.  
  388. ; Diese Routine liest die Aktuellen Mausbewegungsdaten, um
  389. ; danach die Beobachteposition und -richtung zu berechnen
  390. SUB_Maus
  391.         move.w    $a-2(a6),d0
  392.         move.w    Mausraw(PC),d1
  393.         move.w    d0,Mausraw
  394.         move.w    d0,d2
  395.         move.w    d1,d3
  396.         lsr.w    #8,d0
  397.         and.w    #$ff,d2
  398.         lsr.w    #8,d1
  399.         and.w    #$ff,d3
  400.         sub.w    d1,d0
  401.         sub.w    d3,d2
  402.         ext.w    d0
  403.         ext.w    d2
  404.         movem.w    d0/d2,Mausdata
  405.         rts
  406. Mausraw        dc.w    0
  407. Mausdata    dc.w    0,0
  408.  
  409. ; Diese Routine berechnet die aktuelle Perspektivenoffset, fⁿr die
  410. ; verschiedenen H÷hen.
  411. SUB_BEOB_Hohe
  412.         btst    #10,$16-2(a6)        ;linke Maustaste
  413.         bne.s    .nicht
  414.         lea    Hohenoffset(PC),a0
  415.         lea    .Hohe(PC),a1
  416.         move.w    (a1),d0
  417.         tst.w    Mausdata
  418.         beq.s    .nicht
  419.         bmi.s    .nachOben
  420. .nachUnten    subq.w    #1,d0
  421.         bpl.s    .Hoheok
  422.         clr.w    d0
  423.         bra.s    .Hoheok
  424. .nachOben    addq.w    #1,d0
  425.         cmp.w    #CALC_Hohe-1,d0
  426.         ble.s    .Hoheok
  427.         move.w    #CALC_Hohe-1,d0
  428. .Hoheok        move.w    d0,(a1)
  429.         mulu    #256*CALC_Punkte,d0
  430.         move.l    d0,(a0)
  431. .nicht        rts
  432.  
  433. .Hohe        dc.w    0
  434. Hohenoffset    dc.l    0
  435.  
  436. ; Diese Routine berechnet die aktuelle Beobachterposition,
  437. ; mit hilfe der Angaben, die die SUB_Maus-routine liefert.
  438. SUB_BEOB_Position
  439.         move.l    STRK_CPU_winkel(PC),a0
  440.         move.w    BEOB_Richtung(PC),d0
  441.         lea    BEOB_Position(PC),a1
  442.         mulu    #1024/CALC_Geraden*4,d0
  443.         and.w    #$ffc,d0
  444.         move.w    Mausdata(PC),d1
  445.         movem.w    (a0,d0.w),d2/d3
  446.         muls    d1,d2
  447.         muls    d1,d3
  448.         asr.l    #2,d2                ;xadd:8
  449.         asr.l    #2,d3                ;yadd:8
  450.         swap    d2
  451.         swap    d3
  452.         movem.w    (a1),d4/d5
  453.         sub.w    d2,d4
  454.         sub.w    d3,d5
  455.         and.w    #CALC_Bild-1,d4
  456.         and.w    #CALC_Bild-1,d5
  457.         movem.w    d4/d5,(a1)
  458.         rts
  459. BEOB_Position    dc.w    0,0
  460.  
  461. ; Diese Routine berechnet die aktuelle Beobachterrichtung
  462. ; mit hilfe der Angaben, die die SUB_Maus-routine liefert.
  463. SUB_BEOB_Richtung
  464.         move.w    Mausdata+2(PC),d0
  465.         add.w    d0,BEOB_Richtung
  466.         rts
  467. BEOB_Richtung    dc.w    0
  468.  
  469. ****************************************************************
  470.  
  471. ; RAM_reservieren (MODE) (D0)    Speicher reservieren
  472. ; RAM_freigeben            Speicher freigeben
  473.  
  474. Exec_base        equ    $04
  475. AllocEntry        equ    -222
  476. FreeEntry        equ    -228
  477. MemListlen        equ    88
  478.  
  479. ; Diese Routine benutzt die DOS MemList-Struktur, um den ben÷tigten
  480. ; Speicher fⁿr die INFO, CPU und BUF-Datenstrukturen zu reservieren.
  481. ; Konnte der Speicher nicht reserviert werden, wird bei Verlassen
  482. ; der Routine, das negativ Flag gesetzt.
  483. ; Um auf den reservierten Speicher nicht ⁿber die MemList-Struktur
  484. ; zugreifen zu mⁿssen, wird die neue MemList in die alte MemList
  485. ; kopiert.
  486.  
  487. ; Speicher reservieren
  488. ;-----------------
  489. ; Landschaftsdaten
  490. ; Farbrasterdaten
  491. ; Blickkreis
  492. ; Perspektive
  493. ; Rasterwerte
  494. ; Winkelfunktionen
  495. ; Bildspeicher
  496. ; Copperspeicher
  497.  
  498. RAM_reservieren
  499.         move.l    [Exec_base].W,a6
  500.         lea    MemList(PC),a0
  501.         jsr    AllocEntry(a6)
  502.         tst.l    d0
  503.         bmi.s    .error
  504.         move.l    d0,MemListadrs
  505.         move.l    d0,a1
  506.         lea    MemList(PC),a0
  507.         moveq    #MemListlen-1,d0
  508. .copynxt    move.b    (a1)+,(a0)+
  509.         dbf    d0,.copynxt
  510.         moveq    #0,d0
  511. .error        rts
  512.  
  513. ; Speicher freigeben
  514. ;-----------------
  515. ; Landschaftsdaten
  516. ; Farbrasterdaten
  517. ; Blickkreis
  518. ; Perspektive
  519. ; Rasterwerte
  520. ; Winkelfunktionen
  521. ; Bildspeicher
  522. ; Copperspeicher
  523.  
  524. RAM_freigeben
  525.         move.l    [Exec_base].W,a6
  526.         move.l    MemListadrs(PC),a0
  527.         jsr    FreeEntry(a6)
  528.         rts
  529. MEMF_CHIP        equ    $02
  530. MEMF_PUBLIC        equ    $01
  531. MEMF_CLEAR        equ    $10000
  532. MemListadrs        dc.l    0
  533. MemList            dc.l    0            ;node_succ
  534.             dc.l    0            ;node_pred
  535.             dc.b    10            ;node_type
  536.             dc.b    0            ;node_pri
  537.             dc.l    0            ;node_name
  538.             dc.w    9            ;ML_numentries
  539. STRK_INFO_Landschaft    dc.l    MEMF_PUBLIC        ;ML_reqs
  540. SLEN_INFO_Landschaft    dc.l    CALC_Bild*CALC_Bild*2    ;ML_lenght
  541. STRK_INFO_Farbraster    dc.l    MEMF_CHIP        ;ML_reqs
  542. SLEN_INFO_Farbraster    dc.l    CALC_FARBE*255*4*2    ;ML_lenght
  543. STRK_CPU_Blickkreis    dc.l    MEMF_PUBLIC        ;ML_reqs
  544. SLEN_CPU_Blickkreis    dc.l    CALC_Geraden*CALC_Punkte*4    ;ML_lenght
  545. STRK_CPU_Offnungswinkel    dc.l    MEMF_PUBLIC        ;ML_reqs
  546. SLEN_CPU_Offnungswinkel    dc.l    CALC_Spalten*4        ;ML_lenght
  547. STRK_CPU_Perspektive    dc.l    MEMF_PUBLIC        ;ML_reqs
  548. SLEN_CPU_Perspektive    dc.l    256*CALC_Punkte*CALC_Hohe    ;ML_lenght
  549. STRK_CPU_Rasterwerte    dc.l    MEMF_PUBLIC        ;ML_reqs
  550. SLEN_CPU_Rasterwerte    dc.l    256*8            ;ML_lenght
  551. STRK_CPU_Winkel        dc.l    MEMF_PUBLIC        ;ML_reqs
  552. SLEN_CPU_Winkel        dc.l    4096            ;ML_lenght
  553. STRK_BUF_Screen        dc.l    MEMF_CHIP!MEMF_CLEAR    ;ML_reqs
  554. SLEN_BUF_Screen        dc.l    40*255*4*3        ;ML_lenght
  555. STRK_BUF_Copper        dc.l    MEMF_CHIP        ;ML_reqs
  556. SLEN_BUF_Copper        dc.l    37*4            ;ML_lenght
  557.  
  558. ****************************************************************
  559.  
  560. ; INI_Datenstrukturen    (D0)    (MODE)
  561.  
  562. OldOpenLib    equ    -408
  563. CloseLib    equ    -414
  564. Open        equ    -30
  565. Close        equ    -36
  566. Read        equ    -42
  567. Mode_old    equ    1005
  568.  
  569. ; Diese Routine initialisiert die reservierten Datenstrukturen.
  570. ; Bei Informationsdatenstrukturen(INFO) werden die Daten von
  571. ; einer Peripherie geladen. (s.h. NAME)
  572. ; Bei Rechentabellen werden die Daten in die Struktur hinein
  573. ; berechnet.
  574.  
  575. ; INI_Datenstrukturen
  576. ;---------------------
  577. ; Landschaftdaten
  578. ; Farbrasterdaten
  579. ; Blickkreis
  580. ; Perspektive
  581. ; Rasterwerte
  582. ; Winkelfunktionen
  583. ; Copper
  584.  
  585. INI_Datenstrukturen
  586.         lea    NAME_INFO_Landschaft(PC),a0
  587.         jsr    INI_INFO_Landschaft
  588.         bmi.s    .error
  589.         lea    NAME_CPU_Winkel(PC),a0
  590.         jsr    INI_CPU_Winkel
  591.         bmi.s    .error
  592.         lea    NAME_INFO_RASTER+NAME_FARBE(PC),a0
  593.         jsr    INI_INFO_Farbraster
  594.         bmi.s    .error
  595.         jsr    INI_BUF_Copper
  596.         bmi.s    .error
  597.         jsr    INI_CPU_Blickkreis
  598.         bmi.s    .error
  599.         jsr    INI_CPU_Offnungswinkel
  600.         bmi.s    .error
  601.         jsr    INI_CPU_Perspektive
  602.         bmi.s    .error
  603.         jsr    INI_CPU_Rasterwerte
  604.         bmi.s    .error
  605.         moveq    #0,d0
  606.         rts
  607. .error        moveq    #-1,d0
  608.         rts
  609.  
  610. NAME_INFO_RASTER
  611.         dc.b    "RAST16.iff",0,0
  612.         blk.b    20
  613.         dc.b    "RAST32.iff",0,0
  614.         blk.b    20
  615.         dc.b    "RAST64.iff",0,0
  616.         blk.b    20
  617.         dc.b    "RAST256.iff",0
  618.         blk.b    20
  619. NAME_INFO_Landschaft
  620.         dc.b    "Landschaft.dta",0
  621.         even
  622. NAME_CPU_Winkel    dc.b    "SinCos.dta",0
  623.         even
  624. NAME_DOSlib    dc.b    "dos.library",0
  625.         even
  626.  
  627. ; Diese Routine LΣd die Landschaftdaten (H÷hen- und Farbinformationen)
  628. ; Der Name des Files mu▀ in A0 ⁿbergeben werden.
  629. INI_INFO_Landschaft    ;(A0) (AdrsName)
  630.         BSR    INI_OpenLib
  631.         beq.s    INI_error1
  632.         move.l    d0,a6
  633.         BSR    INI_OpenFile
  634.         beq.s    INI_error2
  635.         move.l    d0,a5
  636.         move.l    a5,d1
  637.         move.l    STRK_INFO_Landschaft(PC),d2
  638.         move.l    SLEN_INFO_Landschaft(PC),d3
  639.         jsr    Read(a6)
  640.         cmp.l    SLEN_INFO_Landschaft(PC),d0
  641.         bne.s    INI_error3
  642.         BSR    INI_CloseFile
  643.         BSR    INI_CloseLib
  644.         moveq    #0,d0
  645.         rts
  646. INI_error1    moveq    #-1,d0
  647.         rts
  648. INI_error2    BSR    INI_CloseLib
  649.         bra.s    INI_error1
  650. INI_error3    BSR    INI_CloseFile
  651.         BSR    INI_CloseLib
  652.         bra.s    INI_error1
  653. INI_OpenFile    ;(A0)    (adrsName)
  654.         move.l    a0,d1
  655.         move.l    #Mode_old,d2
  656.         jsr    Open(a6)
  657.         tst.l    d0
  658.         rts
  659. INI_CloseFile    ;(A5) (adrsHandle)
  660.         move.l    a5,d1
  661.         jmp    Close(a6)
  662. INI_OpenLib    movem.l    d1-d7/a0-a6,-(a7)
  663.         move.l    [Exec_base].W,a6
  664.         lea    NAME_DOSlib(PC),a1
  665.         jsr    OldOpenLib(a6)
  666.         movem.l    (a7)+,d1-d7/a0-a6
  667.         tst.l    d0
  668.         rts
  669. INI_CloseLib    ;(A6) (adrsLib)
  670.         move.l    a6,a1
  671.         move.l    [Exec_base].W,a6
  672.         jmp    CloseLib(a6)
  673.  
  674. ; Diese Routine LΣd die Winkelfunktionen (Sinus- und Cosinusfunktionsdaten)
  675. ; Der Name des Files mu▀ in A0 ⁿbergeben werden.
  676. INI_CPU_Winkel    ;(A0)    (AdrsName)
  677.         BSR    INI_OpenLib
  678.         beq.s    INI_error1
  679.         move.l    d0,a6
  680.         BSR    INI_OpenFile
  681.         beq.s    INI_error2
  682.         move.l    d0,a5
  683.         move.l    a5,d1
  684.         move.l    STRK_CPU_Winkel(PC),d2
  685.         move.l    SLEN_CPU_Winkel(PC),d3
  686.         jsr    Read(a6)
  687.         cmp.l    SLEN_CPU_Winkel(PC),d0
  688.         bne.s    INI_error3
  689.         BSR    INI_CloseFile
  690.         BSR    INI_CloseLib
  691.         moveq    #0,d0
  692.         rts
  693.  
  694. ; Diese Routine lΣd die Werte fⁿr die Farbrasterstruktur.
  695. INI_INFO_Farbraster ;(a0=*name)
  696.         BSR    INI_OpenLib
  697.         beq.w    INI_error1
  698.         move.l    d0,a6
  699.         BSR    INI_OpenFile
  700.         beq.w    INI_error2
  701.         move.l    d0,a5
  702.         move.l    a5,d1
  703.         move.l    STRK_BUF_Screen(PC),d2
  704.         move.l    #256*4*40,d3
  705.         jsr    Read(a6)
  706.         tst.l    d0
  707.         beq.w    INI_error3
  708.         BSR    INI_CloseFile
  709.         BSR    INI_CloseLib
  710.         BSR    SUB_IFF
  711.         bmi.w    INI_error1
  712.         move.l    STRK_INFO_Farbraster(PC),a0
  713.         move.l    STRK_BUF_SCREEN(PC),a1
  714.         add.l    #256*4*40,a1
  715.         moveq    #0,d0
  716. .loop1        move.w    #$f0,d1
  717.         and.w    d0,d1
  718.         lsr.w    #3,d1
  719.         lea    (a1,d1.w),a2
  720.         moveq    #$f,d1
  721.         and.w    d0,d1
  722.         mulu    #16*40*4,d1
  723.         add.l    d1,a2
  724.         moveq    #14,d2
  725. .loop3        move.l    a2,a3
  726.         moveq    #16*4-1,d1
  727. .loop2        move.w    (a3),(a0)+
  728.         add.w    #40,a3
  729.         dbf    d1,.loop2
  730.         dbf    d2,.loop3
  731.         move.l    a2,a3
  732.         moveq    #15*4-1,d1
  733. .loop4        move.w    (a3),(a0)+
  734.         add.w    #40,a3
  735.         dbf    d1,.loop4
  736.         add.w    #256/CALC_FARBE,d0
  737.         cmp.w    #256,d0
  738.         blt.s    .loop1
  739.         moveq    #0,d0
  740.         rts
  741.  
  742. SUB_IFF
  743.     move.l    STRK_BUF_SCREEN(PC),a1
  744.     add.l    #256*4*40,a1
  745.     move.l    STRK_BUF_SCREEN(PC),a0
  746.     cmp.l    #"FORM",(a0)+
  747.     bne.s    .error
  748.     move.l    (a0)+,d1
  749.     subq.l    #4,d1
  750.     bmi.s    .error
  751.     cmp.l    #"ILBM",(a0)+
  752.     bne.s    .error
  753. .findbody
  754.     move.l    (a0)+,d0
  755.     subq.l    #4,d1
  756.     bmi.s    .error
  757.     cmp.l    #"BODY",d0
  758.     beq.s    .bodyfound
  759.     move.l    (a0)+,d0
  760.     add.l    d0,a0
  761.     subq.l    #4,d1
  762.     sub.l    d0,d1
  763.     bmi.s    .error
  764.     bra.s    .findbody
  765. .bodyfound
  766.     move.l    (a0)+,d1
  767.     move.w    #256*4-1,d7
  768. .loop2    moveq    #0,d6
  769. .loop1    clr.w    d0
  770.     move.b    (a0)+,d0
  771.     bmi.s    .min
  772.     move.w    d0,d1
  773. .pos_loop1
  774.     move.b    (a0)+,(a1)+
  775.     dbf    d1,.pos_loop1
  776. .weiter    addq.w    #1,d6
  777.     add.w    d0,d6
  778.     cmp.w    #40,d6
  779.     bgt.s    .error
  780.     bne.s    .loop1
  781.     dbf    d7,.loop2
  782.     moveq    #0,d0
  783.     rts
  784. .min    neg.b    d0
  785.     move.w    d0,d1
  786.     move.b    (a0)+,d2
  787. .min_loop1
  788.     move.b    d2,(a1)+
  789.     dbf    d1,.min_loop1
  790.     bra.s    .weiter
  791. .error    moveq    #-1,d0
  792.     rts
  793.  
  794. ; Diese Routine initialisiert die Copperliste mit
  795. ; Bildgr÷▀e, Farben und Bildspeicher.
  796. INI_BUF_Copper
  797.         move.l    STRK_BUF_Copper(PC),a0
  798.         move.l    #$1800000,(a0)+
  799.         move.l    #$1000200,(a0)+
  800.         move.l    #$8e2981,(a0)+
  801.         move.l    #$9028c1,(a0)+
  802.         move.l    #$920038,(a0)+
  803.         move.l    #$9400d0,(a0)+
  804.         lea    Farbtabelle(PC),a1
  805.         moveq    #16-1,d0
  806.         move.w    #$180,d1
  807. .setcolor    move.w    d1,(a0)+
  808.         move.w    (a1)+,(a0)+
  809.         addq.w    #2,d1
  810.         dbf    d0,.setcolor
  811.         move.l    #$1020000,(a0)+
  812.         move.l    #$1040000,(a0)+
  813.         move.l    #$1080078,(a0)+
  814.         move.l    #$10a0078,(a0)+
  815.         move.l    #$200ffffe,(a0)+
  816.         move.l    a0,PTR_screen
  817.         moveq    #7,d0
  818.         move.w    #$e0,d1
  819. .setbpladrs    move.w    d1,(a0)+
  820.         clr.w    (a0)+
  821.         addq.w    #2,d1
  822.         dbf    d0,.setbpladrs
  823.         move.l    #$1004200,(a0)+
  824.         move.l    #$fffffffe,(a0)+
  825.         moveq    #0,d0
  826.         rts
  827.  
  828. ****************************************************************
  829. * Funktionen, die die Datenstrukturen initialisieren, die der
  830. * Geschwindigkeit der Programmausfⁿhrung dienen (Rechentabellen).
  831. ****************************************************************
  832.  
  833. ; Diese Routine berechnet die Blickkreisstruktur.
  834. INI_CPU_Blickkreis
  835.         move.l    STRK_CPU_Blickkreis(PC),a0
  836.         move.l    STRK_CPU_winkel(PC),a1
  837.         clr.w    d0
  838. .nxtGerade    move.l    d0,-(a7)
  839.         mulu    #1024,d0
  840.         divu    #CALC_Geraden,d0
  841.         add.w    d0,d0
  842.         add.w    d0,d0
  843.         and.w    #$ffc,d0
  844.         movem.w    (a1,d0.w),d0/d1
  845.         move.w    d0,d2
  846.         move.w    d1,d3
  847.         muls    #BEOB_Radius1,d0    ;in Kreis
  848.         muls    #BEOB_Radius1,d1
  849.         muls    #BEOB_Radius2,d2    ;out Kreis
  850.         muls    #BEOB_Radius2,d3
  851.         add.l    d0,d0
  852.         add.l    d1,d1
  853.         add.l    d2,d2
  854.         add.l    d3,d3
  855.         swap    d0
  856.         swap    d1
  857.         swap    d2
  858.         swap    d3
  859.         sub.w    d0,d2
  860.         sub.w    d1,d3
  861.         ext.l    d2
  862.         ext.l    d3
  863.  
  864.         sub.w    a2,a2
  865.         sub.w    a3,a3
  866.         clr.l    d4
  867.         clr.l    d5
  868.         move.w    #CALC_Punkte-1,d6
  869. .nxtPunkt    movem.l    d4/d5,-(a7)
  870.         divs    #CALC_Punkte,d4
  871.         divs    #CALC_Punkte,d5
  872.         add.w    d0,d4
  873.         add.w    d1,d5
  874.         ext.w    d4
  875.         ext.w    d5
  876.         movem.w    d4/d5,-(a7)
  877.         sub.w    a2,d4
  878.         sub.w    a3,d5
  879.         movem.w    (a7)+,a2/a3
  880.         and.l    #CALC_BILD-1,d4
  881.         and.l    #CALC_BILD-1,d5
  882.         moveq    #CALC_SHIFT,d7
  883.         lsl.l    d7,d5
  884.         or.l    d4,d5
  885.         move.l    d5,(a0)+
  886.         movem.l    (a7)+,d4/d5
  887.         add.l    d2,d4
  888.         add.l    d3,d5
  889.         dbf    d6,.nxtPunkt
  890.         move.l    (a7)+,d0
  891.         addq.w    #1,d0
  892.         cmp.w    #CALC_Geraden,d0
  893.         bne.w    .nxtGerade
  894.         moveq    #0,d0
  895.         rts
  896.  
  897. ; Diese Routine errechnet die Datenstruktur in der
  898. ; die Anfangsaddressen fⁿr die Blickgeraden enthalten sind
  899. ; ,die den Offnungswinkel ausmachen.
  900. INI_CPU_Offnungswinkel
  901.         move.l    STRK_CPU_Blickkreis(PC),a0
  902.         move.l    STRK_CPU_Offnungswinkel(PC),a1
  903.         move.w    #CALC_Pshift,d0
  904.  
  905.         move.l    #CALC_Geraden*BEOB_Winkel,d1
  906.  
  907.         move.l    #CALC_Spalten*360/4,d2
  908.         clr.l    d3
  909.         clr.l    d4
  910.  
  911.         move.w    #CALC_Spalten-1,d5
  912. .nxtGerade    move.l    d3,-(a7)
  913.         divu    d2,d3
  914.         and.l    #$fffc,d3
  915.  
  916.         lsl.l    d0,d3
  917.         move.l    d3,-(a7)
  918.         sub.l    d4,d3
  919.         move.l    (a7)+,d4
  920.         move.l    d3,(a1)+
  921.         move.l    (a7)+,d3
  922.         add.l    d1,d3
  923.         dbf    d5,.nxtGerade
  924.  
  925.         moveq    #0,d0
  926.         rts
  927.  
  928. ; Diese Routine berechnet die Perspektivenstruktur fⁿr
  929. ; die anzahl der H÷hen.
  930. INI_CPU_Perspektive
  931.         move.l    STRK_CPU_Perspektive(PC),a0
  932.         moveq    #0,d0            ;Oben
  933.         moveq    #0,d1            ;Unten
  934.  
  935. .nxtHohe    movem.l    d0/d1,-(a7)
  936.         divu    #CALC_Hohe,d0
  937.         add.w    #PERS_Obenstart,d0
  938.         divu    #CALC_Hohe,d1
  939.         add.w    #PERS_Untenstart,d1
  940.         *
  941.         move.w    d0,d2
  942.         sub.w    #255,d2
  943.         ext.l    d2
  944.         asl.l    #8,d2
  945.         divs    #PERS_FluchtX,d2    :mo
  946.  
  947.         move.w    d0,d3
  948.         ext.l    d3
  949.         asl.l    #8,d3
  950.         divs    #PERS_FluchtX,d3    ;mu
  951.  
  952.  
  953.  
  954.         moveq    #0,d4            ;n
  955. .nxtPunkt    movem.l    d2/d3/d4,-(a7)
  956.         mulu    #BEOB_Radius2-BEOB_Radius1,d4
  957.         add.l    #BEOB_Radius1*CALC_Punkte,d4
  958.         divu    #CALC_Punkte,d4        ;xp
  959.  
  960.         muls    d4,d2
  961.         add.l    #255*256,d2        ;ypmax
  962.         muls    d4,d3            ;ypmin
  963.         asr.l    #8,d2
  964.         asr.l    #8,d3
  965.  
  966.         moveq    #0,d5            ;p
  967. .nxtWert    move.w    d2,d7
  968.         sub.w    d3,d7
  969.         mulu    d5,d7
  970.         divu    #255,d7
  971.         add.w    d3,d7            ;b
  972.         sub.w    d1,d7            ;b-unten
  973.         ext.l    d7
  974.         muls    #255,d7
  975.         move.w    #PERS_FluchtY,d6
  976.         sub.w    d1,d6
  977.         divs    d6,d7            ;h
  978.         add.w    #128,d7
  979.         bpl.s    .low
  980.  
  981.  
  982.         moveq    #0,d7
  983. .low        cmp.w    #256,d7
  984.         blt.s    .ok
  985.         move.w    #255,d7
  986. .ok        move.b    d7,(a0)+
  987.         addq.b    #1,d5
  988.         bne.s    .nxtWert
  989.         movem.l    (a7)+,d2/d3/d4
  990.         addq.w    #1,d4
  991.         cmp.w    #CALC_Punkte,d4
  992.         bne.w    .nxtPunkt
  993.         *
  994.         movem.l    (a7)+,d0/d1
  995.         add.l    #PERS_Obenend-PERS_Obenstart,d0
  996.         add.l    #PERS_Untenend-PERS_Untenstart,d1
  997.         addq.w    #1,.Hohe
  998.         cmp.w    #CALC_Hohe,.Hohe
  999.         bne.w    .nxtHohe
  1000.         moveq    #0,d0
  1001.         rts
  1002. .Hohe        dc.w    0
  1003.  
  1004. ; Diese Routine berechnet die Rasterwertestruktur fⁿr die Farbdarstellung.
  1005. INI_CPU_Rasterwerte
  1006.         move.l    STRK_CPU_rasterwerte(PC),a0
  1007.         move.l    STRK_INFO_Farbraster(PC),a1
  1008.         add.w    #255*4*2-2,a1
  1009.         move.w    #256-1,d0
  1010.         moveq    #1,d1
  1011. .nxtadrs    add.w    #64*4,d1
  1012.         move.l    a1,(a0)+
  1013.         move.w    #$7ac,(a0)+
  1014.         move.w    d1,(a0)+
  1015.         add.w    #255*4*2,a1
  1016.         dbf    d0,.nxtadrs
  1017.         moveq    #0,d0
  1018.         rts
  1019.  
  1020. ****************************************************************
  1021. * Funktionen, die die Hardwareregister Speichern, Aktivieren und
  1022. * Laden.
  1023. ****************************************************************
  1024.  
  1025. ; Hardwareregister zwischenspeichern.
  1026. HARD_Speichern
  1027.         lea    $DFF000,a6
  1028.         move.w    $1c(a6),d0
  1029.         or.w    #$c000,d0
  1030.         swap    d0
  1031.         move.w    $2(a6),d0
  1032.         or.w    #$8000,d0
  1033.         movem.l    [$68].W,d1-d7/a0
  1034.         movem.l    d0-d7/a0,HARD_buffer
  1035.         rts
  1036.  
  1037. ; Hardwareregister initialisieren.
  1038. HARD_Aktivieren
  1039.         lea    $DFF000,a6
  1040.         move.w    #$7fff,$96(a6)
  1041.         move.w    #$7fff,$9a(a6)
  1042.         move.w    #$7fff,$9c(a6)
  1043.         move.l    STRK_BUF_Copper(PC),$80(a6)
  1044.         move.w    #$87c0,$96(a6)
  1045.         rts
  1046.  
  1047. ; Hardwareregister zurⁿcksetzen.
  1048. HARD_Laden
  1049.         movem.l    HARD_buffer(PC),d0-d7/a0
  1050.         lea    $DFF000,a6
  1051.         move.w    #$7fff,$96(a6)
  1052.         move.w    #$7fff,$9a(a6)
  1053.         move.w    #$7fff,$9c(a6)
  1054.         movem.l    d1-d7/a0,[$68].W
  1055.         move.w    d0,$96(a6)
  1056.         swap    d0
  1057.         move.w    d0,$9a(a6)
  1058.         move.l    [Exec_base].W,a6
  1059.         lea    NAME_Gfxlib(PC),a1
  1060.         jsr    OldOpenLib(a6)
  1061.         move.l    d0,a1
  1062.         move.l    $26(a1),$DFF080
  1063.         jsr    CloseLib(a6)
  1064.         lea    $DFF000,a6
  1065.         clr.w    $88(a6)
  1066.         rts
  1067. HARD_Buffer    blk.l    9,0
  1068. NAME_Gfxlib    dc.b    "graphics.library",0
  1069.         even
  1070.  
  1071. ****************************************************************
  1072. * Daten
  1073. ****************************************************************
  1074. ; Diese 16 Paletten Farben. ( Rot/Grⁿn/Blau nibble )
  1075.  
  1076. Farbtabelle    ;RGB
  1077.     DC.B    $00,$00,$03,$10,$04,$10,$05,$20
  1078.     DC.B    $06,$30,$07,$41,$08,$52,$09,$63
  1079.     DC.B    $0A,$74,$0B,$85,$0C,$96,$0D,$A7
  1080.     DC.B    $0E,$B8,$02,$48,$01,$23,$09,$F3
  1081. E
  1082.