Permalink
Browse files

Experiment with video color

  • Loading branch information...
jaspervdj committed Apr 10, 2012
1 parent d03c197 commit 951874227fb37f3420433c69ea45cb3d4d7df9be
Showing with 21 additions and 4 deletions.
  1. +21 −4 src/Emulator/Video.hs
View
@@ -2,7 +2,7 @@ module Emulator.Video
( video
) where
import Data.Bits ((.&.))
import Data.Bits (shiftR, (.&.), (.|.))
import Data.Char (chr)
import Data.Word (Word16)
@@ -20,13 +20,30 @@ video (Ram address) word
| address' < videoStart = return ()
| address' >= videoEnd = return ()
| otherwise = do
Ansi.setCursorPosition row column
Ansi.setCursorPosition row col
Ansi.setSGR $ color word
putChar $ chr charcode
where
address' = fromIntegral address
videoStart = 0x8000
videoEnd = videoStart + terminalWidth * terminalHeight
row = (address' - videoStart) `div` terminalWidth
column = (address' - videoStart) `mod` terminalWidth
(row, col) = (address' - videoStart) `divMod` terminalWidth
charcode = fromIntegral $ word .&. 0x007f
video _ _ = return ()
color :: Word16 -> [Ansi.SGR]
color w
| w .&. 0x0080 == 0x0000 = []
| otherwise =
[ Ansi.SetColor Ansi.Foreground Ansi.Dull (toEnum fg)
, Ansi.SetColor Ansi.Background Ansi.Dull (toEnum bg)
]
where
fg = fromIntegral $
(w .&. 0x4000) `shiftR` 14 .|.
(w .&. 0x2000) `shiftR` 12 .|.
(w .&. 0x1000) `shiftR` 10
bg = fromIntegral $
(w .&. 0x0400) `shiftR` 10 .|.
(w .&. 0x0200) `shiftR` 8 .|.
(w .&. 0x0100) `shiftR` 6

0 comments on commit 9518742

Please sign in to comment.