Skip to content

Commit

Permalink
add prelude module, bump version, update example
Browse files Browse the repository at this point in the history
  • Loading branch information
ix committed Jun 4, 2019
1 parent a817215 commit 126f205
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 24 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog for Lazyboy

# 0.2.2.0
- Added a Prelude module which provides overloaded operators.
- Updated the example in Main.hs to use the newer syntax.
- Updated README to match the newer syntax.

# 0.2.1.1
- Added a lot of instruction tests and fix some bugs.

Expand Down
22 changes: 5 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,16 @@ Also features a library for manipulating constructs such as memory and graphics.
Currently, RGBASM is the only output target, but in the future native machine code generation is planned.

Syntax example (will be updated as more complex constructs are added):

```haskell
main :: IO ()
main = rom >>= T.putStrLn
where rom = compileROM $ do
smiley <- embedBytes image
-- set scroll values
write (Address scx) 0
write (Address scy) 0
-- set background palette
setBackgroundPalette defaultPalette
-- perform graphics operations
onVblank $ do
disableLCD
memcpy (Name smiley) (Address $ 0x9010) $ fromIntegral $ length image
memset (Address 0x9904) (0x992F - 0x9904) 0 -- clear the background tilemap
write (Address background1) 1 -- write the background tile data
setLCDControl $ defaultLCDControl { lcdDisplayEnable = True, lcdBackgroundEnable = True }
-- halt indefinitely
byte A 0xDE
byte B 0xDE
if' ((A == (0xDE :: Word8)) && (A == B)) $ do
write (Address wram0) 0xDE
freeze

image :: [Word8]
image = [0x00,0x00,0x00,0x00,0x24,0x24,0x00,0x00,0x81,0x81,0x7e,0x7e,0x00,0x00,0x00,0x00]
```

See `app/Main.hs` for a full usage example.
Expand Down
8 changes: 4 additions & 4 deletions example/Main.hs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Control.Monad
import qualified Data.Text.Lazy.IO as T
import Data.Word
import Lazyboy
import Lazyboy.Prelude
import Lazyboy.Target.ASM
import Prelude hiding ((&&), (/=), (<), (==), (>), (||))

main :: IO ()
main = rom >>= T.putStrLn
where rom = compileROM $ do
byte A 0xDE
byte B 0xDE
if' ((A `equalTo` (0xDE :: Word8)) `Lazyboy.and` (A `equalTo` B)) $ do
if' ((A == (0xDE :: Word8)) && (A == B)) $ do
write (Address wram0) 0xDE
freeze
freeze
5 changes: 3 additions & 2 deletions lazyboy.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 4e2f866c2ce7b498a6ca6022a042bf2cacb83928127a1e6c802abd72499ef0d8
-- hash: 2c2f36e2503c75ae0efa9de0982175bc15ad7cc3ae2fd5a750d71f5248abbeb0

name: lazyboy
version: 0.2.1.1
version: 0.2.2.0
synopsis: An EDSL for programming the Game Boy.
description: An EDSL for programming the Nintendo Game Boy. <https://github.com/ix/lazyboy#readme>
category: DSL, Compiler
Expand Down Expand Up @@ -35,6 +35,7 @@ library
Lazyboy.Constants
Lazyboy.Control
Lazyboy.IO
Lazyboy.Prelude
Lazyboy.Target.ASM
Lazyboy.Types
other-modules:
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: lazyboy
version: 0.2.1.1
version: 0.2.2.0
github: "ix/lazyboy"
license: BSD3
author: "Rose"
Expand Down
41 changes: 41 additions & 0 deletions src/Lazyboy/Prelude.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{-|
Module : Lazyboy.Prelude
Description : Convenience aliases for Lazyboy which share names with Haskell's Prelude.
Copyright : (c) Rose 2019
License : BSD3
Maintainer : rose@lain.org.uk
Stability : experimental
Portability : POSIX
This module defines aliases for Lazyboy functions which share names with entities in Haskell's
Prelude library. These are presented for the user to optionally import.
-}

module Lazyboy.Prelude where

import Lazyboy (Condition, Lazyboy, Comparable)
import qualified Lazyboy.Control as Lazyboy

-- | Overload the == (equality) operator for use in Lazyboy.
(==) :: Comparable a b => a -> b -> Lazyboy Condition
(==) = Lazyboy.equalTo

-- | Overload the /= (inequality) operator for use in Lazyboy.
(/=) :: Comparable a b => a -> b -> Lazyboy Condition
(/=) = Lazyboy.notEqualTo

-- | Overload the > (greater than) operator for use in Lazyboy.
(>) :: Comparable a b => a -> b -> Lazyboy Condition
(>) = Lazyboy.greaterThan

-- | Overload the < (lesser than) operator for use in Lazyboy.
(<) :: Comparable a b => a -> b -> Lazyboy Condition
(<) = Lazyboy.lessThan

-- | Overload the && (AND) operator for use in Lazyboy.
(&&) :: Lazyboy Condition -> Lazyboy Condition -> Lazyboy Condition
(&&) = Lazyboy.and

-- | Overload the || (OR) operator for use in Lazyboy.
(||) :: Lazyboy Condition -> Lazyboy Condition -> Lazyboy Condition
(||) = Lazyboy.or

0 comments on commit 126f205

Please sign in to comment.