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:

.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 Surprised. 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.
I'm glad you resolved this! I was composing a response warning you to not use indirection there (ie, ld ix,_texture instead of ld ix,(_texture)) when I saw your edit. I'd love to see more about this project as it progresses, and I hope you'll consider using this thread for general ASM-to-C questions for the TI-84+CSE. This is especially relevant considering how much easier C for the TI-84+CE will be.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement