1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-06-28 23:15:26 +03:00
iris/source/ball.ccp
2010-05-10 01:07:17 +02:00

63 lines
1.8 KiB
COBOL

#pypp 0
// Iris: micro-kernel for a capability-based operating system.
// source/ball.ccp: Bouncing ball demo.
// Copyright 2009 Bas Wijnen <wijnen@debian.org>
//
// 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 <http://www.gnu.org/licenses/>.
#include <iris.hh>
#include <devices.hh>
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_capability <Iris::Display> ()
Iris::Caps fb = display.map_fb ((unsigned)framebuffer)
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)