Last active
June 2, 2017 07:30
-
-
Save pi8027/619946 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 3, 3, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 128, 8, 3, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
48, 64, 16, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
48, 64, 52, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 64, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 128, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# # | |
## ## ## | |
# # ## ## | |
## # # ## | |
## # # ## # # | |
# # # | |
# # | |
## |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <hpgcc49.h> | |
#define VRAM_SIZE 1600 | |
#define SCREEN_WIDTH 17 | |
#define SCREEN_WIDTH_ 20 | |
#define SCREEN_HEIGHT 80 | |
#define VRAM_ACC(vram, x, y) (vram[(x) + (y) * SCREEN_WIDTH_]) | |
unsigned char life_table[64]; | |
char vram_buf1[2 * SCREEN_WIDTH_ + VRAM_SIZE] = | |
{ | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
#include "glider_gun.h" | |
}, | |
vram_buf2[2 * SCREEN_WIDTH_ + VRAM_SIZE]; | |
unsigned int popcount(unsigned int bits) | |
{ | |
unsigned int result = 0; | |
for(; bits; bits >>= 1) result += bits&1; | |
return result; | |
} | |
void init_life_table(void) | |
{ | |
size_t i, j; | |
for(i = 0; i != 64; i++){ | |
unsigned char wval = 0; | |
for(j = 0; j != 8; j++){ | |
unsigned int dots = popcount(i << 3 | j); | |
wval = wval << 1 | (dots == 3 || ((i & 16) && dots == 4)); | |
} | |
life_table[i] = wval; | |
} | |
} | |
void life_next(char *oldmem, char *newmem) | |
{ | |
size_t x, y, z; | |
for(y = 0; y != SCREEN_HEIGHT; y++){ | |
unsigned int r1 = VRAM_ACC(oldmem, 0, y - 1) << 1, | |
r2 = VRAM_ACC(oldmem, 0, y) << 1, | |
r3 = VRAM_ACC(oldmem, 0, y + 1) << 1; | |
for(x = 0; x != SCREEN_WIDTH; x++){ | |
unsigned char wval = 0; | |
for(z = 0; z != 8; z++){ | |
wval = (wval >> 1) | (128 & (life_table[r2 << 3 | r1] << r3)); | |
r1 >>= 1, r2 >>= 1, r3 >>= 1; | |
if(z == 4){ | |
r1 |= VRAM_ACC(oldmem, x + 1, y - 1) << 4; | |
r2 |= VRAM_ACC(oldmem, x + 1, y) << 4; | |
r3 |= VRAM_ACC(oldmem, x + 1, y + 1) << 4; | |
} | |
} | |
VRAM_ACC(newmem, x, y) = wval; | |
} | |
} | |
} | |
int main(void) | |
{ | |
volatile char *vram = getLCDPointer(0, 0); | |
char *vram_p1 = vram_buf1 + SCREEN_WIDTH_, | |
*vram_p2 = vram_buf2 + SCREEN_WIDTH_; | |
init_life_table(); | |
while(!keyb_isON()){ | |
char *tmp; | |
memcpy((char *)vram, vram_p1, VRAM_SIZE); | |
//WAIT_CANCEL; | |
life_next(vram_p1, vram_p2); | |
tmp = vram_p1; | |
vram_p1 = vram_p2; | |
vram_p2 = tmp; | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Data.List | |
import Control.Applicative | |
import Control.Monad | |
main = do | |
c <- lines <$> getContents | |
forM_ c $ \l -> do | |
let l' = intercalate ", " $ | |
map (reverse . take 3 . (++ repeat ' ') . reverse . show) $ | |
take 20 (str2byteseq l ++ repeat 0) | |
putStrLn $ l' ++ "," | |
str2byteseq :: String -> [Int] | |
str2byteseq [] = [] | |
str2byteseq s = | |
let (s1, s2) = splitAt 8 s in str2byte 1 s1 : str2byteseq s2 | |
str2byte :: Int -> String -> Int | |
str2byte b [] = 0 | |
str2byte b (c : s) = str2byte (2 * b) s + (b * if c /= ' ' then 1 else 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment