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 - Beginners question [C and SMSDevKit]

Reply to topic Goto page Previous  1, 2
Author Message
  • Joined: 29 Mar 2012
  • Posts: 484
  • Location: Spain
Reply with quote
Post Posted: Sat Jun 29, 2019 4:02 pm
I would say most "normal" games can be done using plain C. Asm probably is needed on some parts if you have intensive computing.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2456
Reply with quote
Post Posted: Sat Jun 29, 2019 5:36 pm
SDCC creates pretty good code but yes, it's hard to beat handwritten asm (if written by an experienced developer).

I wouldn't worry if I were you, as you can do cool stuff with devkitSMS too, check this list here: a few suggestions are surely eruiz's Astro Force, Galactic Revenge and Silver Valley, or even my own Weka Invaders or MARKanoIIId (unfinished) - but please do check all the other creations in the list too, they're surely worth your attention :)

In the while SMS_decompressZX7() (to decompress to RAM) has been added.
  View user's profile Send private message Visit poster's website
  • Joined: 24 Jun 2019
  • Posts: 28
Reply with quote
Post Posted: Sat Jun 29, 2019 5:55 pm
Awesome :D I will go with the SDCC then x3
I'm not much into inline assembly actually - I spend half a year removing inline assembly from our code base at work xD

I want to download some of those games and stream then :3
  View user's profile Send private message
  • Joined: 24 Jun 2019
  • Posts: 28
Reply with quote
Post Posted: Tue Jul 02, 2019 5:47 pm
It's me again °-°

I'm happy and a bit proud, I finally managed to scroll my map into 8 directions ^o^
Took my long enough though...

Anyway, I'm still concernd if my code is fast enough - currently I render the part of the screen every VBlank and allow the screen to move with 1pixel each direction.
It feels very slow - now I wonder if I render to slow or if it is normal and stuff like that... Any ideas how to validate my concerns?

Edit:
Well... I compared the scroll speed between no rendering of map and a rendering of my map - there are huge differences in the time x.x"
So my code is very slow...

Edit2:
So yesterday in bed I realized that it is over the top to copy the map every frame. Today I want to focus on copying only the parts that really needs to be updated. I hope this will make things better, I'm still frustrated that it is so slow... Am I that bad? >o<
  View user's profile Send private message
  • Joined: 29 Mar 2012
  • Posts: 484
  • Location: Spain
Reply with quote
Post Posted: Wed Jul 03, 2019 6:00 am
You're not that bad at all, siply the time is tight on the z80
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2456
Reply with quote
Post Posted: Wed Jul 03, 2019 9:29 am
Jaberwocky wrote
So yesterday in bed I realized that it is over the top to copy the map every frame. Today I want to focus on copying only the parts that really needs to be updated.


Yes, that's the way. As VRAM access is particularly slow, and as we have hardware scroll anyway, you're going to update one row of data AND one column of data in the same frame worst case. This can be done without perceivable slowdown.
  View user's profile Send private message Visit poster's website
  • Joined: 24 Jun 2019
  • Posts: 28
Reply with quote
Post Posted: Thu Jul 04, 2019 8:41 pm
Thanks guys x3 I finally have my map scrolling in all directions :D The frame rate is better now - I guess it could be even faster, but for a beginning I'm really happy :3

Next thing to tackle will be sprites on the map, in dependency of the current 'camera' position.

Also... In an assembly code I looked into, I read something about a "General purpose RAM" - it had a fixed address, which I can't remember anymore... What is that about? And what do I do if I want more then 64 sprites on my screen?
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12818
  • Location: London
Reply with quote
Post Posted: Thu Jul 04, 2019 9:56 pm
Most games limit scroll speed to 8 pixels per frame (which is a lot), in order to avoid needing to draw more than one column of tiles.

RAM is what the compiler will be using for all your globals and suchlike.

