Skip to content
This repository has been archived by the owner on Apr 25, 2021. It is now read-only.

Commit

Permalink
Release OpenPython firmware v1.0.0
Browse files Browse the repository at this point in the history
- Python Interpreter
  • Loading branch information
EcmaXp committed Oct 18, 2018
1 parent 2fb37b0 commit cf59f93
Show file tree
Hide file tree
Showing 6 changed files with 13,178 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ open class OpenPythonArchitecture(val machine: Machine) : Architecture {
close()

try {
val firmware = OpenPythonFirmware("debug") // TODO: OpenPythonFirmware mapping
val firmware = OpenPythonFirmware("v1.0.0") // TODO: OpenPythonFirmware mapping
recomputeMemory(machine.host().internalComponents())
vm = OpenPythonVirtualMachine(machine, totalMemory, firmware)
} catch (e: Exception) {
Expand Down
63 changes: 63 additions & 0 deletions src/main/resources/assets/openpython/firmwares/v1.0.0/eeprom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
--[==[
"""OpenPython EEPROM"""


def main():
globals().pop('main')
from ucomponent import invoke, get_list as get_components
from ucomputer import crash, get_computer_address

def component(t):
seq = get_components(t)
return seq[0] if seq else None

def check_bootable(filesystems, address):
return address in filesystems and invoke(address, 'exists', '/init.py')

eeprom = __path__
filesystems = get_components("filesystem")

address = invoke(eeprom, 'getData').decode()
if not check_bootable(filesystems, address):
invoke(__path__, 'setData', b'')
for address in filesystems:
if check_bootable(filesystems, address):
invoke(eeprom, 'setData', address.encode())
break
else:
crash("no bootable medium found")

computer = get_computer_address()
invoke(computer, 'beep', 1000, 0.2)

gpu = component("gpu")
monitor = component("monitor")
if gpu and monitor:
invoke(gpu, "bind", monitor)

def load(address):
handle = invoke(address, 'open', '/init.py', 'r')
buffer = []

try:
while True:
buf = invoke(address, 'read', handle, 4096)
if not buf: break
buffer.append(buf)
finally:
invoke(address, 'close', handle)
handle.dispose()

content = b"".join(buffer)
return content.decode()

content = load(address)
context = {'__name__': '__main__', '__path__': address}
func = compile(content, '/init.py', "exec")
exec(func, context)


if __name__ == '__main__':
main()

# ]==] error "This EEPROM requires a CPU running the OpenPython architecture."
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit cf59f93

Please sign in to comment.