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 ... 16, 17, 18
Author Message
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Sep 25, 2024 8:38 am
nice effect!
I'm totally fine with everyone creating their logo as they see fit, as there's not really an official one.
  View user's profile Send private message Visit poster's website
  • Joined: 23 Sep 2024
  • Posts: 4
  • Location: US
Reply with quote
question
Post Posted: Wed Sep 25, 2024 7:25 pm
So is this a program like Genesis has SGDK I want to make a shmup using sprites I created. Also what language is used assembly?
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu Sep 26, 2024 6:13 am
Yes, this is similar to what SGDK is for Genesis. It's using the C language, as the topic title says.
You can read a quick introduction at this wiki.
  View user's profile Send private message Visit poster's website
  • Joined: 09 Jan 2012
  • Posts: 78
  • Location: Germany
Reply with quote
Post Posted: Fri Oct 04, 2024 5:52 pm
First, thanks for timer handler, it works great, but the reason why I'm writing again, is SDCC 4.4 currently supported because I am getting linker error messages like:

Quote
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "console".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "strings".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "engine".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "views".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "widgets".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "main".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "font".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "levels".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "city".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "audio".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "modunsigned".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "mulchar".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "divunsigned".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "_modslong".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "_modulong".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "_divslong".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "_divulong".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "mul".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "modsigned".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "_mullong".
?ASlink-Warning-Conflicting sdcc options:
"-mz80" in module "SGlib" and
"-mz80 sdcccall(1)" in module "divsigned".


