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, 4, 5 ... 14, 15, 16  Next
Author Message
  • Joined: 23 Jan 2015
  • Posts: 28
  • Location: Bridlington, UK
Reply with quote
Post Posted: Tue Apr 21, 2015 4:56 pm
Can you do that with graphics/misc data in bank 2? I only used PSGLib as an example. :¬)
  View user's profile Send private message Visit poster's website
  • Joined: 29 Mar 2012
  • Posts: 879
  • Location: Spain
Reply with quote
Post Posted: Wed Apr 22, 2015 6:36 am
i'm changing banks on Gaudream for title screen, for game, for game over...
  View user's profile Send private message
  • Joined: 22 Mar 2015
  • Posts: 228
Reply with quote
Post Posted: Sun Apr 26, 2015 11:52 pm
How could this help us making ports from GG to SMS? Because the hardest part is:

About the SPRITES
Let sprites to appear outside of the GG screen size and..

About the BACKGROUNDS
They don't show themselves correctly because of two reasons
1.- The scroll vertical/horizontal gives priority to the GG screen size not the SMS's so we could see downside to upside and/or the rightside to leftside.
2.- The background refreshes outside the GG screen size not the SMS's
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14687
  • Location: London
Reply with quote
Post Posted: Mon Apr 27, 2015 6:46 am
Not at all? You want to patch games, adding in a C runtime isn't going to help.
  View user's profile Send private message Visit poster's website
  • Joined: 23 Jan 2015
  • Posts: 28
  • Location: Bridlington, UK
Reply with quote
Post Posted: Mon Apr 27, 2015 6:38 pm
kusfo wrote
i'm changing banks on Gaudream for title screen, for game, for game over...

Cool. I can't wait for the source for this excellent little game to be released. :¬D
  View user's profile Send private message Visit poster's website
  • Joined: 23 Jan 2015
  • Posts: 28
  • Location: Bridlington, UK
Reply with quote
Post Posted: Mon Apr 27, 2015 8:04 pm
Ok, I need a bit of help. There's a bit of a problem with my custom print script.
void TPGG_print (void *src, unsigned char x, unsigned char y) {
  //unsigned int k;
  unsigned int xt;
  unsigned int yt;
  xt = x;
  yt = y;
  //tt = T;
  //SMS_setNextTileatXY(x, y);  //8 3
  while (true) {
    //T=*src++;
    SMS_waitForVBlank();
    SMS_enableLineInterrupt();
    T = ((unsigned char*)src) + 1;
    if (T == 0x07) {
      k=SMS_getKeysPressed();
      while (k != GG_KEY_START) {
        k=SMS_getKeysPressed();
        SMS_waitForVBlank();
        SMS_enableLineInterrupt();
      }
    }
    else if (T == 0x0D) {
      yt++;
      xt=x;
    }
    else if (T == 0x1A) {
      break;
    }
    else {
      if (T > 0x1F) {
        SMS_setTileatXY(xt, yt, (T - 32));
        xt++;
      }
    }
  }
}

...and this error happens.
Quote
test.c:54: error 47: indirections to different types assignment
from type 'unsigned-char generic* fixed'
to type 'unsigned-int fixed'

Thanks in advance. :¬)
TestProgram (2).zip (359.56 KB)
source

  View user's profile Send private message Visit poster's website
  • Joined: 29 Mar 2012
  • Posts: 879
  • Location: Spain
Reply with quote
Post Posted: Mon Apr 27, 2015 8:44 pm
Camtronic16 wrote
Ok, I need a bit of help. There's a bit of a problem with my custom print script.
void TPGG_print (void *src, unsigned char x, unsigned char y) {
  //unsigned int k;
  unsigned int xt;
  unsigned int yt;
  xt = x;
  yt = y;
  //tt = T;
  //SMS_setNextTileatXY(x, y);  //8 3
  while (true) {
    //T=*src++;
    SMS_waitForVBlank();
    SMS_enableLineInterrupt();
    T = ((unsigned char*)src) + 1;
    if (T == 0x07) {
      k=SMS_getKeysPressed();
      while (k != GG_KEY_START) {
        k=SMS_getKeysPressed();
        SMS_waitForVBlank();
        SMS_enableLineInterrupt();
      }
    }
    else if (T == 0x0D) {
      yt++;
      xt=x;
    }
    else if (T == 0x1A) {
      break;
    }
    else {
      if (T > 0x1F) {
        SMS_setTileatXY(xt, yt, (T - 32));
        xt++;
      }
    }
  }
}

...and this error happens.
Quote
test.c:54: error 47: indirections to different types assignment
from type 'unsigned-char generic* fixed'
to type 'unsigned-int fixed'

Thanks in advance. :¬)



  unsigned int xt;
  unsigned int yt;
  xt = x;
  yt = y;


