Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create and draw graphics
#1
What is the best way to draw graphics to the screen e.g. UDG or other method

How do you get sprites from the sprite editor into the basic program?
Reply
#2
how do you draw graphics to the screen?
Reply
#3
UDG creation is slightly different than in Sinclair BASIC. For compatibility's sake you can use POKE USR "a" and so on to create UDG, but there is a better way:
You can create a big array with your UDG data a then poke 23675 to the array address using the @ operator. E.g.:
Code:
10 UDGData => {0,255,0,255,0,255,0,255,0}: REM 8 bytes
20 POKE Uinteger 23675, @UDGData(0) : REM Poke UDG system variable with address of 1st element
Now you can PRINT UDG "A" using PRINT "\A". This syntax is the same ZX Basin uses.
More info on PRINTing UDG and Graphics here: <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Syntax">http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Syntax</a><!-- m -->
Reply
#4
thanks for the help


how would I convert the information from the sprite editor into an array?

I downloaded the latest stable version, but when I click on the EXE files none of them open the IDE,

I had to install the boriel program to c: because I dont have privileges to install to program files
Reply
#5
slenkar Wrote:thanks for the help
how would I convert the information from the sprite editor into an array?
This is quite hard (to do it by hand). There are people that does this in several ways:
  1. Creating a script that generates the array in a basic ASCII file. I can do one for you, but you have to send me (use a private message) a file.
  2. If the file is a binary, you can convert it to a series of bytes, this way:
    Code:
    REM UDG Data. Avoid the program execution to enter this area
    UdgData:
    ASM
        DEFB 127,145,12,0,0, ...
        DEFB 4,0,122,255,255, ...
        ...
    END ASM
  3. Also, if the file is a binary, you can include the binary file directly using #incbin
    Code:
    UdgData:
    ASM
    #incbin "filename.xxx"
    END ASM
Quote:I downloaded the latest stable version, but when I click on the EXE files none of them open the IDE,
I had to install the boriel program to c: because I dont have privileges to install to program files
Since version 1.2.7 another .zip files with just the .exe files will also be released.
Also, there is no IDE with the ZX Basic. It's all command line. However there are IDEs you can use with ZX Basic:
Reply
#6
thanks, ill check out tommy gun
Reply
#7
ok I got tommy gun working,

this is the code to put the fruit into memory:

POKE UINTEGER 23675, @udg(0, 0):

what if I wanted to create a second UDG
Would I change the 23675 number to something different?


Also, do you know of a speccy emulator that accepts commandline arguments and can load a tzx file in quickly?(not spectacular)

Ive found 2 emulators but they only do one of the above each :x
Reply
#8
slenkar Wrote:ok I got tommy gun working,

this is the code to put the fruit into memory:

POKE UINTEGER 23675, @udg(0, 0):

what if I wanted to create a second UDG
Would I change the 23675 number to something different?
For a 2nd UDG, just put the data following the first one; that is: 16 bytes together
Code:
DIM udg(16) as ubyte => { nn, nn, nn, nn, nn, _' Line break allowed using the "_" character
                      nn, nn, nn} : REM Up to 16 bytes

POKE UINTEGER 23675, @udg(0)
You can also declare it in a more "elegant way":
Code:
DIM udg(1, 7) as ubyte => { { 01, 02, 03, 04, 05, 06, 07, 08}, _ ' Line break with character '_'
                                         {01, 02, 03, 04, 05, 06, 07, 08}} : REM 2nd UDG

POKE UINTEGER 23675, @udg(0, 0)
slenkar Wrote:Also, do you know of a speccy emulator that accepts commandline arguments and can load a tzx file in quickly?(not spectacular)

Ive found 2 emulators but they only do one of the above each :x
I use EmuZWin: https://www.zophar.net/sinclair/emuzwin.html
Unfortunately, it seems abandoned since 2008. It runs ok in Windows XP. If you want to test it under Vista or Win7 you might want to enable "compatibility mode".
Reply
#9
slenkar Wrote:what if I wanted to create a second UDG
Would I change the 23675 number to something different?
23675 is the Spectrums system variable address which holds the address of the UDG set. Changing this number will result in a high crash probability or strange bevaviour. You can define another set of UDGs called e.g. secondudg() and use their name in place of udg()
slenkar Wrote:Also, do you know of a speccy emulator that accepts commandline arguments and can load a tzx file in quickly?(not spectacular)

