Moon tutorial doesn't work

SGDK only sub forum

Moderator: Stef

Post Reply
Ricky
Interested
Posts: 23
Joined: Tue May 22, 2012 10:09 am

Moon tutorial doesn't work

Post by Ricky » Mon May 28, 2012 3:32 pm

It compiles and links perfectly fine but when I run in Gens I get a gray screen, this normal? Also I go into the VDP and I can see the moon is in VRAM but it just isn't being drawn.

Code: Select all

#include <genesis.h>

//moon.h is generated from moon.bmp
//just be sure to put your 16colors bitmap on 'res' folder
// file logo-blue-moon-25024.jpg is here for reference : it's the original picture I used
#include "moon.h"

#define TILE1	1


int main( )
{
	// get the image width (in pixel) ==> should be 8pix aligned
	u16 w = moon[0];
	// get the image height (in pixel)  ==> should be 8px aligned
	u16 h = moon[1];

	// get the palette at moon[2 to 17]
	VDP_setPalette(PAL1, (u16 *) &moon[2]);

	// load bitmap data at moon[18....] in VRAM
	// w/8 = width in tiles we want to load
	// h/8 = height in tile we want to load
	// w/8 = width in tiles of the bitamp
	// the 3rd arg is needed because you could load only a part of the bitmap if you want but SGDK needs the width as reference
	VDP_loadBMPTileData((u32*) &moon[18], TILE1, w/8, h/8, w/8);

    // draw the moon at (12,12)
    VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, 1), 12, 12, w / 8, h / 8);

	while(1)
	{
		VDP_waitVSync();
	}
	return 0;
}
right off the site, it should work but I can't get it to.

The moon is the low res file so that can't be the problem. Maybe the link order?

Ricky
Interested
Posts: 23
Joined: Tue May 22, 2012 10:09 am

Post by Ricky » Mon May 28, 2012 8:42 pm

tried it in kega and resgen and same results. gray screen.
kega also says I have a checksum error? what could cause that?

I'm going to mess about with the linking or maybe there was a step I missed in the tutorial. Won't hurt to double check

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Tue May 29, 2012 12:25 am

Ricky wrote:kega also says I have a checksum error? what could cause that?
Homebrew never generates a checksum because the homebrew startup doesn't bother checking the checksum. You can ignore the message.

Ricky
Interested
Posts: 23
Joined: Tue May 22, 2012 10:09 am

Post by Ricky » Tue May 29, 2012 12:29 am

Chilly Willy wrote:
Ricky wrote:kega also says I have a checksum error? what could cause that?
Homebrew never generates a checksum because the homebrew startup doesn't bother checking the checksum. You can ignore the message.
Oh ok, thanks :)

Compiler and linker is not the issue and I'm sure I haven't missed a step
Has something like this ever happen to anyone before and how did they fix it?

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Tue May 29, 2012 1:34 am

Looking at the program... how are BMPs preprocessed before adding to the project? It can't be just making it binary or everything's all wrong. You should check what data is being generated for the moon and see if it matches what the program expects.

Ricky
Interested
Posts: 23
Joined: Tue May 22, 2012 10:09 am

Post by Ricky » Tue May 29, 2012 5:50 am

Chilly Willy wrote:Looking at the program... how are BMPs preprocessed before adding to the project? It can't be just making it binary or everything's all wrong. You should check what data is being generated for the moon and see if it matches what the program expects.
Yes ofcourse, look.

Code: Select all

-------------- Build: Out in smd_helloworld ---------------

bintos -bmp C:\Users\Ricky\Dev\cpp\SMD\smd_helloworld\moon.bmp
gcc.exe -m68000 -Wall -O3 -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer -fno-builtin-memset -fno-builtin-memcpy -IC:\Utils\GenDev\include\  -IC:\Utils\GenDev\bin  -c moon.s -o obj\Out\\moon.o
rm moon.s
gcc.exe -m68000 -Wall -O3 -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer -fno-builtin-memset -fno-builtin-memcpy -c -IC:\Utils\GenDev\include\  -IC:\Utils\GenDev\bin  -o obj\Out\\rom_head.o C:\Users\Ricky\Dev\cpp\SMD\smd_helloworld\rom_head.c
ld.exe -T C:/Utils/GenDev/md.ld -nostdlib --oformat binary -o rom_head.bin obj\Out\\rom_head.o
gcc.exe -m68000 -Wall -O3 -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer -fno-builtin-memset -fno-builtin-memcpy -c -IC:\Utils\GenDev\include\  -IC:\Utils\GenDev\bin  C:/Utils/GenDev/src/boot/sega.s -o obj\Out\\sega.o
gcc.exe -m68000 -Wall -O3 -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer -fno-builtin-memset -fno-builtin-memcpy -c -IC:\Utils\GenDev\include\  -IC:\Utils\GenDev\bin  -o obj\Out\\main.o C:\Users\Ricky\Dev\cpp\SMD\smd_helloworld\main.c
ld.exe -T C:/Utils/GenDev/md.ld -nostdlib --oformat binary -o rom_head.bin obj\Out\\rom_head.o
gcc.exe -m68000 -Wall -O3 -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer -fno-builtin-memset -fno-builtin-memcpy -c -IC:\Utils\GenDev\include\  -IC:\Utils\GenDev\bin  C:/Utils/GenDev/src/boot/sega.s -o obj\Out\\sega.o
ld.exe -T C:/Utils/GenDev/md.ld -nostdlib obj\Out\\sega.o obj\Out\moon.o obj\Out\rom_head.o obj\Out\main.o  C:/Utils/GenDev/lib/libmd.a C:/Utils/GenDev/lib/libgcc.a -o obj\Out\\smd.out
objcopy -O binary obj\Out\\smd.out bin\Out\smd_helloworld.smd
sizebnd bin\Out\smd_helloworld.smd -sizealign 131072
rm rom_head.bin
Output size is 48.02 KB
Output size is 128.00 KB
Output size is 128.00 KB
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 0 warnings
I got Code::Blocks set up to run everything itself instead of using the makefile.gen I got much more control this way and I'll be making a thread on how I managed this soon after I got it fully up and working with all supported SGDK files. As you can see bintos is the first thing I call, then main has its moon.h so it doesn't complain, moon.o is linked later and everything else is business as usual. Can't explain what's going on, I build using the makefile.gen just in case I configured something wrong in Code::Blocks but I get the same results, grey.

