home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / a68kex_431.lzh / A68Kex / evil.asm < prev    next >
Assembly Source File  |  1991-01-17  |  16KB  |  636 lines

  1. ************************************************************************
  2. *                                                                      *
  3. * These are prime number maps                                          *
  4. *                                                                      *
  5. * This implementation was written by:                                  *
  6. * E. Lenz                                                              *
  7. * Johann-Fichte-Strasse 11                                             *
  8. * 8 Munich 40                                                          *
  9. * Germany                                                              *
  10. *                                                                      *
  11. ************************************************************************
  12.  
  13. ; d0 Number counter
  14. ; d1
  15. ; d2 flag if prime
  16. ; d3 colour counter
  17. ; d4 x coordinate
  18. ; d5 y coordinate
  19. ; d6 pointer to buffer
  20. ; d7 menu stuff
  21. ; a0
  22. ; a1
  23. ; a2
  24. ; a3 GfxBase
  25. ; a4 pointer to buffer
  26. ; a5 rast port
  27.  
  28. _AbsExecBase        equ 4
  29.  
  30. **** exec *****
  31.  
  32. _LVOForbid       equ -$84
  33. _LVOPermit       equ -$8a
  34. _LVOAllocMem     equ -$c6
  35. _LVOFreeMem      equ -$d2
  36. _LVOGetMsg       equ -$174
  37. _LVOReplyMsg     equ -$17a
  38. _LVOWaitPort     equ -$180
  39. _LVOCloseLibrary equ -$19e
  40. _LVOOpenLibrary  equ -$228
  41.  
  42. **** intuition ******
  43.  
  44. _LVOCloseScreen    equ -$42
  45. _LVOCloseWindow    equ -$48
  46. _LVOOpenScreen     equ -$c6
  47. _LVOOpenWindow     equ -$cc
  48. _LVOSetMenuStrip   equ -$108
  49.  
  50. ***** graphics ******
  51.  
  52. _LVOText           equ -$3c
  53. _LVOLoadRGB4       equ -$c0
  54. _LVOMove           equ -$f0
  55. _LVODraw           equ -$f6
  56. _LVORectFill       equ -$132
  57. _LVOSetAPen        equ -$156
  58. _LVOScrollRaster   equ -$18c
  59.  
  60. wd_Width         equ 8
  61. wd_Height        equ $a
  62. sc_ViewPort      equ $2c
  63. wd_RPort         equ $32
  64. wd_UserPort      equ $56
  65. pr_MsgPort       equ $5c
  66. pr_CLI           equ $ac
  67. ThisTask         equ $114
  68. VBlankFrequency  equ $212
  69.  
  70.        movea.l _AbsExecBase,a6   test if WB or CLI
  71.        movea.l ThisTask(a6),a0
  72.        tst.l   pr_CLI(a0)
  73.        bne.s   isCLI
  74.  
  75.        lea     pr_MsgPort(a0),a0 for WB get WB Message
  76.        jsr     _LVOWaitPort(a6)
  77.        jsr     _LVOGetMsg(a6)
  78.        move.l  d0,WBenchMsg
  79.  
  80. isCLI  cmpi.b  #60,VBlankFrequency(a6) test if PAL or NTSC
  81.        beq.s   isNTSC
  82.        move.w  #256,nw+6
  83.        move.w  #256,ns+6
  84.  
  85. isNTSC move.l  #$6700,d0         allocate buffer
  86.        move.l  #$30000,d1        largest + clear
  87.        jsr     _LVOAllocMem(a6)
  88.        move.l  d0,d6
  89.        beq.s   Gexit
  90.  
  91.        lea     GfxName(pc),a1        open graphics library
  92.        moveq   #0,d0
  93.        jsr     _LVOOpenLibrary(a6)
  94.        movea.l d0,a3
  95.        tst.l   d0
  96.        beq.s   Gexit
  97.  
  98.        lea     IntName(pc),a1        open intuition library
  99.        moveq   #0,d0
  100.        jsr     _LVOOpenLibrary(a6)
  101.        move.l  d0,IntBase
  102. Gexit  beq     exit
  103.  
  104.        lea     ns(pc),a0              open screen
  105.        movea.l d0,a6
  106.        jsr     _LVOOpenScreen(a6)
  107.        move.l  d0,screen
  108.        beq.s   Gexit
  109.        move.l  d0,nws
  110.        move.l  d0,d2
  111.  
  112.        lea     nw(pc),a0             open window
  113.        jsr     _LVOOpenWindow(a6)
  114.        move.l  d0,window
  115.        beq.s   Gexit
  116.  
  117. ; Set menu
  118.  
  119.        movea.l d0,a0           which window
  120.        lea     Menu1(pc),a1    which menu
  121.        jsr     _LVOSetMenuStrip(a6)
  122.  
  123.        movea.l window(pc),a0
  124.        movea.l wd_RPort(a0),a5
  125.  
  126.        movea.l d2,a0
  127.        lea     sc_ViewPort(a0),a0
  128.  
  129.        lea     ColourTable(pc),a1
  130.        moveq   #16,d0
  131.        movea.l a3,a6
  132.        jsr     _LVOLoadRGB4(a6)
  133.  
  134. ** start off with the prime number 3 ***
  135.  
  136. rest   movea.l d6,a4
  137.        moveq   #3,d0
  138.        move.l  d0,(a4)+
  139.        moveq   #1,d2
  140. redraw movem.l d0/d2,-(a7)
  141.  
  142.        movea.l a3,a6  clear screen
  143.        moveq   #0,d0
  144.        movea.l a5,a1
  145.        jsr     _LVOSetAPen(a6)
  146.  
  147.        movea.l a5,a1
  148.        moveq   #0,d0
  149.        moveq   #0,d1
  150.        move.l  #640,d2
  151.        move.l  #250,d3
  152.        jsr     _LVORectFill(a6)
  153.  
  154.        movea.l a5,a1
  155.        moveq   #1,d0
  156.        jsr     _LVOSetAPen(a6)
  157.  
  158.        moveq   #0,d4       set x position to 0
  159.        moveq   #0,d5
  160.        moveq   #0,d3
  161.        clr.w   fin
  162.  
  163. draw   tst.w   fin
  164.        bne.s   wait
  165.        movem.l (a7)+,d0/d2
  166.        bsr     func
  167.        movem.l d0/d2,-(a7)
  168.        tst.l   d0
  169.        beq.s   exit1
  170.  
  171. wait   bsr     trycls
  172.        beq.s   draw
  173.        cmpi.l  #$200,d7
  174.        beq.s   exit1
  175.  
  176.        cmpi.l  #$100,d7
  177.        bne.s   wait
  178.  
  179. ; Choice from menu
  180.  
  181.        movea.l window(pc),a0
  182.        movea.l $5e(a0),a0   Load Window.MessageKey
  183.        move.w  $18(a0),d0   Load message code
  184.        move.w  d0,d1
  185.        andi.w  #$f,d1
  186.        bne.s   ismen2
  187.  
  188.        andi.w  #$f0,d0      Menu 1
  189.        bne.s   menu12       Submenu 1
  190.        move.w  #ShowPr-addr,addr
  191. Gdraw  movem.l (a7)+,d0/d2
  192.        bra     rest
  193.  
  194. menu12 cmpi.w  #$20,d0      Submenu 2
  195.        bne.s   menu13
  196.        move.w  #print-addr,addr
  197.        bra.s   Gdraw
  198.  
  199. menu13 cmpi.w  #$40,d0      Submenu 2
  200.        bne.s   wait
  201.        move.w  #diff-addr,addr
  202.        bra.s   Gdraw
  203.  
  204.  
  205. ismen2 cmpi.w  #1,d1
  206.        bne.s   wait
  207.        andi.w  #$f0,d0      Menu 2
  208.        bne.s   wait
  209.        movem.l (a7)+,d0/d2
  210.        bra     redraw
  211.  
  212. exit1  movem.l (a7)+,d0/d2
  213.  
  214. exit   movea.l IntBase(pc),a6
  215.        move.l  window(pc),d0
  216.        beq.s   noWin
  217.        movea.l d0,a0
  218.        jsr     _LVOCloseWindow(a6)    close window
  219.  
  220. noWin  move.l  screen(pc),d0         close screen
  221.        beq.s   noScr
  222.        movea.l d0,a0
  223.        jsr     _LVOCloseScreen(a6)
  224.  
  225. noScr  movea.l _AbsExecBase,a6
  226.        tst.l   WBenchMsg
  227.        beq.s   free
  228.        jsr     _LVOForbid(a6)       reply to WB
  229.        movea.l WBenchMsg(pc),a1
  230.        jsr     _LVOReplyMsg(a6)
  231.        jsr     _LVOPermit(a6)
  232.  
  233. free   tst.l   d6                free buffer
  234.        beq.s   NoBenh
  235.        movea.l d6,a1
  236.        move.l  #$6700,d0
  237.        jsr     _LVOFreeMem(a6)
  238.  
  239. NoBenh move.l  IntBase(pc),d1       close intuition library
  240.        beq.s   noInt
  241.        movea.l d1,a1
  242.        jsr     _LVOCloseLibrary(a6)
  243.  
  244. noInt  move.l  a3,d1                close graphics library
  245.        beq.s   noGfx
  246.        movea.l d1,a1
  247.        jsr     _LVOCloseLibrary(a6)
  248.  
  249. noGfx  moveq   #0,d0                no error
  250.        rts
  251.  
  252. trycls movem.l d0-d6/a0-a6,-(a7)
  253.        movea.l _AbsExecBase,a6
  254.        moveq   #0,d7
  255.        movea.l window(pc),a0
  256.        movea.l wd_UserPort(a0),a0  load Window.UserPort
  257.        jsr     _LVOGetMsg(a6)
  258.        tst.l   d0
  259.        beq.s   noMsg1         No message
  260.  
  261.        movea.l d0,a1
  262.        move.l  $14(a1),d7       Message in d7
  263.  
  264. noMsg1 movem.l (a7)+,d0-d6/a0-a6
  265. noMsg  tst.l   d7
  266.        rts
  267.  
  268. ********************************************
  269. *                                          *
  270. * Write number in d0 as decimal to console *
  271. *                                          *
  272. ********************************************
  273.  
  274.  
  275. ShowPr movem.l d0-d3/a0-a1,-(a7)
  276.        move.l  d0,-(a7)
  277.        movea.l a3,a6
  278.  
  279.        addq.l  #8,d5
  280.        move.l  d5,d0
  281.        addq.l  #8,d0
  282.        movea.l window(pc),a0
  283.        cmp.w   wd_Height(a0),d0
  284.        bcs.s   isok
  285.        subq.l  #8,d5
  286.        move.l  d5,-(a7)
  287.        movea.l a5,a1
  288.        moveq   #0,d0
  289.        moveq   #8,d1
  290.        moveq   #0,d2
  291.        moveq   #0,d3
  292.        moveq   #60,d4
  293.        move.w  wd_Height(a0),d5
  294.        jsr     _LVOScrollRaster(a6)
  295.        move.l  (a7)+,d5
  296.  
  297. isok   moveq   #0,d0
  298.        move.l  d5,d1
  299.        movea.l a5,a1
  300.        jsr     _LVOMove(a6)
  301.  
  302.        move.l  (a7)+,d0
  303.        lea     Prime(pc),a1
  304.        movea.l a1,a0
  305.        move.l  #'0000',d1
  306.        move.l  d1,(a1)+
  307.        move.l  d1,(a1)+
  308.        move.l  d1,(a1)+
  309.        lea     Num(pc),a1
  310. plop   move.l  (a1)+,d1
  311.        addq.l  #1,a0
  312. pnext  cmp.l   d1,d0
  313.        bcs.s   plop
  314.        sub.l   d1,d0
  315.        addq.b  #1,(a0)
  316.        tst.l   d0
  317.        bne.s   pnext
  318.        lea     Prime(pc),a0
  319.        moveq   #11,d0
  320. ptest  cmpi.b  #'0',(a0)
  321.        bne.s   endp
  322.        subq.l  #1,d0
  323.        addq.l  #1,a0
  324.        bra.s   ptest
  325. endp   movea.l a5,a1
  326.        jsr     _LVOText(a6)
  327.        movem.l (a7)+,d0-d3/a0-a1
  328. next   bsr.s   NextPr
  329.        tst.l   d2
  330.        beq.s   next
  331.        rts
  332.  
  333. ********************************
  334. *
  335. * advance one graphic point
  336. *
  337. ********************************
  338.  
  339. advan  move.l  d0,-(a7)
  340.        movea.l a3,a6
  341.        move.l  d4,d0
  342.        move.l  d5,d1
  343.        movea.l a5,a1
  344.        jsr     _LVOMove(a6)
  345.  
  346.        move.l  d3,d0
  347.        movea.l a5,a1
  348.        jsr     _LVOSetAPen(a6)
  349.  
  350.        move.l  d4,d0
  351.        move.l  d5,d1
  352.        movea.l a5,a1
  353.        jsr     _LVODraw(a6)
  354.  
  355.        addq.l  #1,d4
  356.        move.l  d4,d0
  357.        addi.w  #20,d0
  358.        move.l  window(pc),a0
  359.        cmp.w   wd_Width(a0),d0
  360.        bne.s   nolin
  361.        moveq   #0,d4
  362.        addq.l  #1,d5
  363.        cmp.w   wd_Height(a0),d5
  364.        bne.s   nolin
  365.        move.w  #1,fin
  366.  
  367. nolin  move.l  (a7)+,d0
  368.        rts
  369.  
  370. **********************************
  371. *                                *
  372. * print map of prime differences *
  373. *                                *
  374. **********************************
  375.  
  376. diff   bsr.s   advan
  377.  
  378.        moveq   #0,d3
  379. knot   bsr.s   NextPr
  380.        tst.l   d2
  381.        bne.s   found
  382.        addq.l  #1,d3
  383.        bra.s   knot
  384.  
  385. found  rts
  386.  
  387. ***********************
  388. *                     *
  389. * print map of primes *
  390. *                     *
  391. ***********************
  392.  
  393. print  moveq   #3,d3
  394.        tst.l   d2
  395.        bne.s   isPrim
  396.        moveq   #0,d3
  397. isPrim bsr.s   advan
  398.  
  399. ******************************************
  400. *                                        *
  401. * Calculate next prime number            *
  402. *                                        *
  403. ******************************************
  404.  
  405. NextPr move.l  d6,a0
  406.        addq.l  #2,d0
  407.        bcs.s   eprim
  408. nlop   move.l  (a0)+,d2
  409.        beq.s   isPr
  410.        move.l  d2,d1
  411.        mulu    d2,d1
  412.        cmp.l   d1,d0
  413.        bcs.s   isPr
  414.        bsr.s   mod
  415.        tst.l   d2
  416.        beq.s   nosave        no prime - try next number
  417.        bra.s   nlop          try next divisor
  418. isPr   move.l  d0,d1
  419.        swap    d1
  420.        tst.w   d1
  421.        bne.s   nosave
  422.        move.l  d0,(a4)+
  423. nosave rts
  424. eprim  moveq   #0,d0
  425.        rts
  426.  
  427. **************************
  428. *                        *
  429. * return d0 mod d2 in d2 *
  430. *                        *
  431. **************************
  432.  
  433. mod    move.l  d0,-(a7)
  434.        lea     pow(pc),a1
  435.        moveq   #9,d1
  436. mlop   move.l  d2,(a1)+
  437.        add.l   d2,d2
  438.        dbra    d1,mlop
  439. mnext  move.l  -(a1),d1
  440.        beq.s   mend
  441. mwhat  cmp.l   d1,d0
  442.        bcs.s   mnext
  443.        sub.l   d1,d0
  444.        beq.s   mend
  445.        bra.s   mwhat
  446. mend   move.l  d0,d2
  447.        move.l  (a7)+,d0
  448.        rts
  449.  
  450. func   dc.w    $6000
  451. addr   dc.w    print-*
  452.  
  453. fin         ds.w 1
  454. WBenchMsg   dc.l 0
  455. DosBase     dc.l 0
  456. IntBase     dc.l 0
  457. window      dc.l 0
  458. screen      dc.l 0
  459.  
  460. ColourTable dc.w $15a,$fff,$000,$e83
  461.             dc.w $069,$087,$0a5,$0c3
  462.             dc.w $0f0,$2d0,$4b0,$690
  463.             dc.w $870,$a50,$c30,$f00
  464.  
  465. Num       dc.l 1000000000,100000000,10000000,1000000,100000,10000,1000,100,10,1
  466. Prime     ds.b 12
  467.  
  468.           dc.l 0
  469. pow       ds.l 1
  470.  
  471. DosName     dc.b 'dos.library',0
  472. GfxName     dc.b 'graphics.library',0
  473. IntName     dc.b 'intuition.library',0
  474.             even
  475.  
  476. title1      dc.b 'Screen',0
  477.             even
  478.  
  479. **** screen definition ****
  480.  
  481. ns          dc.w  0,0
  482.             dc.w  640,199,4
  483.             dc.b  0,1
  484.             dc.w  $8000
  485.             dc.w  $f
  486.             dc.l  0
  487.             dc.l  title1
  488.             dc.l  0
  489.             dc.l  0
  490.  
  491. title       dc.b  'Prime evil & all that jazz',0
  492.             even
  493.  
  494. ***** Window definition *****
  495.  
  496. nw          dc.w 0,0           ;Position left,top
  497.             dc.w 640,199       ;Size width,height
  498.             dc.b 0,1           ;Colors detail-,block pen
  499.             dc.l $344          ;IDCMP-Flags
  500.             dc.l $144f         ;Window flags
  501.             dc.l 0             ;^Gadget
  502.             dc.l 0             ;^Menu check
  503.             dc.l title         ;^Window name
  504. nws         dc.l 0             ;^Screen structure,
  505.             dc.l 0             ;^BitMap
  506.             dc.w 10            ;MinWidth
  507.             dc.w 10            ;MinHeight
  508.             dc.w -1            ;MaxWidth
  509.             dc.w -1,$f         ;MaxHeight,Screen type
  510.  
  511. **** menu definition ****
  512.  
  513. Menu1       dc.l Menu2       Next menu
  514.             dc.w 50,0        Position left edge,top edge
  515.             dc.w 100,20      Dimensions width,height
  516.             dc.w 1           Menu enabled
  517.             dc.l mtext1      Text for menu header
  518.             dc.l item11      ^First in chain
  519.             dc.l 0,0         Internal
  520.  
  521. mtext1      dc.b 'mode',0
  522.             even
  523.  
  524. item11      dc.l item12      next in chained list
  525.             dc.w 0,0         Position left edge,top edge
  526.             dc.w 170,10      Dimensions width,height
  527.             dc.w $53         itemtext+highcomp+itemenabled+checkit
  528.             dc.l $e          Mutual exclude
  529.             dc.l I11txt      Pointer to intuition text
  530.             dc.l 0
  531.             dc.b 0,0
  532.             dc.l 0
  533.             dc.w 0
  534.  
  535.  
  536. I11txt      dc.b 0           Front pen  (blue)
  537.             dc.b 1           Back pen   (white)
  538.             dc.b 0,0         Draw mode
  539.             dc.w 0           Left edge
  540.             dc.w 0           Top edge
  541.             dc.l 0           Text font
  542.             dc.l item11txt   Pointer to text
  543.             dc.l 0           Next text
  544.  
  545. item11txt   dc.b '   Numbers',0
  546.             even
  547.  
  548. item12      dc.l item13      next in chained list
  549.             dc.w 0,10        Position left edge,top edge
  550.             dc.w 170,10      Dimensions width,height
  551.             dc.w $153        itemtext+highcomp+itemenabled+checkit+checked
  552.             dc.l $d          Mutual exclude
  553.             dc.l I12txt      Pointer to intuition text
  554.             dc.l 0
  555.             dc.b 0,0
  556.             dc.l 0
  557.             dc.w 0
  558.  
  559.  
  560. I12txt      dc.b 0           Front pen  (blue)
  561.             dc.b 1           Back pen   (white)
  562.             dc.b 0,0         Draw mode
  563.             dc.w 0           Left edge
  564.             dc.w 0           Top edge
  565.             dc.l 0           Text font
  566.             dc.l item12txt   Pointer to text
  567.             dc.l 0           Next text
  568.  
  569. item12txt   dc.b '   Map',0
  570.             even
  571.  
  572. item13      dc.l 0           next in chained list
  573.             dc.w 0,20        Position left edge,top edge
  574.             dc.w 170,10      Dimensions width,height
  575.             dc.w $53         itemtext+highcomp+itemenabled+checkit
  576.             dc.l $b          Mutual exclude
  577.             dc.l I13txt      Pointer to intuition text
  578.             dc.l 0
  579.             dc.b 0,0
  580.             dc.l 0
  581.             dc.w 0
  582.  
  583.  
  584. I13txt      dc.b 0           Front pen  (blue)
  585.             dc.b 1           Back pen   (white)
  586.             dc.b 0,0         Draw mode
  587.             dc.w 0           Left edge
  588.             dc.w 0           Top edge
  589.             dc.l 0           Text font
  590.             dc.l item13txt   Pointer to text
  591.             dc.l 0           Next text
  592.  
  593. item13txt   dc.b '   Differences',0
  594.             even
  595.  
  596. ***** 2nd menu definition *****
  597.  
  598. Menu2       dc.l 0           Next menu
  599.             dc.w 150,0       Position left edge,top edge
  600.             dc.w 120,20      Dimensions width,height
  601.             dc.w 1           Menu enabled
  602.             dc.l mtext2      Text for menu header
  603.             dc.l item21      ^First in chain
  604.             dc.l 0,0         Internal
  605.  
  606. mtext2      dc.b 'redraw',0
  607.             even
  608.  
  609.  
  610. item21      dc.l 0           next in chained list
  611.             dc.w 0,0         Position left edge,top edge
  612.             dc.w 120,10      Dimensions width,height
  613.             dc.w $52         itemtext+highcomp+itemenabled
  614.             dc.l 0           Mutual exclude
  615.             dc.l I21txt      Pointer to intuition text
  616.             dc.l 0
  617.             dc.b 0,0
  618.             dc.l 0
  619.             dc.w 0
  620.  
  621.  
  622. I21txt      dc.b 0           Front pen  (blue)
  623.             dc.b 1           Back pen   (white)
  624.             dc.b 0,0         Draw mode
  625.             dc.w 0           Left edge
  626.             dc.w 0           Top edge
  627.             dc.l 0           Text font
  628.             dc.l item21txt   Pointer to text
  629.             dc.l 0           Next text
  630.  
  631. item21txt   dc.b 'next page',0
  632.             even
  633.  
  634.             end
  635.  
  636.