xt and yt are int, but x and y ara chars :-)
  View user's profile Send private message
  • Joined: 05 Feb 2012
  • Posts: 10
  • Location: Amsterdam
Reply with quote
Post Posted: Mon Apr 27, 2015 9:50 pm
Quote
test.c:54: error 47: indirections to different types assignment
from type 'unsigned-char generic* fixed'
to type 'unsigned-int fixed'



The offending line 54 states:
Quote

T = ((unsigned char*)src) + 1;


T is defined in line 13 of test.c
Quote

unsigned int T=0;


So you are trying to indirect a pointer from an void * / unsigned char (8 bits) to an unsigned integer (16 bits), and also increase the pointer by 1. (pointer arithmetic with a void pointer is not allowed)
I guess you actually want to dereference the pointer in order to assign the (8 bit) value pointed by the pointer to T (16 bits). So you have to change the void * src into unsigned char *src inside the declaration of TPGG_print

the assignment x to xt and y to yt is permissable: xt and yt (16 bits) are wide enough to accommodate the 8 bits values of x and y.
(implicit conversion through integral promotion)
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue May 05, 2015 8:24 am
Calindro wrote
[...] you will need to set the bank accordingly before calling PSGFrame. Afaik PSGPlay itself doesn't need the bank set because it just prepares variables to play the song and doesn't load any psg data yet.


Yes, that's how it works.
You could have a global variable to keep the value of the last bank you mapped to slot 2, save that value just before switching bank to the one where your song is stored, execute PSGFrame and restore the slot 2 mapping as it was before using the value you saved.
I hope this helps :)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue May 19, 2015 12:11 pm
So, how are things going?
Camtronic16? kusfo? Anyone?
Still using this or got bored?
  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 May 19, 2015 12:28 pm
I've been working in another project ("Antarex" for 1985Alternativo) since we are showing a playing demo this saturday. I'll resume my work in "Gaudream" next week (I already have changed quite a lot of things) :-D
  View user's profile Send private message
  • Joined: 23 Jan 2015
  • Posts: 28
  • Location: Bridlington, UK
Reply with quote
Post Posted: Tue May 19, 2015 6:31 pm
sverx wrote
So, how are things going?
Camtronic16? kusfo? Anyone?
Still using this or got bored?

I'm not bored. I'm just waiting for a bank switching/anything-to-do-with-devkitsms tutorial. I also haven't been able to go on this as much lately as I'm currently doing some exams. I'm (hopefully) going to collage sooner or later! :¬)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue May 19, 2015 7:39 pm
yeah, still no tutorial apart from the github wiki...
Anyway bank switching isn't so complicated.
You place some assets (tiles, tilemaps, PSG tunes, SFX, etc...) in separate files and name these files bank2.c, bank3.c etc...
Then you have to compile everything together as explained in the "How to use more than 48KB in your ROM" section here.
In your code, whenever you need to access one of these assets you should use the macro
SMS_mapROMBank(n);

where n would of course be the number of the bank which contains the assets you need.

If something isn't right clear let me know :)
  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 May 19, 2015 9:00 pm
Just a bunch of Gaudream's code using bankswitchin. As you can see, you do the bankswicthing just before using the resource:
#include <stdbool.h>
#include "SMSlib.h"
#include "PSGlib.h"
#include "bank2.h"
#include "bank3.h"
#include "bank4.h"
#include "bank5.h"
#include "bank6.h"
#include "data.h"
.
.
.
.
.

unsigned int scrollX;
unsigned int scrolly;

bool gameover = false;
bool lifelost = false;
unsigned int currentVRAMPosTilemap;
unsigned int currentVRAMPosSprites;
.
.
.
unsigned char currentRefreshTilemapColumn;
unsigned int currentFrame;


void init_console() {
   SMS_init();
   SMS_VDPturnOnFeature(VDPFEATURE_HIDEFIRSTCOL);
   SMS_displayOn();
}

void reset_variables() {
   currentVRAMPosTilemap = 0;
   .
   scrollX = 0;
   scrolly = 0;
   .
   .
   .
   chargingCounter = 0;

   SMS_initSprites();
   SMS_finalizeSprites();
   SMS_copySpritestoSAT();
   SMS_setBGScrollX(0 - scrollX);
   SMS_loadSpritePalette(blackPalette);
   SMS_loadBGPalette(blackPalette);
}

void logo_inicial() {
   SMS_mapROMBank(4);
   SMS_loadTiles(Logo1985tiles_bin, currentVRAMPosTilemap,
         Logo1985tiles_bin_size); //tiles logo
   SMS_loadTileMap(0, 0, (unsigned int *) Logo1985tilemap_bin,
         Logo1985tilemap_bin_size);
   SMS_loadBGPalette(Logo1985palette_bin_step1);
   SMS_setBackdropColor(3);
   PSGPlay(logo1985_psg);

   while (currentFrame < (FADE_FRAME_COUNT * 9)) {
      .
      .
      .
      .
      PSGFrame();
      SMS_waitForVBlank();
   }
   PSGStop();
   SMS_loadBGPalette(blackPalette);
   SMS_displayOff();
}

