home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d543 / colorcatch.lha / ColorCatch / ColorCatch.asm < prev    next >
Assembly Source File  |  1991-09-20  |  10KB  |  359 lines

  1. *    ColorCatch
  2. *    By Preben Nielsen
  3. *
  4. *    NOTE:    There's no need to 'RUN' or 'RUNBACK' this program from the
  5. *        CLI. It is auto-detaching.
  6. *
  7. *HISTORY
  8. *          Made with Hisoft V2.12
  9. *
  10. *  V1.0   ??-???-90: First release.
  11. *  V2.0   06-Aug-91: Rewrote the code just for fun.
  12. *                    The executables created are now even smaller.
  13. *                    The user-interface is now completely different from
  14. *                    version 1.0.
  15. *                    Is now auto-detaching when run from the CLI.
  16. *                    The executables created by this program can now be
  17. *                    made resident (pure).
  18. *                    Works fine with kickstart 2.x (68000 based).
  19.  
  20.     OPT O+
  21.     OPT O1+            ; Tells when a branch could be optimised to short
  22.     OPT i+            ; Tells when '#' is probably missing
  23.  
  24.         incdir        "AsmInc:"
  25.         include        "P.i"
  26.         include        "Intui.i"
  27.         include        "Detach.i"
  28.         include        "relMacros.i"
  29.         include        "exec/exec_lib.i"
  30.         include        "graphics/view.i"
  31.         include        "graphics/graphics_lib.i"
  32.         include        "intuition/intuition.i"
  33.         include        "intuition/intuition_lib.i"
  34.         include        "libraries/dos.i"
  35.         include        "libraries/dosextens.i"
  36.         include        "libraries/dos_lib.i"
  37.         include        "workbench/workbench.i"
  38.         include        "workbench/icon_lib.i"
  39.  
  40. FileBufSIZE    =120
  41.  
  42. DB        EQUR        A4
  43.  
  44.  dcDeclare    A4
  45.  dcAPtr        WBMsg
  46.  dcAPtr        DosBase
  47.  dcAPtr        IntuiBase
  48.  dcAPtr        DWindow
  49.  dcArea        FileInfo,si_SIZEOF
  50.  dcArea        FileBuf,FileBufSIZE
  51.  dcArea        UndoBuf,FileBufSIZE
  52.  dcEnd
  53.  
  54. Start        DetachSingle    <'ColorCatch'>,4000,0
  55.         dcAlloc                    ; Allocate memory for variables
  56.         dcReset                    ; Clear the memory
  57.         lea        FileInfo(DB),A1
  58.         lea        FileBuf(DB),A2
  59.         move.l        A2,si_Buffer(A1)
  60.         lea        UndoBuf(DB),A2
  61.         move.l        A2,si_UndoBuffer(A1)
  62.         move.w        #FileBufSIZE,si_MaxChars(A1)
  63.         lea        FileGad(PC),A2
  64.         move.l        A1,gg_SpecialInfo(A2)
  65.  
  66.         Prepare        Exec_Call
  67.         suba.l        A1,A1
  68.         CallLib        FindTask
  69.         movea.l        D0,A2
  70.         tst.l        pr_CLI(A2)
  71.         bne.S        GetLibs
  72.         lea        pr_MsgPort(A2),A0
  73.         CallLib        WaitPort
  74.         lea        pr_MsgPort(A2),A0
  75.         CallLib        GetMsg
  76.         move.l        D0,WBMsg(DB)
  77. GetLibs        lea        DosName(PC),A1
  78.         CallLib        OldOpenLibrary
  79.         move.l        D0,DosBase(DB)
  80.         beq.S        Error
  81.         lea        IntuiName(PC),A1
  82.         CallLib        OldOpenLibrary
  83.         move.l        D0,IntuiBase(DB)
  84.         beq.S        Error
  85.         Prepare        Intuition_Call
  86.         lea        NW(PC),A0
  87.         CallLib        OpenWindow
  88.         move.l        D0,DWindow(DB)
  89.         movea.l        D0,A0
  90.         beq.S        Error
  91.         lea        WinTitle(PC),A1
  92.         lea        ScrTitle(PC),A2
  93.         CallLib        SetWindowTitles
  94.         bra.S        Main
  95.  
  96. Error
  97. Exit
  98. FreeWindow    Prepare        Intuition_Call
  99.         move.l        DWindow(DB),D0
  100.         beq.S        FreeIntui
  101.         movea.l        D0,A0
  102.         CallLib        CloseWindow
  103. FreeIntui    Prepare        Exec_Call
  104.         move.l        IntuiBase(DB),D0
  105.         beq.S        FreeDos
  106.         movea.l        D0,A1
  107.         CallLib        CloseLibrary
  108. FreeDos        move.l        DosBase(DB),D0
  109.         beq.S        ReplyWB
  110.         movea.l        D0,A1
  111.         CallLib        CloseLibrary
  112. ReplyWB        move.l        WBMsg(DB),D2
  113.         beq.S        AllDone
  114.         CallLib        Forbid
  115.         movea.l        D2,A1
  116.         CallLib        ReplyMsg
  117. AllDone        dcFree
  118.         moveq        #0,D0
  119.         rts
  120.  
  121. Main        Call        GrabColors
  122. EventLoop    Prepare        Exec_Call
  123.         movea.l        DWindow(DB),A0
  124.         movea.l        wd_UserPort(A0),A0
  125.         CallLib        WaitPort
  126. GetNextMsg    Prepare        Exec_Call
  127.         movea.l        DWindow(DB),A0
  128.         movea.l        wd_UserPort(A0),A0
  129.         CallLib        GetMsg
  130.         tst.l        D0
  131.         beq.S        EventLoop
  132.         move.l        D0,A1
  133.         move.l        im_Class(A1),D2
  134.         move.l        im_IAddress(A1),A2
  135.         CallLib        ReplyMsg
  136.         cmp.l        #CLOSEWINDOW,D2
  137.         beq.S        Exit
  138.         cmp.l        #GADGETUP,D2
  139.         beq.S        GJ
  140.         cmp.l        #ACTIVEWINDOW,D2
  141.         bne.S        GetNextMsg
  142.         Call        ActivateFS
  143.         bra.S        GetNextMsg
  144. GJ        move.w        gg_GadgetID(A2),D0    ; GadgetID is offset from GJ
  145.         jsr        GJ(PC,D0.W)
  146.         bra.S        GetNextMsg
  147.  
  148. *»»» The user either activated the window or
  149. *»»» pressed RETURN in the string gadget or
  150. *»»» selected one of the other gadgets in the window.
  151. ActivateFS    Prepare        Intuition_Call
  152.         lea        FileGad(PC),A0
  153.         move.l        DWindow(DB),A1
  154.         suba.l        A2,A2
  155.         CallLib        ActivateGadget
  156.         rts
  157.  
  158. *»»» The user clicked the 'Grab colors from front screen' gadget
  159. GrabColors    Prepare        Intuition_Call
  160.         move.l        ib_FirstScreen(A6),A0
  161.         move.l        sc_ViewPort+vp_ColorMap(A0),A0
  162.         move.w        cm_Count(A0),D0
  163.         move.l        cm_ColorTable(A0),A0
  164.         lea        ColorCount(PC),A1
  165.         move.w        D0,(A1)+
  166.         bra.S        2$
  167. 1$        move.w        (A0)+,(A1)+
  168. 2$        dbf        D0,1$
  169.         Call        ActivateFS
  170.         rts
  171.  
  172. *»»» The user clicked the 'Save with icon' gadget
  173. SaveWith    moveq        #1,D7
  174.         bra.S        SaveColors
  175. *»»» The user clicked the 'Save without icon' gadget
  176. SaveWithout    moveq        #0,D7
  177. SaveColors    Prepare        Dos_Call
  178.         lea        FileBuf(DB),A0
  179.         move.l        A0,D1
  180.         move.l        #MODE_NEWFILE,D2
  181.         CallLib        Open
  182.         move.l        D0,D5
  183.         move.l        D0,D6
  184.         beq.S        FileFailure
  185.         move.l        D6,D1
  186.         lea        ColorExe(PC),A0
  187.         move.l        A0,D2
  188.         move.l        #EndColorExe-ColorExe,D3
  189.         CallLib        Write
  190.         move.l        D0,D5
  191.         move.l        D6,D1
  192.         CallLib        Close
  193.         cmp.l        D5,D3            ; Errors during writing ?
  194.         bne.S        FileFailure
  195.         tst.l        D7
  196.         beq.S        AllWritten
  197.         Prepare        Exec_Call        ; Make icon too !
  198.         lea        IconName(PC),A1
  199.         CallLib        OldOpenLibrary
  200.         move.l        D0,D6
  201.         beq.S        IconFailure
  202.         lea        FileBuf(DB),A0
  203.         lea        MyDiskObject(PC),A1
  204.         move.l        D6,A6
  205.         CallLib        PutIcon
  206.         move.l        D0,D5
  207.         Prepare        Exec_Call
  208.         move.l        D6,A1
  209.         CallLib        CloseLibrary
  210.         tst.l        D5            ; Errors during writing ?
  211.         bne.S        AllWritten
  212. IconFailure    lea        TxtIconFailure(PC),A0
  213.         bra.S        ShowError
  214. FileFailure    lea        TxtFileFailure(PC),A0
  215. ShowError    lea        ITxtAUTOBody(PC),A1
  216.         move.l        A0,it_IText(A1)
  217.         suba.l        A0,A0
  218.         suba.l        A2,A2
  219.         lea        ITxtAUTOOk(PC),A3
  220.         moveq        #0,D0
  221.         moveq        #0,D1
  222.         move.w        #268,D2
  223.         moveq        #46,D3
  224.         Prepare        Intuition_Call
  225.         CallLib        AutoRequest
  226. AllWritten    Call        ActivateFS
  227.         rts
  228.  
  229. *»»» Write everything between ColorExe and EndColorExe to disk.
  230. *»»» It will become an executable file.
  231. ColorExe    dc.l        $000003F3,$00000000,$00000001,$00000000
  232.         dc.l        $00000000,$0000003B,$000003E9,$0000003B
  233.         dc.l        $7E007C00,$7A002C78,$000493C9,$4EAEFEDA
  234.         dc.l        $24404AAA,$00AC6612,$41EA005C,$4EAEFE80
  235.         dc.l        $41EA005C,$4EAEFE8C,$2E0043FA,$00584EAE
  236.         dc.l        $FE682C00,$672443FA,$005D4EAE,$FE682A00
  237.         dc.l        $67182045,$2068003C,$41E8002C,$303A005A
  238.         dc.l        $43FA0058,$2C464EAE,$FF402C78,$00042005
  239.         dc.l        $67062240,$4EAEFE62,$20066706,$22404EAE
  240.         dc.l        $FE622407,$670A4EAE,$FF7C2242,$4EAEFE86
  241.         dc.l        $70004E75,$67726170,$68696373,$2E6C6962
  242.         dc.l        $72617279,$00696E74,$75697469,$6F6E2E6C
  243.         dc.l        $69627261,$72790000
  244. ColorCount    dc.w        0        ; Number of colors in ColorTable
  245. ColorTable    dcb.w        32,0        ; Array of colors
  246.         dc.l        $00000000
  247.         dc.w        $03F2
  248. EndColorExe
  249.  
  250. *»»» Some data »»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  251.  
  252. DosName        dc.b        'dos.library',0
  253. IntuiName    dc.b        'intuition.library',0
  254. IconName    dc.b        'icon.library',0
  255.  
  256. IDCMP_Flags    =        GADGETUP|CLOSEWINDOW|ACTIVEWINDOW
  257. Other_Flags    =        NOCAREREFRESH|ACTIVATE|RMBTRAP|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE
  258. NW        dc.w        180,50,301,70
  259.         dc.b        0,1
  260.         dc.l        IDCMP_Flags,Other_Flags,GadgetList,0,0,0,0
  261.         dc.w        0,0,0,0,WBENCHSCREEN
  262.  
  263. GadgetList
  264. FileGad        Gadget        CatchGad,113,18,FW,FH,GADGHCOMP,RELVERIFY,STRGADGET
  265.         Gadget2        FBorder,0,ITxtSaveAs,0,0,ActivateFS-GJ,0
  266. CatchGad    Gadget        WithGad,45,34,CW,CH,GADGHCOMP,RELVERIFY,BOOLGADGET
  267.         Gadget2        CBorder,0,ITxtCatch,0,0,GrabColors-GJ,0
  268. WithGad        Gadget        WithoutGad,12,52,B1W,B1H,GADGHCOMP,RELVERIFY,BOOLGADGET
  269.         Gadget2        B1Border,0,ITxtWith,0,0,SaveWith-GJ,0
  270. WithoutGad    Gadget        0,145,52,B2W,B2H,GADGHCOMP,RELVERIFY,BOOLGADGET
  271.         Gadget2        B2Border,0,ITxtWithout,0,0,SaveWithout-GJ,0
  272.  
  273. CW        =242
  274. CH        =11
  275. CBorder        Border        -2,-1,1,0,1,9,CVectors,0
  276. CVectors    dc.w        2,0,CW+1,0,CW+3,2,CW+3,CH-1,CW+1,CH+1,2,CH+1,0,CH-1,0,2,2,0
  277. B1W        =120
  278. B1H        =11
  279. B1Border    Border        -2,-1,1,0,1,9,B1Vectors,0
  280. B1Vectors    dc.w        2,0,B1W+1,0,B1W+3,2,B1W+3,B1H-1,B1W+1,B1H+1,2,B1H+1,0,B1H-1,0,2,2,0
  281. B2W        =144
  282. B2H        =11
  283. B2Border    Border        -2,-1,1,0,1,9,B2Vectors,0
  284. B2Vectors    dc.w        2,0,B2W+1,0,B2W+3,2,B2W+3,B2H-1,B2W+1,B2H+1,2,B2H+1,0,B2H-1,0,2,2,0
  285. FW        =172
  286. FH        =9
  287. FBorder        Border        -4,-3,1,0,1,9,FVectors,0
  288. FVectors    dc.w        2,0,FW+5,0,FW+7,2,FW+7,FH+1,FW+5,FH+3,2,FH+3,0,FH+1,0,2,2,0
  289.  
  290. ITxtCatch    IntuiText    1,0,1,4,2,TxtCatch,0
  291. ITxtSaveAs    IntuiText    1,0,1,-65,0,TxtSaveAs,0
  292. ITxtWith    IntuiText    1,0,1,4,2,TxtWith,0
  293. ITxtWithout    IntuiText    1,0,1,4,2,TxtWithout,0
  294.  
  295. ITxtAUTOBody    IntuiText    AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,8,4,0,0
  296. ITxtAUTOOk    IntuiText    AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,6,3,TxtOk,0
  297.  
  298. TxtCatch    dc.b        'Grab colors from front screen',0
  299. TxtSaveAs    dc.b        'Save as',0
  300. TxtWith        dc.b        'Save with icon',0
  301. TxtWithout    dc.b        'Save without icon',0
  302.  
  303. TxtOk        dc.b        ' Ok ',0
  304. TxtFileFailure    dc.b        "ColorCatch: Can't create file",0
  305. TxtIconFailure    dc.b        "ColorCatch: Can't create icon",0
  306.  
  307. ScrTitle    dc.b        'ColorCatch V2.0 1991 by Preben Nielsen',0
  308. WinTitle    dc.b        'ColorCatch V2.0',0
  309.  
  310. FontName    dc.b        'topaz.font',0
  311.         EVEN
  312.  
  313. TxtAttr        dc.l        FontName
  314.         dc.w        TOPAZ_EIGHTY
  315.         dc.b        FS_NORMAL,FPB_ROMFONT
  316.         EVEN
  317.  
  318. *»»» The rest is for the icon
  319. MyDiskObject    dc.w        WB_DISKMAGIC,WB_DISKVERSION
  320.         Gadget        0,0,0,60,10,GADGIMAGE|GADGHIMAGE,RELVERIFY|GADGIMMEDIATE,BOOLGADGET
  321.         Gadget2        Image1,Image2,0,0,0,0,0
  322.         dc.b        WBTOOL,0
  323.         dc.l        0,0,100,40,0,0,0
  324.  
  325. Image1        Image        0,0,60,10,2,Image1Data,3,0,0
  326. Image2        Image        0,0,60,10,2,Image2Data,3,0,0
  327.  
  328. Image1Data    dc.w        $7FE0,$0FE0,$0000,$0000,$E070,$0C60
  329.         dc.w        $0000,$0000,$C73F,$FC6F,$FFFF,$FFE0
  330.         dc.w        $C7FF,$FC7F,$FE03,$FFE0,$C63F,$FC7F
  331.         dc.w        $FE39,$FFE0,$C7FF,$FC7F,$FE3F,$FFE0
  332.         dc.w        $C73F,$FC7F,$FE31,$FFE0,$E07F,$FE1F
  333.         dc.w        $FE31,$FFE0,$7FFF,$FFFF,$FFF1,$FFC0
  334.         dc.w        $0000,$0000,$0000,$0000
  335.         dc.w        $0000,$0000,$0000,$0000,$1F80,$0380
  336.         dc.w        $0000,$0000,$38C0,$0380,$0000,$0000
  337.         dc.w        $3807,$E383,$F1FC,$3F80,$380E,$3387
  338.         dc.w        $19C6,$7000,$380E,$3387,$19C0,$3F00
  339.         dc.w        $38CE,$3387,$19C0,$0380,$1F87,$E1E3
  340.         dc.w        $F1C0,$7F00,$0000,$0000,$0000,$0000
  341.         dc.w        $0000,$0000,$0000,$0000
  342.  
  343. Image2Data    dc.w        $7FE0,$0FE0,$0000,$0000,$FFF0,$0FE0
  344.         dc.w        $0000,$0000,$FFFF,$FFEF,$FFFF,$FFE0
  345.         dc.w        $FFF8,$1FFC,$0FFF,$C060,$FE31,$CFF8
  346.         dc.w        $E7FF,$8FE0,$FFF1,$CFF8,$E7FF,$C0E0
  347.         dc.w        $FFF1,$CFF8,$E7F1,$FC60,$FFF8,$1FFC
  348.         dc.w        $0FF1,$80E0,$7FFF,$FFFF,$FFF1,$FFC0
  349.         dc.w        $0000,$0000,$0000,$0000
  350.         dc.w        $0000,$0000,$0000,$0000,$1F80,$0380
  351.         dc.w        $0000,$0000,$38C0,$0380,$0000,$0000
  352.         dc.w        $3807,$E383,$F1FC,$3F80,$380E,$3387
  353.         dc.w        $19C6,$7000,$380E,$3387,$19C0,$3F00
  354.         dc.w        $38CE,$3387,$19C0,$0380,$1F87,$E1E3
  355.         dc.w        $F1C0,$7F00,$0000,$0000,$0000,$0000
  356.         dc.w        $0000,$0000,$0000,$0000
  357.         END
  358.  
  359.