Skip to content

Instantly share code, notes, and snippets.

@zohassadar
zohassadar / debugview.py
Last active September 2, 2025 21:42
make .lst output more useful with .nes and .dbg
import argparse
import dataclasses
import pathlib
import re
OUTPUT_EXTENSION = "txt"
@dataclasses.dataclass
class Segment:
@zohassadar
zohassadar / bf.js
Last active March 22, 2025 00:09
golfed brainfuck interpreter
write = (z) => process.stdout.write(z);
arguments = process.argv.slice(2);
arguments.map((o) => {
for (
d = Array((e = 99)).fill((i = p = 0)),
h = (p) =>
f ? (d[--e] = i) : ']' != o[i++] && ('[' == o[i] && h(), h());
(f = d[p]), o[i];
)
; see results of nes tetris line scoring math
; meant for use on https://skilldrick.github.io/easy6502/
; slightly modified version of the following:
; https://github.com/CelestialAmber/TetrisNESDisasm/blob/master/main.asm#L3469-L3515
; pointsTable is normally referenced using x as a pointer. This points to two bytes of zeropage instead
define pointsTable0 $11
; draws a reverse secret grade pattern on the board that's hard to get out of
gameModeState_initGameState:
jsr actualInit
lda #$0
sta player1_vramRow
ldy #11
sty generalCounter
dey
@loop:
Learning some nesfab by playing with this project:
https://github.com/fractal161/nestris-recreation/commit/ada04653a89b8670e45679455caae35cb669b215
Changes made to nesfab to compile:
diff --git a/src/eval.cpp b/src/eval.cpp
index f7c65ac..e8d6f24 100644
--- a/src/eval.cpp
+++ b/src/eval.cpp
#include <stdio.h>
const long INVALID = -1;
const long MAXOUT = 999999;
const long RANGE = 10000;
const long POWERS[] = {1, 10, 100, 1000, 10000, 100000, 1000000};
long convertByte(unsigned char *b) {
unsigned char bigNybble = *b >> 4;
@zohassadar
zohassadar / pentris_sps.py
Last active November 13, 2024 16:08
Pentris SPS
class PentrisSPS:
pieces = [
# F/N/Y may be swapped
"F",
"f",
"J",
"L",
"X",
"S",
; assembles with https://github.com/snarfblam/snarfblasm
BUTTON_UP = $08
iHoriz = $12
spawnID = $19
cheatActive = $35
newlyPressedButtons_player1 = $F5
chooseNextTetrimino = $98EB
gameModeState_startButtonHandling = $A37F
import logging
logger = logging.getLogger(__name__)
pieces = "TJZOSLI"
id_to_piece = {i: p for i, p in enumerate(pieces)}
orientation_ids = [0x02, 0x07, 0x08, 0x0A, 0x0B, 0x0E, 0x12]
def shuffle_rng(rng_hi, rng_lo):
@zohassadar
zohassadar / calcscore.py
Created March 14, 2024 16:14
Calculate the score of 3rd max
clears = list(reversed("""4
5
6
10
11
12
16
20
21
22