Ive found 2 emulators but they only do one of the above each :x
I use ZX Spin, it is not Spectacular but loads TZX generazed by ZXBC instantly. In other emulators maybe you can set the loading options to fast/flashload too. And I think, almost all Emulators support commandline arguments.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#10
Quote:70 REM UDG
71 DIM udg(1, 7) AS uByte => { {60, 66, 129, 129, 129, 129, 66, 60}, _
{24, 60, 60, 60, 126, 251, 247, 126}}
73 POKE UINTEGER 23675, @udg(0, 0): REM Sets UDG variable to first element
74 LET S$ = CHR$(144): LET F$ = CHR$(145)

Is CHR(144) the first user defined graphic ?
what is the last one you can have? CHR(?)


and talking of graphics should I investigate the 4sprite library?

also, if I create an image and import it as a BIN, does the sprite go into UDG memory or general memory?

also, is there a script or library that replaces the spectrum font with something nicer?
Reply
#11
slenkar Wrote:
Code:
70   REM UDG
71   DIM udg(1, 7) AS uByte => { {60, 66, 129, 129, 129, 129, 66, 60}, _
                                 {24, 60, 60, 60, 126, 251, 247, 126}}
73     POKE UINTEGER 23675, @udg(0, 0): REM Sets UDG variable to first element
74   LET S$ = CHR$(144): LET F$ = CHR$(145)

Is CHR(144) the first user defined graphic ?
what is the last one you can have? CHR(?)
The above listing is right. You can CHR(144) up to... ???. Honestrly, not sure, but at least you should be able to use up to UDG "Z" (not existing in the original BASIC).
Remeber you can use "\A" instead of CHR$(144) for your commodity, so "\A"..."\Z". I'm currently a bit busy, but if I recall correctly, I wanted the user to use upper ASCII codes as UDG (e.g. PRINTing CHR$(210) won't print a token, but probably rubbish). I will update this info later.
slenkar Wrote:and talking of graphics should I investigate the 4sprite library?

also, if I create an image and import it as a BIN, does the sprite go into UDG memory or general memory?
Al the sprites and UDG go into general memory. In fact, there is no "UDG memory" in ZX BASIC: This is because you are now in machine code (not in real BASIC). Classic UDG graphics were located beyond RAMTOP. Now the RAMTOP is by default 32767 (see CLEAR 32767 in the generated basic listing upon your program exit. Type LIST<enter> after your program return). By doing the above or using incbin and POKEing 23675 you are reserving memory for your UDG the right way.
slenkar Wrote:also, is there a script or library that replaces the spectrum font with something nicer?
By default, PRINT already has some features. Try
Code:
PRINT BOLD 1; ITALIC 1; "HELLO WORLD"
You can use your fonts the same way you defined UDG: Create an array or use incbin, but this time you have to do POKE Uinteger 23606, @Mychars(0,0) - 256. This is the way it was done in basic, and so did I, to maintain compatibility.

Expanding UDG and graphics:
Needless to say you can have several arrays in your program, and POKE them (UDG, or CHARS) during runtime to have several UDG tables. This is very fast (and even more in ASM).
Reply
#12
ok thanks, that makes things clearer
Reply
#13
how would I use an image that was included as a bin

e.g.
ASM
#incbin "factory.bin"
END ASM


then how would i poke it and draw it?
Reply
#14
slenkar Wrote:how would I use an image that was included as a bin

e.g.
ASM
#incbin "factory.bin"
END ASM

then how would i poke it and draw it?
You can use labels, so put a label immediately *before* the asm block:
Code:
POKE Uinteger 23675, @MyUdgBlock
... : REM Your program...
...
STOP : REM Avoid execution to enter this zone!!
MyUdgBlock: REM a simple Label; @Label returns it's memory address
ASM
#incbin "factory.bin"
END ASM
Hope that this makes it clearer!
Reply
#15
thanks

Quote:POKE Uinteger 23675, @MyUdgBlock

How would i poke more than one image?

and then how would I draw more than one?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)