Skip to content

Instantly share code, notes, and snippets.

View nihirash's full-sized avatar
🪧
I may be slow to respond.

Alexander Sharikhin nihirash

🪧
I may be slow to respond.
View GitHub Profile
@nihirash
nihirash / tokens.c
Created March 19, 2025 19:58
Simplest tokenizer
#include <stdio.h>
#include <stdlib.h>
#define MAX_TOKEN_SIZE 32
char str_to_tokenize[] = " x=10 >= 5 <= 6 == 1+2+3>10<100*10/455+(a+b+c)";
char current_token[MAX_TOKEN_SIZE];
int position = 0;
@nihirash
nihirash / crt.inc
Created April 4, 2023 18:25
Minimal hello world 24 for Agon Light
ASSUME ADL=1
org $40000
jp _start
align 64
db "MOS" ; Header
db 00 ; Version
db 01 ; ADL
_start:
;; Reseting Z80 segment - API will know that we working in ADL
@nihirash
nihirash / plasma.bas
Created April 2, 2023 15:16
bbc basic. Very simple plasma effect
10 DIM S(32) : LET O=0
20 FOR I=0 TO 32
30 LET X = (I*(PI/16)) - PI
40 S(I)=INT(8 * (1 + SIN(X)))
50 NEXT I
55 CLS : O = O+1
60 FOR Y=1 TO 23 : FOR X=1 TO 79
70 COLOUR S((X*X+Y*Y+O) MOD 32)
80 PRINT "#";
90 NEXT : PRINT
@nihirash
nihirash / base-routines.asm
Created March 27, 2023 10:15
Threaded code interpreter for Z80
repeat_proc:
getWord
ld (.count + 1), de
pop de
push de
call Interpreter.push
.count
ld de, 0
call Interpreter.push
next
@nihirash
nihirash / threaded-code-interpreter.s
Created June 12, 2022 11:44
Threaded code interpreter for 68K-compatible CPUs
;; Threaded forth-like code interpreter
;; (c) 2022 Alexander Sharikhin
;; Licensed under Coffeeware License
;;
;; License:
;;
;; If you're using this part of code, I'd love to hear about it.
;; Let me know by sending email to anihirash(at)gmail.com
;;
;; I'm crazy about coffee. If you treat me a delicious coffee - it
@nihirash
nihirash / img2dxt1
Last active February 26, 2022 22:58
Convert any image to DXT1 texture(for Apollo V4 computers). Requires imagemagick installed.
#!/bin/bash
if [ $# -ne 2 ]
then
echo "Usage: img2dxt1 <source-image> <output-name>"
exit 1
fi
if [ ! -f "$1" ]
then
echo "Input file does not exists!"
@nihirash
nihirash / png2rgba555
Last active February 12, 2022 10:35
Python script to convert PNGs to RGBA555 image for SAGA chipset(requires PyPNG - to install call pip3 install pypng)
#!/usr/bin/env python3
import png
import sys
if (len(sys.argv) < 3):
print("Usage: png2rgba555 <input.png> <output.raw>")
exit(1)
input_name = sys.argv[1]
@nihirash
nihirash / Makefile.ecp5
Created May 31, 2021 16:33
Makefile for Lattice ECP5
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
SOURCES=$(call rwildcard,rtl,*.v)
RESULT=hardware
TOP=top
NEXTPNRPARAMS=--25k --package CABGA256 --speed 6
LPF=icesugar_pro
all: $(RESULT).bin
$(RESULT).bin: $(RESULT).cfg
@nihirash
nihirash / Makefile
Created May 31, 2021 16:27
Building ice40 projects :-)
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
SOURCES=$(call rwildcard,rtl,*.v)
RESULT=hardware
TOP=top
NEXTPNRPARAMS=--up5k --package sg48
PCF=top
all: $(RESULT).bin
$(RESULT).bin: $(RESULT).asc
REAL_ORG = #3c51
DICT_BEGIN = #3c49
DATA_REG = 129
CONTROL_REG = 128
RTS_LOW = #16
RTS_HIGH = #56
MACRO CHECKSUM start
fin = $
chk = 0