void pantalla_principal() {
   .
   .
   SMS_mapROMBank(3);
   SMS_loadTiles(presentacionTiles_bin, currentVRAMPosTilemap,
         presentacionTiles_bin_size); //tiles logo
   SMS_loadTileMap(0, 0, (unsigned int *) presentacionTileMap_bin,
         presentacionTileMap_bin_size);
   SMS_loadBGPalette(presentacionPalette_bin);
   SMS_setBackdropColor(3);
   SMS_displayOn();
   PSGPlay(title_psg);
   currentFrame = 0;
   while (1) {
      keyPressed = SMS_getKeysPressed();
      if (keyPressed & PORT_A_KEY_1) {
         break;
      }
      PSGFrame();
      currentFrame++;
      SMS_waitForVBlank();
   }
   PSGStop();
   PSGSFXPlay(start_psg,SFX_CHANNEL2);
   while (PSGSFXGetStatus() == PSG_PLAYING) {
      PSGSFXFrame();
      SMS_waitForVBlank();
   }
   PSGSFXStop();

   .
   .
   SMS_loadBGPalette(presentacionPalette_bin_step1);
   .
   .
}

void fillFirstTilemap() {
   unsigned char i = 0;
   unsigned char j = 0;

   while (i < NUM_COLUMNS) {
      .
      .
      .
      i++;
   }
}

void init_level(){
   currentFrame = 0;
   scrollX = 0;
   .
   .
   .
   fillFirstTilemap();
   .
   .
   .
}



void pintar_sprites() {

   .
   .
   .


   SMS_copySpritestoSAT();
   SMS_initSprites();
   .
   .
   .
   SMS_finalizeSprites();
}




void bucle_juego() {


   currentVRAMPosTilemap = 0;
   currentVRAMPosSprites = BASE_ADRESS_SPRITES;

   //cambiamos al map 4
   SMS_mapROMBank(2);

   SMS_loadTiles(level1Tiles_bin, currentVRAMPosTilemap, level1Tiles_bin_size); //tiles nivel
   currentVRAMPosTilemap = currentVRAMPosTilemap + (level1Tiles_bin_size >> 5);


   SMS_loadBGPalette(level1Palette_bin);

   SMS_loadTiles(DragonTiles_bin, currentVRAMPosSprites, DragonTiles_bin_size);
   currentVRAMPosSprites = currentVRAMPosSprites + (DragonTiles_bin_size >> 5);
   SMS_loadTiles(VidaTiles_bin, currentVRAMPosSprites, VidaTiles_bin_size);
   .
   .
   SMS_loadTiles(MosaiquitoTiles_bin, currentVRAMPosSprites, MosaiquitoTiles_bin_size);
   .
   .
   SMS_loadTiles(font_bin, currentVRAMPosSprites,font_bin_size);
   .
   .


   SMS_displayOn();
   SMS_mapROMBank(5);
   PSGPlay(ingame_psg);
   while (!gameover) {
         .
         .
         .
         .
         currentFrame++;
         PSGFrame();
         if (PSGSFXGetStatus() == PSG_PLAYING) {
            PSGSFXFrame();
         } else {
            PSGSFXStop();
         }
         SMS_waitForVBlank();
         pintar_sprites();

      }
   }
   PSGStop();
   PSGSFXStop();
}

void game_over() {
   .
   .
   SMS_mapROMBank(6);
   SMS_setBGScrollX(0);
   SMS_loadTiles(gameoverTiles_bin, currentVRAMPosTilemap, gameoverTiles_bin_size); //tiles logo
   SMS_loadTileMap(0, 0, (unsigned int *) gameoverTilemap_bin,
      gameoverTilemap_bin_size);
   SMS_loadBGPalette(gameoverPalette_bin);
   SMS_setBackdropColor(3);
   SMS_initSprites();
   SMS_finalizeSprites();
   SMS_copySpritestoSAT();
   PSGPlayNoRepeat(gover_psg);
   while (PSGGetStatus() == PSG_PLAYING) {
      PSGFrame();
      SMS_waitForVBlank();
   }

}

void main() {
   init_console();
   while (1) {
      reset_variables();
      logo_inicial();
      pantalla_principal();
      bucle_juego();
      game_over();
}

}

