Skip to content

Commit ef81560

Browse files
DavidBuchanan314AileenLumina
authored andcommitted
save dumping, tcp repl, and mandelbrot (gfx) examples
1 parent c8f4308 commit ef81560

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

examples/_nx/mandelbrot.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import _nx
2+
3+
GfxMode_LinearDouble = 2
4+
WIDTH = 1280
5+
HEIGHT = 720
6+
MAX_ITER = 32
7+
8+
palette_r = [0, 8, 16, 24, 32, 40, 42, 38, 32, 22, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 57, 96, 137, 182, 216, 224, 232, 240, 248]
9+
palette_g = [0, 1, 6, 13, 24, 37, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 110, 90, 66, 40, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
10+
palette_b = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 24, 45, 70, 97, 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 202, 168, 130, 90, 46]
11+
12+
def mandel(x0, y0):
13+
x, y = (0.0, 0.0)
14+
for i in range(MAX_ITER):
15+
x, y = ( (x*x - y*y + x0), (2*x*y + y0) )
16+
if (x*x + y*y) >= 4:
17+
return i
18+
return 0
19+
20+
_nx.gfx_set_mode(GfxMode_LinearDouble)
21+
22+
fb = bytearray([0]*WIDTH*HEIGHT*4) # RGBA8888
23+
24+
for y in range(HEIGHT):
25+
y0 = (y/HEIGHT*2)-1
26+
for x in range(WIDTH):
27+
x0 = (x/HEIGHT*2)-2.5
28+
iterations = mandel(x0, y0)
29+
fb[(y*WIDTH+x)*4] = palette_r[iterations]
30+
fb[(y*WIDTH+x)*4+1] = palette_g[iterations]
31+
fb[(y*WIDTH+x)*4+2] = palette_b[iterations]
32+
33+
_nx.gfx_set_framebuffer(fb)
34+
_nx.gfx_flush_and_sync()

examples/_nx/saves.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import _nx
2+
import os
3+
import sys
4+
5+
title_id = 0x01007ef00011e000 # BotW
6+
7+
_nx.account_initialize()
8+
user_id = _nx.account_get_active_user()
9+
10+
if user_id is None:
11+
print("No active user, you need to launch and close a game prior to launching hbl.")
12+
sys.exit()
13+
14+
_nx.fs_mount_savedata("save", title_id, user_id)
15+
16+
print(os.listdir("save:/"))

examples/tcp_repl.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import socket
2+
import sys
3+
import code
4+
import time
5+
6+
DEBUG_PORT = 1337
7+
8+
def remote_repl(local):
9+
sys.stdout.flush()
10+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
11+
s.bind(("0.0.0.0", DEBUG_PORT))
12+
s.listen(1)
13+
14+
print("Waiting for remote debug connection on port {}.".format(DEBUG_PORT))
15+
16+
conn, addr = s.accept()
17+
18+
print("Accepted remote debug connection from '{}'.".format(addr[0]))
19+
20+
sys.stdout.flush()
21+
sys.stderr.flush()
22+
stdin_bak, stdout_bak, stderr_bak = sys.stdin, sys.stdout, sys.stderr
23+
rfile = conn.makefile("r")
24+
wfile = conn.makefile("w")
25+
sys.stdin, sys.stdout, sys.stderr = rfile, wfile, wfile
26+
27+
try:
28+
code.interact(local=local)
29+
except SystemExit:
30+
pass
31+
32+
conn.close()
33+
s.close()
34+
sys.stdin, sys.stdout, sys.stderr = stdin_bak, stdout_bak, stderr_bak
35+
print("Remote debug session closed.")
36+
37+
while 1:
38+
remote_repl(locals())
39+
time.sleep(1)

0 commit comments

Comments
 (0)