#pypp 0 // Iris: micro-kernel for a capability-based operating system. // source/ball.ccp: Bouncing ball demo. // Copyright 2009 Bas Wijnen // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #include #include static unsigned *framebuffer static int const r = 10 void ball (int x, int y, unsigned colour): for int ty = y - r; ty < y + r; ++ty: if ty < 0 || ty >= 240: continue for int tx = x - r; tx < x + r; ++tx: if tx < 0 || tx >= 320: continue if (x - tx) * (x - tx) + (y - ty) * (y - ty) > r * r: continue framebuffer[ty * 320 + tx] = (colour) Iris::Num start (): Iris::my_parent.init_done () int colour = 0x3f30ff framebuffer = (unsigned *)0x15000 Iris::Display display = Iris::my_parent.get_device (0x10000) int x = r, y = r, dx = 3, dy = 0 Iris::Cap eof = Iris::my_receiver.create_capability (0) while true: display.set_eof_cb (eof) Iris::wait () ball (x, y, 0) x += dx y += dy if y + r >= 240: dy = -dy y = 240 - r if x - r < 0: x = r dx = -dx if x + r >= 320: x = 320 - r dx = -dx if y == 240 - r && dy == 0: dy = -21 ++dy ball (x, y, colour)