Jump to content
IGNORED

Peekchar & tiled with multiple tilesets


Recommended Posts

Hi all,

 

I'm trying to get my head around peekchar. My understanding is that I can use this to determine the value character at a particular position.

 

What happens if in tiled i'm using multiple tilesets, do they go up cumulatively ?

 

eg. if I have 3 tilesets,

  • tileset 1 with 5 tiles is that (0-5)
  • tileset 2 with 5 more tiles (6-10) 
  • tileset 3 with 2 tiles (11-12)

 

Would pokechar then also work in a similar way?

 

 

Edited by Muddyfunster
Link to comment
Share on other sites

Tiled internally keeps track of the first ID for each tileset so that each tile effectively has a unique ID based on the order in which your tilesets were imported meaning, yes, your example is correct.

 

When you import the map data all it's actually taking is the list of IDs that make up the map, so it's up to you make sure your tile graphics start in a new block and are imported in the same order so that the IDs Tiled uses line up with the offsets the 7800 uses for drawing.

When you use peekchar it's then just reading one of the IDs in the map (based on a few parameters to make it easier to get the specific byte you want) and giving you the result.

  • Thanks 1
Link to comment
Share on other sites

Something I should have said before is that with your tiles you'll need to be careful to make sure that the size of your tiles in Tiled is appropriate for the graphics mode you're using. The tile height should match your zone height (so probably 8 or 16) and the width should be 4 pixels for 160A, or 8 for 320A, then doubled to 8 or 16 respectively if you have doublewide tiles enabled.

  • Like 2
Link to comment
Share on other sites

2 hours ago, SmittyB said:

Something I should have said before is that with your tiles you'll need to be careful to make sure that the size of your tiles in Tiled is appropriate for the graphics mode you're using. The tile height should match your zone height (so probably 8 or 16) and the width should be 4 pixels for 160A, or 8 for 320A, then doubled to 8 or 16 respectively if you have doublewide tiles enabled.

Thanks Smitty,

 

Right now i'm using 160A with a width of 8 (so 4 doubled with doublewide) and a height of 8 (zoneheight is 8 )

 

I did look at using 160B tiles, just an experiment, but struggle to get them to load. Happy with 160A tiles at the moment.

 

It's one of my many educational work in progress projects, thanks again for the pointers.

 

 

Link to comment
Share on other sites

I assume that when I peekchar the result is decimal not hex?

 

is there a way to see what tile has been assigned what value? 

 

I added some code based on the ramcharmap example to convert my char sprite to peekchar co-ordinates and then look at what tile value the sprite is on, i'm getting what look like hex numbers when I plotvalue the number that comes back from peekchar.

 

is there a way to get an index of my tiles?

 

Sorry for so many questions, appreciate any guidance :)

 

 

Link to comment
Share on other sites

When you use peekchar it returns the value of whichever byte it reads from the map data, and as hex and dec are ways to represent that value the value itself is not inherently one or the other.

When you use use plotvalue it's likely not showing you what you expect because it expects the value you give it to be binary-coded-decimal which is somewhat different as it's effectively expecting an entirely different number that represents the value you actually want to see.

 

7800BASIC includes a function for converting to BCD as per the snippet below from the guide.

Quote

If you wish to display a regular variable, 7800basic also includes a “converttobcd” utility function that returns the BCD value of a non-BCD variable. The non-BCD variable should be in the range between 0-99, or else it will start to display incorrect values.


   BCDVar=converttobcd(NonBCDVNonBCDVar)

 

 

If you open your TMX file in a text editor you should see at the top where it lists your tilesets and each will have a 'firstID' value (or something similar) but apart from that Tiled kind of leaves it to you to work it out. When you mouse over a tile it will show the offset of to the tile into the tileset which should be the same as the ID for the first tileset but if say your second tileset starts at the 32nd tile, Tiled would show you an ID of 3 for what would actually be the 37th tile.

Similarly, as the 7800 doesn't really deal with 'tiles' in the usual sense it's just up to you to know which tile it thinks of as tile 0 and how it goes from there.

 

