1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-07-01 03:11:05 +03:00
iris/source/ball.ccp

63 lines
1.8 KiB
Plaintext
Raw Normal View History

2010-01-24 22:34:24 +02:00
#pypp 0
2010-02-06 00:15:58 +02:00
// 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/>.
2010-01-24 22:34:24 +02:00
#include <iris.hh>
#include <devices.hh>
static unsigned *framebuffer
static int const r = 10
2010-02-18 18:35:37 +02:00
void ball (int x, int y, unsigned colour):
2010-01-24 22:34:24 +02:00
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
2010-02-18 18:35:37 +02:00
framebuffer[ty * 320 + tx] = (colour)
2010-01-24 22:34:24 +02:00
Iris::Num start ():
Iris::my_parent.init_done ()
2010-02-18 18:35:37 +02:00
int colour = 0x3f30ff
2010-01-24 22:34:24 +02:00
framebuffer = (unsigned *)0x15000
Iris::Display display = Iris::my_parent.get_capability <Iris::Display> ()
Iris::Caps fb = display.map_fb ((unsigned)framebuffer)
2010-01-24 22:34:24 +02:00
int x = r, y = r, dx = 3, dy = 0
Iris::Cap eof = Iris::my_receiver.create_capability (0)
2010-01-24 22:34:24 +02:00
while true:
display.set_eof_cb (eof)
Iris::wait ()
2010-02-18 18:35:37 +02:00
ball (x, y, 0)
2010-01-24 22:34:24 +02:00
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
2010-02-18 18:35:37 +02:00
ball (x, y, colour)