Tiles with NextBasic ?

The Speccy's spritely young offspring. Discuss everything from FPGA to ZX
Post Reply
funkheld
Dizzy
Posts: 55
Joined: Tue May 18, 2021 9:01 pm

Tiles with NextBasic ?

Post by funkheld »

Hi good afternoon.
I don't understand the tiles with the nextbasic.
find no good explanation for how these are created and how they are then used.
who can please help me with a demo?

Thank you.
greeting
funkheld
Dizzy
Posts: 55
Joined: Tue May 18, 2021 9:01 pm

Re: Tiles with NextBasic ?

Post by funkheld »

here is the text for the tile.
Image
Alcoholics Anonymous
Microbot
Posts: 194
Joined: Mon Oct 08, 2018 3:36 am

Re: Tiles with NextBasic ?

Post by Alcoholics Anonymous »

The text above your screenshot in that documentation is relevant so I will quote it here:
Tiling commands
For layer 2 and lo-res modes, there are new commands available to draw complete
screens (or sections of a screen) from a set of tiles and a tilemap.
Tiles are either 8x8 pixels in size or 16x16 pixels in size. This allows a 16K
bank to hold 256 8x8 tiles or 64 16x16 tiles. Tiles are numbered 0..255.
Therefore, a complete set of 8x8 tiles occupies a single 16K bank, and a
complete set of 16x16 tiles occupies 4 16K banks. If you use 16x16 tiles, you
can restrict the tile numbers used and therefore reduce the memory requirements
(eg if you need 64 or fewer different tiles, only 1 16K bank is required).
A tilemap is a linear map of 8-bit tile numbers. The user can specify any width
up to 2048 tiles; each row of tiles follows directly after the previous one.
The tilemap must be fully contained in a single 16K bank. This gives a maximum
tilemap size of 256x64, 128x128, 2048x8 etc.
Any pixels in a tile which are the same colour as the current global
transparency colour (which defaults to 227) will not be written to the screen.
If you want to draw pixels containing the global transparency colour you can
temporarily change it to another colour (not used in your tiles) using the
PALETTE OVER command before using TILE. Alternatively, you can use the LAYER
ERASE command to clear regions of the screen to the global transparency colour
before drawing tiles on top.
Information on layer 2 and lo-res tilemaps is stored separately, so you can use
both.
A tile is either an 8x8 pixel image or a 16x16 pixel image. There can be up to 256 of them identified by number 0-255. NextBASIC is currently supporting this idea of tiles for the lores and layer2 display surfaces. Let's talk about layer2 which is the one colour per pixel layer.

Each pixel of an 8x8 image or 16x16 image will take up one byte to identify one of 256 colours from the layer2 palette. So an 8x8 image will take 64 bytes to define and a 16x16 image will take 256 bytes to define. I don't know for sure but I think the images are defined left to right then top to bottom.

TILE BANK n indicates where the tile images are stored in memory. You would store the image for tile 0, then tile 1, then tile 2, etc. As you can have up to 256 different tile images, if your tiles are 8x8 that's a maximum memory occupation of 64*256 = 16K (one bank). If your tiles are 16x16, that's a maximum memory occupation of 256*256 = 64K (four banks). You can change where the tile images come from at any time by running this command with different n. Since this is not the hardware tile map, this will only affect future draws of tiles.

So far you've only defined tile graphics. Next you need to indicate how the tiles are arranged on screen. You do that by making an array of bytes in memory that identifies tile images by number. Something like this, assuming I have 5 tile images numbered 0-4:

0000000000
1100000100
1220000100
1333033333
4444444444

My tilemap is 10 tiles wide and 5 tiles tall for a total of 50 bytes. If each tile is 8x8 pixels, this represents a screen area 80 pixels wide by 40 pixels tall. If each tile is 16x16 pixels, this represents a screen area 160 pixels wide by 80 pixels tall.

TILE DIM n,offset,w,tilesize indicates where the tile map is located in memory. Again as this is not the hardware tilemap, changing this only affects future tile draws. Notice you can define a tilemap that exceeds the screen's size in width and height. This is to allow scrolling backgrounds to be easily programmed.

Lastly you have commands that causes a region of screen to be drawn using the defined tilemap.

TILE
TILE AT x,y
TILE w,h
TILE w,h AT x,y
TILE w,h TO x2,y2
TILE w,h AT x,y TO x2,y2


w,h indicate how many tiles to draw on screen. x,y indicate the top left coordinate in the tilemap to draw from. x2,y2 indicate the destination tile position on the screen of the top left corner.

If trying to scroll such a tilemap, your tilemap would normally be larger than the screen and you'd hardware scroll layer2 in some direction, say to the left. This will eventually leave an unfilled portion on the right edge that can be drawn using the one of the TILE commands.

