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 tutorial

Reply to topic Goto page Previous  1, 2
Author Message
  • Joined: 01 Jan 2014
  • Posts: 331
Reply with quote
Post Posted: Thu Oct 13, 2016 9:15 am
Hey Sverx,

Sorry if these questions have been asked before. Redirect me if so.

Is the asset management / bank switching dealt with by the programmer or is it built in to C?

Is there support for using nametable locations other than $7800?

Nice work btw. 20 mins after downloading sdcc and skimming through the tutorial i had the screen divided in to several scrolling sections and sprites flying around.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu Oct 13, 2016 9:30 am
Current SDCC version doesn't yet support FAR pointers, so there's virtually no support for transparent bankswitching... thus this is dealt with the old manual way.
You can use the

SMS_mapROMBank(n)

macro, for example as in:

SMS_mapROMBank(bg__tiles__psgcompr_bank);
SMS_loadPSGaidencompressedTiles (bg__tiles__psgcompr, BG_TILES);


Nametable (PNT) location is fixed because of the great speed optimizations it involves:

#define SMS_PNTAddress            0x7800

If you need to change location at run time, I can help you fork a SMSlib version that supports that, it shouldn't be too hard. Also, if you need just TWO locations, you could define two constant addresses and duplicate the macros that uses that constants, as

#define XYtoADDR(x,y)             (SMS_PNTAddress|((unsigned int)(y)<<6)|((unsigned char)(x)<<1))

so that you can still use

#define SMS_setNextTileatAddr(a)  SMS_setAddr(a)

for instance.

I hope this helps :)
  View user's profile Send private message Visit poster's website
  • Joined: 01 Jan 2014
  • Posts: 331
Reply with quote
Post Posted: Thu Oct 13, 2016 11:26 pm
Thank you.

One nametable is fine, i was just checking my options. Time to code.
  View user's profile Send private message
  • Joined: 12 Oct 2015
  • Posts: 183
  • Location: Ireland
Reply with quote
Post Posted: Tue Dec 13, 2016 8:15 pm
sverx wrote
I might have these SFXs somewhere, not really sure at the moment :|
BTW I wonder why your own SFX isn't working, it looks like you're doing it the correct way. Channel #2 only, export to VGM, convert to PSG (are you using the -2 switch on vgm2psg converter, right?) and you're done.
If you can't hear that, check if you aren't either firing the SFX at all or you're not calling the PSGSFXFrame() function.


Got this working! I realized what I did wrong in my test program: I played the SFX when I hit the pause key [if (SMS_queryPauseRequested())] but I forgot to immediately call SMS_resetPauseRequest() hence the reason why SFX either didn't play or played "weird".

NB: the other thing I've seen is that I believe you *must* either fade out the SFX volume to nothing or make the last "note" of the SFX silent; otherwise the SFX will continue to "drone" - I thought PSGSFXStop() would stop playing the SFX but doesn't seem to be... Thanks
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Dec 14, 2016 10:20 am
SteveProXNA wrote
NB: the other thing I've seen is that I believe you *must* either fade out the SFX volume to nothing or make the last "note" of the SFX silent; otherwise the SFX will continue to "drone" - I thought PSGSFXStop() would stop playing the SFX but doesn't seem to be... Thanks


Actually, that's what happens when your SFX isn't properly converted or fired... let me explain.
When you convert a VGM file to a PSG one (for a SFX), you should use a command line option which tells the converter if you're going to use hardware channel 2 or channel 3 (or both!) - the converter will remove from the file any information about the channels it shouldn't touch.
Then, when you fire that SFX, you should pass the very same information, as it isn't saved into the PSG file (it's a completely header-less format).
When you fail in matching those, you'll likely get that nasty effect.
I hope this helps! :)
  View user's profile Send private message Visit poster's website
  • Joined: 19 Feb 2009
  • Posts: 4
Reply with quote
Post Posted: Fri Feb 10, 2017 10:23 pm
Hi! Sorry for my silly question, but what I have to do to be able to compile for GG?

Loading tiles background is working like a charm. To be able to do this I had to:

1. Set the option "output hex (GG)" at bmp2tile on Pallete tab;
2. Compile using SMSLib_GG
3. Uncomment the #define constant TARGET_GG

Besides that, to ensure my tilemap was draw correctly I had to set the loadtilemap function like this:

void loadAssets(void) {
  SMS_loadPSGaidencompressedTiles(initial_scene__tiles__psgcompr, BG_TILES);
    SMS_loadSTMcompressedTileMapArea(6,3,initial_scene__tilemap__stmcompr,20);
    GG_loadBGPalette(initial_scene__palette__bin);
}