You probably don't want to use more than 64 sprites. Consider the 8 sprite limit per row limit also applies.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 2456
Reply with quote
Post Posted: Fri Jul 05, 2019 8:26 am
Jaberwocky wrote
And what do I do if I want more then 64 sprites on my screen?


The hardware supports no more than 64 sprites so if you really need more than that (hardly, I would say!) you should multiplex, or use 'software sprites', which is an expression to indicate that you're drawing your characters in the background (slow, cumbersome) instead of using the system hardware features.

Note that even multiplexing the sprites you won't ever get more than 8 sprites appear on every single screen line.
  View user's profile Send private message Visit poster's website
  • Joined: 24 Jun 2019
  • Posts: 28
Reply with quote
Post Posted: Sun Jul 14, 2019 12:34 pm
Thanks again for the help :3
Had a busy week but I managed to get some basic stuff running - I improved my screen scrolling and played a bit with sprites.

What does multiplexing of sprites mean?

Also... from the old pokemon games I remember an effect where you had a black screen and could only see the map through a circle - is such an effect possibel with the SMS as well? And how would you do that?
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12818
  • Location: London
Reply with quote
Post Posted: Sun Jul 14, 2019 1:31 pm
Multiplexing means you update the sprite table at some point in the screen. I don't know any game which does that because it's really hard.

To get a spotlight effect you'd need to draw the whole screen using black tiles, except for near the centre where you draw a blocky circle. Then use sprites to mask the edges to be pixel perfect. This costs a lot of sprites though. I think Ys does it?
  View user's profile Send private message Visit poster's website
  • Joined: 14 Oct 2008
  • Posts: 307
Reply with quote
Post Posted: Sun Jul 14, 2019 5:03 pm
Jaberwocky wrote

Also... from the old pokemon games I remember an effect where you had a black screen and could only see the map through a circle - is such an effect possibel with the SMS as well? And how would you do that?


That would be the GBA and DS generation games (gen 1 only darkened the palette and gen 2 made it completely black), which possibly had some hardware support for it. (I have only heard from some people who said GBA could do "Mode 7" effects like the SNES, but wanted to make a technical argument about the name, I wonder if GBA had other hardware visual features of the SNES.)

But yes, as said to do it on a console without built-in hardware functionality it would require tile and sprite trickery.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2456
Reply with quote
Post Posted: Sun Jul 14, 2019 5:21 pm
GBA's HDMA effect coupled with the windowing feature - basically you can define a (rectangular) window and make everything outside the window not be shown. With HDMA you'll then redefine the window left and right position at each scanline thus making a circle/ellipse.
  View user's profile Send private message Visit poster's website
  • Joined: 24 Jun 2019
  • Posts: 28
Reply with quote
Post Posted: Sun Jul 14, 2019 5:48 pm
Woah... Is there anything you guys don't know? :'D

I thank you all so much for all those answers :3 I might try such a tile sprite trickery - but all in all I want to do a simple game now. I'm done with experimenting :D
  View user's profile Send private message
  • Joined: 24 Jun 2019
  • Posts: 28
Reply with quote
Post Posted: Yesterday at 7:56 pm
Well... Here I go again...

I have not used the Bank mapping yet... but... If I understand it correctly... Pretending I have data stored in Bank2 and Bank3...

Bank2 seems to be automaticly mapped, because I used it already but never used the mapping function. So... If bank 2 is mapped, but in code I use an address from bank3 - I will read the data from bank 2 right? Like an offset... So to get the real data, I would have to map bank 3, correct? Kind of overriding the bank 2 content with the one from bank 3.

Urgs... I'm bad in explaining, but is that the basic concept?
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12818
  • Location: London
Reply with quote
Post Posted: Today at 6:02 am
Yes. The easiest way to manage it is to put all your data in the higher banks and code in the lower 32KB, and always select the bank before reading the data.
  View user's profile Send private message Visit poster's website
  • Joined: 24 Jun 2019
  • Posts: 28
