Skip to content

Instantly share code, notes, and snippets.

@ncot-tech
ncot-tech / montecarlo-pi.py
Created March 13, 2024 19:38
Monte-Carlo method for calculating Pi
import pygame
import random
import math
# Initialize Pygame
pygame.init()
# Set up the screen
WIDTH, HEIGHT = 600, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
@ncot-tech
ncot-tech / gauss-legendre-pi.py
Created March 13, 2024 19:36
gauss-legendre pi calculation algorithm
def pi_digits():
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
decimal = []
for _ in range(100):
if 4 * q + r - t < n * t:
decimal.append(n)
print (n)
time.sleep(1)
q, r, t, k, n, l = (
@ncot-tech
ncot-tech / example usage
Created November 6, 2023 21:05
Agon Light 2 UART1 Serial IO from AgDev
static volatile SYSVAR *sv;
int main()
{
sv = vdp_vdu_init();
if (vdp_key_init() == -1)
return 1;
xUART uart = {
.baudRate = 115200,
@ncot-tech
ncot-tech / sensor.yaml
Created October 29, 2023 10:02
Home assistant sensor for solar battery runtime
- sensor:
- name: "House Battery Runtime"
state: >
{% set runtime = states('sensor.house_battery_runtime_raw') %}
{% set hours = runtime | float %}
{% set minutes = ((hours % 1) * 60) | int %}
{% set hours = (hours - (hours % 1)) | int %}
{{ 'Remaining Time: %02i:%02i'%(hours, minutes) }}
- name: "House Battery Runtime Raw"
unit_of_measurement: "hours"
@ncot-tech
ncot-tech / Makefile
Created October 24, 2023 16:13
Agon Light AgDev Makefile
# ----------------------------
# Makefile Options
# ----------------------------
NAME = DEMO
DESCRIPTION = "Ag C Toolchain Demo"
COMPRESSED = NO
CFLAGS = -Wall -Wextra -Oz
CXXFLAGS = -Wall -Wextra -Oz
@ncot-tech
ncot-tech / layer2dmaclear
Created March 25, 2021 22:48
ZX Spectrum Next DMA Layer 2 Screen Clearing
// R3G3B2
void clearLayer2Screen(unsigned char colour)
{
unsigned char zero = colour;
IO_123B = 0x03; // Top
// WR0
IO_6B = 0x79;
IO_6B = 0x00; IO_6B = 0x00; // A Start
IO_6B = 0x00; IO_6B = 0x40; // 16k
@ncot-tech
ncot-tech / plotpixel
Created March 25, 2021 22:47
ZX Spectrum Next Layer 2 Pixel Plotting Routine
inline void plot(unsigned char x, unsigned char y, unsigned char colour)
{
unsigned char newy = y;
// Work out which bit of screen we need
if (y >= 128) {
IO_123B = 0x83; // Bottom
newy -= 128;
} else if (y >= 64) {
IO_123B = 0x43; // Middle
newy -= 64;
@ncot-tech
ncot-tech / rgb2colour
Created March 25, 2021 22:46
8 bit per pixel RGB C Macro
//R3G3B2
#define RGB2COLOUR(r,g,b) \
(unsigned char)( \
( \
(r & 0x7) << 5 \
) | \
( \
(g & 0x7) << 2 \
) | \
(b & 0x3) \
@ncot-tech
ncot-tech / joytest.asm
Created June 23, 2020 11:08
Z80 Joystick Test
OUTPUT joytest.z80
ORG $8000
ld de,starttxt
call print
loop:
in a,($1) ; read port 1
ld (button),a ; copy the byte read
fire: