Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - devkitSMS - develop your homebrew in C

Reply to topic Goto page Previous  1, 2, 3 ... 10, 11, 12, 13, 14, 15, 16  Next
Author Message
  • Joined: 14 Apr 2013
  • Posts: 623
Reply with quote
Post Posted: Mon Feb 13, 2023 10:00 am
sverx wrote
eruiz00 wrote
Even worst... When I use the working función into the game itself... I get random errors...(each time the game renders a energy capsule... If it's diferent than the previous (there are two colors)... Will load the four tiles fron the zx7... And It fails... I have a interrupt handler with the music playing and real time frame based unsafe update of Up to 12 sprites for the player...

The fact is that, if i use the zx7 to ram... And then the sms_loadtiles function everyrhing works perfect!!!


I start to suspect we have a different issue here...

Are you updating the sprites for the player in a interrupt handler?

If so, this is the issue. If the interrupt handler messes with the VDP and if it interrupts another function that messes with it too, that's when the trouble begins.

The VDP has no 'context' and thus a transfer can't be interrupted by another operation and resumed later. The only way to make such a thing work would be to make all the transfers uninterruptible (or at least broken in atomic chunks) and that's not what SMSlib does as such an approach is very heavy and rarely useful.

What I suggest if you still need to load tiles to VRAM while the interrupts are on, is to stagger the loading into small chunks that can be performed in a short time so that the interrupting code won't ever run on them.

The "inconsistent state after interrupt" exception in Emulicious also triggers on that situation.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Mar 22, 2023 1:24 pm
I pushed a few updates to SMSlib in these last few days

I added
SMS_loadTileMapColumn(x,y,src,height)
to quickly update a single column of tiles on screen. This can be useful especially if you're coding an engine that scrolls horizontally, but can be used for other effects too of course.

then I rewrote in asm the code behind
SMS_loadTileMapArea(x,y,src,width,height)
so this is way faster now. This can be useful to quickly update a rectangular part of the background.

finally, today I added two functions to modify palettes on the fly
void SMS_loadBGPaletteafterColorSubtraction (const void *palette, const unsigned char subtraction_color);
void SMS_loadSpritePaletteafterColorSubtraction (const void *palette, const unsigned char subtraction_color);
with those, you can have the palette applied with all the entries affected by subtracting the components of the provided subtraction_color. What does this mean? This mean you can for instance filter out all the red component from a palette by using RGB(3,0,0) as the subtraction_color parameter, or have all the colors in the palette 'darken' one step by using RGB(1,1,1) as subtraction_color.
It's also very useful for fade-ins and fade-outs. For instance, Phantasy Star like fade-outs could be made by using something like this:


const unsigned char color_reduction[]={RGB(1,0,0), RGB(2,0,0), RGB(3,0,0),
                                       RGB(3,1,0), RGB(3,2,0), RGB(3,3,0),
                                       RGB(3,3,1), RGB(3,3,2), RGB(3,3,3)};

void phantasy_star_fade_to_black (void) {
  unsigned char i;
  for (i=0;i<sizeof(color_reduction);i++) {
    SMS_waitForVBlank();
    SMS_waitForVBlank();
    SMS_waitForVBlank();
    SMS_waitForVBlank();   // put as many frames you want between steps
    SMS_loadBGPaletteafterColorSubtraction(BGpalette_bin, color_reduction[i]);
    SMS_loadSpritePaletteafterColorSubtraction(Spritepalette_bin, color_reduction[i]);
  }
}
which will first reduce your palettes reds to zero, then also the greens to zero and finally the blues too in 9 steps total, the last step being total black, of course.

I hope you will enjoy! :)
  View user's profile Send private message Visit poster's website
  • Joined: 12 Aug 2021
  • Posts: 73
Reply with quote
Post Posted: Wed Mar 22, 2023 1:45 pm
Funnily enough I had to manually make a similar palette darkening code in the past. Good to know that I can ditch that code now ! :D

Also this vertical tilemap update is sure going to be handy !

Thanks for the update :)
  View user's profile Send private message
  • Joined: 06 Mar 2022
  • Posts: 598
  • Location: London, UK
Reply with quote
Post Posted: Wed Mar 22, 2023 2:12 pm
Nice one, these look like great additions - thanks for continuing to maintain the lib!

On the subject, I'm using the recently added SMS_getTileatXY heavily in my competition entry, that was a very timely addition and super useful!
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Mar 22, 2023 3:05 pm
armixer24 wrote
Good to know that I can ditch that code now ! :D


