forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add port to original Xbox using nxdk
- Loading branch information
Showing
6 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
include ../../py/mkenv.mk | ||
|
||
# qstr definitions (must come before including py.mk) | ||
QSTR_DEFS = qstrdefsport.h | ||
|
||
# include py core make definitions | ||
include $(TOP)/py/py.mk | ||
|
||
#CROSS_COMPILE = arm-none-eabi- | ||
|
||
INC += -I. | ||
INC += -I$(TOP) | ||
INC += -I$(BUILD) | ||
|
||
CFLAGS := $(INC) -Wall | ||
|
||
#Debugging/Optimization | ||
#ifeq ($(DEBUG), 1) | ||
#CFLAGS += -O0 -ggdb | ||
#else | ||
#CFLAGS += -Os -DNDEBUG | ||
#endif | ||
|
||
#LDFLAGS = -nostdlib -T stm32f405.ld [email protected] --cref | ||
|
||
SRC_C = \ | ||
main.c | ||
|
||
#SRC_S = \ | ||
# startup_stm32f40xx.s \ | ||
# gchelper.s \ | ||
OBJ += $(PY_CORE_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o)) | ||
|
||
# Add stuff to nxdk target | ||
main.exe: $(OBJ) | ||
|
||
XBE_TITLE = micropython | ||
|
||
#FIXME: Remove path | ||
NXDK_DIR=/home/fox/Data/Projects/XboxDev/nxdk | ||
include $(NXDK_DIR)/Makefile | ||
|
||
#FIXME: This is a cruel hack because uPython sucks a bit (unistd.h) | ||
CFLAGS := $(NXDK_CFLAGS) -Dssize_t=int -DSEEK_SET=0 -DSEEK_CUR=1 -DSEEK_END=2 | ||
CXXFLAGS := $(NXDK_CXXFLAGS) | ||
ASFLAGS := $(NXDK_ASFLAGS) | ||
LDFLAGS := $(NXDK_LDFLAGS) | ||
|
||
include $(TOP)/py/mkrules.mk |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Build Instructions for original Xbox using nxdk | ||
|
||
The tool chain required for the build can be found at <https://github.com/XboxDev/nxdk>. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include "py/compile.h" | ||
#include "py/runtime.h" | ||
#include "py/repl.h" | ||
#include "py/mperrno.h" | ||
|
||
#include <hal/debug.h> | ||
#include <pbkit/pbkit.h> | ||
#include <hal/xbox.h> | ||
#include <hal/video.h> | ||
|
||
void do_str(const char *src, mp_parse_input_kind_t input_kind) { | ||
nlr_buf_t nlr; | ||
if (nlr_push(&nlr) == 0) { | ||
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); | ||
qstr source_name = lex->source_name; | ||
mp_parse_tree_t parse_tree = mp_parse(lex, input_kind); | ||
mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true); | ||
mp_call_function_0(module_fun); | ||
nlr_pop(); | ||
} else { | ||
// uncaught exception | ||
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val); | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
|
||
XVideoSetMode(640, 480, 32, REFRESH_DEFAULT); | ||
|
||
int ret = pb_init(); | ||
if (ret != 0) { | ||
XSleep(2000); | ||
return 1; | ||
} | ||
|
||
pb_show_debug_screen(); | ||
|
||
mp_init(); | ||
do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT); | ||
do_str("for i in range(10):\n print(i)", MP_PARSE_FILE_INPUT); | ||
mp_deinit(); | ||
return 0; | ||
} | ||
|
||
mp_lexer_t *mp_lexer_new_from_file(const char *filename) { | ||
mp_raise_OSError(MP_ENOENT); | ||
} | ||
|
||
mp_import_stat_t mp_import_stat(const char *path) { | ||
return MP_IMPORT_STAT_NO_EXIST; | ||
} | ||
|
||
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { | ||
return mp_const_none; | ||
} | ||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); | ||
|
||
void nlr_jump_fail(void *val) { | ||
while (1); | ||
} | ||
|
||
void NORETURN __fatal_error(const char *msg) { | ||
while (1); | ||
} | ||
|
||
#ifndef NDEBUG | ||
void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) { | ||
printf("Assertion '%s' failed, at file %s:%d\n", expr, file, line); | ||
__fatal_error("Assertion failed"); | ||
} | ||
#endif | ||
|
||
/* | ||
int _lseek() {return 0;} | ||
int _read() {return 0;} | ||
int _write() {return 0;} | ||
int _close() {return 0;} | ||
void _exit(int x) {for(;;){}} | ||
int _sbrk() {return 0;} | ||
int _kill() {return 0;} | ||
int _getpid() {return 0;} | ||
int _fstat() {return 0;} | ||
int _isatty() {return 0;} | ||
*/ | ||
|
||
#if 0 | ||
void *malloc(size_t n) {return NULL;} | ||
void *calloc(size_t nmemb, size_t size) {return NULL;} | ||
void *realloc(void *ptr, size_t size) {return NULL;} | ||
void free(void *p) {} | ||
int printf(const char *m, ...) {return 0;} | ||
void *memcpy(void *dest, const void *src, size_t n) {return NULL;} | ||
int memcmp(const void *s1, const void *s2, size_t n) {return 0;} | ||
void *memmove(void *dest, const void *src, size_t n) {return NULL;} | ||
void *memset(void *s, int c, size_t n) {return NULL;} | ||
int strcmp(const char *s1, const char* s2) {return 0;} | ||
int strncmp(const char *s1, const char* s2, size_t n) {return 0;} | ||
size_t strlen(const char *s) {return 0;} | ||
char *strcat(char *dest, const char *src) {return NULL;} | ||
char *strchr(const char *dest, int c) {return NULL;} | ||
#include <stdarg.h> | ||
int vprintf(const char *format, va_list ap) {return 0;} | ||
int vsnprintf(char *str, size_t size, const char *format, va_list ap) {return 0;} | ||
#endif | ||
|
||
#undef putchar |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <stdint.h> | ||
|
||
// options to control how MicroPython is built | ||
|
||
#define MICROPY_QSTR_BYTES_IN_HASH (1) | ||
#define MICROPY_ALLOC_PATH_MAX (512) | ||
#define MICROPY_EMIT_X64 (0) | ||
#define MICROPY_EMIT_THUMB (0) | ||
#define MICROPY_EMIT_INLINE_THUMB (0) | ||
#define MICROPY_COMP_MODULE_CONST (0) | ||
#define MICROPY_COMP_CONST (0) | ||
#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (0) | ||
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0) | ||
#define MICROPY_MEM_STATS (0) | ||
#define MICROPY_DEBUG_PRINTERS (0) | ||
#define MICROPY_ENABLE_GC (0) | ||
#define MICROPY_HELPER_REPL (0) | ||
#define MICROPY_HELPER_LEXER_UNIX (0) | ||
#define MICROPY_ENABLE_SOURCE_LINE (0) | ||
#define MICROPY_ENABLE_DOC_STRING (0) | ||
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE) | ||
#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (0) | ||
#define MICROPY_PY_ASYNC_AWAIT (0) | ||
#define MICROPY_PY_BUILTINS_BYTEARRAY (0) | ||
#define MICROPY_PY_BUILTINS_MEMORYVIEW (0) | ||
#define MICROPY_PY_BUILTINS_ENUMERATE (0) | ||
#define MICROPY_PY_BUILTINS_FROZENSET (0) | ||
#define MICROPY_PY_BUILTINS_REVERSED (0) | ||
#define MICROPY_PY_BUILTINS_SET (0) | ||
#define MICROPY_PY_BUILTINS_SLICE (0) | ||
#define MICROPY_PY_BUILTINS_PROPERTY (0) | ||
#define MICROPY_PY___FILE__ (0) | ||
//#define MICROPY_PY_GC (0) | ||
#define MICROPY_PY_ARRAY (0) | ||
#define MICROPY_PY_ATTRTUPLE (0) | ||
#define MICROPY_PY_COLLECTIONS (0) | ||
#define MICROPY_PY_MATH (0) | ||
#define MICROPY_PY_CMATH (0) | ||
#define MICROPY_PY_IO (0) | ||
#define MICROPY_PY_STRUCT (0) | ||
#define MICROPY_PY_SYS (0) | ||
#define MICROPY_CPYTHON_COMPAT (0) | ||
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE) | ||
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE) | ||
#define MICROPY_USE_INTERNAL_PRINTF (0) | ||
#define MICROPY_NLR_SETJMP (1) | ||
|
||
// type definitions for the specific machine | ||
|
||
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1)) | ||
|
||
#define UINT_FMT "%lu" | ||
#define INT_FMT "%ld" | ||
|
||
typedef int32_t mp_int_t; // must be pointer size | ||
typedef uint32_t mp_uint_t; // must be pointer size | ||
typedef long mp_off_t; | ||
|
||
// dummy print | ||
#define MP_PLAT_PRINT_STRN(str, len) do { debugPrint("%s", str); } while (0) | ||
|
||
// extra built in names to add to the global namespace | ||
#define MICROPY_PORT_BUILTINS \ | ||
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, | ||
|
||
// We need to provide a declaration/definition of alloca() | ||
//#include <alloca.h> | ||
#define alloca(x) __builtin_alloca(x) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty file |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// qstrs specific to this port |