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 January 12, 2021 19:12
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 September 18, 2022 18:53
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 / omega_fades_2.asm
Last active February 3, 2021 20:38
ZX Spectrum fade-in/fade-out effects using attributes, focusing on small code size (second version)
; 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_2.asm
OPT --syntax=abf
DEVICE ZXSPECTRUM48,31999
ORG $8000
; uncomment and set to available SCR file to run the effect on ZX screen image (6912 bytes)
; DEFINE SCR_FILE "diver - Mercenary 4. The Heaven's Devil (2014) (Forever 2014 Olympic Edition, 1).scr"
@ped7g
ped7g / AllanTurveyCheckerboard.asm
Created February 15, 2021 22:54
ZX Spectrum Z80 asm - Attribute brightness checkerboard routine, optimized to size (32B)
; Author: Ped7g ; (C) 2021 ; license: https://opensource.org/licenses/MIT
; Z80 assembly, syntax for sjasmplus: https://github.com/z00m128/sjasmplus
; to build: sjasmplus AllanTurveyCheckerboard.asm
OPT --syntax=abf : DEVICE ZXSPECTRUM48,31999 : ORG $8000
; D:E = field height:width, A = attribute, modifies: AF, HL, BC, IXL
drawCheckerboard:
ld hl,$5800
.alternateLine
xor $40 ; alternate BRIGHT 1
@ped7g
ped7g / short_nr_init.asm
Created April 8, 2021 06:41
ZX Spectrum Next - size optimised setup of larger block of next-registers
; Author: Ped7g ; (C) 2021 ; license: https://opensource.org/licenses/MIT
; Z80N (ZX Next) assembly, sjasmplus syntax: https://github.com/z00m128/sjasmplus
;
; code-size optimisation for larger next-reg init block, where `nextreg r,v` ED91rrvv
; opcode takes four bytes for every next-reg set, so a block of 20 pair values takes
; 80 bytes (with the "setup_next_regs_v2" approach such block will take only 58 bytes)
;----------------------------------------------------------------------------------------
; variant 1, reads next-reg pairs from particular memory address
; this will break-even at 8 value pairs, every one more pair is two byte less
@ped7g
ped7g / zexallsj.asm
Created August 23, 2021 18:18
zexdoc.z80 and zexall.z80 patched for sjasmplus v1.18.2 - produce identical .com binary except padding bytes being zeroed
; the macro syntax is impossible to patch from outside (the "&" operators for label/arguments),
; so macros had been hard-edited to sjasmplus syntax. Other incompatible lines are amended
; through DEFINEs and OPT adjusting sjasmplus parsing
; some defines to change unknown syntax/decorations to nothing or silent assert to ignore them
DEFINE title assert 1,
DEFINE aseg
DEFINE local assert 1,
DEFINE error assert 0,
@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
@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 / 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 / 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"