Well, it depends on what exactly that code is doing.

For instance I don't like this kind of fading too much because it doesn't really resemble decreasing the brightness, as it shifts all the color.
But it's quite common on the SMS and it's something that is periodically requested so I added that.
  View user's profile Send private message Visit poster's website
  • Joined: 12 Aug 2021
  • Posts: 73
Reply with quote
Post Posted: Wed Mar 22, 2023 4:33 pm
sverx wrote

Well, it depends on what exactly that code is doing.

Since I was initially coding with GG in mind, I have done a much more basic system.
I have a darkening function which takes a single "darkening amount" parameter with a value between 0 and 15. It subtracts this value from all colour components of the palette, capping them down at 0 if the "darkening amount" is bigger than the colour component's brightness level.
It was fairly basic, but it looks neat on GG, since it has 16 brightness levels for each colour component.

For the SMS version of that code, I was considering doing something similar to your code, but with these values instead:


const unsigned char color_reduction[]={RGB(1,0,0), RGB(1,1,0), RGB(1,1,1),
                                       RGB(2,1,1), RGB(2,2,1), RGB(2,2,2),
                                       RGB(3,2,2), RGB(3,3,2), RGB(3,3,3)};


I would need to check how it looks like in practice, but since your system is more flexible than mine, I could play around with how the fade goes, or even how long it lasts!
  View user's profile Send private message
  • Joined: 04 Jul 2010
  • Posts: 539
  • Location: Angers, France
Reply with quote
Post Posted: Wed Mar 22, 2023 8:15 pm
Few weeks ago i've added a little snippet for smooth screen fading
https://www.smspower.org/Development/SmoothScreenFadingSDCC
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu Mar 23, 2023 8:35 am
armixer24 wrote
I have a darkening function which takes a single "darkening amount" parameter with a value between 0 and 15. It subtracts this value from all colour components of the palette, capping them down at 0 if the "darkening amount" is bigger than the colour component's brightness level.


I see, and you could do the same by using
RGB(1,1,1), RGB(2,2,2), RGB(3,3,3)
with the new functions.

also, I see what you would do with your different fade colors, you would reduce each red, green, blue in turns until they all get to zero. It might look very good, actually! :)

ichigobankai wrote
Few weeks ago i've added a little snippet for smooth screen fading


I have seen that, thanks. I thought it wasn't very flexible as it was, as you would have to modify asm to get to fade only one palette, for example, or to make it fade differently, even just slower or faster.
But recently I had this idea of having functions to create 'skewed' palettes on the fly and one useful use of that surely is to code fade-ins and fade-outs.

Also I am working on palette mixing and I originally thought to release some demo for the competition but I honestly think I won't make it on time. I'll release that when ready (so far it wouldn't even be running properly...)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu Mar 23, 2023 8:40 am
willbritton wrote
I'm using the recently added SMS_getTileatXY heavily in my competition entry, that was a very timely addition and super useful!


That was Raphnet's contribution. I'm happy you find it useful! :D
  View user's profile Send private message Visit poster's website
  • Joined: 04 Jul 2010
  • Posts: 539
  • Location: Angers, France
Reply with quote
Post Posted: Thu Mar 23, 2023 9:35 am
sverx wrote
I have seen that, thanks.


I know you've seen it as I've told you mid january via some PM exchange on Discord ^^
As long as it's a little bit useful for somes, it's cool.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu Mar 23, 2023 10:49 am
ichigobankai wrote
I know you've seen it as I've told you mid january via some PM exchange on Discord ^^


I have a terrible memory, forgive me :|
  View user's profile Send private message Visit poster's website
  • Joined: 04 Jul 2010
  • Posts: 539
  • Location: Angers, France
Reply with quote
Post Posted: Thu Mar 23, 2023 11:25 am
Don't worry there's no problem ;)
  View user's profile Send private message
  • Joined: 09 Jan 2012
  • Posts: 67
  • Location: Germany
Reply with quote
Post Posted: Sat Apr 01, 2023 4:09 pm
Is it possible to use a combination of Everdrive and SMS-MKIII Adapter to create applications greater than 48KB with bank switching?
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Apr 05, 2023 9:36 am
dark wrote
Is it possible to use a combination of Everdrive and SMS-MKIII Adapter to create applications greater than 48KB with bank switching?


The Mark III hardware is almost exactly the same hardware of the SMS so it should run any homebrew with no problems, provided that the EverDrive and the adapter works together fine...
  View user's profile Send private message Visit poster's website
  • Joined: 06 Mar 2022
  • Posts: 598
  • Location: London, UK
