A script to dump a few bytes from a file in hex.
Excruciatingly slowly prints some bytes from a file in hexadecimal. I cobbled this trying to figure out what was happening when uploading text files that have characters with the high bit set. I don't think it is particularly useful, but it does serve as a warning about trying something so ambitious.
WARNINGS:
Do not casually ask for more than say 256 bytes, or to dump at an offset more than that. If you do, you will be resetting the machine or waiting...
As written, the script cannot be interrupted (other than dropping into the debugger, but I don't know what you would do next).
To use this:
- Put the code listed below into a text file with some name, eg. "HD.TEXT" (case does not matter)
- From the main menu of the Workshop, type "r" for run. (If you do it in a different menu, you will be renaming a file or suffer some other punishment.)
- Type "<HD(filename,start,count,output)" and return
You must type the "<" character for the Workshop to recognize it is an Exec file.
You can leave .TEXT off of the name of the Exec script to run
filename is required and must be complete, eg. N68K.ERR - it does not need to be a text file, but it is unclear what the results mean
you may enter a question mark as the filename to see terse instructions about parameters
start is optional, it will default to 1 (which is the first byte in the file)
count is optional, it will default to 16
output is optional, it will default to -CONSOLE
examples:
r<HD(n68k.err) dump 16 bytes starting at the first one to the console
r<HD.TEXT(diff.obj,,32) dump 32 bytes starting at the first one to the console
r<hd(n68k.err,8,2) dump 2 bytes starting at the eighth one to the console
r<hd(n68k.err,,99999,N68k.err.hexdump.text) dump many bytes to the file "N68k.err.hexdump.text"
EXEC (filename,start,count,outfile)
IF filename = '?' THEN
WRITELN 'Parameters: (filename,start[1],count[16],outfile[-console])'
WRITELN 'Dump "count" bytes from "filename" to "outfile" in hex beginning at byte number "start"'
HALT
ENDIF
DEFAULT start to 1
DEFAULT count to 16
DEFAULT outfile to '-console'
WRITELN 'Hex dump of ',count,' bytes from ',filename,', to ',outfile,', starting at byte #',start
RESET fref,filename
REWRITE outref,outfile
IF IORESULT <> '' THEN
HALT IORESULT
ENDIF
SET %3 TO 1
WHILE %3 LT start DO
READCH (fref) %4
if %4 = 'EOF' THEN
WRITELN 'EOF reached prematurely at ',%3,' bytes'
HALT
ELSEIF IORESULT <> '' THEN
HALT IORESULT
ENDIF
SET %3 to EVAL(%3 + 1)
ENDWHILE
SET %3 TO 0
SET %9 to count
WHILE %3 LT %9 DO
READCH (fref) %4
if %4 = 'EOF' THEN
WRITELN 'EOF reached after ',%3,' bytes were dumped'
HALT
ELSEIF IORESULT <> '' THEN
HALT IORESULT
ENDIF
SET %5 TO ORD (%4)
SET %6 TO EVAL (%5 MOD 16 + 1)
SET %7 TO EVAL (%5 / 16 + 1)
SET %8 TO CONCAT ( COPY ('0123456789ABCDEF',%7,1), COPY ('0123456789ABCDEF',%6,1))
WRITE (outref) %8,' '
IF IORESULT <> '' THEN
HALT IORESULT
ENDIF
SET %3 to EVAL(%3 + 1)
SET %5 to EVAL (%3 MOD 16)
IF %5 EQ 0 THEN
WRITELN (outref) ' '
ENDIF
IF %3 GE %9 THEN
IF outfile = '-console' THEN
WRITE ' -- Enter space to dump ',count,' more, '
REQUEST %1 WITH 'anything else to cancel...'
IF %1 = ' ' THEN
SET %9 TO EVAL(count + %9)
ELSE
CLOSE fref
HALT 'Done'
ENDIF
ELSE
CLOSE fref
CLOSE outref
HALT 'Done'
ENDIF
ENDIF
ENDWHILE
ENDEXEC
BUGS etc.:
It doesn't seem to recognize the end of a file - fixed I think- No obvious way to stop it if you give it ambitious parameters and realize your mistake
edit: fixed EOF, implemented output to a file