Move hex_dump, add NE2K_LOG_PACKETS

This commit is contained in:
Fabian 2022-07-21 22:23:32 +09:00
parent c1bd7076bd
commit bca3648fd2
3 changed files with 50 additions and 32 deletions

View file

@ -1,37 +1,5 @@
"use strict";
/** @param {number=} length */
function hex_dump(buffer, length)
{
var result = [];
length = length || buffer.byteLength;
var addr = 0;
var line, byt;
for(var i = 0; i < length >> 4; i++)
{
line = h(addr + (i << 4), 5) + " ";
for(var j = 0; j < 0x10; j++)
{
byt = buffer[addr + (i << 4) + j];
line += h(byt, 2) + " ";
}
line += " ";
for(j = 0; j < 0x10; j++)
{
byt = buffer[addr + (i << 4) + j];
line += (byt < 33 || byt > 126) ? "." : String.fromCharCode(byt);
}
result.push(line);
}
return "\n" + result.join("\n");
}
/** @const */
var CDROM_SECTOR_SIZE = 2048;
/** @const */

View file

@ -77,6 +77,42 @@ function h(n, len)
return "0x" + v86util.pad0(str.toUpperCase(), len || 1);
}
/** @param {number=} length */
function hex_dump(buffer, length)
{
function hex(n, len)
{
return v86util.pad0(n.toString(16).toUpperCase(), len);
}
var result = [];
length = length || buffer.byteLength;
var addr = 0;
var line, byt;
for(var i = 0; i < length >> 4; i++)
{
line = hex(addr + (i << 4), 5) + " ";
for(var j = 0; j < 0x10; j++)
{
byt = buffer[addr + (i << 4) + j];
line += hex(byt, 2) + " ";
}
line += " ";
for(j = 0; j < 0x10; j++)
{
byt = buffer[addr + (i << 4) + j];
line += (byt < 33 || byt > 126) ? "." : String.fromCharCode(byt);
}
result.push(line);
}
return "\n" + result.join("\n");
}
if(typeof crypto !== "undefined" && crypto.getRandomValues)
{

View file

@ -3,6 +3,7 @@
// http://www.ethernut.de/pdf/8019asds.pdf
const NE2K_LOG_VERBOSE = false;
const NE2K_LOG_PACKETS = false;
/** @const */ var E8390_CMD = 0x00; /* The command register (for all pages) */
@ -178,6 +179,13 @@ function Ne2k(cpu, bus, preserve_mac_from_state_image)
{
var start = this.tpsr << 8;
var data = this.memory.subarray(start, start + this.tcnt);
if(NE2K_LOG_PACKETS)
{
dbg_log("send len=" + data.length + " ethertype=" + h(data[12] << 8 | data[13] << 0, 4) + " ipv4.len=" + (data[14 + 2] << 8 | data[14 + 3]) + " ipv4.protocol=" + h(data[14 + 9]));
dbg_log(hex_dump(data));
}
this.bus.send("net0-send", data);
this.bus.send("eth-transmit-end", [data.length]);
this.cr &= ~4;
@ -927,6 +935,12 @@ Ne2k.prototype.receive = function(data)
return;
}
if(NE2K_LOG_PACKETS)
{
dbg_log("receive len=" + data.length + " ethertype=" + h(data[12] << 8 | data[13] << 0, 4) + " ipv4.len=" + (data[14 + 2] << 8 | data[14 + 3]) + " ipv4.protocol=" + h(data[14 + 9]));
dbg_log(hex_dump(data));
}
this.bus.send("eth-receive-end", [data.length]);
if(this.rxcr & 0x10)