I can see the moon in VRAM/Tile view when debugging the VDP from GensKmod.

I'm going to be building all tutorials to see whats going on.

Tutorial 1 builds and works (hello world)
Tutorial 2 builds and works (buttons)
Tutorial 3pt1 builds and works (drawing pixels)
Tutorial 3pt2 builds but does not work (moon fails, grey screen)

Testing tutorial 4 tomorrow, I'm going to bed
:lol:

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue May 29, 2012 7:45 am

I will check the problem asap (i'm at work), indeed that tutorial should work.

Ricky
Interested
Posts: 23
Joined: Tue May 22, 2012 10:09 am

Post by Ricky » Tue May 29, 2012 4:06 pm

Stef wrote:I will check the problem asap (i'm at work), indeed that tutorial should work.
Thanks Stef

Tutorial 4 doesn't build undefined

Code: Select all

||=== smd_helloworld, Out ===|
C:\Users\Ricky\Dev\cpp\SMD\smd_helloworld\main.c||In function `main':|
C:\Users\Ricky\Dev\cpp\SMD\smd_helloworld\main.c|48|error: `_spritedef' undeclared (first use in this function)|
where is _spritedef declared?

[edit]
took a screenshot of what VRAM looks like
Image

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed May 30, 2012 9:42 am

There is something broke in the VDP_loadBMPTileData as using a tile index not aligned on 32 result in corrupted transfer...

Change your code to this version and it will work :

Code: Select all

	// get the image width (in pixel) ==> should be 8pix aligned
	u16 w = moon[0];
	// get the image height (in pixel)  ==> should be 8px aligned
	u16 h = moon[1];

	// get the palette at moon[2 to 17]
	VDP_setPalette(PAL1, (u16 *) &moon[2]);

	// load bitmap data at moon[18....] in VRAM
	// w/8 = width in tiles we want to load
	// h/8 = height in tile we want to load
	// w/8 = width in tiles of the bitamp
	// the 3rd arg is needed because you could load only a part of the bitmap if you want but SGDK needs the width as reference
	VDP_loadBMPTileData((u32*) &moon[18], 0, w/8, h/8, w/8);

	// draw the moon at (12,12)
	VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, 0), 12, 12, w/8, h/8);

	while(1)
	{
		VDP_waitVSync();
	}
	return 0;
Another problem is that plan A seems to be filled with '1' so it display grey over the B plan, it's why i changed to A plan in the example.
I think there is severals bugs there, i really need to check that.

Ricky
Interested
Posts: 23
Joined: Tue May 22, 2012 10:09 am

Post by Ricky » Wed May 30, 2012 3:50 pm

Stef wrote:There is something broke in the VDP_loadBMPTileData as using a tile index not aligned on 32 result in corrupted transfer...

Change your code to this version and it will work :

Code: Select all

	// get the image width (in pixel) ==> should be 8pix aligned
	u16 w = moon[0];
	// get the image height (in pixel)  ==> should be 8px aligned
	u16 h = moon[1];

	// get the palette at moon[2 to 17]
	VDP_setPalette(PAL1, (u16 *) &moon[2]);

	// load bitmap data at moon[18....] in VRAM
	// w/8 = width in tiles we want to load
	// h/8 = height in tile we want to load
	// w/8 = width in tiles of the bitamp
	// the 3rd arg is needed because you could load only a part of the bitmap if you want but SGDK needs the width as reference
	VDP_loadBMPTileData((u32*) &moon[18], 0, w/8, h/8, w/8);

	// draw the moon at (12,12)
	VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, 0), 12, 12, w/8, h/8);

	while(1)
	{
		VDP_waitVSync();
	}
	return 0;
Another problem is that plan A seems to be filled with '1' so it display grey over the B plan, it's why i changed to A plan in the example.
I think there is severals bugs there, i really need to check that.
Thanks so much Stef!
Image
Works perfectly.

Now as for that undeclared _spritedef..

I'm using the latest version of SGDK btw :)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Wed May 30, 2012 10:36 pm

I need to update tutorials, the structure is now called SpriteDef.
If you replace all "spritedef_" occurence with "SpriteDef" it should work :)

Ricky
Interested
Posts: 23
Joined: Tue May 22, 2012 10:09 am

Post by Ricky » Thu May 31, 2012 10:31 pm

Got all tutorials working perfectly after help from Stef.

Thanks ;D I'm off to make my first game, See ya!

Post Reply