aboutsummaryrefslogtreecommitdiffstats
path: root/src/video.ads
blob: e293d7b6f129939c175bf6a8cb9071ea1c475714 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
with Sf;
with Sf.Graphics;
with Sf.Graphics.Sprite;
with Sf.Window.Keyboard;

package Video is
   use Sf;
   use Sf.Graphics;
   use Sf.Window.Keyboard;

   type Model is (Chip_8, Super_Chip_10);

   Title  : constant String := "Ada-Chip";

   Width  : sfUint32;
   Height : sfUint32;
   Scale  : sfUint32;

   procedure Clear_Screen;
   procedure Low_Res;
   procedure High_Res;
   procedure Initialize (M : Model);
   procedure Display;
   procedure Finish;
   procedure Poll_Events;

   procedure Scroll_Right;
   procedure Scroll_Left;

   function Is_Running return Boolean;
   function Toggle_Pixel (X, Y : sfUint32) return Boolean;

   type Key is (
      Unknown,
      Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine,
      A, B, C, D, E, F
   );

   for Key use (
      Unknown => -1,
      Zero  => 0,
      One   => 1,
      Two   => 2,
      Three => 3,
      Four  => 4,
      Five  => 5,
      Six   => 6,
      Seven => 7,
      Eight => 8,
      Nine  => 9,
      A     => 10,
      B     => 11,
      C     => 12,
      D     => 13,
      E     => 14,
      F     => 15
   );

   type Key_Map is array (Key'First .. Key'Last) of sfScancode;

   function Key_Down (K : Key) return Boolean;
   function Key_Up (K : Key) return Boolean;
   function Next_Key return Key;

   function Translate_Scancode (S : sfScancode) return Key;
   function Translate_Key (K : Key) return sfScancode;

private
   Last_Key       : Key;
   app            : sfRenderWindow_Ptr;
   Pixels         : sfImage_Ptr;
   Pixels_Texture : sfTexture_Ptr;
   Pixels_Sprite  : constant sfSprite_Ptr := Sprite.create;

   Key_Conv : Key_Map := (
      sfScanUnknown,
      sfScanNum0, sfScanNum1, sfScanNum2, sfScanNum3, sfScanNum4, sfScanNum5,
      sfScanNum6, sfScanNum7, sfScanNum8, sfScanNum9,
      sfScanA, sfScanB, sfScanC, sfScanD, sfScanE, sfScanF
   );
end Video;