From dbc2c6139b984c5d331e33fa6455f03a01638878 Mon Sep 17 00:00:00 2001 From: Adam Greenwood-Byrne Date: Wed, 12 Aug 2020 14:58:20 +0100 Subject: [PATCH] Controlling Breakout using the MacBook Pro trackpad over Bluetooth --- part8-breakout-ble/fb.c | 28 +++++++++ part8-breakout-ble/fb.h | 1 + part8-breakout-ble/kernel.c | 112 ++++++++++++++++-------------------- 3 files changed, 80 insertions(+), 61 deletions(-) diff --git a/part8-breakout-ble/fb.c b/part8-breakout-ble/fb.c index ff52a43..e87f82c 100644 --- a/part8-breakout-ble/fb.c +++ b/part8-breakout-ble/fb.c @@ -199,6 +199,34 @@ void moveRect(int oldx, int oldy, int width, int height, int shiftx, int shifty, } } +void moveRectAbs(int oldx, int oldy, int width, int height, int newx, int newy, unsigned char attr) +{ + unsigned int xcount = 0, ycount = 0; + unsigned int bitmap[width][height]; // This is very unsafe if it's too big for the stack... + unsigned int offs; + + // Save the bitmap + while (xcount < width) { + while (ycount < height) { + offs = ((oldy + ycount) * pitch) + ((oldx + xcount) * 4); + + bitmap[xcount][ycount] = *((unsigned int*)(fb + offs)); + ycount++; + } + ycount=0; + xcount++; + } + // Wipe it out with background colour + drawRect(oldx, oldy, oldx + width, oldy + width, attr, 1); + // Draw it again + for (int i=newx;i> 4; - - h1 = bt_waitReadByte(); - h2 = bt_waitReadByte(); - - unsigned int length = h1 | (h2 << 8); - unsigned char data[length]; - - for (int i=0;iy = object->y + yoff; } +void moveObjectAbs(struct Object *object, int x, int y) +{ + moveRectAbs(object->x, object->y, object->width, object->height, x, y, 0x00); + object->x = x; + object->y = y; +} + struct Object *detectCollision(struct Object *with, int xoff, int yoff) { for (int i=0; i> 4; + + h1 = bt_waitReadByte(); + h2 = bt_waitReadByte(); + + unsigned int length = h1 | (h2 << 8); + unsigned char data[length]; + + for (int i=0;iy); + } + uart_writeText("\n"); + } + } + } +} + void main() { struct Object *foundObject; @@ -405,13 +402,6 @@ void main() while (lives > 0 && bricks > 0) { acl_poll(); - // Get any waiting input and flush the buffer - if (dir != 1) { - if (dir == 2) if (paddle->x + paddle->width + (paddle->width / 2) <= WIDTH-MARGIN) moveObject(paddle, paddle->width / 2, 0); - if (dir == 0) if (paddle->x >= MARGIN+(paddle->width / 2)) moveObject(paddle, -(paddle->width / 2), 0); - } - uart_loadOutputFifo(); - // Are we going to hit anything? foundObject = detectCollision(ball, velocity_x, velocity_y); @@ -429,7 +419,7 @@ void main() } } - wait_msec(4000); // Wait a little... + wait_msec(0x2000); moveObject(ball, velocity_x, velocity_y); // Check we're in the game arena still