- [Resolved] Calling DrawSprite_1Bit Routine in C
- 11 Jul 2015 08:13:11 am
- Last edited by biergaizi on 11 Jul 2015 11:30:28 am; edited 1 time in total
Hi folks.
After solved the issue of crt0, I have started some programming on the TI-84 CSE. Recently, I'm working on a project that needs to output graphics to the screen. With the help of built-in DrawSprite routines in DoorsCSE, that's an easy job, but I've been stuck for 2 days on making it works together with C.
Here are my testing programs, and the goal is to write a C program that does the same thing of this asm.
Code:
If I run this program, I can see a black line is displayed near the center of the screen before the program exits.
For my understanding, DrawSprite_1Bit takes x-coordinate from de, and y-coordinate from hl, then it read the image data from a piece of continuous memory address, where the first two bytes is a pointer points to the palette, the second two bytes in the width and height, finally follows the pixmap.
So, I have tried to write a equivalent C program to do that,
Code:
But after I run the program, the screen remains white until it quits.
What happened? I'm really depressed . Could someone please points out that the mistake I made?
Update:
It seems the memcpy() trick doesn't work well, but after I changed it to
Code:
The program is still crashing...
Update 2:
Okay, the issue is finally resolved. Yet another issue caused by my dizzy brain...
The problem is at
Code:
In C programming language, the name of the array, is the alias of the pointer to the array. But, things are not like that in asm. (_texture) actually copy the value "a[0] " instead of the address "&a[0]", therefore DrawSprite can not work.
After solved the issue of crt0, I have started some programming on the TI-84 CSE. Recently, I'm working on a project that needs to output graphics to the screen. With the help of built-in DrawSprite routines in DoorsCSE, that's an easy job, but I've been stuck for 2 days on making it works together with C.
Here are my testing programs, and the goal is to write a C program that does the same thing of this asm.
Code:
.nolist
#include "ti84pcse.inc"
#include "dcse8.inc"
.list
.org UserMem
BinaryStart:
.db $EF,$11 ;OpenLib( 2 2
.db "D",$BB,$BF,$BB,$BF,$BB,$C2,$BB,$C3,"CSE",$11,$3F ; 14 16
.db $EF,$12,$3F ;ExecLib 3 19
.db $D5,$3F ;Return 2 21
.db tExtTok,tAsm84CPrgm,$3F ; 3 24 bytes total
HeaderStart:
.dw ASMStart-HeaderStart ;offset to code
.dw 10
.db 3
.db "DoorsCSE",8,0
.dw Header_Author_End-Header_Author_Start
.db 2
Header_Author_Start:
.db "Kerm Martian",0
Header_Author_End:
.dw Header_Desc_End-Header_Desc_Start
.db 0
Header_Desc_Start:
.db "Clipped Sprite Test",0
Header_Desc_End:
.dw 0
.db $ff
ASMStart:
.relocate UserMem
ProgramStart:
push af
push bc
push de
push hl
push ix
push iy
call ClearLCDFull
ld ix,Sprite_1Bit1
ld hl,100
ld de,100
call DrawSprite_1Bit
pop iy
pop ix
pop hl
pop de
pop bc
pop af
ret
Palette_1Bit:
.db $00,$00,$00,$00
Sprite_1Bit:
.dw Palette_1Bit
.db 30,4
.db $00,$00,$00,$00
.db $ff,$ff,$ff,$ff
.db $00,$00,$00,$00
.db $ff,$ff,$ff,$ff
.endrelocate
.end
If I run this program, I can see a black line is displayed near the center of the screen before the program exits.
For my understanding, DrawSprite_1Bit takes x-coordinate from de, and y-coordinate from hl, then it read the image data from a piece of continuous memory address, where the first two bytes is a pointer points to the palette, the second two bytes in the width and height, finally follows the pixmap.
So, I have tried to write a equivalent C program to do that,
Code:
#include <string.h>
#define ClearLCDFull 0x402A
#define DrawSprite_1Bit 0x4036
const static unsigned char palette[4] = {
0x00, 0x00, 0x00, 0x00
};
static unsigned char texture[] = {
// dw
0x00, 0x00,
// db
30, 4,
// db
0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF
};
int main(void)
{
unsigned char *ptr = texture;
// HACK: Now I think 0x00, 0x00 has been replaced to a pointer,
// but the program doesn't work.
memcpy(texture, &ptr, 2);
__asm
call ClearLCDFull
ld ix, (_texture)
ld hl, #100
ld de, #100
call DrawSprite_1Bit
__endasm;
return 0;
}
But after I run the program, the screen remains white until it quits.
What happened? I'm really depressed . Could someone please points out that the mistake I made?
Update:
It seems the memcpy() trick doesn't work well, but after I changed it to
Code:
unsigned int addr = (unsigned int) &palette;
texture[0] = addr & 0xFF;
texture[1] = (addr >> 8) & 0xFF;
The program is still crashing...
Update 2:
Okay, the issue is finally resolved. Yet another issue caused by my dizzy brain...
The problem is at
Code:
ld ix, (_texture)
In C programming language, the name of the array, is the alias of the pointer to the array. But, things are not like that in asm. (_texture) actually copy the value "a[0] " instead of the address "&a[0]", therefore DrawSprite can not work.