Reply with quote
Logo
Post Posted: Thu May 04, 2023 6:43 am
Noticed how many competition entries used devkitSMS this year and got inspired!

  View user's profile Send private message Visit poster's website
  • Joined: 29 Mar 2012
  • Posts: 879
  • Location: Spain
Reply with quote
Post Posted: Thu May 04, 2023 7:21 am
In Gotris latest versions and in my new project I'm using this logo, but it hasn't got any traction :_)
devkitsms.png (1.55 KB)
devkitsms.png

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu May 04, 2023 7:44 am
yeah, devkitSMS has no official logo (yet?) and I know I'm very hard to please (sorry!!!) so I guess everyone can use whatever they fancy and get my bless :) ❤️
  View user's profile Send private message Visit poster's website
  • Joined: 12 Dec 2021
  • Posts: 43
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Sat Jul 08, 2023 1:37 am
sverx wrote
I pushed a few updates to SMSlib in these last few days


I haven't been doing SMS dev much lately, but am sorta getting back into it as I did promise myself to write a demo for the Syntax demoscene party here in Melbourne.

I'll have to check out the fading, as I also have to see if SDCC 4.3.0 breaks my entire project all over again like 4.2.0 did, heh. I guess I got a little discouraged by the function signature changes. So apologies if I've posted some of the following before, it's been a while, heh.

I was playing with palette stuff a while back, similar to this. The code is here, with a few different fuctions / approaches:
https://github.com/mikehdt/sms-demo/blob/main/src/engine/palettes.c
Might be helpful / a starting point for anyone.

One function that might be of interest, sverx, was this one that a friend helped me with:
https://github.com/mikehdt/sms-demo/blob/main/src/helpers/memcpy_expand_byte.c
It's a slightly faster / optimised version of SMS_VRAMmemcpy for the situation where one might want to dump a whole array of 8-bit values quickly to the VDP with the 8- to 16-bit precision expansion short-cutted. It's not a 1:1 replacement of SMS_VRAMmemcpy, just an alternative when you're using an 8-bit data structure that's amenable to its logic and need a bit of extra speed due to the VDP's 16-bit bus.

You're welcome to take it if you think it may be useful for devkitSMS as an extra option for faster VDP transfers for tilemap arrays which are full-row-width.

I use it to drop the plasma and fire effects straight in once their calculations are done, as they're all stored as an array of 8-bit values. Because they're already so taxing on the poor Z80 I need all the speed I can get :)
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sat Jul 08, 2023 2:59 pm
darkowl wrote
One function that might be of interest, sverx, was this one that a friend helped me with:
https://github.com/mikehdt/sms-demo/blob/main/src/helpers/memcpy_expand_byte.c
It's a slightly faster / optimised version of SMS_VRAMmemcpy for the situation where one might want to dump a whole array of 8-bit values quickly to the VDP with the 8- to 16-bit precision expansion short-cutted. It's not a 1:1 replacement of SMS_VRAMmemcpy, just an alternative when you're using an 8-bit data structure that's amenable to its logic and need a bit of extra speed due to the VDP's 16-bit bus.


It might be worth to add a similar function that copies an array of bytes into VRAM as an array of words where all the higher bytes have the same value, but I would probably make it possible to specify that value because one may need not it just be zero, as the high byte contains the msb of the tile counter plus the flip bits, the priority bit and the palette bit. Note that anyway the VRAM update itself won't be faster, you will just save space for the array and you may save some time initializing the values in it.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14688
  • Location: London
Reply with quote
Post Posted: Mon Aug 21, 2023 6:59 pm
Discussion of a VGM player split to https://www.smspower.org/forums/19747-DevKitSMSVGMPlayerAccessingTheEverdriveFil...
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 546
  • Location: Málaga, Spain
Reply with quote
Post Posted: Thu Aug 24, 2023 8:09 pm
Having this error compiling smslib with sdcc 4.3

SMSlib_loadTileMapArea.asm:73: Error: <a> Invalid Addressing Mode.
SMSlib_loadTileMapArea.asm:90: Error: <a> Invalid Addressing Mode.
SMSlib_loadTileMapArea.asm:92: Error: <a> Invalid Addressing Mode.
SMSlib_loadTileMapArea.asm:95: Error: <a> Invalid Addressing Mode.
removing SMSlib_loadTileMapArea.rel
SMSlib_loadTileMapColumn.asm:82: Error: <a> Invalid Addressing Mode.
removing SMSlib_loadTileMapColumn.rel


