char and color ....x16

All aspects of programming on the Commander X16.
Post Reply
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

char and color ....x16

Post by funkheld »

Hi good afternoon.

I can't get through to the char and color yet.
How do the values combine with color , background-color, char without background-color etc.

Where can you read this please?

------------------------
cx16.vpoke(1,$b000,1)
cx16.vpoke(1,$b000+1,1*16+2) ?????

------------------------

Thanks.
greeting
Attachments
char-1.jpg
char-1.jpg (3.07 KiB) Viewed 1075 times
hstubbs3
Posts: 72
Joined: Thu Oct 26, 2023 12:14 pm

Re: char and color ....x16

Post by hstubbs3 »

There's 2 1bpp modes... from playing around with vpoke yesterday, the kernal mode used 1-bpp- 16 color

https://github.com/X16Community/x16-doc ... -text-mode

Tile mode 1 bpp (16 color text mode)
T256C should be set to 0.

MAP_BASE points to a tile map containing tile map entries, which are 2 bytes each:

Offset Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
0 Character index
1 Background color Foreground color

So setting something like $10 for color in this mode would make the character inversed -> transparent on white background

If its the other mode -

Tile mode 1 bpp (256 color text mode)
T256C should be set to 1.

MAP_BASE points to a tile map containing tile map entries, which are 2 bytes each:

Offset Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
0 Character index
1 Foreground color

then $10 would set the foreground color to 16...
https://github.com/X16Community/x16-doc ... alette.png

which is black ....


so try setting the color code to $10 ( or 16) and see if you get black on transparent or transparent on white... Then you can tell which mode the text is in and what colors are available?
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: char and color ....x16

Post by funkheld »

hello thanks for color-info and kacheln.

I will ask more questions please.
I don't really understand the tiles yet.

what exactly are tiles/kacheln?
are tiles/kacheln chars?
Where are the tiles made and stored please?
How are the tiles written on the screen?

thanks
greeting
hstubbs3
Posts: 72
Joined: Thu Oct 26, 2023 12:14 pm

Re: char and color ....x16

Post by hstubbs3 »

>what exactly are tiles/kacheln?
tiles are 8 pixel by 8 pixel (well, by default - the VERA can do tilemaps 8x8,8x16x16x8,or16x16) images at the appropriate bitdepth... The text mode for both BASIC and the prog8 library you were using uses 8x8 1bpp (1 bit per pixel) graphics.
So at $TILE_BASE_ADDRESS, these are stored 1 after the other .. in binary it would look something like this -
00000000 ; +0, tile 0 -> blank
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000 ; +8, tile 1 -> A
00011000
00100100
01000010
01111110
01000010
01000010
00000000
......

every 8 bytes -> 1 tile .
>are tiles/kacheln chars?
that is how the text modes use the tiles, but one could use them for any 8x8 bit of graphics... as an example, I would highly recommend checking out the youtube videos on PETSCII robots, which utilized the tile set to do all the drawing on the PET and a few other versions.
Other examples of this type of graphics scheme would be on the NES - the CHAR ROM contained 2 sets of 256 tiles the video chip could use for graphics...

in the 1bpp tile modes, only 256 tiles can be addressed, in the 2bpp,4bpp,8bpp ( 4 color, 16 color, 256 color ) tile modes, the 2bytes in the MAP data are defined differently -
MAP_BASE points to a tile map containing tile map entries, which are 2 bytes each:

Offset Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
0 Tile index (7:0)
1 Palette offset V-flip H-flip Tile index (9:8)

allowing up to 1024 different tiles and ability to flip them vertically or horizontally.

>Where are the tiles made and stored please?
KERNAL puts the tile set here - $1:F000-$1:F7FF Charset
https://github.com/X16Community/x16-doc ... ace-layout

I tend to create tiles using a text editor, using binary or hex constants..
IE - in my assembly code might use this for 1bpp
.byte %00000000
.byte %00011000
.byte %00100100
.byte %01000010
.byte %01111110
.byte %01000010
.byte %01000010
.byte %00000000

But that would be the same as this string of HEX values -
.byte $00,$18,$24,$42,$7E,$42,$42,$00

