home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 616.lha / Tapete / LoadBody.asm < prev    next >
Assembly Source File  |  1992-03-03  |  7KB  |  198 lines

  1. ;----------------------------------------------------------------------------
  2. ;    :Program.    LoadBody.asm
  3. ;    :Author.     Fridtjof Siebert
  4. ;    :Address.    Nobileweg 67, D-7-Stgt-40
  5. ;    :Phone.      0711/822509
  6. ;    :Shortcut.   [fbs]
  7. ;    :Version.    .01
  8. ;    :Date.       06-Jun-88
  9. ;    :Copyright.  PD
  10. ;    :Language.   68000-Assembler
  11. ;    :Translator. Profimat.
  12. ;    :Imports.    none.
  13. ;    :UpDate.     none.
  14. ;    :Contents.   Prozedur zum Laden des BODYs eines gepackten ILBM-Bildes.
  15. ;    :Remark.     There is some MODULA on the right to improve clearity.
  16. ;----------------------------------------------------------------------------
  17. ;
  18. ; PROCEDURE LoadBody(GetData: PROC; Buffer,BitMapPtrs: ADDRESS; LineLength,
  19. ;                    LineWidth: LONGINT; Height,Depth: INTEGER;
  20. ;                    ExtraPlane: BOOLEAN);
  21. ;
  22. ;
  23. ;------  Exported Procedure: ------
  24. ;
  25.   XDEF LoadBody
  26. ;
  27. ;------  Values from caller:  ------
  28. ;
  29. GetData    equr A2;
  30. Buffer     equr A3;
  31. BitMapPtrs equr A4;
  32. LineLength equr D2;
  33. LineWidth  equr D3;
  34. Height     equr D5;
  35. Depth      equr D4;
  36. ExtraPlane equr D6;
  37. ;
  38. ;------  Variables:  ------
  39. ;
  40. Line       equr D5;
  41. Plane      equr D6;
  42. Byte       equr D7;
  43. Location   equr A1;
  44. Right      equr A6;
  45. ;
  46. Scratch    equr D0;
  47. count      equr D1;
  48.  
  49. Extra      = 0;
  50. AnzLines   = 2;
  51. ;
  52. ;----------------------------------------------------------------------------
  53.  
  54. LoadBody:
  55.  
  56. ;
  57. ;------  Save some data (there aren't enough Registers):  ------
  58. ;
  59.   subq    #4,A7
  60.   move.w  ExtraPlane,Extra(A7);
  61.   move.w  Height,AnzLines(A7);
  62. ;
  63. ;------  Get Data from File (512 Bytes):  ------
  64. ;
  65.   movem.l D2-D7/A1-A6,-(sp);
  66.   jsr     (GetData);                       GetData();
  67.   movem.l (sp)+,D2-D7/A1-A6;
  68.   move    #0,count;                        count := 0;
  69. ;
  70. ;------  Initialize Loop for Lines:  ------
  71. ;
  72.   move    #0,Line;                         Line := 0;
  73. ;
  74. LineLoop: ;                                REPEAT
  75. ;
  76. ;-------  Initialize Loop for Planes:  ------
  77. ;
  78.   move    #0,Plane;                          Plane := 0;
  79. ;
  80. PlaneLoop: ;                                 REPEAT
  81. ;
  82. ;------  Calculate Position within Image:  ------
  83. ;
  84.     move    LineWidth,Scratch;
  85.     mulu    Line,Scratch;
  86.     move.l  Scratch,Location;
  87.     asl     #2,Plane;
  88.     add.l   0(BitMapPtrs,Plane),Location;      Location := BitMapPtrs^[Plane];
  89.     asr     #2,Plane;
  90. ;
  91. ;------  Calculate Position after the Plane-Loop:  ------
  92. ;
  93.     move.l  Location,Right;
  94.     add.l   LineLength,Right;                  Right := Location + LineLength;
  95. ;
  96. ;------  Let's read the data:  ------
  97. ;
  98. ReadRepeat: ;                                  REPEAT
  99. ;
  100. ;------  Get 1 Byte and check it:  ------
  101. ;
  102.       bsr     GetByte;                           Scratch := GetByte();
  103.       cmp.b   #128,Scratch;
  104.       bhi.s   RepeatNext;
  105.       beq.s   DoRien;                            IF Scratch<128 THEN
  106. ;
  107. ;------  Get Next Scratch+1 Bytes Liberately:  ------
  108. ;
  109.       move.b  Scratch,Byte;                        Byte := Scratch;
  110. GetMany: ;                                           REPEAT
  111.         bsr     GetByte;                             Scratch := GetByte();
  112.         move.b  Scratch,(Location);                  Location^ := Scratch;
  113.         addq.l  #1,Location;                         INC(Location)
  114.         subq.b  #1,Byte;                             DEC(Byte);
  115.         bpl.s   GetMany;                           UNTIL Byte<0;
  116.         bra.s   DoRien;
  117. ;
  118. ;------  Get Next Byte and Repeat it 257-Scratch times:  ------
  119. ;
  120. RepeatNext: ;                                    ELSIF Scratch>128 THEN
  121.       move.b  Scratch,Byte;                        Byte := Scratch;
  122.       bsr     GetByte;                             Scratch := GetByte();
  123. RepeatIt: ;                                        REPEAT;
  124.         move.b  Scratch,(Location);                  Location^ := Scratch;
  125.         addq.l  #1,Location;                         INC(Location);
  126.         addq.b  #1,Byte;                             INC(Byte);
  127.         cmp.b   #1,Byte;                           UNTIL Byte=1;
  128.         bne.s   RepeatIt;                        END;
  129. ;
  130. ;------  Compare new Location with first of next Line:  ------
  131. ;
  132. DoRien:
  133.       cmp.l   Location,Right;                  UNTIL Location>=Right;
  134.       bhi.s   ReadRepeat;
  135. ;
  136. ;------  Increament Plane and repeat Loop:  ------
  137. ;
  138.     addq    #1,Plane;                          INC(Plane);
  139.     cmp     Depth,Plane;                     UNTIL Pland>=Depth;
  140.     blt.s   PlaneLoop;
  141. ;
  142. ;------  Get Extra-Plane if exists:  ------
  143. ;
  144.     tst     Extra(A7);
  145.     beq.s   NoExtraPlane;                    IF ExtraPlane THEN
  146. ; next lines are equal to them above, but the data isn't saved:
  147.     move.l  #0,Location;                       Location := NIL;
  148. ExReadRepeat: ;                                REPEAT
  149.       bsr     GetByte;                           Scratch := GetByte();
  150.       cmp.b   #128,Scratch;
  151.       bhi.s   ExRepeatNext;
  152.       beq.s   ExDoRien;                          IF Scratch<128 THEN
  153.       move.b  Scratch,Byte;                        Byte := Scratch;
  154. ExGetMany: ;                                       REPEAT
  155.         bsr     GetByte;                             Scratch := GetByte();
  156.         addq.l  #1,Location;                         INC(Location)
  157.         subq.b  #1,Byte;                             DEC(Byte);
  158.         bpl.s   ExGetMany;                         UNTIL Byte<0;
  159.         bra.s   ExDoRien;
  160. ExRepeatNext: ;                                  ELSIF Scratch>128 THEN
  161.       move.b  Scratch,Byte;                        Byte := Scratch;
  162.       bsr     GetByte;                             Scratch := GetByte();
  163. ExRepeatIt: ;
  164.         add.l   #257,Location;                     INC(Location,257);
  165.         and.l   #$FF,Byte
  166.         sub.l   Byte,Location;                     DEC(Location,Byte);
  167. ExDoRien:
  168.       cmp.l   Location,LineLength;
  169.       bhi.s   ExReadRepeat;                    UNTIL Location>=LineLength;
  170. NoExtraPlane: ;                              END;
  171. ;
  172. ;------  Increament Line and repeat Loop:  ------
  173. ;
  174.   addq    #1,Line;                           INC(Line);
  175.   cmp     AnzLines(A7),Line;                 UNTIL AnzLines>=Line
  176.   blt     LineLoop;
  177. ;
  178. ;------  That's it:  ------
  179. ;
  180.   addq    #4,A7;
  181.   rts;
  182. ;
  183. ;-------  Read one Byte:  ------
  184. ;                                        PROCEDURE GetByte();
  185. GetByte: ;                               BEGIN
  186.   move.b  0(Buffer,count),Scratch;         Scratch := Buffer^[count];
  187.   addq.w  #1,count;                        INC(count);
  188.   cmp.w   #512,count;
  189.   blt.s   BufferNotEmpty;                  IF count>=512 THEN
  190.   movem.l   D0-D7/A1-A6,-(sp);               PUSH(all);
  191.   jsr     (GetData);                         GetData();
  192.   movem.l   (sp)+,D0-D7/A1-A6;               PULL(all);
  193.   clr     count;                             count := 0;
  194. BufferNotEmpty: ;                          END;
  195.   rts;                                   END GetByte;
  196.  
  197.   end
  198.