Why I had to set up 6,3 at w,h parameter (instead of 0,0) I don't know yet. Somebody could help me? What I am doing wrong? (I know I had to study more I am trying to).
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Feb 10, 2017 10:35 pm
It's correct :) The GG screen shows only the central part of the 'virtual' screen, you should image that everything else you load on the tilemap is out of the central 'window', if you get what I mean.
  View user's profile Send private message Visit poster's website
  • Joined: 19 Feb 2009
  • Posts: 4
Reply with quote
Post Posted: Sat Feb 11, 2017 4:46 pm
Last edited by chains on Sat Feb 11, 2017 11:52 pm; edited 1 time in total
sverx wrote
It's correct :) The GG screen shows only the central part of the 'virtual' screen, you should image that everything else you load on the tilemap is out of the central 'window', if you get what I mean.


Yeah! I got it. Makes perfect sense. Thank you!

sverx wrote
Also, if you don't need to move these images over a background, you could use the background itself, changing the tiles according to your frame. That's what I would call an 'animated background', e.g. a torch burning while hanging on a wall, as in Prince of Persia for instance...


That's exactly what I am trying to do.. but no luck until now.

Do you guys have a pattern to calculate the frames per sec or something to do this task? Everything I came up with handles with the OS' "current time", but I can't figure it out how to do it with Z80.

I think I will have to write my own algorithm... I wonder with someone came up with a similar problem and could help me? :)

I've tried to implement an accumulator while in the looping and then after a certain amount of "time" do some other things, clear the memory and repeat. But so long no luck. :(
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sat Feb 11, 2017 5:58 pm
On a GG the screen refresh is 60 times per second. The 'trick' is to make your code sync with it, using
SMS_waitForVBlank()

which will stop the processing until vblank starts, which means you'll be at start of the blanking phase, the right time to update VRAM contents (update SAT for instance, and some tiles eventually). Also, as long as you're in vblank, you can use UNSAFE (fast) functions as the VRAM can be accessed at maximum speed with no data corruption.
  View user's profile Send private message Visit poster's website
  • Joined: 19 Feb 2009
  • Posts: 4
Reply with quote
Post Posted: Sat Feb 11, 2017 11:50 pm
Thanks again for your answer. You're great!

That's what I am trying to do.. But I don't figure out why I am not able to emulate a 1s of delay between cycles before drawing something else. Let's do some code to exemplify.

Here's my code:

void titleScene(void) {
  unsigned int ks = 0;
  unsigned int x;
  const unsigned int *pnt;
  loadTitleAssets();
  SMS_displayOn();
  while(gameState == ST_TITLE) {
    ks = SMS_getKeysStatus();
    if(ks & GG_KEY_START) {
      gameState = ST_MAIN;
      break;
    }
    for (x = 0; x < 13; x++) {
      SMS_setNextTileatXY(GG_X+3+x,GG_Y+13);
      pnt = &press_start__tilemap__bin[x*2];
      SMS_setTile(*pnt+++PS_TILES);
    }
    SMS_waitForVBlank();
  }
  SMS_displayOff();
  mainScene();
}


Works great. But I am not happy with it because I want to add a blink animation at the press start phrase. At 1sec the VDP should display "press start" and at the 2sec shouldn't display nothing at all. And so on...

So, I added a simple accumulator to emulate that. At every 60 frames, computes a sec. (just an example)


    [...]
    unsigned char secs = 0;
    unsigned int t = 0;
    [...]
    t++;
    if(t == 60) {
      secs++;
       t = 0;
    }
    SMS_waitForVBlank();
    [...]


So at the draw logic, we may add a new condition:


    for (x = 0; x < 13; x++) {
      SMS_setNextTileatXY(GG_X+3+x,GG_Y+13);
      if(secs == 0) {
        pnt = &press_start__tilemap__bin[x*2];
      } else {
        pnt = &press_start__tilemap__bin[2];
      }
      SMS_setTile(*pnt+++PS_TILES);
    }


That
&press_start__tilemap__bin[2]
means a blank tile.

Makes sense?

But it's not working. The processor is assuming the else condition every time and the "press start" sentence is not appearing. I lack a debug tool to look with more detail at the VDP processing. Do you know something to help with it? I'm using a MacOS.

I am not fluent in english nor C, so I apologize for any inconvenient in advance...

Edit: t = 0;
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun Feb 12, 2017 10:52 am
Hard to tell why it isn't working, it may be the if condition checking just if secs is zero instead of checking if it is odd or even...
BTW I suggest you to switch your approach to a simpler one: just one unsigned char variable, and then check if it's time to draw/erase something or simply do nothing
unsigned char cnt=0;
if (++cnt==1) {
  // draw text
} else if (cnt==61) {
  // erase text
} else if (cnt==120) {
  cnt=0;
}
  View user's profile Send private message Visit poster's website
  • Joined: 22 Oct 2017
  • Posts: 16
