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 / 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_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:
@ped7g
ped7g / AndrewDansbyClearBox
Last active April 18, 2022 13:46
ZX Spectrum Z80 assembly - set "box" on screen to particular attribute value
; Variations on Andrew's question from FB group, two possible entry points
; clear_box with HL as char-coordinates or clear_box_adr with HL as attribute address
clear_box:
; h = valid character y coordinate
; l = valid character x coordinate
; b = width
; c = height
; a = attribute to fill
push af
ld a,h
@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 / erastothenes2.asm
Last active February 25, 2022 04:08
Z80 asm Erastothenes sieve to calculate prime numbers - part two, hunting for performance
; 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
;
; This is second version of the sieve routine (asm-like asm, focusing on performance, hard-wired buffer, etc...)
; For first C-like version check: https://gist.github.com/ped7g/c55bfa0d55ca13ce029549636cdd1de5
;
; sieve routine sieve_a_2 starts around line 110, below test harness
; comment/uncomment the case you wan to debug:
@ped7g
ped7g / erastothenes.asm
Created February 23, 2022 10:41
Z80 asm Erastothenes sieve to calculate prime numbers
; 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
; DEFINE ORG_ADR $5D01 ; using maximum memory in zx48 snapshot -> prime numbers: 4339, last prime number 41491
; DEFINE DO_MAX_BUFFER_CASE ; (4339 primes was with shorter test-code, not last version)
DEFINE ORG_ADR $8080 ; using only uncontended faster memory, but smaller buffers
OPT --syntax=abf
@ped7g
ped7g / clockwise32x32char_z80n.asm
Last active February 14, 2022 14:37
ZX Spectrum Next example of optimisations using the Z80N extended instructions
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Author: Ped7g ; (C) 2022 ; license: https://opensource.org/licenses/MIT
; Z80N (ZX Next) assembly, sjasmplus syntax: https://github.com/z00m128/sjasmplus
;
; code-size optimisation based on facebook post with small example showcasing the usage of routines
;
; default config of example is doing the counter-clockwise rotation of buffer to screen,
; flip comment to get clock-wise variant:
computeULAFromVRamAddress EQU computeULAFromVRamAddressCCW