SMS_EMBED_SEGA_ROM_HEADER(9999, 0); // code 9999 hopefully free, here this means 'homebrew'
SMS_EMBED_SDSC_HEADER(0, 4, 2015, 4, 13, "1985Alternativo\\2015", "Gaudream",
   "Flappy Bird Clone for SMSPower Compo'15");
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14687
  • Location: London
Reply with quote
Post Posted: Wed May 20, 2015 8:13 am
I guess the folder to bank converter could define macros for the bank number for each data chunk to make it a bit less fragile.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed May 20, 2015 8:37 am
Cunning! :)
Yeah, I think I might add an optional third parameter so that -if specified- folder2c will also create a #define [assetname]_bank for each asset.
This way you would also be able to move assets from a folder to another (so from a bank to a different one) without having to change your sources.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed May 20, 2015 11:19 am
Now it does what Maxim said :)
  View user's profile Send private message Visit poster's website
  • Joined: 23 Jan 2015
  • Posts: 28
  • Location: Bridlington, UK
Reply with quote
Post Posted: Wed May 20, 2015 8:18 pm
Well I tried but I got a 'fatal' error.
Quote
*** sverx's IHX to SMS converter ***
Fatal: allocating ROM at or past 0xC000

....even though I followed the instructions on the GitHub page. :¬|

Here's the .bat file I made.
@echo off
echo Build data.c from data folder
folder2c Assets Data 1
sdcc -c -mz80 --std-sdcc99 Data.c

echo Build Main
sdcc -c -mz80 --std-sdcc99 --constseg BANK2 Data.c
sdcc -mz80 --std-sdcc99 --fomit-frame-pointer --data-loc 0xC000 -Wl-b_BANK2=0x8000 -DTARGET_GG Game.c SMSlib\SMSlib_GG.rel PSGlib\PSGlib.rel Data.rel
ihx2sms Game.ihx Game.gg

echo DONE! Converted to Portal.gg
pause

It compiles without any error until it gets to the IHX to SMS (or in this case GG) conversion.
Please help if possible. Thanks in advance. :¬)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu May 21, 2015 8:15 am
I would say you're maybe putting more than 16KB in a single bank. folder2c output should tell you how many bytes are in the converted file.

Also, you're probably mixing things, since you're using '1' as a third parameter in folder2c call, and compiling the data as BANK2...

Last, I suggest you remove '--fomit-frame-pointer' which is still not 100% perfectly working in SDCC and '-DTARGET_GG' which is useless when compiling your code.

One last thing: make sure you're using latest ihx2sms, there was a nasty bug in it until March 30.

(p.s. it's quite unusual to see a single additional BANK, are you sure 48KB ROM aren't enough? Or are you planning to add more banks as you proceed?)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Jun 03, 2015 8:47 am
Did some of the suggestions actually helped?


edit: I just added
void SMS_loadPSGaidencompressedTiles (void *src, unsigned int Tilefrom);

to load PSGaiden compressed tilesets. I wonder why nobody requested that feature before...
  View user's profile Send private message Visit poster's website
  • Joined: 23 Jan 2015
  • Posts: 28
  • Location: Bridlington, UK
Reply with quote
Post Posted: Wed Jun 03, 2015 9:01 pm
sverx wrote
Did some of the suggestions actually helped?

Not quite. I tried some of your fixes but then I get an error that's not helpful in the slightest.
Quote
sdcpp.exe: fatal error: when writing output to : No such file or directory

without saying what file it was trying to access. >:¬(
Just try compiling it using 'build.bat'!

Any suggestions are welcome. :¬)
ThingGG.zip (580.1 KB)

  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu Jun 04, 2015 8:33 am
OK, I could compile it changing your build.bat a bit.

Note that I compiled test.c separately, before the linking phase... there's still a bug within SDCC when compiling a source file and linking at the same time, so it's better compile every .c file separately and link in a final separate command. See this example batch file:

folder2c 1Graphics graphics 2
folder2c 1Sound sound 3
folder2c 1Text text 4

sdcc -c -mz80 --std-sdcc99 --constseg BANK2 graphics.c
sdcc -c -mz80 --std-sdcc99 --constseg BANK3 sound.c
sdcc -c -mz80 --std-sdcc99 --constseg BANK4 text.c
sdcc -c -mz80 --std-sdcc99 -DTARGET_GG test.c

sdcc -mz80 --std-sdcc99 --data-loc 0xC000 -Wl-b_BANK2=0x8000 -Wl-b_BANK3=0x8000 -Wl-b_BANK4=0x8000 test.rel SMSlib\SMSlib_GG.rel PSGlib\PSGlib.rel Graphics.rel Sound.rel text.rel

ihx2sms test.ihx test.gg


note that you have to use -DTARGET_GG only when compiling your test.c, and in the linking phase you have to specify a -Wl-b_BANKn=0x8000 for each one of your additional banks. Finally, the order of the .rel in the call should have your program first, then the libraries and finally the other rel files in the order you need them.

