Page 18 of 57

Posted: Sat Jun 25, 2011 5:54 pm
by Chilly Willy
You don't necessarily need the tiles in different layers, but they need to go in different places in the tile buffer. Overwriting the old tiles WILL result in tearing if it can't be done in the vblank... and it can't. So the tiles need to be double-buffered over everything else. But your palette handling looks okay now.

Thank you

Posted: Sat Jun 25, 2011 6:58 pm
by sega16
Ok I double buffered the tiles and it worked perfectly thank you chilly willy and tmEE.
here is the final code:

Code: Select all

#include "genesis.h"
#include "global.h"
#include "Tubelec.h"
const u8 even = 0;//dma will gltich without this (somehow the program got un-aligned)
#include "road_tiles.h"
#include "road_palletes.h"
void VDP_waitnotVSync()
{
    vu16 *pw;
    u16 vdp_state;

    vdp_state = VDP_VBLANK_FLAG;
    pw = (u16 *) GFX_CTRL_PORT;
    while (!(vdp_state & VDP_VBLANK_FLAG)) vdp_state = *pw;
    while (vdp_state & VDP_VBLANK_FLAG) vdp_state = *pw;

}

void robotnik_3d()
{

    stopPlay_2ADPCM(AUDIO_PCM_CH1);
    startPlay_2ADPCM((const u8 *)Tubelec, sizeof(Tubelec), AUDIO_PCM_CH1,1);
    u8 frame;
    frame=0;
    //right now all it will be doing is moving the road
    VDP_resetScreen();//clear all stuff on the screen
    //now put this in a loop
    //draw the tiles

    while (1)
    {

        if (frame == 4)
        {
            frame = 0;
        }
        //VDP_setPalette(PAL0, (const u16 *)road_palletes+(frame*16));
        //VDP_loadTileData( (const u32 *)road_tiles+(frame*5440), 1, 1120, 1);
        VDP_waitnotVSync();//dma is faster during vblank I think wait for the vblank (i just edited the vysnc code)
        //
        //VDP_doVRamDMA((const u32 *)road_tiles+(frame*5440), 32, 21760);
        switch (frame)// looks slightly better when I put this after dmaing the tiles
        {
            case 0:
            VDP_doCRamDMA((const u32 *)road_palletes, 0,32);
            VDP_doVRamDMA((const u32 *)road_tiles, 32, 21760);
            VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(0,0,0,0,1), 0, 11, 40, 17);
            break;
            case 1:
            VDP_doCRamDMA((const u32 *)road_palletes+8, 32,32);
            VDP_doVRamDMA((const u32 *)road_tiles+5440, 21792, 21760);
            VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(1,0,0,0,681), 0, 11, 40, 17);
            break;
            case 2:
            VDP_doCRamDMA((const u32 *)road_palletes+16, 0,32);
            VDP_doVRamDMA((const u32 *)road_tiles+10880, 32, 21760);
            VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(0,0,0,0,1), 0, 11, 40, 17);
            break;
            case 3:
            VDP_doCRamDMA((const u32 *)road_palletes+24, 32,32);
            VDP_doVRamDMA((const u32 *)road_tiles+16320, 21792, 21760);
            VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(1,0,0,0,681), 0, 11, 40, 17);
            break;
        }
        //#define TILE_ATTR_FULL(pal, pri, flipV, flipH, index)
        //VDP_fillTileMapRectInc(APLAN, 1, 0, 11, 40, 17);
        VDP_waitVSync();

        frame++;
    }
}

Posted: Thu Jul 07, 2011 9:38 pm
by Jae686
How do I install toolchain under linux (ubuntu) ?

Best Regards

Posted: Fri Jul 08, 2011 12:07 am
by Chilly Willy
If you're using linux, I suggest making the toolchain in my thread on the topic. Then copy just the SDK source from this mini devkit and use the linux toolchain to compile it.

Posted: Sat Jul 09, 2011 5:38 pm
by Jae686
Chilly Willy wrote:If you're using linux, I suggest making the toolchain in my thread on the topic. Then copy just the SDK source from this mini devkit and use the linux toolchain to compile it.
Todo so I must edit the makelib.gen and makefile.gen to reflect the changed executable's name (gcc, ar, etc) correct?

Were can I find the tools that are included on the SGDK but not on Willy's toolchain?



SHELL=$(BIN)/sh
AR= $(BIN)/m68k-elf-ar
CC= $(BIN)/m68k-elf-gcc
OBJCPY= $(BIN)/m68k-elf-objcopy
ASMZ80= $(BIN)/sjasm
MACCER= $(BIN)/mac68k
SIZEBND= $(BIN)/m68k-elf-size
BINTOC= $(BIN)/bintoc
BINTOS= $(BIN)/bintos
WAVTORAW= $(BIN)/wavtoraw
PCMTORAW= $(BIN)/pcmtoraw

GENRES= $(BIN)/genres
NM= $(BIN)/m68k-elf-nm
NM2WCH= $(BIN)/nm2wch
RM= $(BIN)/rm

Posted: Sat Jul 09, 2011 7:38 pm
by Chilly Willy
My own makefile that turns the mini devkit files into a lib looks like this

Code: Select all