Reply with quote
Post Posted: Wed Oct 25, 2017 1:47 am
trying to use bmp2tile to create the assets, but I have no dialog boxes in the program (screenshots attached)

am I missing some files that will allow me to properly use this software? sorry for such a stupid and basic question... in the readme of bmp2tile it describes a number of options as well as "Click on "Save" to save the tile data to a file." and I see none of that.

edit: I opened bmp2tile on a different windows computer and now along the bottom there are options and the ability to save. so it looks like I am missing some DLL or redistributable.

edit 2:
changed the code to use non compressed functions along with my copy/pasted uncompressed tilemaps
SMS_loadTiles(field__tiles__psgcompr, BG_TILES,1216);
SMS_loadTileMap (0, 0, field__tilemap__stmcompr, 4728);
SMS_loadBGPalette(field__palette__bin);
SMS_loadTiles(sprites__tiles__psgcompr, SPRITE_TILES,912);
SMS_loadSpritePalette(sprites__palette__bin);
and the result compiles and plays! looks messed up, but I'm happy.
ss-source.png (34.32 KB)
ss-source.png
ss-tiles.png (56.65 KB)
ss-tiles.png
dependency2.png (115.28 KB)
dependency2.png
hacked.png (108.62 KB)
hacked.png

  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14683
  • Location: London
Reply with quote
Post Posted: Wed Oct 25, 2017 6:41 am
BMP2Tile does not work well at high DPI settings, please use the compatibility options to disable that.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Oct 25, 2017 9:03 am
Wainstop wrote
changed the code to use non compressed functions along with my copy/pasted uncompressed tilemaps
  SMS_loadTiles(field__tiles__psgcompr, BG_TILES,1216);
  SMS_loadTileMap (0, 0, field__tilemap__stmcompr, 4728);
  SMS_loadBGPalette(field__palette__bin);
  SMS_loadTiles(sprites__tiles__psgcompr, SPRITE_TILES,912);
  SMS_loadSpritePalette(sprites__palette__bin);

and the result compiles and plays! looks messed up, but I'm happy.


it's messed up because you're using compressed tilemaps and tiles (stmcompr, psgcompr) and you're loading them with the functions to load uncompressed assets. Use the proper functions and it will work :)
  View user's profile Send private message Visit poster's website
  • Joined: 22 Oct 2017
  • Posts: 16
Reply with quote
Post Posted: Fri Oct 27, 2017 1:45 am
sverx wrote
it's messed up because you're using compressed tilemaps and tiles (stmcompr, psgcompr) and you're loading them with the functions to load uncompressed assets.


no. I only kept the filenames the same as in the tutorial. the contents of the files are simply copy and pasting out of the edit control of bmp2tile. uncompressed. this was the only option for me, because on my Windows 7 64-bit laptop at 1366x768, bmp2tile does not display any controls whatsoever (as in the screenshots I shared). it's not possible for me to export or save any output except by directly copy and pasting out of the edit box. I have tried compatibility settings.

do you have a suggestion of any other tools to use instead for converting images? also, how should I use the fourth parameter of those uncompressed functions? do I specify the size in bytes of what I am loading?
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14683
  • Location: London
Reply with quote
Post Posted: Fri Oct 27, 2017 6:12 am
You can drive BMP2Tile from the command line to generate the compressed assets. Something about your system is making it draw the controls off the screen, I'm not sure what but I expect it is something to do with scaling or font size.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Oct 27, 2017 8:02 am
Wainstop wrote
I only kept the filenames the same as in the tutorial. the contents of the files are simply copy and pasting out of the edit control of bmp2tile.


wow. no, it won't ever work this way, as in the edit control you won't see a binary file but an .asm source instead. Use BMP2Tile command line if you can't make the GUI work, as Maxim suggested.

the last parameter is the size of data, in bytes.
  View user's profile Send private message Visit poster's website
  • Joined: 01 Jan 2014
  • Posts: 331
Reply with quote
Post Posted: Sat Oct 28, 2017 1:39 am
elo,

Is there support for ixh, ixl, iyh, iyl instructions in inline asm?

EDIT: Found info on wiki, no supported.
  View user's profile Send private message
  • Joined: 08 May 2018
  • Posts: 5
