summaryrefslogtreecommitdiff
path: root/src/packets/nes.ts
diff options
context:
space:
mode:
authorTheMas3212 <mas3212@gmail.com>2023-09-24 20:57:51 +1000
committerTheMas3212 <mas3212@gmail.com>2023-09-24 20:57:51 +1000
commit2341a7ec25e85481251d803be42597981d2bb9db (patch)
tree0d1f7c40db52a5279deb53d8bfb98e83a78a1849 /src/packets/nes.ts
parent8aea0dba74aecf0846217b5363cd3f9eab543f35 (diff)
downloadtasd-js-2341a7ec25e85481251d803be42597981d2bb9db.tar.gz
tasd-js-2341a7ec25e85481251d803be42597981d2bb9db.zip
NES, SNES, Genesis and Extra Packets
Diffstat (limited to 'src/packets/nes.ts')
-rw-r--r--src/packets/nes.ts85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/packets/nes.ts b/src/packets/nes.ts
new file mode 100644
index 0000000..30b1418
--- /dev/null
+++ b/src/packets/nes.ts
@@ -0,0 +1,85 @@
+import { PACKET_TYPES } from "../constants";
+import { encodeString, readBoolean, readString, readUint16, readUint8, writeBoolean, writeUint16, writeUint8 } from "../utils";
+import { TASDPacket, buildBuffer } from "./utils";
+
+export class NESLatchFilterPacket implements TASDPacket {
+ constructor(public time: number) {}
+ get key() {
+ return PACKET_TYPES.NES_LATCH_FILTER;
+ }
+ get size() {
+ return 2;
+ }
+ static fromBuffer(buffer: Uint8Array) {
+ return new this(readUint16(buffer, 0));
+ }
+ toBuffer(g_keylen: number): Uint8Array {
+ const payload = new Uint8Array(2);
+ writeUint16(this.time, payload, 0);
+ return buildBuffer(g_keylen, this.key, payload);
+ }
+ toString(): string {
+ return `NESLatchFilter ${this.time}`;
+ }
+}
+
+export class NESClockFilterPacket implements TASDPacket {
+ constructor(public time: number) {}
+ get key() {
+ return PACKET_TYPES.NES_CLOCK_FILTER;
+ }
+ get size() {
+ return 1;
+ }
+ static fromBuffer(buffer: Uint8Array) {
+ return new this(readUint8(buffer, 0));
+ }
+ toBuffer(g_keylen: number): Uint8Array {
+ const payload = new Uint8Array(1);
+ writeUint8(this.time, payload, 0);
+ return buildBuffer(g_keylen, this.key, payload);
+ }
+ toString(): string {
+ return `NESClockFilter ${this.time}`;
+ }
+}
+
+export class NESOverreadPacket implements TASDPacket {
+ constructor(public high: boolean) {}
+ get key() {
+ return PACKET_TYPES.NES_OVERREAD;
+ }
+ get size() {
+ return 1;
+ }
+ static fromBuffer(buffer: Uint8Array) {
+ return new this(readBoolean(buffer, 0));
+ }
+ toBuffer(g_keylen: number): Uint8Array {
+ const payload = new Uint8Array(1);
+ writeBoolean(this.high, payload, 0);
+ return buildBuffer(g_keylen, this.key, payload);
+ }
+ toString(): string {
+ return `NESOverread ${this.high}`;
+ }
+}
+
+export class NESGameGenieCodePacket implements TASDPacket {
+ constructor(public code: string) {}
+ get key() {
+ return PACKET_TYPES.NES_GAME_GENIE_CODE;
+ }
+ get size() {
+ return this.code.length;
+ }
+ static fromBuffer(buffer: Uint8Array) {
+ return new this(readString(buffer, 0, buffer.length));
+ }
+ toBuffer(g_keylen: number): Uint8Array {
+ return buildBuffer(g_keylen, this.key, encodeString(this.code));
+ }
+ toString(): string {
+ return `NESGameGenieCode ${this.code}`;
+ }
+} \ No newline at end of file