How to use UDG 4 ZXpand / ZXBlast

Discussions about Sinclair ZX80 and ZX81 Hardware
Post Reply
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

How to use UDG 4 ZXpand / ZXBlast

Post by Andy Rea »

okay over in the sales thread.... a disscusion has broken out how to use UDG in your own programs....

first we need an alternate character set to use, this could be one from the DK'tronics ROM or one that you create your self using the UDG designer or some other 3rd party tool, either way you should end up with a file on your storage device containing your chosen charcater set 512 bytes long for each 64 charset, or 1024 bytes long for each 128 charset.

once you have your charset file you now need to choose an address hwere you want to load it too, for a 64 charset this address MUST be on a 512 byte boundary, i.e 8192, 8704, 9216 ect... for 128 charsets the address MUST be on a 1024 byte boundary i.e 8192, 9216, 10240 ect... this is our Base ADDress

and we must also calculate the corresponding value for the I register that is used to point the zx81 hardware at our character set. we do this by dividing our Base ADDress by 256 ( please not that if using eightyone emulator with CHR$16 selected in hardware you will need to add 1 to this result only if using 128 charsets) so for Base ADDress 8192 you would get 32 and Base ADDress 10240 you would get 40. this is the number you need for the I register.

Changing the I register in Basic is not difficult but does require a little 5 byte MC routine. in the following example the small 5 byte long mc program is poked into line 1 by lines 2 thru 6, the value poked at address 16515 is the value used for the I register and can be changed to match our chosen Base ADDress. we then load our user defined characters at our chosen memory adress the USR 16514 call at line 10 chages the I register and now the zeddy is using our characters, the rest of our program executes normally until we reach the end where is may be preferable to switch back to the standard ROM characters we do this by poking a value of 30 ( the default value ) at address 16515 and again calling the short USR 16514 to change the I register for us.

Code: Select all

1 REM XXXXX
2 POKE 16514,62
3 POKE 16515,32
4 POKE 16516,237
5 POKE 16517,71
6 POKE 16518,201

7 LOAD "MYCHARS;8192"

10 RAND USR 16514
20 REM REST OF THE PROGRAM USING UDG
30
40
...
9989 REM 30 IS THE I REGISTER VALUE FOR STANDARD ROM CHARACTERS
9990 POKE 16515,30
9995 REM SWITCH BACK TO ROM CHARS
9996 RAND USR 16514
9999 STOP
HTH Andy
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: How to use UDG 4 ZXpand / ZXBlast

Post by Andy Rea »

PokeMon wrote: Fri Aug 25, 2017 12:32 pm
If I understand you right then the board uses only the memory (of ZXblast for example) to display the UDG stored there ? That would be simple to realize (fill that area with proper data at instance startup). Can be I register pointing anywhere to RAM or ROM ? What if I register pointing to the first 8k with a different ROM 0-8k ?

So now a changed ROM can be put on ZXblast for any instance in ZXblast ROM but during the short refresh period the ZXblast internal ROM is disabled and let the original ZX81 ROM enable. So I guess it would take the internal charset as UDG. Probably UDG is required to be in a region 8k-64k, right ?
Yes that is about right Karl, the board does no address decoding whatsoever, if you happen to have external ROM enabled during refresh ( and disabling the internal ROM at the same time ) then even external ROM should work, i didn't really think about this initially.

and yes any memory that is enabled during refresh at any address should work, although i have not tested above 48K

regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

Re: How to use UDG 4 ZXpand / ZXBlast

Post by Moggy »

Andy Rea wrote: Fri Aug 25, 2017 2:20 pm okay over in the sales thread.... a disscusion has broken out how to use UDG in your own programs....

first we need an alternate character set to use, this could be one from the DK'tronics ROM or one that you create your self using the UDG designer or some other 3rd party tool, either way you should end up with a file on your storage device containing your chosen charcater set 512 bytes long for each 64 charset, or 1024 bytes long for each 128 charset.

once you have your charset file you now need to choose an address hwere you want to load it too, for a 64 charset this address MUST be on a 512 byte boundary, i.e 8192, 8704, 9216 ect... for 128 charsets the address MUST be on a 1024 byte boundary i.e 8192, 9216, 10240 ect... this is our Base ADDress

and we must also calculate the corresponding value for the I register that is used to point the zx81 hardware at our character set. we do this by dividing our Base ADDress by 256 ( please not that if using eightyone emulator with CHR$16 selected in hardware you will need to add 1 to this result only if using 128 charsets) so for Base ADDress 8192 you would get 32 and Base ADDress 10240 you would get 40. this is the number you need for the I register.

