home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / LATTIC_3.LZH / WTEST / WTEST.S < prev   
Text File  |  1988-08-31  |  7KB  |  328 lines

  1.  
  2. * WERCS test program written with DevpacST version 2
  3.  
  4. * style notes:
  5. * subroutines are named in upper-case, everything else
  6. * is lower-case
  7. * low registers (d0-d2/a0-a2) are trashable, other registers
  8. * are used for parameters
  9.  
  10.     opt    a+            automatic PC mode to save bytes
  11.  
  12.     include    gemmacro.s
  13.  
  14.     include    wrsc.i
  15.  
  16. * macro to calculate object addresses
  17. OBJECT    macro    tree,object,result,scratchreg
  18.     move.w    \2,\4
  19.     mulu    #ob_sizeof,\4
  20.     lea    0(\1,\4),\3
  21.     endm
  22.  
  23. * the object structure
  24.     rsreset
  25. ob_next    rs.w    1
  26. ob_head    rs.w    1
  27. ob_tail    rs.w    1
  28. ob_type    rs.w    1
  29. ob_flags    rs.w    1
  30. ob_state    rs.w    1
  31. ob_spec    rs.l    1
  32. ob_x    rs.w    1
  33. ob_y    rs.w    1
  34. ob_width    rs.w    1
  35. ob_height    rs.w    1
  36. ob_sizeof    rs.w    0
  37.  
  38. * various AES constants
  39. type_tree    equ    0
  40. type_string    equ    5
  41. WF_WORKXYWH    equ    4
  42. WF_NEWDESK    equ    14
  43. FMD_START    equ    0
  44. FMD_GROW    equ    1
  45. FMD_SHRINK    equ    2
  46. FMD_FINISH    equ    3
  47. G_BUTTON    equ    26
  48. bitSELECTED    equ    0
  49. te_txtlen    equ    24
  50. MN_SELECTED    equ    10
  51.  
  52. * the program proper
  53.     move.l    4(a7),a3        base page
  54.     move.l    #mystack,a7
  55.     move.l    $c(a3),d0        text len
  56.     add.l    $14(a3),d0        data len
  57.     add.l    $1c(a3),d0        BSS len
  58.     add.l    #$100,d0        basepage
  59.     move.l    d0,-(sp)
  60.     move.l    a3,-(sp)
  61.     clr.w    -(sp)
  62.     move.w    #$4a,-(sp)
  63.     trap    #1            shrink memory
  64.     lea    12(sp),sp
  65.     bra    start
  66.  
  67. INITIALISE
  68.     appl_init
  69.     move.w    d0,ap_id        store the application id
  70.     rsrc_load    #rsc_filename
  71.     bne.s    rloaded_ok
  72. * resource load failed
  73.     form_alert    #1,#badrsc_alert
  74.     bra    terminate
  75. rloaded_ok
  76.     graf_mouse    #0        mouse is an arrow
  77.     sf    deskflag
  78.     rsrc_gaddr    #type_tree,#Menu1
  79.     move.l    addr_out,menu_ptr
  80.     menu_bar    menu_ptr,#1
  81.     wind_get    #0,#WF_WORKXYWH
  82.     lea    int_out+2,a0
  83.     lea    screenx,a1
  84.     REPT    4
  85.     move.w    (a0)+,(a1)+        copy screen size
  86.     ENDR
  87.     clr.b    editstring
  88.     move.w    #DRadio1,radio
  89.     rts
  90.  
  91. * set or reset the Desktop pattern
  92. * in:a3=new address
  93. SETDESK    move.l    a3,int_in+4
  94.     clr.w    int_in+8
  95.     wind_set    #0,#WF_NEWDESK
  96.     form_dial    #FMD_FINISH,#0,#0,#0,#0,screenx,screeny,screenw,screenh
  97.     rts
  98.  
  99. DEINITIALISE
  100.     tst.b    deskflag
  101.     beq.s    .nodesk
  102.         sub.l    a3,a3
  103.         bsr    SETDESK
  104.         sf    deskflag
  105. .nodesk    menu_bar    menu_ptr,#0
  106.     rsrc_free
  107. terminate
  108.     appl_exit
  109.     move.l    #$4c0000,-(sp)
  110.     trap    #1
  111.  
  112. * general routine to produce a dialog box and handle interaction
  113. * in:a3=dialog address,d3.w=editable object number
  114. * out:d3.w=exit object number
  115. HANDLE_DIALOG
  116.     movem.l    d4-d7,-(sp)        we need some local variables
  117.  
  118.     form_center    a3
  119.     movem.w    int_out+2,d4-d7        d4-d7=x,y,w,h
  120.     form_dial    #FMD_START,#0,#0,#0,#0,d4,d5,d6,d7
  121.     move.w    d6,d0
  122.     asr.w    #1,d0
  123.     add.w    d4,d0            =x+w/2
  124.     move.w    d7,d1
  125.     asr.w    #1,d1
  126.     add.w    d5,d1            =y+h/2
  127.     form_dial    #FMD_GROW,d0,d1,#0,#0,d4,d5,d6,d7
  128.     objc_draw    a3,#0,#10,d4,d5,d6,d7
  129.     form_do    a3,d3
  130.     move.w    d0,d3            return result
  131.     move.w    d6,d0
  132.     asr.w    #1,d0
  133.     add.w    d4,d0            =x+w/2
  134.     move.w    d7,d1
  135.     asr.w    #1,d1
  136.     add.w    d5,d1            =y+h/2
  137.     form_dial    #FMD_SHRINK,d0,d1,#0,#0,d4,d5,d6,d7
  138.     form_dial    #FMD_FINISH,#0,#0,#0,#0,d4,d5,d6,d7
  139.     OBJECT    a3,d3,a0,d0
  140.     cmp.b    #G_BUTTON,ob_type+1(a0)
  141.     bne.s    .notbut
  142.         bclr    #bitSELECTED,ob_state+1(a0)
  143. .notbut    movem.l    (sp)+,d4-d7
  144.     rts
  145.  
  146. * set a tedinfo record
  147. * in:a3=tree,d3.w=object,a4=source string
  148. SET_TEDINFO
  149.     OBJECT    a3,d3,a0,d0
  150.     move.l    ob_spec(a0),a0        the tedinfo record ptr
  151.     move.w    te_txtlen(a0),d2    max length
  152.     subq.w    #1,d2
  153. * copy up to d2.w chars
  154.     move.l    (a0),a0            destination buffer addr
  155. .copy    move.b    (a4)+,d0
  156.     beq.s    .done
  157.     move.b    d0,(a0)+        copy char
  158.     subq.w    #1,d2
  159.     bne.s    .copy            up to the limit
  160. .done    clr.b    (a0)
  161.     rts
  162.  
  163. * extract a tedinfo record
  164. * in:a3=tree,d3.w=object,a4=where to copy it
  165. GET_TEDINFO
  166.     OBJECT    a3,d3,a0,d0
  167.     move.l    ob_spec(a0),a0        the tedinfo record ptr
  168.     move.l    (a0),a0            the actual text
  169. .copy    move.b    (a0)+,(a4)+
  170.     bne.s    .copy
  171.     rts
  172.  
  173. * select a particular radio button
  174. * in:a3=tree,d3.w=parent,d4.w=button
  175. SET_BUTTON
  176.     OBJECT    a3,d3,a0,d0
  177.     move.w    ob_head(a0),d2
  178. .until    cmp.w    d3,d2
  179.     beq.s    .done
  180.         OBJECT    a3,d2,a0,d0
  181.         bclr    #bitSELECTED,ob_state+1(a0)
  182.         cmp.w    d4,d2
  183.         bne.s    .boring
  184.         bset    #bitSELECTED,ob_state+1(a0)
  185. .boring    move.w    ob_next(a0),d2
  186.     bra.s    .until
  187. .done    rts
  188.  
  189. * return which button of a group is selected
  190. * in:a3=tree,d3=parent
  191. * out:d3=selected button number
  192. GET_BUTTON
  193.     OBJECT    a3,d3,a0,d0
  194.     move.w    ob_head(a0),d2
  195. .until    cmp.w    d3,d2
  196.     beq.s    .done
  197.         OBJECT    a3,d2,a0,d0
  198.         btst    #bitSELECTED,ob_state+1(a0)
  199.         bne.s    .gotit            if found
  200.         move.w    ob_next(a0),d2
  201.         bra.s    .until
  202. .gotit    move.w    d2,d3                result
  203. .done    rts
  204.  
  205. * handle a particular dialog box
  206. TEST_DIALOG
  207.     movem.l    d3/d4/a3/a4,-(sp)
  208.     rsrc_gaddr    #type_tree,#TestDialog
  209.     move.l    addr_out,a3
  210.     moveq    #DEditable,d3
  211.     lea    editstring,a4
  212.     bsr    SET_TEDINFO
  213.     moveq    #DParent,d3
  214.     move.w    radio,d4
  215.     bsr    SET_BUTTON
  216.     moveq    #DEditable,d3
  217.     bsr    HANDLE_DIALOG
  218.     cmp.w    #DOK,d3
  219.     bne.s    .notok
  220.         lea    editstring,a4
  221.         moveq    #DEditable,d3
  222.         bsr    GET_TEDINFO
  223.         moveq    #DParent,d3
  224.         bsr    GET_BUTTON
  225.         move.w    d3,radio
  226. .notok    movem.l    (sp)+,d3/d4/a3/a4
  227.     rts
  228.  
  229. * handle a menu click
  230. * in:d3=title,d4=item
  231. HANDLE_MENU
  232.     cmp.w    #MAbout,d3
  233.     bne.s    .1
  234.         rsrc_gaddr    #type_string,#AAlert
  235.         form_alert    #1,addr_out
  236.         bra    .done
  237. .1    cmp.w    #MQuit,d3
  238.     bne.s    .2
  239.         st    finished
  240.         bra    .done
  241. .2    cmp.w    #MCheckme,d3
  242.     bne.s    .3
  243.         bchg    #0,checked+1
  244.         menu_icheck    menu_ptr,#MCheckme,checked
  245.         bra    .done
  246. .3    cmp.w    #MDialog,d3
  247.     bne.s    .4
  248.         bsr    TEST_DIALOG
  249.         bra    .done
  250. .4    cmp.w    #MInstall,d3
  251.     bne    .5
  252.         tst.b    deskflag
  253.         beq.s    .nodesk
  254.             sf    deskflag
  255.             sub.l    a3,a3
  256.             bsr    SETDESK
  257.             bra    .done
  258.         .nodesk:
  259.             st    deskflag
  260.             rsrc_gaddr    #0,#NewDesktop
  261.             move.l    addr_out,a0
  262.             move.w    screenx,ob_x(a0)
  263.             move.w    screeny,ob_y(a0)
  264.             move.w    screenw,ob_width(a0)
  265.             move.w    screenh,ob_height(a0)
  266.             move.l    a0,a3
  267.             bsr    SETDESK
  268.             bra    .done
  269. .5
  270. .done    menu_tnormal    menu_ptr,d4,#1
  271.     rts
  272.  
  273. * the main loop of the application
  274. * the only interesting events are messages
  275. MAIN    sf    finished
  276.     clr.w    checked
  277. .loop    evnt_mesag    #messagebuf
  278.     lea    messagebuf,a0
  279.     move.w    (a0),d0            message type
  280.     cmp.w    #MN_SELECTED,d0
  281.     bne.s    .1
  282.         move.w    8(a0),d3
  283.         move.w    6(a0),d4
  284.         bsr    HANDLE_MENU
  285. .1    tst.b    finished
  286.     beq.s    .loop
  287.     rts
  288.  
  289. start    bsr    INITIALISE
  290.     bsr    MAIN
  291.     bra    DEINITIALISE        never to return...
  292.  
  293.     SECTION    DATA
  294.  
  295. rsc_filename    dc.b    'WRSC.RSC',0
  296. badrsc_alert    dc.b    '[3][Resource file error][Quit]',0
  297.  
  298.     SECTION    BSS
  299.  
  300. * global variables
  301.  
  302. deskflag    ds.b    1
  303. finished    ds.b    1
  304. checked        ds.w    1
  305. radio        ds.w    1
  306. menu_ptr    ds.l    1
  307. * these have to remain together
  308. screenx    ds.w 1
  309. screeny    ds.w 1
  310. screenw    ds.w 1
  311. screenh    ds.w 1
  312.  
  313. ap_id        ds.w 1
  314. messagebuf    ds.b 16
  315.  
  316. editstring    ds.b    20
  317.  
  318.     ds.l    100            stack space
  319. mystack    ds.w    1            (stacks go backwards)
  320.  
  321.  
  322. * if not linking then include the run-times
  323.  
  324.     IFEQ    __LK
  325.     include    aeslib.s
  326. ***    include    vdilib.s        VDI not required
  327.     ENDC
  328.