//////////////////////////////////////////////////////////////////////////////// // // Microsoft Research Singularity // // Copyright (c) Microsoft Corporation. All rights reserved. // // Note: // using System; using System.Text; using System.GC; using System.Runtime.Remoting; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Threading; using System.Collections; using System.Diagnostics; using Microsoft.Singularity; using Microsoft.Singularity.Directory; using Microsoft.Singularity.V1.Services; using Microsoft.Singularity.Io; using Microsoft.Singularity.Channels; using Keyboard = Microsoft.Singularity.Io.Keyboard; namespace Microsoft.Singularity.Applications { public class SlideShow { public static KeyboardDeviceContract.Imp:Ready OpenKeyboard(string! devName) { KeyboardDeviceContract.Exp! exp; KeyboardDeviceContract.Imp! imp; KeyboardDeviceContract.NewChannel(out imp, out exp); DirectoryServiceContract.Imp ns = DirectoryService.NewClientEndpoint(); ErrorCode errorOut; if (SdsUtils.Bind(devName, ns, exp, out errorOut)) { switch receive { case imp.Success(): break; case imp.ContractNotSupported(): throw new Exception("Contract not supported"); case imp.ChannelClosed(): throw new Exception("Didn't imp.RecvActConnect"); } delete ns; return imp; } if (errorOut == ErrorCode.ChannelClosed) { // REVIEW: Why is this a special case? throw new Exception("Encountered a ChannelClosed while opening Keyboard"); } DebugStub.WriteLine( "OpenKeyboard lookup of {0} failed ({1})\n", __arglist(devName, SdsUtils.ErrorCodeToString(errorOut)) ); delete imp; delete ns; return null; } public static VideoDeviceContract.Imp:Ready OpenVideo(string! devName) { VideoDeviceContract.Exp! exp; VideoDeviceContract.Imp! imp; VideoDeviceContract.NewChannel(out imp, out exp); DirectoryServiceContract.Imp ns = DirectoryService.NewClientEndpoint(); ErrorCode errorCode; if (SdsUtils.Bind(devName, ns, exp, out errorCode)) { switch receive { case imp.Success(): break; case imp.ContractNotSupported(): throw new Exception("Contract not supported"); case imp.ChannelClosed(): throw new Exception("Didn't imp.RecvActConnect"); } delete ns; return imp; } DebugStub.WriteLine( "OpenVideo lookup of {0} failed : {1}\n", __arglist(devName, SdsUtils.ErrorCodeToString(errorCode)) ); delete imp; delete ns; return null; } public static int Main(string[] args) { VideoDeviceContract.Imp video = OpenVideo("/dev/video"); Console.WriteLine("Singularity Slide Show Viewer (PID={0})", ProcessService.GetCurrentProcessId()); DebugStub.WriteLine("Singularity Slide Show Viewer (PID={0})", __arglist(ProcessService.GetCurrentProcessId())); if (video == null) { Console.WriteLine("Can only display slides on a graphic display."); return 1; } if (Slides.Content == null || Slides.Content.Length == 0) { Console.WriteLine("No slides to display."); delete video; return 1; } KeyboardDeviceContract.Imp keyboard = OpenKeyboard("/dev/keyboard"); if (keyboard == null) { // TODO: show keyboardless slides with timer? delete video; return 1; } int slide = 0; byte[] currentSlide = (!)Slides.Content[slide]; byte[]! in ExHeap current = new[ExHeap] byte [currentSlide.Length]; Bitter.FromByteArray(current, 0, currentSlide.Length, currentSlide, 0); video.SendFill(0, 0, 1023, 767, 0); video.RecvAckFill(); video.SendBitBltBmp(32, 16, current); video.RecvAckBitBltBmp(out current); try { for (;;) { int x; int y; bool go_back = false; bool go_fore = false; bool go_home = false; bool go_end = false; uint key = 0; keyboard.SendGetKey(); switch receive { case keyboard.AckKey(ikey): key = ikey; break; case keyboard.NakKey(): break; case keyboard.ChannelClosed(): throw new Exception("Didn't get reply from Keyboard"); } if (key == 0) { Console.WriteLine("GetKey failed, try typing `start slides'."); DebugStub.WriteLine("GetKey failed."); Tracing.Log(Tracing.Warning, "GetKey failed."); break; } if ((key & (uint)Keyboard.Qualifiers.KEY_DOWN) == 0) { continue; } if ((key & (uint)Keyboard.Qualifiers.KEY_MOUSE) == 0) { char c = (char)(key & (uint)Keyboard.Qualifiers.KEY_BASE_CODE); switch (c) { case (char)Keyboard.Keys.ESCAPE: delete video; delete keyboard; delete current; return 0; case (char)Keyboard.Keys.HOME: go_home = true; break; case (char)Keyboard.Keys.UP_ARROW: case (char)Keyboard.Keys.LEFT_ARROW: case (char)Keyboard.Keys.PAGE_UP: case '\b': go_back = true; break; case (char)Keyboard.Keys.DOWN_ARROW: case (char)Keyboard.Keys.RIGHT_ARROW: case (char)Keyboard.Keys.PAGE_DOWN: case '\n': case ' ': go_fore = true; break; case (char)Keyboard.Keys.END: go_end = true; break; default: continue; } } else { if ((key & (uint)Keyboard.Qualifiers.MOUSE_BUTTON_1) != 0) { go_fore = true; } else if ((key & (uint)Keyboard.Qualifiers.MOUSE_BUTTON_0) != 0) { go_back = true; } else { continue; } } if (go_home) { slide = 0; currentSlide = (!)Slides.Content[slide]; } else if (go_fore) { ++slide; if (slide >= Slides.Content.Length) { slide = Slides.Content.Length; currentSlide = (!)EndOfShow.Content[0]; } else { currentSlide = (!)Slides.Content[slide]; } } else if (go_back) { if (--slide < 0) { slide = 0; } currentSlide = (!)Slides.Content[slide]; } else if (go_end) { slide = Slides.Content.Length; currentSlide = (!)EndOfShow.Content[0]; } if (current.Length < currentSlide.Length) { delete current; current = new[ExHeap] byte [currentSlide.Length]; } Bitter.FromByteArray(current, 0, currentSlide.Length, currentSlide, 0); video.SendFill(0, 0, 1023, 767, 0); video.RecvAckFill(); video.SendBitBltBmp(32, 16, current); video.RecvAckBitBltBmp(out current); } } catch (Exception e) { DebugStub.WriteLine("Caught exception: {0}", __arglist(e)); } delete keyboard; delete video; delete current; return 0; } } public class EndOfShow { public static readonly byte[][]! Content = { new byte[] { 0x42,0x4d,0x0e,0x10,0x00,0x00,0x00,0x00, 0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00, 0x00,0x00,0x67,0x00,0x00,0x00,0x0d,0x00, 0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00, 0x00,0xff,0xd8,0x0f,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x98,0xff, 0x00,0x00,0x00,0x98,0xff,0x00,0x00,0x00, 0xfe,0xff,0x00,0x00,0x00,0xfa,0xff,0xff, 0xff,0xff,0xfe,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfd,0xff,0x00,0x00, 0x00,0x03,0x00,0xff,0xff,0xff,0xfd,0xff, 0x00,0x00,0x00,0xfc,0xff,0xff,0xff,0xff, 0xfa,0xff,0x00,0x00,0x00,0xfd,0xff,0xff, 0xff,0xff,0xfd,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfa,0xff,0x00,0x00, 0x00,0xfd,0xff,0xff,0xff,0xff,0xfd,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfe,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xfd,0xff,0x00,0x00,0x00,0xfc, 0xff,0xff,0xff,0xff,0xfd,0xff,0x00,0x00, 0x00,0xfd,0xff,0xff,0xff,0xff,0xf9,0xff, 0x00,0x00,0x00,0xfd,0xff,0xff,0xff,0xff, 0xfd,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xfd,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfd,0xff,0x00,0x00, 0x00,0xfd,0xff,0xff,0xff,0xff,0xfc,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfd,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xfd,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfd,0xff,0x00,0x00, 0x00,0xfe,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xf9,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfd,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfe, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfd,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfb,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfd,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfe, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfb,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfd,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfe,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfe, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfe,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfd,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfe,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfd, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfb,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfd,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfe,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfd, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfe,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfd,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfd,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfd, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xf9,0xff,0x00,0x00,0x00,0xfe,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xf9,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xfd,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfe,0xff,0x00,0x00, 0x00,0x03,0x00,0xff,0xff,0xff,0xfd,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfb,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xfd,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfe,0xff,0x00,0x00, 0x00,0x03,0x00,0xff,0xff,0xff,0xf7,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfe,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xfe,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfe,0xff,0x00,0x00, 0x00,0x03,0x00,0xff,0xff,0xff,0xfd,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfe,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xf3,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfe,0xff,0x00,0x00, 0x00,0x03,0x00,0xff,0xff,0xff,0xfd,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfe,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xfd,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfe,0xff,0x00,0x00, 0x00,0x15,0x00,0xff,0xff,0xff,0x00,0x00, 0x00,0xff,0xff,0xff,0x00,0x00,0x00,0xff, 0xff,0xff,0x00,0x00,0x00,0xff,0xff,0xff, 0xfa,0xff,0x00,0x00,0x00,0xfe,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xf9, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfd,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfe,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfd,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfb, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfd,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfe,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfa,0xff,0x00, 0x00,0x00,0xfd,0xff,0xff,0xff,0xff,0xfd, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfe,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfe,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfd,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfe, 0xff,0x00,0x00,0x00,0xfb,0xff,0xff,0xff, 0xff,0xfa,0xff,0x00,0x00,0x00,0xfd,0xff, 0xff,0xff,0xff,0xfd,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfd,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfe, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfd,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfe,0xff,0x00,0x00,0x00, 0x15,0x00,0xff,0xff,0xff,0x00,0x00,0x00, 0xff,0xff,0xff,0x00,0x00,0x00,0xff,0xff, 0xff,0x00,0x00,0x00,0xff,0xff,0xff,0xfa, 0xff,0x00,0x00,0x00,0xfe,0xff,0x00,0x00, 0x00,0xfa,0xff,0xff,0xff,0xff,0xfe,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfd,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xfe,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfd,0xff,0x00,0x00, 0x00,0x03,0x00,0xff,0xff,0xff,0xfb,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfd,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xfe,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfb,0xff,0x00,0x00, 0x00,0x03,0x00,0xff,0xff,0xff,0xfa,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfe,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xfe,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfd,0xff,0x00,0x00, 0x00,0x03,0x00,0xff,0xff,0xff,0xfe,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfd,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xfb,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfa,0xff,0x00,0x00, 0x00,0x03,0x00,0xff,0xff,0xff,0xfd,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfe,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xfd,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfe,0xff,0x00,0x00, 0x00,0x15,0x00,0xff,0xff,0xff,0x00,0x00, 0x00,0xff,0xff,0xff,0x00,0x00,0x00,0xff, 0xff,0xff,0x00,0x00,0x00,0xff,0xff,0xff, 0xfa,0xff,0x00,0x00,0x00,0xfe,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xf9, 0xff,0x00,0x00,0x00,0xfe,0xff,0xff,0xff, 0xff,0xfe,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfe,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfe,0xff,0x00, 0x00,0x00,0xfe,0xff,0xff,0xff,0xff,0xfb, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfd,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfe,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfb,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfd, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfe,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfe,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfe,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfe, 0xff,0x00,0x00,0x00,0xfe,0xff,0xff,0xff, 0xff,0xfe,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfd,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfb,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfd, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfe,0xff,0x00,0x00,0x00,0xfe,0xff, 0xff,0xff,0xff,0xfe,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xfe,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xfd, 0xff,0x00,0x00,0x00,0x09,0x00,0xff,0xff, 0xff,0x00,0x00,0x00,0xff,0xff,0xff,0xfd, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xfd,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xfb,0xff,0x00,0x00,0x00, 0xfe,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xf9,0xff,0x00,0x00,0x00,0x06, 0x00,0xff,0xff,0xff,0x00,0x00,0x00,0xfe, 0xff,0xff,0xff,0xff,0xfc,0xff,0x00,0x00, 0x00,0xfe,0xff,0xff,0xff,0xff,0x06,0x00, 0x00,0x00,0x00,0xff,0xff,0xff,0xfa,0xff, 0x00,0x00,0x00,0xfd,0xff,0xff,0xff,0xff, 0xfe,0xff,0x00,0x00,0x00,0xfd,0xff,0xff, 0xff,0xff,0xfb,0xff,0x00,0x00,0x00,0xfd, 0xff,0xff,0xff,0xff,0xfd,0xff,0x00,0x00, 0x00,0x03,0x00,0xff,0xff,0xff,0xfe,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfd,0xff,0x00,0x00,0x00,0xfe,0xff,0xff, 0xff,0xff,0x06,0x00,0x00,0x00,0x00,0xff, 0xff,0xff,0xfd,0xff,0x00,0x00,0x00,0xfd, 0xff,0xff,0xff,0xff,0xf9,0xff,0x00,0x00, 0x00,0xfd,0xff,0xff,0xff,0xff,0xfd,0xff, 0x00,0x00,0x00,0x06,0x00,0xff,0xff,0xff, 0x00,0x00,0x00,0xfe,0xff,0xff,0xff,0xff, 0xfc,0xff,0x00,0x00,0x00,0xfd,0xff,0xff, 0xff,0xff,0xfe,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xfd,0xff,0x00,0x00, 0x00,0x03,0x00,0xff,0xff,0xff,0xfd,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfb,0xff,0x00,0x00,0x00,0xfe,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xee, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xf4,0xff,0x00,0x00,0x00,0x03,0x00, 0xff,0xff,0xff,0xf4,0xff,0x00,0x00,0x00, 0x03,0x00,0xff,0xff,0xff,0xf7,0xff,0x00, 0x00,0x00,0x03,0x00,0xff,0xff,0xff,0xed, 0xff,0x00,0x00,0x00,0x03,0x00,0xff,0xff, 0xff,0xe6,0xff,0x00,0x00,0x00,0xfe,0xff, 0x00,0x00,0x00,0xfa,0xff,0xff,0xff,0xff, 0xf3,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xf3,0xff,0x00,0x00,0x00,0xfe, 0xff,0xff,0xff,0xff,0xf6,0xff,0x00,0x00, 0x00,0x03,0x00,0xff,0xff,0xff,0xfe,0xff, 0x00,0x00,0x00,0x03,0x00,0xff,0xff,0xff, 0xfa,0xff,0x00,0x00,0x00,0x03,0x00,0xff, 0xff,0xff,0xed,0xff,0x00,0x00,0x00,0x03, 0x00,0xff,0xff,0xff,0xe6,0xff,0x00,0x00, 0x00,0x98,0xff,0x00,0x00,0x00,0x98,0xff, 0x00,0x00,0x00, }, }; } }