Changing the I register in Basic is not difficult but does require a little 5 byte MC routine. in the following example the small 5 byte long mc program is poked into line 1 by lines 2 thru 6, the value poked at address 16515 is the value used for the I register and can be changed to match our chosen Base ADDress. we then load our user defined characters at our chosen memory adress the USR 16514 call at line 10 chages the I register and now the zeddy is using our characters, the rest of our program executes normally until we reach the end where is may be preferable to switch back to the standard ROM characters we do this by poking a value of 30 ( the default value ) at address 16515 and again calling the short USR 16514 to change the I register for us.

Code: Select all

1 REM XXXXX
2 POKE 16514,62
3 POKE 16515,32
4 POKE 16516,237
5 POKE 16517,71
6 POKE 16518,201

7 LOAD "MYCHARS;8192"

10 RAND USR 16514
20 REM REST OF THE PROGRAM USING UDG
30
40
...
9989 REM 30 IS THE I REGISTER VALUE FOR STANDARD ROM CHARACTERS
9990 POKE 16515,30
9995 REM SWITCH BACK TO ROM CHARS
9996 RAND USR 16514
9999 STOP
HTH Andy
Just job Andy, thanks buddy I will have a play with this tonight. :D
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: How to use UDG 4 ZXpand / ZXBlast

Post by Andy Rea »

For Moggy if your requirements is only a few characters that need changing an alternative approach might be to copy the ROM charcaters to Ram and then modify the ones you want changing, here is a small basic program that does so 64char mode. make sure ZXpand is set to low mem, CONFIG "M=L" and load with the ;X it first switches to fast to perform the copy then prints out 4 of each character when you are promted input a number between 0 and 63 that characters data is poked with some random numbers...

upon examining the program i think you will see what is going on, so you could for example just reprogram half a dozen or so characters if that is all your program needed quite easily instead of having to create a complete new charset... ( hmmm i think i just thought of a new function for UDG designer replace this set with standard ROM, for use when starting on a completely new set ) anyway... the program

regards andy
CRAZY1.P
(1.4 KiB) Downloaded 198 times
what's that Smell.... smells like fresh flux and solder fumes...
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

Re: How to use UDG 4 ZXpand / ZXBlast

Post by Moggy »

Thanks for this Andy. :D
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: How to use UDG 4 ZXpand / ZXBlast

Post by Andy Rea »

Next up is a small example of how by simply changing a few characters a game can be made a little more interesting, take for example the game muncher http://www.zx81stuff.org.uk/zx81/tape/Muncher by silver soft, when loaded on a standard zx81 it is quite playable. with a few changed and a simple pre-loader program we can enhance it to look more like the pacman it is meant to be.

the attached zip has 3 files.

MUNCCHAR.UDG user defined charset to be loaded at 8192 ( 512 bytes long )
MUNCLOAD.p the preloader program that loads the UDG's and switches I register before loading the original program
muncher.p the original program

instructions for ZXpand...
first make sure you have low ram CONFIG "M=L"
to use these 3 files should be copied in the same folder on your SD card simply load MUNCLOAD ( not autorun so you can look at the program ) when ready type RUN it will poke the small MC program needed for changing the I register, then load the characters at memory address 8192, then calls the MC in line 1 to change the I Reg finally loads the original program.

regards Andy
MUNCHER.zip
(3.84 KiB) Downloaded 193 times
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: How to use UDG 4 ZXpand / ZXBlast

Post by PokeMon »

Thanks and sorry for bothering your sales thread with my questions. :oops:
User avatar
siggi
Posts: 990
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: How to use UDG 4 ZXpand / ZXBlast

Post by siggi »

Moved here from other thread:
Moggy wrote: Fri Aug 25, 2017 11:35 am QUOTE.

"Changing the i register takes only 5 bytes so can be poked into a line 1 rem statement so charsets can be used easily from basic also."

This is the bit that leaves me stumped. :oops:
I have created some UDG's but don't know how to display them using basic any chance of a simple example, say a line of "X"'s being turned into a UDG of my choice?
The 5 bytes in M/C are necessary to change the I register to point to another UDG-character set in RAM. You could use standard POKE command to store the UDG pattern there by BASIC.
I have done that also in my UDG game:
viewtopic.php?f=6&t=526&p=4987&hilit=Interc+u#p4987

Regards
Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
User avatar
siggi
Posts: 990
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: How to use UDG 4 ZXpand / ZXBlast

Post by siggi »

In my program the UDG charset is setup starting line 8000. The code to switch to the new character set is stored in line 8002. Variable UDG holds its current address (it is relocatable). The M/C copies the Sinclair character generator to 8192 and then switches the I register to point there. Then the chatarcter set at 8192 is POKEd (while UDG is ON!) to the new characters:

UDG-INIT-INTERCEPTOR.jpg
UDG-INIT-INTERCEPTOR.jpg (215.16 KiB) Viewed 4731 times
Hope that helps
Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: How to use UDG 4 ZXpand / ZXBlast

Post by PokeMon »

Maybe it is a good idea to put the change of I register in the p-file code after loading it into memory. I think the loader routine is assembly and does know the location exactly and can set the I register properly.
Post Reply