The commands are:

sdcc -o SMSlib_loadTileMapArea.rel -c -mz80 --opt-code-speed --max-allocs-per-node 100000 --peep-file peep-rules.txt SMSlib_loadTileMapArea.c
sdcc -o SMSlib_loadTileMapColumn.rel -c -mz80 --opt-code-speed --max-allocs-per-node 100000 --peep-file peep-rules.txt SMSlib_loadTileMapColumn.c


Regards
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Aug 25, 2023 6:52 am
so it looks like the newer SDCC reclassified some Z80 instructions in the 'undocumented' category after all.

while I code a workaround, you can add
--allow-undocumented-instructions
to these two command lines and it should work.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Aug 28, 2023 1:45 pm
I just posted a workaround update that should work both with newer and older SDCC.
Let me know if you get any other error, thanks!
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jan 2023
  • Posts: 53
  • Location: Manchester, England
Reply with quote
Post Posted: Mon Aug 28, 2023 10:04 pm
kusfo wrote
In Gotris latest versions and in my new project I'm using this logo, but it hasn't got any traction :_)


Would it be ok if I added this as a splash screen in my projects? It looks really cool and would be a great way for to raise more awareness for this awesome tool that makes programming for the Master System so much more accessible ^_^
  View user's profile Send private message Visit poster's website
  • Joined: 10 Aug 2023
  • Posts: 31
Reply with quote
Post Posted: Tue Aug 29, 2023 2:21 am
Hi there!

I'm a long time homebrew dev and for the past while I've been working on a devkitSMS-based project. I post updates under pw_32x on Twitter/X. The project is located on github at pw32x/ninjagirl/

(I can't post actual links yet since I'm new)

Unsurprisingly I've been struggling a lot with performance. The worst issue at the moment is setting up sprites.

If you look at the image below, the pink area in the left and right columns is a visualization of the time spent setting up the sprites for the three eyeballs. As you can see, it's a large part of a frame.

The objects themselves are 4x4 sprites each, 48 sprites total. Now, I understand that the Master System isn't a graphical powerhouse. Games typically have smaller sprites. This scene is meant as an aide, as optimizations are easier to see visually.

But still, I'm wondering how I could speed it up.

In the game, sprite resources are made up of an array of XY offsets and an index into a array of tiles. XY are offsets to the object's screen position and the tile index is an offset to the location of the object's tiles in VDP.

An example of a sprite resource can be found here:
pw32x/ninjagirl/blob/main/project/source/client/exported/evil_eye.c, line 827

const AnimationSprite evil_eyeFrame0Sprites[] =
{
   // X offset, Y offset, tile index
    { -15, -16, 0 },
    { -7, -16, 1 },
    { 1, -16, 2 },
     etc...


I have functions to draw the sprites, the main one being DrawUtils_Draw(void) in

pw32x/ninjagirl/blob/main/project/source/engine/draw_utils.c, line 64.

The switch jumps to the case that matches the number of sprites to draw and falls through every subsequent case to draw the rest.

The draw call's variables are setup with the DRAWUTILS_SETUP macro in draw_utils.h.

The function call at every sprite is an obvious performance hit. I think a function that handles an array of sprites should be faster. Something like SMS_addSprites(screenX, screenY, vdpTileStart, spriteXYT* arrayOfSpriteTiles) but I'm not an assembly guy so I wouldn't know how to write that.

I've seen SMS_addTwoAdjoiningSprites and SMS_addThreeAdjoiningSprites but I don't think they quite fit my use case.

Any ideas of what else could I look at?

Thanks!

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Aug 29, 2023 8:01 am
Louis The SEGA Nerd wrote
kusfo wrote
In Gotris latest versions and in my new project I'm using this logo, but it hasn't got any traction :_)


Would it be ok if I added this as a splash screen in my projects? It looks really cool and would be a great way for to raise more awareness for this awesome tool that makes programming for the Master System so much more accessible ^_^


sure! as devkitSMS doesn't have an official logo, you can use whatever you prefer :)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Aug 29, 2023 8:12 am
pw wrote
Hi there!
[...]
Unsurprisingly I've been struggling a lot with performance. The worst issue at the moment is setting up sprites.
[...]


Welcome! :)

Yes, setting up sprites takes a lot of time, and this is expected.

