diff --git a/part12-wgt/Makefile b/part12-wgt/Makefile index 80b5247..8cf1829 100644 --- a/part12-wgt/Makefile +++ b/part12-wgt/Makefile @@ -20,6 +20,9 @@ bin/wgt2blk.o: bin/wgt2.blk bin/lettersspr.o: bin/letters.spr $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ +bin/breakspr.o: bin/break.spr + $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ + bin/spacespr.o: bin/space.spr $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ @@ -32,8 +35,8 @@ bin/mousespr.o: bin/mouse.spr %.o: %.c $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ -kernel8.img: boot/boot.o $(OFILES) bin/wgt1pal.o bin/wgt1blk.o bin/wgt2blk.o bin/lettersspr.o bin/spacespr.o bin/invaderspr.o bin/mousespr.o - $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot/boot.o $(OFILES) bin/wgt1pal.o bin/wgt1blk.o bin/wgt2blk.o bin/lettersspr.o bin/spacespr.o bin/invaderspr.o bin/mousespr.o -T boot/link.ld -o kernel8.elf +kernel8.img: boot/boot.o $(OFILES) bin/wgt1pal.o bin/wgt1blk.o bin/wgt2blk.o bin/lettersspr.o bin/spacespr.o bin/invaderspr.o bin/mousespr.o bin/breakspr.o + $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot/boot.o $(OFILES) bin/wgt1pal.o bin/wgt1blk.o bin/wgt2blk.o bin/lettersspr.o bin/spacespr.o bin/invaderspr.o bin/mousespr.o bin/breakspr.o -T boot/link.ld -o kernel8.elf $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img clean: diff --git a/part12-wgt/bin/break.spr b/part12-wgt/bin/break.spr new file mode 100644 index 0000000..7b7f815 Binary files /dev/null and b/part12-wgt/bin/break.spr differ diff --git a/part12-wgt/examples/wgt60.c b/part12-wgt/examples/wgt60.c new file mode 100644 index 0000000..49b34c9 --- /dev/null +++ b/part12-wgt/examples/wgt60.c @@ -0,0 +1,284 @@ +#include "wgtspr.h" +#include "include/mem.h" + +// ######## REQUIRED FUNCTIONS ######## + +unsigned long state0 = 1000; +unsigned long state1 = 2000; + +unsigned long rand(void) +{ + unsigned long s1 = state0; + unsigned long s0 = state1; + + state0 = s0; + s1 ^= s1 << 23; + s1 ^= s1 >> 17; + s1 ^= s0; + s1 ^= s0 >> 26; + state1 = s1; + + return state0 + state1; +} + +void wait_msec(unsigned int n) +{ + register unsigned long f, t, r; + + // Get the current counter frequency + asm volatile ("mrs %0, cntfrq_el0" : "=r"(f)); + // Read the current counter + asm volatile ("mrs %0, cntpct_el0" : "=r"(t)); + // Calculate expire value for counter + t+=((f/1000)*n)/1000; + do{asm volatile ("mrs %0, cntpct_el0" : "=r"(r));}while(r 267) /* Is ball bouncing off right wall? */ + { + dobounce (); + lx = 267; + sbx = -sbx; /* Change direction */ + } + if (lx < 49) /* Is ball bouncing off left wall? */ + { + dobounce (); + lx = 49; + sbx = -sbx; /* Change direction */ + } + if (ly < 9) /* Is ball bouncing off top wall? */ + { + dobounce (); + ly = 9; + sby = -sby; /* Change direction */ + } + + lx += sbx; /* Update ball positions */ + ly += sby; + + s[1].x = (float)lx; + s[1].y = (float)ly; + + if (s[1].y > 186) /* Did it get by the user and go off the bottom? */ + { +/* + for (i = 2000; i >= 200; i--) + sound (i); + nosound (); +*/ + lx = 160; // Reset it to the starting position + ly = 100; + } + + if (overlap (0, 1)) /* Hit the ball with paddle? */ + { + // sound (900); + sby = -ysp; /* Change speed and direction based on + part of paddle hit */ + if (s[1].x > s[0].x + 21) + sbx = xsp * 4; + else if (s[1].x > s[0].x + 18) + sbx = xsp * 2; + else if (s[1].x > s[0].x + 12) + sbx = xsp; + else if (s[1].x > s[0].x + 6) + sbx = -xsp; + else if (s[1].x > s[0].x + 3) + sbx = -xsp * 2; + else + sbx = -xsp * 4; + } + + /* Now check edges of ball for brick contact */ + chk1 = wgetpixel (s[1].x + 3, s[1].y - 1) >> 24; /* Upper edge */ + chk2 = wgetpixel (s[1].x + 3, s[1].y + 6) >> 24; /* Lower edge */ + chk3 = wgetpixel (s[1].x - 1, s[1].y + 3) >> 24; /* Left edge */ + chk4 = wgetpixel (s[1].x + 6, s[1].y + 3) >> 24; /* Right edge */ + + if (chk1 > 28) + { + hit (3, -1); + sby = ysp; + } + else if (chk2 > 28) + { + hit (3, 6); + sby = -ysp; + } + if (chk3 > 28) + { + hit (-1, 3); + sbx = -sbx; + lx += 2; + } + else if (chk4 > 28) + { + hit (6, 3); + sbx = -sbx; + lx -= 2; + } + // nosound (); /* Turn off all sound */ + draw_sprites (1); /* Draw the sprites again */ +} + +void hit (short ix, short iy) +{ +short x1, x2; +short y1, y2; + + // sound (600); /* Beep because we hit something */ + wsetcolor (vgapal[0]); + /* Loop through all the bricks to see what we hit */ + for (x = 1; x < 28; x++) + { + x1 = x * 7 + 57; + x2 = x1 + 6; + for (y = 1; y < 10; y++) + { + y1 = y * 5 + 20; + y2 = y1 + 4; + if ((s[1].x + ix >= x1) && (s[1].x + ix <= x2) + && (s[1].y + iy >= y1) && (s[1].y + iy <= y2) && (blk[y][x] != 0)) + { + wsetscreen (spritescreen); + wbar (x1, y1, x2, y2); /* Erase brick */ + wsetscreen (backgroundscreen); + wbar (x1, y1, x2, y2); /* Erase brick */ + wnormscreen (); + /* And update visual screen */ + wcopyscreen (x1, y1, x2, y2, spritescreen, x1, y1, NULL); + blk[y][x] = 0; /* Disable brick in array */ + hits++; + if ((hits % 15) == 0) /* Increase speed after every 15 hits */ + { + xsp += .1; + ysp += .1; + } + } + } + } +} + +void dobounce (void) +{ +/* + sound (200); + nosound (); +*/ +} + +void main() +{ + wgt60(); + while (1); +} diff --git a/part12-wgt/wscreen.c b/part12-wgt/wscreen.c index 02a3b9f..ef5f069 100644 --- a/part12-wgt/wscreen.c +++ b/part12-wgt/wscreen.c @@ -42,7 +42,7 @@ void wcopyscreen (short x, short y, short x2, short y2, block source, short dest if (source == NULL) { - source = abuf; /* Set to visual screen */ + source = fbuf; /* Set to visual screen */ swidth = 320; } else { @@ -77,7 +77,7 @@ void wcopyscreen (short x, short y, short x2, short y2, block source, short dest if (dest == NULL) { - dest = abuf; /* Set to visual screen */ + dest = fbuf; /* Set to visual screen */ dwidth = 320; } else diff --git a/part12-wgt/wsetcol.c b/part12-wgt/wsetcol.c index 69450d3..0b01b40 100644 --- a/part12-wgt/wsetcol.c +++ b/part12-wgt/wsetcol.c @@ -21,7 +21,7 @@ void wsetpalette (unsigned char start, unsigned char finish, color *pal) { for (int i = start; i <= finish; i++) { - vgapal[i] = rgb(pal[i].r, pal[i].g, pal[i].b); + vgapal[i] = (i << 24) + rgb(pal[i].r, pal[i].g, pal[i].b); } }