home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / PULDOWN2.ASM < prev    next >
Assembly Source File  |  1994-10-15  |  9KB  |  356 lines

  1.     page    66,132
  2. ;******************************** PULDOWN2.ASM *******************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. ;----------------------------------------------------------------------------
  13.     extrn    dos_mem_allocate:far
  14.     extrn    dos_mem_release:far
  15.     extrn    to_upper:far
  16.     extrn    MENU_SYSTEM:far
  17. comment 
  18. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MENU   )
  19. QMENU_SYSTEM - Quick pulldown menu bar
  20. ;
  21. ;  inputs:  ds:bx = pointer to list of names.  (See list format below)
  22. ;  
  23. ;  output:  ah = main menu index, 0=first item, 1=second, etc. -1=abort key
  24. ;           al = sub menu item if present
  25. ;
  26. ;  note: The menu list is displayed on the top line of the screen and is
  27. ;        built as follows:
  28. ;               db   'main option1',0
  29. ;               db     'sub option1',0
  30. ;               db     'sub option2',0
  31. ;               db    0            ;end of main option1
  32. ;               db   'main option2',0
  33. ;               db    0            ;end of main option2
  34. ;                  .
  35. ;                  .
  36. ;               db    0            ;end of all options.
  37. ;
  38. ;         One zero between strings is a sub menu separation.
  39. ;         two zeros between strings is a new main menu item start
  40. ;         three zeros is end of all strings.
  41. ;* * * * * * * * * * * * * *
  42. 
  43. ;---------------------------
  44. qp_in_ptr    dw    0    ;input list ptr
  45. qp_in_seg    dw    0    ;input list seg
  46. qp_main_cnt    db    0    ;number of main menu items
  47. qp_sub_cnt    db    0    ;number of sub menu's
  48. qp_text_sz    dw    0    ;text strings
  49.  
  50. qp_main_ptr    dw    0    ;ptr to main entry structure
  51. qp_sub_ptr    dw    0    ;ptr to next sub menu struc
  52. qp_text_ptr    dw    0    ;ptr to next text definition
  53.  
  54. ;---------------------------
  55.     public    QMENU_SYSTEM
  56. QMENU_SYSTEM    PROC    FAR
  57.     apush    bx,cx,dx,si,di,bp,ds,es
  58.     cld
  59.     mov    cs:qp_in_ptr,bx
  60.     mov    cs:qp_in_seg,ds
  61.     sub    ax,ax                ;setup to count menu items
  62.     mov    word ptr cs:qp_main_cnt,ax
  63.     mov    cs:qp_text_sz,ax
  64. qp_lp1:    call    next_option
  65.     add    cs:qp_text_sz,cx
  66.     cmp    ah,1
  67.     jne    qp_1                ;jmp if not main menu item
  68.     inc    cs:qp_main_cnt
  69. qp_1:    cmp    ah,2
  70.     jne    qp_2                ;jmp if not sub menu
  71.     inc    cs:qp_sub_cnt
  72. qp_2:    cmp    ah,0
  73.     jne    qp_lp1                ;jmp if still counting
  74. ;
  75. ; compute amount of memory needed to build menu structure
  76. ;
  77.     mov    ah,size menu_def
  78.     mov    al,cs:qp_main_cnt
  79.     add    al,cs:qp_sub_cnt
  80.     inc    al
  81.     mul    ah            ;ax = memory for option struc's
  82.     add    ax,cs:qp_text_sz
  83.     add    ax,cs:qp_text_sz
  84. ;
  85. ; allocate -ax- bytes to hold structures
  86. ;
  87.     mov    dx,0                ;allocate dx,ax bytes
  88.     call    dos_mem_allocate        ;returns seg in -es-
  89.     jc    qp_err                ;jmp if no memory
  90. ;
  91. ; clear the memory area
  92. ;
  93.     mov    cx,ax                ;cx = length of alocated memory
  94.     mov    di,0                ;memory offset
  95.     mov    al,0
  96.     rep    stosb                ;clear block
  97. ;
  98. ; compute start of major structure sections
  99. ;
  100.     mov    ax,offset m_main01
  101.     mov    qp_main_ptr,ax            ;set ptr to first main entry
  102.  
  103.     mov    ah,size menu_def
  104.     mov    al,cs:qp_main_cnt
  105.     mul    ah
  106.     add    ax,offset m_main01
  107.     mov    qp_sub_ptr,ax            ;set ptr to first sub menu
  108.  
  109.     mov    ah,size menu_def
  110.     mov    al,cs:qp_sub_cnt
  111.     mul    ah
  112.     add    ax,qp_sub_ptr
  113.     mov    qp_text_ptr,ax            ;set ptr to text area
  114. ;
  115. ; fill in the structure header fields
  116. ;   registers:  ds:  = callers segment
  117. ;               es:  = assigned memory segment
  118. ;
  119.     mov    es:[m_rows],1
  120.     mov    es:[m_columns],80
  121.     
  122. ;
  123. ; setup to fill in the main & sub structures
  124. ;
  125.     mov    bx,cs:qp_in_ptr
  126.     mov    ax,0
  127.     
  128. qp_lp2:    call    next_option
  129.     cmp    ah,0
  130.     je    qp_done2        ;jmp if all done
  131.     push    ax
  132.     cmp    ah,2
  133.     je    qp_set_sub        ;jmp if sub option found
  134. ;
  135. ; ** main menu text found: registers  dx:si=start of text  ds:bx=next parse
  136. ;                                        cx=length of text
  137.     mov    di,qp_main_ptr
  138. ;
  139. ; compute main menu item hot key
  140. ;    
  141.          mov    al,byte ptr [si]    ;get first letter of text
  142.     mov    ah,0
  143.     call    to_upper
  144.     sub    al,'A'
  145.     add    ax,offset hot_key_tbl
  146.     mov    bp,ax
  147.     mov    al,byte ptr cs:[bp]    ;look up hot key
  148.     mov    es:[di.e_hot_key],al
  149. ;
  150. ;store length of text string
  151. ;
  152.     mov    es:[di.e_length],cl
  153. ;
  154.     mov    ax,qp_text_ptr        ;get next text store ptr
  155.     mov    es:[di.e_text_ptr],ax
  156.     call    move_text        ;move text and update ptr
  157. ;
  158. ; set process ptr
  159. ;
  160.     mov    ax,word ptr es:[m_options]
  161.     mov    es:[di.e_process],ax
  162.     inc    es:[m_options]
  163. ;
  164. ; setup the column
  165. ;
  166.     cmp    es:[m_options],1    ;check if first entry
  167.     jne    qp_5            ; jmp if not first entry
  168.     mov    al,1
  169.     jmp    qp_6
  170. qp_5:    mov    al,es:[di.e_column - size menu_entry] ;get previous column
  171.     add    al,es:[di.e_length - size menu_entry]
  172.     add    al,2            ;two spaces
  173. qp_6:    mov    es:[di.e_column],al    ;store new column
  174.          add    cs:qp_main_ptr,size menu_entry
  175.     pop    ax            ;restore next_option info.
  176.     jmp    qp_lp2
  177. ;
  178. ; ** sub menu text found: registers  ds:si=start of text  ds:bx=next parse
  179. ;                                       cx=length of text
  180. ;                                    es:di=main menu struc
  181. ;
  182. qp_set_sub:
  183.     push    bx
  184.     mov    bx,cs:qp_sub_ptr
  185. ;
  186. ; compute length of sub menu box
  187. ;
  188.     add    cl,2    
  189.     cmp    byte ptr es:[di.e_sub_length],cl ;check if text will fit in box
  190.     jae    qp_7            ;jmp if text will fit
  191.     mov    byte ptr es:[di.e_sub_length],cl ;enlarge box
  192. qp_7:    sub    cl,2    
  193.     
  194.     mov    es:[bx.e_length],cl
  195.     mov    ax,qp_text_ptr        ;get next text store ptr
  196.     mov    es:[bx.e_text_ptr],ax
  197.     call    move_text        ;move text and update ptr
  198.  
  199. ;
  200. ; set process ptr
  201. ;
  202.     cmp    es:[di.e_count],0    ;check if this is the first
  203.     jne    qp_08            ;  jmp if not first
  204.     mov    ax,es:[di.e_process]    ;get origional process ptr
  205.     mov    es:[di.e_process],bx    ;replace process count with sub ptr
  206.     xchg    al,ah
  207.     mov    al,[di.e_count]
  208.     jmp    qp_09
  209.     
  210. qp_08:    mov    ax,word ptr es:[bx.e_process-size menu_entry] ;get prev sub
  211.     inc    al            ;bump sub menu count
  212. qp_09:    mov    es:[bx.e_process],ax
  213.  
  214.     add    al,2
  215.     mov    es:[bx.e_row],al    ;store row
  216.  
  217.     mov    al,es:[di.e_column]    ;get main column
  218.     inc    al
  219.     mov    es:[bx.e_column],al
  220.  
  221. qp_11:    
  222.     add    qp_sub_ptr,size menu_entry
  223.     inc    byte ptr es:[di.e_count]    ;count sum menu entries
  224.     pop    bx
  225.     pop    ax                ;restore next_option info
  226.     jmp    qp_lp2
  227. qp_done2:
  228. ;
  229. ; we have built the data block, now call pulldown
  230. ;
  231.     mov    ax,es
  232.     mov    ds,ax
  233.     mov    bx,0
  234.     mov    ah,bar_save+bar_restore+bar_display+wait_valid_key
  235.     call    MENU_SYSTEM
  236.     push    ax
  237.     call    dos_mem_release
  238.     pop    ax
  239. qp_err:
  240.     apop    es,ds,bp,di,si,dx,cx,bx    
  241.     retf
  242. QMENU_SYSTEM    ENDP
  243. ;---------------------------
  244. hot_key_tbl    label    byte
  245.     db    30    ;a
  246.     db    48    ;b
  247.     db    46    ;c
  248.     db    32    ;d
  249.     db    18    ;e
  250.     db    33    ;f
  251.     db    34    ;g
  252.     db    35    ;h
  253.     db    23    ;i
  254.     db    36    ;j
  255.     db    37    ;k
  256.     db    38    ;L
  257.     db    50    ;m
  258.     db    49    ;n
  259.     db    24    ;o
  260.     db    25    ;p
  261.     db    16    ;q
  262.     db    19    ;r
  263.     db    31    ;s
  264.     db    20    ;t
  265.     db    22    ;u
  266.     db    47    ;v
  267.     db    17    ;w
  268.     db    45    ;x
  269.     db    21    ;y
  270.     db    44    ;z
  271. ;---------------------------
  272. ; move_text
  273. ;  inputs:  es:ax = text store point
  274. ;              cx = text length
  275. ;           ds:si = text source ptr
  276. ;
  277. move_text:
  278.     apush    cx,si,di
  279.     mov    di,ax
  280.     rep    movsb
  281.     mov    byte ptr es:[di],0
  282.     inc    di
  283.     mov    cs:qp_text_ptr,di
  284.     apop    di,si,cx
  285.     ret
  286. ;---------------------------
  287. ; get next option and return flags
  288. ;   inputs: ds:bx = current option ptr, or next process ptr if continuation
  289. ;              ah = should be set to zero on first call, then the state
  290. ;                   preserved until done.
  291. ;   output: ds:bx points past zero at end of option
  292. ;              ah = 0 end of options
  293. ;                   1 current option is main (ds:si)
  294. ;                   2 current option is sub (ds:si)
  295. ;              cx = length of current option (ds:si)
  296. ;              si = state of -bx- at entry, or start of current option
  297. ;              bx = next parse point
  298. ;
  299. next_option:
  300.     push    es
  301.     mov    si,bx
  302.     push    ds
  303.     pop    es
  304.     cmp    ah,1
  305.     je    n_main        ;jmp if main menu item was previous
  306.     jb    n_main3        ;jmp if this is first entry
  307. ;
  308. ; previous menu item was a sub menu
  309. ;
  310.     lodsb            ;get next char
  311.     cmp    al,0
  312.     jne    n_cont2        ;continuing sub menu selection
  313.     jmp    n_main2
  314. ;
  315. ; assume we are scanning a main option
  316. ;
  317. n_main:    lodsb            ;get next char
  318.     cmp    al,0        ;check if submenu next
  319.     jne    sub_state1    ;jmp if start of sub menu option
  320. ;
  321. ; we either have another main option next, or this is the end
  322. ;
  323. n_main2:inc    bx        ;move past zero
  324. n_main3:lodsb
  325.     cmp    al,0
  326.     jne    n_cont1        ;jmp if main menu item next
  327.     mov    ah,0
  328.     jmp    n_exit        ;jmp if end of options
  329. ;
  330. ; the next option is a main menu item
  331. ;
  332. n_cont1:mov    ah,1
  333.     jmp    n_cont2
  334. ;
  335. ; we are transiting from a main to a sub menu
  336. ;
  337. sub_state1:
  338.     mov    ah,2
  339.     jmp    n_cont2
  340. ;
  341. ; continuation of sub menu extraction
  342. n_cont2:mov    cx,0
  343. n_cont3:lodsb
  344.     inc    cx
  345.     cmp    al,0
  346.     jne    n_cont3        ;loop till end of option found
  347.     
  348. n_exit:    xchg    si,bx
  349.     pop    es
  350.     ret
  351. ;--------------------------------------------------------------------------
  352.  
  353. LIBSEG    ENDS
  354.     end
  355.