Reply with quote
Post Posted: Sun May 13, 2018 7:51 am
bmp2tile043 errors out when loading the provided png containing the score font. After much flailing about, I narrowed it down to the png using RGB directly rather than indexed color. I have converted the png to indexed color (attached) and bmp2tile happily converts it and it loads and works as intended in the tutorial project.

Just hoping to save some future person some time. Sverx, thank you very much for devkitSMS, it is a very nice package.

Also, I am fond of using make over batch files for compilation. Assuming a project folder structure that looks like this:

assets/
banks/
build/
include/
src/
Makefile


The following makefile can be used directly by changing some configuration variables for your project and environment:
## Path Configuration - Modify for your environment ##
SDCC_ROOT=C:/SDCC
DEVKITSMS_ROOT=C:/SDCC/devkitSMS
IHX2SMS = $(SDCC_ROOT)/bin/ihx2sms
ASSETS2BANKS = $(SDCC_ROOT)/bin/assets2banks

# Change to build/ for *nix systems
BUILD = build\\

# Change to banks/ for *nix systems
BANKS = banks\\

## Name of your remove program. If you're on *nix you most likely want `rm' here. ##
REMOVE = del

## Name of move command
MOVE = MOVE /Y

## Program configuration. Target name, libs to link, include directories. ##
TARGET=hello

LIBS = SMSlib.lib
INCLUDES = -Iinclude

CFLAGS  = -c -mz80
LDFLAGS = -mz80 --data-loc 0xC000 -Wl-b_BANK2=0x8000 --no-std-crt0 $(DEVKITSMS_ROOT)/crt0/crt0_sms.rel

## Stop editing here ##

CC = $(SDCC_ROOT)/bin/sdcc

.SUFFIXES: .rel
.PHONY: assets

