question about DMA

For anything related to VDP (plane, color, sprite, tiles)

Moderators: BigEvilCorporation, Mask of Destiny

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

question about DMA

Post by zhengyaxin_8bit » Thu Jan 05, 2012 2:39 pm

hi Pal,

when I as use DMA to move data from ROM to VDP in SEGA game system, problems happened when move data out of 128k program address space, but it's ok when i move data within 128k program address space.

;----------------------------------
DMA from rom to vdp ram
example:
org 20000h
mydata (length is 0x8000h)
org 4000h
other program
dma is ok
;;;;;;;;;;;;;;;;;;;;

org 3c000h
mydata length is 0x8000h
org 44000h
other proram
dma is error

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

Post by Chilly Willy » Thu Jan 05, 2012 4:45 pm

It's because the DMA cannot cross a 128K boundary. If you data crosses a boundary, you need to make it not do so, or split the DMA into two operations to avoid this issue.

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Sat Jan 07, 2012 2:48 am

What i can do ,to fixed the dma data within 128k space.

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Sat Jan 07, 2012 3:51 am

There are many program and data together ,I don't know how to put the dma-data to the address I wanted within 128k bound. Please give me a example.

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Sat Jan 07, 2012 5:06 am

Use align directive. If you use C, declare the data external in C program, include it as binary at the end of sega.s. Something like this:

Code: Select all

C:

extern const unsigned char mydata[];

Asm:

_mydata:
 .align 131072
 .incbin "yourdata.bin"

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

Post by Chilly Willy » Sat Jan 07, 2012 5:56 am

".align 131072" for 68000 assembly, and ".align 17" for SH2. The SH2 assembler assumes the argument is the power of two to align to.

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Sun Jan 08, 2012 2:29 am

Shiru wrote:Use align directive. If you use C, declare the data external in C program, include it as binary at the end of sega.s. Something like this:

Code: Select all

C:

extern const unsigned char mydata[];

Asm:

_mydata:
 .align 131072
 .incbin "yourdata.bin"
My data used C language like is:
//--------bg.h-------------------
#ifndef _Background_
#define _Background_
extern u16 BJZ_15_PNT[0x000c];
extern u16 BJZ_15_PAL[0x40];
extern u32 BJZ_15_PGT[0x2920];
extern u16 PTB_13_PNT[0x00c8];
extern u16 PTB_13_PAL[0x40];
extern u32 PTB_13_PGT[0x2258];
#endif
//--------bg.h end---------------
//--------bg.c-------------------
const u16 BJZ_15_PNT[0x000c]={
/*Line 0*/ 0x4492,0x451c,0x451d,0x451e,0x451f,0x4518,
/*Line 1*/ 0x4498,0x4520,0x4521,0x4522,0x4523,0x44c7,
...................................
/*Line 15*/ 0x0001,0x0001,0x4001,......,0x4001,0x4001,
};
const u16 BJZ_15_PAL[0x40]={
/*Color 0*/ 0x027b,0x019d,0x0358.......,0x0610,
...................................
/*Color 3*/ 0x0259,0x0aab,0x0026.......,0x0a00,
};
const u32 BJZ_15_PGT[0x2920]={
/*0000H*/ 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
...................................
/*0523H*/ 0x54999999,0x99999999,0x99999999,0x99999999,0x99999999,0x11111111,0xffffffff,0x11111111,

const u16 PTB_13_PNT[0x0280]={
/*Line 0*/ 0x0001,0x0001,
...................................
/*Line 15*/ 0x0001,0x0001,0x4001,......,0x4001,0x4001,
};
const u16 PTB_13_PAL[0x40]={
/*Color 0*/ 0x0000,0x0235,0x0348.......,0x0fff,
...................................
/*Color 3*/ 0x0000,0x0444,0x0888.......,0x03ff,
};
const u32 PTB_13_PGT[0x1d28]={
/*0000H*/ 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
...................................
/*03a4H*/ 0x98889aff,0xa9889aff,0xa9889aff,0xfa989aff,0xfaa99aff,0xfffaafff,0xffffffff,0xffffffff,
};

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Sun Jan 08, 2012 2:47 am

Do we must use assembly to align data?
How to define multi-data segment?like is?

C:
extern const u16 BJZ_15_PNT[];
extern const u16 BJZ_15_PAL[];
extern const u32 BJZ_15_PGT[];
extern const u16 PTB_13_PNT[];
extern const u16 PTB_13_PAL[];
extern const u32 PTB_13_PGT[];

Asm:
.align 131072
_BJZ_15_PNT:
.incbin "BJZ_15_PNT.bin"
_BJZ_15_PAL
.incbin "BJZ_15_PNT.bin"
_BJZ_15_PGT
.incbin "BJZ_15_PNT.bin"

.align 0x20000
_PTB_13_PNT:
.incbin "BJZ_15_PNT.bin"
_PTB_13_PAL
.incbin "BJZ_15_PNT.bin"
_PTB_13_PGT
.incbin "BJZ_15_PNT.bin"

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Sun Jan 08, 2012 3:07 am

Can you give me a example code to my email ?(zhengyaxin_8bit@yahoo.com.cn)

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Sun Jan 08, 2012 5:45 am

I gave you an example in the post above. I don't know how to explain it in more details, sorry.

Code in your second post looks like a correct one.

There is also some __attribute__((aligned(N)) in GCC that could be used to align C data, but I don't know how to use it exactly and is it work in the Genesis-targeted version.

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

Post by Chilly Willy » Sun Jan 08, 2012 7:01 pm

You align data in C like this

Code: Select all

unsigned char __attribute__((aligned(16))) membuf[48*1024];
I use this quite often in my MD/32X programs just fine.

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Mon Jan 09, 2012 2:32 am

warning: alignment of 'BJZ_15_PGT' is greater than maximum object
file alignment. Using 32768
if I want to setting 131072 that will be creat error.The maximum object is 32768.
But it is very useful to me :)

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Mon Jan 09, 2012 2:33 am

warning: alignment of 'BJZ_15_PGT' is greater than maximum object
file alignment. Using 32768
if I want to setting 131072 that will be creat error.The maximum object is 32768.
But it is very useful to me :)

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Mon Jan 09, 2012 2:56 am

if I change bg.c to bg.s, then after compiler the follow information will be creat

sega.o: In function `HBL':
(.text+0x332): relocation truncated to fit: R_68K_PC16 against symbol `_hblankca
llback' defined in .text section in base.o
sega.o: In function `VBL':
(.text+0x346): relocation truncated to fit: R_68K_PC16 against symbol `_vblankca
llback' defined in .text section in base.o
make: *** [rom.out] Error 1

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

Post by Chilly Willy » Mon Jan 09, 2012 3:25 am

zhengyaxin_8bit wrote:if I change bg.c to bg.s, then after compiler the follow information will be creat

sega.o: In function `HBL':
(.text+0x332): relocation truncated to fit: R_68K_PC16 against symbol `_hblankca
llback' defined in .text section in base.o
sega.o: In function `VBL':
(.text+0x346): relocation truncated to fit: R_68K_PC16 against symbol `_vblankca
llback' defined in .text section in base.o
make: *** [rom.out] Error 1
I think that's that old bsr error - you need to make sure the bsr VBL/HBL in sega.s is changed to jsr VBL/HBL or you get an error from VBL/HBL being too far away to branch to.

Post Reply