question about DMA
Moderators: BigEvilCorporation, Mask of Destiny
-
- Very interested
- Posts: 101
- Joined: Thu Sep 04, 2008 2:57 am
- Location: China
question about DMA
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
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
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
-
- Very interested
- Posts: 101
- Joined: Thu Sep 04, 2008 2:57 am
- Location: China
-
- Very interested
- Posts: 101
- Joined: Thu Sep 04, 2008 2:57 am
- Location: China
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"
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
-
- Very interested
- Posts: 101
- Joined: Thu Sep 04, 2008 2:57 am
- Location: China
My data used C language like is: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"
//--------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,
};
-
- Very interested
- Posts: 101
- Joined: Thu Sep 04, 2008 2:57 am
- Location: China
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"
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"
-
- Very interested
- Posts: 101
- Joined: Thu Sep 04, 2008 2:57 am
- Location: China
Can you give me a example code to my email ?(zhengyaxin_8bit@yahoo.com.cn)
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.
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.
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
You align data in C like this
I use this quite often in my MD/32X programs just fine.
Code: Select all
unsigned char __attribute__((aligned(16))) membuf[48*1024];
-
- Very interested
- Posts: 101
- Joined: Thu Sep 04, 2008 2:57 am
- Location: China
-
- Very interested
- Posts: 101
- Joined: Thu Sep 04, 2008 2:57 am
- Location: China
-
- Very interested
- Posts: 101
- Joined: Thu Sep 04, 2008 2:57 am
- Location: China
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
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
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
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.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