Screen.agda 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. module Screen where
  2. import Data.Nat
  3. import Data.Bool
  4. import Data.List
  5. import Logic.Base
  6. open Data.Bool
  7. open Data.List
  8. open Data.Nat
  9. open Logic.Base
  10. -- Ranges -----------------------------------------------------------------
  11. data Range : Set where
  12. range : Nat -> Nat -> Range
  13. inRange : Range -> Nat -> Bool
  14. inRange (range lo hi) x = lo ≤ x && x ≤ hi
  15. low : Range -> Nat
  16. low (range lo _) = lo
  17. high : Range -> Nat
  18. high (range _ hi) = hi
  19. size : Range -> Nat
  20. size (range lo hi) = suc hi - lo
  21. enumerate : Range -> List Nat
  22. enumerate (range lo hi) = enum lo hi
  23. where
  24. list : Nat -> Nat -> List Nat
  25. list _ 0 = []
  26. list k (suc n) = k :: list (suc k) n
  27. enum : Nat -> Nat -> List Nat
  28. enum lo hi = map (_+_ lo) (list 0 (suc hi - lo))
  29. -- The screen example -----------------------------------------------------
  30. xRange : Range
  31. xRange = range 0 79
  32. yRange : Range
  33. yRange = range 0 24
  34. screenRange : Range
  35. screenRange = range 0xb8000 0xb87ff
  36. -- Converting (x,y) to addr
  37. plot : Nat -> Nat -> Nat
  38. plot x y = low screenRange + x + size xRange * y
  39. -- The property
  40. forAll : Range -> (Nat -> Bool) -> Bool
  41. forAll r p = foldr (\n b -> p n && b) true (enumerate r)
  42. prop : Bool
  43. prop = forAll xRange \x ->
  44. forAll yRange \y ->
  45. inRange screenRange (plot x y)
  46. proof : IsTrue prop
  47. proof = tt