home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 618a.lha / GoLD / GoLDSub.a < prev   
Text File  |  1992-02-02  |  14KB  |  433 lines

  1. ;****************************************************************************
  2. ;
  3. ; GoLDSub - Routinen für 'Game of Life - Duo'
  4. ;
  5. ;****************************************************************************
  6. ;
  7. ; void SetCell(bmap,x,y,col)
  8. ;
  9. ;   Sets the cell at coordinates (x,y) to the color 'col'.
  10. ;     Here x and y are not pixel-coordinates but 'cell-coordinates', i.e.
  11. ;   the position of the cell is at window position (4x,3y).
  12. ;     The BitMap is assumed to have 2 Planes and there is no check for
  13. ;   legal coordinate values.
  14. ;
  15. ;****************************************************************************
  16. ;
  17. ; void ScanAgar(Agar,AuxAgar,CellTrans,xsize,ysize,cs)
  18. ;
  19. ;   From 'Agar' the new types of the cells which change in the current
  20. ;   cycle are computed and stored in 'AuxAgar'.
  21. ;     'Agar' and 'AuxAgar' are character arrays of 'xsize' columns and
  22. ;   'ysize' lines. 'CellTrans' is an array with 'cs' columns and as many
  23. ;   lines as there are different types of cells. 'CellTrans[i][j]' contains
  24. ;   the type of the cell into which a cell of type i has to be changed when
  25. ;   the sum of the eight neighbouring cells yields j.
  26. ;
  27. ;****************************************************************************
  28. ;
  29. ; void ChangeAgar(bm,Agar,AuxAgar,xsize,ysize,xoffset,yoffset)
  30. ;
  31. ;   The new types of the cells which change in the current cycle are read
  32. ;   from 'AuxAgar' and used to update 'Agar' and the display.
  33. ;     (xoffset,yoffset) are the cell-coordinates of the upper left corner
  34. ;   of the output area in the BitMat 'bm'.
  35. ;
  36. ;****************************************************************************
  37. ;
  38. ; void DisplayAgar(bm,Agar,xsize,ysize,xoffset,yoffset)
  39. ;
  40. ;   The 'Agar' of size 'xsize' x 'ysize' is displayed in the BitMap 'bm' at
  41. ;   cell-coordinates (xoffset,yoffset).
  42. ;
  43. ;****************************************************************************
  44. ;
  45. ; void CountCells(Agar,BluSum,RedSum,Len)
  46. ;
  47. ;   The number of blue and red cells in 'Agar' (which is interpreted as a
  48. ;   character string of length 'Len + 1') is returned in '*BluSum' and
  49. ;   '*RedSum', resp.
  50. ;
  51. ;****************************************************************************
  52. ;
  53. ; Created by
  54. ;              Andreas Neubacher
  55. ;
  56. ;              Hausleitnerweg 26
  57. ;              4020 Linz
  58. ;              Austria
  59. ;
  60. ;              E-mail: aneubach@risc.uni-linz.ac.at (Internet)
  61. ;                       k318577@alijku11            (Bitnet)
  62. ;
  63. ;****************************************************************************
  64. ;
  65. ;  Copyright notice:
  66. ;  I don't claim any copyright and put this code into the public domain.
  67. ;
  68. ;****************************************************************************
  69. ;
  70. ; 92-01-19  AN : Finished release version
  71. ;
  72. ;****************************************************************************
  73.  
  74.  
  75.  section GoLDSub,code
  76.  
  77. ;****************************************************************************
  78.  
  79.  xdef _SetCell  ;         C entry : void SetCell(bmap, x, y, col);
  80.                 ;                     struct BitMap *bmap;
  81.                 ;                             short x,y,col;
  82.  xdef SetCell   ; Assembler entry :               A0   D0 D0 D1
  83.                 ;                                      hi lo
  84. _SetCell
  85.   movea.l   4(SP),A0
  86.   move.l    8(SP),D0
  87.   swap      D0
  88.   move.w    14(SP),D0
  89.   move.l    16(SP),D1
  90.  
  91. ; Register usage
  92. ;
  93. ; D0 ... x/y (hi-/lo-word), mask for nibble set/clear
  94. ; D1 ... col; offset for the byte, which contains the second line of the cell
  95. ; D2 ... offset for the byte, which contains the first line of the cell
  96. ; A0 ... pointer to the BitMap
  97. ; A1 ... pointer to the Bitplane
  98.  
  99. SetCell
  100.   move.l    D2,-(SP)
  101.   swap      D1
  102.   move.w    (A0),D1                 ; D1 := bmap->BytesPerRow
  103.   move.w    D1,D2
  104.   add.w     D2,D2
  105.   add.w     D1,D2                   ; D2 := 3 * bmap->BytesPerRow
  106.   mulu.w    D0,D2                   ;                             * y
  107.  
  108.   swap      D0
  109.   lsr.w     #1,D0
  110.   bcs       ELSE1                   ; IF x even THEN
  111.     add.w     D0,D2                 ;   D2 := D2 + x/2
  112.     move.l    #$008F0070,D0         ;   D0 := maske for high nibble
  113.     bra       ENDIF1
  114. ELSE1                               ; ELSE
  115.     add.w     D0,D2                 ;   D2 := D2 + x/2
  116.     move.l    #$00F80007,D0         ;   D0 := maske for low nibble
  117. ENDIF1                              ; ENDIF
  118.   add.w     D2,D1                   ; D1 := D2 + bmap->BytesPerRow
  119.  
  120.   movea.l   8(A0),A1                ; A1 points to first Bitplane
  121.   btst      #16,D1
  122.   beq       ELSE2                   ; IF col odd THEN
  123.     or.b      D0,(A1,D2.w)          ;   set cell
  124.     or.b      D0,(A1,D1.w)          ;   set cell
  125.     bra       ENDIF2
  126. ELSE2                               ; ELSE
  127.     swap      D0
  128.     and.b     D0,(A1,D2.w)          ;   clear cell
  129.     and.b     D0,(A1,D1.w)          ;   clear cell
  130.     swap      D0
  131. ENDIF2                              ; ENDIF
  132.  
  133.   movea.l   12(A0),A1               ; A1 points to second Bitplane
  134.   btst      #17,D1
  135.   beq       ELSE3                   ; IF col > 1 THEN
  136.     or.b      D0,(A1,D2.w)          ;   set cell
  137.     or.b      D0,(A1,D1.w)          ;   set cell
  138.     bra       ENDIF3
  139. ELSE3                               ; ELSE
  140.     swap      D0
  141.     and.b     D0,(A1,D2.w)          ;   clear cell
  142.     and.b     D0,(A1,D1.w)          ;   clear cell
  143. ENDIF3                              ; ENDIF
  144.  
  145.   move.l    (SP)+,D2
  146.   rts
  147.  
  148.  
  149. ;****************************************************************************
  150.  
  151.  
  152.  xdef _ScanAgar ;         C entry : void ScanAgar(a, aa, ct, xs, ys, cs);
  153.                 ;                      char *a,*aa,*ct;
  154.                 ;                     short xs,ys,cs;
  155.  xdef ScanAgar  ; Assembler entry :               A0 A1  A2  D0  D1  D2
  156.  
  157. _ScanAgar
  158.   movea.l   4(SP),A0
  159.   movea.l   8(SP),A1
  160.   movea.l   12(SP),A2
  161.   move.l    16(SP),D0
  162.   move.l    20(SP),D1
  163.   move.l    24(SP),D2
  164.  
  165. ; Register usage
  166. ;
  167. ; D0 ... 'xs'
  168. ; D1 ... 'ys', row counter
  169. ; D2 ... 'cs', sum of cell values
  170. ; D3 ... column counter
  171. ; A0 ... 'a'
  172. ; A1 ... 'aa'
  173. ; A2 ... 'ct'
  174. ; A3/A4 ... auxiliary pointers into 'a'
  175. ; A5/A6 ... pointers to second/third line of matrix 'ct'
  176.  
  177. ScanAgar
  178.   movem.l   D3/A3-A6,-(SP)
  179.  
  180.   movea.l   A0,A3
  181.   adda.w    D0,A3
  182.   movea.l   A3,A4
  183.   adda.w    D0,A4
  184.   adda.w    D0,A1
  185.   addq.l    #1,A1
  186.  
  187.   movea.l   A2,A5
  188.   adda.w    D2,A5
  189.   movea.l   A5,A6
  190.   adda.w    D2,A6
  191.  
  192.   moveq     #0,D2
  193.   subq.w    #3,D0                       ; xs := xs - 3
  194.   subq.w    #3,D1                       ; ys := ys - 3
  195. REPEAT1                                 ; REPEAT
  196.   move.w    D0,D3                       ;   D3 := xs
  197. REPEAT2                                 ;   REPEAT
  198.       move.b    (A0)+,D2                ;     D2 := sum over
  199.       add.b     (A0),D2                 ;           the eight
  200.       add.b     1(A0),D2                ;           neighbours
  201.       add.b     (A3)+,D2                ;           of the
  202.       add.b     1(A3),D2                ;           current
  203.       add.b     (A4)+,D2                ;           cell
  204.       add.b     (A4),D2                 ;
  205.       add.b     1(A4),D2                ;
  206.       btst      #0,(A3)
  207.       beq       ELSE4                   ;     IF current cell = 1 THEN
  208.         move.b    (A5,D2.w),(A1)+       ;       curr. aux. cell := ct[1][D2]
  209.         bra       ENDIF4
  210. ELSE4 btst      #1,(A3)
  211.       bne       ELSE5                   ;     ELSE IF current cell = 0 THEN
  212.         move.b    (A2,D2.w),(A1)+       ;       curr. aux. cell := ct[0][D2]
  213.         bra       ENDIF4
  214. ELSE5                                   ;     ELSE
  215.         move.b    (A6,D2.w),(A1)+       ;       curr. aux. cell := ct[2][D2]
  216. ENDIF4                                  ;     ENDIF
  217.     dbf       D3,REPEAT2                ;   UNTIL row finished
  218.     addq.l    #2,A0
  219.     addq.l    #2,A1                     ;   next
  220.     addq.l    #2,A3                     ;   row
  221.     addq.l    #2,A4
  222.   dbf       D1,REPEAT1                  ; UNTIL all rows finished
  223.  
  224.   movem.l   (SP)+,D3/A3-A6
  225.   rts
  226.  
  227.  
  228. ;****************************************************************************
  229.  
  230.  
  231.  xdef _ChangeAgar ;         C entry : void ChangeAgar(bm, a, aa, xs, ys, xo, yo);
  232.                   ;                     struct BitMap *bm;
  233.                   ;                              char *a,*aa;
  234.                   ;                             short xs,ys,xo,yo;
  235.  xdef ChangeAgar  ; Assembler entry :                 A0  A1 A2  D0  D1  D2  D2
  236.                   ;                                                      hi  lo
  237. _ChangeAgar
  238.   movea.l   4(SP),A0
  239.   movea.l   8(SP),A1
  240.   movea.l   12(SP),A2
  241.   move.l    16(SP),D0
  242.   move.l    20(SP),D1
  243.   move.l    24(SP),D2
  244.   swap      D2
  245.   move.w    30(SP),D2
  246.  
  247. ; Register usage
  248. ;
  249. ; D0 ... x/y (hi-/lo-word)
  250. ; D1 ... value of current cell; color
  251. ; D2 ... x-offset
  252. ; D3 ... column counter
  253. ; D4 ... row counter
  254. ; D5 ... 'xs'
  255. ; D6 ... y-offset
  256. ; A0 ... 'bm'
  257. ; A2 ... pointer to current cell in 'aa'
  258. ; A3 ... pointer to current cell in 'a'
  259.  
  260. ChangeAgar
  261.   movem.l   D2-D6/A3,-(SP)
  262.  
  263.   movea.l   A1,A3
  264.   add.w     D0,A2
  265.   addq.l    #1,A2
  266.   add.w     D0,A3
  267.   addq.l    #1,A3
  268.   subq.w    #3,D0
  269.   subq.w    #3,D1
  270.   move.w    D1,D4
  271.   move.w    D2,D6
  272.   add.w     D1,D6
  273.   swap      D2
  274.   add.w     D0,D2
  275.   move.w    D0,D5
  276.  
  277. REPEAT3                                 ; REPEAT
  278.     move.w    D5,D3
  279. REPEAT4                                 ;   REPEAT
  280.       move.b    (A2),D1                 ;     D1 := current cell in 'aa'
  281.       bne       ELSE6                   ;     IF D1 = 0 THEN
  282.         move.b    D1,(A3)               ;       current cell in 'a' := D1
  283.         moveq     #2,D1                 ;       color := 2
  284.         bra       ENDIF7                ;       GOTO ENDIF7
  285. ELSE6 cmp.b     #2,D1
  286.       bgt       ENDIF6                  ;     ELSE IF D1 < 3 THEN
  287.         beq       ELSE7                 ;       IF D1 = 1 THEN
  288.           move.b    D1,(A3)             ;         current cell in 'a' := D1
  289.           moveq     #0,D1               ;         color := 0
  290.         bra       ENDIF7                ;       ELSE
  291. ELSE7     move.b    D1,(A3)             ;         current cell in 'a' := D1
  292.           moveq     #1,D1               ;         color := 1
  293. ENDIF7                                  ;       ENDIF
  294.         move.w      D2,D0
  295.         sub.w       D3,D0
  296.         swap        D0
  297.         move.w      D6,D0
  298.         sub.w       D4,D0
  299.         jsr         SetCell             ;       SetCell(bm,D2-D3,D6-D4,color)
  300. ENDIF6                                  ;     ENDIF
  301.       addq.l      #1,A2                 ;     next
  302.       addq.l      #1,A3                 ;     cell
  303.     dbf         D3,REPEAT4              ;   UNTIL row finished
  304.     addq.l      #2,A2                   ;   next
  305.     addq.l      #2,A3                   ;   row
  306.   dbf         D4,REPEAT3                ; UNTIL all rows finished
  307.  
  308.   movem.l   (SP)+,D2-D6/A3
  309.   rts
  310.  
  311.  
  312. ;****************************************************************************
  313.  
  314.  
  315.  xdef _DisplayAgar  ;         C entry : void DisplayAgar(bm, a, xs, ys, xo, yo);
  316.                     ;                     struct BitMap *bm;
  317.                     ;                              char *a;
  318.                     ;                             short xs,ys,xo,yo;
  319.  xdef DisplayAgar   ; Assembler entry :                  A0  A2 D0  D1  D2  D2
  320.                     ;                                                   hi lo
  321. _DisplayAgar
  322.   movea.l   4(SP),A0
  323.   movea.l   8(SP),A2
  324.   move.l    12(SP),D0
  325.   move.l    16(SP),D1
  326.   move.l    20(SP),D2
  327.   swap      D2
  328.   move.w    26(SP),D2
  329.  
  330. ; Register usage
  331. ;
  332. ; D0 ... x/y (hi-/lo-word)
  333. ; D1 ... value of current cell; color
  334. ; D2 ... x-offset
  335. ; D3 ... y-offset
  336. ; D4 ... 'xs'
  337. ; D5 ... column counter
  338. ; D6 ... line counter
  339. ; A0 ... 'bm'
  340. ; A2 ... pointer to current cell in 'a'
  341.  
  342. DisplayAgar
  343.   movem.l   D3-D6,-(SP)
  344.  
  345.   add.w     D0,A2
  346.   addq.l    #1,A2
  347.   subq.w    #3,D0
  348.   subq.w    #3,D1
  349.   move.w    D1,D3
  350.   add.w     D2,D3
  351.   move.w    D1,D6
  352.   swap      D2
  353.   add.w     D0,D2
  354.   move.w    D0,D4
  355.  
  356. REPEAT5                                 ; REPEAT
  357.     move.w    D4,D5
  358. REPEAT6                                 ;   REPEAT
  359.       move.b    (A2)+,D1                ;     D1 := current cell in 'a'
  360.       bne       ELSE8                   ;     IF D1 = 0 THEN
  361.         moveq     #2,D1                 ;       color := 2
  362.         bra       ENDIF8                ;
  363. ELSE8 btst      #0,D1
  364.       beq       ELSE9                   ;     ELSE IF D1 = 1 THEN
  365.         moveq     #0,D1                 ;       color := 0
  366.         bra       ENDIF8                ;     ELSE
  367. ELSE9   moveq     #1,D1                 ;       color := 1
  368. ENDIF8                                  ;     ENDIF
  369.       move.w      D2,D0
  370.       sub.w       D5,D0
  371.       swap        D0
  372.       move.w      D3,D0
  373.       sub.w       D6,D0
  374.       jsr         SetCell               ;     SetCell(bm,D2-D5,D3-D6,color)
  375.     dbf         D5,REPEAT6              ;   UNTIL row finished
  376.     addq.l      #2,A2                   ;   next row
  377.   dbf         D6,REPEAT5                ; UNTIL all rows finished
  378.  
  379.   movem.l   (SP)+,D3-D6
  380.   rts
  381.  
  382.  
  383. ;****************************************************************************
  384.  
  385.  
  386.  xdef _CountCells ;         C entry : void CountCells(a, bluc, redc, len);
  387.                   ;                              char *a;
  388.                   ;                             short *redc,*bluc;
  389.                   ;                     unsigned short len;
  390.  xdef CountCells  ; Assembler entry :                 A0 A1    A2    D0
  391.  
  392. _CountCells
  393.   movea.l   4(SP),A0
  394.   movea.l   8(SP),A1
  395.   movea.l   12(SP),A2
  396.   move.l    16(SP),D0
  397.  
  398. ; Register usage
  399. ;
  400. ; D0 ... cell counter
  401. ; D1 ... counter for blue cells
  402. ; D2 ... counter for red cells
  403. ; D3 ... current cell
  404. ; A0 ... pointer to current cell
  405. ; A1 ... 'bluc'
  406. ; A2 ... 'redc'
  407.  
  408. CountCells
  409.   movem.l   D2/D3,-(SP)
  410.  
  411.   moveq.l   #0,D1
  412.   move.l    D1,D2
  413. REPEAT7                                 ; REPEAT
  414.     move.b    (A0)+,D3                  ;   get current cell
  415.     bne       ELSE10                    ;   IF cell = 0 THEN
  416.       addq.w    #1,D1                   ;     blue cell
  417.       bra       ENDIF10
  418. ELSE10
  419.     btst      #0,D3
  420.     bne       ENDIF10                   ;   ELSE IF cell = 2 THEN
  421.       addq.w    #1,D2                   ;     red cell
  422. ENDIF10                                 ;   ENDIF
  423.   dbf       D0,REPEAT7                  ; UNTIL all cells finished
  424.  
  425.   move.w    D1,(A1)
  426.   move.w    D2,(A2)
  427.  
  428.   movem.l   (SP)+,D2/D3
  429.   rts
  430.  
  431.  END
  432.  
  433.