Sprite and Sound APIs

Chat about anything CX16 related that doesn't fit elsewhere
rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Sprite and Sound APIs

Post 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.

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Sprite and Sound APIs

Post 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.



 



rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Sprite and Sound APIs

Post 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.

 

ZeroByte
Posts: 714
Joined: Wed Feb 10, 2021 2:40 pm

Sprite and Sound APIs

Post 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. ?

 

 

Greg King
Posts: 162
Joined: Wed Jul 08, 2020 1:14 pm

Sprite and Sound APIs

Post 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.

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Sprite and Sound APIs

Post 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.

Ed Minchau
Posts: 503
Joined: Sat Jul 11, 2020 3:30 pm

Sprite and Sound APIs

Post 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. 

Snickers11001001
Posts: 140
Joined: Wed Jan 20, 2021 6:43 pm

Sprite and Sound APIs

Post 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. 

Elektron72
Posts: 137
Joined: Tue Jun 30, 2020 3:47 pm

Sprite and Sound APIs

Post 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.

Snickers11001001
Posts: 140
Joined: Wed Jan 20, 2021 6:43 pm

Sprite and Sound APIs

Post 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! 

 

Post Reply