home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / MISC / FPC355_5.ZIP / TCOM96.ZIP / TCOM / DEBUGGER / SRCINDEX.SEQ < prev    next >
Encoding:
Text File  |  1991-04-22  |  34.8 KB  |  964 lines

  1. \\ SRCINDEX.SEQ    Use an index of pointers to source for each target address
  2.  
  3. Use an index of pointers to locations in list files.
  4. The index contains entries for each target address.
  5. Also use HYPER.NDX style index of symbols.
  6.  
  7. Makes explicit reference to the following files.
  8.         80c196.FLS      ( List of list-file handles )
  9.         80c196.IND      ( Target address index      )
  10.         80c196.NDX      ( Like HYPER.NDX            )
  11. ( the name 80c196 really ought to be in a configuration file e.g. DB.CFG )
  12.  
  13. {
  14. anew flxwords
  15. decimal
  16.  
  17. 0 value end-session
  18. 0 value nbrowse-addr \ set while browsing, to use for setting breakpoints etc.
  19. 0 value from,           \ flag for compiled by , or c,
  20. 0 value firstcode       \ flag for first byte of instruction
  21. 0 value othercode       \ flag for other byte of instruction
  22. 0 value hilevel         \ flag for hilevel call
  23.  
  24.  
  25. : ?serror ( f a c -- ) \ if f is true show the error string a c
  26.         [ editor ] ?softerror ;
  27.  
  28.  
  29. }
  30.         Here is the file stack support.
  31. {
  32. create abrowseplace 6 allot
  33. create thisplace 8 allot
  34. create fileplace 6 allot
  35. ' fileplace alias >filesfile  \ What file we are in.   A pointer into *.FLS
  36. : file-here  fileplace 2+ ;   \ Where we are in the file
  37.  
  38. create neststack 10 6 * allot
  39. 0 value nestlevel                       \ here is a stack of buffers
  40.                                         \ for nested browsing
  41.      \ each contains a 2-byte files-file pointer and a 4-byte file offset
  42.  
  43. : nestbuf ( -- a ) \ return the address of the current nest buffer
  44.         nestlevel 0max 9 min  6 * neststack +  ;
  45. : pushnest ( -- ) \ save present file and location on the nesting stack
  46.         fileplace nestbuf 6 cmove
  47.         nestlevel 1+ 9 min !> nestlevel
  48.         ;
  49. : popnest  ( -- ) \ restore previous file and location from the nesting stack
  50.         nestlevel 1-  0max !> nestlevel
  51.         nestbuf fileplace 6 cmove
  52.         ;
  53.  
  54.  
  55.  
  56. ( 10) 8 constant index-record-length
  57. }
  58.         Here is the address-index file support
  59.  
  60. The index file contains 10 bytes for each address in the target code,
  61. starting at location zero.
  62. Bytes 0,1       Points into the handles file to the handle for the file
  63.                 that contains the listing of the current address.
  64. Bytes 2,3,4,5   Points into the source file to the start of the line
  65.                 that compiled the code at the current address.
  66. Byte  6         Offset into line in source file.
  67. {
  68. }
  69. Index record format
  70. 0,1             flspoint @      \  pointer to source file handle in TARGET.FLS
  71.                 $F000 bits      \  and flags for compilation type
  72.  
  73. 2,3,4,5         (filepointer) 2@        \  line location in source file
  74.  
  75. 6               (>IN) c@        \  location in source line ( < 255 )
  76. 7               lbyte or        \  target byte value
  77.  
  78. \ 8,9             LOADLINE @      \ line number in source file
  79. {
  80.  
  81. 10 constant #records                            \ index file buffer
  82. index-record-length #records *  constant indbuflen
  83. 100 constant indblkrecords
  84. index-record-length indblkrecords *  constant indblklen
  85. create indbuf indblklen allot
  86.  
  87. : >record ( n -- a ) \ return the address of record n
  88.                    \ n = 0 is the last record in the buffer, and is the one
  89.                    \ for the "current" indexed location.
  90.                    \ n < 0 for prior records.
  91.         1- index-record-length *
  92.         indbuflen +
  93.         indbuf +  ;
  94.  
  95. : *file ( n -- p ) \ return the file pointer from record n
  96.                    \ This is a single-number that is an offset into the
  97.                    \ file containing source-file handles.
  98.         >record @
  99.         dup $1000 and 0<> !> firstcode  \ see if first byte of instruction
  100.         dup $2000 and 0<> !> othercode  \ see if other byte of instruction
  101.         dup $4000 and 0<> !> hilevel    \ see if hilevel call
  102.         dup $8000 and 0<> !> from,      \ see if from ,
  103.         $FFF and                        \ return source file pointer
  104.         ;
  105.  
  106. : soffset ( n -- d ) \ return the offset into the source file from record n
  107.                      \ This is a double-number
  108.         >record 2+ 2@  ;
  109. : scol# ( n -- ln ) \ return the column offset from record n
  110.         >record 6 + c@ ;
  111. : scode-byte ( n -- ln ) \ return the code byte from record n
  112.         >record 7 + c@ ;
  113. : sline# ( n -- ln ) \ return the line number from record n
  114.         >record 8 + @ ;
  115.  
  116.  
  117.  
  118.  
  119. : key-upc ( -- key ) \ get a keystroke and convert all
  120.                      \ lower-case letters into uppercase
  121.         key
  122.         dup 'a' 'z' between if upc then  ;
  123.  
  124.  
  125.  
  126. create flsbuf  50 allot         \ files file buffer
  127. create flsbuf1 50 allot         \ second files file buffer
  128. create lssbuf  200 allot        \  .lss file buffer
  129.  
  130.  
  131. handle flshndl                \ file handle for symbol writing
  132. handle indexhndl
  133.  
  134. 0 value lfound
  135. 0 value max-addr        \ highest address represented in the index file
  136.  
  137. : ?indexopen    ( -- f1 )       \ is symbol file open, if not open it
  138.                                 \ return f1=true if symbol file is open
  139.                 flshndl >hndle @ 0<
  140.                 if      " TARGET.FLS" flshndl ">handle
  141.                         flshndl read-only hopen dup
  142.                         " Could not open files file" ?serror
  143.                         0=
  144.                 else    true
  145.                 then
  146.                 indexhndl >hndle @ 0<
  147.                 if      " TARGET.IND" indexhndl ">handle
  148.                         indexhndl read-only hopen dup
  149.                         " Could not open index file" ?serror
  150.                         indexhndl endfile   \ compute max address in index
  151.                         index-record-length mu/mod drop nip 1+ !> max-addr
  152.                         0=
  153.                 else    true
  154.                 then
  155.                 and    ;
  156.  
  157. : ltype ( a c -- ) \ show a line and blank to the end
  158.         ?dup if 2- 0max                 \ remove the cr lf
  159.                 cols min type           \ show the line
  160.                 cols #out @ - spaces    \ blank to the end
  161.              else
  162.                 drop
  163.                 cols 0 do '░' femit loop        \ grey beyound end of file
  164.              then
  165.         ;
  166.  
  167. 0 value hicol  \ the column at which the word highlight starts
  168. create browse-word 32 allot     \ hold the highlighted word for browsing
  169.  
  170. : hitype ( a c -- ) \ type the counted string with a word highlighted
  171.         2- 0max
  172.         >attrib3
  173.         hicol over      \ only highlight if hicol is within line
  174.         < if
  175.                 hicol
  176.                 0<> if  over hicol type            \ columns before hicol
  177.                         hicol /string
  178.                     then
  179.                 2dup bl scan            \ scan to next blank
  180.                 >attrib2
  181.                 2swap 2 pick - 2dup type        \ show one word in red
  182.                 30 min dup browse-word c!       \ and save it for browsing
  183.                 browse-word 1+ swap cmove
  184.                 >attrib3
  185.           then
  186.         type                            \ rest of text
  187.         80 #out @ - spaces              \ rest of line blank
  188.         >norm
  189.         ;
  190.  
  191. 0 value priorlines
  192. 0 value #backups
  193. 0 value backup-len
  194.  
  195. : backup-lines ( n -- ) \ Step back n lines in the source/list file
  196.         1 max 20 min     \ Limit to 20 lines back
  197.         dup !> #backups
  198.         file-here 2@    \ Present offset into source file
  199.         rot 132 *       \ Guess distance to move back in file
  200.         !> backup-len
  201.         backup-len 0 d- \ New offset into source file
  202.         2dup 0. d< if   \ Don't go back past the start of the file
  203.                          drop +!> backup-len  0.
  204.                    then
  205.                         \ Now offset to guessed place in file
  206.         2dup seqhandle movepointer
  207.         2dup  filepointer 2!  file-here 2!
  208.         ibreset         \ Now the next lineread will be way back in the file
  209.                         \ and backup-len contains the number of bytes from
  210.                         \ that lineread to our present position in the file.
  211.  
  212.                         \ Now read lines until we get to our present position
  213.                         \ to find how many lines are in it ( priorlines )
  214.         off> priorlines
  215.         begin   incr> priorlines
  216.                 lineread count
  217.                 nip dup negate +!> backup-len
  218.                 0=  backup-len 0<=  or until
  219.  
  220.         file-here 2@
  221.         2dup seqhandle movepointer   \ offset back to guessed place in file
  222.         filepointer 2!
  223.         ibreset
  224.                         \ Now priorlines is how many lineread's it takes to
  225.                         \ get to our present position.
  226.         priorlines #backups -
  227.                         \ Now dump lines until we get where we want
  228.         0 ?do  lineread c@ 0= ?leave  loop
  229.         filepointer 2@ file-here 2!
  230.         ;
  231.  
  232. : advance-lines ( n -- ) \ Step forward n lines in the source/list file
  233.         1 max 20 min    \ Limit to 20 lines forwards
  234.                         \ Now dump lines until we get where we want
  235.         0 do  lineread c@ 0= ?leave  loop
  236.         filepointer 2@ file-here 2!
  237.         ;
  238.  
  239. : show-this ( -- ) \ show the line at the current browse address
  240.         0 3 at
  241.         >filesfile @ thisplace !
  242.         filepointer 2@ thisplace 2+ 2!
  243.         lineread        \ read source line for indexed address
  244.         count hitype    \ now display this line
  245.         ;
  246.  
  247. : show-next ( -- ) \ show lines after the current browse address
  248.         browselines 4 -
  249.         0 ?do cr lineread count ltype      \ show following lines
  250.           loop
  251.         ;
  252.  
  253. : show-file ( -- ) \ show a screenful of the file in seqhandle
  254.         0 1 at lineread count ltype
  255.         0 2 at lineread count ltype
  256.         show-this
  257.         show-next
  258.         ;
  259.  
  260. : (open-list) ( -- f )  \ open the file list file ready for lineread
  261.                         \ Flag f is true if successful
  262.         >filesfile @ 0 flshndl movepointer
  263.         flsbuf 50 flshndl hread         \ get source handle
  264.         0<>
  265.         dup if  flsbuf seqhandle $>handle
  266.                 seqhandle hopen         \ open source file
  267.                 drop
  268.                 file-here 2@ seqhandle movepointer  \ offset to place in file
  269.                 file-here 2@ filepointer 2!
  270.                 ibreset                             \ reset lineread buffer
  271.         then
  272.         ;
  273. : open-list ( --)
  274.         (open-list) drop ;
  275.  
  276. : get-file&show ( -- )
  277.         0 scol# !> hicol        \ get column of address's word
  278.         0 *file >filesfile !    \ pointer into TARGET.FLS
  279.         from, firstcode or hilevel or 0= if exit then
  280.         0 soffset file-here 2!  \ offset in file to required address
  281.         (open-list) if                  \ open the file
  282.                         2 backup-lines
  283.                         show-file       \ display it
  284.                         seqhandle hclose drop
  285.                         on> lfound   \ flag that it was displayed successfully
  286.                     then
  287.         ;
  288.  
  289. : read-index&show ( -- )
  290.                       \ Read index into indbuf, such that the current
  291.                       \ location's index record is always in the same place
  292.                       \ This makes it easy to look at prior locations.
  293.         browse-addr
  294.         10
  295.         u< if   0. indexhndl movepointer        \ location in index file
  296.                 indbuf indbuflen erase
  297.                 9 browse-addr - index-record-length *  \ amount by which
  298.                 dup indbuf + swap                      \ to shift
  299.                 indbuflen swap -                       \ and shorten the read
  300.                 tuck
  301.                 indexhndl hread   \ read index file
  302.          else   browse-addr 9 -
  303.                 index-record-length *d
  304.                 indexhndl movepointer      \ location in index file
  305.                 indbuf
  306.                 indbuflen
  307.                 tuck
  308.                 indexhndl hread   \ read index file
  309.          then
  310.         ( #requested  #read )
  311.         = if
  312.                 get-file&show
  313.           else
  314.                 0 1 at ." \2 cannot read index file "
  315.           then
  316.         ;
  317.  
  318.  
  319. : (abrowse) ( -- ) \ browse source using the address in browse-addr
  320.         off> lfound
  321.         ?indexopen
  322.         if      read-index&show
  323.         else    true " \2 Index file not found " ?serror
  324.         then  ;
  325. ' (abrowse) is abrowse
  326. }
  327. ─────────────────────────────────────────────────────────────────────────────
  328.   Scan index to find address of current line
  329. ─────────────────────────────────────────────────────────────────────────────
  330. {
  331. : checkhndl ( p -- f ) \ p = pointer to index buffer record
  332.                 @ $FFF and     \ source file pointer
  333.                 0 flshndl movepointer   \ move pointer to read
  334.                 flsbuf1 50 flshndl hread \ get source handle
  335.                 0<>
  336.                 thisplace @    \ current source file pointer
  337.                 0 flshndl movepointer   \ move pointer to read
  338.                 flsbuf  50 flshndl hread \ get source handle
  339.                 0<> and
  340.                 if      flsbuf  count
  341.                         flsbuf1 count
  342.                         rot over = if   compare 0=
  343.                                  else   3drop false
  344.                                  then
  345.                 else    false
  346.                 then
  347.         ;
  348. 0 value afound
  349. 0 value indcol
  350. 0 value indptr
  351. : record-match ( i -- f ) \ examine record i of the block
  352.         index-record-length * indbuf +
  353.         dup !> indptr
  354.         dup 2+ 2@       \ compare file offset from index
  355.         thisplace 2+ 2@ \ to current browsing file offset
  356.         d= if                     \ if they match
  357.                 dup 6 + c@  \ see if offset in source line
  358.             !> indcol
  359. \                hicol       \ matches current offset in line
  360. ( patch )   hicol indcol =  \ >=
  361.                 ( =) if checkhndl else drop 0 then   \ check file handles
  362.          else
  363.                 drop false
  364.          then
  365.         ;
  366. : scan-block ( n -- n' )
  367.         indblkrecords
  368.         0 do    i record-match
  369.                 if      i +!> browse-addr
  370.                         drop 0
  371.                         on> afound
  372.                         leave
  373.                 then
  374.           loop
  375.         ;
  376. : scan-index ( -- )
  377.         0. indexhndl movepointer        \ beginning of index file
  378.         begin
  379.                 indbuf indblklen indexhndl hread  \ read a block of index file
  380.                 dup if  scan-block  then          \ scan this block
  381.                 0<> key? 0=
  382.         and while   \ continue until all read, or place found, or key pressed
  383.                 indblkrecords +!> browse-addr   \ accumulate address search
  384.         repeat
  385.         ;
  386. : find-addr ( -- ) \ browse index to find the address if current file line
  387.         off> lfound
  388.         off> afound
  389.         off> browse-addr
  390.         ?indexopen
  391.         if      scan-index
  392.         then
  393.         ;
  394. : show-addr ( -- )
  395.         30 0 at
  396.         save> base  hex
  397.         hicol 2 .r
  398.         ." Address "
  399.         at? ." ...." at
  400.         find-addr
  401.         afound
  402.         0= if   ." -------------"
  403.            else
  404.                 browse-addr 4 u.r
  405.                 indptr     @ 5 u.r
  406.                 indptr 2+ 2@ 8 ud.r
  407.                 indptr 6 + @ 5 u.r
  408.            then
  409.         restore> base
  410.         ;
  411. }
  412. ─────────────────────────────────────────────────────────────────────────────
  413. ─────────────────────────────────────────────────────────────────────────────
  414. {
  415. : break-here ( -- ) \ set a breakpoint at current browse location
  416.                     \ and go into the debugger to receive it
  417.         waiting-at-break
  418.         if      \ if the target is waiting in a breakpoint
  419.                 gofromtrap \ run from the breakpoint
  420.         then
  421.         nbrowse-addr    \ this address set while browsing
  422.         0 setbreak
  423. \        dsteps
  424.         ;
  425.  
  426. : setbreakpoint ( -- ) \ to set breakpoints from browser
  427.         savescr
  428.         10 10 60 20 box&fill
  429.         ."  \1 Press \3 Enter \1 to set breakpoint at "
  430.         >attrib3
  431.         save> base hex
  432.         nbrowse-addr 5 .r ." h "
  433.         restore> base
  434.         >norm  bcr
  435.         ." B = show serial port buffer" bcr
  436.         ." M = monitor serial port"     bcr
  437.         key-upc case
  438.                 $0d of  restscr break-here      endof   \ Enter
  439.                 'M' of  cls monitor restscr     endof
  440.                 'B' of  cls .buf
  441.                         cr ." \2 Press a key "
  442.                         key drop restscr        endof
  443.                 drop beep restscr
  444.             endcase
  445.         ;
  446.  
  447.  
  448.  
  449. only forth also hidden also editor also forth definitions
  450.  
  451. handle wordhndl
  452. handle hndlsave
  453.  
  454. 32 constant hpblen
  455. create helpbuf hpblen allot
  456.  
  457. create delims  2 c, bl c, ',' c, 32 allot
  458.  
  459. 0 value wordfnd
  460. 0 value index.start
  461. 0 value index.found
  462.                                         \ n1 = line to start searching from
  463.                                         \ n2 = line number in file if found
  464. : #check-ndx    ( n1 --- n2 f1 )        \ f1 = true if found index
  465.                                         \ searched for word must be at HERE.
  466.         =: index.start                  \ set the starting line
  467.         here c@ 0= if 0 false exit then
  468.         here helpbuf over c@ 2+ hpblen min cmove
  469.         wordhndl save!> seqhandle
  470. \        " HYPER.NDX" ">$ $file 0=
  471.         " TARGET.NDX" ">$ $file 0=
  472.         if      IBRESET
  473.                 0.0 seek
  474.                 loadline off
  475.                 off> wordfnd
  476.                 index.start 1 max 0     \ skip to previous occurrance
  477.                 ?do     lineread c@ 0= ?leave
  478.                 loop
  479.                 0 20000 1
  480.                 do      outbuf c@ 0= ?leave
  481.                         outbuf 1+ c@ 249 ( ∙ ) =
  482.                     if
  483. \                        outbuf count 3 - swap c!
  484. \                        outbuf 1+ hndlsave $>handle
  485.                         outbuf 2+ @ >filesfile !   \ pointer into TARGET.FLS
  486.                     else
  487.                         bl outbuf count + 2- c!
  488.                                       \ have at least 1 blank at end of line.
  489.                         helpbuf count outbuf 1+ swap 1+ caps-comp 0=
  490.                         if      drop
  491.                                 outbuf count bl scan 1 -1 d+
  492.                                 2dup bl scan nip -
  493.                                 dup here c! here 1+ swap cmove
  494.                                 here %number 2drop
  495.                                 loadline @ =: index.found
  496.                                 on> wordfnd leave
  497.                         then
  498.                     then
  499.                         lineread c@ 0= ?leave
  500.                 loop    wordhndl hclose drop
  501.                 wordfnd
  502.         else    0 false
  503.         then
  504.         restore> seqhandle
  505.         ;
  506.  
  507.  
  508. : #here-ed/br   ( n1 --- f ) \ n1 is line to start on
  509.                              \ Word to browse is in a counted string at HERE
  510.                              \ Returns f=true if unable to find word
  511.         #check-ndx ( this returns line# )
  512.         if      0.0 file-here 2!
  513.                 open-list               \ open the file found by #check-ndx
  514.                 ( line# ) 3 - 0max
  515.                 0 do  lineread c@ 0= ?leave  loop  \ skip to the line-2
  516.                 filepointer 2@ file-here 2!
  517.                         \ now the next lineread will be the first to show
  518.                 off> hicol
  519.                 show-file
  520.                 seqhandle hclose drop
  521.                 false
  522.         else
  523.                 drop true
  524.         then
  525.         ;
  526.  
  527. : br-unnest ( -- ) \ drop down one level of nested browsing
  528.         nestlevel
  529.         0<> if  popnest                 \ get prior place
  530.                 open-list show-file     \ reshow file
  531.                 seqhandle hclose drop
  532.             else
  533.                 beep
  534.             then
  535.         ;
  536.  
  537. : unnest-all ( -- ) \ drop down to the bottom level of nested browsing
  538.         off> nestlevel
  539.         abrowseplace fileplace 6 cmove  \ get original place
  540.         open-list show-file             \ reshow file
  541.         seqhandle hclose drop
  542.         ;
  543.  
  544. create nbbuf 32 allot
  545.        nbbuf off
  546.  
  547. : nbrowse       ( -- )          \ prompt for a word to browse
  548.         savescr
  549.         8 8 59 10 box&fill
  550.         ."  \1 Word to browse: "
  551.         >attrib1
  552.         on> autoclear
  553.         #out @ 1+ #line @ nbbuf 30 lineeditor
  554.         >norm
  555.         restscr
  556.         nbbuf c@ 0<> and
  557.         if      nbbuf count here c! here count cmove
  558.                 bl here count + c!
  559.                 pushnest        \ save current browse place
  560.                 0 #here-ed/br
  561.                 if
  562.                         true "  \3 No LINKAGE for this word " ?serror
  563.                         br-unnest
  564.                 then
  565.         then
  566.         ;
  567.  
  568. : browse-here ( -- ) \ browse for the word in browse-word
  569.         browse-word c@ 0<>
  570.         if      browse-word count here c! here count cmove
  571.                 bl here count + c!
  572.                 pushnest        \ save current browse place
  573.                 0 #here-ed/br
  574.                 if
  575.                         true "  \3 No LINKAGE for this word " ?serror
  576.                         br-unnest
  577.                 then
  578.         then    ;
  579.  
  580. : nxtbrowse     ( -- )          \ find next matching browse of word
  581.         pushnest        \ save current browse place
  582.         helpbuf here over c@ 2+ cmove
  583.         index.found 1+ #here-ed/br      \ repeat previous search
  584.         if
  585.                 true "  \3 No MORE LINKS for this word " ?serror
  586.                 br-unnest
  587.         then
  588.         ;
  589. }
  590.  
  591. : >delimiter    ( --- )         \ move to next space in line
  592.                 linelen dup screenchar over min
  593.                 ?do     linebuf 1+ i + c@ dup           \ -- c1 c1
  594.                         delims count rot scan nip       \ look for delimiter
  595.                         swap 127 > or                   \ or > than 127
  596.                                                         \ -- f1
  597.                         if      drop i leave then
  598.                 loop    =: screenchar   ;
  599.  
  600. : <delimiter    ( ---  n1 )     \ n1 = offset from line strt to prev space
  601.                 0 dup screenchar
  602.                 ?do     linebuf 1+ i + c@ dup           \ -- c1 c1
  603.                         delims count rot scan nip       \ look for delimiter
  604.                         swap 127 > or                   \ or > than 127
  605.                                                         \ -- f1
  606.                         if      drop i leave then
  607.             -1 +loop    dup =: screenchar ;
  608.  
  609. : get-word@cur  ( --- )
  610.                 save> screenchar        \ save current cursor position
  611.                 <delimiter              \ if space found, then bump forward 1
  612.                 linebuf 1+ + c@
  613.                 dup delims count rot scan nip   \ did we find a delimiter?
  614.                 swap hyperchar = or     \ or the hyper character?
  615.                 if      incr> screenchar
  616.                 then
  617.                 screenchar              \ cursor position
  618.                 >delimiter              \ find next space
  619.                 screenchar              \ get new cursor position ( old new )
  620.                 swap =: screenchar      \ restore cursor position ( new )
  621.                 screenchar - 0 max >r   \ length of word under cursor saved
  622.                 linebuf 1+ screenchar + \ source
  623.                 here 1+ r@ cmove        \ move word to destination HERE
  624.                 r> here c!                      \ set words length byte
  625.  
  626.                 here 1+ c@ hyperchar =          \ remove a leading hyper char
  627.                 if      here count >r dup 1+ swap r> 1- cmove
  628.                         -1 here c+!
  629.                 then
  630.                 here count + 2 bl fill          \ append a couple of blanks
  631.                 restore> screenchar ;
  632.  
  633. : word-ed/br    ( false --- f1 )
  634.                 get-word@cur
  635.                 0 #here-ed/br ;
  636. {
  637.  
  638. : word-right ( -- ) \ ^cur-right
  639.         open-list
  640.         0 1 at lineread count ltype
  641.         0 2 at lineread count ltype     \ show prior lines
  642.         0 3 at
  643.         lineread count           \ get current line
  644.         2dup
  645.         hicol /string                   \ start at hicol column
  646.         bl scan                         \ move to next blank
  647.         bl skip                         \ skip over leading blanks
  648.         drop 2 pick - !> hicol
  649.         dup 2- hicol min !> hicol          \ stop at end of line
  650.         hitype          \ now show this line
  651.         show-next       \ and the rest of the screen
  652.         seqhandle hclose drop
  653.         ;
  654. : cur-right ( -- ) \ cur-right
  655.         open-list
  656.         1 +!> hicol
  657.         show-file
  658.         seqhandle hclose drop
  659.         ;
  660.  
  661. : curend ( -- )
  662.         open-list
  663.         0 1 at lineread count ltype
  664.         0 2 at lineread count ltype     \ show prior lines
  665.         0 3 at
  666.         lineread count           \ get current line
  667.         dup 2- 0max !> hicol
  668.         hitype          \ now show this line
  669.         show-next       \ and the rest of the screen
  670.         seqhandle hclose drop
  671.         ;
  672. : curhome ( -- )
  673.         open-list
  674.         off> hicol
  675.         show-file
  676.         seqhandle hclose drop
  677.         ;
  678.  
  679. : word-left ( -- ) \ ^cur-left
  680.         open-list
  681.         0 1 at lineread count ltype
  682.         0 2 at lineread count ltype     \ show prior lines
  683.         0 3 at
  684.         lineread count          \ get current line
  685.         dup  hicol 0max  min !> hicol  \ keep hicol within line
  686.         over hicol +            \ start at current highlight point
  687.         hicol 0 do      1- dup c@
  688.                         bl <> ?leave    \ back over blanks
  689.                 loop
  690.         hicol 0 do      dup 1- c@
  691.                         bl = ?leave     \ back over non-blanks
  692.                         1-
  693.                 loop
  694.         2 pick -
  695.         0max !> hicol
  696.         hitype          \ now show this line
  697.         show-next       \ and the rest of the screen
  698.         seqhandle hclose drop
  699.         ;
  700. : cur-left ( -- ) \ cur-left
  701.         open-list
  702.         hicol 0> if  -1 +!> hicol  then
  703.         show-file
  704.         seqhandle hclose drop
  705.         ;
  706.  
  707. : LBbye ( -- ) \ get out of the debugger/browser environment
  708.         on> end-session
  709.         ;
  710. \ : toggledebug ( -- ) \ F2 key  --  switch debugging window on/off
  711. \        on> showingdebug
  712. \        ;
  713.  
  714. newmenu tfile$
  715.         menuline"  Browse a word      Alt-F9 " nbrowse
  716.         menuline" ────────────────────────── " noop
  717.         menuline"  Dos Shell      Ctrl-Enter " do-dos
  718.         menuline" ────────────────────────── " noop
  719.         menuline"  Quit browsing      Sh-F10 " LBbye
  720. endmenu
  721.  
  722. : LBhelp
  723.         savescr
  724.         0 2 59 21 box&fill
  725.         bcr ."   Browser commands:"             bcr
  726.         ." F9       browse highlighted word"    bcr
  727.         ." Alt-F9   enter a word to browse"     bcr
  728.         ." F10      previous browse place"      bcr
  729.         ." sh-F10   leave browse/debugger"      bcr
  730.         ." B        set a breakpoint"           bcr
  731.         ." F        enter a Forth command"      bcr
  732.         ." Cursor up/down"                      bcr
  733.         ."          move around in browse file" bcr
  734.         ." Page up/down"                        bcr
  735.         ."          move around in browse file" bcr
  736.         ." Home     move to top of browse file" bcr
  737.         ." End      move to end of browse file" bcr
  738.         ." + -      move browse address"        bcr
  739.     showingdebug if
  740.         bcr ."   \1 Press ESC to continue, or SPACE for more help "
  741.         key $1B <> if  debug_help  then
  742.     else
  743.         bcr ."   \1 Press any key to continue"
  744.         key drop
  745.     then
  746.         restscr
  747.         ;
  748.  
  749. newmenu thelp$
  750.         menuline"  Browse Help            F1 " LBhelp
  751. endmenu
  752.  
  753. newmenubar LB-bar
  754. +," Menu  "
  755. +," Help  "
  756. endmenu
  757.  
  758. create LB-list    tfile$ , thelp$ ,
  759.  
  760. \ 0 value LBsave  \ defsave
  761.  
  762. : .top ( -- ) \ top line of screen
  763.         0 0 at ." \4 ESC=menu \1  TARGET browser  "
  764.         ;
  765. : LBmenu       ( --- )
  766.         0 0 at ." \4 Enter, or first letter \1    "
  767. \        LBsave =: mcol
  768.         savemenu
  769.         LB-bar   =: menubar
  770.         LB-list  =: menulist
  771.         ['] default-mline   is mline
  772.         ['] default-mcolumn is mcolumn
  773.         ['] drop            is doother
  774.         menu
  775.         restmenu
  776. \        mcol =: LBsave
  777.         .top
  778.         ;
  779.  
  780. 0 value LB-inc  \ direction of incrementing address
  781. : abrowse-find ( -- )
  782.         begin   abrowse                 \ look up address and show listing
  783.                 lfound 0= if    LB-inc +!> browse-addr
  784.                                 at?
  785.                                 40 0 at
  786.                                 browse-addr h.  \ show progress in search
  787.                                 at
  788.                           then
  789.                 lfound key? or until
  790.         ;
  791.  
  792. : addr+browse ( n -- ) \ move the address where we are browsing, a distance n
  793.         afound 0= if drop exit then  \ exit if we do not have a known address
  794.         browse-addr swap        \ save browse-addr for wrap-check
  795.         dup 0< if   -1
  796.                else  1
  797.                then
  798.                !> LB-inc        \ set direction for auto-incrementing
  799.         +!> browse-addr
  800.         dup 0<
  801.         browse-addr 0<          \ check for a wrap ( won't work above 32k! )
  802.         xor if  LB-inc
  803.                 0< if   drop
  804.                         off> browse-addr \ If wrapped decreasing, zero addr
  805.                  else   !> browse-addr   \ If increasing, restore old addr
  806.                  then
  807.           else drop
  808.           then
  809.         browse-addr max-addr            \ if above end of index file
  810.         u> if   max-addr !> browse-addr \ reset to end,
  811.                 -1 !> LB-inc            \ and reverse increments
  812.                 then
  813.         abrowse-find
  814.         ;
  815.  
  816. : +browse ( n -- ) \ move where we are browsing, through the file,
  817.                    \  a distance n
  818.         open-list
  819.         dup 0> if  advance-lines
  820.              else  negate backup-lines
  821.              then
  822.         show-file
  823.         seqhandle hclose drop
  824.         ;
  825.  
  826. : topfile ( -- ) \ move to the top of the current file
  827.         pushnest
  828.         0.0 file-here 2!
  829.         open-list
  830.         show-file
  831.         seqhandle hclose drop
  832.         ;
  833.  
  834. : bottomfile ( -- ) \ move to the end of the current file
  835.         pushnest
  836.         open-list
  837.         seqhandle endfile file-here 2!  \ end of file
  838.         20 backup-lines                 \ back 20 lines
  839.         show-file
  840.         seqhandle hclose drop
  841.         ;
  842.  
  843. : .browse-state ( -- ) \ show nestlevel and stack
  844.         76 0 at
  845.         depth ?dup 0<> if >attrib2 4 .r         \ show stack
  846.                      else >norm 4 spaces
  847.                      then
  848.         73 0 at
  849.         nestlevel dup 0= if >attrib3 else >attrib2 then \ show nest level
  850.         2 .r space >norm
  851.         ;
  852.  
  853.  
  854.  
  855. : BRkeys ( key -- ) \ execute key functions of browser
  856.         case
  857.               \ $0a of  do-dos                  endof   \ ^Enter
  858.                 $0d of  browse-here             endof   \ Enter
  859.                 $09 of  nxtbrowse               endof   \ tab
  860.                 $8f of                          endof   \ sh-tab
  861.                 $08 of  br-unnest               endof   \ bs
  862.                 $7f of                          endof   \ ^bs
  863.  
  864.                 'B' of  setbreakpoint           endof
  865.                 'F' of  Forth-command           endof
  866.  
  867.                 '0' of  unnest-all              endof   \ 0 key
  868.                 $d2 of  unnest-all              endof   \ ins
  869.                 $d3 of                          endof   \ del
  870.  
  871.                 $bb of  LBhelp                  endof   \ F1
  872.               \ $bc of  toggledebug             endof   \ F2
  873.                 $c3 of  browse-here             endof   \ F9
  874.                 $c4 of  br-unnest               endof   \ F10
  875.                 $dd of  LBbye                   endof   \ sh-F10
  876.                 $f0 of  nbrowse                 endof   \ Alt-F9
  877.  
  878.                 $cb of  cur-left                endof   \ cur-left
  879.                 $cd of  cur-right               endof   \ cur-right
  880.                 $f3 of  word-left               endof   \ ^cur-left
  881.                 $f4 of  word-right              endof   \ ^cur-right
  882.                 $2d of  -1 addr+browse          endof   \ -
  883.                 $2b of   1 addr+browse          endof   \ +
  884.                 $c8 of  -1 +browse              endof   \ cur-up
  885.                 $d0 of   1 +browse              endof   \ cur-down
  886.                 $84 of  -1 +browse              endof   \ ^pgup
  887.                 $f6 of   1 +browse              endof   \ ^pgdn
  888.                 $c9 of  2 browselines - +browse endof   \ pgup
  889.                 $d1 of  browselines 2- +browse  endof   \ pgdn
  890.  
  891.                 $f7 of  topfile                 endof   \ ^home
  892.                 $c7 of  curhome                 endof   \ home
  893.                 $cf of  curend                  endof   \ end
  894.                 $f5 of  bottomfile              endof   \ ^end
  895.  
  896.                 $1b of   LBmenu                 endof   \ esc
  897.  
  898.                 drop beep       \ all other keys
  899.         endcase
  900.         ;
  901.  
  902. : LBkeys ( key -- )
  903.         showingdebug if
  904.                 case
  905.                 $0D of  one-step      show_debug        endof   \ enter
  906.                 $20 of  one-step/skip show_debug        endof   \ space
  907.                 '-' of  up_dbline                       endof   \ bkpt up
  908.                 '+' of  down_dbline                     endof   \ bkpt down
  909.                 '0' of  off> next-break show_debug      endof   \ 0 key
  910.                 $d2 of  off> next-break show_debug      endof   \ ins
  911.                 'R' of  set_register                    endof  \ register set
  912.  
  913.                 BRkeys  \ other keys may be for browsing
  914.                 endcase
  915.         else
  916.                 BRkeys
  917.         then
  918.         ;
  919.  
  920.  
  921. : LB ( -- ) \ browse listings
  922.         savecursor cursor-off
  923.         savescr
  924.         dark
  925.         rows !> browselines
  926.         .top
  927.         1 !> LB-inc
  928.         off> end-session
  929.         off> showingdebug
  930.         off> nestlevel
  931.  
  932.         begin   abrowse                 \ look up address and show listing
  933.                 lfound 0= if    LB-inc addr+browse
  934.                                 key? if .browse-state
  935.                                         key-upc LBkeys
  936.                                      then
  937.                           then
  938.                 lfound end-session or until
  939.  
  940.         lfound if
  941.                         fileplace abrowseplace 6 cmove  \ remember this place
  942.                         begin  .browse-state
  943.                                 show-addr
  944.                                 key-upc LBkeys
  945.                                 end-session until    \ browse listings
  946.                else
  947.                         true " \2 Could not index address " ?serror
  948.                then
  949.         DB-endfunc
  950.         restscr
  951.         restcursor
  952.         ;
  953.  
  954. : acb ( n -- ) \ run browser starting with address n
  955.         !> browse-addr
  956.         LB ;
  957.  
  958. 0 value reset-vector
  959. : cb ( -- ) \ top level word to run browser starting at reset entry point
  960.         reset-vector  acb  ;
  961.  
  962. }
  963.  
  964.