Root/
| 1 | #pypp 0 |
| 2 | // Iris: micro-kernel for a capability-based operating system. |
| 3 | // source/ball.ccp: Bouncing ball demo. |
| 4 | // Copyright 2009 Bas Wijnen <wijnen@debian.org> |
| 5 | // |
| 6 | // This program is free software: you can redistribute it and/or modify |
| 7 | // it under the terms of the GNU General Public License as published by |
| 8 | // the Free Software Foundation, either version 3 of the License, or |
| 9 | // (at your option) any later version. |
| 10 | // |
| 11 | // This program is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License for more details. |
| 15 | // |
| 16 | // You should have received a copy of the GNU General Public License |
| 17 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | |
| 19 | #include <iris.hh> |
| 20 | #include <devices.hh> |
| 21 | |
| 22 | static unsigned *framebuffer |
| 23 | static int const r = 10 |
| 24 | |
| 25 | void ball (int x, int y, unsigned colour): |
| 26 | for int ty = y - r; ty < y + r; ++ty: |
| 27 | if ty < 0 || ty >= 240: |
| 28 | continue |
| 29 | for int tx = x - r; tx < x + r; ++tx: |
| 30 | if tx < 0 || tx >= 320: |
| 31 | continue |
| 32 | if (x - tx) * (x - tx) + (y - ty) * (y - ty) > r * r: |
| 33 | continue |
| 34 | framebuffer[ty * 320 + tx] = (colour) |
| 35 | |
| 36 | Iris::Num start (): |
| 37 | Iris::my_parent.init_done () |
| 38 | int colour = 0x3f30ff |
| 39 | framebuffer = (unsigned *)0x15000 |
| 40 | Iris::Display display = Iris::my_parent.get_capability <Iris::Display> () |
| 41 | Iris::Caps fb = display.map_fb ((unsigned)framebuffer) |
| 42 | int x = r, y = r, dx = 3, dy = 0 |
| 43 | Iris::Cap eof = Iris::my_receiver.create_capability (0) |
| 44 | while true: |
| 45 | display.set_eof_cb (eof) |
| 46 | Iris::wait () |
| 47 | ball (x, y, 0) |
| 48 | x += dx |
| 49 | y += dy |
| 50 | if y + r >= 240: |
| 51 | dy = -dy |
| 52 | y = 240 - r |
| 53 | if x - r < 0: |
| 54 | x = r |
| 55 | dx = -dx |
| 56 | if x + r >= 320: |
| 57 | x = 320 - r |
| 58 | dx = -dx |
| 59 | if y == 240 - r && dy == 0: |
| 60 | dy = -21 |
| 61 | ++dy |
| 62 | ball (x, y, colour) |
| 63 |
Branches:
master
