home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / graphics / degadesk / desktop1.c < prev    next >
C/C++ Source or Header  |  1989-10-11  |  14KB  |  419 lines

  1. ; **************************************************************************
  2. ; This is the source of DESKTOP.ACC, a program that changes the normal gray
  3. ; background with a Degas P?3 file. This source is public domain, but I
  4. ; would appreciate it very much if a program that uses (part) of this
  5. ; source respects the name of the author!
  6. ; **************************************************************************
  7. ; This source is written for Megamax C, with the inline assembly.
  8. ; **************************************************************************
  9. ; Noud van Kruysbergen
  10. ; N.I.C.I.
  11. ; P.O. Box 9104
  12. ; 6500 HE Nijmegen
  13. ; The Netherlands
  14. ; email: kruysbergen@hnykun53.bitnet
  15. ; **************************************************************************
  16. #include <gemdefs.h>
  17. #include <stdio.h>
  18. #include <osbind.h>
  19. #include <gembind.h>
  20.  
  21. int status=1;
  22. int handle;
  23. int menu_id,msgbf[8];
  24. int i,j;
  25. long l,picstart,bufcount,piccount;
  26.  
  27. static long _oldgem();
  28. static long _newgem();
  29.  
  30. static int _style(),_interior(),_mode();
  31. extern int gl_apid;
  32. static long _buffer();
  33. long buffer;
  34.  
  35. static int _clipx0(),_clipy0(),_clipx1(),_clipy1();
  36. char path[50],file[14];
  37. char t[70];
  38.  
  39. char newdta[44];
  40.  
  41. newroutines()
  42. {
  43.      asm
  44.      {
  45.                     dc.l      0x58425241
  46.                     dc.l      0x4e5f4450
  47.                     dc.l      0L
  48.  
  49.           _newgem:  cmpi.w    #115,D0
  50.                     bne       gemquit
  51.                     movem.l   D0-A3,-(A7)
  52.  
  53.                     move.l    D1,A0
  54.                     move.l    (A0),A0
  55.                     move.w    (A0),D0
  56.  
  57.                     cmpi.w    #114,D0
  58.                     bne       nofill
  59.                     lea       _interior,A0
  60.                     move.w    (A0),D0
  61.                     cmpi.w    #2,D0
  62.                     bne       gemrest
  63.                     lea       _style,A0
  64.                     move.w    (A0),D0
  65.                     cmpi.w    #4,D0
  66.                     bne       gemrest
  67.  
  68.                     lea       _mode,A0
  69.                     move.w    (A0),D0
  70.                     beq       gemrest
  71.                     move.l    D1,A0
  72.                     move.l    8(A0),A0
  73.                     move.w    (A0)+,D0
  74.                     bne       gemrest
  75.                     move.w    (A0)+,D0
  76.                     cmpi.w    #19,D0
  77.                     beq       menu
  78.                     tst.w     D0
  79.                     bne       gemrest
  80.           menu:     move.w    (A0)+,D0
  81.                     cmpi.w    #639,D0
  82.                     bne       gemrest
  83.                     move.w    (A0),D0
  84.                     cmpi.w    #399,D0
  85.                     bne       gemrest
  86.  
  87.                     move.l    0x44e,A1
  88. ; A1: screenadress
  89.                     move.w    _clipy0,D0
  90.                     move.w    D0,D2
  91. ; D2: y0
  92.                     muls      #80,D0
  93.                     adda.l    D0,A1
  94. ; A1: screenadress + y0 offset
  95.                     lea       _buffer,A0
  96.                     move.l    (A0),A0
  97. ; A0: pictureadress
  98.                     adda.l    D0,A0
  99. ; A0: pictureadress + y0 offset
  100.                     move.w    _clipy1,D0
  101.                     sub.w     D2,D0
  102.                     move.w    D0,D2
  103. ; D2: total number of lines
  104.                     move.w    _clipx0,D3
  105. ; D3: x0
  106.                     move.w    D3,D7
  107.                     ext.l     D7
  108.                     divs      #8,D7
  109.                     move.w    D7,D3
  110.                     adda.l    D3,A0
  111.                     adda.l    D3,A1
  112. ; D3: x0/8
  113.                     swap      D7
  114.                     move.w    D7,D4
  115. ; D4: x0%8
  116.                     move.w    _clipx1,D5
  117.                     addq.w    #1,D5
  118. ; D5: x1
  119.                     move.w    D5,D7
  120.                     ext.l     D7
  121.                     divs      #8,D7
  122.                     move.w    D7,D5
  123. ; D5: x1/8
  124.                     swap      D7
  125.                     move.w    D7,D6
  126. ; D6: x1%8
  127.                     move.l    D5,D0
  128.                     sub.l     D3,D0
  129.                     bne       label3
  130.  
  131.                     move.w    D6,D7
  132.                     subi.w    #8,D7
  133.                     neg.w     D7
  134.                     move.b    #-1,D3
  135.                     lsr.b     D7,D3
  136.                     lsl.b     D7,D3
  137.                     lsl.b     D4,D3
  138.                     lsr.b     D4,D3
  139.           loop2:    move.b    D3,D5
  140.                     move.b    (A0),D7
  141.                     and.b     D5,D7
  142.                     not.b     D5
  143.                     and.b     (A1),D5
  144.                     add.b     D5,D7
  145.                     move.b    D7,(A1)
  146.                     adda.l    #80,A0
  147.                     adda.l    #80,A1
  148.                     dbf       D2,loop2
  149.                     bra       selfok
  150.  
  151.           label3:   subq.w    #1,D0
  152.                     tst.w     D4
  153.                     seq       D5
  154.                     beq       yloop
  155.                     tst.w     D0
  156.                     sne       D5
  157.                     beq       yloop
  158.                     subq.w    #1,D0
  159. ; first incomplete byte
  160.           yloop:    move.l    A0,A2
  161.                     move.l    A1,A3
  162.                     tst.w     D4
  163.                     beq       nostart
  164.                     move.b    (A2)+,D3
  165.                     move.b    #-1,D7
  166.                     lsr.b     D4,D7
  167.                     and.b     D7,D3
  168.                     not.b     D7
  169.                     and.b     (A3),D7
  170. ; D1 contains lowest picturebits, D7 highest backgroundbits
  171.                     add.b     D3,D7
  172.                     move.b    D7,(A3)+
  173.  
  174.           nostart:  move.w    D0,D7
  175.                     tst.w     D5
  176.                     beq       endbyte
  177.           xloop:    move.b    (A2)+,(A3)+
  178.                     dbf       D7,xloop
  179. ; last incomplete byte
  180.           endbyte:  tst.w     D6
  181.                     beq       no_end
  182.                     move.b    (A2)+,D3
  183.                     move.b    #-1,D7
  184.                     lsr.b     D6,D7
  185.                     not.b     D7
  186.                     and.b     D7,D3
  187.                     not.b     D7
  188.                     and.b     (A3),D7
  189.                     add.b     D3,D7
  190.                     move.b    D7,(A3)
  191.  
  192.           no_end:   adda.l    #80,A0
  193.                     adda.l    #80,A1
  194.           label1:   dbf       D2,yloop
  195.  
  196.           selfok:   movem.l   (A7)+,D0-A3
  197.                     rte
  198.  
  199.           nofill:   move.l    D1,A0
  200.                     move.l    4(A0),A0
  201.                     move.w    (A0),D2
  202.                     cmpi.w    #23,D0
  203.                     bne       nointerior
  204.                     lea       _interior,A0
  205.                     move.w    D2,(A0)
  206.                     bra       gemrest
  207.  
  208.           nointerior:cmpi.w   #24,D0
  209.                     bne       nostyle
  210.                     lea       _style,A0
  211.                     move.w    D2,(A0)
  212.                     bra       gemrest
  213.  
  214.           nostyle:  cmpi.w    #129,D0
  215.                     bne       gemrest
  216.                     lea       _mode,A0
  217.                     move.w    D2,(A0)
  218.                     beq       gemrest
  219.                     move.l    D1,A0
  220.                     move.l    8(A0),A0
  221.                     lea       _clipx0,A1
  222.                     move.w    (A0)+,(A1)
  223.                     lea       _clipy0,A1
  224.                     move.w    (A0)+,(A1)
  225.                     lea       _clipx1,A1
  226.                     move.w    (A0)+,(A1)
  227.                     lea       _clipy1,A1
  228.                     move.w    (A0),(A1)
  229.  
  230.           gemrest:  movem.l   (A7)+,D0-A3
  231.           gemquit:  move.l    _oldgem,-(A7)
  232.                     rts
  233.  
  234.           _oldgem:  dc.l      0L
  235.           _buffer:  dc.l      0L
  236.           _style:   dc.w      0
  237.           _interior:dc.w      0
  238.           _mode:    dc.w      0
  239.           _clipx0:  dc.w      0
  240.           _clipy0:  dc.w      0
  241.           _clipx1:  dc.w      0
  242.           _clipy1:  dc.w      0
  243.      }
  244. }
  245.  
  246. Readfile()
  247. {
  248.      handle=-1;
  249.      strcpy(t,path);
  250.      j=0;
  251.      while(t[j++]!='*' && j<70);
  252.      if (j<70)
  253.      {
  254.           path[j]=0;
  255.           t[--j]=0;
  256.           strcat(path,".P?3");
  257.           strcat(t,file);
  258.           if ((handle=Fopen(t,0))>=0)
  259.           {
  260.                Fseek(34L,handle,0);
  261.                j=strlen(file);
  262.                if (file[--j]=='3' && file[--j]=='C')
  263.                {
  264.                     l=Fsetdta(newdta);
  265.                     Fsfirst(t,0);
  266.                     Fsetdta(l);
  267.                     l=*(long *)(newdta+26);
  268.                     if (piccount=picstart=Malloc(l))
  269.                     {
  270.                          l=Fread(handle,l,picstart);
  271.                          bufcount=buffer;
  272.                          do
  273.                          {
  274.                               asm
  275.                               {
  276.                                              move.l    piccount(A4),A0
  277.                                              move.b    (A0),D0
  278.                                              ext.w     D0
  279.                                              and.w     #0xff,D0
  280.                                              move.w    D0,j(A4)
  281.                                              addq.l    #1,piccount(A4)
  282.                               }
  283.                               if (j<128)
  284.                               {
  285.                                    asm
  286.                                    {
  287.                                                   move.l    bufcount(A4),A2
  288.                                                   move.l    piccount(A4),A1
  289.                                                   move.w    j(A4),D0
  290.                                         pic1loop: move.b    (A1)+,(A2)+
  291.                                                   dbf       D0,pic1loop
  292.                                                   move.l    A1,piccount(A4)
  293.                                                   move.l    A2,bufcount(A4)
  294.                                    }
  295.                               }
  296.                               else
  297.                               {
  298.                                    if (j!=128)
  299.                                    {
  300.                                         j^=255;
  301.                                         asm
  302.                                         {
  303.                                                        move.l    bufcount(A4),A2
  304.                                                        move.l    piccount(A4),A1
  305.                                                        move.w    j(A4),D0
  306.                                                        addq.w    #1,D0
  307.                                              pic2loop: move.b    (A1),(A2)+
  308.                                                        dbf       D0,pic2loop
  309.                                                        addq.l    #1,piccount(A4)
  310.                                                        move.l    A2,bufcount(A4)
  311.                                         }
  312.                                    }
  313.                               }
  314.                          }
  315.                          while((piccount-picstart<l) && (bufcount-buffer<32000L));
  316.                          Mfree(picstart);
  317.                     }
  318.                     else form_error(8);
  319.                }
  320.                else Fread(handle,32000L,buffer);
  321.                Fclose(handle);
  322.           }
  323.      }
  324.      return(handle);
  325. }
  326.  
  327. Install()
  328. {
  329.           asm
  330.           {
  331.                          lea       _oldgem,A0
  332.                          move.l    0x88,(A0)
  333.                          lea       _newgem,A1
  334.                          move.l    A1,0x88
  335.                          move.l    (A0),-4(A1)
  336.           }
  337. }
  338.  
  339. main()
  340. {
  341.      appl_init();
  342.      buffer=Malloc(32000L);
  343.      asm
  344.      {
  345.                     lea       _buffer,A0
  346.                     move.l    buffer(A4),(A0)
  347.      }
  348.      strcpy(t,"A:\\DESKTOP.P?3");
  349.      strcpy(path,"A:\\*.P?3");
  350.      t[file[0]=0]=path[0]=(char)(Dgetdrv()+65);
  351.      Fsetdta(newdta);
  352.      i=Fsfirst(t,0);
  353.      if (!i)
  354.      {
  355.           strcpy(file,(char *)(newdta+30));
  356.           if (Readfile()<0) status=file[0]=0;
  357.           else Supexec(Install);
  358.      }
  359.      menu_id=menu_register(gl_apid,"  Desktop Picture");
  360.      while ()
  361.      {
  362.           evnt_mesag(msgbf);
  363. /*************************************************************
  364. --- for version 2.01: include these lines ---
  365.           if (status)
  366.           {
  367.                l=Super(0L);
  368.                asm
  369.                {
  370.                               lea       _newgem,A1
  371.                               cmpa.l    0x88,A1
  372.                               beq       already
  373.                               lea       _oldgem,A0
  374.                               move.l    0x88,(A0)
  375.                               move.l    A1,0x88
  376.                               move.l    (A0),-4(A1)
  377.                     already:
  378.                }
  379.                Super(l);
  380.           }
  381. ***************************************************************/
  382.           if (msgbf[0]==AC_OPEN && msgbf[4]==menu_id)
  383.           {
  384.                i=form_alert(3-status,"[2][| Desktop Picture 2.01|= Noud van Kruysbergen|][New| On |Off]");
  385.                if (i!=3-status)
  386.                {
  387.                     wind_update(BEG_UPDATE);
  388.                     form_dial(FMD_START,0,0,0,0,0,0,640,400);
  389.                     if ((i==2 && file[0]==0) || i==1)
  390.                     {
  391.                          fsel_input(path,file,&j);
  392.                          if (j && Readfile()<0)
  393.                          {
  394.                               form_error(2);
  395.                               file[0]=0;
  396.                          }
  397.                     }
  398.                     if (((i==2 && file[0]!=0) || i==3) && status!=(j=3-i))
  399.                     {
  400.                          if (status=j) Supexec(Install);
  401.                          else
  402.                          {
  403.                               l=Super(0L);
  404.                               asm
  405.                               {
  406.                                              lea       _oldgem,A0
  407.                                              move.l    (A0),0x88
  408.                               }
  409.                               Super(l);
  410.                          }
  411.                     }
  412.                     form_dial(FMD_FINISH,0,0,0,0,0,0,640,400);
  413.                     wind_update(END_UPDATE);
  414.                }
  415.           }
  416.      }
  417. }
  418.  
  419.