From: Tim Vaughan Date: Fri, 22 Apr 2016 09:57:23 +0000 (+1200) Subject: improved dump() X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=1060539f1cf03aa9225443762bad93d384fb4f0a;p=forth.jl.git improved dump() --- diff --git a/src/forth.jl b/src/forth.jl index 4f0cb1c..91eea4f 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -770,23 +770,33 @@ end function dump(startAddr::Int64; count::Int64 = 100, cellsPerLine::Int64 = 10) chars = Array{Char,1}(cellsPerLine) - for i in 0:(count-1) - addr = startAddr + i - if i%cellsPerLine == 0 - print("$addr:") - end - - print("\t$(mem[addr]) ") + lineStartAddr = cellsPerLine*div((startAddr-1),cellsPerLine) + 1 + endAddr = startAddr + count - 1 + + q, r = divrem((endAddr-lineStartAddr+1), cellsPerLine) + numLines = q + (r > 0 ? 1 : 0) + + i = lineStartAddr + for l in 1:numLines + print(i,":") + + for c in 1:cellsPerLine + if i >= startAddr && i <= endAddr + print("\t",mem[i]) + if mem[i]>=32 && mem[i]<128 + chars[c] = Char(mem[i]) + else + chars[c] = '.' + end + else + print("\t") + chars[c] = ' ' + end - if (mem[addr]>=32 && mem[addr]<128) - chars[i%cellsPerLine + 1] = Char(mem[addr]) - else - chars[i%cellsPerLine + 1] = '.' + i += 1 end - if i%cellsPerLine == cellsPerLine-1 - println(string("\t", ASCIIString(chars))) - end + println("\t", ASCIIString(chars)) end end