SDCC 4.3 works fine with the same code.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sat Oct 05, 2024 3:32 pm
These are warnings, you can ignore them.
Anyway, I suspect if you remove --sdcccall 1 from your SDCC command line (it's the default anyway) the warnings will likely go away.
  View user's profile Send private message Visit poster's website
  • Joined: 09 Jan 2012
  • Posts: 78
  • Location: Germany
Reply with quote
Post Posted: Thu Dec 05, 2024 9:09 pm
Hi, I searched the web for SFX samples and found the following site: https://harmlesslion.com/sn_sfxr/

Unfortunately something isn't right, I suspect wrong loops.
Vgmplay and Winamp can play this tracks but showing a wrong length.
Psglib only plays a long tone.
How can I fix this?
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Dec 06, 2024 8:24 am
I've never seen that web page before, but it seems a nice tool!
As for what I can tell, the VGMs looks fine - I generated this VGM which contains (vgm2txt tool output):

VGM Header:
VGM Signature:      "Vgm "
File Version:      0x00000110 (1.10)
EOF Offset:      0x00000066 (absolute)
GD3 Tag Offset:      0x00000000 (absolute)
Data Offset:      0x00000040 (absolute)
Total Length:      3675 samples (00:00.08 s)
Loop Point Offset:   0x0000025C (absolute)
Loop Start:      4293842011 samples (530:65566.03 s)
Loop Length:      1128960 samples (00:25.60 s)
Recording Rate:      60 Hz
SN76496 Clock:      3579540 Hz
SN76496 Feedback:   0x00
SN76496 ShiftRegWidth:   15 bits
SN76496 Flags:      0x00
YM2413 Clock:      0 Hz - unused
YM2612 Clock:      0 Hz - unused
YM2151 Clock:      0 Hz - unused
SegaPCM Clock:      0 Hz - unused
SegaPCM Interface:   0x00000000
RF5C68 Clock:      0 Hz - unused
YM2203 Clock:      0 Hz - unused
YM2203 AY8910 Flags:   0x00
YM2608 Clock:      0 Hz - unused
YM2608 AY8910 Flags:   0x00
YM2610 Clock:      0 Hz - unused
YM3812 Clock:      0 Hz - unused
YM3526 Clock:      0 Hz - unused
Y8950 Clock:      0 Hz - unused
YMF262 Clock:      0 Hz - unused
YMF278B Clock:      0 Hz - unused
YMF271 Clock:      0 Hz - unused
YMZ280B Clock:      0 Hz - unused
RF5C164 Clock:      0 Hz - unused
PWM Clock:      0 Hz - unused
AY8910 Clock:      0 Hz - unused
AY8910 Type:      0x00 - AY-3-8910A
AY8910 Flags:      0x00
Volume Modifier:   0x00 (0) = 1.000
Reserved (0x7D):   0x00
Loop Base:      0x00 = ±0
Loop Modifier:      0x00 (MaxLoops * 0.00)
GB DMG Clock:      0 Hz - unused
NES APU Clock:      0 Hz - unused
MultiPCM Clock:      0 Hz - unused
UPD7759 Clock:      0 Hz - unused
OKIM6258 Clock:      0 Hz - unused
OKIM6258 Flags:      0x00
K054539 Flags:      0x00
C140 Type:      0x00
OKIM6295 Clock:      0 Hz - unused
K051649 Clock:      0 Hz - unused
K054539 Clock:      0 Hz - unused
HuC6280 Clock:      0 Hz - unused
C140 Clock:      0 Hz - unused
K053260 Clock:      0 Hz - unused
Pokey Clock:      0 Hz - unused
QSound Clock:      0 Hz - unused

VGMData:
0x00000040: 50 84       SN76496:   Latch/Data: Tone Ch 0 -> 0x004
0x00000042: 50 03       SN76496:   Data: 03
0x00000044: 50 93       SN76496:   Latch/Data: Volume Ch 0 -> 0x3 = 80%
0x00000046: 62          Wait:   735 samples (1/60 s)   (total   735 (00:00.01))
0x00000047: 50 84       SN76496:   Latch/Data: Tone Ch 0 -> 0x004
0x00000049: 50 03       SN76496:   Data: 03
0x0000004B: 50 95       SN76496:   Latch/Data: Volume Ch 0 -> 0x5 = 66%
0x0000004D: 62          Wait:   735 samples (1/60 s)   (total   1470 (00:00.03))
0x0000004E: 50 84       SN76496:   Latch/Data: Tone Ch 0 -> 0x004
0x00000050: 50 03       SN76496:   Data: 03
0x00000052: 50 98       SN76496:   Latch/Data: Volume Ch 0 -> 0x8 = 46%
0x00000054: 62          Wait:   735 samples (1/60 s)   (total   2205 (00:00.05))
0x00000055: 50 84       SN76496:   Latch/Data: Tone Ch 0 -> 0x004
0x00000057: 50 03       SN76496:   Data: 03
0x00000059: 50 9B       SN76496:   Latch/Data: Volume Ch 0 -> 0xB = 26%
0x0000005B: 62          Wait:   735 samples (1/60 s)   (total   2940 (00:00.06))
0x0000005C: 50 84       SN76496:   Latch/Data: Tone Ch 0 -> 0x004
0x0000005E: 50 03       SN76496:   Data: 03
0x00000060: 50 9D       SN76496:   Latch/Data: Volume Ch 0 -> 0xD = 13%
0x00000062: 62          Wait:   735 samples (1/60 s)   (total   3675 (00:00.08))
0x00000063: 50 9F       SN76496:   Latch/Data: Volume Ch 0 -> 0xF = 0%
0x00000065: 66          End of Data


and it seems correct to me. I then tried converting it to PSG format and the result is what is expected.

Note that this SFX uses channel 0, are you using channel 0 too?
  View user's profile Send private message Visit poster's website
  • Joined: 09 Jan 2012
  • Posts: 78
  • Location: Germany
Reply with quote
Post Posted: Sat Dec 07, 2024 3:52 pm
Oh, thanks after checking my code again it sounds much better when you put the PSG(SFX)Frame in the correct scope, my fault.
Btw. when should I use sfx routines?
Is this only for the channel parameter so you can mix music and sfx together?

PS:
Any chances to get a tile decompression into SGlib?
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun Dec 08, 2024 4:47 pm
you need to tell the vgm2psg converter tool which channel(s) the SFX uses, and then also pass that parameter when firing the SFX from code

Quote
Any chances to get a tile decompression into SGlib?

Let me see what I can do :)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Dec 10, 2024 12:19 pm
@dark: I think I could add ZX7 to be used as general data compressor, making it decompress directly to VRAM - how would you create the asset anyway? BMP2Tile has no support for 'legacy' modes AFAIK...
  View user's profile Send private message Visit poster's website
  • Joined: 09 Jan 2012
  • Posts: 78
  • Location: Germany
Reply with quote
Post Posted: Thu Dec 12, 2024 7:11 pm
I'm using my python script(already posted here somewhere) for converting images like start and death screen. For this I use 1,5 segments(256+128 tiles) of the screen, the rest on top and bottom is free for text.
You see in the output of my build environment, there aren't much space left.

Btw. Do the sprite data uses the same data format as tile data? For the tile data you need second array for the index(2x4bits) to map to the fix color palette, for each tile line(FG, BG). But the sprite have only one color per sprite, so how do I set the colors? Technically the BG should be always color index 0.
output.jpg (368.4 KB)
output.jpg

  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 567
  • Location: Málaga, Spain
Reply with quote
Sprite clipping
Post Posted: Thu Dec 12, 2024 9:17 pm
Hi Sverx!

Working for the next competition, I am trying to archieve 50/60fps instead of the 2 frames in 1 technique I have been using in the past, for that I am using GSlib (faster than my scroll engine) and I am refining my engine to have only the needed functionality. In the process, I realised that I need optimizing functions for some things, in particular for sprite clipping.