There are a few ways you can (partially) workaround this issue, for instance:
- you can use 'tall' sprites (8×16 pixels) instead of regular ones, so you will only need half of them to draw the same object. This will save you 50% of the time spent setting up sprites.
- you can group them in two or three when they're adjoining horizontally and use SMS_addTwoAdjoiningSprites / SMS_addThreeAdjoiningSprites. This will save you approximately 50% of time on the second (and third) sprite.
- you can recompile the library using NO_SPRITE_CHECKS - there won't be any safety net using the sprites (check this note) but you would save approximately 25% of time at every call.

Note you can even combine some -or even all- of the previous.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14688
  • Location: London
Reply with quote
Post Posted: Tue Aug 29, 2023 8:27 am
I guess you could also manage the sprite table as arrays and just (unsafe) emit the data in the vblank; but that would require more effort to make the data be as required. SDCC tends to be slow when dealing with array indices, so instead you’d want to work with pointers. Implementing sprite table reordering for flicker could be done at the time of writing it out.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Aug 29, 2023 1:50 pm
@Maxim - the alternative of *not* using any of the SMS_addSprite* functions is surely to write to the sprite tables yourself directly using the metasprite data, but to be faster than calling the functions then you need to rearrange the metasprite data in some other way - probably all the Y deltas first and the X deltas and Tile IDs later.

At the moment devkitSMS/SMSlib has no metasprite support but if I find a smart idea I could try adding that. But generic metasprite support is not interesting, and there's too little advantage.
  View user's profile Send private message Visit poster's website
  • Joined: 29 Mar 2012
  • Posts: 879
  • Location: Spain
Reply with quote
Post Posted: Tue Aug 29, 2023 7:24 pm
Louis The SEGA Nerd wrote
kusfo wrote
In Gotris latest versions and in my new project I'm using this logo, but it hasn't got any traction :_)


Would it be ok if I added this as a splash screen in my projects? It looks really cool and would be a great way for to raise more awareness for this awesome tool that makes programming for the Master System so much more accessible ^_^


Sure! And we have sverx blessings, :-D
  View user's profile Send private message
  • Joined: 10 Aug 2023
  • Posts: 31
Reply with quote
Post Posted: Wed Aug 30, 2023 12:39 am
Thanks for the suggestions!

I switched over to the NO_SPRITE_CHECKS version of SMS_addSprite and gained about 30 scan lines for the same scene, so that's pretty good.

I don't think I'll be using the 8x16 sprites. It would be useful if most of the sprites were square-ish, but I think game objects will be all kinds of shapes.

I have no problems with rearranging the meta sprite format to better pass its data to the drawing functions. At the moment I'm thinking about how I could format them so I could use the add 2 or 3 sprite functions. During export I already break down game objects into horizontal strips of sprites.

I don't think creating an add 4 sprites function should be that difficult to whip up, even if I'm not adept at assembly. The pattern's already there with the other two functions.

I think having the option of drawing sprites in vertical strips might also useful. It would be easier to handle drawing large objects when there's clipping at the sides.

Stuff to think about!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Aug 30, 2023 8:14 am
pw wrote
I don't think I'll be using the 8x16 sprites. It would be useful if most of the sprites were square-ish, but I think game objects will be all kinds of shapes.


I see, but sometimes to save on some resource (CPU, or number of total sprites for example) you have to spend more on others, such as having some sprites use some empty tile...

But anyway I would say opting for 8×16 sprites is mostly driven by needing more stuff on screen. If you don't, you likely keep 8×8 sprites.
  View user's profile Send private message Visit poster's website
  • Joined: 04 Jul 2010
  • Posts: 539
  • Location: Angers, France
Reply with quote
Post Posted: Wed Aug 30, 2023 8:22 am
As Sverx say, 8x16 is top for pushing more(faster) sprites on screen as you have only 1 declaration for 2 (joined) sprites.

Shape is not a real problem, but you'll have to write some tools to handle/prepare them.

  View user's profile Send private message
  • Joined: 10 Aug 2023
  • Posts: 31
Reply with quote
Post Posted: Wed Aug 30, 2023 11:28 pm
Yep, you guys are right. I've had time to think about it and it makes the most sense. I definitely should be looking into it.


Edit: SEVERAL HOURS LATER

I switched the engine and animation exporter over to using 8x16 sprites and basically performance has doubled. I guess I shouldn't be surprised :)

Thanks a lot guys!

Next step is looking at the draw adjacent sprite functions for potentially an extra boost.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu Aug 31, 2023 7:26 am
pw wrote
Next step is looking at the draw adjacent sprite functions for potentially an extra boost.


