home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / rs60-2.dms / rs60-2.adf / Tutorials / Tutorial2.asm < prev    next >
Encoding:
Assembly Source File  |  1991-10-17  |  6.6 KB  |  211 lines

  1. *****************************************************************************
  2. * Program: Tutorial2.asm
  3. * Descrip: Second tutorial executable for ReSource.
  4. *   Usage: None
  5. *  Author: Jeff Lavin
  6. * History: 08/18/91 V1.0 Created
  7. *****************************************************************************
  8.  
  9.     ifnd    __m68
  10.     fail    'Wrong assembler!'
  11.     endc
  12.     exeobj
  13.     objfile    'Tutorial2'
  14.  
  15.     ifnd    SysBase
  16. SysBase    equ    4
  17.  
  18. SYS    macro        ;Call a library function
  19.     jsr    (_LVO\1,a6)
  20.     endm
  21.     endc
  22.  
  23. Tutorial2    lea    (DT,pc),a5    ;Get our relative base
  24.     movea.l    a5,a0
  25.     moveq    #(BSS_Len/4)-1,d1    ;Subtract 1 for the dbcc
  26.     moveq    #0,d0
  27. ..Loop    move.l    d0,(a0)+    ;Clear work area
  28.     dbra    d1,..Loop
  29.  
  30.     movea.l    (SysBase).w,a6
  31.     movea.l    (ThisTask,a6),a2    ;Our task base
  32.     tst.l    (pr_CLI,a2)    ;From CLI or WBench?
  33.     bne.b    .FromCLI
  34.  
  35.     lea    (pr_MsgPort,a2),a0
  36.     SYS    WaitPort
  37.     lea    (pr_MsgPort,a2),a0
  38.     SYS    GetMsg    ;Get WBench startup msg
  39.     move.l    d0,(_WBenchMsg-DT,a5) ;and save it
  40.  
  41. .FromCLI    lea    (GfxName,pc),a1    ;Open graphics.library
  42.     moveq    #0,d0    ;Any version
  43.     SYS    OpenLibrary
  44.     move.l    d0,(_GfxBase-DT,a5)
  45.     beq.w    Cleanup
  46.     movea.l    d0,a6    ;GraphicsBase is in A6
  47.  
  48.     lea    (MyTextAttr,pc),a0
  49.     SYS    OpenFont
  50.     move.l    d0,(_FontPtr-DT,a5)
  51.     beq.w    Cleanup
  52.  
  53.     lea    (IntName,pc),a1    ;Open intuition.library
  54.     moveq    #0,d0    ;Any version
  55.     movea.l    (SysBase).w,a6
  56.     SYS    OpenLibrary
  57.     move.l    d0,(_IntuitionBase-DT,a5)
  58.     beq.b    Cleanup
  59.     movea.l    d0,a6    ;IntuitionBase is in A6
  60.  
  61.     lea    (MyNewWindow,pc),a0
  62.     SYS    OpenWindow    ;Open our demo window
  63.     move.l    d0,(_WindowPtr-DT,a5)
  64.     beq.b    Cleanup
  65.  
  66.     movea.l    d0,a0
  67.     movea.l    (wd_RPort,a0),a1
  68.     move.l    a1,(_RastPort-DT,a5)
  69.     movea.l    (_FontPtr-DT,a5),a0
  70.     movea.l    (_GfxBase-DT,a5),a6
  71.     SYS    SetFont
  72.  
  73. .GetMsg    movea.l    (_WindowPtr-DT,a5),a2 ;Ptr to our demo window
  74.     movea.l    (wd_UserPort,a2),a0
  75.     movea.l    (SysBase).w,a6
  76.     SYS    GetMsg
  77.     tst.l    d0    ;Did we get an IntuiMsg?
  78.     bne.b    .GotMsg
  79.  
  80.     movea.l    (wd_UserPort,a2),a0
  81.     SYS    WaitPort    ;Wait for an IntuiMsg
  82.     bra.b    .GetMsg    ;Go remove the msg
  83.  
  84. .GotMsg    movea.l    d0,a1    ;Ok, we've got an IntuiMsg
  85.     move.l    (im_Class,a1),d2    ;Extract the IDCMP class
  86.     movea.l    (im_IAddress,a1),a2 ;and the address
  87.     SYS    ReplyMsg    ;Return the msg to Intuition
  88.  
  89.     cmpi.l    #GADGETUP,d2    ;Was it a GADGETUP msg?
  90.     bne.b    .CheckDown    ;No, check next type
  91.     bsr.w    EraseText    ;Yes, process it
  92.     bra.b    .GetMsg    ;Get next msg
  93.  
  94. .CheckDown    cmpi.l    #GADGETDOWN,d2    ;Was it a GADGETDOWN msg?
  95.     bne.b    .CheckClose    ;No, check next type
  96. .Dispatch    movea.l    (gg_UserData,a2),a0 ;Get function address
  97.     jsr    (a0)    ;Do that puppy!
  98.     bra.b    .GetMsg    ;Get next msg
  99.  
  100. .CheckClose    cmpi.l    #CLOSEWINDOW,d2    ;Was it a CLOSEWINDOW msg?
  101.     bne.b    .GetMsg    ;No, keep looking for msgs
  102.             ;Fall thru to cleanup
  103. Cleanup    move.l    (_IntuitionBase-DT,a5),d0 ;Do we have a ptr to Intuition?
  104.     beq.b    .CloseFont    ;No, then we don't have a window
  105.     movea.l    d0,a6    ;Yes, get ptr into A6
  106.     move.l    (_WindowPtr-DT,a5),d0
  107.     beq.b    .CloseInt
  108.     movea.l    d0,a0
  109.     SYS    CloseWindow    ;Close the demo window
  110.  
  111. .CloseInt    movea.l    a6,a1
  112.     movea.l    (SysBase).w,a6
  113.     SYS    CloseLibrary    ;Close intuition.library
  114.  
  115. .CloseFont    move.l    (_GfxBase-DT,a5),d0
  116.     beq.b    .WBench
  117.     movea.l    d0,a6
  118.     move.l    (_FontPtr-DT,a5),d0
  119.     beq.b    .CloseGfx
  120.     movea.l    d0,a1
  121.     SYS    CloseFont
  122.  
  123. .CloseGfx    movea.l    a6,a1
  124.     movea.l    (SysBase).w,a6
  125.     SYS    CloseLibrary    ;Close graphics.library
  126.  
  127. .WBench    move.l    (_WBenchMsg-DT,a5),d2
  128.     beq.b    .Exit
  129.     movea.l    (SysBase).w,a6
  130.     SYS    Forbid    ;So WBench won't UnloadSeg() us
  131.     movea.l    d2,a1
  132.     SYS    ReplyMsg    ;Return startup msg
  133. .Exit    moveq    #0,d0    ;Always return OK
  134.     rts
  135.  
  136. ;True_Button function
  137.  
  138. Brag    moveq    #3,d0
  139.     lea    (True.txt,pc),a0
  140.     bra.b    PrintText
  141.  
  142. ;Face_Button function
  143.  
  144. Complain    moveq    #2,d0
  145.     lea    (Ouch.txt,pc),a0
  146.     bra.b    PrintText
  147.  
  148. EraseText    moveq    #0,d0
  149.     lea    (Erase.txt,pc),a0
  150.  
  151. PrintText    move.l    a0,-(sp)
  152.     movea.l    (_RastPort-DT,a5),a1
  153.     movea.l    (_GfxBase-DT,a5),a6
  154.     SYS    SetAPen
  155.  
  156.     moveq    #70,d0
  157.     moveq    #46,d1
  158.     movea.l    (_RastPort-DT,a5),a1
  159.     SYS    Move
  160.  
  161.     movea.l    (sp)+,a0
  162.     moveq    #4,d0
  163.     movea.l    (_RastPort-DT,a5),a1
  164.     SYS    Text
  165.     rts
  166.  
  167. ;False_Button function
  168.  
  169. Beep    movea.l    (_WindowPtr-DT,a5),a0
  170.     movea.l    (wd_WScreen,a0),a0
  171.     movea.l    (_IntuitionBase-DT,a5),a6
  172.     SYS    DisplayBeep
  173.     rts
  174.  
  175. MyTextAttr    dl    FontName
  176.     dw    8
  177.     db    FS_NORMAL
  178.     db    FPF_ROMFONT
  179.  
  180. MyNewWindow    dw    100,100,170,55
  181.     db    -1,-1
  182.     dl    CLOSEWINDOW!GADGETUP!GADGETDOWN
  183.     dl    WINDOWCLOSE!WINDOWDRAG!SIMPLE_REFRESH!NOCAREREFRESH!ACTIVATE
  184.     dl    True_Button
  185.     dl    0
  186.     dl    WindowTitle
  187.     dl    0,0
  188.     dw    0,0,0,0
  189.     dw    WBENCHSCREEN
  190.  
  191. True_Button    dl    Face_Button
  192.     dw    20,20,31,15
  193.     dw    GADGHCOMP
  194.     dw    GADGIMMEDIATE!RELVERIFY
  195.     dw    BOOLGADGET
  196.     dl    Button_Border,0
  197.     dl    True_ITxt
  198.     dl    0,0
  199.     dw    0
  200.     dl    Brag
  201.  
  202. True_ITxt    db    1,0,RP_JAM1,0
  203.     dw    0,20
  204.     dl    MyTextAttr,True.txt,0
  205.  
  206. Face_Button    dl    False_Button
  207.     dw    70,20,31,15
  208.     dw    GADGIMAGE!GADGHIMAGE
  209.     dw    GADGIMMEDIATE!RELVERIFY
  210.     dw    BOOLGADGET
  211.     dl    Smil