also, in your test.c file, at line 19, a semicolon is missing at the end of line.
After that, it compiles fine :)
  View user's profile Send private message Visit poster's website
  • Joined: 23 Jan 2015
  • Posts: 28
  • Location: Bridlington, UK
Reply with quote
Post Posted: Fri Jun 05, 2015 2:37 pm
sverx wrote
OK, I could compile it changing your build.bat a bit.

Note that I compiled test.c separately, before the linking phase... there's still a bug within SDCC when compiling a source file and linking at the same time, so it's better compile every .c file separately and link in a final separate command. See this example batch file:

folder2c 1Graphics graphics 2
folder2c 1Sound sound 3
folder2c 1Text text 4

sdcc -c -mz80 --std-sdcc99 --constseg BANK2 graphics.c
sdcc -c -mz80 --std-sdcc99 --constseg BANK3 sound.c
sdcc -c -mz80 --std-sdcc99 --constseg BANK4 text.c
sdcc -c -mz80 --std-sdcc99 -DTARGET_GG test.c

sdcc -mz80 --std-sdcc99 --data-loc 0xC000 -Wl-b_BANK2=0x8000 -Wl-b_BANK3=0x8000 -Wl-b_BANK4=0x8000 test.rel SMSlib\SMSlib_GG.rel PSGlib\PSGlib.rel Graphics.rel Sound.rel text.rel

ihx2sms test.ihx test.gg


note that you have to use -DTARGET_GG only when compiling your test.c, and in the linking phase you have to specify a -Wl-b_BANKn=0x8000 for each one of your additional banks. Finally, the order of the .rel in the call should have your program first, then the libraries and finally the other rel files in the order you need them.

also, in your test.c file, at line 19, a semicolon is missing at the end of line.
After that, it compiles fine :)

Ah, okay! I hadn't noticed that missing semi-colon while testing! :¬P
Anyway, thanks for the new .bat file. It now works great and one of the only things I have to do now is sort the banks out.

-----

Also, could someone help me with some scrolling please?
I've been trying to use the Mappy tile editor found at http://tilemap.co.uk/mappy.php to create my level maps but I'm a bit of a noob when it comes to scrolling huge maps (or SMS/GG programming in general :¬P)
Would it be possible to add in a couple of basic functions to help with this?
Just functions that load up a map file and can scroll it around like this...
//Just a basic example
SMS_mappyLoad(levelmap_map, 0, 0, 10); //Load the level map file at positions 0, 0 with the tiles starting at tile number 10 (so if the tile number in the map file is 3, it displays tile number 13)
while(true) {
  scrollx++; //increment x scroll for scrolling function
  if(scrollx % 8 == 0) { //if scrollx is a multiple of 8
    SMS_scrollLineMap(RIGHT); //scrolls in the next tiles at the right
    scrollx = 1 //resets the scroll value
  }
}

...and maybe a basic collision detection routine using the collision built-in to Mappy in the block editor or animated tiles support if you want.

Thanks in advance.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14687
  • Location: London
Reply with quote
Post Posted: Fri Jun 05, 2015 4:02 pm
I'm not sure anyone has released code for using Mappy's data file(s) in an SMS game. You would probably want to have options for the tile size (not just 8x8). It's quite an advanced feature request.
  View user's profile Send private message Visit poster's website
  • Joined: 23 Jan 2015
  • Posts: 28
  • Location: Bridlington, UK
Reply with quote
Post Posted: Fri Jun 05, 2015 5:14 pm
Maxim wrote
I'm not sure anyone has released code for using Mappy's data file(s) in an SMS game. You would probably want to have options for the tile size (not just 8x8). It's quite an advanced feature request.

Nah, just 8x8 is what I need to keep things simple. :¬)
Mappy comes with a bit of documentation about one of it's file types (the .FMP file format) and it comes with script support for converting it to any other file type so I just really need a basic level map scrolling tutorial.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Jun 08, 2015 9:16 am
scrolling large maps isn't so complicated, and you can manipulate the tilemap using the functions
void SMS_setTileatXY (unsigned char x, unsigned char y, unsigned int tile);
void SMS_setNextTileatXY (unsigned char x, unsigned char y);
void SMS_setTile (unsigned int tile);


for instance, say you want the screen to scroll up: you have to load a new line of tiles into the first line below the lower border of the screen and you can do that by calling
SMS_setNextTileatXY(0,24)

followed by 32
SMS_setTile(YourTileNum)

since the VRAM pointer automatically advances to pointing the next tile.

If your map is stored as a 2D array, you could even use
void SMS_loadTileMapArea (unsigned char x, unsigned char y,  unsigned int *src, unsigned char width, unsigned char height);

to load a whole new line at once.