CC = m68k-elf-gcc
AR = m68k-elf-ar
RANLIB = m68k-elf-ranlib
OBJC = m68k-elf-objcopy
RM = rm -f
ASMZ80 = zasm
BINTOC = bin2c

OPTION= -Dnologo_

libmd.a_OBJS = base.o tools.o vdp.o font.o vdp_bg.o vdp_dma.o \
	vdp_pal.o vdp_spr.o vdp_tile.o bitmap.o bitmapx.o z80_ctrl.o \
	tab_sin.o tab_log2.o tab_pow2.o maths.o maths3D.o ym2612.o \
	psg.o audio.o joy.o timer.o logo_lib.o z80_drv1.o z80_drv2.o \
	z80_mvst.o

INCS = -I./include
FLAGS = $(OPTION) -m68000 -Wall -O1 -c -fomit-frame-pointer $(INCS)
FLAGSZ80 = -vb2

all: z80_drv1.o80 z80_drv1.c z80_drv2.o80 z80_drv2.c md.o $(libmd.a_OBJS) libmd.a

%.a: $(libmd.a_OBJS)
	$(RM) $@
	$(AR) cru $@ $($@_OBJS)
	$(RANLIB) $@

%.o80: %.s80
	$(ASMZ80) $(FLAGSZ80) -o $@ -i $<

%.c: %.o80
	$(BINTOC) $<

%.o: %.c
	$(CC) $(FLAGS) -c $< -o $@

%.o: %.s
	$(CC) $(FLAGS) -c $< -o $@

clean:
	$(RM) -rf *.o *.a *.o80 *.log
	$(RM) -f z80_drv1.c z80_drv1.h z80_drv2.c z80_drv2.h

install: all
	cp include/*.h $(GENDEV)/include
	cp libmd.a $(GENDEV)/lib
	cp md.o $(GENDEV)/lib
That assumes GENDEV and the PATH environment vars set as explained in my toolchain thread.

Done that way, you would link md.o first, then the object files for the program, then the libs (including libmd).

bintoc is made by compiling the bintoc source from the devkit and coying the executable to the toolchain binary directory. Zasm is one of a couple Z80 compilers that work fairly well, the other being sjasmplus.

I currently use zasm 3.0.18... the current is 3.0.20. I need to update or move to sjasmplus sometime... :)

Posted: Sat Jul 09, 2011 8:49 pm
by Jae686
Is your makefile correct on line 12? when running it i get

Code: Select all


jaerder@jaerder-G50V:~/development/MD_sgdk/TMP/sgdk$ make
Makefile:12: *** missing separator.  Stop.

Posted: Sat Jul 09, 2011 9:14 pm
by Chilly Willy
Make sure any leading spaces are changed to a hard tab. That's the problem when posting makefiles in code tags - the tabs often get changed to spaces, and spaces make a makefile fail.

Posted: Sun Jul 24, 2011 4:39 am
by sega16
I was looking into using the vblank for updating the screen and anyways is it posible to set _VBL to goto a c function
what does _vblank_callback do I searched for it in sega.s but that was the only reference were is it jumping to?
_VBL:
movem.l %d0-%d1/%a0-%a1,-(%sp)
jsr _vblank_callback
movem.l (%sp)+,%d0-%d1/%a0-%a1
rte

Posted: Sun Jul 24, 2011 7:51 am
by KanedaFr
you should look at

Code: Select all

void setVBlankCallback(_voidCallback *CB) 
the cube_flat demo uses it, if you want to see how it works

Posted: Sun Jul 24, 2011 3:10 pm
by sega16
thank you so much KanedaFr just what I needed to know!

GLITCH

Posted: Thu Jul 28, 2011 12:14 am
by sega16
I just found a glitch and a fix to VDP_setTileMapRect

while (j--) *pwdata = basetile | *src++;

should be:

while (j--) *pwdata = basetile + *src++;

that fixed the tile map drawing problem were the tiles mess up

Posted: Thu Jul 28, 2011 9:43 am
by Stef
Someone already reported me this as a bug, but that's definitely not.
"basetile" is intented to be a default mask to define defaut tile property (palette, flip, priority...) and not a base tile index. I guess i should rename that parameter to avoid confusion.
*src should contain specific tile property and the complete index number.

Maybe i should redesign this method to add an extra parameter so we have "baseTileValue" and "baseTileIndex" so you can define your fixed properties (palette, flip etc...) and the base tile index.

Posted: Thu Jul 28, 2011 12:10 pm
by Chilly Willy
Stef wrote:Someone already reported me this as a bug, but that's definitely not.
"basetile" is intented to be a default mask to define defaut tile property (palette, flip, priority...) and not a base tile index. I guess i should rename that parameter to avoid confusion.
*src should contain specific tile property and the complete index number.

Maybe i should redesign this method to add an extra parameter so we have "baseTileValue" and "baseTileIndex" so you can define your fixed properties (palette, flip etc...) and the base tile index.
Leave the current function alone and make a new one that takes a separate arguments for flags and tileoffset.

Posted: Thu Jul 28, 2011 2:29 pm
by Stef
Chilly Willy wrote: Leave the current function alone and make a new one that takes a separate arguments for flags and tileoffset.
Finally the good name for these arguments :)
I think i should replace "basetile" by "flags" on the previous method and add a new as you said.