home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / TCS / demos / cod / brshs.s next >
Encoding:
Text File  |  2000-09-26  |  8.6 KB  |  331 lines

  1. *******************************************************************************
  2. * brush handling example
  3. *******************************************************************************
  4. * INFO    loads a 320x256x8 ILBM to a FullRes screen and then performs
  5. *    various brush operations on it
  6. * NOTE    - optionally you can pass as CLI argument the name of another
  7. *      320x256x8 ILBM to load (yours must have the same size and
  8. *      must respect all the restrictions of TCS_LdILBM(), otherwise
  9. *      the program won't execute or the graphics will look bad -
  10. *      not dangerous, anyway!)
  11. *    - LMB to quit
  12. *******************************************************************************
  13.  
  14.     machine    68020
  15.  
  16.     include    INCLUDES:libraries/tcs.i
  17.     include    INCLUDES:libraries/tcs_lib.i
  18.     include    /inc/macros.i
  19.  
  20.  
  21.  
  22. *******************************************************************************
  23. * definitions
  24. *******************************************************************************
  25.  
  26. DSPLWD    =    320    ;our TCS display width and
  27. DSPLHT    =    256    ;height (LORES pixels)
  28. SCRWD    =    320    ;TCS screen width and
  29. SCRHT    =    256    ;height (FullRes pixels)
  30. DSPLX0    =    $81*4    ;display start
  31. DSPLY0    =    $2c    ;position (SHRES pixels)
  32. DSPLX1    =    DSPLX0+DSPLWD*4    ;display end
  33. DSPLY1    =    DSPLY0+DSPLHT    ;position (SHRES pixels)
  34. DSPLBRTNS    =    256    ;max brightness
  35. GFXCTXT    =    0    ;graphic context
  36. CWBTM    =    0    ;clipping
  37. CWTOP    =    0    ;window
  38. CWRT    =    0    ;borders
  39. CWLF    =    0    ;coordinates
  40. VDOMODE    =    TCS_VMf_FullRes    ;display video mode
  41.  
  42. ARGSNO    =    1    ;command line arguments No.
  43. BRSHSZ    =    32    ;width & height of a brush
  44.  
  45.  
  46.  
  47. *******************************************************************************
  48. * code start
  49. *******************************************************************************
  50.  
  51.     include    /inc/shl_strtup.i
  52.  
  53.  
  54.  
  55. *******************************************************************************
  56. * init
  57. *******************************************************************************
  58.  
  59. _PrgInit    movea.l    CmdLnArgs,a0    ;picture filename address
  60.     tst.l    a0
  61.     bne.s    .ld    ;if filename specified...
  62.     lea.l    PicFlNm,a0    ;default picture
  63. .ld    movea.l    ([DIAdr.l],TCS_DI_CSAdr.w),a1 ;directly to
  64.     move.l    #SCRWD*SCRHT,d0    ;screen buffer
  65.     CALLTCS    LdILBM    ;load it
  66.     cmpi.l    #TCS_PE_OK,d0    ;success?
  67.     blo.s    .fail    ;if not...
  68.     move.l    d0,PicIIAdr    ;else store its ILBMInfo structure address
  69.     rts        ;& clr ccr.Z to signal success
  70. .fail    move.w    #4,ccr    ;signal error
  71.     rts
  72.  
  73.  
  74.  
  75. *******************************************************************************
  76. * main
  77. *******************************************************************************
  78.  
  79. _PrgMain    movea.l    DIAdr,a0
  80.     move.b    ([PicIIAdr.l],TCS_II_RGBxMode.w),d0 ;picture RGBx mode
  81.     move.w    #DSPLBRTNS,d1
  82.     CALLTCS    SetRGBxMode    ;set display palette
  83.  
  84. *******************************************************************************
  85. * normal masks
  86.  
  87.     movea.l    DIAdr,a0    ;cut the first
  88.     suba.l    a1,a1    ;brush from the
  89.     moveq.l    #0,d0    ;screen
  90.     moveq.l    #64,d1    ;and keep it
  91.     move.w    #BRSHSZ,d2    ;in a buffer
  92.     move.w    #BRSHSZ,d3    ;allocated by
  93.     CALLTCS    GetBrsh    ;the library
  94.     move.l    d0,brsh0    ;store the brush address
  95.     beq.s    .exit    ;if error...
  96.  
  97.     movea.l    DIAdr,a0    ;cut the second
  98.     suba.l    a1,a1    ;brush from the
  99.     moveq.l    #0,d0    ;screen
  100.     moveq.l    #96,d1    ;and keep it
  101.     move.w    #BRSHSZ,d2    ;in a buffer
  102.     move.w    #BRSHSZ,d3    ;allocated by
  103.     CALLTCS    GetBrsh    ;the library
  104.     move.l    d0,brsh1    ;store the brush address
  105.     beq.s    .exit    ;if error...
  106.  
  107.     movea.l    brsh0,a0    ;make a normal
  108.     suba.l    a1,a1    ;mask for the
  109.     move.b    #$ff,d0    ;first brush
  110.     move.b    #153,d1    ;and keep it
  111.     move.w    #BRSHSZ,d2    ;in a buffer
  112.     move.w    #BRSHSZ,d3    ;allocated by
  113.     CALLTCS    MkBrshMsk    ;the library
  114.     move.l    d0,msk0    ;store the mask address
  115.     beq.s    .exit    ;if error...
  116.  
  117.     movea.l    brsh1,a0    ;make a normal
  118.     suba.l    a1,a1    ;mask for the
  119.     move.b    #$ff,d0    ;second brush
  120.     move.b    #153,d1    ;and keep it
  121.     move.w    #BRSHSZ,d2    ;in a buffer
  122.     move.w    #BRSHSZ,d3    ;allocated by
  123.     CALLTCS    MkBrshMsk    ;the library
  124.     move.l    d0,msk1    ;store the mask address
  125.     beq.s    .exit    ;if error...
  126.  
  127.     movea.l    DIAdr,a0    ;print
  128.     movea.l    msk0,a1    ;the
  129.     move.w    #64,d0    ;first
  130.     move.w    #64,d1    ;mask
  131.     move.w    #BRSHSZ,d2    ;on
  132.     move.w    #BRSHSZ,d3    ;the
  133.     CALLTCS    WrtBrsh0    ;screen
  134.  
  135.     movea.l    DIAdr,a0    ;print
  136.     movea.l    msk1,a1    ;the
  137.     move.w    #64,d0    ;second
  138.     move.w    #96,d1    ;mask
  139.     move.w    #BRSHSZ,d2    ;on
  140.     move.w    #BRSHSZ,d3    ;the
  141.     CALLTCS    WrtBrsh0    ;screen
  142.  
  143.     movea.l    DIAdr,a0    ;print
  144.     movea.l    brsh0,a1    ;the
  145.     movea.l    msk0,a2    ;first
  146.     move.w    #96,d0    ;brush
  147.     move.w    #64,d1    ;(masked)
  148.     move.w    #BRSHSZ,d2    ;on
  149.     move.w    #BRSHSZ,d3    ;the
  150.     CALLTCS    WrtBrsh8    ;screen
  151.  
  152.     movea.l    DIAdr,a0    ;print
  153.     movea.l    brsh1,a1    ;the
  154.     movea.l    msk1,a2    ;second
  155.     move.w    #96,d0    ;brush
  156.     move.w    #96,d1    ;(masked)
  157.     move.w    #BRSHSZ,d2    ;on
  158.     move.w    #BRSHSZ,d3    ;the
  159.     CALLTCS    WrtBrsh8    ;screen
  160.  
  161.     movea.l    brsh0,a0    ;merge
  162.     movea.l    brsh1,a1    ;the two
  163.     movea.l    msk0,a2    ;brushes
  164.     movea.l    a0,a3    ;together
  165.     move.w    #BRSHSZ,d2    ;using the
  166.     move.w    #BRSHSZ,d3    ;first brush
  167.     CALLTCS    MrgBrshs    ;as destination
  168.  
  169.     movea.l    msk0,a0    ;merge
  170.     movea.l    msk1,a1    ;the two
  171.     movea.l    a0,a2    ;masks
  172.     movea.l    a0,a3    ;together
  173.     move.w    #BRSHSZ,d2    ;using the
  174.     move.w    #BRSHSZ,d3    ;first mask
  175.     CALLTCS    MrgBrshs    ;as destination
  176.  
  177.     movea.l    DIAdr,a0    ;print
  178.     movea.l    brsh0,a1    ;the
  179.     move.w    #160,d0    ;mixed
  180.     move.w    #64,d1    ;brush
  181.     move.w    #BRSHSZ,d2    ;on
  182.     move.w    #BRSHSZ,d3    ;the
  183.     CALLTCS    WrtBrsh0    ;screen
  184.  
  185.     movea.l    DIAdr,a0    ;print
  186.     movea.l    msk0,a1    ;the
  187.     move.w    #192,d0    ;mixed
  188.     move.w    #64,d1    ;mask
  189.     move.w    #BRSHSZ,d2    ;on
  190.     move.w    #BRSHSZ,d3    ;the
  191.     CALLTCS    WrtBrsh0    ;screen
  192.  
  193.     movea.l    DIAdr,a0    ;print
  194.     movea.l    brsh0,a1    ;the
  195.     movea.l    msk0,a2    ;mixed
  196.     move.w    #224,d0    ;brush
  197.     move.w    #64,d1    ;(masked)
  198.     move.w    #BRSHSZ,d2    ;on
  199.     move.w    #BRSHSZ,d3    ;the
  200.     CALLTCS    WrtBrsh8    ;screen
  201.  
  202. *******************************************************************************
  203. * partial masks
  204.  
  205.     movea.l    DIAdr,a0    ;cut a brush
  206.     movea.l    brsh0,a1    ;brush from the
  207.     moveq.l    #0,d0    ;screen
  208.     move.w    #160,d1    ;and keep it
  209.     move.w    #BRSHSZ,d2    ;in a buffer
  210.     move.w    #BRSHSZ,d3    ;previously allocated
  211.     CALLTCS    GetBrsh    ;by the library
  212.  
  213.     movea.l    brsh0,a0    ;make a red-only
  214.     movea.l    msk0,a1    ;mask for the
  215.     move.b    #$88,d0    ;brush
  216.     move.b    #94,d1    ;and keep it
  217.     move.w    #BRSHSZ,d2    ;in a buffer
  218.     move.w    #BRSHSZ,d3    ;previously allocated
  219.     CALLTCS    MkBrshMsk    ;by the library
  220.  
  221.     movea.l    DIAdr,a0    ;print
  222.     movea.l    msk0,a1    ;the
  223.     move.w    #64,d0    ;newly created
  224.     move.w    #160,d1    ;mask
  225.     move.w    #BRSHSZ,d2    ;on
  226.     move.w    #BRSHSZ,d3    ;the
  227.     CALLTCS    WrtBrsh0    ;screen
  228.  
  229.     movea.l    DIAdr,a0    ;print
  230.     movea.l    brsh0,a1    ;the
  231.     movea.l    msk0,a2    ;newly created
  232.     move.w    #96,d0    ;brush
  233.     move.w    #160,d1    ;(masked)
  234.     move.w    #BRSHSZ,d2    ;on
  235.     move.w    #BRSHSZ,d3    ;the
  236.     CALLTCS    WrtBrsh8    ;screen
  237.  
  238.     movea.l    brsh0,a0    ;make a green-only
  239.     movea.l    msk0,a1    ;mask for the
  240.     move.b    #$44,d0    ;brush
  241.     move.b    #94,d1    ;and keep it
  242.     move.w    #BRSHSZ,d2    ;in a buffer
  243.     move.w    #BRSHSZ,d3    ;previously allocated
  244.     CALLTCS    MkBrshMsk    ;by the library
  245.  
  246.     movea.l    DIAdr,a0    ;print
  247.     movea.l    msk0,a1    ;the
  248.     move.w    #64,d0    ;newly created
  249.     move.w    #192,d1    ;mask
  250.     move.w    #BRSHSZ,d2    ;on
  251.     move.w    #BRSHSZ,d3    ;the
  252.     CALLTCS    WrtBrsh0    ;screen
  253.  
  254.     movea.l    DIAdr,a0    ;print
  255.     movea.l    brsh0,a1    ;the
  256.     movea.l    msk0,a2    ;newly created
  257.     move.w    #96,d0    ;brush
  258.     move.w    #192,d1    ;(masked)
  259.     move.w    #BRSHSZ,d2    ;on
  260.     move.w    #BRSHSZ,d3    ;the
  261.     CALLTCS    WrtBrsh8    ;screen
  262.  
  263.     movea.l    brsh0,a0    ;make a blue-only
  264.     movea.l    msk0,a1    ;mask for the
  265.     move.b    #$22,d0    ;brush
  266.     move.b    #94,d1    ;and keep it
  267.     move.w    #BRSHSZ,d2    ;in a buffer
  268.     move.w    #BRSHSZ,d3    ;previously allocated
  269.     CALLTCS    MkBrshMsk    ;by the library
  270.  
  271.     movea.l    DIAdr,a0    ;print
  272.     movea.l    msk0,a1    ;the
  273.     move.w    #64,d0    ;newly created
  274.     move.w    #224,d1    ;mask
  275.     move.w    #BRSHSZ,d2    ;on
  276.     move.w    #BRSHSZ,d3    ;the
  277.     CALLTCS    WrtBrsh0    ;screen
  278.  
  279.     movea.l    DIAdr,a0    ;print
  280.     movea.l    brsh0,a1    ;the
  281.     movea.l    msk0,a2    ;newly created
  282.     move.w    #96,d0    ;brush
  283.     move.w    #224,d1    ;(masked)
  284.     move.w    #BRSHSZ,d2    ;on
  285.     move.w    #BRSHSZ,d3    ;the
  286.     CALLTCS    WrtBrsh8    ;screen
  287.  
  288. *******************************************************************************
  289.  
  290.     movea.l    DIAdr,a0    ;make screen
  291.     CALLTCS    CPUFRPass0    ;buffer visible
  292.  
  293.     WTLMB
  294. .exit    rts
  295.  
  296.  
  297.  
  298. *******************************************************************************
  299. * cleanup
  300. *******************************************************************************
  301.  
  302. _PrgClnUp    movea.l    msk1,a0    ;free all the memory
  303.     CALLTCS    FreeBrsh    ;allocated for
  304.     movea.l    msk0,a0    ;the masks
  305.     CALLTCS    FreeBrsh    ;created here
  306.     movea.l    brsh1,a0    ;free all the memory
  307.     CALLTCS    FreeBrsh    ;allocated for
  308.     movea.l    brsh0,a0    ;the brushes
  309.     CALLTCS    FreeBrsh    ;created here
  310.     movea.l    PicIIAdr,a0    ;free all the memory
  311.     CALLTCS    UnLdILBM    ;allocated for the picture
  312.     rts
  313.  
  314.  
  315.  
  316. *******************************************************************************
  317. * data
  318. *******************************************************************************
  319.  
  320.     include    /inc/dat.i
  321.  
  322.     cnop    0,4
  323.  
  324. brsh0    dc.l    0    ;pointers to brushes
  325. brsh1    dc.l    0    ;created here
  326. msk0    dc.l    0    ;pointers to masks
  327. msk1    dc.l    0    ;created here
  328. PicIIAdr    dc.l    0    ;picture ILBMInfo structure address
  329. tmplt    dc.b    "PICTURE=P",0    ;template for ReadArgs()
  330. PicFlNm    dc.b    "/pix/brshs.rgbh.iff",0    ;default picture
  331.