When you're over the 28th line of tiles, you should start overwriting the first line in the tilemap (a.k.a. PNT)

For horizontal scrolling, you can do basically the same thing, even if you're probably going to use a loop of
void SMS_setTileatXY()

since you're going to update VRAM tiles which are stored apart from each other.

--------------------------

For mappy maps, you could try using FMP2GBA which converts a Mappy map into a C array. Unfortunately it seems to support 8x8 tiling only and also doesn't support animated tiles.

In Anguna - the Prison Dungeon, I took the original game FMP maps and converted to C arrays using
for /F "tokens=1-10 delims=." %%i in ('dir *.fmp /b') do (
  fmp2gba %%i.fmp %%i.c level_%%i NOGFX
)


which turned every 'somename.FMP' in my folder into a 'somename.c' containing arrays like
const unsigned short level_somename_map[] = { <map tiles numbers here> }

which is just what you need, IMHO.

I hope it helps! :)
  View user's profile Send private message Visit poster's website
  • Joined: 23 Jan 2015
  • Posts: 28
  • Location: Bridlington, UK
Reply with quote
Post Posted: Wed Jun 17, 2015 10:44 am
sverx wrote
scrolling large maps isn't so complicated, and you can manipulate the tilemap using the functions
void SMS_setTileatXY (unsigned char x, unsigned char y, unsigned int tile);
void SMS_setNextTileatXY (unsigned char x, unsigned char y);
void SMS_setTile (unsigned int tile);


for instance, say you want the screen to scroll up: you have to load a new line of tiles into the first line below the lower border of the screen and you can do that by calling
SMS_setNextTileatXY(0,24)

followed by 32
SMS_setTile(YourTileNum)

since the VRAM pointer automatically advances to pointing the next tile.

If your map is stored as a 2D array, you could even use
void SMS_loadTileMapArea (unsigned char x, unsigned char y,  unsigned int *src, unsigned char width, unsigned char height);

to load a whole new line at once.

When you're over the 28th line of tiles, you should start overwriting the first line in the tilemap (a.k.a. PNT)

For horizontal scrolling, you can do basically the same thing, even if you're probably going to use a loop of
void SMS_setTileatXY()

since you're going to update VRAM tiles which are stored apart from each other.

--------------------------

For mappy maps, you could try using FMP2GBA which converts a Mappy map into a C array. Unfortunately it seems to support 8x8 tiling only and also doesn't support animated tiles.

In Anguna - the Prison Dungeon, I took the original game FMP maps and converted to C arrays using
for /F "tokens=1-10 delims=." %%i in ('dir *.fmp /b') do (
  fmp2gba %%i.fmp %%i.c level_%%i NOGFX
)


which turned every 'somename.FMP' in my folder into a 'somename.c' containing arrays like
const unsigned short level_somename_map[] = { <map tiles numbers here> }

which is just what you need, IMHO.

I hope it helps! :)

Thanks! :¬) I'm now making a test game for scrolling. However, there is some error when using the latest version.
Quote
devkitSMS-master\SMSLib\SMSLib.h:48: syntax error: token -> 'usefirsthalf' ; column 55
which points to
Quote
void SMS_useFirstHalfTilesforSprites (bool usefirsthalf);
...which is weird considering it never happened in the older versions.
...and yes, I'm using <stdbool.h>.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Jun 17, 2015 11:28 am
Check if you didn't change the order of your includes.
stdbool.h should come BEFORE SMSlib.h in every C source file you're including it.

#include <stdbool.h>
#include "SMSlib.h"
  View user's profile Send private message Visit poster's website
  • Joined: 23 Jan 2015
  • Posts: 28
  • Location: Bridlington, UK
Reply with quote
Post Posted: Wed Jun 17, 2015 2:10 pm
sverx wrote
Check if you didn't change the order of your includes.
stdbool.h should come BEFORE SMSlib.h in every C source file you're including it.

#include <stdbool.h>
#include "SMSlib.h"

Oh silly me. :¬P Fixed it now. I need to get more sleep...
But I'm having a problem with bank switching.

#include <stdbool.h>
#include "devkitSMS-master\SMSLib\SMSLib.h"
#include "graphics.h"
//#include "devkitSMS-master\PSGLib\PSGLib.h"

void main() {
  SMS_mapROMBank(1);
  SMS_loadPSGaidencompressedTiles(title_pscompr, 0);
  SMS_loadSTMcompressedTileMap (0, 0, title_stmcompr);
  GG_loadBGPalette(title_bin);
  while (true) {
    SMS_waitForVBlank();
  }
}

This code is supposed to render a title screen, but the screen is just black.
Please help... :¬)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Jun 17, 2015 2:19 pm
You're probably doing everything correctly, you just forgot to turn screen on...
SMS_displayOn();

place that after the palette loading