>How are the tiles written on the screen?
By using a tiled layer mode, TILEBASE points to where tile #0 would start in VRAM, and then in the MAP you use the tile indexes.
IE - the charset the kernal uses has 'A' as tile #1, so to write an A onto the screen somewhere requires writing a 1.. 'F' is tile #6, etc.. and you would write those to the address corresponding with the row and column in the map.

if you wanted to place a 'tile' somewhere randomly on the screen... say at (137,53), then you would need to use a SPRITE or use a BITMAP mode layer and copy the pixels there yourself. ( Copying pixels in this way is often called 'blitting', in case you are trying to find more info on that technique)... BITMAP layers can be 1,2,4,or 8 bpp , SPRITES are limited to being 4 or 8bpp - you either have 16 color sprite or 256 color sprite ...

For a game, especially something trying to look like say an NES or SNES style game, layer0 might be configured to use a 2bpp or 4bpp tile mode.. with the map data and tiledata put somewhere in VRAM where there's room..

That would be for the background / level itself..
Then sprites between layer0 and layer1 for enemies, power ups, etc..

And maybe leave layer1 as text mode, so that you can write HUD or other text as an overlay.

You always ask where these things are stored... but the VERA is highly configurable, so unless you are using a particular defined mode, like say the way BASIC / KERNAL sets things up, or a particular programming library, the locations in VRAM are up to you, as well as which layers are enabled/disabled and the other assorted features, like switching the display from 640x480 to 320x240 or 160x120 or 256x192 or various points in-between with the scale registers ..
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: char and color ....x16

Post by funkheld »

Hello, here is my example.

kachel 0 is : x=10 , y=50
txt.plot(10,50)
txt.print("@")
txt.color(col)

tiles/kacheln are chars?
I used tile/kachel 0 here in the example.

Can you please put the tiles at your own address?

thanks

Code: Select all

const uword VERA_CHARSET = $f000        ; $1f000

sub makechar() {
	ubyte b
        cx16.vaddr_autoincr(1, VERA_CHARSET, 0, 1)       
                        b=255
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b		
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=255
			cx16.VERA_DATA0 = b   
			
			b=131
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b		
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b   

                        b=255
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b		
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b   

                        b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b		
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=255
			cx16.VERA_DATA0 = b    

                        b=128+64+2+1
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b		
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=255
			cx16.VERA_DATA0 = b    

			b=24
			cx16.VERA_DATA0 = b			
			b=24
			cx16.VERA_DATA0 = b			
			b=24
			cx16.VERA_DATA0 = b		
			b=24
			cx16.VERA_DATA0 = b			
			b=24
			cx16.VERA_DATA0 = b			
			b=24
			cx16.VERA_DATA0 = b			
			b=24
			cx16.VERA_DATA0 = b			
			b=24
			cx16.VERA_DATA0 = b          
    }
    
thanks
greeting
Attachments
kachel.jpg
kachel.jpg (15.38 KiB) Viewed 916 times
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: char and color ....x16

Post by funkheld »

Hi good afternoon.

If I change tile 0 during the game, then all tiles 0 that were previously written change.

can you please change that?

Code: Select all

sub keypress(ubyte key) {
        when key {
	  'r' -> makechar()
          't' -> makechar1()
        }
    }
    
sub makechar() {
	ubyte b
        cx16.vaddr_autoincr(1, VERA_CHARSET, 0, 1)       
                        b=255
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b		
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=255
			cx16.VERA_DATA0 = b   
			
    }
	
	sub makechar1() {
	ubyte b
        cx16.vaddr_autoincr(1, VERA_CHARSET, 0, 1)       
                        b=0
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b		
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=129
			cx16.VERA_DATA0 = b			
			b=0
			cx16.VERA_DATA0 = b   
			
    }
    
Thanks.
greeting
kelli217
Posts: 532
Joined: Sun Jul 05, 2020 11:27 pm

Re: char and color ....x16

Post by kelli217 »

Sorry, that is intended behavior. All displays of tile 0 use the same data. If you wish to make a change, and only have it affect one place, then you must define a new tile (tile 1, tile 2, etc.) and place it in that location in the map where you wish to see the change.

This does indeed mean that you should be careful to pay attention to your memory usage in how many tiles you define, especially if they are large tiles with many colors.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: char and color ....x16

Post by funkheld »

hello thanks for info.

greeting
Post Reply