Page 2 of 4

Sprite and Sound APIs

Posted: Sat Jul 24, 2021 2:51 am
by rje

Okay, now I have to load the accumulator with a parametric value.

Not sure how to do this in C.  I can do constant-string assembly:


asm("LDA $F00");




...but I really really really really doubt I can do this:


char onTheFly[16];

onTheFly = "LDA $BAA";
...
asm( onTheFly );




So I can't set the accumulator or X or Y registers that way.

 

I know the SYS command will load A, X, Y, and Status.  But... that's BASIC.  Does that call a KERNEL routine, perhaps?  Hmmm perhaps.


Sprite and Sound APIs

Posted: Sat Jul 24, 2021 2:53 am
by rje

Oh.  Found it:

 


Function



Call a subroutine passing register values.



Header



6502.h



Declaration



void __fastcall__ _sys (struct regs* r);



Description



The function will call the subroutine at the address specified in the pc member of the passed regs structure. All registers and the CPU flags are set to the values given in the regs structure. On return from the subroutine, the new values of the registers and flags are stored back overwriting the old values.



 




Sprite and Sound APIs

Posted: Sat Jul 24, 2021 3:23 am
by rje

If I use the _sys() call, I can call his ABI directly.  All I need is the registers set correctly (that's the struct) and some of the pseudo-registers in zero page.  I think that's what I'll try.

 

r.pc = 0xfef0;  // sprite_set_image
r.a = 0; // sprite 0
r.x = 32; // width
r.y = 32; // height
setR0( addr );       // a macro for something that sets 0x0002 and 0x0003
eightBitsPerPixel(); // a macro for something like asm("LDA #8"); asm("STA $0006"); 
_sys( r );

Description: This function sets the image of a sprite.

The number of the sprite is given in .A, The bits per pixel (bpp) in r2L, and the width and height in .X and .Y.

T
he pixel data at r0 is interpreted accordingly and converted into the graphics hardware's native format.

 

^ That last bit is interesting.  Does that mean the sprite data is in main RAM and not on VERA?  It should already be in VERA, shouldn't it?  I load the sprite data direct to VERA... I'll assume it's a VERA offset.

 


Sprite and Sound APIs

Posted: Sat Jul 24, 2021 3:55 am
by ZeroByte

You can use C-space variables in asm() calls with cc65.

C identifiers are imported into assembly with a _ prepended to their names.

So you could do this:

char[12] onthefly

...

asm ("lda _onthefly")

This would be like &onthefly - I haven't tried things like asm("lda #<_onthefly") - not sure how sophisticated the asm() command is, but since it's part of the same software suite that is also the assembler, I imagine it's able to decipher that.... I used it in my IRQ handler

asm("jmp (_systemIRQ)"  where in C, systemIRQ holds the address from $314 at boot. I don't know where C put it, and don't care. ?

 

 


Sprite and Sound APIs

Posted: Mon Jul 26, 2021 3:53 am
by Greg King


On 7/23/2021 at 11:23 PM, rje said:




^ That last bit is interesting.  Does that mean the sprite data is in main RAM, and not on VERA?  It should already be in VERA, shouldn't it?  I load the sprite data direct to VERA... I'll assume it's a VERA offset.



Those functions were designed for the mouse sprite.  Its shape data is in the Kernal ROM.  sprite_set_image is used to copy it into VRAM.  sprite_set_position is used to move the mouse pointer during vertical blanking.


Sprite and Sound APIs

Posted: Mon Jul 26, 2021 2:07 pm
by rje


10 hours ago, Greg King said:




Those functions were designed for the mouse sprite.  Its shape data is in the Kernal ROM.  sprite_set_image is used to copy it into VRAM.  sprite_set_position is used to move the mouse pointer during vertical blanking.



Ohhhhhhhh.

OK!  So I will at least want to write a C library for VERA sprite stuff.  And so I can still think about one in assembly too.


Sprite and Sound APIs

Posted: Mon Jul 26, 2021 7:39 pm
by Ed Minchau


On 7/23/2021 at 9:23 PM, rje said:




^ That last bit is interesting.  Does that mean the sprite data is in main RAM and not on VERA?  It should already be in VERA, shouldn't it?  I load the sprite data direct to VERA... I'll assume it's a VERA offset.



 



Yes, the sprite data should already be in VRAM.  The sprite attribute table at 1FC00 will point to the start location of the sprite data in VRAM.

I found @SlithyMatt's sprite tutorial on YouTube very helpful. 


Sprite and Sound APIs

Posted: Tue Jul 27, 2021 12:21 am
by Snickers11001001

Dumb question as you guys are talking sprites. 

Is there an offscreen offset?    What I mean is if I want to have a sprite sort of drive onto the screen from the left side, can I set the sprite to a particular location that's outside the display and sort of scoot it in?   

Sorry for the dumb question. 


Sprite and Sound APIs

Posted: Tue Jul 27, 2021 12:52 am
by Elektron72


20 minutes ago, Snickers11001001 said:




Is there an offscreen offset?    What I mean is if I want to have a sprite sort of drive onto the screen from the left side, can I set the sprite to a particular location that's outside the display and sort of scoot it in?



The VERA will interpret positions beyond the right/bottom edge as two's complement signed numbers, allowing sprites to start beyond the left/top edge of the screen.


Sprite and Sound APIs

Posted: Tue Jul 27, 2021 1:01 am
by Snickers11001001

Thanks!   Well, that's some extra maths I guess I need to work on, LOL. 

ETA:   That also seems to answer another question I had about the need for 10 bits to represent the vertical position given a 480 pixel high screen.   Thanks again!