From 250fca0493984b8bf953e63ae14e355e0f3bcbb5 Mon Sep 17 00:00:00 2001 From: Adam Greenwood-Byrne Date: Sun, 21 Mar 2021 00:09:56 +0000 Subject: [PATCH] Added examples/wgt60.c - a new Breakout... still needs mouse input to be implemented though --- part12-wgt/Makefile | 7 +- part12-wgt/bin/break.spr | Bin 0 -> 1424 bytes part12-wgt/examples/wgt60.c | 284 ++++++++++++++++++++++++++++++++++++ part12-wgt/wscreen.c | 4 +- part12-wgt/wsetcol.c | 2 +- 5 files changed, 292 insertions(+), 5 deletions(-) create mode 100644 part12-wgt/bin/break.spr create mode 100644 part12-wgt/examples/wgt60.c 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 0000000000000000000000000000000000000000..7b7f815c1a04852d0ecd3acb598bac3d6df8463d GIT binary patch literal 1424 zcmeH`OON7K5QRUwc{I2UG|l^I48~yI57Tbi_K~s}MH4BC#BZ3zNLfTt{$u`DE@V5s z&L&4!rIPC2x~Hm6WpJ*4{Q3Q_Z_bzRzkhQ8NpT!sE|(~Z!Z17@kNf?8v)Qaxs~`w` z-}gMvbzR4ChQndM-|uuftyZhiXw+)8YPDJ}mo3XG7K?>KA)C#bgeD_#$|WUAIj5Xb z4k^2ob;>ejk>DqI36q3z!Z4wq&`oG3G-K*9wU|nb9b?55V+t{ku}P^IT~LJ1=!o`c zi`FPWb2LL!G)5ydKt0q(O;krUR6#bfP!Z)(78#z)IzfX)lX(lj&8&mhW!huX#~m;p z;*1zM495&y`V)Fnx*nYwZJ*Yh=7L5*eaY*J+M1UQ)h(4By3lah8u9mptzUq9@*poJ)ijr)Q2fhcf#LyDHlkHZ|6- ztm-Tq1Wgt#=572Avo2nbX`jgecgT2z<1iXCbQw(OPw9DdXLNkpb6N|U0gWZ~6|ZY* z8(y|lcU1P257Eo{Vc)ea5J^xLHE;+D20k%>14`JJu zk^B!}naC%wKmR9VSQs9ql1<6%kzLAW^0uAN=kIR}&4LN{2kzAKL&u%Y7D0Hki)DE8 rm#feeWDx#)G5Sb<`ttMjZogh{{?}iwcl+!0w>z%4P5mGLbqD?d3Y2?o literal 0 HcmV?d00001 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); } }