Reply with quote
Post Posted: Today at 7:54 am
I guess the lines "-Wl-b_BANK2=0x8000 -Wl-b_BANK3=0x8000" for the SDCC means, that the mapped bank will be at address 0x8000 - is that correct?

And the lower 32KB you reference are "--data-loc 0xC000"? >-<
So bascily everything I don't stuff into a bank?

So I wonder... Can I please the compiler to place certain values at specific addresses? Pretending I'm right with that the bank starts at 0x8000.

Could I tell the compiler to place char x at for example 0x8002? Or an offset like 0x2?
I ask because then I could use the address hard coded in my programm and use the bank maping to replace the value. I take, that this is already done by ordering the data in the banks in a certain way - like starting with palettes because they have a fixed size and so on.

I just wonder if I can relay on it or if I can enforce those things... Does that make sense? °-°
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2456
Reply with quote
Post Posted: Today at 8:41 am
Jaberwocky wrote
I guess the lines "-Wl-b_BANK2=0x8000 -Wl-b_BANK3=0x8000" for the SDCC means, that the mapped bank will be at address 0x8000 - is that correct?


correct! (you're setting BANK2 and BANK3 address in ROM at value 0x8000)

Jaberwocky wrote
And the lower 32KB you reference are "--data-loc 0xC000"? >-<
So bascily everything I don't stuff into a bank?


no, that part tells the linker that we've got RAM at 0xC000

Jaberwocky wrote
So I wonder... Can I please the compiler to place certain values at specific addresses? Pretending I'm right with that the bank starts at 0x8000.

Could I tell the compiler to place char x at for example 0x8002? Or an offset like 0x2?
I ask because then I could use the address hard coded in my programm and use the bank maping to replace the value. I take, that this is already done by ordering the data in the banks in a certain way - like starting with palettes because they have a fixed size and so on.

I just wonder if I can relay on it or if I can enforce those things... Does that make sense? °-°


There's absolute placement, but you hardly need that. If you're using assets2banks you'll get an header file (or many of them if you don't use --singleheader) with all the pointers, sizes and bank placement you need.

edit: in detail, for each asset you'll find three definitions. This is for asset 'palette.bin' for instance:
extern const unsigned char   palette_bin[16];
#define            palette_bin_size 16
#define            palette_bin_bank 2


you can see that it's 16 bytes in size and it's been placed in bank 2. So to load that to BG palette, you need to

SMS_mapROMBank (palette_bin_bank);
SMS_loadBGPalette (palette_bin);
  View user's profile Send private message Visit poster's website
  • Joined: 24 Jun 2019
  • Posts: 28
Reply with quote
Post Posted: Today at 9:01 am
I see... Why bank 2 though? What is about bank 1 and bank 2?

I already noticed that a bank seems to be 16K in size, which multiplied by 2 (bank 0 and 1) will be 32K - exactly the size of the "lower 32KB" you mentioned.
I guess that is no coincidence xD

Another question about the timing again...
I want to do a thing like meassure the play time in minutes. I already learned, that I have no timer for this, so all I could do is count the frames, depending on the VBlank-Time correct?

But that means, that my timer must also distinguish between PAL and NTSC. But when my code is terrible slow, like my first map scrolling, then I will manipulate the timer as well...
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2456
Reply with quote
Post Posted: Today at 10:15 am
you'll count the passing time in frames, then it's up to you to decide if you want to support both frame rates (50 and 60 frames per second) or just set your 'one second' equivalence to either one or the other (or 55 to be slightly off both).

Many games just don't care. Their timer either run faster on NTSC/60Hz or slower on PAL/50Hz. Note that your game anyway will run at the fps speed, so it'll run faster on NTSC and slower on PAL, unless you create an engine that supports both and adapt itself (not easy at all to do).
  View user's profile Send private message Visit poster's website
Reply to topic Goto page Previous  1, 2



Back to the top of this page

Back to SMS Power!