...also, you could use
SMS_mapROMBank(title_pscompr_bank);

instead of that 1 in there...

edit: are you sure you're using PS Gaiden compressed tiles (.psgcompr)? It's NOT the same as Phantasy Star RLE (pscompr)...
  View user's profile Send private message Visit poster's website
  • Joined: 23 Jan 2015
  • Posts: 28
  • Location: Bridlington, UK
Reply with quote
Post Posted: Wed Jun 17, 2015 4:34 pm
sverx wrote
You're probably doing everything correctly, you just forgot to turn screen on...
SMS_displayOn();

place that after the palette loading

...also, you could use
SMS_mapROMBank(title_pscompr_bank);

instead of that 1 in there...

edit: are you sure you're using PS Gaiden compressed tiles (.psgcompr)? It's NOT the same as Phantasy Star RLE (pscompr)...

Oh, OK. :¬P I didn't realise it didn't enable the screen on init. Also, I had no idea about the differences between the compressors. Thanks for pointing them out. :¬D
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Jun 26, 2015 9:59 am
Update rolled.
SMS_displayOn() and SMS_displayOff() macros no longer disable vertical interrupt, as it wasn't needed and could cause problems to line interrupt and pad reading.
Also, I added support for projects that need fewer sprites and for those needing DI/EI nesting (this feature requires SDCC 3.5.1 but it still has some quirks that need to be fixed... so please keep on using SDCC 3.4.0 for normal operations...)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Jun 29, 2015 11:07 am
Moving to SDCC 3.5.1 - supports preliminar DI/EI nesting. Probably not so useful after all.
  View user's profile Send private message Visit poster's website
  • Joined: 09 Jan 2012
  • Posts: 67
  • Location: Germany
Reply with quote
Post Posted: Mon Sep 14, 2015 9:16 pm
It would be nice to have some helper functions for converting (curses based) text mode games like putchar(ch, x, y). I also miss a random function for simple card games.
  View user's profile Send private message Visit poster's website
  • Joined: 25 Feb 2006
  • Posts: 863
  • Location: Belo Horizonte, MG, Brazil
Reply with quote
Post Posted: Mon Sep 14, 2015 11:08 pm
dark wrote
It would be nice to have some helper functions for converting (curses based) text mode games like putchar(ch, x, y).


SDCC implements most of stdio.h; you just have to define void putchar(char c), and the rest should automatically work.

A half-baked putchar() implementation could be as simple as that:

void putchar (char c) {
   SMS_setTile(c - 32);
}


And you could use it like so:

  SMS_setNextTileatXY(6, 5);
  printf("This is an example. Have a number: %d", 42);


Of course, the code above can't handle line breaks, and it won't scroll the text if the cursor tries to move below the screen, but it's already a start.

dark wrote
I also miss a random function for simple card games.


SDCC includes most of the C standard library, including rand().
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14687
  • Location: London
Reply with quote
Post Posted: Tue Sep 15, 2015 6:54 am
Zexall contains much of a console emulator, including line breaks and scrolling. For a real text mode game you might want to go to the the legacy text mode with more columns.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Sep 15, 2015 8:23 am
haroldoop pretty much said it all... anyway to handle texts you'll probably want to:
- load tiles containing your charset somewhere in VRAM
- update (a part of) the screen tilemap according to the text you want to render
you can do both with the provided functions. On top of those then you can build your own functions (eg. for handling word wrap, windowing, scrolling text locally, etc etc...)
  View user's profile Send private message Visit poster's website
  • Joined: 07 Oct 2015
  • Posts: 114
Reply with quote
Post Posted: Wed Oct 07, 2015 10:36 am
Hey, I'm new to the forums!

First of all congrats for the hard work and thanks for giving us the possibility of creating games for our favourite console.

I'm developing some tests and while I was at it I noticed that every button/direction in the pads which fell in the most significant byte weren't read (MSB was always 0). That included left, right, 1 and 2 from PAD 2.

I checked the sources and the SMS specs and found a small typo. IOPortH in SMSlib.c should point to 0xDD, not to 0xDE.

Changing the value to 0xDD makes both pads work.

Thank you again.
  View user's profile Send private message
  • Joined: 29 Mar 2012
  • Posts: 879
  • Location: Spain
Reply with quote
Post Posted: Wed Oct 07, 2015 10:49 am
Nice to see you here na_th_an! :-D
  View user's profile Send private message
  • Joined: 07 Oct 2015
  • Posts: 114
Reply with quote
Post Posted: Wed Oct 07, 2015 11:01 am
Hey, nice to see you too ;)
I'm just fiddling around for the moment. But my fiddling has a second player so... :D
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Oct 07, 2015 11:22 am
na_th_an wrote
I checked the sources and the SMS specs and found a small typo. IOPortH in SMSlib.c should point to 0xDD, not to 0xDE.


