home *** CD-ROM | disk | FTP | other *** search
- \ Memory editor Mike Mayo 9/13/89
-
- decimal
-
- : %mec! ( d a -- ) \ a byte store analogous to the default byte
- \ fetch of DUMP ; for use by memory editor
- dumpseg @ swap c!L ;
-
- \ these deferred words allow the editor to be patched for editing
- \ memory in some target processor's environment
- defer mec! ' %mec! is mec! \ the word for storing a changed location
- defer medump ' dump is medump \ the dump utility to use
- defer medln ' dln is medln \ the one-line part of the dump utility
- 2 value nwidth \ 2 for byte-wide, 4 for word-wide
-
- 0 value 0address \ address of start of editing area
- 0 value 0dataY \ screen row of first data line
- 0 value datalength \ length of area to edit
- 0 value addr+ \ address offset into editing area
-
- : set-attrib ( attrib -- ) \ dig into video memory and poke attrib
- \ into the attributes for the current location
- video-seg @
- addr+ 16 /mod swap nwidth 2 <> if 2/ then
- nwidth 1+ * 12 + 2* \ x
- swap 0dataY + 160 * \ y
- + ( rev-attrib video-seg video-offset )
- nwidth 2 <> if 3dup 5 + 3dup c!L 2+ c!L then
- 1+ 3dup c!L 2+ c!L ;
-
- : cur>rev ( -- ) \ reverse video the current location
- >attrib4 attrib c@ set-attrib >norm ;
- : cur>norm ( -- ) \ normal video the current location
- >norm attrib c@ set-attrib >norm ;
- : cur>bold ( -- ) \ bold the current location
- >attrib3 attrib c@ set-attrib >norm ;
-
- : curat ( -- ) \ place the cursor on the current byte or word
- cur>rev cursor-off
- base @
- 0 datalength 16 / 0dataY + 1+ at
- ." Edit location " addr+ 0address + hex >attrib3 5 u.r space >norm
- base !
- addr+ 16 /mod swap nwidth 2 <> if 2/ then
- nwidth 1+ * 12 + swap 0dataY + at ;
- : curhome ( -- ) \ move the cursor to the left side
- cur>norm addr+ $0fff0 and =: addr+ curat ;
- : curend ( -- ) \ move the cursor to the end of the line
- cur>norm addr+ $0f nwidth 2 <> if 1- then or =: addr+ curat ;
- : ^curhome ( -- ) \ move the cursor to the top left
- cur>norm off> addr+ curat ;
- : ^curend ( -- ) \ move the cursor to the bottom right
- cur>norm datalength 1- nwidth 2 <> if 1- then =: addr+ curat ;
- : redump ( -- ) \ redo the data display
- 0 0dataY 2- 2- at 0address datalength medump curat ;
- : pgup ( -- ) \ page up scrolls the window 1 line
- -16 +!> 0address redump ;
- : pgdn ( -- ) \ page down scrolls the window 1 line
- 16 +!> 0address redump ;
- : ^pgup ( -- ) \ control page up scrolls the window 8 lines
- -128 +!> 0address redump ;
- : ^pgdn ( -- ) \ control page down scrolls the window 8 lines
- 128 +!> 0address redump ;
- : curleft ( -- ) \ move the cursor one byte to the left, with scroll
- cur>norm nwidth 2 <> if decr> addr+ then decr> addr+
- addr+ 0< if 8 +!> addr+ pgup curend else curat then ;
- : curright ( -- ) \ move the cursor one byte to the right, with scroll
- cur>norm nwidth 2 <> if incr> addr+ then incr> addr+
- addr+ datalength >= if -8 +!> addr+ pgdn curhome else curat then ;
- : curdown ( -- ) \ move the cursor one line down, with scroll
- cur>norm addr+ 16 +
- datalength >= if pgdn else 16 +!> addr+ curat then ;
- : curup ( -- ) \ move the cursor one line up, with scroll
- cur>norm addr+ 16 -
- 0< if pgup else -16 +!> addr+ curat then ;
-
- create metib 7 allot \ buffer for keyboard input used by CHANGE
-
- : change ( -- ) \ change data at the current location
- cur>bold
- base @ >r
- 0 datalength 16 / 0dataY + 2+ at
- ." Key in HEX number then press <enter>"
- ." \s04( just press enter to leave unchanged )"
- >attrib3
- 0 datalength 16 / 0dataY + 1+ at
- ." Change data at " 0address addr+ + hex u. ." to > "
-
- \ get a new value
- cursor-on metib 6 blank
- 1 metib c!
- #out @ #line @ metib 6 lineeditor
- if
- metib c@
- nwidth <= if metib ?uppercase number? nip
- if 0address addr+ + mec! true
- else drop false
- then
- else false
- then
- else
- false
- then
- 0= if ." No change \:08" then
- >norm
-
- 0 #line @ at 79 spaces 0 #line @ 1+ at 79 spaces
- \ redisplay the line containing changed data
- curat 0 #line @ 1- at
- 0address addr+ $fff0 and + medln
-
- addr+ datalength 1- nwidth 2 <> if 1- then
- < if curright \ move the cursor to the next data location
- else curat then \ unless it is the last one on the screen
- r> base ! ;
-
- : mem-edit ( a l -- )
- ." \d\4 Memory editor: \n"
- ." \4 [Cntrl] Home End keys move cursor \0 "
- ." \4 [Cntrl] Page keys move window \n"
- ." \4 <enter> to alter data at cursor \0\s11\4 <esc> when done "
- #line @ 4 + =: 0dataY
- 255 umin 10 max
- dup 16 mod 0<> if $0f or 1+ then \ length always 16n
- 2dup =: datalength =: 0address
- medump \ display the data to be edited
- off> addr+ curat \ and place cursor at the top left
- begin
- key case \ handle editing keystokes
- 203 of curleft 0 endof \ left
- 205 of curright 0 endof \ right
- 200 of curup 0 endof \ up
- 208 of curdown 0 endof \ down
- 13 of change 0 endof \ enter, to change byte
- 199 of curhome 0 endof \ home
- 207 of curend 0 endof \ end
- 247 of ^curhome 0 endof \ control home
- 245 of ^curend 0 endof \ control end
- 201 of pgup 0 endof \ page up
- 209 of pgdn 0 endof \ page down
- 132 of ^pgup 0 endof \ control page up
- 246 of ^pgdn 0 endof \ control page down
- ^[ of -1 endof \ esc, to exit
- drop 0 endcase
- until
- cur>norm
- 0 0dataY 4 - at 79 spaces \ blank out top lines
- 0 0dataY 5 - at 79 spaces
- 0 datalength 16 / 0dataY + 1+ at \ place cursor below dump box
- 79 spaces 0 #line @ at \ and blank that line
- \ now restore deferred words and values
- \ to the defaults for editing local bytes
- ['] %mec! is mec! ['] %dumpc@ is dumpc@
- ['] dump is medump ['] dln is medln
- 2 !> nwidth
- cursor-on ;
-
- defined wdump nip
- #if
-
- \ The following is an example of redirecting the editor
- \ by changing the deferred words
-
- : %wd! ( w A1 --- ) DUMPSEG @ SWAP !L ; \ word-dump store
-
- : wEDIT ( a n -- ) \ edit word memory
- 4 !> nwidth
- ['] dlnw is medln ['] wdump is medump
- ['] %dump@ is dump@ ['] %wd! is mec! mem-edit ;
-
- #then
-
- \s
- : tm \ demonstrate the memory editor
- pad 128 mem-edit ;
-
-