// // Kiwi Scientific Acceleration // FramestoreDriver // // (C) 2009 DJ Greaves - University of Cambridge, Computer Laboratory // using System; using KiwiSystem; static class FstoreLocalMirror { const int width = 512; const int height = 512; static byte [] MyMirror = new Byte [width*height]; public static int sendCmd(uint arg) { int rc_ = KiwiFormGraphics.sendCmd(arg); return rc_; } public static byte setget_pixel(ushort xx, ushort yy, bool readf, byte col) { Kiwi.Pause(); int p = xx + 512 * yy; if (readf) { return (byte)(255 - MyMirror[p]); // Complement in mirror RAM so resets to 'white' } else { KiwiFormGraphics.setget_pixel(xx, yy, readf, col); MyMirror[p] = (byte)(255 - col); return col; } Kiwi.Pause(); } } public class FramestoreDriver { public const int pix_width = 512; public const int pix_height = 512; public static void sendCmd(uint arg) { int rc_ = FstoreLocalMirror.sendCmd(arg); } public static void DrawSquare(uint x0, uint y0, uint ww, byte col = 130) { x0 |= 1; Console.WriteLine("DrawSquare Top {0},{1} dim={2}", x0, y0, ww); for (uint p=0; p<ww; p++) { Kiwi.Pause(); Console.WriteLine(" DrawSquare bz {0} of {1}", p, ww); FstoreLocalMirror.setget_pixel((ushort)(x0+p), (ushort)(y0), false, col); // horiz top FstoreLocalMirror.setget_pixel((ushort)(x0+p), (ushort)(y0+ww), false, col); // horiz bot FstoreLocalMirror.setget_pixel((ushort)(x0), (ushort)(y0+p), false, col); // vert left FstoreLocalMirror.setget_pixel((ushort)(x0+ww), (ushort)(y0+p), false, col); // vert right } } public static void DrawBlock(uint x0, uint y0, uint ww, uint hh, byte col = 130) // Shaded rectangle. { Console.WriteLine("DrawBlock Top {0},{1} dim={2}", x0, y0, ww); for (uint p=0; p<ww; p++) for (uint q=0; q<hh; q++) { Kiwi.Pause(); FstoreLocalMirror.setget_pixel((ushort)(x0+p), (ushort)(y0+q), false, col); // Pixel Blit (one pixel is always a blit!) } } public static void DrawSqBlock(uint x0, uint y0, uint ww, byte col = 130) // Shaded square. { Console.WriteLine("DrawSqBlock Top {0},{1} dim={2}", x0, y0, ww); DrawBlock(x0, y0, ww, ww, col); } static int undraw_no; static byte [] pixels_under_cursor = new byte [100]; static ushort cursor_x, cursor_y; static void cursor_pixel(uint xx, uint yy, bool savef, bool undrawf, byte col) { Kiwi.Pause(); if (savef) { byte old_pixel = FstoreLocalMirror.setget_pixel((ushort)xx, (ushort)yy, true, (byte)col); // Read old pixels from framestore. pixels_under_cursor[undraw_no++] = old_pixel; } else if (undrawf) { byte old = pixels_under_cursor[undraw_no++]; FstoreLocalMirror.setget_pixel((ushort)xx, (ushort)yy, false, old); } else KiwiFormGraphics.setget_pixel((ushort)xx, (ushort)yy, false, (byte)col); } static void draw_crosshair_cursor(ushort x0, ushort y0, byte col, bool savef, bool undrawf) { const int cursor_size = 7; undraw_no = 0; for (uint p=0; p<cursor_size; p++) { Kiwi.Pause(); Console.WriteLine(" bz {0}", p); cursor_pixel((ushort)(x0+p), (ushort)(y0), savef, undrawf, col); cursor_pixel((ushort)(x0-p), (ushort)(y0), savef, undrawf, col); cursor_pixel((ushort)(x0), (ushort)(y0+p), savef, undrawf, col); cursor_pixel((ushort)(x0), (ushort)(y0-p), savef, undrawf, col); } } public static void framestore_draw_crosshair_cursor(ushort x0, ushort y0, uint col) { if (x0 != cursor_x || y0 != cursor_y) // If moved, undraw old and save pixels under new site. { draw_crosshair_cursor(cursor_x, cursor_y, (byte)0, /*savef*/false, /*undrawf*/true); draw_crosshair_cursor(x0, y0, 0, /*savef*/true, /*undrawf*/false); cursor_x = x0; cursor_y = y0; draw_crosshair_cursor(x0, y0, (byte)col, /*savef*/false, /*undrawf*/false); } } public static void DrawTestDiagonal() // A simple test { for (uint xx=44; xx<44+20; xx++) { uint yy = xx + 63; FstoreLocalMirror.setget_pixel((ushort)(xx), (ushort)(yy), false, (byte)((xx+yy))); Kiwi.Pause(); } } } // // eof