1+ # Bad Apple on Presto.
2+ #
3+ # To create the badapple240x240.bin file for the SD card see
4+ # https://github.com/MichaelBell/badapple/tree/presto
5+ # and use the "bit_dump240.py" script in that repo.
6+
17from time import ticks_us
28
39import machine
410import micropython
511from picographics import DISPLAY_PRESTO , PicoGraphics
12+
613from presto import Presto
714
815machine .freq (264000000 )
916
10- import machine
11- import sdcard
12- import uos
17+ import sdcard # noqa: E402
18+ import uos # noqa: E402
1319
1420try :
1521 # Setup for SD Card
2430
2531# Setup for the Presto display
2632presto = Presto ()
27- display = PicoGraphics (DISPLAY_PRESTO , buffer = memoryview (presto ))
33+ display = PicoGraphics (DISPLAY_PRESTO , buffer = memoryview (presto . presto ))
2834WIDTH , HEIGHT = display .get_bounds ()
2935
3036# Read the bad apple video file from the SD card
3541tick_increment = 1000000 // 30
3642next_tick = ticks_us ()
3743
44+
3845# This Micropython Viper function is compiled to native code
3946# for maximum execution speed.
4047@micropython .viper
41- def render (data :ptr8 , x :int , y :int , next_tick :int ): # noqa: F821
48+ def render (data : ptr8 , x : int , y : int , next_tick : int ): # noqa: F821
4249 for i in range (0 , 1024 , 2 ):
4350 # The encoded video data is an array of span lengths and
4451 # greyscale colour values
@@ -59,7 +66,7 @@ def render(data:ptr8, x:int, y:int, next_tick:int): # noqa: F821
5966 y += 1
6067 x = 0
6168 if y >= 240 :
62- presto .update (display )
69+ presto .update ()
6370
6471 # Wait until the next frame at 15FPS
6572 next_tick += 1000000 // 15
@@ -69,6 +76,7 @@ def render(data:ptr8, x:int, y:int, next_tick:int): # noqa: F821
6976
7077 return x , y , next_tick
7178
79+
7280# Read out the file and render
7381while True :
7482 data = video .read (1024 )
0 commit comments