The question is if would be logic to have the adjoining SMS_addSprites (Two,Three and Four) with clipping, or I have some alternative (by example the metasprites functionality with clipping) with similar performance.

Even more, maybe I do not need vertical clipping, only horizontal one, as is very difficult to have a sprite based block with more than 64 pixels height.

Regards!
  View user's profile Send private message
  • Joined: 28 Jan 2017
  • Posts: 567
  • Location: Málaga, Spain
Reply with quote
Post Posted: Thu Dec 12, 2024 9:45 pm
By example, this would be a clipping add_two_adjoining sprites one:

unsigned char drawTwoSprites(unsigned int x, unsigned int y, unsigned char base)
{
   // Check y
   y-=windowtop;
   if((y>192)&&(y<65536-16))return 0;
   
   // Adjust with map
   x-=windowleft;
   if(x<256-8)
   {
      SMS_addTwoAdjoiningSprites(x,y,base);
      return 1;
   }
   else if(x<256)
   {
      SMS_addSprite(x,y,base);
      return 1;
   }
   else if(x>(65536-8))
   {
      SMS_addSprite(x+8,y,base+2);
      return 1;
   }
   else return 0;
}


windowleft and windowtop are the coordinates of the window in the gslib map, to get the absolute position to draw the sprite.

It could be done better than this? Maybe the metasprites (if they have clipping) will be faster than this approach? I am thinking in 16x16, but also in 24x32, 32x32... up to 32x48 sprites.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Dec 13, 2024 10:02 am
dark wrote
I'm using my python script(already posted here somewhere) for converting images like start and death screen. For this I use 1,5 segments(256+128 tiles) of the screen, the rest on top and bottom is free for text.
You see in the output of my build environment, there aren't much space left.


I see, so I will add ZX7 decompression to VRAM, and I also should look into turning SGlib into a real library (I mean, made of a few modules instead of being a single module) so that to save ROM when functions aren't used.
It will require some time, though.

dark wrote
Btw. Do the sprite data uses the same data format as tile data? For the tile data you need second array for the index(2x4bits) to map to the fix color palette, for each tile line(FG, BG). But the sprite have only one color per sprite, so how do I set the colors? Technically the BG should be always color index 0.


A sprite color is the fourth parameter in
SG_addSprite (unsigned char x, unsigned char y, unsigned char tile, unsigned char attr)
the tile data has the same format as the BG tiles AFAIK.

@eruiz00 - I suspect you're trying to map world coordinates to screen coordinates, but SMSlib can't do that, so you have either to use the provided SpriteClipping functions (which are indeed slow) or write code to determine when a sprite gets clipped, which looks like what you're doing already. Metasprites can help with their clipping, but you still have to determine if each metasprite needs to be drawn or not, as they can't be placed outside of the screen.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Dec 13, 2024 4:45 pm
First step done, I just pushed an update to SGlib adding the
SG_decompressZX7toVRAM(const void *src, unsigned int dst)
function, that can be easily called through one of the macros
SG_loadZX7compressedBGTiles(src,tilefrom)
SG_loadZX7compressedSpritesTiles(src,tilefrom)
depending on if you want to load tiles for the background or tiles for the sprites

Let me know if this works, I'll work on breaking the SGlib single module into parts later, hopefully soon.
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 567
  • Location: Málaga, Spain
Reply with quote
Post Posted: Sat Dec 14, 2024 10:24 pm
Ummmm....

I checked the metasprite code and i saw that it has some sort of clipping for the sprites, so I made an utility to convert a tilemap from bmp2tile to a metasprite definition (using the coordinates 0,0 - 8,0 - 0,8 - 8,8 ..... ) and it worked, yeah!

but I found that, as the position parameters for the metasprites are unsigned chars, I suppose that the clipping iis done, but you cannot draw a metasprite with, let's say... negative coordinates for the origin, or cordinates greater than 256, 192, so I returned to the function published before (although I have to develop functions for other array sizes, 32x40, 32x64....)
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun Dec 15, 2024 2:41 pm
@eruiz00: yes, that's what I meant to say regarding metasprites, they don't work in 'wide' coordinates, so you can't say place a metasprite at (-2,100) and have part of it show on screen, you can only place them on screen using screen coordinates and have the parts outside of screen removed - the best you can do is to put a metasprite origin in a central point and let half of it disappear when it goes close to the border

