+mksmith Posted June 23, 2020 Share Posted June 23, 2020 One of the things a have been struggling with at times is keeping data tables within the 256 byte size limit. This is two-fold issue - the table size and calculating an offset. According to the documentation on accessing regular data, the size is limited to 256 bytes and if you wanted to create larger it is suggested to use sequential tables - each has their pros and cons. So what if I told you there is a way to access tables larger than this quickly and easily?? Most of us probably use tables for either map data or some sort of grid style layout or lookup. During Millie and Molly development I discovered I could use the peekchar function to replace calculating an offset to my RAM based table containing the background layout (as objects move the background needed to be restored). This worked great as I could replace a convoluted offset calculation using co-ordinates. I then expanded this and used the pokechar function to update this and other tables in RAM as needed. Getting back to Arkanoid recently, I started reworking this with my learnings from M&M. Whilst building the background for the Doh level I required a more expansive table as this level background contains many more tiles (another learning from M&M - replace large sprite strips with tiles. Mike outlines this process here) than the standard levels. I initially looked at different methods to build the display but it was getting pretty messy (won't bore you with the details!). Anyway I eventually thought lets just put in the whole table (13*26-338 bytes) and set it up to copy into a RAM table and see what happens. So I fired up the debugger in A7800 and looking at this RAM area - wow hang-on the whole thing is in there! Ok great, so lets try just accessing it from ROM. Bingo, the level started up and displayed as I was expecting!! How does it work? The code below gives you the basics to configure and read your table from ROM (this will also work using a RAM table): Any limitations? Talking to @RevEng about it the only real limitation potentially is your X,Y needs to stay within the 256x256 limit (this is theory only!) rem vars dim offsetX = var0 dim offsetY = var1 dim objectIndex = var2 rem lookup loop for offsetY = 0 to 25 for offsetX = 0 to 12 rem get object objectIndex = peekchar(levelPlayfield,offsetX,offsetY,13,26) rem TODO: add you code here... next next data levelPlayfield 1, 2, 2,12, 13, 2, 2, 2, 12,13, 2, 2, 3 4,37,38,37, 45, 46, 47, 48, 49,37,38,37, 8 4,39,40,39, 50, 51, 52, 53, 54,39,40,39, 8 5,41,42,41, 55, 56, 57, 58, 59,41,42,41, 9 6,43,44,43, 60, 61, 62, 63, 64,43,44,43,10 7,37,38,37, 65, 66, 67, 68, 69,37,38,37,11 4,39,40,39, 70, 71, 72, 73, 74,39,40,39, 8 4,41,42,41, 75, 76, 77, 78, 79,41,42,41, 8 5,43,44,43, 80, 81, 82, 83, 84,43,44,43, 9 6,37,38,37, 85, 86, 87, 88, 89,37,38,37,10 7,39,40,39, 90, 91, 92, 93, 94,39,40,39,11 4,41,42,41, 95, 96, 97, 98, 99,41,42,41, 8 4,43,44,43,100,101,102,103,104,43,44,43, 8 5,37,38,37,105,106,107,108,109,37,38,37, 9 6,39,40,39,110,111,112,113,114,39,40,39,10 7,41,42,41,115,116,117,118,119,41,42,41,11 4,43,44,43,120,121,122,123,124,43,44,43, 8 4,37,38,37, 38, 37, 38, 37, 38,37,38,37, 8 5,39,40,39, 40, 39, 40, 39, 40,39,40,39, 9 6,41,42,41, 42, 41, 42, 41, 42,41,42,41,10 7,43,44,43, 44, 43, 44, 43, 44,43,44,43,11 4,37,38,37, 38, 37, 38, 37, 38,37,38,37, 8 4,39,40,39, 40, 39, 40, 39, 40,39,40,39, 8 5,41,42,41, 42, 41, 42, 41, 42,41,42,41, 9 6,43,44,43, 44, 43, 44, 43, 44,43,44,43,10 7,37,38,37, 38, 37, 38, 37, 38,37,38,37,11 end For me this opens up a whole lot of possibilities! I hope you can find it useful too! 4 Quote Link to comment Share on other sites More sharing options...
SlidellMan Posted June 23, 2020 Share Posted June 23, 2020 I might have to try using your table, though what code to use in the rem TODO section would confuse me. That, and figuring out how to use it in the games I want to make. 1 Quote Link to comment Share on other sites More sharing options...
+SmittyB Posted June 23, 2020 Share Posted June 23, 2020 That's a pretty neat solution. Another possibility would be to have an array of pointers to other arrays using 'indirect variable arrays' but that would definitely be limited to 256*256 and the code wouldn't be anywhere near as clean. 1 Quote Link to comment Share on other sites More sharing options...
+Muddyfunster Posted June 23, 2020 Share Posted June 23, 2020 Thanks for this example Mat, really useful. I've been wrestling with some aspects of the engine in EXO and I wanted to move away form using sprites to represent certain background elements, this gives me a few ideas Cheers. 2 Quote Link to comment Share on other sites More sharing options...
+mksmith Posted June 23, 2020 Author Share Posted June 23, 2020 3 hours ago, SlidellMan said: I might have to try using your table, though what code to use in the rem TODO section would confuse me. That, and figuring out how to use it in the games I want to make. Well thats the fun bit ? I'm using the basis of this code to plot objects into the screen. The objectIndex gives me a reference to the object I want to plot for example: rem playfield images incgraphic gfx/playfield/playfield_0.png 160A 0 2 incgraphic gfx/playfield/playfield_border1.png 160A 0 2 3 1 incgraphic gfx/playfield/playfield_border2.png 160A 0 2 3 1 incgraphic gfx/playfield/playfield_border3.png 160A 0 2 3 1 incgraphic gfx/playfield/playfield_border4.png 160A 0 2 3 1 incgraphic gfx/playfield/playfield_border5.png 160A 0 2 3 1 incgraphic gfx/playfield/playfield_border6.png 160A 0 3 2 1 incgraphic gfx/playfield/playfield_border7.png 160A 0 2 3 1 incgraphic gfx/playfield/playfield_border8.png 160A 0 2 3 1 incgraphic gfx/playfield/playfield_border9.png 160A 0 2 3 1 incgraphic gfx/playfield/playfield_border10.png 160A 0 3 2 1 incgraphic gfx/playfield/playfield_border11.png 160A 0 2 3 1 incgraphic gfx/playfield/playfield_border12.png 160A 0 2 3 1 incgraphic gfx/playfield/playfield_border13.png 160A 0 2 3 1 rem playfield (base) renderY = 16 for offsetY = 0 to 25 for offsetX = 0 to 12 rem object objectIndex = peekchar(levelPlayfield,offsetX,offsetY,13,26) rem location renderX = (offsetX*12) rem draw plotsprite playfield_0 0 renderX renderY objectIndex next rem increment renderY = renderY + 8 next data levelPlayfield 1, 2, 2,12,13, 2, 2, 2,12,13, 2, 2, 3 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,11 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,11 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,11 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,11 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,10 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,11 In this example the extra parameter in plotsprite allows us to 'offset' from the base image to another image in the gfx block. To do this you incgraphic the 'playfield' images in index order and lookup the levelPlayfield table for the index. The only caveat to this method is the images must be in the same gfx block. Using a little bit of what SmittyB is talking about with object pointers this can be enhanced a little further 3 hours ago, SmittyB said: That's a pretty neat solution. Another possibility would be to have an array of pointers to other arrays using 'indirect variable arrays' but that would definitely be limited to 256*256 and the code wouldn't be anywhere near as clean. Definitely lots of possibilities using array pointers! 1 hour ago, Muddyfunster said: Thanks for this example Mat, really useful. I've been wrestling with some aspects of the engine in EXO and I wanted to move away form using sprites to represent certain background elements, this gives me a few ideas Cheers. There may be ways ? 1 Quote Link to comment Share on other sites More sharing options...
SlidellMan Posted June 24, 2020 Share Posted June 24, 2020 Can offsets be wider than 26 (0-25) and taller than 13 (0-12) within the 256 byte limit? Quote Link to comment Share on other sites More sharing options...
+mksmith Posted June 24, 2020 Author Share Posted June 24, 2020 8 hours ago, SlidellMan said: Can offsets be wider than 26 (0-25) and taller than 13 (0-12) within the 256 byte limit? Yes definitely! You can make a rectangle/square of your desired size - it's up to you. 1 Quote Link to comment Share on other sites More sharing options...
TwentySixHundred Posted June 25, 2020 Share Posted June 25, 2020 Thanks for sharing Matt, i was asking about something like this on discord the other night. So this example will really help to create boundaries for the playfield maps. I think i understand most of it, just need to work out the parts im not 100% sure about. ? 3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.