home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / Asm / Demos / Julia.s < prev    next >
Encoding:
Text File  |  1997-02-16  |  6.9 KB  |  357 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;JULIA 2
  3. ;-------
  4. ;A fractal generator, not orginally written by myself but now works with
  5. ;the library.
  6.  
  7.     INCDIR    "INCLUDES:"
  8.     INCLUDE    "exec/exec_lib.i"
  9.     INCLUDE    "games/games_lib.i"
  10.     INCLUDE    "games/games.i"
  11.  
  12. CALL    MACRO
  13.     jsr    _LVO\1(a6)
  14.     ENDM
  15.  
  16.     SECTION    "Julia",CODE
  17.  
  18. ;==========================================================================;
  19. ;                             INITIALISE DEMO
  20. ;==========================================================================;
  21.  
  22. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  23.     move.l    ($4).w,a6
  24.     lea    GMS_Name(pc),a1
  25.     moveq    #$00,d0
  26.     CALL    OpenLibrary
  27.     move.l    d0,GMS_Base
  28.     beq    Quit
  29.  
  30.     move.l    GMS_Base(pc),a6
  31.     sub.l    a0,a0
  32.     CALL    SetUserPrefs
  33.  
  34.     lea    Screen(pc),a0
  35.     CALL    AddScreen
  36.     tst.l    d0
  37.     bne    Error
  38.  
  39.     CALL    ShowScreen
  40.  
  41. ;==========================================================================;
  42. ;                                DRAW JULIA
  43. ;==========================================================================;
  44.  
  45.     lea    DataArea(pc),a5
  46.     move.l    #$fffffffe,(a5)+    ;a5 = $fffffffe+
  47.     move.l    #$80000014,(a5)+    ;a5 = mask & word per raster count
  48.  
  49. StartJulia:
  50.     move.l    GMS_Base(pc),a6
  51.     lea    Screen(pc),a0
  52.     moveq    #BUFFER1,d0
  53.     CALL    ClrScreen
  54.  
  55.     move.l    Screen+GS_MemPtr1(pc),a0
  56.     lea    JuliaData(pc),a6
  57.     move.l    (a6)+,(a5)    ;a5 = ?
  58. .JuliaFound
  59.     move.w    (a5),MValue    ;initial m
  60.     move.w    (a6),PixStep    ;pixel step
  61.     move.w    (a6)+,RastStep    ;raster step
  62.     move.l    (a6)+,C1C2    ;initial c1 and c2
  63.     move.w    #256,LinesLeft(a5)    ;vertical height
  64.     lea    256*40(a0),a1
  65.     lea    256*40(a1),a2
  66.     lea    256*40(a2),a3
  67.     lea    $04000000,a6    ;for magnitude test
  68.  
  69.     lea    256*40(a3),a4
  70.  
  71.     MOVE.L    A6,-(SP)
  72.     move.l    GMS_Base(pc),a6
  73.     CALL    WaitSVBL
  74.     MOVE.L    (SP)+,A6
  75.  
  76. PixelLoop:
  77.     move.w    (a5),d1    ;d1 = Initial X
  78.     move.w    InitialY(a5),d0    ;d0 = Initial Y
  79.     moveq    #30,d7    ;d7 = 30.
  80.     movem.w    C1C2(pc),d4-d5    ;MA : d4/d5 = C1/C2
  81.     move.w    d0,d2    ;d2 = Initial Y
  82.     move.w    d1,d3    ;d3 = Initial X
  83.     bra.s    CheckMagnitude
  84.  
  85. IterateJulia:
  86.     sub.l    d3,d2    ;x^2 - y^2
  87.     lsl.l    #4,d2    ;fix decimal point
  88.     swap    d2    ;...
  89.     add.w    d4,d2    ;x1 = x^2 - y^2 + c1
  90.  
  91.     move.w    d1,d3    ;y
  92.     muls    d0,d3    ;x * y
  93.     lsl.l    #5,d3    ;fix decimal point and multiply by 2
  94.     swap    d3    ;...
  95.     add.w    d5,d3    ;y1 = 2 * x * y + c2
  96.  
  97.     move.w    d2,d0    ;x = x1
  98.     move.w    d3,d1    ;y = y1
  99.  
  100. CheckMagnitude:
  101.     muls    d2,d2    ;x^2
  102.     muls    d3,d3    ;y^2
  103.     move.l    d2,d6
  104.     add.l    d3,d6    ;z = x^2 + y^2
  105.     cmp.l    a6,d6    ;escaped yet?
  106.     dbhi    d7,IterateJulia
  107.  
  108.     move.w    PixelMask(a5),d6
  109.     moveq    #0,d5
  110.     move.b    JumpTable+1(pc,d7.w),d5
  111.     jmp    JumpTable(pc,d5.w)
  112.  
  113. JumpTable:
  114.     dc.b    Plot00-JumpTable
  115.     dc.b    Plot31-JumpTable
  116.     dc.b    Plot30-JumpTable
  117.     dc.b    Plot29-JumpTable
  118.     dc.b    Plot28-JumpTable
  119.     dc.b    Plot27-JumpTable
  120.     dc.b    Plot26-JumpTable
  121.     dc.b    Plot25-JumpTable
  122.     dc.b    Plot24-JumpTable
  123.     dc.b    Plot23-JumpTable
  124.     dc.b    Plot22-JumpTable
  125.     dc.b    Plot21-JumpTable
  126.     dc.b    Plot20-JumpTable
  127.     dc.b    Plot19-JumpTable
  128.     dc.b    Plot18-JumpTable
  129.     dc.b    Plot01-JumpTable
  130.     dc.b    Plot16-JumpTable
  131.     dc.b    Plot15-JumpTable
  132.     dc.b    Plot14-JumpTable
  133.     dc.b    Plot13-JumpTable
  134.     dc.b    Plot12-JumpTable
  135.     dc.b    Plot11-JumpTable
  136.     dc.b    Plot10-JumpTable
  137.     dc.b    Plot09-JumpTable
  138.     dc.b    Plot08-JumpTable
  139.     dc.b    Plot07-JumpTable
  140.     dc.b    Plot06-JumpTable
  141.     dc.b    Plot05-JumpTable
  142.     dc.b    Plot04-JumpTable
  143.     dc.b    Plot03-JumpTable
  144.     dc.b    Plot02-JumpTable
  145.     dc.b    Plot17-JumpTable
  146.  
  147. Plot22:    or.w    d6,(a4)
  148.     or.w    d6,(a2)
  149.     or.w    d6,(a1)
  150.     bra.b    Plot00
  151.  
  152. Plot21:    or.w    d6,(a4)
  153.     or.w    d6,(a2)
  154.     or.w    d6,(a0)
  155.     bra.b    Plot00
  156.  
  157. Plot20:    or.w    d6,(a4)
  158.     or.w    d6,(a2)
  159.     bra.b    Plot00
  160.  
  161. Plot18:    or.w    d6,(a4)
  162.     or.w    d6,(a1)
  163.     bra.b    Plot00
  164.  
  165. Plot26:    or.w    d6,(a4)
  166. Plot10:    or.w    d6,(a3)
  167.     or.w    d6,(a1)
  168.     bra.b    Plot00
  169.  
  170. Plot23:    or.w    d6,(a4)
  171.     or.w    d6,(a2)
  172.     or.w    d6,(a1)
  173.     or.w    d6,(a0)
  174.     bra.b    Plot00
  175.  
  176. Plot19:    or.w    d6,(a4)
  177.     or.w    d6,(a1)
  178.     or.w    d6,(a0)
  179.     bra.b    Plot00
  180.  
  181. Plot27:    or.w    d6,(a4)
  182. Plot11:    or.w    d6,(a3)
  183.     or.w    d6,(a1)
  184.     or.w    d6,(a0)
  185.     bra.b    Plot00
  186.  
  187. Plot17:    or.w    d6,(a4)
  188.     or.w    d6,(a0)
  189.     bra.b    Plot00
  190.  
  191. Plot25:    or.w    d6,(a4)
  192. Plot09:    or.w    d6,(a3)
  193.     or.w    d6,(a0)
  194.     bra.b    Plot00
  195.  
  196. Plot29:    or.w    d6,(a4)
  197. Plot13:    or.w    d6,(a3)
  198. Plot05:    or.w    d6,(a2)
  199.     or.w    d6,(a0)
  200.     bra.b    Plot00
  201.  
  202. Plot16:    or.w    d6,(a4)
  203.     bra.b    Plot00
  204.  
  205. Plot24:    or.w    d6,(a4)
  206. Plot08:    or.w    d6,(a3)
  207.     bra.b    Plot00
  208.  
  209. Plot28:    or.w    d6,(a4)
  210. Plot12:    or.w    d6,(a3)
  211. Plot04:    or.w    d6,(a2)
  212.     bra.b    Plot00
  213.  
  214. Plot30:    or.w    d6,(a4)
  215. Plot14:    or.w    d6,(a3)
  216. Plot06:    or.w    d6,(a2)
  217. Plot02:    or.w    d6,(a1)
  218.     bra.b    Plot00
  219.  
  220. Plot31:    or.w    d6,(a4)
  221. Plot15:    or.w    d6,(a3)
  222. Plot07:    or.w    d6,(a2)
  223. Plot03:    or.w    d6,(a1)
  224. Plot01:    or.w    d6,(a0)
  225.  
  226. Plot00:    MOVE.L    D0,-(SP)
  227.     move.w    PixStep(pc),d0
  228.     add.w    d0,(a5)    ;pixel "step"
  229.     MOVE.L    (SP)+,D0
  230.  
  231.     ror.w    PixelMask(a5)    ;shift mask over
  232.     bpl.w    PixelLoop
  233.  
  234.     addq.w    #2,a0
  235.     addq.w    #2,a1
  236.     addq.w    #2,a2
  237.     addq.w    #2,a3
  238.     addq.w    #2,a4
  239.     subq.w    #1,WordsInRaster(a5)    ; subtract from word counter
  240.     bne.w    PixelLoop
  241.  
  242.     MOVE.L    A6,-(SP)
  243.     move.l    GMS_Base(pc),a6
  244.     CALL    AutoSwitch
  245.     MOVE.L    (SP)+,A6
  246.  
  247.     btst.b    #6,$bfe001
  248.     beq.b    Exit
  249.  
  250.     move.w    #320/16,WordsInRaster(a5) ; words per raster
  251.     btst.b    #2,$dff016    ;new julia?
  252.     beq.b    NewJulia
  253.  
  254. RasterInit:
  255.     move.w    MValue(pc),(a5)    ;inital M value
  256. RasterAdd:
  257.     MOVE.L    D0,-(SP)
  258.     move.w    RastStep(pc),d0
  259.     add.w    d0,InitialY(a5)    ; raster "step"
  260.     MOVE.L    (SP)+,D0
  261.     subq.w    #1,LinesLeft(a5)
  262.     bne.w    PixelLoop
  263.  
  264. WaitMouse:
  265.     btst.b    #6,$bfe001
  266.     beq.b    Exit
  267.     btst.b    #2,$dff016
  268.     bne.b    WaitMouse
  269.  
  270. NewJulia:
  271.     btst.b    #2,$dff016
  272.     beq.b    NewJulia
  273.     bra.w    StartJulia
  274.  
  275. ;===========================================================================;
  276. ;                              RETURN TO DOS
  277. ;===========================================================================;
  278.  
  279. Exit:    move.l    GMS_Base(pc),a6
  280.     lea    Screen(pc),a0
  281.     CALL    DeleteScreen    ;Give back screen memory etc.
  282. Error    move.l    GMS_Base(pc),a1
  283.     move.l    ($4).w,a6
  284.     CALL    CloseLibrary
  285. Quit    MOVEM.L    (SP)+,A0-A6/D1-D7
  286.     moveq    #$00,d0
  287.     rts
  288.  
  289. ;===========================================================================;
  290. ;                                  DATA
  291. ;===========================================================================;
  292.  
  293. MValue:    dc.w    0
  294. PixStep:
  295.     dc.w    0
  296. RastStep:
  297.     dc.w    0
  298. C1C2:    dc.l    0
  299.  
  300. GMS_Name:
  301.     dc.b    "games.library",0
  302.     even
  303. GMS_Base:
  304.     dc.l    0
  305.  
  306. AMT_PLANES =    5
  307.  
  308. Screen:    dc.l    GSV1,0
  309.     dc.l    0,0,0    ;Screen memory 1/2/3.
  310.     dc.l    0    ;Screen link.
  311.     dc.l    .Palette    ;Address of screen palette.
  312.     dc.l    0    ;Address of rasterlist.
  313.     dc.l    0    ;Amt of colours in palette.
  314.     dc.w    320,256    ;Screen Width and Height.
  315.     dc.w    0,0,0    ;Picture Width, ByteWidth and Height.
  316.     dc.w    AMT_PLANES    ;Amount of planes
  317.     dc.w    0,0    ;X/Y screen offset.
  318.     dc.w    0,0    ;X/Y picture offset.
  319.     dc.l    0    ;Special attributes.
  320.     dc.w    LORES|COL12BIT    ;Screen mode.
  321.     dc.w    PLANAR    ;Screen type
  322.  
  323. .Palette
  324.     dc.w    $000,$831,$00e,$00d,$00c,$00b,$00a,$009
  325.     dc.w    $008,$007,$106,$205,$304,$403,$502,$611
  326.     dc.w    $720,$00f,$942,$a53,$b64,$c75,$d86,$c97
  327.     dc.w    $ba8,$a9a,$98b,$879,$767,$555,$343,$131
  328.  
  329. JuliaData:
  330.     dc.l    $f800eb00
  331.     dc.w    $0018,$0100,$0ad0,$ec00
  332.  
  333.     dc.l    $fd21eeae
  334.     dc.w    $0225,$000d,$f420,$fd43
  335.  
  336.     dc.l    $ef000010
  337.     dc.w    $0600,$0100,$f226,$fd56
  338.  
  339.     dc.l    $0015ee00
  340.     dc.w    $fb40,$ede2,$f0b2,$001d
  341.  
  342.     dc.l    $05c0ff00
  343.     dc.w    $ef12,$e812,$001d,$f320
  344.     dc.l    0
  345.  
  346.  
  347.     rsset    -4
  348. PixelMask rs.w    1    ;mask to "OR" with bitplanes
  349. WordsInRaster rs.w 1    ;number of words left in current raster
  350. InitialX rs.w    1    ;inital x
  351. InitialY rs.w    1    ;inital y
  352. LinesLeft rs.w    1    ;number of lines left to draw
  353.  
  354.     dc.l    0
  355. DataArea:
  356.     ds.b    40
  357.