*** About memory banks: the 128K Spectrum only has 8 of them numbered 0-7. The 1MB Spectrum Next has 48 of them numbered 0-47 and the 2MB Spectrum Next has 112 of them numbered 0-111. The 128K Spectrum, Spectrum +3 and Next all use banks 0-7 in similar ways with portions reserved for the system and ramdisk. NextBASIC further takes bank 8 for itself. Banks 9-11 and 12-14 are default locations for layer 2 (which you could change). So when using memory banks, it's safest to use 15 or higher. After you are done experimentation, it's best to reserve memory banks from NextBASIC before using them because other things you might use (music player, printer driver) might also take memory and you don't want your basic and those other things to collide.

*** About palettes: when defining tile graphics, each byte identifies a colour in the image. This colour 0-255 is actually a palette entry which is like a table lookup that returns a 9-bit RRRGGGBBB colour to the hardware. You are responsible for programming the palette so that each colour 0-255 maps to colours you want to use. The default is a 1:1 correspondence. IE colour 0 = palette entry 0 contains 0 (RRRGGGBB B = 00000000 0 = black, colour 1 = palette entry 1 contains 1 (RRRGGGBB B = 00000001 1 = medium blue). I've separated the ninth bit because the palette initialization only writes in 8-bit colours 0-255 which causes the 9th blue bit to be automatically generated as the logical OR of the other blue bits).
Alcoholics Anonymous
Microbot
Posts: 194
Joined: Mon Oct 08, 2018 3:36 am

Re: Tiles with NextBasic ?

Post by Alcoholics Anonymous »

A program that lets you draw sprites, tiles, etc on the zx next itself:

https://leeorg.itch.io/krystle-designs

There are many pc tools on github and gitlab written for the pc that do image conversions to the Next. One online on is this one:

https://zx.remysharp.com/tools/

They tend to be less geared toward basic. Some people draw tile graphics in a pc art package on a screen tesselated by 16x16 images and then do a conversion and store the result straight into memory.

Some file formats are described here:

https://wiki.specnext.dev/File_Formats
funkheld
Dizzy
Posts: 55
Joined: Tue May 18, 2021 9:01 pm

Re: Tiles with NextBasic ?

Post by funkheld »

hello thanks for the info.

I have this program to design the tiles on my pc :
https://zx.remysharp.com/sprites/#tiles

greeting
funkheld
Dizzy
Posts: 55
Joined: Tue May 18, 2021 9:01 pm

Re: Tiles with NextBasic ?

Post by funkheld »

Hi good afternoon.
I have split an image into 3x 64 sprites.
it has a sprite size of 16x12 for tiles.

sprite1.spr
sprite2.spr
sprite3.spr

how can I put these sprite1.spr , sprite2.spr and sprite3.spr into one tile below each other?

Thank you
greeting
Image

Image

Image
funkheld
Dizzy
Posts: 55
Joined: Tue May 18, 2021 9:01 pm

Re: Tiles with NextBasic ?

Post by funkheld »

a tilemap is scrolled into 3-screen zones with copper.

greeting


tilemap :

Code: Select all

10 RUN AT 3
20 LAYER 2,1: CLS
30 LOAD "sprite3.spr" BANK 13
40 LOAD "tilesprite1.map" BANK 14
50 TILE BANK 13
60 TILE DIM 14,0,16,16
70 TILE 16,12
80 PAUSE 0
copper with tilemap :

Code: Select all

10 RUN AT 3
20 LAYER 2,1: CLS
30 LOAD "sprite3.spr" BANK 13
40 LOAD "tilesprite1.map" BANK 14
50 TILE BANK 13
60 TILE DIM 14,0,16,16
70 TILE 16,12
90 %x=0 : %y=0 : %z=0
100 repeat
110  %x=%x+1 : if %x > 255 then %x=0
120  %y=%y+2 : if %y > 255 then %y=0
130  %z=%z+3 : if %z > 255 then %z=0
140  pause 1
150  PROC copper()
160 repeat until 0
1010 DEFPROC copper()
1020 reg %$61,0 : reg %$62,0

1030 reg %$60,%$16 : reg %$60,%x
1040 reg %$60,%$80 : reg %$60,64

1050 reg %$60,%$16 : reg %$60,%y
1060 reg %$60,%$80 : reg %$60,128

1070 reg %$60,%$16 : reg %$60,%z
1080 REG %$60,%$ff : REG %$60,%$ff

1090 REG %$62,%@11000000
1100 endproc
Image


Image
funkheld
Dizzy
Posts: 55
Joined: Tue May 18, 2021 9:01 pm

Re: Tiles with NextBasic ?

Post by funkheld »

write line 20 :
20 LAYER 2,1: CLS : LAYER DIM 16,0,239,191

greeting
Image
Post Reply