In NO_SPRITE_CHECKS mode, such a boost would likely be 15 to 20% - so it might be a good idea only if you don't spend more time outside the call itself...
  View user's profile Send private message Visit poster's website
  • Joined: 10 Aug 2023
  • Posts: 31
Reply with quote
Post Posted: Sun Sep 03, 2023 3:38 pm
When looking at the SMS_add****AdjoiningSprites_f functions, I've noticed that at the beginning it does a check to see if there are enough sprites free to draw the row and exits early if it doesn't. Yet later on in the function, it checks the limit for every sprite and returns if it does. Did I read that right?


In terms of progress, I've added a SMS_addFourAdjoiningSprites_f and converted my sprite exporter and sprite drawing to work with adjoining sprites. I got another nice performance boost out of it so I'm quite happy about that.
  View user's profile Send private message
  • Joined: 27 Feb 2023
  • Posts: 122
  • Location: France
Reply with quote
Post Posted: Sat Sep 09, 2023 7:25 pm
I am having an issue tonight on my project, and couldn't find the reason.

My first project was on Game Gear, and I have now moved on the MS for the second one. I managed to make a scrolling worldmap (by streaming the content etc...) and it works quite well.

The next step is to push sprites on the screen.

But, for some obscure reason, it seems that anytime I use the SMS_VRAMmemset function, the game simply hangs. On GG, I have been using it all the time for pushing sprites and coordinates, and I was intending on doing the same on MS.

I also tried using my clear_VRAM function (which relies on VRAMmemset) at the very beginning of the code (almost the first thing I do) and I get the same result : the console and display hangs. Using SMS_VRAMmemcpy does not hang, but it does not do exactly what I want.

Using SMS_Addsprite does hang as well (probably doing a VRAMmemset call I guess)

Any advice will be appreciated, thanks :)

Edit : I have compilation warnings actually, probably the issue :


?ASlink-Warning-Undefined Global '_SMS_VRAMmemset' referenced by module 'common_utils'

?ASlink-Warning-Undefined Global '_SMS_VRAMmemset' referenced by module 'handle_worldmap_banked'

I don't get this warning with SMS_VRAMmemcpy.
  View user's profile Send private message
  • Joined: 10 Aug 2023
  • Posts: 31
Reply with quote
Post Posted: Sun Sep 10, 2023 4:30 am
Regarding the UNSAFE_SMS_* functions. When is the appropriate time to call them?
  View user's profile Send private message
  • Joined: 04 Jul 2010
  • Posts: 539
  • Location: Angers, France
Reply with quote
Post Posted: Sun Sep 10, 2023 4:38 am
Vblank or when the screen is off.
  View user's profile Send private message
  • Joined: 29 Mar 2012
  • Posts: 879
  • Location: Spain
Reply with quote
Post Posted: Sun Sep 10, 2023 8:15 am
cireza wrote


Edit : I have compilation warnings actually, probably the issue :


?ASlink-Warning-Undefined Global '_SMS_VRAMmemset' referenced by module 'common_utils'

?ASlink-Warning-Undefined Global '_SMS_VRAMmemset' referenced by module 'handle_worldmap_banked'

I don't get this warning with SMS_VRAMmemcpy.


This warning means the SMS_VRAMmemset is not found after the linking phase, so you are calling some random point of memory.

As I suppose the other functions work, that may be either a mismatch on library versions or maybe some typo in the name?
  View user's profile Send private message
  • Joined: 06 Mar 2022
  • Posts: 598
  • Location: London, UK
Reply with quote
Post Posted: Sun Sep 10, 2023 8:37 am
SMS_VRAMmemset is a macro so you shouldn't be seeing it as a missing symbol - check you have the right version of SMSlib.h and that it's being included properly.

The warning you posted is a linker warning, not a compilation one. Did you get any warnings from the *compiler* before this one perhaps?
  View user's profile Send private message Visit poster's website
  • Joined: 27 Feb 2023
  • Posts: 122
  • Location: France
Reply with quote
Post Posted: Sun Sep 10, 2023 10:00 am
Thanks, got it to work. I was planning on reinstalling everything, but could not make it work. I eventually realized that I had been working on the master branch of devkitsms, and not the latest release.

I got confused and could not make it work until I understood that I had actually downloaded the master branch when sverx made updates around March this year (thanks for the support by the way, I remember having some good gains with it, especially in the % of code generated).

