Skip to content

Instantly share code, notes, and snippets.

View ped7g's full-sized avatar
💭
ZX Spectrum Next is here, panic!

Peter Ped Helcmanovsky ped7g

💭
ZX Spectrum Next is here, panic!
  • 7 Gods demo group
  • Prague
  • X @ped7g
View GitHub Profile
@ped7g
ped7g / omega_fades.asm
Last active May 22, 2025 11:17
ZX Spectrum fade-in/fade-out effects using attributes, focusing on small code size (no tables used)
; Authors: Omega, Ped7g, Baze ; (C) 2021 ; license: https://opensource.org/licenses/MIT
; Z80 assembly, syntax for sjasmplus: https://github.com/z00m128/sjasmplus
; to assemble run: sjasmplus omega_fades.asm
OPT --syntax=abf
DEVICE ZXSPECTRUM48,31999
ORG $8000
;------------------------------------------------------------------------------
; ULA attributes "fade out" effect, going through PAPER/INK values,
; decrements them (individually) by 1 every iteration (call of routine)
@ped7g
ped7g / ped_base64.asm
Last active May 8, 2025 22:39
linux x86_64 asm example of "base64 encoder" (for lecturing purposes)
; (C) [copyleft] 2021 Peter Helcmanovsky
; License: CC0 https://creativecommons.org/share-your-work/public-domain/cc0
;
; x86_64 linux asm example of base64 encoding
;
; reads stdin, encodes it to base64 without new-lines, outputs to stdout
;
; the code is meant to be rather straightforward and simple (for lecturing purpose),
; not performance optimal
;
@ped7g
ped7g / flipULA2.asm
Last active January 22, 2025 21:46
ZX Spectrum Next - ULA double buffering example v2 (advanced techniques: DMA + custom IM1 interrupt)
DEFINE USE_DMA_TO_CLEAR_SCREEN ; comment out to get LDIR clear version
DEFINE USE_DOUBLE_BUFFERING ; comment out to see single-buffer redraw issues
DEVICE ZXSPECTRUMNEXT
BORDER MACRO color?
ld a,color?
out (254),a
ENDM
@ped7g
ped7g / bites2bytes.asm
Created March 22, 2024 19:18
Z80 machine code challenge, turn number of bits into bytes required to store it in C language
;; original facebook post in "Z80 Assembly Programming On The ZX Spectrum" group:
; Here's a challenge for your creativity.
; Create a Z80 assembly function with the following properties:
; Input in A: values in the range [1,32]
; Output in A: 1 for 1-8, 2 for 9-16, 4 for 17-32
; No loops or other conditional jumps.
; No usage of ROM code.
; No comparisons.
; The function will map how many bits an integer needs to how many bytes it needs in a typical C style struct.
@ped7g
ped7g / fb_cauldron.asm
Created March 6, 2024 01:18
"cauldron" logo drawn by attributes for ZX Spectrum, size coding optimization, 40 bytes
; ZX SPECTRUM code, sjasmplus syntax: https://github.com/z00m128/sjasmplus
; alternative code for Allan Turvey post: https://www.facebook.com/groups/z80asm/posts/1982356728824612/
ORG $8000-8
DEVICE ZXSPECTRUM48, $ - 1
size_start:
dg ...#.###
dg ....####
dg ...#####
dg ...#####
dg ..######
@ped7g
ped7g / quicksort.asm
Created March 1, 2022 13:04
Z80 asm quicksort of uint16_t array
; Author: Ped7g ; (C) 2022 ; license: MIT / GPL / Public Domain (pick whichever fits best for you)
; assembled with: https://github.com/z00m128/sjasmplus/
; based on https://github.com/MartinezTorres/z80_babel project, written as comparison
;
; Notes for myself about debugging/verification: in CSpect debugger `SAVE "data.bin",from,length`
; Then `hexdump -v -e '/2 "%u\n"' DATA.BIN > data.txt`. Then compare with `sort -g data.txt`
DEFINE ORG_ADR $8080 ; using only uncontended faster memory, but smaller buffers
OPT --syntax=abf : CSPECTMAP "qsort.map"
@ped7g
ped7g / fixed_point_math_example_x86_64_linux.asm
Created March 15, 2018 00:45
x86_64 linux asm example of fixed-point arithmetic
; (C) [copyleft] 2018 Peter Helcmanovsky
; License: CC0 https://creativecommons.org/share-your-work/public-domain/cc0
;
; x86_64 linux asm example of fixed-point arithmetic
; (see https://en.wikipedia.org/wiki/Fixed-point_arithmetic)
;
; to build I'm using nasm and ld:
; nasm -f elf64 %f -l %n.lst -w+all; ld -b elf64-x86-64 -o %n %n.o
; (where %f is source file name and %n is just the main part w/o extension)
;
@ped7g
ped7g / quicksort_strings.asm
Created May 9, 2023 22:32
Z80 quicksort of array with pointers to 64 byte long strings
; Author: Ped7g ; (C) 2022 ; license: MIT / GPL / Public Domain (pick whichever fits best for you)
; sort array of pointers to 64 char long strings (for example filenames)
; assembled with: https://github.com/z00m128/sjasmplus/
DEFINE ORG_ADR $8080 ; using only uncontended faster memory, but smaller buffers
OPT --syntax=abf : CSPECTMAP "qsorts.map"
DEVICE ZXSPECTRUM48, ORG_ADR-1
ORG ORG_ADR
@ped7g
ped7g / constants.i.asm
Created May 4, 2023 10:31
Failed attempt to create band-aid tool to make ZX Next HDMI 50Hz mode timing good-enough for multicolor titles
; ----- Colour palette (ULA)
BLACK equ 0
BLUE equ 1
RED equ 2
MAGENTA equ 3
GREEN equ 4
CYAN equ 5
YELLOW equ 6
WHITE equ 7
@ped7g
ped7g / rom_first_int.asm
Last active August 23, 2022 09:25
ZX Spectrum custom ROM to measure time till first /INT signal
; (C): copyright 2022 Peter Ped Helcmanovsky, license: MIT
; name: custom ZX Spectrum ROM to measure time until first /INT signal
; public gist somewhere at: https://gist.github.com/ped7g (search for it)
;
; to assemble (with z00m's sjasmplus https://github.com/z00m128/sjasmplus/ v1.20.1+)
; run: sjasmplus rom_first_int.asm
;
; history: 2022-08-23: v1.0 - initial version
;
; purpose: