Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updates

  • Loading branch information...
commit 1e7b18fe2a6efaab90c2d9b448cc0426a4bd3fbf 1 parent f0130b0
@tomahawkins authored
Showing with 10 additions and 7 deletions.
  1. +10 −7 BMP.hs
View
17 BMP.hs
@@ -6,20 +6,18 @@ import Data.Digest.CRC32
import Data.Word
main :: IO ()
-main = B.writeFile "test.esb" $ B.pack $ esb $ bootloaderHeader $ nop ++ jumpToBoot
+main = B.writeFile "test.esb" $ B.pack $ esb $ bootloaderHeader test
+test :: [Word8]
+test = jumpToBoot -- b 0
+
+-- | Format ESB image.
esb :: [Word8] -> [Word8]
esb image = [0xE5, 0x5B, 0xBE, 0xE5, 5, 0, 0, 0] ++ le (fromIntegral $ crc32 block) ++ block
where
block :: [Word8]
block = [1, 0, 0, 0, 3, 0, 0, 0, 128, 0, 0, 0] ++ le (length image) ++ image
-le :: Int -> [Word8]
-le a = [ fromIntegral $ shiftR a n .&. 0xFF | n <- [0, 8 .. 24] ]
-
-be :: Int -> [Word8]
-be a = [ fromIntegral $ shiftR a n .&. 0xFF | n <- [24, 16 .. 0] ]
-
-- | Adds bootloader header to a program. Program must start at address 0x8001c.
bootloaderHeader :: [Word8] -> [Word8]
bootloaderHeader program' = be (0 - sum block) ++ block
@@ -46,6 +44,11 @@ bootloaderHeader program' = be (0 - sum block) ++ block
sum [] = 0
sum _ = error "words not on 32-bit boundry"
+le :: Int -> [Word8]
+le a = [ fromIntegral $ shiftR a n .&. 0xFF | n <- [0, 8 .. 24] ]
+
+be :: Int -> [Word8]
+be a = [ fromIntegral $ shiftR a n .&. 0xFF | n <- [24, 16 .. 0] ]
Please sign in to comment.
Something went wrong with that request. Please try again.