also remember, you can't place any hardware sprite at any negative X coordinate showing only a part of it on screen, the only alternatives are:
- early clock mode bit (all sprites are placed 8 pixels left of their coordinate)
- hide the leftmost 8 pixels of screen and use that as a new border (as sprite won't appear on top of the hidden part)
  View user's profile Send private message Visit poster's website
  • Joined: 09 Jan 2012
  • Posts: 78
  • Location: Germany
Reply with quote
Post Posted: Sun Dec 15, 2024 5:59 pm
Hi,
there is a typo in the readme of SGlib, should be named with a prefix SG_.

Are there tutorials out there how to set up Sublime with the Emulicious Debugger plugin?
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 567
  • Location: Málaga, Spain
Reply with quote
Post Posted: Sun Dec 15, 2024 6:09 pm
sverx wrote
@eruiz00: yes, that's what I meant to say regarding metasprites, they don't work in 'wide' coordinates, so you can't say place a metasprite at (-2,100) and have part of it show on screen, you can only place them on screen using screen coordinates and have the parts outside of screen removed - the best you can do is to put a metasprite origin in a central point and let half of it disappear when it goes close to the border

also remember, you can't place any hardware sprite at any negative X coordinate showing only a part of it on screen, the only alternatives are:
- early clock mode bit (all sprites are placed 8 pixels left of their coordinate)
- hide the leftmost 8 pixels of screen and use that as a new border (as sprite won't appear on top of the hidden part)


Yeah, I saw it... so I returned to my adhoc functions (one per size) with optimized clipping, something like the ones I used in electric dreams but more optimized (and now, that I am doing my little pure asm functions, I am very happy with the performance, it's not too hard!!!).

A bug I found is in GSLib, I explain, if I make this:

unsigned int *meta=GSL_metatileLookup(tilex,tiley);
*meta=newvalue;
GSL_metatileUpdate();


The screeen update will fail if the four tiles are, horizontally, partially out of screen (by example, if the first column is in column 31). It is not a big trouble for me, as I am using my own ansi c function, but it is a bug.

I explain, gslib will update two metatiles, the one pointed by *meta and the next one (updating 8 tiles in total).

I don't know if you have energy to dive into gslib (as it is a long and very complex code), I do not need such fix, really, it's only for your information.

Regards.
  View user's profile Send private message
  • Joined: 14 Apr 2013
  • Posts: 641
Reply with quote
Post Posted: Sun Dec 15, 2024 8:40 pm
dark wrote
Hi,
there is a typo in the readme of SGlib, should be named with a prefix SG_.

Are there tutorials out there how to set up Sublime with the Emulicious Debugger plugin?

You should be able to set it up following the instructions for Sublime's Sublime Debugger extension.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Dec 16, 2024 9:24 am
dark wrote
there is a typo in the readme of SGlib, should be named with a prefix SG_.


Thanks. I'm still learning how to properly copy&paste...

eruiz00 wrote
A bug I found is in GSLib


I'm keeping a copy of Psidum's original code with a few bugfixes here - see if that works better, and please file an issue (or alternatively post here) if the bug is still there, thanks!
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 567
  • Location: Málaga, Spain
Reply with quote
Prepend sprites
Post Posted: Sun Dec 22, 2024 8:28 am
Hi, happy christmas to everyone!

I realised that I need to have a function to add an sprite in front of the previously added ones in the same frame.

Could it be possible?

I refer to something like this:

SMS_addTwoAdjoiningSprites(124,40,232);
SMS_prependTwoAdjoiningSprites(124,40,232); <-- these two sprites are going to be shown in front of the prior ones.

I know, I could change the workflow for each frame to put these sprites earlier, but I would need to include an additional loop (for all enemies that need this feature) and I am short of cpu&vdp time (as always xD)

regards.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun Dec 22, 2024 2:52 pm
eruiz00 wrote
I realised that I need to have a function to add an sprite in front of the previously added ones in the same frame.
Could it be possible?


You might want to use
signed char SMS_reserveSprite (void)
so that you can 'set aside' one/a few sprites to be possibly used later if they are needed. Example:
reserved1=SMS_reserveSprite();
reserved2=SMS_reserveSprite();

then if later you then realize you needed those, you then use these two functions:
void SMS_updateSpritePosition (signed char sprite, unsigned char x, unsigned char y)
void SMS_updateSpriteImage (signed char sprite, unsigned char tile)

for instance something like
SMS_updateSpritePosition (reserved1, 100, 120);
SMS_updateSpriteImage (reserved1, EXPLOSION_SPRITE);
SMS_updateSpritePosition (reserved2, 108, 120);
SMS_updateSpriteImage (reserved2, EXPLOSION_SPRITE+2);

I don't know if this solves your specific issue but I hope it will :)
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 567
  • Location: Málaga, Spain
Reply with quote
Post Posted: Sun Dec 22, 2024 8:05 pm
Could I use these functions without reservesprite first? I am thinking in direct editing of the sprite table without having to reserve the 64 available sprites... and set the number of used sprites without having to reserve them.

are the reserved values a serie of numbers? (-63, -62, -61.... o 0,1,2...)
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Dec 23, 2024 9:06 am
yes, in theory you could do that by reserving all the 64 sprites once in the beginning and the repositioning them at every frame, but I suspect it will be much slower, so that's likely not a good idea

another approach could be to completely skip the sprite functions and directly access the sprite buffers, but again it's hardly going to be faster

can't you simply add a check in your loop over the enemies that if some flag is set you'll first add the additional sprites and then add the regular ones? I mean, I don't know exactly what you're doing so I have no idea of what I'm saying...
  View user's profile Send private message Visit poster's website
  • Joined: 28 Jan 2017
  • Posts: 567
  • Location: Málaga, Spain
Reply with quote
Post Posted: Mon Dec 23, 2024 10:59 am
I got a solution, but not technical, I changed some visual aspect of the game and now it is not needed, it was an interesting theme for me, to touch the sprite table without use of the SMS_devkit functions.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Dec 23, 2024 1:03 pm
eruiz00 wrote
it was an interesting theme for me, to touch the sprite table without use of the SMS_devkit functions.


you can see the sprite buffer variables are defined here and they are:
unsigned char SpriteTableY[MAXSPRITES];
unsigned char SpriteTableXN[MAXSPRITES*2];
unsigned char SpriteNextFree;
so if you want to handle these directly, just remember to set SpriteNextFree to the number of sprites you're using before calling SMS_copySpritestoSAT() or alternatively you can set that to 64 just once but then remember to set all unused sprites Y to some value such as 199 (must be > 192 and < 240) and not equal to 0xD0 because that's the sprite terminator. Also values in SpriteTableY needs to be Y coordinates - 1
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Dec 23, 2024 2:39 pm
I just added a decompression function for the stc4 compressed tileset format:
SMS_loadSTC4compressedTiles (src, tilefrom)

the decompressor is pretty fast (~23 tiles/frame average) and the compression rate for the stc4 format are at around 40% average (so the compressed data is approx 60% of the size of the original data)

also compressed tilesets can be concatenated and loaded with a single call, provided you remove the terminator byte from all the tilesets except for the last one - example using assets2banks:
{
# put multiple stc4 compressed tilesets into one single block
tileset_1.stc4compr
:segment -1
tileset_2.stc4compr
:segment -1
tileset_3.stc4compr
}

and then load them with a single call with:
SMS_loadSTC4compressedTiles (tileset_1_stc4compr, 0)
for instance.
  View user's profile Send private message Visit poster's website
  • Joined: 29 Dec 2024
  • Posts: 6
Reply with quote
.h and .c compile missing
Post Posted: Sun Dec 29, 2024 3:39 pm
hello! Firstly, thanks for the Devkit!

I'm having a problem that I don't quite understand why it happens. When I compile the game including only the "bank(x).h" files, it compiles but does not load the images saved in it. If I include the "bank(x).c" files in the code, they load normally, but I use up space in the code bank. I saw in all the examples that they all only load the .h file from the bank.
What am I doing wrong? (I generated them with folder2c).

main.c

#include <stdio.h>
#include <stdlib.h>
#include "SMSlib.h"
#include "bank2.h"
#include "bank3.h"
#include "bank4.h"


my compilation code:

sdcc -c -mz80 --constseg bank2 bank2.c
sdcc -c -mz80 --constseg bank3 bank3.c
sdcc -c -mz80 --constseg bank4 bank4.c

sdcc -c -mz80 --peep-file peep-rules.txt main.c

sdcc -o main.ihx -mz80 --no-std-crt0 --data-loc 0xC000 -Wl-b_BANK2=0x24000 -Wl-b_BANK3=0x34000 -Wl-b_BANK4=0x44000 crt0_sms.rel main.rel SMSlib.lib bank2.rel bank3.rel bank4.rel

makesms main.ihx main.sms
  View user's profile Send private message
  • Joined: 09 Jun 2014
  • Posts: 421
Reply with quote
Post Posted: Sun Dec 29, 2024 5:07 pm
Are you doing a bank switch in your code? Like so:

SMS_mapROMBank(tiles_bin_bank);
SMS_loadTiles (tiles_bin, 0, tiles_bin_size);

See the example here: https://www.smspower.org/forums/18547-BankSwitchingDevkitSMS
  View user's profile Send private message Visit poster's website
  • Joined: 29 Dec 2024
  • Posts: 6
Reply with quote
.h and .c compile missing
Post Posted: Sun Dec 29, 2024 7:34 pm
My code:

void carregar_fundos()
{

SMS_mapROMBank(2);

SMS_displayOff();

SMS_loadBGPalette(fundojogopal_bin);
SMS_loadPSGaidencompressedTiles(fundojogotiles_psgcompr,0);
SMS_loadTileMap(0,0, fundojogotilemap_bin, fundojogotilemap_bin_size);

if (nlevel==2) {
SMS_setBGPaletteColor(0, RGB(0, 0, 170));
SMS_setBGPaletteColor(2, RGB(0, 85, 255));
SMS_setBGPaletteColor(3, RGB(0, 170, 255));

SMS_displayOn();
}

}


If I add #include "bank2.c" at the beginning along with "bank2.h" it loads perfectly. But if I remove bank2.c it doesn't load. The problem is that adding the ".c" of all banks takes up space in the code bank.

In all the examples I see, no one ever puts "#include bank(x).c".

I've tried compiling in different ways, but I still can't understand what I'm doing wrong.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Dec 30, 2024 2:22 pm
tmineiro wrote
What am I doing wrong?
sdcc -o main.ihx -mz80 --no-std-crt0 --data-loc 0xC000 -Wl-b_BANK2=0x24000 -Wl-b_BANK3=0x34000 -Wl-b_BANK4=0x44000 crt0_sms.rel main.rel SMSlib.lib bank2.rel bank3.rel bank4.rel


it looks like you're linking data banks (banks that contain your assets) at the wrong address. It should be
-Wl-b_BANK2=0x28000 -Wl-b_BANK3=0x38000 -Wl-b_BANK4=0x48000
because data banks should be at 0xn8000

Also it's better if you don't do
SMS_mapROMBank(2);
but do
SMS_mapROMBank(fundojogopal_bin_bank);
instead, so that if you move your assets around everything will still work correctly.

I hope this helps! :)
  View user's profile Send private message Visit poster's website
  • Joined: 09 Jun 2014
  • Posts: 421
Reply with quote
Post Posted: Mon Dec 30, 2024 4:36 pm
There is an example around that uses 4000. I initially used that example as well, but later changed it to 8000.

No idea where 4000 comes from. Is that value ever correct, or is the example just plain incorrect?
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Dec 30, 2024 5:15 pm
slogra wrote
There is an example around that uses 4000. [...] Is that value ever correct, or is the example just plain incorrect?


Where is the example? The 0xn4000 is used to map code banks (so when using banked code), not data banks, as data is mapped at 0xn8000 instead (banked code use slot-1 page [at $4000] through trampolines in crt0 to map chunks of code when needed, but the assets needs to be manually banked in using slot-2 page [at $8000])
  View user's profile Send private message Visit poster's website
  • Joined: 29 Dec 2024
  • Posts: 6
Reply with quote
Post Posted: Mon Dec 30, 2024 8:07 pm
sverx wrote
slogra wrote
There is an example around that uses 4000. [...] Is that value ever correct, or is the example just plain incorrect?


Where is the example? The 0xn4000 is used to map code banks (so when using banked code), not data banks, as data is mapped at 0xn8000 instead (banked code use slot-1 page [at $4000] through trampolines in crt0 to map chunks of code when needed, but the assets needs to be manually banked in using slot-2 page [at $8000])



it WORKED!! Thank you very much!!!

*** sverx's makesms converter ***
Info: 36826 bytes used/81920 total [44.95%] - size of output ROM is 80 KB
Info: [bank0 6938] [bank1 16313] [bank2 9678] [bank3 1610] [bank4 10555] bytes free

Compiling with that code line, I have a code bank (0) of 16k, and an empty bank of 1.

Can I put code in it, just use __banked? So do I need to change the bank1 address to 14000?

If I want to use more banks with code, do I just change the addresses to 4000? and leave the asset values ​​at 8000?

Another question, is there another way to keep the 32k bank for coding and add many asset banks by compiling the way I'm doing?
  View user's profile Send private message
  • Joined: 09 Jun 2014
  • Posts: 421
Reply with quote
Post Posted: Tue Dec 31, 2024 11:18 am
sverx wrote
slogra wrote
There is an example around that uses 4000. [...] Is that value ever correct, or is the example just plain incorrect?


Where is the example? The 0xn4000 is used to map code banks (so when using banked code), not data banks, as data is mapped at 0xn8000 instead (banked code use slot-1 page [at $4000] through trampolines in crt0 to map chunks of code when needed, but the assets needs to be manually banked in using slot-2 page [at $8000])


Sorry, i don't remember where i got it. In my build batch i can see i tried 4000 because i commented out before i fixed it to 8000. I must've gotten the 4000 from somewhere. Probably it was an example that used banked code 4000.


tmineiro wrote

Can I put code in it, just use __banked? So do I need to change the bank1 address to 14000?

If I want to use more banks with code, do I just change the addresses to 4000? and leave the asset values ​​at 8000?

Another question, is there another way to keep the 32k bank for coding and add many asset banks by compiling the way I'm doing?


I think if you don't use bank1 you will have room for code.

Yes, you can/should use _bank. If you look inside your bank.h files you will see it points to the bank number. E.g. #define background_tilemap_stmcompr_bank 2

You can use as many assets bank as you want.


This is an example of what i used:

sdcc -o output.ihx -mz80 --no-std-crt0 --data-loc 0xC000 -Wl-b_BANK2=0x28000 -Wl-b_BANK3=0x38000 -Wl-b_BANK4=0x48000 -Wl-b_BANK5=0x58000 -Wl-b_BANK6=0x68000 -Wl-b_BANK7=0x78000 -Wl-b_BANK8=0x88000 ..\SMSlib\crt0_sms.rel main.rel ..\SMSlib\SMSlib.lib bank2.rel bank3.rel bank4.rel bank5.rel bank6.rel bank7.rel bank8.rel


Nowadays i use assets2banks instead of folder2c. I simply put all my assets in one folder and use _bank to find the correct bank.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Dec 31, 2024 2:20 pm
tmineiro wrote
Compiling with that code line, I have a code bank (0) of 16k, and an empty bank of 1.

Can I put code in it, just use __banked? So do I need to change the bank1 address to 14000?

If I want to use more banks with code, do I just change the addresses to 4000? and leave the asset values ​​at 8000?

Another question, is there another way to keep the 32k bank for coding and add many asset banks by compiling the way I'm doing?


Basically there are two options:
  • use up to 32 KiB for your code (bank 0 and bank 1) - you don't need to do anything special to achieve this, your code will spill into bank 1 when bank 0 is full
  • use more than 32 KiB for your code - you need to code your program in separate source files, declare as __banked those functions that need to you call from other modules and then compile all the sources separately, linking them together just at the end - more details here


the first approach is what people usually do, unless you're building a complex game

also, as @slogra pointed out, you can use assets2banks instead of folder2c, it will automatically organize your assets in banks and you won't ever have to worry about where something ended up because it creates all the definitions for you - instructions and more details here!
  View user's profile Send private message Visit poster's website
  • Joined: 29 Dec 2024
  • Posts: 6
Reply with quote
Post Posted: Tue Dec 31, 2024 4:28 pm
sverx wrote
tmineiro wrote
Compiling with that code line, I have a code bank (0) of 16k, and an empty bank of 1.

Can I put code in it, just use __banked? So do I need to change the bank1 address to 14000?

If I want to use more banks with code, do I just change the addresses to 4000? and leave the asset values ​​at 8000?

Another question, is there another way to keep the 32k bank for coding and add many asset banks by compiling the way I'm doing?


Basically there are two options:
  • use up to 32 KiB for your code (bank 0 and bank 1) - you don't need to do anything special to achieve this, your code will spill into bank 1 when bank 0 is full
  • use more than 32 KiB for your code - you need to code your program in separate source files, declare as __banked those functions that need to you call from other modules and then compile all the sources separately, linking them together just at the end - more details here


the first approach is what people usually do, unless you're building a complex game

also, as @slogra pointed out, you can use assets2banks instead of folder2c, it will automatically organize your assets in banks and you won't ever have to worry about where something ended up because it creates all the definitions for you - instructions and more details here!



Thank you very much friends! You guys are awesome!

Everything works perfect here!

Happy new year and a great 2025 with lots of codes and master system!
  View user's profile Send private message
  • Joined: 29 Dec 2024
  • Posts: 6
Reply with quote
GSlib not working ..Lib question
Post Posted: Sat Jan 25, 2025 5:24 am
hello friends! Happy New Year!

I was having problems using PSGlib for a while. I would download examples, compile it and it just wouldn't work. So I found the PSGlib.lib file, I just replaced it in the folder and also in the compilation, instead of using the .rel after the library was compiled, and everything started working perfectly!

I've been struggling for days with GSlib, I downloaded all the examples, but I can't get it to work. I follow the example compilations, everything exactly as they indicate and it simply doesn't work, nor does the basic test of loading a static background with the GS function to load a tilemap.

Am I having the same problem as PSGlib? If I get the GSlib.lib file, will I be able to run and compile it?

Any ideas? I don't know what else to try...
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sat Jan 25, 2025 4:54 pm
I suspect there might be an issue using GSlib with a recent version of SDCC because of the different calling conventions involved.

I'll see if I can roll a simple update in a few days. I'll let you know.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun Jan 26, 2025 3:10 pm
...and indeed it was it. :)

I first tried compiling and linking the GSLib code as it was, and I only got screen corruption. So I forced the existing functions to use the previous SDCC calling convention (as it was working with it, I had tested it personally!) and everything now works again.

I pushed an update to my fork of the GSLib repository, so you need to download again both GSLib.rel and GSLib.h (they're inside the c directory) to use that lib correctly from your own code.
  View user's profile Send private message Visit poster's website
  • Joined: 27 Feb 2023
  • Posts: 154
  • Location: France
Reply with quote
Post Posted: Sun Jan 26, 2025 6:45 pm
Hello,

I am getting a bit stuck with some unusual error. When I compile a few lines of code, I get this generated in the .asm file and it doesn't seem to be accepted.







This is inconsistent though, I managed to have the code compile properly by removing some of my SMS_LoadTiles calls or by removing some +slot instructions in the parameters. But not all of them.

I can manage by myself with errors, but in this case, I don't understand what is happening. After looking at the Z80 manual, I wonder if the instruction is valid at all.



Using devkit SMS 1.2
SDCC 4.2.0

EDIT : finally found a solution. I replaced the switch by several ifs, and now it compiles.
Capture.PNG (11.98 KB)
1
Capture.PNG
Capture2.PNG (32.28 KB)
2
Capture2.PNG
Capture3.PNG (15.25 KB)
3
Capture3.PNG
Capture4.PNG (9.63 KB)
4
Capture4.PNG

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun Jan 26, 2025 8:41 pm
yeah, unfortunately SDCC 4.2.0 has a few bugs, you might want to try using a newer version (here it generates an 'unofficial' opcode which then gets rejected by the assembler stage...)

The opcode is
SET b,r
which sets one bit (the 'b'th) in an 8-bit register, but IYH is an 'unofficial' one
  View user's profile Send private message Visit poster's website
  • Joined: 27 Feb 2023
  • Posts: 154
  • Location: France
Reply with quote
Post Posted: Sun Jan 26, 2025 9:09 pm
I see that 4.4.0 is the latest. I might try it, hoping it won't break something else :)
  View user's profile Send private message
  • Joined: 28 Jan 2017
  • Posts: 567
  • Location: Málaga, Spain
Reply with quote
Post Posted: Sun Jan 26, 2025 9:26 pm
SDCC 4.4.0 works out of the box without troubles. I am sure because I have the new 3mb game with 96kb of code working with SDCC4.4.0 without issues along the development.

The only fail you will find is if you use gslib, you have to manually declare some functions as sdcccall(0), in particular:


void GSL_initializeMap(void *scrolltable, void *metatiles) __sdcccall(0);
void GSL_positionWindow(unsigned int X, unsigned int Y) __sdcccall(0);
unsigned int * GSL_metatileLookup(unsigned int x, unsigned int y) __sdcccall(0);
unsigned int GSL_tileLookup(unsigned int x, unsigned int y) __sdcccall(0);
void GSL_refreshVDP(void) __sdcccall(0);
void GSL_scroll(signed char x, signed char y) __sdcccall(0);
void GSL_VBlank(void) __sdcccall(0);
void GSL_metatileUpdate(void) __sdcccall(0);
void GSL_metatileUpdateCustom(unsigned int x, unsigned int y, unsigned int offset) __sdcccall(0);


If you want even more optimization, you can add to the compilation the tool mdlz80optimizer from santi ontañon. Will make the code a bit faster.


* I see you, Sverx, already put the sdccall calls to the non void functions. I am using gslib in this new game and I found one error with the replacement of tiles when the tiles are partially visible in the right border, but everything else works like a charm.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 4021
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Jan 27, 2025 9:54 am
@eruiz00 - please let me know how to reproduce the GSLib bug exactly and I'll see if I can fix it - I make no promise but I'll see what I can do.

Also, I just pushed an update to SMSlib, adding
void UNSAFE_SMS_VRAMmemcpy (unsigned int dst, const void *src, unsigned int size)
to quickly copy any amount of bytes to VRAM, to be used only during vblank or when screen is off.

This function can be used directly or through the two macros
UNSAFE_SMS_loadNTiles(src,tilefrom,tilecount)  /* copy any amount of tiles to VRAM */
UNSAFE_SMS_loadTiles(src,tilefrom,size)        /* copy any amount of bytes to VRAM */

which are meant to be used to copy Tiles to VRAM quickly, the only difference between the two is that you either specify the count in tiles for the transfer or the size in bytes, also to ensure that both
UNSAFE_SMS_loadTiles(src,tilefrom,size)
and
SMS_loadTiles(src,tilefrom,size)
use the same parameters.
  View user's profile Send private message Visit poster's website
  • Joined: 29 Dec 2024
  • Posts: 6
Reply with quote
Post Posted: Wed Jan 29, 2025 2:57 am
sverx wrote
...and indeed it was it. :)

I first tried compiling and linking the GSLib code as it was, and I only got screen corruption. So I forced the existing functions to use the previous SDCC calling convention (as it was working with it, I had tested it personally!) and everything now works again.

I pushed an update to my fork of the GSLib repository, so you need to download again both GSLib.rel and GSLib.h (they're inside the c directory) to use that lib correctly from your own code.


It worked perfectly!
Thank you very much for the help.
  View user's profile Send private message
Reply to topic Goto page Previous  1, 2, 3 ... 16, 17, 18



Back to the top of this page

Back to SMS Power!