|
ForumsSega Master System / Mark III / Game GearSG-1000 / SC-3000 / SF-7000 / OMV |
Home - Forums - Games - Scans - Maps - Cheats - Credits Music - Videos - Development - Hacks - Translations - Homebrew |
Author | Message |
---|---|
|
Trying to import Sonic Maps background into my code
Posted: Wed Oct 19, 2022 9:22 pm Last edited by umbe1987 on Thu Oct 20, 2022 10:16 am; edited 1 time in total |
Hello everyone,
before attempting to implement horizontal scroll to my first study project (I am referring to my previous post here), I would like to load a nice and wide background. I have downloaded the first level of Sonic from here, and edited the image so that sprites are not present and the palette is limited to 16 colors (I attach the resulting PNG to this post). The reason I am doing this is because BMP2Tile complained about it upon import, so I thought it was because of the many colors in the palette (bg+sprite, where I would only need bg?). After editing, I was able to import it. So, I fed it to BMP2Tile (v0.61), it took some time to process it, and finally it was converted into tiles+tilemap+palette. In the past, I used to simply copy and paste the plain text output of these three in three separate empty files, gave them a .inc extension and simply imported those in my code. Problem is, the result is a super fuzzy/messy image. I suspect it's because the image is too large and needs compression (I might be wrong though). When I try to save it with BMP2Tile (which I am using through Wine in Linux BTW), I am not sure which compression I am supposed to use, and how I should load them from within my code. Right now, I am importing my current simple .inc background and tiles with this code (taken from Maxim's tutorial): ld hl,$0000 | CRAMWrite call SetVDPAddress ld hl,PaletteData ld bc,PaletteDataEnd-PaletteData call CopyToVDP ld hl,$0000 | VRAMWrite call SetVDPAddress ld hl,TileData ld bc,TileDataEnd-TileData call CopyToVDP ld hl,$3800 | VRAMWrite call SetVDPAddress ld hl,TileMapData ld bc,TileMapDataEnd-TileMapData call CopyToVDP ... PaletteData: include "assets/palette.inc" PaletteDataEnd: TileData: include "assets/tiles.inc" TileDataEnd: TileMapData: include "assets/tilemap.inc" TileMapDataEnd: |
|
|
Posted: Wed Oct 19, 2022 9:37 pm |
The image is much bigger than the video RAM can hold, so when you are loading tilemap data it is in fact writing all over the palette RAM and tile data. Unfortunately you just can't load a big background and scroll around inside it, the tilemap area is only 256x224 pixels (32x28 tiles) and you have to carefully load data into it as needed. | |
|
Posted: Wed Oct 19, 2022 9:46 pm |
I am super thankful for your feedback Maxim! May I ask a hint on how to do that? Should I need e.g. to load the maximum possible data with the same code I presented above, check if I am reaching the end of the "chunk" with my character moving in the level and load the rest only then? Anyway, thanks again for your answer, I really appreciate your help! EDIT Just to say that at this stage I am probably not going to load more than 32x28 tiles, but I am curious as to how more can be loaded, although I totally understand it might not be easy to describe and I might not understand it now, so please feel free to ignore my question. |
|
|
Posted: Thu Oct 20, 2022 6:49 am |
By hiding the left column, you have a 248x192 “window” into the 256x224 tilemap. When you scroll it a little bit, it will show partial tiles on the sides of the screen, so just before tiles become visible as the scrolling changes, you should write a single column or row of tile data to the tilemap.
Emulators like Emulicious and Meka have a tilemap display separate from the game screen which you can use to better understand how it works. I recommend you observe it in an existing game. |
|
|
Posted: Thu Oct 20, 2022 7:07 am |
Will do, thanks! |
|
|
Posted: Thu Oct 20, 2022 10:12 am |
Working :)
Thanks!!!! |
|