I'm also doubting myself about how doublewide affects things with Tiled because it's been a while since I've used it so I apologise in advance if anything I've said previously turns out to be incorrect.

  • Like 2
Link to comment
Share on other sites

Thanks Smitty.

 

You were right about the tile id's. I managed to get the test program working and displaying the id, it was still showing hex (AA) so i thought, what the hell, lets try it and I converted that to decimal (170) I tried a simple "if peekchar = 170 then turn the background red else turn the background black", it worked. So tentatively I think I've got it working! thanks again for the pointers.

 

Going to tinker some more tomorrow on preventing movement through the scenery tiles.

Link to comment
Share on other sites

Something else I discovered today : it seems that you cannot have an IF..THEN plotmapfile

 

eg. 

if screen = 0 then plotmapfile gfx/exotest1.tmx exotest1 0 0 20 24

wont compile

 

I would have to work around this with something like 

 

if screen = 0 then goto plot_screen_0

plot_screen_0

plotmapfile gfx/exotest1.tmx exotest1 0 0 20 24

am I missing something or is that code flow expected?

Link to comment
Share on other sites

I don't know the answer to your question, but I was thinking that if you have multiple screens, it might be a good use for on ... goto, e.g.:

 

	on screen goto plot_screen_0 plot_screen_1 plot_screen_2 plot_screen_3
plot_screen_0
	plotmapfile gfx/exotest1.tmx exotest1 0 0 20 24
    goto end_plot_screen
plot_screen_1
	plotmapfile gfx/exotest2.tmx exotest2 0 0 20 24
    goto end_plot_screen
plot_screen_2
	plotmapfile gfx/exotest3.tmx exotest3 0 0 20 24
    goto end_plot_screen
plot_screen_3
	plotmapfile gfx/exotest4.tmx exotest4 0 0 20 24
    goto end_plot_screen
end_plot_screen

 

  • Like 2
Link to comment
Share on other sites

2 hours ago, Muddyfunster said:

Something else I discovered today : it seems that you cannot have an IF..THEN plotmapfile

[...]

wont compile. am I missing something or is that code flow expected?

This is a limitation that came in in the door with bB, that I need to address at some point. The underlying code that skips an if...then uses 6502 branching, and if a particular 7800basic command or sequence of commands generates more than 128 bytes worth of rom within the if clause, it causes a branch-out-of-range issue in the generated assembly.

 

It's triggered a bit more frequently in 7800basic than bB (but not overly frequent) because some of the 7800basic statements generate more rom usage than anything you'll find in bB.

 

Karl's suggestion is more CPU friendly than a bunch of if clauses, while also working around the problem neatly.

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Sorry to bump this topic but i have been racking my brain for some time with peekchar. Im wanting to read an individual alphadata value stored in RAM for platforms/gravity ect. The method i have been using is too dodgy and long winded and id rather just call for what tiles the player is standing on. After breaking down the ramcharmap sample it's still going over my head as for understanding how to read the correct tiles.

 

Might have a rest for tonight and reload tomorrow, just waiting for this to click and make sense. Anyway i could be back with some layman questions lol

Link to comment
Share on other sites

Ok so after having a chance to play around tonight and try to work out exactly whats going on with peekchar, still no dice. After having a read through the Mikes blog and breaking down the ramcharmap sample i have ended up with this. Makes sense to me, however im obviously missing something here as the player just freefalls. Also i am using tallsprites, doublewide, preloaded RAM tiles and 160A mode

 mytemp1=(playerx+4)/8 : rem 8 is our zoneheight 
 mytemp2=playery/4 : rem 4 is 160A character width, but x2 for doublewide 
 mytemp2=mytemp2+1 : rem the block under our feet

 playerchar=peekchar(screendata,mytemp1,mytemp2,20,12)

 if playerchar=5 then P0C3=$30 : goto DONEFALLING

 playery=playery+1.0 ; player grav

DONEFALLING

Im sure there is something im overlooking

Link to comment
Share on other sites

18 minutes ago, TwentySixHundred said:

if playerchar=5 then P0C3=$30 : goto DONEFALLING

