21UDGS By Phil Hite 2007 Version 1.54 Freeware for the 48K or 128K ZX Spectrum. Allows you to define all 21 User Defined Graphics at once. You can store up to 10 sets of UDGs in memory. Keys: ? or H=Help 5=Left 6=Down 7=Up 8=Right CAPS SHIFT+5 6 7 8=Plot 0, 9 or Z=Plot/Delete or Kempston joystick SYMBOL SHIFT+5 6 7 8=Nudge I=Ink P=Paper B=Bright F=Flash S=Swap colours O=Clear colours/Undo J=Clear pixels/Undo X=Cut C=Copy V=Paste N=Invert Y=Rotate left U=Rotate right W=Flip horizontally E=Flip vertically M=Memory address - or + G=Define graphics D=List decimal codes E=Edit K=Pick up graphics from memory R=Resize grid to 5x4, 8x2, or 7x3 S=Save V=Verify L=Load T=Print A=Clear grid Q=Quit There are 2 Versions: 21udgs154 =Machine Code compiled with MCoder III 21udgs154bas=BASIC included for reference only as it is slow 1540 FOR h=1 TO dh: NEXT h This line slows the program down for compiling Remove REM before compiling with MCoder III Delete line 10 before compiling with MCoder III (to save precious bytes of memory) Use GO TO 20 and not RUN to run the program 21udgs154bas.txt=BASIC txt file If you BREAK into 21udgs154, restart the program with GO TO 20 Kempston joystick emulation with the Fuse emulator on the Mac 10 PRINT IN 31: GO TO 10 When Preferences > Set joysticks on snapshot load is ticked, Kempston joystick emulation returns IN 31 values of 255 and 56 instead of 0. 21udgs154 code handles this fault for accurate Kempston joystick emulation. Kempston joystick settings for 21udgs154.tzx Preferences > Untick Set joysticks on snapshot load Inputs > Joystick 1 Real device SPEED_LINK Competition Pro Emulated joystick Kempston Untick Interface 2 Tick Kempston joystick interface HOW TO USE UDGS IN BASIC In this example, 4 UDGs C,D,H, and S are defined as club, diamond, heart, and spade. Set g to the number of UDGs required from 1 to 21. 9000 FOR g=1 TO 4: READ g$: FOR y=0 TO 7: READ x: POKE USR g$+y,x: NEXT y: NEXT g 9010 DATA "c",16,56,56,84,254,254,84,56 9020 DATA "d",16,56,124,254,254,124,56,16 9030 DATA "h",108,254,254,254,254,124,56,16 9040 DATA "s",16,56,124,254,254,84,16,56 SAVE VERIFY LOAD UDGS Save the UDGs (21*8 bytes=168) stored at the current memory address. SAVE "UDGS"CODE USR "a",168 VERFIY "UDGS"CODE USR "a" LOAD "UDGS"CODE USR "a" SPECTRUM 128K In 128K mode, UDGs T and U are reserved for the additional SPECTRUM and PLAY commands. Enable UDGs T and U. IF PEEK 23388=16 THEN POKE 23611,205 Enable SPECTRUM and PLAY again. IF PEEK 23388=16 THEN POKE 23611,221 ADDITIONAL SETS OF UDGS SPECTRUM 48K/128K UDGs are stored in address 65368 -168 from the memory address for each additional set of UDGs. In this example 3 sets are used. Set 1=65368 Set 2=65368-168=65200 Set 3=65200-168=65032 CLEAR lowest memory address-1. 10 CLEAR 65031 Set m to the memory address required, then GO SUB 9999. 20 LET m=65368: GO SUB 9999: REM USE SET 1 30 LET m=65200: GO SUB 9999: REM USE SET 2 40 LET m=65032: GO SUB 9999: REM USE SET 3 50 STOP 9999 POKE 23675,m-256*INT (m/256): POKE 23676,INT (m/256): RETURN CHECK IF SPECTRUM 16K IF PEEK 23733=127 THEN PRINT "THIS IS A SPECTRUM 16K" ADDITIONAL SETS OF UDGS SPECTRUM 16K UDGs are stored in address 32600. -168 from the memory address for each additional set of UDGs. In this example 3 sets are used. Set 1=32600 Set 2=32600-168=32432 Set 3=32432-168=32264 CLEAR lowest memory address-1. 10 CLEAR 32263 Set m to the memory address required, then GO SUB 9999. 20 LET m=32600: GO SUB 9999: REM USE SET 1 30 LET m=32432: GO SUB 9999: REM USE SET 2 40 LET m=32264: GO SUB 9999: REM USE SET 3 50 STOP 9999 POKE 23675,m-256*INT (m/256): POKE 23676,INT (m/256): RETURN SCREEN$ UDGS COLLISION DETECTION SCREEN$ can't usually detect UDGs, but here's a solution. 10 PRINT AT 0,0;"A": REM GRAPHICS A 20 GO SUB 9998: REM MOVE SCREEN$ POINTER 30 IF SCREEN$ (0,0)="A" THEN PRINT "Collision": GO TO 60: REM CAPITAL A 40 REM IF SCREEN$... MORE COLLISIONS 50 GOSUB 9999: REM RESET SCREEN$ POINTER 60 STOP 9998 POKE 23606,PEEK 23675-8: POKE 23607,PEEK 23676-2: RETURN : REM MOVE SCREEN$ POINTER 9999 POKE 23606,0: POKE 23607,60: RETURN : REM RESET SCREEN$ POINTER References: Gerry Williams - Introduced me to computers and programming 1982 Character Generator (Horizons) - 1982 Sinclair Research Ltd - Psion Software Ltd Making the Most of the Micro (TV Series) 1983 - Demonstrated UDGs UDG Plotter - ZX Computing June/July 1983 Page 98 - David Elphick UDGs Machine - 1985 Sagesoft - Steve A J Broad AlchNews Issue Two Page 140 - 1992 Alchemist Research - Andy Davis https://www.worldofspectrum.org https://spectrumcomputing.co.uk Thank you to everyone on the World of Spectrum and Spectrum Computing forums for your advice and encouragement. https://21udgs.com phil_hite@hotmail.com 24 September 2024