| Nico Huber | a455f0e | 2018-01-07 11:40:40 +0100 | [diff] [blame] | 1 | with Ada.Numerics.Discrete_Random; |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 2 | with Ada.Unchecked_Conversion; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 3 | with Ada.Command_Line; |
| 4 | with Interfaces.C; |
| 5 | |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 6 | with HW.Time; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 7 | with HW.Debug; |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 8 | with HW.PCI.Dev; |
| 9 | with HW.MMIO_Range; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 10 | with HW.GFX.GMA.Config; |
| Nico Huber | 5903f92 | 2020-10-05 14:15:57 +0200 | [diff] [blame^] | 11 | with HW.GFX.GMA.Registers; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 12 | with HW.GFX.GMA.Display_Probing; |
| 13 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 14 | package body HW.GFX.GMA.GFX_Test |
| 15 | is |
| 16 | pragma Disable_Atomic_Synchronization; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 17 | |
| Nico Huber | a455f0e | 2018-01-07 11:40:40 +0100 | [diff] [blame] | 18 | Primary_Delay_MS : constant := 8_000; |
| 19 | Secondary_Delay_MS : constant := 4_000; |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 20 | HP_Delay_MS : constant := 500; |
| Nico Huber | a455f0e | 2018-01-07 11:40:40 +0100 | [diff] [blame] | 21 | Seed : constant := 12345; |
| 22 | |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 23 | package Rand_P is new Ada.Numerics.Discrete_Random (Natural); |
| Nico Huber | d8282b6 | 2018-06-18 00:44:55 +0200 | [diff] [blame] | 24 | function Rand (Gen : Rand_P.Generator) |
| 25 | return Int32 is (Int32 (Rand_P.Random (Gen))); |
| Nico Huber | a455f0e | 2018-01-07 11:40:40 +0100 | [diff] [blame] | 26 | |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 27 | Start_X : constant := 0; |
| 28 | Start_Y : constant := 0; |
| 29 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 30 | package Dev is new PCI.Dev (PCI.Address'(0, 2, 0)); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 31 | |
| Nico Huber | c76749d | 2018-06-09 22:04:55 +0200 | [diff] [blame] | 32 | type GTT_Entry is record |
| 33 | Addr : GTT_Address_Type; |
| 34 | Valid : Boolean; |
| 35 | end record; |
| 36 | GTT_Backup : array (GTT_Range) of GTT_Entry; |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 37 | GTT_Backup_Count : Natural; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 38 | |
| 39 | procedure Backup_GTT |
| 40 | is |
| 41 | begin |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 42 | GMA.GTT_Entry_Count (GTT_Backup_Count); |
| 43 | if GTT_Backup_Count = 0 then |
| 44 | Debug.Put_Line ("WARNING: GTT size is 0, skipping GTT backup."); |
| 45 | return; |
| 46 | end if; |
| 47 | for Idx in GTT_Range range 0 .. GTT_Backup_Count - 1 loop |
| Nico Huber | c76749d | 2018-06-09 22:04:55 +0200 | [diff] [blame] | 48 | Read_GTT (GTT_Backup (Idx).Addr, GTT_Backup (Idx).Valid, Idx); |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 49 | end loop; |
| 50 | end Backup_GTT; |
| 51 | |
| 52 | procedure Restore_GTT |
| 53 | is |
| 54 | begin |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 55 | if GTT_Backup_Count = 0 then |
| 56 | return; |
| 57 | end if; |
| 58 | for Idx in GTT_Range range 0 .. GTT_Backup_Count - 1 loop |
| Nico Huber | c76749d | 2018-06-09 22:04:55 +0200 | [diff] [blame] | 59 | Write_GTT (Idx, GTT_Backup (Idx).Addr, GTT_Backup (Idx).Valid); |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 60 | end loop; |
| 61 | end Restore_GTT; |
| 62 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 63 | type Pixel_Type is record |
| 64 | Red : Byte; |
| 65 | Green : Byte; |
| 66 | Blue : Byte; |
| 67 | Alpha : Byte; |
| 68 | end record; |
| 69 | |
| 70 | for Pixel_Type use record |
| 71 | Blue at 0 range 0 .. 7; |
| 72 | Green at 1 range 0 .. 7; |
| 73 | Red at 2 range 0 .. 7; |
| 74 | Alpha at 3 range 0 .. 7; |
| 75 | end record; |
| 76 | |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 77 | White : constant Pixel_Type := (255, 255, 255, 255); |
| 78 | Black : constant Pixel_Type := ( 0, 0, 0, 255); |
| 79 | Red : constant Pixel_Type := (255, 0, 0, 255); |
| 80 | Green : constant Pixel_Type := ( 0, 255, 0, 255); |
| 81 | Blue : constant Pixel_Type := ( 0, 0, 255, 255); |
| 82 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 83 | function Pixel_To_Word (P : Pixel_Type) return Word32 |
| 84 | with |
| 85 | SPARK_Mode => Off |
| 86 | is |
| 87 | function To_Word is new Ada.Unchecked_Conversion (Pixel_Type, Word32); |
| 88 | begin |
| 89 | return To_Word (P); |
| 90 | end Pixel_To_Word; |
| 91 | |
| Nico Huber | 7bb10c6 | 2018-01-12 14:07:44 +0100 | [diff] [blame] | 92 | Max_W : constant := 4096; |
| 93 | Max_H : constant := 2160; |
| 94 | FB_Align : constant := 16#0004_0000#; |
| 95 | Cursor_Align : constant := 16#0001_0000#; |
| 96 | Max_Cursor_Wid : constant := 256; |
| 97 | subtype Screen_Index is Natural range 0 .. 3 * |
| 98 | (Max_W * Max_H + FB_Align / 4 + |
| 99 | 3 * Max_Cursor_Wid * Max_Cursor_Wid + Cursor_Align / 4) |
| 100 | - 1; |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 101 | type Screen_Type is array (Screen_Index) of Word32; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 102 | |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 103 | function Screen_Offset (FB : Framebuffer_Type) return Natural is |
| 104 | (Natural (Phys_Offset (FB) / 4)); |
| 105 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 106 | package Screen is new MMIO_Range (0, Word32, Screen_Index, Screen_Type); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 107 | |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 108 | Screen_Backup : Screen_Type; |
| 109 | |
| 110 | procedure Backup_Screen (FB : Framebuffer_Type) |
| 111 | is |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 112 | First : constant Screen_Index := Screen_Offset (FB); |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 113 | Last : constant Screen_Index := First + Natural (FB_Size (FB)) / 4 - 1; |
| 114 | begin |
| 115 | for Idx in Screen_Index range First .. Last loop |
| 116 | Screen.Read (Screen_Backup (Idx), Idx); |
| 117 | end loop; |
| 118 | end Backup_Screen; |
| 119 | |
| 120 | procedure Restore_Screen (FB : Framebuffer_Type) |
| 121 | is |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 122 | First : constant Screen_Index := Screen_Offset (FB); |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 123 | Last : constant Screen_Index := First + Natural (FB_Size (FB)) / 4 - 1; |
| 124 | begin |
| 125 | for Idx in Screen_Index range First .. Last loop |
| 126 | Screen.Write (Idx, Screen_Backup (Idx)); |
| 127 | end loop; |
| 128 | end Restore_Screen; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 129 | |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 130 | function Drawing_Width (FB : Framebuffer_Type) return Natural is |
| 131 | (Natural (FB.Width + 2 * Start_X)); |
| 132 | |
| 133 | function Drawing_Height (FB : Framebuffer_Type) return Natural is |
| 134 | (Natural (FB.Height + 2 * Start_Y)); |
| 135 | |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 136 | function Corner_Fill |
| 137 | (X, Y : Natural; |
| 138 | FB : Framebuffer_Type; |
| 139 | Pipe : Pipe_Index) |
| 140 | return Pixel_Type |
| 141 | is |
| 142 | Xrel : constant Integer := |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 143 | (if X < 32 then X else X - (Drawing_Width (FB) - 32)); |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 144 | Yrel : constant Integer := |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 145 | (if Y < 32 then Y else Y - (Drawing_Height (FB) - 32)); |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 146 | |
| 147 | function Color (Idx : Natural) return Pixel_Type is |
| 148 | (case (Idx + Pipe_Index'Pos (Pipe)) mod 4 is |
| 149 | when 0 => Blue, when 1 => Black, |
| 150 | when 3 => Green, when others => Red); |
| 151 | begin |
| 152 | return |
| 153 | (if Xrel mod 16 = 0 or Xrel = 31 or Yrel mod 16 = 0 or Yrel = 31 then |
| 154 | White |
| 155 | elsif Yrel < 16 then |
| 156 | (if Xrel < 16 then Color (0) else Color (1)) |
| 157 | else |
| 158 | (if Xrel < 16 then Color (3) else Color (2))); |
| 159 | end Corner_Fill; |
| 160 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 161 | function Fill |
| 162 | (X, Y : Natural; |
| 163 | Framebuffer : Framebuffer_Type; |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 164 | Pipe : Pipe_Index) |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 165 | return Pixel_Type |
| 166 | is |
| 167 | use type HW.Byte; |
| 168 | |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 169 | Xp : constant Natural := X * 256 / Drawing_Width (Framebuffer); |
| 170 | Yp : constant Natural := Y * 256 / Drawing_Height (Framebuffer); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 171 | Xn : constant Natural := 255 - Xp; |
| 172 | Yn : constant Natural := 255 - Yp; |
| 173 | |
| 174 | function Map (X, Y : Natural) return Byte is |
| 175 | begin |
| 176 | return Byte (X * Y / 255); |
| 177 | end Map; |
| 178 | begin |
| 179 | return |
| 180 | (case Pipe is |
| 181 | when GMA.Primary => (Map (Xn, Yn), Map (Xp, Yn), Map (Xp, Yp), 255), |
| 182 | when GMA.Secondary => (Map (Xn, Yp), Map (Xn, Yn), Map (Xp, Yn), 255), |
| 183 | when GMA.Tertiary => (Map (Xp, Yp), Map (Xn, Yp), Map (Xn, Yn), 255)); |
| 184 | end Fill; |
| 185 | |
| 186 | procedure Test_Screen |
| 187 | (Framebuffer : Framebuffer_Type; |
| 188 | Pipe : GMA.Pipe_Index) |
| 189 | is |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 190 | P : Pixel_Type; |
| 191 | -- We have pixel offset wheras the framebuffer has a byte offset |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 192 | Offset_Y : Natural := Screen_Offset (Framebuffer); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 193 | Offset : Natural; |
| Nico Huber | 9ca69f1 | 2017-08-28 14:31:46 +0200 | [diff] [blame] | 194 | |
| 195 | function Top_Test (X, Y : Natural) return Boolean |
| 196 | is |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 197 | C : constant Natural := Drawing_Width (Framebuffer) / 2; |
| 198 | S_Y : constant Natural := 3 * (Y - Start_Y) / 2; |
| Nico Huber | 9ca69f1 | 2017-08-28 14:31:46 +0200 | [diff] [blame] | 199 | Left : constant Integer := X - C + S_Y; |
| 200 | Right : constant Integer := X - C - S_Y; |
| 201 | begin |
| 202 | return |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 203 | (Y - Start_Y) < 12 and |
| Nico Huber | 9ca69f1 | 2017-08-28 14:31:46 +0200 | [diff] [blame] | 204 | ((-1 <= Left and Left <= 0) or |
| 205 | (0 <= Right and Right <= 1)); |
| 206 | end Top_Test; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 207 | begin |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 208 | for Y in 0 .. Drawing_Height (Framebuffer) - 1 loop |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 209 | Offset := Offset_Y; |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 210 | for X in 0 .. Drawing_Width (Framebuffer) - 1 loop |
| 211 | if (X < 32 or X >= Drawing_Width (Framebuffer) - 32) and |
| 212 | (Y < 32 or Y >= Drawing_Height (Framebuffer) - 32) |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 213 | then |
| 214 | P := Corner_Fill (X, Y, Framebuffer, Pipe); |
| Nico Huber | 9ca69f1 | 2017-08-28 14:31:46 +0200 | [diff] [blame] | 215 | elsif Framebuffer.Rotation /= No_Rotation and then |
| 216 | Top_Test (X, Y) |
| 217 | then |
| 218 | P := White; |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 219 | elsif Y mod 16 = 0 or X mod 16 = 0 then |
| 220 | P := Black; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 221 | else |
| 222 | P := Fill (X, Y, Framebuffer, Pipe); |
| 223 | end if; |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 224 | Screen.Write (Offset, Pixel_To_Word (P)); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 225 | Offset := Offset + 1; |
| 226 | end loop; |
| 227 | Offset_Y := Offset_Y + Natural (Framebuffer.Stride); |
| 228 | end loop; |
| 229 | end Test_Screen; |
| 230 | |
| Nico Huber | 7bb10c6 | 2018-01-12 14:07:44 +0100 | [diff] [blame] | 231 | function Donut (X, Y, Max : Cursor_Pos) return Byte |
| 232 | is |
| 233 | ZZ : constant Int32 := Max * Max * 2; |
| 234 | Dist_Center : constant Int32 := ((X * X + Y * Y) * 255) / ZZ; |
| 235 | Dist_Circle : constant Int32 := Dist_Center - 20; |
| 236 | begin |
| 237 | return Byte (255 - Int32'Min (255, 6 * abs Dist_Circle + 64)); |
| 238 | end Donut; |
| 239 | |
| Nico Huber | 5903f92 | 2020-10-05 14:15:57 +0200 | [diff] [blame^] | 240 | procedure Draw_Cursor (Pipe : Pipe_Index; Rotation : Rotation_Type; Cursor : Cursor_Type) |
| Nico Huber | 7bb10c6 | 2018-01-12 14:07:44 +0100 | [diff] [blame] | 241 | is |
| 242 | use type HW.Byte; |
| 243 | Width : constant Width_Type := Cursor_Width (Cursor.Size); |
| Nico Huber | 5903f92 | 2020-10-05 14:15:57 +0200 | [diff] [blame^] | 244 | GTT_Offset : constant GTT_Range := |
| 245 | (if Rotation = Rotated_90 or Rotation = Rotated_270 then |
| 246 | Cursor.GTT_Offset - GTT_Rotation_Offset |
| 247 | else |
| 248 | Cursor.GTT_Offset); |
| 249 | Screen_Offset : Natural := Natural (Shift_Left (Word32 (GTT_Offset), 12) / 4); |
| Nico Huber | 7bb10c6 | 2018-01-12 14:07:44 +0100 | [diff] [blame] | 250 | begin |
| 251 | if Cursor.Mode /= ARGB_Cursor then |
| 252 | return; |
| 253 | end if; |
| 254 | for Y in Cursor_Pos range -Width / 2 .. Width / 2 - 1 loop |
| 255 | for X in Cursor_Pos range -Width / 2 .. Width / 2 - 1 loop |
| 256 | declare |
| 257 | D : constant Byte := Donut (X, Y, Width / 2); |
| 258 | begin |
| 259 | -- Hardware seems to expect pre-multiplied alpha (i.e. |
| 260 | -- color components already contain the alpha). |
| 261 | Screen.Write |
| 262 | (Index => Screen_Offset, |
| 263 | Value => Pixel_To_Word ( |
| 264 | (Red => (if Pipe = Secondary then D / 2 else 0), |
| 265 | Green => (if Pipe = Tertiary then D / 2 else 0), |
| 266 | Blue => (if Pipe = Primary then D / 2 else 0), |
| 267 | Alpha => D))); |
| 268 | Screen_Offset := Screen_Offset + 1; |
| 269 | end; |
| 270 | end loop; |
| 271 | end loop; |
| 272 | end Draw_Cursor; |
| 273 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 274 | procedure Calc_Framebuffer |
| 275 | (FB : out Framebuffer_Type; |
| 276 | Mode : in Mode_Type; |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 277 | Rotation : in Rotation_Type; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 278 | Offset : in out Word32) |
| 279 | is |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 280 | Width : constant Width_Type := Mode.H_Visible; |
| 281 | Height : constant Height_Type := Mode.V_Visible; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 282 | begin |
| 283 | Offset := (Offset + FB_Align - 1) and not (FB_Align - 1); |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 284 | if Rotation = Rotated_90 or Rotation = Rotated_270 then |
| 285 | FB := |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 286 | (Width => Height, |
| 287 | Height => Width, |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 288 | Start_X => Start_X, |
| 289 | Start_Y => Start_Y, |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 290 | BPC => 8, |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 291 | Stride => Div_Round_Up (Height + 2 * Start_X, 32) * 32, |
| 292 | V_Stride => Div_Round_Up (Width + 2 * Start_Y, 32) * 32, |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 293 | Tiling => Y_Tiled, |
| 294 | Rotation => Rotation, |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 295 | Offset => Offset + Word32 (GTT_Rotation_Offset) * GTT_Page_Size); |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 296 | else |
| 297 | FB := |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 298 | (Width => Width, |
| 299 | Height => Height, |
| 300 | Start_X => Start_X, |
| 301 | Start_Y => Start_Y, |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 302 | BPC => 8, |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 303 | Stride => Div_Round_Up (Width + 2 * Start_X, 16) * 16, |
| 304 | V_Stride => Height + 2 * Start_Y, |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 305 | Tiling => Linear, |
| 306 | Rotation => Rotation, |
| 307 | Offset => Offset); |
| 308 | end if; |
| Nico Huber | b747049 | 2017-11-30 14:48:35 +0100 | [diff] [blame] | 309 | Offset := Offset + Word32 (FB_Size (FB)); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 310 | end Calc_Framebuffer; |
| 311 | |
| Nico Huber | 7bb10c6 | 2018-01-12 14:07:44 +0100 | [diff] [blame] | 312 | type Cursor_Array is array (Cursor_Size) of Cursor_Type; |
| 313 | Cursors : array (Pipe_Index) of Cursor_Array; |
| 314 | |
| 315 | procedure Prepare_Cursors |
| 316 | (Cursors : out Cursor_Array; |
| Nico Huber | 5903f92 | 2020-10-05 14:15:57 +0200 | [diff] [blame^] | 317 | Rotation : in Rotation_Type; |
| Nico Huber | 7bb10c6 | 2018-01-12 14:07:44 +0100 | [diff] [blame] | 318 | Offset : in out Word32) |
| 319 | is |
| Nico Huber | 7bb10c6 | 2018-01-12 14:07:44 +0100 | [diff] [blame] | 320 | GMA_Phys_Base_Mask : constant := 16#fff0_0000#; |
| 321 | |
| 322 | Phys_Base : Word32; |
| 323 | Success : Boolean; |
| 324 | begin |
| Nico Huber | 87719ae | 2024-06-20 13:06:05 +0000 | [diff] [blame] | 325 | if Config.GMA_Base_Is_64bit then |
| 326 | Dev.Read32 (Phys_Base, Config.GMA_Phys_Base_Index + 4); |
| 327 | if Phys_Base /= 0 then |
| 328 | pragma Debug (Debug.Put_Line ("Cannot handle 64-bit DSM yet.")); |
| 329 | return; |
| 330 | end if; |
| 331 | end if; |
| 332 | |
| 333 | Dev.Read32 (Phys_Base, Config.GMA_Phys_Base_Index); |
| Nico Huber | 7bb10c6 | 2018-01-12 14:07:44 +0100 | [diff] [blame] | 334 | Phys_Base := Phys_Base and GMA_Phys_Base_Mask; |
| 335 | Success := Phys_Base /= GMA_Phys_Base_Mask and Phys_Base /= 0; |
| 336 | if not Success then |
| 337 | Debug.Put_Line ("Failed to read stolen memory base."); |
| 338 | return; |
| 339 | end if; |
| 340 | |
| 341 | for Size in Cursor_Size loop |
| 342 | Offset := (Offset + Cursor_Align - 1) and not (Cursor_Align - 1); |
| 343 | declare |
| 344 | Width : constant Width_Type := Cursor_Width (Size); |
| Nico Huber | 5903f92 | 2020-10-05 14:15:57 +0200 | [diff] [blame^] | 345 | Height : Width_Type renames Width; |
| 346 | |
| 347 | Phys_End : constant Word32 := Offset + Word32 (Width * Height) * 4; |
| 348 | GTT_Start : constant GTT_Range := GTT_Range (Shift_Right (Offset, 12)); |
| 349 | GTT_End : constant GTT_Range := GTT_Range (Shift_Right (Phys_End, 12)); |
| 350 | -- 90 degree rotations use a special framebuffer mapping w/ GTT_Rotation_Offset: |
| 351 | Scanout_Offset : constant GTT_Range := |
| 352 | (if Rotation in Rotated_90 | Rotated_270 then GTT_Rotation_Offset else 0); |
| Nico Huber | 7bb10c6 | 2018-01-12 14:07:44 +0100 | [diff] [blame] | 353 | begin |
| 354 | Cursors (Size) := |
| 355 | (Mode => ARGB_Cursor, |
| 356 | Size => Size, |
| 357 | Center_X => Width, |
| Nico Huber | 5903f92 | 2020-10-05 14:15:57 +0200 | [diff] [blame^] | 358 | Center_Y => Height, |
| 359 | GTT_Offset => GTT_Start + Scanout_Offset); |
| 360 | |
| 361 | while Offset < Phys_End loop |
| Nico Huber | 7bb10c6 | 2018-01-12 14:07:44 +0100 | [diff] [blame] | 362 | GMA.Write_GTT |
| 363 | (GTT_Page => GTT_Range (Offset / GTT_Page_Size), |
| 364 | Device_Address => GTT_Address_Type (Phys_Base + Offset), |
| 365 | Valid => True); |
| 366 | Offset := Offset + GTT_Page_Size; |
| 367 | end loop; |
| Nico Huber | 5903f92 | 2020-10-05 14:15:57 +0200 | [diff] [blame^] | 368 | |
| 369 | if Rotation in Rotated_90 | Rotated_270 then |
| 370 | -- In case of y-tiled surfaces (needed for 90 degree rotations), |
| 371 | -- the fence makes the framebuffer writeable like a linear one. |
| 372 | Registers.Add_Fence |
| 373 | (First_Page => GTT_Start, |
| 374 | Last_Page => GTT_End - 1, |
| 375 | Tiling => Y_Tiled, |
| 376 | Pitch => Natural (Width / Tile_Width (Y_Tiled)), |
| 377 | Success => Success); |
| 378 | |
| 379 | -- Though, for the scanout of the rotated surface, we have to add |
| 380 | -- a special, rotated framebuffer mapping. For each linear page |
| 381 | -- index we calculate `Phys_Addr` column-wise from bottom to top. |
| 382 | declare |
| 383 | subtype Rotated_Pages is GTT_Range range |
| 384 | GTT_Start + GTT_Rotation_Offset .. GTT_End - 1 + GTT_Rotation_Offset; |
| 385 | |
| 386 | Bytes_Per_Row : constant GTT_Address_Type := |
| 387 | GTT_Address_Type (Tile_Rows (Y_Tiled) * Width * 4); |
| 388 | V_Pages : constant GTT_Range := GTT_Range (Height / Tile_Rows (Y_Tiled)); |
| 389 | V_Bytes : constant GTT_Address_Type := |
| 390 | GTT_Address_Type (V_Pages) * Bytes_Per_Row; |
| 391 | |
| 392 | Phys_Addr : GTT_Address_Type := GTT_Address_Type (Phys_Base + Phys_End); |
| 393 | begin |
| 394 | for Page in Rotated_Pages loop |
| 395 | Phys_Addr := Phys_Addr - Bytes_Per_Row; |
| 396 | |
| 397 | Registers.Write_GTT |
| 398 | (GTT_Page => Page, |
| 399 | Device_Address => Phys_Addr, |
| 400 | Valid => True); |
| 401 | |
| 402 | if (Page - Rotated_Pages'First + 1) mod V_Pages = 0 then |
| 403 | Phys_Addr := Phys_Addr + GTT_Page_Size + V_Bytes; |
| 404 | end if; |
| 405 | end loop; |
| 406 | end; |
| 407 | end if; |
| Nico Huber | 7bb10c6 | 2018-01-12 14:07:44 +0100 | [diff] [blame] | 408 | end; |
| 409 | end loop; |
| 410 | end Prepare_Cursors; |
| 411 | |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 412 | Pipes : GMA.Pipe_Configs; |
| 413 | |
| Nico Huber | d8282b6 | 2018-06-18 00:44:55 +0200 | [diff] [blame] | 414 | procedure Prepare_Configs (Rotation : Rotation_Type; Gen : Rand_P.Generator) |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 415 | is |
| 416 | use type HW.GFX.GMA.Port_Type; |
| 417 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 418 | Offset : Word32 := 0; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 419 | Success : Boolean; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 420 | begin |
| 421 | GMA.Display_Probing.Scan_Ports (Pipes); |
| 422 | |
| 423 | for Pipe in GMA.Pipe_Index loop |
| 424 | if Pipes (Pipe).Port /= GMA.Disabled then |
| 425 | Calc_Framebuffer |
| 426 | (FB => Pipes (Pipe).Framebuffer, |
| 427 | Mode => Pipes (Pipe).Mode, |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 428 | Rotation => Rotation, |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 429 | Offset => Offset); |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 430 | GMA.Setup_Default_FB |
| 431 | (FB => Pipes (Pipe).Framebuffer, |
| 432 | Clear => False, |
| 433 | Success => Success); |
| 434 | if not Success then |
| 435 | Pipes (Pipe).Port := GMA.Disabled; |
| 436 | end if; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 437 | end if; |
| Nico Huber | 5903f92 | 2020-10-05 14:15:57 +0200 | [diff] [blame^] | 438 | Prepare_Cursors (Cursors (Pipe), Rotation, Offset); |
| Nico Huber | d8282b6 | 2018-06-18 00:44:55 +0200 | [diff] [blame] | 439 | Pipes (Pipe).Cursor := Cursors (Pipe) (Cursor_Size'Val (Rand (Gen) mod 3)); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 440 | end loop; |
| 441 | |
| 442 | GMA.Dump_Configs (Pipes); |
| 443 | end Prepare_Configs; |
| 444 | |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 445 | procedure Script_Cursors |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 446 | (Pipes : in out GMA.Pipe_Configs; |
| 447 | Hotplug_List : out Display_Probing.Port_List; |
| 448 | Total_Deadline : in Time.T; |
| 449 | Time_MS : in Natural) |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 450 | is |
| 451 | type Corner is (UL, UR, LR, LL); |
| 452 | type Cursor_Script_Entry is record |
| 453 | Rel : Corner; |
| 454 | X, Y : Int32; |
| 455 | end record; |
| 456 | Cursor_Script : constant array (Natural range 0 .. 19) of Cursor_Script_Entry := |
| 457 | ((UL, 16, 16), (UL, 16, 16), (UL, 16, 16), (UL, -32, 0), (UL, 16, 16), |
| 458 | (UR, -16, 16), (UR, -16, 16), (UR, -16, 16), (UR, 0, -32), (UR, -16, 16), |
| 459 | (LR, -16, -16), (LR, -16, -16), (LR, -16, -16), (LR, 32, 0), (LR, -16, -16), |
| 460 | (LL, 16, -16), (LL, 16, -16), (LL, 16, -16), (LL, 0, 32), (LL, 16, -16)); |
| 461 | |
| 462 | Deadline : constant Time.T := Time.MS_From_Now (Time_MS); |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 463 | HP_Deadline : Time.T := Time.MS_From_Now (HP_Delay_MS); |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 464 | Timed_Out : Boolean := False; |
| 465 | Cnt : Word32 := 0; |
| 466 | begin |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 467 | Hotplug_List := (others => Disabled); |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 468 | loop |
| 469 | for Pipe in Pipe_Index loop |
| 470 | exit when Pipes (Pipe).Port = GMA.Disabled; |
| 471 | declare |
| 472 | C : Cursor_Type renames Pipes (Pipe).Cursor; |
| 473 | FB : Framebuffer_Type renames Pipes (Pipe).Framebuffer; |
| Nico Huber | 3d7c33f | 2020-10-01 15:14:38 +0200 | [diff] [blame] | 474 | Width : constant Width_Type := FB.Width; |
| 475 | Height : constant Height_Type := FB.Height; |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 476 | CS : Cursor_Script_Entry renames Cursor_Script |
| 477 | (Natural (Cnt) mod (Cursor_Script'Last + 1)); |
| 478 | begin |
| 479 | C.Center_X := CS.X; |
| 480 | C.Center_Y := CS.Y; |
| 481 | case CS.Rel is |
| 482 | when UL => null; |
| 483 | when UR => C.Center_X := CS.X + Width; |
| 484 | when LR => C.Center_X := CS.X + Width; |
| 485 | C.Center_Y := CS.Y + Height; |
| 486 | when LL => C.Center_Y := CS.Y + Height; |
| 487 | end case; |
| 488 | GMA.Place_Cursor (Pipe, C.Center_X, C.Center_Y); |
| 489 | end; |
| 490 | end loop; |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 491 | |
| 492 | Timed_Out := Time.Timed_Out (HP_Deadline); |
| 493 | if Timed_Out then |
| 494 | HP_Deadline := Time.MS_From_Now (HP_Delay_MS); |
| 495 | GMA.Display_Probing.Hotplug_Events (Hotplug_List); |
| 496 | if Hotplug_List (Hotplug_List'First) /= Disabled then |
| 497 | return; |
| 498 | end if; |
| 499 | end if; |
| 500 | |
| 501 | Timed_Out := Time.Timed_Out (Total_Deadline); |
| 502 | exit when Timed_Out; |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 503 | Timed_Out := Time.Timed_Out (Deadline); |
| 504 | exit when Timed_Out; |
| 505 | Time.M_Delay (160); |
| 506 | Cnt := Cnt + 1; |
| 507 | end loop; |
| 508 | end Script_Cursors; |
| 509 | |
| 510 | type Cursor_Info is record |
| 511 | X_Velo, Y_Velo : Int32; |
| 512 | X_Acc, Y_Acc : Int32; |
| 513 | Color : Pipe_Index; |
| 514 | Size : Cursor_Size; |
| 515 | end record; |
| Nico Huber | d8282b6 | 2018-06-18 00:44:55 +0200 | [diff] [blame] | 516 | function Cursor_Rand (Gen : Rand_P.Generator) |
| 517 | return Int32 is (Rand (Gen) mod 51 - 25); |
| 518 | Cursor_Infos : array (Pipe_Index) of Cursor_Info; |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 519 | |
| 520 | procedure Move_Cursors |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 521 | (Pipes : in out GMA.Pipe_Configs; |
| 522 | Hotplug_List : out Display_Probing.Port_List; |
| 523 | Total_Deadline : in Time.T; |
| 524 | Time_MS : in Natural; |
| 525 | Gen : in Rand_P.Generator) |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 526 | is |
| 527 | procedure Select_New_Cursor |
| 528 | (P : in Pipe_Index; |
| 529 | C : in out Cursor_Type; |
| 530 | CI : in out Cursor_Info) |
| 531 | is |
| 532 | Old_C : constant Cursor_Type := C; |
| 533 | begin |
| 534 | -- change either size or color |
| Nico Huber | d8282b6 | 2018-06-18 00:44:55 +0200 | [diff] [blame] | 535 | if Rand (Gen) mod 2 = 0 then |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 536 | CI.Color := Pipe_Index'Val |
| Nico Huber | d8282b6 | 2018-06-18 00:44:55 +0200 | [diff] [blame] | 537 | ((Pipe_Index'Pos (CI.Color) + 1 + Rand (Gen) mod 2) mod 3); |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 538 | else |
| 539 | CI.Size := Cursor_Size'Val |
| Nico Huber | d8282b6 | 2018-06-18 00:44:55 +0200 | [diff] [blame] | 540 | ((Cursor_Size'Pos (CI.Size) + 1 + Rand (Gen) mod 2) mod 3); |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 541 | end if; |
| Nico Huber | ca2ec16 | 2026-07-02 17:41:21 +0000 | [diff] [blame] | 542 | |
| 543 | -- always ensure the cursor fits |
| 544 | if Cursor_Width (CI.Size) > Pipes (P).Framebuffer.Width or |
| 545 | Cursor_Width (CI.Size) > Pipes (P).Framebuffer.Height |
| 546 | then |
| 547 | CI.Size := Cursor_64x64; |
| 548 | end if; |
| 549 | |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 550 | C := Cursors (CI.Color) (CI.Size); |
| 551 | C.Center_X := Old_C.Center_X; |
| 552 | C.Center_Y := Old_C.Center_Y; |
| 553 | GMA.Update_Cursor (P, C); |
| 554 | end Select_New_Cursor; |
| 555 | |
| 556 | Deadline : constant Time.T := Time.MS_From_Now (Time_MS); |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 557 | HP_Deadline : Time.T := Time.MS_From_Now (HP_Delay_MS); |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 558 | Timed_Out : Boolean := False; |
| 559 | Cnt : Word32 := 0; |
| 560 | begin |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 561 | Hotplug_List := (others => Disabled); |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 562 | for Pipe in Pipe_Index loop |
| 563 | exit when Pipes (Pipe).Port = GMA.Disabled; |
| 564 | Select_New_Cursor (Pipe, Pipes (Pipe).Cursor, Cursor_Infos (Pipe)); |
| 565 | end loop; |
| 566 | loop |
| 567 | for Pipe in Pipe_Index loop |
| 568 | exit when Pipes (Pipe).Port = GMA.Disabled; |
| 569 | declare |
| 570 | C : Cursor_Type renames Pipes (Pipe).Cursor; |
| 571 | CI : Cursor_Info renames Cursor_Infos (Pipe); |
| 572 | FB : Framebuffer_Type renames Pipes (Pipe).Framebuffer; |
| Nico Huber | 3d7c33f | 2020-10-01 15:14:38 +0200 | [diff] [blame] | 573 | Width : constant Width_Type := FB.Width; |
| 574 | Height : constant Height_Type := FB.Height; |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 575 | |
| 576 | Update : Boolean := False; |
| 577 | begin |
| 578 | if Cnt mod 16 = 0 then |
| Nico Huber | d8282b6 | 2018-06-18 00:44:55 +0200 | [diff] [blame] | 579 | CI.X_Acc := Cursor_Rand (Gen); |
| 580 | CI.Y_Acc := Cursor_Rand (Gen); |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 581 | end if; |
| 582 | CI.X_Velo := CI.X_Velo + CI.X_Acc; |
| 583 | CI.Y_Velo := CI.Y_Velo + CI.Y_Acc; |
| 584 | C.Center_X := C.Center_X + CI.X_Velo / 100; |
| 585 | C.Center_Y := C.Center_Y + CI.Y_Velo / 100; |
| 586 | if C.Center_X not in 0 .. Width - 1 then |
| Nico Huber | ac2a141 | 2026-07-02 10:41:59 +0200 | [diff] [blame] | 587 | C.Center_X := Int32'Max (0, Int32'Min (Width, C.Center_X)); |
| 588 | CI.X_Velo := -CI.X_Velo; |
| 589 | Update := True; |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 590 | end if; |
| 591 | if C.Center_Y not in 0 .. Height - 1 then |
| Nico Huber | ac2a141 | 2026-07-02 10:41:59 +0200 | [diff] [blame] | 592 | C.Center_Y := Int32'Max (0, Int32'Min (Height, C.Center_Y)); |
| 593 | CI.Y_Velo := -CI.Y_Velo; |
| 594 | Update := True; |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 595 | end if; |
| 596 | if Update then |
| 597 | Select_New_Cursor (Pipe, C, CI); |
| 598 | else |
| 599 | GMA.Place_Cursor (Pipe, C.Center_X, C.Center_Y); |
| 600 | end if; |
| 601 | end; |
| 602 | end loop; |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 603 | |
| 604 | Timed_Out := Time.Timed_Out (HP_Deadline); |
| 605 | if Timed_Out then |
| 606 | HP_Deadline := Time.MS_From_Now (HP_Delay_MS); |
| 607 | GMA.Display_Probing.Hotplug_Events (Hotplug_List); |
| 608 | if Hotplug_List (Hotplug_List'First) /= Disabled then |
| 609 | return; |
| 610 | end if; |
| 611 | end if; |
| 612 | |
| 613 | Timed_Out := Time.Timed_Out (Total_Deadline); |
| 614 | exit when Timed_Out; |
| Nico Huber | a63e833 | 2018-02-01 16:41:30 +0100 | [diff] [blame] | 615 | Timed_Out := Time.Timed_Out (Deadline); |
| 616 | exit when Timed_Out; |
| 617 | Time.M_Delay (16); -- ~60 fps |
| 618 | Cnt := Cnt + 1; |
| 619 | end loop; |
| 620 | end Move_Cursors; |
| 621 | |
| Nico Huber | 5903f92 | 2020-10-05 14:15:57 +0200 | [diff] [blame^] | 622 | procedure Run_The_Show |
| 623 | (Deadline : Time.T; |
| 624 | Gen : Rand_P.Generator; |
| 625 | Rotation : Rotation_Type) |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 626 | is |
| 627 | Timed_Out : Boolean; |
| 628 | Hotplug_List : GMA.Display_Probing.Port_List; |
| 629 | |
| 630 | New_Pipes : GMA.Pipe_Configs := Pipes; |
| 631 | |
| 632 | function Rand_Div (Num : Position_Type) return Position_Type is |
| 633 | (case Rand (Gen) mod 4 is |
| 634 | when 3 => Rand (Gen) mod Num / 3, |
| 635 | when 2 => Rand (Gen) mod Num / 2, |
| 636 | when 1 => Rand (Gen) mod Num, |
| 637 | when others => 0); |
| 638 | begin |
| 639 | for Pipe in GMA.Pipe_Index loop |
| 640 | if Pipes (Pipe).Port /= GMA.Disabled then |
| 641 | Test_Screen |
| 642 | (Framebuffer => Pipes (Pipe).Framebuffer, |
| 643 | Pipe => Pipe); |
| 644 | end if; |
| 645 | for Size in Cursor_Size loop |
| Nico Huber | 5903f92 | 2020-10-05 14:15:57 +0200 | [diff] [blame^] | 646 | Draw_Cursor (Pipe, Rotation, Cursors (Pipe) (Size)); |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 647 | end loop; |
| 648 | end loop; |
| 649 | |
| 650 | Cursor_Infos := |
| 651 | (others => |
| 652 | (Color => Pipe_Index'Val (Rand (Gen) mod 3), |
| Nico Huber | b181b9b | 2026-07-03 10:42:04 +0000 | [diff] [blame] | 653 | Size => Cursor_Size'Val (Rand (Gen) mod 3), |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 654 | others => Cursor_Rand (Gen))); |
| 655 | |
| 656 | Script_Cursors (Pipes, Hotplug_List, Deadline, Primary_Delay_MS); |
| 657 | if Hotplug_List (Hotplug_List'First) /= Disabled then |
| 658 | return; |
| 659 | end if; |
| 660 | Timed_Out := Time.Timed_Out (Deadline); |
| 661 | if Timed_Out then |
| 662 | return; |
| 663 | end if; |
| 664 | |
| 665 | Rand_P.Reset (Gen, Seed); |
| 666 | loop |
| 667 | GMA.Display_Probing.Hotplug_Events (Hotplug_List); |
| 668 | if Hotplug_List (Hotplug_List'First) /= Disabled then |
| 669 | return; |
| 670 | end if; |
| 671 | New_Pipes := Pipes; |
| 672 | for Pipe in GMA.Pipe_Index loop |
| 673 | exit when Pipes (Pipe).Port = Disabled; |
| 674 | declare |
| 675 | New_FB : Framebuffer_Type renames |
| 676 | New_Pipes (Pipe).Framebuffer; |
| 677 | Cursor : Cursor_Type renames New_Pipes (Pipe).Cursor; |
| Nico Huber | b181b9b | 2026-07-03 10:42:04 +0000 | [diff] [blame] | 678 | CI : Cursor_Info renames Cursor_Infos (Pipe); |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 679 | Width : constant Width_Type := |
| 680 | Pipes (Pipe).Framebuffer.Width; |
| 681 | Height : constant Height_Type := |
| 682 | Pipes (Pipe).Framebuffer.Height; |
| 683 | begin |
| 684 | New_FB.Start_X := Position_Type'Min |
| Nico Huber | 19d13a5 | 2026-04-10 16:21:56 +0000 | [diff] [blame] | 685 | (Width - 64, Rand_Div (Width)); |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 686 | New_FB.Start_Y := Position_Type'Min |
| Nico Huber | 19d13a5 | 2026-04-10 16:21:56 +0000 | [diff] [blame] | 687 | (Height - 64, Rand_Div (Height)); |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 688 | New_FB.Width := Width_Type'Max |
| Nico Huber | 19d13a5 | 2026-04-10 16:21:56 +0000 | [diff] [blame] | 689 | (64, Width - New_FB.Start_X - Rand_Div (Width)); |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 690 | New_FB.Height := Height_Type'Max |
| Nico Huber | 19d13a5 | 2026-04-10 16:21:56 +0000 | [diff] [blame] | 691 | (64, Height - New_FB.Start_Y - Rand_Div (Height)); |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 692 | |
| Nico Huber | ca2ec16 | 2026-07-02 17:41:21 +0000 | [diff] [blame] | 693 | Cursor.Mode := No_Cursor; |
| Nico Huber | 3d7c33f | 2020-10-01 15:14:38 +0200 | [diff] [blame] | 694 | Cursor.Center_X := New_FB.Width / 2; |
| 695 | Cursor.Center_Y := New_FB.Height / 2; |
| Nico Huber | b181b9b | 2026-07-03 10:42:04 +0000 | [diff] [blame] | 696 | CI.X_Velo := 6 * Cursor_Rand (Gen) / (Width / New_FB.Width); |
| 697 | CI.Y_Velo := 6 * Cursor_Rand (Gen) / (Height / New_FB.Height); |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 698 | end; |
| 699 | end loop; |
| 700 | GMA.Dump_Configs (New_Pipes); |
| 701 | GMA.Update_Outputs (New_Pipes); |
| 702 | Move_Cursors |
| 703 | (New_Pipes, Hotplug_List, Deadline, Secondary_Delay_MS, Gen); |
| 704 | exit when Hotplug_List (Hotplug_List'First) /= Disabled; |
| 705 | |
| 706 | Timed_Out := Time.Timed_Out (Deadline); |
| 707 | exit when Timed_Out; |
| 708 | end loop; |
| 709 | end Run_The_Show; |
| 710 | |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 711 | procedure Print_Usage |
| 712 | is |
| 713 | begin |
| Nico Huber | 30d8971 | 2021-06-11 14:13:24 +0200 | [diff] [blame] | 714 | Debug.Put ("Usage: "); |
| 715 | Debug.Put (Ada.Command_Line.Command_Name); |
| 716 | Debug.Put_Line (" <delay seconds> [(0|90|180|270)]"); |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 717 | Debug.New_Line; |
| 718 | end Print_Usage; |
| 719 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 720 | procedure Main |
| 721 | is |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 722 | use type HW.GFX.GMA.Port_Type; |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 723 | use type HW.Word64; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 724 | use type Interfaces.C.int; |
| 725 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 726 | Res_Addr : Word64; |
| 727 | |
| Nico Huber | a455f0e | 2018-01-07 11:40:40 +0100 | [diff] [blame] | 728 | Delay_MS : Natural; |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 729 | Rotation : Rotation_Type := No_Rotation; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 730 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 731 | Dev_Init, |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 732 | Initialized : Boolean; |
| 733 | |
| Nico Huber | d8282b6 | 2018-06-18 00:44:55 +0200 | [diff] [blame] | 734 | Gen : Rand_P.Generator; |
| 735 | |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 736 | Deadline : Time.T; |
| 737 | Timed_Out : Boolean; |
| 738 | Hotplug_List : GMA.Display_Probing.Port_List; |
| 739 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 740 | function iopl (level : Interfaces.C.int) return Interfaces.C.int; |
| 741 | pragma Import (C, iopl, "iopl"); |
| 742 | begin |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 743 | if Ada.Command_Line.Argument_Count < 1 then |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 744 | Print_Usage; |
| 745 | return; |
| 746 | end if; |
| 747 | |
| Nico Huber | a455f0e | 2018-01-07 11:40:40 +0100 | [diff] [blame] | 748 | Delay_MS := Natural'Value (Ada.Command_Line.Argument (1)) * 1_000; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 749 | |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 750 | if Ada.Command_Line.Argument_Count >= 2 then |
| 751 | declare |
| 752 | Rotation_Degree : constant String := Ada.Command_Line.Argument (2); |
| 753 | begin |
| 754 | if Rotation_Degree = "0" then Rotation := No_Rotation; |
| 755 | elsif Rotation_Degree = "90" then Rotation := Rotated_90; |
| 756 | elsif Rotation_Degree = "180" then Rotation := Rotated_180; |
| 757 | elsif Rotation_Degree = "270" then Rotation := Rotated_270; |
| 758 | else Print_Usage; return; end if; |
| 759 | end; |
| 760 | end if; |
| 761 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 762 | if iopl (3) /= 0 then |
| 763 | Debug.Put_Line ("Failed to change i/o privilege level."); |
| 764 | return; |
| 765 | end if; |
| 766 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 767 | Dev.Initialize (Dev_Init); |
| 768 | if not Dev_Init then |
| 769 | Debug.Put_Line ("Failed to map PCI config."); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 770 | return; |
| 771 | end if; |
| 772 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 773 | Dev.Map (Res_Addr, PCI.Res2, WC => True); |
| 774 | if Res_Addr = 0 then |
| 775 | Debug.Put_Line ("Failed to map PCI resource2."); |
| 776 | return; |
| 777 | end if; |
| 778 | Screen.Set_Base_Address (Res_Addr); |
| 779 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 780 | GMA.Initialize |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 781 | (Clean_State => True, |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 782 | Success => Initialized); |
| 783 | |
| 784 | if Initialized then |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 785 | Backup_GTT; |
| 786 | |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 787 | Deadline := Time.MS_From_Now (Delay_MS); |
| 788 | loop |
| 789 | Prepare_Configs (Rotation, Gen); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 790 | |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 791 | GMA.Update_Outputs (Pipes); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 792 | |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 793 | if not (for all P in Pipe_Index => Pipes (P).Port = Disabled) then |
| 794 | for Pipe in GMA.Pipe_Index loop |
| 795 | if Pipes (Pipe).Port /= GMA.Disabled then |
| 796 | Backup_Screen (Pipes (Pipe).Framebuffer); |
| 797 | end if; |
| Nico Huber | a455f0e | 2018-01-07 11:40:40 +0100 | [diff] [blame] | 798 | end loop; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 799 | |
| Nico Huber | 5903f92 | 2020-10-05 14:15:57 +0200 | [diff] [blame^] | 800 | Run_The_Show (Deadline, Gen, Rotation); |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 801 | |
| 802 | for Pipe in GMA.Pipe_Index loop |
| 803 | if Pipes (Pipe).Port /= GMA.Disabled then |
| 804 | Restore_Screen (Pipes (Pipe).Framebuffer); |
| 805 | end if; |
| 806 | end loop; |
| 807 | else |
| 808 | loop |
| 809 | Time.M_Delay (HP_Delay_MS); |
| 810 | GMA.Display_Probing.Hotplug_Events (Hotplug_List); |
| 811 | exit when Hotplug_List (Hotplug_List'First) /= Disabled; |
| 812 | |
| 813 | Timed_Out := Time.Timed_Out (Deadline); |
| 814 | exit when Timed_Out; |
| 815 | end loop; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 816 | end if; |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 817 | |
| 818 | Timed_Out := Time.Timed_Out (Deadline); |
| 819 | exit when Timed_Out; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 820 | end loop; |
| Nico Huber | a563ec2 | 2019-09-29 19:07:27 +0200 | [diff] [blame] | 821 | |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 822 | Restore_GTT; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 823 | end if; |
| 824 | end Main; |
| 825 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 826 | end HW.GFX.GMA.GFX_Test; |