It is now working properly, here is a quick picture of the worldmap where I was able to randomly put my first sprite (I am using TALL mode as this will help moving around less sprites).
Capture.PNG (138.5 KB)
compiling_works_again!
Capture.PNG

  View user's profile Send private message
  • Joined: 10 Aug 2023
  • Posts: 31
Reply with quote
Post Posted: Mon Sep 11, 2023 12:35 am
How could SMS_loadTileMapAreaatAddr be modified so that it takes a vdp tile index? For example, I have a tile map that with elements that start at 0 but the tileset isn't always stored at the start of tile memory.
  View user's profile Send private message
  • Joined: 04 Jul 2010
  • Posts: 539
  • Location: Angers, France
Reply with quote
Post Posted: Mon Sep 11, 2023 12:57 pm
The best is to convert/export your tiles/map with PNG2tile, it can generate a Tiled map file. Then you can edit or create a new map with it. (Tiled is a very nice map editor ; https://www.mapeditor.org)
You'll have to create a converter for the TMX file (binary or asm).
You can surely find this kind of stuff on Github (or ask on Tiled's discord channel)
  View user's profile Send private message
  • Joined: 27 Feb 2023
  • Posts: 122
  • Location: France
Reply with quote
Post Posted: Mon Sep 11, 2023 5:13 pm
pw wrote
How could SMS_loadTileMapAreaatAddr be modified so that it takes a vdp tile index? For example, I have a tile map that with elements that start at 0 but the tileset isn't always stored at the start of tile memory.

In case this might be of use, here is a post where I explained how I proceed (of course other people might do differently).
https://www.smspower.org/forums/19690-SMSDevelopmentTools#126896

This process has me create the tiles, a dictionary of metatiles and then I store the map as a big array of metatiles. As suggested by ichigobankai, I use Tiled to create my maps and BMP2Tile for the conversion process (same thing as PNG2Tile).

And then I resort to functions to find the corresponding metatile and draw it.

For example :
void draw_single_metatile(unsigned char right, unsigned char down) {

   unsigned char nb_tilemap, d, r;

   nb_tilemap = getMetaTileFromPos(right, down);

   //draw the 2x2 square of tiles corresponding to the metatile
   for(d=0; d<2; d++) {
      for(r=0; r<2; r++) {
         SMS_mapROMBank(BANK_CHIPSET);
         SMS_setTileatXY(right*2+r,down*2+d, world_meta_tilemaps_dict[nb_tilemap*4+d*2+r]);
      }
   }
}

The function getMetaTileFromPos tells me which metatile I have to draw (when iterating to draw the screen).

Then I set each tile manually using setTileatXY, it is very easy to add an offset to the tile number you wish to display.

SMS_setTileatXY(right*2+r,down*2+d, world_meta_tilemaps_dict[nb_tilemap*4+d*2+r] + 48);

SMS_setTileatXY(right*2+r,down*2+d, world_meta_tilemaps_dict[nb_tilemap*4+d*2+r] + tile_offset);

Of course you might not need metatiles at all. You can simply put your offset in setTileatXY and that's it.

Hope this helps.
  View user's profile Send private message
  • Joined: 27 Feb 2023
  • Posts: 122
  • Location: France
Reply with quote
Post Posted: Sat Sep 16, 2023 2:30 pm
Hello,

Here is a question about makesms usage. I am currently building a GG game with it but something is not working as expected. For some reason, I am not getting the expected information at address 0x7FF0 in my rom.

I am calling the functions to set the header exactly like in my previous game. However I am now uing makesms since I am banking code (instead of ihx2sms). I can clearly see that ihx2sms includes the details correctly while it seems empty with makesms.

The result is that my Game Gear/Everdrive treats the rom as a SMS game instead of a GG game (the rom is named rom.gg).

The header is included at the top of my main.c file, exactly like in my previous game. I did uncomment the #define TARGET_GG in the SMSlib.h file as well.


#include "header/common_utils.h"
#include "header/gameplay.h"
#include "header/handle_battle_banked.h"
#include "header/handle_worldmap_banked.h"
#include "header/SMSlib.h"
 
//GG ROM header
SMS_EMBED_SEGA_ROM_HEADER(9999,0);
SMS_EMBED_SDSC_HEADER(0,0,2023,8,23,"cireza","COMM_REBL_SECT","COMM_REBL_SECT");

unsigned char RANDOM_SEED;

void main (void)
{
...
}


Compiling details :

sdcc -o sms.ihx -mz80 --no-std-crt0 --data-loc 0xC000 -Wl-b_BANK1=0x14000 -Wl-b_BANK2=0x24000 -Wl-b_BANK3=0x38000 -Wl-b_BANK4=0x48000 -Wl-b_BANK5=0x58000 -Wl-b_BANK6=0x68000 -Wl-b_BANK7=0x78000 crt0/crt0_sms.rel SMSlib_GG.lib source/PSGlib/PSGlib.rel main.rel gameplay.rel common_utils.rel palette.rel handle_battle_banked.rel handle_worldmap_banked.rel chipset_worldmap_tiles.rel chipset_worldmap.rel charset_hero_comm.rel charset_hero_rebl.rel charset_hero_sect.rel

makesms sms.ihx out/rom.gg


Thank you for your help ! :)
compiled_with_ihx2sms.PNG (55.74 KB)
ihx
compiled_with_ihx2sms.PNG
compiled_with_makesms.PNG (44.59 KB)
makesms
compiled_with_makesms.PNG

  View user's profile Send private message
  • Joined: 06 Mar 2022
  • Posts: 598
  • Location: London, UK
Reply with quote
Post Posted: Sun Sep 17, 2023 8:26 am
Your bank virtual addresses seem to jump by an extra 0x4000 between bank 2 and bank 3 - shouldn't they go like 0x14000, 0x24000, 0x34000, 0x44000, etc.?

Not sure that would cause the issue you're seeing but might do.

sverx did mention earlier this year that there might be a problem with makesms and I'm not sure if we ever confirmed it had been fixed. In any case you might want to make sure you are using the latest version.
  View user's profile Send private message Visit poster's website
  • Joined: 27 Feb 2023
  • Posts: 122
  • Location: France
Reply with quote
Post Posted: Sun Sep 17, 2023 10:36 am
willbritton wrote
Your bank virtual addresses seem to jump by an extra 0x4000 between bank 2 and bank 3 - shouldn't they go like 0x14000, 0x24000, 0x34000, 0x44000, etc.?

Not sure that would cause the issue you're seeing but might do.

sverx did mention earlier this year that there might be a problem with makesms and I'm not sure if we ever confirmed it had been fixed. In any case you might want to make sure you are using the latest version.

Thank you for answering.

My understanding is that I have to specify 0x?4000 for code banks and 0x?8000 for data banks, as it tells in which place the data of the bank is supposed to be loaded (bank1 or bank2).

I can always put the data manually with a hex editor, but I lose some convenience in the process.

I am currently using the master branch of devkitsms, so this has to be the latest.
  View user's profile Send private message
  • Joined: 06 Mar 2022
  • Posts: 598
  • Location: London, UK
Reply with quote
Post Posted: Sun Sep 17, 2023 1:15 pm
cireza wrote
My understanding is that I have to specify 0x?4000 for code banks and 0x?8000 for data banks, as it tells in which place the data of the bank is supposed to be loaded (bank1 or bank2).

Where did you get that understanding from? You may be right, but that doesn't match my understanding as I thought that banked code and data ought to be able to be mixed freely, I hadn't thought you had to assign a whole 16KB to either code or data but not both.
I have never used banked code, but have used in-line bank preprocessor directives together with the SDCC linker switches to bank data at the source code level and can't imagine how you would go about keeping banked code and data separate.

EDIT: okay I've read through the docs again and I see what you mean, the first digit of the virtual address is a bank number and the rest of it tells the linker which slot it should map to, so setting it to 0x?4000 I think means always use slot 1 as I guess that is the only slot that banked code can work in.

Can you see from any intermediate, e.g. lst files, which segment the TMR Sega header is actually going into?

I wonder if you actually need to put your header macros into code that's going to be banked by default into slot 1 (i.e. Bank 1), rather than at the top of main?
  View user's profile Send private message Visit poster's website
  • Joined: 27 Feb 2023
  • Posts: 122
  • Location: France
Reply with quote
Post Posted: Sun Sep 17, 2023 2:01 pm
willbritton wrote
I wonder if you actually need to put your header macros into code that's going to be banked by default into slot 1 (i.e. Bank 1), rather than at the top of main?

Why didn't I think about that ? You are right, my headers end up at the end of bank0.

I will put them in by first bank of code. Thanks !

Edit : I tried but it seems it is still not going at the expected place :(
Stays at 3F00
Capture.PNG (55.58 KB)
Capture.PNG

  View user's profile Send private message
Reply to topic Goto page Previous  1, 2, 3 ... 10, 11, 12, 13, 14, 15, 16  Next



Back to the top of this page

Back to SMS Power!