You're damn right! Thanks for highlighting the problem, I have now fixed it in the repo. :)
  View user's profile Send private message Visit poster's website
  • Joined: 07 Oct 2015
  • Posts: 114
Reply with quote
Post Posted: Wed Oct 07, 2015 2:42 pm
Glad to be of help!

And while we are at it, just a simple question: do you plan 8x16 sprite support in the future?
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Oct 07, 2015 3:19 pm
Well, not a simple question.
I could simply say that 8x16 sprites are already supported, just use
SMS_VDPturnOnFeature (VDPFEATURE_USETALLSPRITES);

but the truth is that the SMS_addSpriteClipping function expects sprites to be 8x8. A workaround anyway could be 'tweaking' the clipping window
SMS_setClippingWindow(0,0,255,191+8);

... or just don't use this, and do your clipping yourself and use SMS_addSprite.

So, you see, even if officially unsupported they could be unofficially supported ;)

Let me know if you find other bugs or you feel there's some missing feature, thanks!
  View user's profile Send private message Visit poster's website
  • Joined: 05 Jun 2010
  • Posts: 757
  • Location: Pennsylvania, USA
Reply with quote
Post Posted: Wed Oct 07, 2015 7:57 pm
This is pretty cool! Hope to see some more ambitious demos being used with this library for the next coding competition.
  View user's profile Send private message Visit poster's website
  • Joined: 07 Oct 2015
  • Posts: 114
Reply with quote
Post Posted: Thu Oct 08, 2015 6:30 am
sverx wrote
[...]So, you see, even if officially unsupported they could be unofficially supported ;)


That's awesome, thanks. Exactly what I needed.

I love the way this library it's built. It gives you exactly what you need with 0 hassle. Great job!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sat Oct 10, 2015 12:54 pm
sverx wrote
A workaround anyway could be 'tweaking' the clipping window
SMS_setClippingWindow(0,0,255,191+8);


Ok, sorry, I realized this is just plain wrong. :|
Proper support for 8x16 sprites in SMS_addSpriteClipping is on the way.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Oct 12, 2015 9:39 am
Library updated. Now you can change sprite mode directly using this newer function:
void SMS_setSpriteMode (unsigned char mode)

the following modes are defined:
SPRITEMODE_NORMAL
SPRITEMODE_TALL
SPRITEMODE_ZOOMED
SPRITEMODE_TALL_ZOOMED

which means support for 8x8, 8x16 and 2x zoomed sprites too (that is 16x16 and 16x32)
Please remember that there's a hardware problem with zoomed sprites on first revision SMS, as Charles detailed:
Quote
There is a bug in how the original SMS VDP processes zoomed sprites compared to the SMS 2 and GG VDP; it will only allow the first four sprites of the eight shown on a scanline to be zoomed horizontally and vertically, and the remaining four will be zoomed vertically. The SMS 2 and GG allow all eight sprites to be zoomed in both directions.

Also, MegaDrive/Genesis VDP doesn't support sprite zooming so... beware.
  View user's profile Send private message Visit poster's website
  • Joined: 07 Oct 2015
  • Posts: 114
Reply with quote
Post Posted: Tue Oct 13, 2015 6:05 am
Thanks, 8x16 sprites are a must if you want bigger buddies.

While we are at it, if you accept suggestions for new features, a PAL/NTSC detection would be nice. Of course we can use the snippets found in the dev section of this site, but have them built in the library would come up handy.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Oct 13, 2015 8:12 am
na_th_an wrote
if you accept suggestions for new features

of course! :)

I can try adding code that identifies PAL/NTSC and the VDP revision too, and of course functions to query the result... mmm... I'll work on that :)

edit: PAL/NTSC detection is on the way. I'd like to run a few tests on hardware before releasing the newer function, though.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3762
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Oct 14, 2015 7:38 am
PAL/NTSC detection added, it's performed on initialization and you can query that using the newly added function (which is SMS only)
SMS_VDPType (void)

that could return one of the two bit constants VDP_PAL and VDP_NTSC, according to 50/60 Hz screen refresh rate.

It seems to work correctly both on emulators (Emulicious and MEKA) and on my SMS II fitted with a 50/60 Hz switch.

In my plans I'll add also 'hardware model' detection, at a later time.

example usage:
  if (SMS_VDPType() & VDP_NTSC)
    SMS_setBGPaletteColor(0,0x03);    // red
  else if (SMS_VDPType() & VDP_PAL)
    SMS_setBGPaletteColor(0,0x30);    // blue
  View user's profile Send private message Visit poster's website
Reply to topic Goto page Previous  1, 2, 3, 4, 5 ... 14, 15, 16  Next



Back to the top of this page

Back to SMS Power!