SRCS = $(notdir $(wildcard src/*.c))
OBJS = $(SRCS:%.c=$(BUILD)%.rel)
BANKOBJS = $(notdir $(wildcard banks/*.rel))

all: assets $(TARGET)

$(TARGET): $(OBJS)
   $(CC) $(LDFLAGS) -o build/$(TARGET).ihx $(OBJS) $(LIBS) banks/$(BANKOBJS)
   $(IHX2SMS) $(BUILD)$(TARGET).ihx $(TARGET).sms

$(BUILD)%.rel: src/%.c
      $(CC) $(CFLAGS) $(INCLUDES) $< -o $(BUILD)

assets:
   $(ASSETS2BANKS) assets --compile
   $(MOVE) *.h ./include
   $(MOVE) *.rel ./banks

clean:
   $(REMOVE) $(TARGET).sms \
      $(BUILD)*.ihx $(BUILD)*.lk $(BUILD)*.map $(BUILD)*.noi \
      $(BUILD)*.asm $(BUILD)*.lst $(BUILD)*.rel $(BUILD)*.sym \
      $(BANKS)*.rel


It contains all the build output to the build/ directory and leaves the built rom in the root of the project.
score.png (1.03 KB)
Indexed color Score PNG
score.png

  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14683
  • Location: London
Reply with quote
Post Posted: Sun May 13, 2018 9:10 am
Yes, BMP2Tile does not try to manage the palette for you as generally that's something you will manage yourself across multiple images. It ought to give a meaningful error message though.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun May 13, 2018 9:51 am
wasn't score.png already an indexed image? I wonder how I did convert that, then... :|

BTW thanks for the makefile, which would come handy if one changes just some sources and doesn't want to recompile everything - speaking about that unfortunately a single trivial change in a single asset will force everything to be recompiled.

Anyway, does the makefile compile assures you the correct link order of the modules? crt0 must be the first, then there should be all the objects that contains code (thus your game and the libraries used) and after that all the bank* objects in strict ascending order. Otherwise linking will produce a file that ihx2sms will turn into a 'broken' ROM file.
  View user's profile Send private message Visit poster's website
  • Joined: 08 May 2018
  • Posts: 5
Reply with quote
Post Posted: Sun May 13, 2018 6:49 pm
sverx wrote
a single trivial change in a single asset will force everything to be recompiled.


The make file addresses this in a couple different ways. First, there are different targets for the assets and the source files. Secondly, the assets recipe is set to be a .PHONY target. This means make doesn't try to associate running that recipe to any particular file so a change in the assets won't automatically be detected and compiled.

So running just
make
will execute the all: target which will first run assets2banks and then compile the rom. If no changes to assets have been made the asset generation step can be skipped by running
make <TARGETNAME>
where <TARGETNAME> is defined in the makefile as the TARGET variable, e.g;
make hello
That will build just the changed source files to make the rom and link in the already existing bank rels in that order.

But even if you ignore the targets and just run the default make it won't force a recompilation of anything since it is just linking in the already built bankN.rels that assets2banks has helpfully created.

You just may get tired of seeing assets rebuilt for no reason :)

sverx wrote
Anyway, does the makefile compile assures you the correct link order of the modules? crt0 must be the first, then there should be all the objects that contains code (thus your game and the libraries used) and after that all the bank* objects in strict ascending order. Otherwise linking will produce a file that ihx2sms will turn into a 'broken' ROM file.


With one exception I've addressed below: yes.
$(CC) $(LDFLAGS) -o build/$(TARGET).ihx $(OBJS) $(LIBS) banks/$(BANKOBJS)


This is the recipe for doing the link of the ihx. LDFLAGS includes "--no-std-crt0 $(DEVKITSMS_ROOT)/crt0/crt0_sms.rel" so that will be placed before anything else and then followed by built objects, static libraries, and lastly the bankN.rels.

The BANKOBJs variable is relying on the filesystem for sort order which is working fine for me since I am not up to over 9 banks yet ;) This is not ideal. While I try to figure out how to do a crossplatform numerical sort (make only provides a lexicographic sort which is not very useful for this case) this order can be manually specified by setting BANKOBJ ourselves. Below is a slightly updated makefile that shows this:

## Path Configuration - Modify for your environment ##
SDCC_ROOT=C:/SDCC
DEVKITSMS_ROOT=C:/SDCC/devkitSMS
IHX2SMS = $(SDCC_ROOT)/bin/ihx2sms
ASSETS2BANKS = $(SDCC_ROOT)/bin/assets2banks

# Change to build/ for *nix systems
BUILD = build\\

# Change to banks/ for *nix systems
BANKS = banks\\

## Name of your remove program. If you're on *nix you most likely want `rm' here. ##
REMOVE = del

## Name of move command
MOVE = MOVE /Y

## Program configuration. Target name, libs to link, include directories. ##
TARGET=hello

LIBS = SMSlib.lib
INCLUDES = -Iinclude

CFLAGS  = -c -mz80
LDFLAGS = -mz80 --data-loc 0xC000 -Wl-b_BANK2=0x8000 --no-std-crt0 $(DEVKITSMS_ROOT)/crt0/crt0_sms.rel

## Stop editing here ##

CC = $(SDCC_ROOT)/bin/sdcc

.SUFFIXES: .rel
.PHONY: assets

SRCS = $(notdir $(wildcard src/*.c))
OBJS = $(SRCS:%.c=$(BUILD)%.rel)
BANKOBJS = banks/bank2.rel

all: assets $(TARGET)

$(TARGET): $(OBJS)
   $(CC) $(LDFLAGS) -o build/$(TARGET).ihx $(OBJS) $(LIBS) $(BANKOBJS)
   $(IHX2SMS) $(BUILD)$(TARGET).ihx $(TARGET).sms

$(BUILD)%.rel: src/%.c
      $(CC) $(CFLAGS) $(INCLUDES) $< -o $(BUILD)

assets:
   $(ASSETS2BANKS) assets --compile
   $(MOVE) *.h ./include
   $(MOVE) *.rel ./banks

clean:
   $(REMOVE) $(TARGET).sms \
      $(BUILD)*.ihx $(BUILD)*.lk $(BUILD)*.map $(BUILD)*.noi \
      $(BUILD)*.asm $(BUILD)*.lst $(BUILD)*.rel $(BUILD)*.sym \
      $(BANKS)*.rel
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14683
  • Location: London
Reply with quote
Post Posted: Sun May 13, 2018 9:51 pm
Using padded bank numbers would make them sort lexicographically, and hex would get you the maximum range in two characters.
  View user's profile Send private message Visit poster's website
  • Joined: 08 May 2018
  • Posts: 5
Reply with quote
Post Posted: Sun May 13, 2018 11:03 pm
Maxim wrote
Using padded bank numbers would make them sort lexicographically, and hex would get you the maximum range in two characters.


Yes but I'm not sure if that is configurable using assets2banks which is generating the filenames.

I am, of course, new to this so there are many things that are still murky to me.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon May 14, 2018 8:12 am
orphean wrote
Maxim wrote
Using padded bank numbers would make them sort lexicographically, and hex would get you the maximum range in two characters.


Yes but I'm not sure if that is configurable using assets2banks which is generating the filenames.


if there's request for that, I might add a command line switch - it doesn't seem too complex after all ;)
  View user's profile Send private message Visit poster's website
  • Joined: 12 Oct 2015
  • Posts: 183
  • Location: Ireland
Reply with quote
Post Posted: Tue May 15, 2018 8:08 am
Last edited by SteveProXNA on Sat Aug 04, 2018 10:05 am; edited 1 time in total
Hi all - I also blogged about experiences how to setup the devkitSMS and some programming samples:

http://steveproxna.blogspot.com/2017/09/devkitsms-programming-setup.html
http://steveproxna.blogspot.com/2017/11/devkitsms-programming-sample.html
http://steveproxna.blogspot.com/2018/03/devkitsms-programming-sample-ii.html
  View user's profile Send private message Visit poster's website
  • Joined: 03 Aug 2018
  • Posts: 2
Reply with quote
Post Posted: Fri Aug 03, 2018 8:24 pm
Hello sverx,

Is it possible to load a map with a size 128*24 for a scrolling game ?
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14683
  • Location: London
Reply with quote
Post Posted: Fri Aug 03, 2018 8:54 pm
The video memory only holds 32x28, you would need to use http://www.smspower.org/forums/16800-GeneralScrollLibraryGSLib or some custom code to deal with it.
  View user's profile Send private message Visit poster's website
  • Joined: 03 Aug 2018
  • Posts: 2
Reply with quote
Post Posted: Sat Aug 04, 2018 12:11 am
oh thks a lot Maxim , just what i want :D
  View user's profile Send private message
  • Joined: 11 Apr 2019
  • Posts: 2
  • Location: Juiz de Fora/MG-BRASIL
Reply with quote
Post Posted: Tue Aug 13, 2019 1:02 am
I can not make it work at all .. do not make any mistake, but it is all black screen.

Build assets.c and assets.h from assets folder
*** sverx's folder2c converter ***
Info: conversion completed. File "assets.c" defines 1068 total bytes.
Build Main
Linking
*** sverx's ihx2sms converter ***
Info: 2939 bytes used/32768 total [8.97%] - size of output ROM is 32 KB
Info: SEGA header found, checksum updated
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Aug 14, 2019 4:24 pm
if you've got the SMS file and it's not working you can attach it here and I'll check what's wrong
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2018
  • Posts: 6
Reply with quote
Post Posted: Wed Aug 10, 2022 6:56 pm
DavilaGames wrote
I can not make it work at all .. do not make any mistake, but it is all black screen.

Build assets.c and assets.h from assets folder
*** sverx's folder2c converter ***
Info: conversion completed. File "assets.c" defines 1068 total bytes.
Build Main
Linking
*** sverx's ihx2sms converter ***
Info: 2939 bytes used/32768 total [8.97%] - size of output ROM is 32 KB
Info: SEGA header found, checksum updated


Getting the same issue. I am building on a mac, so I had to make the assets using png2tile instead of bmp2tile. That is the only part where I am not 100% sure of the outcome.

I tried both in binary format and other using the various functions, no success, black screen looking at me.

No errors in compilation or anything weird. I get my nice .gg rom....and that's it.

(am building for gg. I replaced the functions correctly and have added the #define TARGET_GG at the top of my main. As a test I also tried building for SMS, still black screen.)
  View user's profile Send private message
  • Joined: 12 Aug 2021
  • Posts: 73
Reply with quote
Post Posted: Wed Aug 10, 2022 7:21 pm
Hi,

Out of curiosity, have you also set colours in the palette ? Otherwise you may end up seeing nothing because all colour entries are black !

If you are using emulicious, try to set the palette to "TMS" in the video ram viewer (I don't remember how it is exactly called, but it is part of the debugging tools), to see if anything is present in VRAM.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Wed Aug 10, 2022 7:49 pm
if your ROM is compiled correctly and still you don't see anything on the screen, these are a few hints about what to check:

- check if you remembered to turn display on, using:
SMS_displayOn();
- check if you had loaded at least the background palette (as armixer24 just suggested)
- check that you have loaded some tiles into VRAM (if your tiles are 'empty' and your color 0 is black, you'd get a black background)
- check that you're loading a tilemap

if everything fails, check with different emulators and/or on real hardware

if still you get black screen in any case, I'm very interested to see it myself, so you can PM me/share your ROM if you want
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2018
  • Posts: 6
Reply with quote
Post Posted: Fri Aug 12, 2022 8:06 am
sverx wrote
if your ROM is compiled correctly and still you don't see anything on the screen, these are a few hints about what to check:

- check if you remembered to turn display on, using:
SMS_displayOn();

- check if you had loaded at least the background palette (as armixer24 just suggested)
- check that you have loaded some tiles into VRAM (if your tiles are 'empty' and your color 0 is black, you'd get a black background)
- check that you're loading a tilemap

if everything fails, check with different emulators and/or on real hardware

if still you get black screen in any case, I'm very interested to see it myself, so you can PM me/share your ROM if you want


all of the above, sadly done. I made two roms, one done with the psgcompr/stmcompr files. One made with binary files (using the appropriate functions to load each one of them).

attached both, because why not :D

Tried on real hw and on emulator. (meka and emulicious and on a flashcart).
Tried folder2c and assets2bank. None of them work.


The only thing that makes me suspicious is png2tile, but I matched the settings from various places and they all look ok (palette gg, compression for the tiles and tilemap, etc...)

I also tried to build an sms rom, same result.
ggtests.zip (2.75 KB)

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Aug 12, 2022 8:21 am
the zip file doesn't contain the source code, BTW running this in Emulicious it looks like you're probably using the functions parameters in the wrong order. Can you share how you're calling the functions?
(The BG palette seems to be loading correctly, but that's a single parameter function so no surprise here...)

edit: oh, wait, what version of SDCC are you using? what branch of devkitSMS?

you should be using SDCC 4.1.0 for the official branch, SDCC 4.2.0 or later versions for the 'experimental' branch (former still suggested until everything is fine with experimental)

anyway, in case you're using SDCC 4.2.0 or later with the official devkitSMS branch, you could still keep on using that version but when compiling you have to add the
--sdcccall 0
command line switch to tell the compiler that we're using the 'legacy' calling conventions, because they changed those quite recently.
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2018
  • Posts: 6
Reply with quote
Post Posted: Fri Aug 12, 2022 4:17 pm
sverx wrote
the zip file doesn't contain the source code, BTW running this in Emulicious it looks like you're probably using the functions parameters in the wrong order. Can you share how you're calling the functions?
(The BG palette seems to be loading correctly, but that's a single parameter function so no surprise here...)

edit: oh, wait, what version of SDCC are you using? what branch of devkitSMS?

you should be using SDCC 4.1.0 for the official branch, SDCC 4.2.0 or later versions for the 'experimental' branch (former still suggested until everything is fine with experimental)

anyway, in case you're using SDCC 4.2.0 or later with the official devkitSMS branch, you could still keep on using that version but when compiling you have to add the
--sdcccall 0
command line switch to tell the compiler that we're using the 'legacy' calling conventions, because they changed those quite recently.


for sdcc i am using this:


SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/sm83/tlcs90/ez80_z80/z80n/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502 4.2.0 #13081 (Mac OS X x86_64)
published under GNU General Public License (GPL)


I tried adding --sdcccall 0 when calling it, no change.

of course I can share the source code and the build file if needed (it is barely the beginning of the tutorial code though.

as for the function call order, the same as the tutorial:


    SMS_loadTiles(field__tiles__bin, 0,field__tiles__bin_size);
    SMS_loadTileMap(0, 0, field__tilemap__bin,field__tilemap__bin_size);
    GG_loadBGPalette(field__palette__bin);


for the bin version and


    SMS_loadPSGaidencompressedTiles(field__tiles__psgcompr, 0);
    SMS_loadSTMcompressedTileMap(0, 0, field__tilemap__stmcompr);
    GG_loadBGPalette(field__palette__bin);


for the compressed version.

After either of them I call: SMS_displayOn

and the endless loop.
  View user's profile Send private message
  • Joined: 12 Aug 2021
  • Posts: 73
Reply with quote
Post Posted: Fri Aug 12, 2022 5:17 pm
Out of curiosity, I've run the "uncompressed" test.gg ROM in Emulicious.

I have set the memory to be initialised with 0's so we can only see the changes that your code made.

It seems DevKitSMS initialises properly. However, I am not too sure about the resources you loaded.

To start simple, I tried looking at the palette in Emulicious' memory debugger.



Emulicious reads back the contents of the memory not only as hexadecimal (on the left), but also as characters (on the right), and those characters to me look like an assembly source file, as generated by BMP2Tile for example.

This makes me think you may not have exported the resources as binary, and that might be why the contents that was displayed did not make sense.

If you are using BMP2Tile on Windows, when you click the "Save" button, in the window that opens, make sure you change the file type to "Binary files (*.bin)", and try to feed that file to assets2banks (or whichever tool you are using to turn binary files into C source).

Additionally I can see that some parts in the tileset memory have content modified, but it's garbage data. You may be having the same issue, try to re-export the tileset and tilemap data as binary files :)

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Aug 12, 2022 6:52 pm
armixer24 wrote
This makes me think you may not have exported the resources as binary, and that might be why the contents that was displayed did not make sense.


Good catch!

I see png2tile has a -binary parameter, you're probably missing that in your conversion command line
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2018
  • Posts: 6
Reply with quote
Post Posted: Sat Aug 13, 2022 6:18 am
armixer24 wrote
Out of curiosity, I've run the "uncompressed" test.gg ROM in Emulicious.

I have set the memory to be initialised with 0's so we can only see the changes that your code made.

It seems DevKitSMS initialises properly. However, I am not too sure about the resources you loaded.

To start simple, I tried looking at the palette in Emulicious' memory debugger.



Emulicious reads back the contents of the memory not only as hexadecimal (on the left), but also as characters (on the right), and those characters to me look like an assembly source file, as generated by BMP2Tile for example.

This makes me think you may not have exported the resources as binary, and that might be why the contents that was displayed did not make sense.

If you are using BMP2Tile on Windows, when you click the "Save" button, in the window that opens, make sure you change the file type to "Binary files (*.bin)", and try to feed that file to assets2banks (or whichever tool you are using to turn binary files into C source).

Additionally I can see that some parts in the tileset memory have content modified, but it's garbage data. You may be having the same issue, try to re-export the tileset and tilemap data as binary files :)



Thanks! Actually I had already tried the -binary option (using png2tile) and it did not change anything :(

BUT! when yesterday sverx suggested I add the

--sdcccall 0
(which I did....and did not work) I mistakenly added a "full width space" (japanese keyboard was accidentally selected) after the 0 and the option was being ignored.

So to sum it up, the issue from the beginning was the lack of --sdcccall 0, when I added it I did a stupid thing, did not notice the output and it did not work.

Thanks to everyone for the help!!!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Aug 15, 2022 8:14 am
Glad you solved it! :)

BTW, using the latest SDCC with a version of devkitSMS that requires a different SDCC isn't perfect.

Since it was overdue anyway, I just 'officially' switched devkitSMS to SDCC 4.2.0 (or later) so make sure you update the devkit and remove that
--sdcccall 0


It'll be just easier.
  View user's profile Send private message Visit poster's website
  • Joined: 30 Jan 2023
  • Posts: 52
  • Location: Manchester, England
Reply with quote
Post Posted: Sun Feb 19, 2023 1:30 pm
Thanks for this tutorial, it definitely helped me learn some of the basics and I expanded upon it to make a pong game :)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Feb 20, 2023 11:39 am
Louis The SEGA Nerd wrote
Thanks for this tutorial, it definitely helped me learn some of the basics and I expanded upon it to make a pong game :)


Happy it helped! My plan was exactly to introduce to the devkit, so it's nice to see it worked :D
  View user's profile Send private message Visit poster's website
  • Joined: 27 Feb 2023
  • Posts: 122
  • Location: France
Reply with quote
Post Posted: Mon Feb 27, 2023 6:57 pm
sverx wrote
Happy it helped! My plan was exactly to introduce to the devkit, so it's nice to see it worked :D

Hello sverx, I wanted to let you know that I have been using devkitSMS for several months now on a personal project (that I will be sharing shortly, when I can create topics) and this is the reason I was able to create a Game Gear game at all.

I first started in assembly (where I only have basic knowledge) and it was too abstract and difficult for me. I still learnt a lot, including what things the processor can and cannot do, which is useful even when coding in C to avoid performance issues (don't use modulo, multiply/divide by multiples of 2 as much as possible etc...). But C, overall, made it possible as I had much better knowledge.

So thanks a lot.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Feb 28, 2023 8:05 am
@cireza: I'm looking forward to see your game! Do you know we have a coding competition running?
You can enter by March 27. But you can do as you prefer, it's totally fine.
  View user's profile Send private message Visit poster's website
  • Joined: 27 Feb 2023
  • Posts: 122
  • Location: France
Reply with quote
Post Posted: Wed Mar 01, 2023 9:09 pm
sverx wrote
@cireza: I'm looking forward to see your game! Do you know we have a coding competition running?
You can enter by March 27. But you can do as you prefer, it's totally fine.

I saw there was news about it. However I don't think I will participate as I want to keep my free time for the Game Gear game. But thanks for the heads-up.
  View user's profile Send private message
  • Joined: 29 Mar 2012
  • Posts: 879
  • Location: Spain
Reply with quote
Post Posted: Thu Mar 02, 2023 7:02 am
I think sverx is proposing you present your Game Gear game :-)
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14683
  • Location: London
Reply with quote
Post Posted: Thu Mar 02, 2023 8:26 am
You might spend a little time to make a demo version for the competition even if you don’t intend to complete it by the deadline.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3757
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu Mar 02, 2023 9:39 am
kusfo wrote
I think sverx is proposing you present your Game Gear game :-)


yeah that's what I meant to say - sorry! >.<
  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!