home *** CD-ROM | disk | FTP | other *** search
/ Dream 41 / Amiga_Dream_41.iso / Amiga / Programmation / assembleur / proasm192.lha / ProAsm / routines / gtfsupport.r < prev    next >
Encoding:
Text File  |  1996-09-07  |  14.1 KB  |  851 lines

  1.  
  2. ;---;  gtfsupport.r  ;---------------------------------------------------------
  3. *
  4. *    ****    VARIOUS GTFACE SUPPORT ROUTINES    ****
  5. *
  6. *    Author        Stefan Walter
  7. *    Version        1.03b
  8. *    Last Revision    31.09.96
  9. *    Notes        demands calls with CALL_ macro
  10. *    Identifier    gfs_defined
  11. *    Prefix        gfs_    (GTFace support)
  12. *                 » »    »
  13. *    Functions    AllocLVNode, AllocLVNodeRaw, FreeLVNode
  14. *            AddHeadLVNode, AddTailLVNode, RemHeadLVNode
  15. *            RemTailLVNode, RemoveLVNode, FreeLVList.
  16. *
  17. *            SetGadgetTag,SetLVLabels,RemoveLVLabels,
  18. *            ChangeLVLabels, SetCYActive, GetLVLabels
  19. *            ActivateGadget, OnMenu, OffMenu, FindLVNode,
  20. *            FindLVNodeMsg.
  21. *
  22. *            StringHistoryHookFunction
  23. *
  24. ;------------------------------------------------------------------------------
  25.  
  26. ;------------------
  27.     ifnd    gfs_defined
  28. gfs_defined    =1
  29.  
  30. ;------------------
  31. ; Some macros.
  32. ;
  33.     include    basicmac.r
  34.     include    tasktricks.r
  35.  
  36.  
  37.  
  38.  
  39. ;------------------------------------------------------------------------------
  40. *
  41. * AllocLVNodeRaw    Allocate a listview node due to a string generated
  42. *            with RawDoFmt(). The string is copied.
  43. *
  44. * INPUT:    a0    Format string.
  45. *        a1    Raw data.
  46. *        d0    Number of bytes to add after node structure.
  47. *
  48. * RESULT:    d0    Node or 0.
  49. *        a0    Node or 0.
  50. *        ccr    On d0.
  51. *
  52. ;------------------------------------------------------------------------------
  53.  
  54. ;------------------
  55.     IFD    xxx_AllocLVNodeRaw
  56. AllocLVNodeRaw:
  57.  
  58. ;------------------
  59. ; Start.
  60. ;
  61. \start:    movem.l    d1-d7/a1-a6,-(sp)
  62.     move.l    d0,d5
  63.     move.l    a0,a3
  64.     move.l    a1,a4
  65.     DoRawCnt_
  66.  
  67.     add.l    d5,d0
  68.     moveq    #14,d1
  69.     add.l    d1,d0    
  70.  
  71.     moveq    #1,d1            ;even VMem allowed!
  72.     swap    d1            ;clear!
  73.     move.l    4.w,a6
  74.     jsr    -198(a6)        ;AllocMem()
  75.     tst.l    d0
  76.     beq.s    \done
  77.  
  78.     move.l    d0,a2
  79.     move.l    a3,a0
  80.     move.l    a4,a1
  81.     lea    14(a2,d5.l),a3
  82.     move.l    a3,10(a2)
  83.     
  84.     DoRaw_
  85.  
  86. \done:    move.l    d0,a0
  87.     move.l    a0,d0            ;set ccr
  88.     movem.l    (sp)+,d1-d7/a1-a6
  89.     rts
  90.  
  91.     ENDIF
  92. ;------------------
  93.  
  94.  
  95.  
  96.  
  97. ;------------------------------------------------------------------------------
  98. *
  99. * AllocLVNode    Allocate a listview node. The node will contain a selected
  100. *        number of bytes after the node structure and a string that is
  101. *        copied.
  102. *
  103. * INPUT:    a0    String (will appear in the listview gadget).
  104. *        d0    Number of bytes to add after node structure.
  105. *
  106. * RESULT:    d0    Node or 0.
  107. *        a0    Node or 0
  108. *        ccr    On d0.
  109. *
  110. ;------------------------------------------------------------------------------
  111.  
  112. ;------------------
  113.     IFD    xxx_AllocLVNode
  114. AllocLVNode:
  115.  
  116. ;------------------
  117. ; Start.
  118. ;
  119. \start:    movem.l    d1-d7/a1-a6,-(sp)
  120.     move.l    a0,a2
  121.     move.l    d0,d7
  122.     moveq    #14,d0            ;LN_SIZEOF
  123.     add.l    d7,d0            ;+ desired number of bytes
  124. \loop:    addq.l    #1,d0            ;+ string size
  125.     tst.b    (a0)+
  126.     bne.s    \loop
  127.  
  128.     moveq    #1,d1            ;even VMem allowed!
  129.     swap    d1            ;clear!
  130.     move.l    4.w,a6
  131.     jsr    -198(a6)        ;AllocMem()
  132.     tst.l    d0
  133.     beq.s    \done
  134.  
  135.     move.l    d0,a0
  136.     lea    14(a0,d7.l),a1
  137.     move.l    a1,10(a0)
  138. \loop2:    move.b    (a2)+,(a1)+        ;copy string...
  139.     bne.s    \loop2
  140.     tst.l    d0
  141.  
  142. \done:    move.l    d0,a0
  143.     movem.l    (sp)+,d1-d7/a1-a6
  144.     rts
  145.  
  146.     ENDIF
  147. ;------------------
  148.  
  149.  
  150.  
  151.  
  152. ;------------------------------------------------------------------------------
  153. *
  154. * FreeLVList    Remove the entier listview list and free all nodes.
  155. *
  156. * INPUT:    a0    List.
  157. *        a2    WindowKey.
  158. *        a3    Gadget.
  159. *
  160. ;------------------------------------------------------------------------------
  161.  
  162. ;------------------
  163.     IFD    xxx_FreeLVList
  164. FreeLVList:
  165.  
  166. ;------------------
  167. ; Start.
  168. ;
  169. \start:    movem.l    d0-a6,-(sp)
  170.     move.l    a0,a4
  171.     move.l    a3,a0
  172.     CALL_    RemoveLVLabels
  173.     move.l    4.w,a6
  174. \loop:    move.l    a4,a0
  175.     jsr    -258(a6)        ;RemHead()
  176.     tst.l    d0
  177.     beq.s    \done
  178.     move.l    d0,a0
  179.     CALL_    FreeLVNode
  180.     bra.s    \loop
  181. \done:    movem.l    (sp)+,d0-a6
  182.     rts
  183.  
  184.     ENDIF
  185. ;------------------
  186.  
  187.  
  188.  
  189.  
  190. ;------------------------------------------------------------------------------
  191. *
  192. * FreeLVNode    Free a previously generated listview node.
  193. *
  194. * INPUT:    a0    Node.
  195. *
  196. ;------------------------------------------------------------------------------
  197.  
  198. ;------------------
  199.     IFD    xxx_FreeLVNode
  200. FreeLVNode:
  201.  
  202. ;------------------
  203. ; Start.
  204. ;
  205. \start:    movem.l    d0-a6,-(sp)
  206.     move.l    10(a0),a2
  207. \loop:    tst.b    (a2)+
  208.     bne.s    \loop
  209.     move.l    a2,d0
  210.     sub.l    a0,d0            ;size: from node to end of string
  211.     move.l    a0,a1
  212.     move.l    4.w,a6
  213.     jsr    -210(a6)        ;FreeMem()
  214.     movem.l    (sp)+,d0-a6
  215.     rts
  216.  
  217.     ENDIF
  218. ;------------------
  219.  
  220.  
  221.  
  222.  
  223. ;------------------------------------------------------------------------------
  224. *
  225. * AddHeadLVNode    Add a listview node at the head of the list.
  226. *
  227. * INPUT:    a0    List.
  228. *        a1    Node.
  229. *        a2    WindowKey.
  230. *        a3    Gadget.
  231. *
  232. ;------------------------------------------------------------------------------
  233.  
  234. ;------------------
  235.     IFD    xxx_AddHeadLVNode
  236. AddHeadLVNode:
  237.  
  238. ;------------------
  239. ; Start.
  240. ;
  241. \start:    movem.l    d0-a6,-(sp)
  242.     move.l    a0,a4
  243.     move.l    a3,a0
  244.     CALL_    RemoveLVLabels
  245.     move.l    a4,a0
  246.     move.l    4.w,a6
  247.     jsr    -240(a6)        ;AddHead()
  248.     move.l    a4,d0
  249.     CALL_    SetLVLabels
  250.     movem.l    (sp)+,d0-a6
  251.     rts
  252.  
  253.     ENDIF
  254. ;------------------
  255.  
  256.  
  257.  
  258.  
  259. ;------------------------------------------------------------------------------
  260. *
  261. * AddTailLVNode    Add a listview node at the tail of the list.
  262. *
  263. * INPUT:    a0    List.
  264. *        a1    Node.
  265. *        a2    WindowKey.
  266. *        a3    Gadget.
  267. *
  268. ;------------------------------------------------------------------------------
  269.  
  270. ;------------------
  271.     IFD    xxx_AddTailLVNode
  272. AddTailLVNode:
  273.  
  274. ;------------------
  275. ; Start.
  276. ;
  277. \start:    movem.l    d0-a6,-(sp)
  278.     move.l    a0,a4
  279.     move.l    a3,a0
  280.     CALL_    RemoveLVLabels
  281.     move.l    a4,a0
  282.     move.l    4.w,a6
  283.     jsr    -246(a6)        ;AddTail()
  284.     move.l    a4,d0
  285.     move.l    a3,a0
  286.     CALL_    SetLVLabels
  287.     movem.l    (sp)+,d0-a6
  288.     rts
  289.  
  290.     ENDIF
  291. ;------------------
  292.  
  293.  
  294.  
  295.  
  296. ;------------------------------------------------------------------------------
  297. *
  298. * RemHeadLVNode    Remove first node of a listview gadget.
  299. *
  300. * INPUT:    a0    List.
  301. *        a1    Node.
  302. *        a2    WindowKey.
  303. *        a3    Gadget.
  304. *
  305. ;------------------------------------------------------------------------------
  306.  
  307. ;------------------
  308.     IFD    xxx_RemHeadLVNode
  309. RemHeadLVNode:
  310.  
  311. ;------------------
  312. ; Start.
  313. ;
  314. \start:    pea    (a1)
  315.     move.l    (a0),a1
  316.     tst.l    (a1)            ;empty?
  317.     beq.s    \done
  318.     CALL_    RemoveLVNode
  319. \done:    move.l    (sp)+,a1
  320.     rts
  321.  
  322.     ENDIF
  323. ;------------------
  324.  
  325.  
  326.  
  327.  
  328. ;------------------------------------------------------------------------------
  329. *
  330. * RemTailLVNode    Remove last node of a listview gadget.
  331. *
  332. * INPUT:    a0    List.
  333. *        a1    Node.
  334. *        a2    WindowKey.
  335. *        a3    Gadget.
  336. *
  337. ;------------------------------------------------------------------------------
  338.  
  339. ;------------------
  340.     IFD    xxx_RemTailLVNode
  341. RemTailLVNode:
  342.  
  343. ;------------------
  344. ; Start.
  345. ;
  346. \start:    pea    (a1)
  347.     move.l    8(a0),a1
  348.     tst.l    4(a1)            ;empty?
  349.     beq.s    \done
  350.     CALL_    RemoveLVNode
  351. \done:    move.l    (sp)+,a1
  352.     rts
  353.  
  354.     ENDIF
  355. ;------------------
  356.  
  357.  
  358.  
  359.  
  360. ;------------------------------------------------------------------------------
  361. *
  362. * RemoveLVNode    Remove a listview node from the gadget.
  363. *
  364. * INPUT:    a0    List.
  365. *        a1    Node.
  366. *        a2    WindowKey.
  367. *        a3    Gadget.
  368. *
  369. ;------------------------------------------------------------------------------
  370.  
  371. ;------------------
  372.     IFD    xxx_RemoveLVNode
  373. RemoveLVNode:
  374.  
  375. ;------------------
  376. ; Start.
  377. ;
  378. \start:    movem.l    d0-a6,-(sp)
  379.     move.l    a0,a4
  380.     move.l    a3,a0
  381.     CALL_    RemoveLVLabels
  382.     move.l    4.w,a6
  383.     jsr    -252(a6)        ;Remove()
  384.     exg.l    a4,d0
  385.     move.l    a3,a0
  386.     CALL_    SetLVLabels
  387.     movem.l    (sp)+,d0-a6
  388.     rts
  389.  
  390.     ENDIF
  391. ;------------------
  392.  
  393.  
  394.  
  395.  
  396.  
  397. ;--------------------------------------------------------------------
  398. *
  399. * ActivateGadget    Activate a gadget.
  400. *
  401. * INPUT:    a0    Gadget.
  402. *        a2    WindowKey.
  403. *
  404. ;--------------------------------------------------------------------
  405.  
  406. ;------------------
  407.  
  408.     IFD    xxx_ActivateGadget
  409. ActivateGadget:
  410.     movem.l    d0-a6,-(sp)
  411.     move.l    (a2),a1
  412.     suba.l    a2,a2
  413.     move.l    gtf_intbase(pc),a6
  414.     jsr    -462(a6)        ;ActivateGadget()
  415.     movem.l    (sp)+,d0-a6
  416.     rts
  417.  
  418.     ENDIF
  419. ;------------------
  420.  
  421.  
  422.  
  423.  
  424. ;--------------------------------------------------------------------
  425. *
  426. * OnMenu    Activate or deactivate menu strip, title, item or subitem.
  427. * OffMenu
  428. *
  429. * INPUT:    d0    *_mn ID number of object.
  430. *        a2    WindowKey.
  431. *
  432. ;--------------------------------------------------------------------
  433.  
  434. ;------------------
  435.  
  436.     IFD    xxx_OnMenu
  437. OnMenu:    movem.l    d0-a6,-(sp)
  438.     move.l    (a2),a0
  439.     move.l    gtf_intbase(pc),a6
  440.     jsr    -192(a6)        ;OnMenu()
  441.     movem.l    (sp)+,d0-a6
  442.     rts
  443.  
  444.     ENDIF
  445. ;------------------
  446.  
  447.     IFD    xxx_OffMenu
  448. OffMenu:
  449.     movem.l    d0-a6,-(sp)
  450.     move.l    (a2),a0
  451.     move.l    gtf_intbase(pc),a6
  452.     jsr    -180(a6)        ;OffMenu()
  453.     movem.l    (sp)+,d0-a6
  454.     rts
  455.  
  456.     ENDIF
  457. ;------------------
  458.  
  459.  
  460.  
  461.  
  462. ;--------------------------------------------------------------------
  463. *
  464. * Different Gadget modification routines.
  465. *
  466. * INPUT:    a0    Gadget.
  467. *        d0    Tag data.
  468. *        a2    WindowKey.
  469. *
  470. * RESULT:    d1    Tag number.
  471. *
  472. ;--------------------------------------------------------------------
  473.  
  474. ;------------------
  475.  
  476.     IFD    xxx_EnableGadget
  477. EnableGadget:
  478. xxx_SetGadgetTag    SET    1
  479.     move.l    #GA_Disabled,d1
  480.     moveq    #0,d0
  481.     bra    SetGadgetTag
  482.     ENDIF
  483.  
  484.  
  485.     IFD    xxx_DisableGadget
  486. DisableGadget:
  487. xxx_SetGadgetTag    SET    1
  488.     move.l    #GA_Disabled,d1
  489.     moveq    #-1,d0
  490.     bra    SetGadgetTag
  491.     ENDIF
  492.  
  493.  
  494.     IFD    xxx_RemoveLVLabels
  495. RemoveLVLabels:
  496. xxx_SetGadgetTag    SET    1
  497.     move.l    #GTLV_Labels,d1
  498.     moveq    #-1,d0
  499.     bra    SetGadgetTag
  500.     ENDIF
  501.  
  502.  
  503.     IFD    xxx_ChangeLVLabels
  504. ChangeLVLabels:
  505. xxx_SetLVLabels        SET    1
  506.     move.l    d0,-(sp)
  507.     CALL_    RemoveLVLabels
  508.     move.l    (sp)+,d0
  509.     ENDIF
  510.  
  511.  
  512.     IFD    xxx_SetLVLabels
  513. SetLVLabels:
  514. xxx_SetGadgetTag    SET    1
  515.     move.l    #GTLV_Labels,d1
  516.     bra    SetGadgetTag
  517.     ENDIF
  518.  
  519.  
  520.     IFD    xxx_SetCYActive
  521. SetCYActive:
  522. xxx_SetGadgetTag    SET    1
  523.     move.l    #GTCY_Active,d1
  524.     bra    SetGadgetTag
  525.     ENDIF
  526.     
  527.  
  528.     IFD    xxx_GetLVLabel
  529. GetLVLabel:
  530.     movem.l    d1/a0,-(sp)
  531.     move.w    d0,d1
  532.     move.l    (a0),d0
  533.  
  534. \loop:    move.l    d0,a0
  535.     move.l    (a0),d0
  536.     beq.s    \no
  537.     subq.w    #1,d1
  538.     bhs.s    \loop
  539.     move.l    a0,d0
  540.  
  541. \no:    tst.l    d0
  542.     movem.l    (sp)+,d1/a0
  543.     rts
  544.     ENDIF
  545.  
  546.  
  547. ;------------------
  548.  
  549.  
  550.  
  551.  
  552.  
  553. ;--------------------------------------------------------------------
  554. *
  555. * SetGadgetTag    Call GT_SetGadgetAttrs with one tag.
  556. *
  557. * INPUT:    a0    Gadget
  558. *        d0    Tag data
  559. *        d1    Tag Number
  560. *        a2    WindowKey.
  561. *
  562. ;--------------------------------------------------------------------
  563.  
  564. ;------------------
  565.     IFD    xxx_SetGadgetTag
  566. SetGadgetTag:
  567. xxx_gtf_tagspace    SET    1
  568.  
  569. ;------------------
  570. ; Do!
  571. ;
  572. \do:    movem.l    d0-a6,-(sp)
  573.     move.l    gfw_window(a2),a1
  574.     suba.l    a2,a2
  575.     lea    gtf_tagspace+12(pc),a3
  576.     clr.l    -(a3)
  577.     move.l    d0,-(a3)
  578.     move.l    d1,-(a3)
  579.     move.l    gtf_gadtoolsbase(pc),a6
  580.     jsr    -42(a6)            ;GT_SetGadgetAttrsA()
  581.     movem.l    (sp)+,d0-a6
  582.     rts
  583.  
  584.     ENDIF
  585. ;------------------
  586.  
  587.  
  588.  
  589.  
  590. ;--------------------------------------------------------------------
  591. *
  592. * FindLVNode    Find Listview node.
  593. * FindLVNodeMsg    Find Listview node that is stated in gfw_msgcode.
  594. *
  595. * INPUT:    a0    List.
  596. *        d0    Number.
  597. *        a2    WindowKey (only for FindLVNodeMsg).
  598. *
  599. * RESULT:    d0    Node or 0.
  600. *        a0    Same as d0.
  601. *        ccr    On d0.
  602. *
  603. ;--------------------------------------------------------------------
  604.  
  605. ;------------------
  606.     IFD    xxx_FindLVNodeMsg
  607.     move.w    gfw_msgcode(a2),d0
  608. xxFindLVNode    SET    1
  609.  
  610.     ENDC
  611.  
  612. ;------------------
  613.     IFD    xxx_FindLVNode
  614. FindLVNode:
  615.  
  616. ;------------------
  617. ; Do!
  618. ;
  619. \do:    move.l    (a0),a0
  620.  
  621. \loop:    tst.l    (a0)
  622.     beq.s    \notfound
  623.     tst.w    d0
  624.     beq.s    \found
  625.     subq.w    #1,d0
  626.     move.l    (a0),a0
  627.     bra.s    \loop
  628.  
  629. \found:    move.l    a0,d0
  630.     rts
  631.  
  632. \notfound:
  633.     moveq    #0,d0
  634.     rts
  635.  
  636.     ENDC
  637.  
  638.  
  639. ;--------------------------------------------------------------------
  640. *
  641. * Historyfunction for Stringgadgets.
  642. *
  643. * You'll need to declare this with 'NEED_ StringHistoryHookFunction'
  644. *
  645. ;--------------------------------------------------------------------
  646.  
  647. ;------------------
  648.     IFD    xxx_StringHistoryHookFunction
  649.  
  650.     rsreset
  651. gtfh_buffer    rs.l    1
  652. gtfh_buflen    rs.l    1
  653. gtfh_bufusage    rs.l    1
  654. gtfh_start    rs.l    1
  655. gtfh_counter    rs.l    1
  656. gtfh_current    rs.l    1
  657. gtfh_SIZEOF    rsval
  658.  
  659. ;
  660. ; HistoryHook_    StringHistStruct
  661. ;
  662. HistoryHook_    MACRO
  663.     dc.l    0,0
  664.     dc.l    StringHistoryHookFunction
  665.     dc.l    0
  666.     dc.l    \1
  667.     ENDM
  668.  
  669.  
  670. ;
  671. ; StringHistoryStruct_    Buffer,BufferSize
  672. ;
  673. StringHistoryStruct_    MACRO
  674.     dc.l    \1
  675.     dc.l    \2
  676.     dc.l    0,0,0,0
  677.     ENDM
  678.  
  679.  
  680. StringHistoryHookFunction:
  681.  
  682. ;------------------
  683. ; Hook.
  684. ;
  685. ;    A0 - pointer to hook itself
  686. ;    A1 - pointer to parameter packet ("message")
  687. ;    A2 - Hook specific address data ("object," e.g, gadget )
  688. ;
  689. \start:    moveq    #0,d0
  690.     cmp.l    #SGH_KEY,(a1)
  691.     bne.s    \done
  692.     movem.l    d3/a3/a4,-(sp)
  693.     move.l    16(a0),a3
  694.     move.l    sgw_Actions(a2),d3
  695.     btst    #SGAB_END,d3
  696.     bne.s    \remember
  697.     move.l    sgw_IEvent(a2),a4
  698.     cmp.b    #$4c,7(a4)
  699.     beq.s    \prev    
  700.     cmp.b    #$4d,7(a4)
  701.     beq.s    \next
  702. \no:    movem.l    (sp)+,d3/a3/a4
  703. \done:    rts
  704.  
  705. \remember:
  706.     bsr.s    \addtohist
  707. \do:    moveq    #-1,d0
  708.     bra.s    \no
  709.  
  710. \prev:    bsr    \historyrew
  711.     bra.s    \do
  712. \next:    bsr    \historyfwd
  713.     bra.s    \do
  714.  
  715.  
  716. ;------------------
  717. ; Add to history buffer
  718. ;
  719. ;    a3:    History Info Block.
  720. ;    a2:    SGWork.
  721. ;
  722. \addtohist:
  723.     movem.l    d0/d1/d7/a0/a1/a4/a5,-(sp)
  724.     move.l    gtfh_buffer(a3),a4    ;start of buffer
  725.     move.l    a4,a5
  726.     move.l    gtfh_buflen(a3),d7    ;length of buffer
  727.     add.l    d7,a5            ;end of buffer
  728.     moveq    #0,d0
  729.     move.w    sgw_NumChars(a2),d0
  730.     beq.s    \fin
  731.     move.w    #254,d1
  732.     cmp.w    d1,d0
  733.     bls.s    1$
  734.     move.w    d1,d0            ;limit to 254+1 (for len)
  735. 1$:    move.l    gtfh_bufusage(a3),d1
  736.     add.l    d0,d1
  737.     addq.l    #1,d1
  738.     cmp.l    d7,d1
  739.     bls.s    \norem
  740.     move.l    a4,a0            ;free last entry and try again
  741.     add.l    gtfh_start(a3),a0
  742.     moveq    #0,d1
  743.     move.b    (a0),d1
  744.     add.l    d1,a0
  745.     bsr.s    \historylimit
  746.     sub.l    a4,a0
  747.     move.l    a0,gtfh_start(a3)
  748.     sub.l    d1,gtfh_bufusage(a3)
  749.     subq.l    #1,gtfh_counter(a3)
  750.     bra.s    1$
  751.  
  752. \norem:    addq.l    #1,gtfh_counter(a3)
  753.     move.l    a4,a0
  754.     add.l    gtfh_bufusage(a3),a0
  755.     add.l    gtfh_start(a3),a0
  756.     move.l    d1,gtfh_bufusage(a3)
  757.  
  758.     bsr.s    \historylimit
  759.     move.b    d0,(a0)
  760.     addq.b    #1,(a0)+
  761.     move.l    sgw_WorkBuffer(a2),a1
  762. \loop:    bsr.s    \historylimit
  763.     move.b    (a1)+,(a0)+
  764.     subq.b    #1,d0
  765.     bne.s    \loop
  766.  
  767. \fin:    clr.l    gtfh_current(a3)
  768.     movem.l    (sp)+,d0/d1/d7/a0/a1/a4/a5
  769.     rts
  770.  
  771. \historylimit:
  772.     cmp.l    a4,a0
  773.     bhs.s    \nl1
  774.     add.l    d7,a0
  775. \nl1:    cmp.l    a5,a0
  776.     blo.s    \nl2
  777.     sub.l    d7,a0
  778. \nl2:    rts
  779.  
  780.  
  781.  
  782. ;------------------
  783. ; Go one forth in command history.
  784. ; If nothing to go forth, clear line.
  785. ;
  786. \historyfwd:
  787.     tst.l    gtfh_current(a3)
  788.     beq.s    \gethistory
  789.     subq.l    #1,gtfh_current(a3)
  790.     bra.s    \gethistory
  791.  
  792. \historyrew:
  793.     addq.l    #1,gtfh_current(a3)
  794.  
  795. \gethistory:
  796.     movem.l    d0/d1/d7/a4/a5/a1,-(sp)
  797.     move.l    gtfh_buffer(a3),a4    ;start of buffer
  798.     move.l    a4,a5
  799.     move.l    gtfh_buflen(a3),d7    ;length of buffer
  800.     add.l    d7,a5            ;end of buffer
  801.  
  802.     move.l    sgw_WorkBuffer(a2),a1
  803.     move.l    gtfh_current(a3),d1
  804.     beq.s    \cls
  805.     move.l    gtfh_counter(a3),d0
  806.     beq.s    \cls
  807.     cmp.l    d0,d1
  808.     bls.s    11$
  809.     move.l    d0,d1
  810. 11$:    move.l    d1,gtfh_current(a3)
  811.     move.l    a4,a0
  812.     add.l    gtfh_start(a3),a0
  813.     sub.l    d1,d0
  814.     beq.s    \got
  815. \loop3:    moveq    #0,d1
  816.     move.b    (a0),d1
  817.     add.l    d1,a0
  818.     bsr.s    \historylimit
  819.     subq.l    #1,d0
  820.     bne.s    \loop3
  821.  
  822. \got:    moveq    #0,d1
  823.     move.b    (a0)+,d1
  824.     subq.l    #1,d1
  825.     clr.w    sgw_BufferPos(a2)
  826.     move.w    d1,sgw_NumChars(a2)
  827.     beq.s    \done2
  828.  
  829. \loop2:    bsr.s    \historylimit
  830.     move.b    (a0)+,(a1)+
  831.     subq.w    #1,d1
  832.     bne.s    \loop2
  833.  
  834. \done2:    clr.b    (a1)
  835.     movem.l    (sp)+,d0/d1/d7/a4/a5/a1
  836.     rts
  837.  
  838. \cls:    clr.w    sgw_NumChars(a2)
  839.     clr.w    sgw_BufferPos(a2)
  840.     bra.s    \done2
  841.  
  842.     ENDC
  843.  
  844.  
  845. ;--------------------------------------------------------------------
  846.  
  847. ;------------------
  848.     endif
  849.  
  850.     end
  851.