added movement to sprites

also, waitmouse is now C function instead of inline assembly
This commit is contained in:
Wei-ju Wu 2016-09-26 16:25:39 -07:00
parent cb9243504c
commit 9c216ac95e
3 changed files with 43 additions and 4 deletions

View File

@ -1,3 +1,4 @@
/* C version of How To Code 7 http://aminet.net/package/docs/misc/howtocode7 */
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <exec/execbase.h>
@ -82,3 +83,11 @@ void reset_display(void)
custom.cop1lc = (ULONG) ((struct GfxBase *) GfxBase)->copinit;
RethinkDisplay();
}
#define PRA_FIR0_BIT (1 << 6)
void waitmouse(void)
{
volatile UBYTE *ciaa_pra = (volatile UBYTE *) 0xbfe001;
while ((*ciaa_pra & PRA_FIR0_BIT) != 0) ;
}

View File

@ -3,6 +3,11 @@
#define __COMMON_DEFS_H__
// Custom Chip Registers
#define BLTDDAT 0x000
#define DMACONR 0x002
#define VPOSR 0x004
#define VHPOSR 0x006
#define DMACON 0x096
#define BPL1PTH 0x0e0
#define BPL1PTL 0x0e2
@ -65,8 +70,6 @@
extern BOOL init_display(void);
extern void reset_display(void);
// VBCC Inline assembly
void waitmouse(void) = "waitmouse:\n\tbtst\t#6,$bfe001\n\tbne\twaitmouse";
extern void waitmouse(void);
#endif /* __COMMON_DEFS_H__ */

View File

@ -49,6 +49,11 @@ static UWORD __chip sprite_data[] = {
0x0000, 0x0000
};
volatile UBYTE *ciaa_pra = (volatile UBYTE *) 0xbfe001;
volatile UBYTE *custom_vhposr= (volatile UBYTE *) 0xdff006;
#define PRA_FIR0_BIT (1 << 6)
#define DELAY 1
int main(int argc, char **argv)
{
struct Task *current_task = FindTask(NULL);
@ -89,7 +94,29 @@ int main(int argc, char **argv)
custom.dmacon = 0x83a0; // Bitplane + Copper + Sprite DMA activate
custom.copjmp1 = 1;
waitmouse();
// wait for mouse button
UBYTE hstart = 0x60;
UBYTE vstart = 0x6d;
UBYTE vstop = 0x72;
int incx = 1, minx = 0x60, maxx = 0x90;
int incy = 1, miny = 0x6d, maxy = 0x90;
int delay = DELAY;
while ((*ciaa_pra & PRA_FIR0_BIT) != 0) {
// PAL vblank test
while (*custom_vhposr != 0x00) ;
delay--;
if (delay == 0) {
delay = DELAY;
hstart += incx;
vstart += incy;
if (hstart >= maxx || hstart <= minx) incx = -incx;
if (vstart >= maxy || vstart <= miny) incy = -incy;
}
vstop = vstart + 5;
sprite_data[0] = (vstart << 8) | hstart;
sprite_data[1] = vstop << 8;
}
reset_display();
return 0;