I'm guessing it's this line. doublewide means two characters are used for every one, so you probably want 10 here instead of 5. That's a mistake I made before. 

  • Like 1
Link to comment
Share on other sites

Thanks Karl and yeah that makes sense since you pointed it out although im still getting the same result though. No matter the value im checking none seem to work besides 0, however strange things happen without rhyme or reason. Also just been throwing different random values at everything but that's not causing much of a difference either. Cheers anyway ?

Link to comment
Share on other sites

 

57 minutes ago, TwentySixHundred said:

mytemp2=playery/4 : rem 4 is 160A character width, but x2 for doublewide

Also, why are you dividing by 4 for the Y value? Shouldn't that also be 8?  Also FYI you have the comments for Y on the X line and vice versa, which makes it a bit confusing to read.  ? 

  • Like 1
Link to comment
Share on other sites

Yeah i divided by 4 to test if there was any effect as 8 wasn't working. Also yeah i flipped the temps around for x and y without changing the comments lol. To be honest it's usually how i reverse engineer code samples i don't fully understand. By temporarily switching things around and watching for whatever crazy results occur, i can usually work out what effects what lines of code. #visual_learner ?

Link to comment
Share on other sites

Just to check it off the list, did you copy the level rom data to your screendata memory with memcpy? Heads up that if you have other graphics in the block before your characters, the values will be offset.

 

Also, try displaying what peekchar is returning on the screen, with plotvalue. That helps with debugging.

  • Like 1
Link to comment
Share on other sites

52 minutes ago, Karl G said:

So, it didn't work when you changed it back to dividing by 8, and checking for playerchar=10, either? If so, I'm out of ideas at the moment. Maybe someone smarter and more experienced with 7800basic will figure it out, though. :-D

Still no dice, and now even after throwing random numbers nothing is changing. I have no idea why this simple command is not making sense to me yet ?

52 minutes ago, RevEng said:

Just to check it off the list, did you copy the level rom data to your screendata memory with memcpy? Heads up that if you have other graphics in the block before your characters, the values will be offset.

 

Also, try displaying what peekchar is returning on the screen, with plotvalue. That helps with debugging.

Yeah Mike i have been using memcpy to store the alphadata into RAM. Not 100% sure what you mean by graphics in the block before characters although i can stab any values in there and still get the same freefalling result.

 

After plotting the value im getting 64 but this never changes whilst the player is freefalling. I would assume as the player pos updates so would peekchar in return making the value change depending on the tile the player is over.

 

Im sure it's something really simple im just overlooking or have left out ?

 

EDIT: So interestingly i have changed the condition statement to

if playerchar=64 then P0C3=$30 : goto DONEFALLING

Just to see what would happen and turns out the playerchar value is not 64.

Edited by TwentySixHundred
Link to comment
Share on other sites

15 minutes ago, TwentySixHundred said:

Not 100% sure what you mean by graphics in the block before characters although i can stab any values in there and still get the same freefalling result.

The 7800 has locations of ROM that graphics need to go into, so they display properly. Each time you do an "incgraphic mygraphic.png" it will import graphics into the current graphics block, until it's full, and then it moves on to the next. If you check the compile messages, you'll see stuff like...

 

*** (): INFO, GFX Block #1 starts @ $A000
        mysprite1 mysprite2 playfield_tiles
        [...]

In the above example, the first "playfield_tiles" character won't be character index "0", because there are other graphics that proceed it in it's graphics block. To force it to be at position 0, you'd reorder things so playfield_tiles comes first. (and if there are other incgraphic statements prior, you might need a "newblock" before the incgraphic for the tiles.)

 

Aside from looking at that, I think you need to temporarily disable the falling code, and just add some temp code allow your player to be moved all around the screen by joystick. See if the values change where they should, and what they change to.

Link to comment
Share on other sites

21 minutes ago, TwentySixHundred said:

EDIT: So interestingly i have changed the condition statement to

if playerchar=64 then P0C3=$30 : goto DONEFALLING

Just to see what would happen and turns out the playerchar value is not 64.

The value returned isn't BCD format, so if plotvalue displays "64", it's actually "$64".

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...