├── fpdoom ├── include │ ├── math.h │ ├── sys │ │ ├── time.h │ │ └── stat.h │ ├── signal.h │ ├── time.h │ ├── fcntl.h │ ├── errno.h │ ├── values.h │ ├── assert.h │ ├── unistd.h │ ├── ctype.h │ ├── stdlib.h │ └── stdio.h ├── cxx_init.h ├── usbio.h ├── start2.s ├── sdio.h ├── cmd_def.h ├── helper.make ├── fatfile.h ├── sc6531e_fdl1.ld ├── doomkey.h ├── sc6531e_fdl.ld ├── Makefile ├── keytrn_pc.c ├── init_sc6530.h ├── start1.s ├── start.s ├── sfc.h ├── keytrn.c ├── common.h ├── entry2.c ├── microfat.h ├── syscode.h ├── init_sc6531e.h ├── init_sc6531da.h ├── libc │ └── printf.h └── lcd_spi.h ├── fpbuild ├── eduke32 │ ├── fix16.h │ ├── joystick.h │ ├── renderlayer.h │ ├── version.c │ ├── palette.h │ ├── common.h │ ├── vfs.h │ └── compat.cpp ├── jfaudiolib │ └── include │ │ ├── sndcards.h │ │ ├── music.h │ │ └── fx_man.h ├── helper.make ├── a-new.c ├── calctables.c ├── unistd.c ├── README.md ├── jfmact.patch └── Makefile ├── pack_reloc └── Makefile ├── fptest └── Makefile ├── chocolate-doom ├── SDL2_dummy │ ├── SDL_endian.h │ └── SDL.h ├── config.h ├── helper.make ├── README.md ├── port_hacks.c └── Makefile ├── fpmenu ├── start3.s ├── start3_t117.s ├── Makefile ├── readbin.c ├── config.txt └── readconf.h ├── libc_server ├── Makefile └── cmd_def.h ├── sdboot ├── jump4m.s ├── Makefile ├── start.s ├── main.c ├── README.md └── entry.c ├── ums9117 ├── start2.s ├── ums9117_fdl1.ld ├── ums9117_fdl2.ld ├── README.md ├── start.s ├── start1.s ├── entry2.c ├── syscomm.c ├── init_t117.h ├── lcd_spi.h └── usbio.c ├── wolf3d ├── helper.make ├── README.md ├── wlsys_def.h ├── Makefile ├── calctables.c ├── extra.c └── wlsys_fp.c ├── infones ├── helper.make ├── Makefile └── README.md ├── gnuboy ├── helper.make ├── port_hacks.c ├── README.md ├── Makefile └── gbasm.s ├── sdboot_t117 ├── Makefile ├── README.md ├── main.c ├── entry.c └── start.s ├── LICENSE ├── pctest └── syscode.h ├── snes9x ├── helper.make ├── Makefile └── README.md └── release.make /fpdoom/include/math.h: -------------------------------------------------------------------------------- 1 | #ifndef __MATH 2 | #define __MATH 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /fpbuild/eduke32/fix16.h: -------------------------------------------------------------------------------- 1 | #ifndef FIX16_H 2 | #define FIX16_H 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /fpbuild/eduke32/joystick.h: -------------------------------------------------------------------------------- 1 | #ifndef JOYSTICK_H 2 | #define JOYSTICK_H 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /fpdoom/include/sys/time.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYS_TIME 2 | #define __SYS_TIME 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /fpbuild/eduke32/renderlayer.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDERLAYER_H 2 | #define RENDERLAYER_H 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /fpbuild/jfaudiolib/include/sndcards.h: -------------------------------------------------------------------------------- 1 | #ifndef __SNDCARDS_H 2 | #define __SNDCARDS_H 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /fpbuild/eduke32/version.c: -------------------------------------------------------------------------------- 1 | const char *s_buildRev = "(not set)"; 2 | const char *s_buildTimestamp = __DATE__ " " __TIME__; 3 | -------------------------------------------------------------------------------- /fpbuild/jfaudiolib/include/music.h: -------------------------------------------------------------------------------- 1 | #ifndef __MUSIC_H 2 | #define __MUSIC_H 3 | 4 | static inline void MUSIC_RegisterTimbreBank(unsigned char* a) {} 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /fpdoom/include/signal.h: -------------------------------------------------------------------------------- 1 | #ifndef __SIGNAL 2 | #define __SIGNAL 3 | 4 | typedef void (*sighandler_t)(int); 5 | 6 | sighandler_t signal(int signum, sighandler_t handler); 7 | 8 | #define SIGINT 2 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /fpdoom/include/time.h: -------------------------------------------------------------------------------- 1 | #ifndef __TIME 2 | #define __TIME 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef long time_t; 9 | 10 | time_t time (time_t*); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /fpdoom/include/fcntl.h: -------------------------------------------------------------------------------- 1 | #ifndef __FCNTL 2 | #define __FCNTL 3 | 4 | #define O_ACCMODE 00000003 5 | #define O_RDONLY 00000000 6 | #define O_WRONLY 00000001 7 | #define O_RDWR 00000002 8 | #define O_CREAT 00000100 9 | #define O_TRUNC 00001000 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /pack_reloc/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CFLAGS = -O2 -Wall -Wextra -std=c99 -pedantic -Wno-unused 3 | APPNAME = pack_reloc 4 | 5 | .PHONY: all clean 6 | all: $(APPNAME) 7 | 8 | clean: 9 | $(RM) $(APPNAME) 10 | 11 | $(APPNAME): $(APPNAME).c 12 | $(CC) -s $(CFLAGS) -o $@ $^ 13 | -------------------------------------------------------------------------------- /fpdoom/include/errno.h: -------------------------------------------------------------------------------- 1 | #ifndef __ERRNO 2 | #define __ERRNO 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern int *__errno(void); 9 | #define errno (*__errno()) 10 | 11 | #define ENOENT 2 12 | #define EINVAL 22 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | #endif 18 | -------------------------------------------------------------------------------- /fpdoom/cxx_init.h: -------------------------------------------------------------------------------- 1 | typedef void (*ctor_t)(int, char**, char**); 2 | extern ctor_t __init_array_start[1]; 3 | extern ctor_t __init_array_end[1]; 4 | 5 | static inline void cxx_init(int argc, char **argv) { 6 | ctor_t *p = __init_array_start; 7 | for (; p != __init_array_end; p++) 8 | (*p)(argc, argv, NULL); 9 | } 10 | -------------------------------------------------------------------------------- /fpdoom/include/values.h: -------------------------------------------------------------------------------- 1 | #ifndef __VALUES 2 | #define __VALUES 3 | 4 | #define MAXCHAR 0x7f 5 | #define MINCHAR 0x80 6 | #define MAXSHORT 0x7fff 7 | #define MINSHORT 0x8000 8 | #define MAXINT 0x7fffffff 9 | #define MININT 0x80000000 10 | #define MAXLONG 0x7fffffff 11 | #define MINLONG 0x80000000 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /fptest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = fptest 2 | TWO_STAGE = 0 3 | 4 | SYS_EXTRA = sdio microfat sfc 5 | 6 | APP_SRCS = main 7 | APP_OBJS1 = $(APP_SRCS:%=$(OBJDIR)/app/%.o) 8 | APP_OBJS2 = 9 | 10 | include ../buildinc.make 11 | 12 | #CFLAGS += -DSDIO_VERBOSE=2 13 | 14 | APP_CFLAGS += -std=c99 -pedantic 15 | APP_CFLAGS += -I$(SYSDIR) 16 | -------------------------------------------------------------------------------- /fpdoom/include/assert.h: -------------------------------------------------------------------------------- 1 | #ifndef __ASSERT 2 | #define __ASSERT 3 | 4 | #ifdef NDEBUG 5 | #define assert(e) ((void)0) 6 | #else 7 | #define assert(e) ((e) ? (void)0 : __assert2(__FILE__, __LINE__, __func__, #e)) 8 | #endif 9 | 10 | __attribute__((noreturn)) 11 | void __assert2(const char *, int, const char *, const char *); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /fpdoom/usbio.h: -------------------------------------------------------------------------------- 1 | #ifndef USBIO_H 2 | #define USBIO_H 3 | 4 | #include "common.h" 5 | 6 | void usb_init_base(void); 7 | void usb_init(void); 8 | int usb_getchar(int wait); 9 | int usb_read(void *dst, unsigned len, int wait); 10 | int usb_write(const void *src, unsigned len); 11 | 12 | #define USB_WAIT 1 13 | #define USB_NOWAIT 0 14 | 15 | #endif // USBIO_H 16 | -------------------------------------------------------------------------------- /chocolate-doom/SDL2_dummy/SDL_endian.h: -------------------------------------------------------------------------------- 1 | #ifndef SDL_endian_h_ 2 | #define SDL_endian_h_ 3 | 4 | #define SDL_BYTEORDER __BYTE_ORDER__ 5 | #define SDL_LIL_ENDIAN __ORDER_LITTLE_ENDIAN__ 6 | #define SDL_BIG_ENDIAN __ORDER_BIG_ENDIAN__ 7 | 8 | #if SDL_BYTEORDER == SDL_LIL_ENDIAN 9 | #define SDL_SwapLE16(x) (x) 10 | #define SDL_SwapLE32(x) (x) 11 | #else 12 | #error 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /fpmenu/start3.s: -------------------------------------------------------------------------------- 1 | @ -*- tab-width: 8 -*- 2 | .arch armv5te 3 | .syntax unified 4 | 5 | .macro CODE32_FN name 6 | .section .text.\name, "ax", %progbits 7 | .p2align 2 8 | .code 32 9 | .type \name, %function 10 | .global \name 11 | \name: 12 | .endm 13 | 14 | CODE32_FN _start 15 | bl __image_end 16 | .long __image_size 17 | // ldr sp, 1f 18 | blx entry_main 19 | //1: .long 0x40009000 20 | -------------------------------------------------------------------------------- /libc_server/Makefile: -------------------------------------------------------------------------------- 1 | 2 | LIBUSB = 1 3 | CFLAGS = -O2 -Wall -Wextra -std=c99 -pedantic -Wno-unused 4 | CFLAGS += -DUSE_LIBUSB=$(LIBUSB) 5 | APPNAME = libc_server 6 | 7 | ifeq ($(LIBUSB), 1) 8 | LIBS = -lusb-1.0 9 | endif 10 | 11 | .PHONY: all clean 12 | all: $(APPNAME) 13 | 14 | clean: 15 | $(RM) $(APPNAME) 16 | 17 | $(APPNAME): $(APPNAME).c cmd_def.h 18 | $(CC) -s $(CFLAGS) -o $@ $^ $(LIBS) 19 | -------------------------------------------------------------------------------- /chocolate-doom/SDL2_dummy/SDL.h: -------------------------------------------------------------------------------- 1 | #ifndef SDL_h_ 2 | #define SDL_h_ 3 | 4 | typedef void *SDL_Event; 5 | typedef void *SDL_Window; 6 | 7 | static inline void SDL_Quit(void) {} 8 | 9 | #define SDL_ShowSimpleMessageBox(flags, title, message, window) \ 10 | fprintf(stderr, "%s\n", message) 11 | 12 | static inline int SDL_SetHint(const char *name, const char *value) { 13 | return 0; 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /fpdoom/start2.s: -------------------------------------------------------------------------------- 1 | @ -*- tab-width: 8 -*- 2 | .arch armv5te 3 | .syntax unified 4 | 5 | .macro CODE32_FN name 6 | .section .text.\name, "ax", %progbits 7 | .p2align 2 8 | .code 32 9 | .type \name, %function 10 | .global \name 11 | \name: 12 | .endm 13 | 14 | CODE32_FN _start 15 | adr r4, _start 16 | ldr r0, [r4, #16] 17 | add pc, r4, r0 18 | 19 | 1: .long __image_start 20 | .long __image_size 21 | .long __bss_size 22 | .long entry_main2 23 | -------------------------------------------------------------------------------- /chocolate-doom/config.h: -------------------------------------------------------------------------------- 1 | #define PACKAGE_NAME "Chocolate Doom" 2 | #define PACKAGE_TARNAME "chocolate-doom" 3 | #define PACKAGE_VERSION "3.1.0" 4 | #define PACKAGE_STRING PACKAGE_NAME " " PACKAGE_VERSION 5 | #define PROGRAM_PREFIX "chocolate-" 6 | 7 | /* #undef HAVE_FLUIDSYNTH */ 8 | /* #undef HAVE_LIBSAMPLERATE */ 9 | /* #undef HAVE_LIBPNG */ 10 | #if EMBEDDED == 1 && GAME_STRIFE 11 | #define HAVE_DIRENT_H 12 | #endif 13 | #define HAVE_DECL_STRCASECMP 1 14 | #define HAVE_DECL_STRNCASECMP 1 15 | -------------------------------------------------------------------------------- /fpmenu/start3_t117.s: -------------------------------------------------------------------------------- 1 | @ -*- tab-width: 8 -*- 2 | .arch armv7-a 3 | .syntax unified 4 | 5 | .macro CODE32_FN name 6 | .section .text.\name, "ax", %progbits 7 | .p2align 2 8 | .code 32 9 | .type \name, %function 10 | .global \name 11 | \name: 12 | .endm 13 | 14 | CODE32_FN _start 15 | .ascii "DHTB" 16 | .long 1 17 | .org _start + 0x30, 0 18 | .long __image_size - 0x200 19 | .org _start + 0x200, 0 20 | 21 | bl __image_end + 0x200 22 | .long __image_size 23 | 24 | blx entry_main 25 | 26 | -------------------------------------------------------------------------------- /fpdoom/sdio.h: -------------------------------------------------------------------------------- 1 | #ifndef SDIO_H 2 | #define SDIO_H 3 | 4 | #ifndef SDIO_VERBOSE 5 | #define SDIO_VERBOSE 1 6 | #endif 7 | 8 | extern unsigned sdio_shl; 9 | 10 | void sdio_init(void); 11 | int sdcard_init(void); 12 | int sdio_read_block(uint32_t idx, uint8_t *buf); 13 | int sdio_write_block(uint32_t idx, uint8_t *buf); 14 | 15 | #if SDIO_VERBOSE > 1 16 | extern int sdio_verbose; 17 | #define SDIO_VERBOSITY(level) (sdio_verbose = (level)) 18 | #else 19 | #define SDIO_VERBOSITY(level) (void)0 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /fpdoom/include/sys/stat.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYS_STAT 2 | #define __SYS_STAT 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | int mkdir(const char*, int); 9 | 10 | struct stat { 11 | int st_mode, st_size, st_mtime; 12 | }; 13 | 14 | int fstat(int, struct stat*); 15 | int stat(const char*, struct stat*); 16 | int fstatat(int, const char*, struct stat*, int); 17 | 18 | #define S_IFDIR 0040000 19 | 20 | #define S_IRWXU 00700 21 | #define S_IRUSR 00400 22 | #define S_IWUSR 00200 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | #endif 28 | -------------------------------------------------------------------------------- /sdboot/jump4m.s: -------------------------------------------------------------------------------- 1 | @ -*- tab-width: 8 -*- 2 | .arch armv5te 3 | .syntax unified 4 | 5 | .section .text, "ax", %progbits 6 | .p2align 2 7 | .type _start, %function 8 | .global _start 9 | 10 | // SC6530/SC6531 devices only have access to the first 4MB 11 | // of flash memory when booting. This trampoline is required 12 | // if the sdboot section is located after 4MB. 13 | 14 | .long 0x000a3d3d 15 | 2: .long 0xffffffff 16 | .code 32 17 | _start: 18 | ldr r0, 1f 19 | mov r1, #16 20 | str r1, [r0] 21 | ldr pc, 2b 22 | 23 | 1: .long 0x20a00200 24 | -------------------------------------------------------------------------------- /fpbuild/eduke32/palette.h: -------------------------------------------------------------------------------- 1 | #ifndef PALETTE_H 2 | #define PALETTE_H 3 | 4 | #include "common_game.h" 5 | #ifdef kMaxPAL 6 | #define BASEPALCOUNT kMaxPAL 7 | #else 8 | #define BASEPALCOUNT 5 9 | #endif 10 | 11 | extern uint8_t basepaltable[BASEPALCOUNT][768]; 12 | 13 | void paletteSetColorTable(int32_t id, const uint8_t *table); 14 | 15 | static inline 16 | void videoSetPalette(char dabrightness, uint8_t dapalid, uint8_t flags) { 17 | setbrightness(dabrightness, basepaltable[dapalid], flags); 18 | } 19 | 20 | #define paletteFreeLookupTable(x) 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /fpbuild/eduke32/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | extern uint32_t wrandomseed; 5 | 6 | static inline void wsrand(int seed) { 7 | wrandomseed = seed; 8 | } 9 | 10 | // This aims to mimic Watcom C's implementation of rand 11 | static inline int wrand(void) { 12 | wrandomseed = 1103515245 * wrandomseed + 12345; 13 | return (wrandomseed >> 16) & 0x7fff; 14 | } 15 | 16 | #define strnlen strnlen_new 17 | static inline size_t strnlen(const char *s, size_t len) { 18 | size_t n = 0; 19 | while (n < len && s[n]) n++; 20 | return n; 21 | } 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /fpdoom/include/unistd.h: -------------------------------------------------------------------------------- 1 | #ifndef __UNISTD 2 | #define __UNISTD 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | int open(const char*, int, ...); 11 | int close(int); 12 | ssize_t read(int, void*, size_t); 13 | ssize_t write(int, const void*, size_t); 14 | off_t lseek(int, off_t, int); 15 | char *getcwd(char*, size_t); 16 | int chdir(const char*); 17 | 18 | int access(const char*, int); 19 | 20 | #define R_OK 4 21 | #define W_OK 2 22 | #define X_OK 1 23 | #define F_OK 0 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /ums9117/start2.s: -------------------------------------------------------------------------------- 1 | @ -*- tab-width: 8 -*- 2 | .arch armv7-a 3 | .syntax unified 4 | 5 | .macro CODE32_FN name 6 | .section .text.\name, "ax", %progbits 7 | .p2align 2 8 | .code 32 9 | .type \name, %function 10 | .global \name 11 | \name: 12 | .endm 13 | 14 | CODE32_FN _start 15 | .ascii "DHTB" 16 | .long 1 17 | .org _start + 0x30, 0 18 | .long __image_size - 0x200 19 | .org _start + 0x200, 0 20 | 21 | adr r4, _start 22 | ldr r0, [r4, #0x210] 23 | add pc, r4, r0 24 | 25 | 1: .long __image_start 26 | .long __image_size 27 | .long __bss_size 28 | .long entry_main2 29 | -------------------------------------------------------------------------------- /libc_server/cmd_def.h: -------------------------------------------------------------------------------- 1 | enum { 2 | HOST_CONNECT = 0x00, 3 | 4 | CMD_MESSAGE = 0x80, 5 | CMD_FOPEN = 0x81, 6 | CMD_FREAD = 0x82, 7 | CMD_FWRITE = 0x83, 8 | CMD_FCLOSE = 0x84, 9 | CMD_FSEEK = 0x85, 10 | CMD_FTELL = 0x86, 11 | CMD_GETARGS = 0x87, 12 | CMD_RESETIO = 0x88, 13 | CMD_USBBENCH = 0x89, 14 | }; 15 | 16 | #define CHECKSUM_INIT 0x5a5a 17 | 18 | #define MAX_FILES 255 19 | #define MAX_IOSIZE 0x4000 20 | 21 | #define _IO_LINEBUF 1 22 | #define _IO_WRITE 2 23 | #define _IO_PIPE 4 24 | #define _IO_APPEND 8 25 | 26 | #define _ARGV_GET_ARGC 1 27 | #define _ARGV_GET_SIZE 2 28 | #define _ARGV_GET_ARGV 4 29 | 30 | -------------------------------------------------------------------------------- /wolf3d/helper.make: -------------------------------------------------------------------------------- 1 | 2 | ZIPDIR = . 3 | Wolf4SDL_hash = dc8b250af35fb0ace68db5eb879490b50068c20e 4 | Wolf4SDL_list = * 5 | 6 | .PHONY: all patch gitinit diff 7 | all: Wolf4SDL 8 | download: $(ZIPDIR)/Wolf4SDL.zip 9 | 10 | $(ZIPDIR)/Wolf4SDL.zip: 11 | wget -O $@ "https://github.com/KS-Presto/Wolf4SDL/archive/$(Wolf4SDL_hash).zip" 12 | 13 | %: $(ZIPDIR)/%.zip 14 | name="$@-$($@_hash)"; unzip -q $< $(patsubst %,"$$name/%",$($@_list)) && mv $$name $@ 15 | 16 | patch: Wolf4SDL 17 | patch -p1 -d Wolf4SDL < wolf3d.patch 18 | 19 | gitinit: Wolf4SDL 20 | cd Wolf4SDL && git init && git add . && git commit -m "init" 21 | 22 | diff: Wolf4SDL/.git 23 | cd Wolf4SDL && git diff > ../wolf3d.patch2 24 | 25 | -------------------------------------------------------------------------------- /infones/helper.make: -------------------------------------------------------------------------------- 1 | 2 | ZIPDIR = . 3 | InfoNES_hash = 363bac8bbb030c3d3708ab32cd719ae6b2919971 4 | InfoNES_list = src/* 5 | 6 | .PHONY: all patch gitinit diff 7 | all: InfoNES 8 | download: $(ZIPDIR)/InfoNES.zip 9 | 10 | $(ZIPDIR)/InfoNES.zip: 11 | wget -O $@ "https://github.com/jay-kumogata/InfoNES/archive/$(InfoNES_hash).zip" 12 | 13 | %: $(ZIPDIR)/%.zip 14 | name="$@-$($@_hash)"; unzip -q $< $(patsubst %,"$$name/%",$($@_list)) && mv $$name $@ 15 | 16 | patch: InfoNES 17 | patch -p1 -d InfoNES < InfoNES.patch 18 | 19 | gitinit: InfoNES 20 | cd InfoNES && git init && git add . && git commit -m "init" 21 | 22 | diff: InfoNES/.git 23 | cd InfoNES && git add . && git diff --staged > ../InfoNES.patch2 24 | 25 | -------------------------------------------------------------------------------- /fpbuild/eduke32/vfs.h: -------------------------------------------------------------------------------- 1 | #ifndef VFS_H 2 | #define VFS_H 3 | 4 | #define buildvfs_fd int 5 | #define buildvfs_fd_invalid (-1) 6 | #define buildvfs_kfd int 7 | #define buildvfs_kfd_invalid (-1) 8 | 9 | #define buildvfs_exists(fn) (access(fn, F_OK) == 0) 10 | 11 | static inline void buildvfs_fputstrptr(FILE *fp, const char *str) { 12 | fwrite(str, 1, strlen(str), fp); 13 | } 14 | 15 | #define BUILDVFS_FIND_REC CACHE1D_FIND_REC 16 | #define BUILDVFS_FIND_FILE CACHE1D_FIND_FILE 17 | #define BUILDVFS_FIND_DIR CACHE1D_FIND_DIR 18 | #define BUILDVFS_SOURCE_GRP CACHE1D_SOURCE_GRP 19 | 20 | #define klistaddentry(rec, name, type, source) (-1) // not supported 21 | #define kfileparent(origfp) ((char*)NULL) // only for GRP files 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /fpdoom/cmd_def.h: -------------------------------------------------------------------------------- 1 | enum { 2 | HOST_CONNECT = 0x00, 3 | 4 | CMD_MESSAGE = 0x80, 5 | CMD_FOPEN = 0x81, 6 | CMD_FREAD = 0x82, 7 | CMD_FWRITE = 0x83, 8 | CMD_FCLOSE = 0x84, 9 | CMD_FSEEK = 0x85, 10 | CMD_FTELL = 0x86, 11 | CMD_GETARGS = 0x87, 12 | CMD_RESETIO = 0x88, 13 | CMD_USBBENCH = 0x89, 14 | }; 15 | 16 | #define CHECKSUM_INIT 0x5a5a 17 | 18 | #define MAX_FILES 255 19 | #if UMS9117 20 | // FIXME: should not request more than the USB buffer size 21 | #define MAX_IOSIZE 0x3000 22 | #else 23 | #define MAX_IOSIZE 0x4000 24 | #endif 25 | 26 | #define _IO_LINEBUF 1 27 | #define _IO_WRITE 2 28 | #define _IO_PIPE 4 29 | #define _IO_APPEND 8 30 | 31 | #define _ARGV_GET_ARGC 1 32 | #define _ARGV_GET_SIZE 2 33 | #define _ARGV_GET_ARGV 4 34 | 35 | -------------------------------------------------------------------------------- /gnuboy/helper.make: -------------------------------------------------------------------------------- 1 | 2 | ZIPDIR = . 3 | gnuboy_hash = c367bb4ba96fb07cd62f72f5ecb43aeff7012564 4 | gnuboy_list = * 5 | gnuboy_DIR = gnuboy 6 | 7 | .PHONY: all patch gitinit diff 8 | all: $(gnuboy_DIR) 9 | download: $(ZIPDIR)/gnuboy.zip 10 | 11 | $(ZIPDIR)/gnuboy.zip: 12 | wget -O $@ "https://github.com/rofl0r/gnuboy/archive/$(gnuboy_hash).zip" 13 | 14 | $(gnuboy_DIR): $(ZIPDIR)/gnuboy.zip 15 | name="gnuboy-$(gnuboy_hash)"; unzip -q $< $(patsubst %,"$$name/%",$($@_list)) && mv $$name $@ 16 | 17 | patch: $(gnuboy_DIR) 18 | patch -p1 -d $(gnuboy_DIR) < gnuboy.patch 19 | 20 | gitinit: $(gnuboy_DIR) 21 | cd $(gnuboy_DIR) && git init && git add . && git commit -m "init" 22 | 23 | diff: $(gnuboy_DIR)/.git 24 | cd $(gnuboy_DIR) && git diff > gnuboy.patch2 25 | 26 | -------------------------------------------------------------------------------- /sdboot_t117/Makefile: -------------------------------------------------------------------------------- 1 | NAME = sdboot_t117 2 | TWO_STAGE = -1 3 | LIBC_SDIO = 3 4 | 5 | OBJS = $(patsubst %,$(OBJDIR)/app/%.o,start entry main) 6 | OBJS += $(patsubst %,$(OBJDIR)/sys/%.o,asmcode usbio common libc syscomm syscode sdio microfat sdram_init) 7 | 8 | include ../build_t117.make 9 | 10 | LDSCRIPT = $(SYSDIR_T117)/ums9117_fdl1.ld 11 | 12 | CFLAGS += -DNO_ADI_LOG=1 13 | CFLAGS += -DSDIO_NO_PINMAP=1 14 | ifeq ($(LIBC_SDIO), 3) 15 | CFLAGS += -DSDIO_VERBOSE=0 -DSDIO_SHL=CHIPRAM_ADDR 16 | endif 17 | CFLAGS := $(filter-out -DFAT_WRITE=1, $(CFLAGS)) 18 | 19 | APP_CFLAGS += -I$(SYSDIR_T117) -I$(SYSDIR) 20 | 21 | $(OBJDIR)/$(NAME).elf: $(OBJS) 22 | $(CC) $(LFLAGS) $(OBJS) -o $@ 23 | 24 | %.bin: $(OBJDIR)/%.elf 25 | $(OBJCOPY) -O binary -j .text $< $@ 26 | 27 | -------------------------------------------------------------------------------- /infones/Makefile: -------------------------------------------------------------------------------- 1 | NAME = infones 2 | INFONES = InfoNES/src 3 | USE_ASM = 1 4 | 5 | APP_SRCS = InfoNES_System scr_update 6 | ifneq ($(USE_ASM), 0) 7 | APP_SRCS += nesasm 8 | endif 9 | NES_SRCS = K6502 InfoNES InfoNES_Mapper InfoNES_pAPU 10 | 11 | APP_OBJS1 = $(APP_SRCS:%=$(OBJDIR)/app/%.o) 12 | APP_OBJS2 = $(NES_SRCS:%=$(OBJDIR)/nes/%.o) 13 | 14 | include ../buildinc.make 15 | 16 | APP_CFLAGS += -std=c99 -pedantic 17 | APP_CFLAGS += -Wno-strict-prototypes 18 | 19 | NES_CFLAGS := $(APP_CFLAGS) -Wno-unused-parameter -Wno-extra-semi 20 | NES_CFLAGS += -DAPU_Mute=1 21 | 22 | APP_CFLAGS += -I$(SYSDIR) -I$(INFONES) 23 | ifneq ($(USE_ASM), 0) 24 | APP_CFLAGS += -DUSE_ASM 25 | endif 26 | 27 | $(OBJDIR)/nes/%.o: $(INFONES)/%.c | objdir 28 | $(call compile_cc,$(NES_CFLAGS)) 29 | 30 | 31 | -------------------------------------------------------------------------------- /fpdoom/helper.make: -------------------------------------------------------------------------------- 1 | 2 | ZIPDIR = . 3 | DOOM_hash = a77dfb96cb91780ca334d0d4cfd86957558007e0 4 | DOOM_list = linuxdoom-1.10/* 5 | DOOM_DIR = ../doom_src 6 | 7 | .PHONY: all patch gitinit diff 8 | all: $(DOOM_DIR) 9 | download: $(ZIPDIR)/DOOM.zip 10 | 11 | $(ZIPDIR)/DOOM.zip: 12 | wget -O $@ "https://github.com/id-Software/DOOM/archive/$(DOOM_hash).zip" 13 | 14 | $(DOOM_DIR): $(ZIPDIR)/DOOM.zip 15 | name="DOOM-$(DOOM_hash)"; unzip -q $< $(patsubst %,"$$name/%",$(DOOM_list)) && mv $$name/linuxdoom-1.10 $@; $(RM) -d $$name 16 | 17 | patch: $(DOOM_DIR) 18 | patch -p1 -d $(DOOM_DIR) < ../doom.patch 19 | 20 | gitinit: $(DOOM_DIR) 21 | cd $(DOOM_DIR) && git init && git add . && git commit -m "init" 22 | 23 | diff: $(DOOM_DIR)/.git 24 | cd $(DOOM_DIR) && git diff > ../doom.patch2 25 | 26 | -------------------------------------------------------------------------------- /fpdoom/fatfile.h: -------------------------------------------------------------------------------- 1 | #ifndef FATFILE_H 2 | #define FATFILE_H 3 | 4 | #include 5 | #include "microfat.h" 6 | 7 | typedef struct fatfile { 8 | #if FAT_WRITE 9 | uint8_t flags, entry_pos; 10 | uint32_t entry_seg; 11 | #endif 12 | uint32_t *chain, start, chain_last; 13 | uint32_t pos, size; 14 | } fatfile_t; 15 | 16 | extern fatdata_t fatdata_glob; 17 | 18 | size_t fat_fread(void *dst, size_t size, size_t count, fatfile_t *f); 19 | size_t fat_fwrite(const void *src, size_t size, size_t count, fatfile_t *f); 20 | int fat_fgetc(fatfile_t *f); 21 | int fat_fputc(int ch, fatfile_t *f); 22 | 23 | fatfile_t *fat_fopen(const char *name, const char *mode); 24 | int fat_fclose(fatfile_t *f); 25 | int fat_fseek(fatfile_t *f, long offset, int origin); 26 | long fat_ftell(fatfile_t *f); 27 | int fat_fflush(fatfile_t *f); 28 | #endif 29 | -------------------------------------------------------------------------------- /fpbuild/jfaudiolib/include/fx_man.h: -------------------------------------------------------------------------------- 1 | #ifndef __FX_MAN_H 2 | #define __FX_MAN_H 3 | 4 | enum FX_ERRORS { FX_Ok = 0 }; 5 | 6 | static inline void FX_SetVolume(int a) {} 7 | static inline void FX_SetReverseStereo(int a) {} 8 | static inline void FX_SetReverb(int a) {} 9 | static inline void FX_SetReverbDelay(int a) {} 10 | static inline int FX_VoiceAvailable(int a) { return 0; } 11 | static inline int FX_EndLooping(int a) { return 0; } 12 | static inline int FX_SetPan(int a, int b, int c, int d) { return 0; } 13 | static inline int FX_SetFrequency(int a, int b ) { return 0; } 14 | static inline int FX_PlayAuto3D(char* a, unsigned b, int c, int d, int e, int f, unsigned g) { return 0; } 15 | static inline int FX_SoundActive(int handle) { return 0; } 16 | static inline int FX_StopSound(int a) { return 0; } 17 | static inline int FX_StopAllSounds(void) { return 0; } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /sdboot/Makefile: -------------------------------------------------------------------------------- 1 | CHIP = 0 2 | NAME := sdboot$(if $(filter 0,$(CHIP)),,$(CHIP)) 3 | TWO_STAGE = -1 4 | LIBC_SDIO = 3 5 | 6 | OBJS = $(patsubst %,$(OBJDIR)/app/%.o,start entry) 7 | OBJS += $(patsubst %,$(OBJDIR)/sys/%.o,sdio microfat) 8 | OBJS += $(OBJDIR)/app/main.o 9 | OBJS += $(patsubst %,$(OBJDIR)/sys/%.o,asmcode usbio common libc syscomm syscode) 10 | 11 | include ../build_sc6531.make 12 | 13 | LDSCRIPT = $(SYSDIR)/sc6531e_fdl1.ld 14 | 15 | CFLAGS += -DSDIO_NO_PINMAP=1 16 | ifeq ($(LIBC_SDIO), 3) 17 | CFLAGS += -DSDIO_VERBOSE=0 -DSDIO_SHL=CHIPRAM_ADDR 18 | endif 19 | CFLAGS := $(filter-out -DFAT_WRITE=1, $(CFLAGS)) 20 | CFLAGS += -DSDBOOTKEY=-1 21 | 22 | APP_CFLAGS += -I$(SYSDIR) 23 | 24 | $(OBJDIR)/$(NAME).elf: $(OBJS) 25 | $(CC) $(LFLAGS) $(OBJS) -o $@ 26 | 27 | jump4m.bin: $(OBJDIR)/app/jump4m.o 28 | $(OBJCOPY) -O binary $< $@ 29 | 30 | %.bin: $(OBJDIR)/%.elf 31 | $(OBJCOPY) -O binary -j .text $< $@ 32 | 33 | -------------------------------------------------------------------------------- /sdboot/start.s: -------------------------------------------------------------------------------- 1 | @ -*- tab-width: 8 -*- 2 | .arch armv5te 3 | .syntax unified 4 | 5 | .macro CODE32_FN name 6 | .section .text.\name, "ax", %progbits 7 | .p2align 2 8 | .code 32 9 | .type \name, %function 10 | .global \name 11 | \name: 12 | .endm 13 | 14 | // 0 : MMU enable 15 | // 2 : Level 1 Data Cache enable 16 | // 12 : Instruction Cache enable 17 | 18 | CODE32_FN _start 19 | b 3f 20 | .long 0xffffffff 21 | .ascii "SDLOADER" 22 | .long __image_size 23 | .global sdbootkey 24 | sdbootkey: // sdboot + 0x14 25 | .long 0xffffffff 26 | 3: mrc p15, #0, r0, c1, c0, #0 // Read Control Register 27 | bic r0, #5 28 | .if 0 29 | bic r0, #0x1000 30 | .else // faster 31 | orr r0, #0x1000 32 | .endif 33 | mcr p15, #0, r0, c1, c0, #0 // Write Control Register 34 | msr cpsr_c, #0xd3 35 | ldr sp, 1f 36 | adr r0, _start 37 | .if 1 38 | blx entry_main 39 | .else 40 | ldr pc, 2f 41 | 2: .long entry_main 42 | .endif 43 | 1: .long 0x40009000 // __stack_bottom 44 | 45 | -------------------------------------------------------------------------------- /chocolate-doom/helper.make: -------------------------------------------------------------------------------- 1 | 2 | ZIPDIR = . 3 | chocolate_doom_hash = 0b3cb528c3f53c61d7a4ebe13a7d522570b98d83 4 | chocolate_doom_list = src/* textscreen/* 5 | chocolate_doom_DIR = chocolate-doom 6 | 7 | .PHONY: all patch gitinit diff 8 | all: $(chocolate_doom_DIR) 9 | download: $(ZIPDIR)/chocolate-doom.zip 10 | 11 | $(ZIPDIR)/chocolate-doom.zip: 12 | wget -O $@ "https://github.com/chocolate-doom/chocolate-doom/archive/$(chocolate_doom_hash).zip" 13 | 14 | $(chocolate_doom_DIR): $(ZIPDIR)/chocolate-doom.zip 15 | name="chocolate-doom-$(chocolate_doom_hash)"; unzip -q $< $(patsubst %,"$$name/%",$(chocolate_doom_list)) && mv $$name $@ 16 | 17 | patch: $(chocolate_doom_DIR) 18 | patch -p1 -d $(chocolate_doom_DIR) < chocolate-doom.patch 19 | 20 | gitinit: $(chocolate_doom_DIR) 21 | cd $(chocolate_doom_DIR) && git init && git add . && git commit -m "init" 22 | 23 | diff: $(chocolate_doom_DIR)/.git 24 | cd $(chocolate_doom_DIR) && git diff > chocolate-doom.patch2 25 | 26 | -------------------------------------------------------------------------------- /fpdoom/include/ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef __CTYPE 2 | #define __CTYPE 3 | 4 | static inline int isdigit(int c) { 5 | return (unsigned)c - '0' < 10; 6 | } 7 | 8 | static inline int isalpha(int c) { 9 | return (unsigned)(c | 32) - 'a' < 26; 10 | } 11 | 12 | static inline int isalnum(int c) { 13 | return isalpha(c) || isdigit(c); 14 | } 15 | 16 | static inline int isspace(int c) { 17 | return c == ' ' || (unsigned)c - 9 < 5; 18 | } 19 | 20 | static inline int isupper(int c) { 21 | return (unsigned)c - 'A' < 26; 22 | } 23 | 24 | static inline int islower(int c) { 25 | return (unsigned)c - 'a' < 26; 26 | } 27 | 28 | static inline int ispunct(int c) { 29 | return (unsigned)c - 0x21 < 0x5e && !isalnum(c); 30 | } 31 | 32 | static inline int isprint(int c) { 33 | return (unsigned)c - 0x20 < 0x5f; 34 | } 35 | 36 | static inline int toupper(int c) { 37 | return (unsigned)c - 'a' < 26 ? c - 32 : c; 38 | } 39 | 40 | static inline int tolower(int c) { 41 | return (unsigned)c - 'A' < 26 ? c + 32 : c; 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /fpdoom/sc6531e_fdl1.ld: -------------------------------------------------------------------------------- 1 | /* ld-script : SC6531E FDL1 */ 2 | 3 | OUTPUT_FORMAT("elf32-littlearm") 4 | OUTPUT_ARCH(arm) 5 | 6 | BSS_START = 0x40000000; BSS_SIZE = 0x4000; 7 | IMAGE_START = 0x40004000; IMAGE_SIZE = 0x5000; 8 | STACK_SIZE = 0x2000; 9 | 10 | ENTRY(_start) 11 | SECTIONS { 12 | .bss BSS_START : { 13 | __bss_start = .; 14 | *(.bss .bss.* .gnu.linkonce.b.*) 15 | __bss_end = ALIGN(4); 16 | } 17 | ASSERT(__bss_end - BSS_START <= BSS_SIZE, "BSS overflow") 18 | 19 | .text IMAGE_START : { 20 | __image_start = .; 21 | *(.text._start) *(.text .text.*) 22 | *(.rodata .rodata.* .gnu.linkonce.r.*) 23 | *(.data .data.* .gnu.linkonce.d.*) 24 | . = ALIGN(4); 25 | __image_end = .; 26 | __stack_top = ALIGN(16); 27 | __stack_bottom = __stack_top + STACK_SIZE; 28 | /* . = DEFINED(IMAGE_ALIGN) ? ALIGN(IMAGE_ALIGN) : .; */ 29 | } = 0xffffffff 30 | ASSERT(__stack_bottom - IMAGE_START <= IMAGE_SIZE, "image overflow") 31 | 32 | __image_size = __image_end - __image_start; 33 | __bss_size = __bss_end - __image_end; 34 | } 35 | -------------------------------------------------------------------------------- /ums9117/ums9117_fdl1.ld: -------------------------------------------------------------------------------- 1 | /* ld-script : UMS9117 FDL1 */ 2 | 3 | OUTPUT_FORMAT("elf32-littlearm") 4 | OUTPUT_ARCH(arm) 5 | 6 | BSS_START = 0x40; BSS_SIZE = 0x5fc0; 7 | IMAGE_START = 0x6200; IMAGE_SIZE = 0x8000; 8 | STACK_SIZE = 0x2000; 9 | 10 | ENTRY(_start) 11 | SECTIONS { 12 | .bss BSS_START : { 13 | __bss_start = .; 14 | *(.bss .bss.* .gnu.linkonce.b.*) 15 | __bss_end = ALIGN(4); 16 | } 17 | ASSERT(__bss_end - BSS_START <= BSS_SIZE, "BSS overflow") 18 | 19 | .text IMAGE_START : { 20 | __image_start = .; 21 | *(.text._start) *(.text .text.*) 22 | *(.rodata .rodata.* .gnu.linkonce.r.*) 23 | *(.data .data.* .gnu.linkonce.d.*) 24 | . = ALIGN(4); 25 | __image_end = .; 26 | __stack_top = ALIGN(16); 27 | __stack_bottom = __stack_top + STACK_SIZE; 28 | } 29 | ASSERT(__stack_bottom - IMAGE_START <= IMAGE_SIZE, "image overflow") 30 | 31 | __image_size = __image_end - __image_start; 32 | __bss_size = __bss_end - __image_end; 33 | 34 | /DISCARD/ : { *(.ARM.exidx .ARM.exidx.*) } 35 | /DISCARD/ : { *(.gnu.hash .dynamic .interp) } 36 | } 37 | -------------------------------------------------------------------------------- /fpdoom/doomkey.h: -------------------------------------------------------------------------------- 1 | // -*- tab-width: 8 -*- 2 | 3 | #define KEY_RIGHTARROW 0xae 4 | #define KEY_LEFTARROW 0xac 5 | #define KEY_UPARROW 0xad 6 | #define KEY_DOWNARROW 0xaf 7 | #define KEY_ESCAPE 27 8 | #define KEY_ENTER 13 9 | #define KEY_TAB 9 10 | #define KEY_F1 (0x80+0x3b) 11 | #define KEY_F2 (0x80+0x3c) 12 | #define KEY_F3 (0x80+0x3d) 13 | #define KEY_F4 (0x80+0x3e) 14 | #define KEY_F5 (0x80+0x3f) 15 | #define KEY_F6 (0x80+0x40) 16 | #define KEY_F7 (0x80+0x41) 17 | #define KEY_F8 (0x80+0x42) 18 | #define KEY_F9 (0x80+0x43) 19 | #define KEY_F10 (0x80+0x44) 20 | #define KEY_F11 (0x80+0x57) 21 | #define KEY_F12 (0x80+0x58) 22 | 23 | #define KEY_BACKSPACE 127 24 | #define KEY_PAUSE 0xff 25 | 26 | #define KEY_EQUALS 0x3d 27 | #define KEY_MINUS 0x2d 28 | 29 | #define KEY_RSHIFT (0x80+0x36) 30 | #define KEY_RCTRL (0x80+0x1d) 31 | #define KEY_RALT (0x80+0x38) 32 | 33 | #define KEY_LALT KEY_RALT 34 | 35 | // new keys: 36 | 37 | #define KEY_CAPSLOCK (0x80+0x3a) 38 | 39 | #define KEY_HOME (0x80+0x47) 40 | #define KEY_END (0x80+0x4f) 41 | #define KEY_PGUP (0x80+0x49) 42 | #define KEY_PGDN (0x80+0x51) 43 | #define KEY_INS (0x80+0x52) 44 | #define KEY_DEL (0x80+0x53) 45 | 46 | -------------------------------------------------------------------------------- /fpdoom/include/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDLIB 2 | #define __STDLIB 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | static inline int abs(int num) { 12 | #ifdef __thumb__ 13 | int sign = num >> 31; 14 | return (num ^ sign) - sign; 15 | #else 16 | return num < 0 ? -num : num; 17 | #endif 18 | } 19 | 20 | static inline long labs(long num) { 21 | #ifdef __thumb__ 22 | long sign = num >> (sizeof(long) * 8 - 1); 23 | return (num ^ sign) - sign; 24 | #else 25 | return num < 0 ? -num : num; 26 | #endif 27 | } 28 | 29 | int atoi(const char*); 30 | long atol(const char*); 31 | long strtol(const char*, char**, int); 32 | unsigned long strtoul(const char*, char**, int); 33 | static inline char *getenv(const char *name) { (void)name; return NULL; } 34 | 35 | __attribute__((noreturn)) 36 | void exit(int); 37 | int atexit(void(*)(void)); 38 | 39 | #define RAND_MAX 0x7fffffff 40 | void srand(unsigned); 41 | int rand(void); 42 | 43 | void qsort(void*, size_t, size_t, 44 | int (*)(const void*, const void*)); 45 | void* bsearch(const void*, const void*, size_t, size_t, 46 | int (*)(const void*, const void*)); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /pctest/syscode.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define FPBIN_DIR "" 4 | 5 | extern struct sys_data { 6 | struct sys_display { uint16_t w1, h1, w2, h2; } display; 7 | uint16_t keytrn[2][64]; 8 | uint16_t mac; 9 | uint8_t scaler, rotate; 10 | uint8_t *framebuf; 11 | uint8_t user[4]; 12 | } sys_data; 13 | 14 | enum { 15 | EVENT_KEYDOWN, EVENT_KEYUP, EVENT_END, EVENT_QUIT 16 | }; 17 | int sys_event(int *rkey); 18 | void sys_framebuffer(void *base); 19 | void sys_start(void); 20 | void sys_wait_refresh(void); 21 | void sys_start_refresh(void); 22 | 23 | unsigned sys_timer_ms(void); 24 | void sys_wait_ms(uint32_t delay); 25 | void sys_wait_us(uint32_t delay); 26 | int sys_getkeymap(uint8_t *dest); 27 | 28 | // appinit 29 | 30 | void keytrn_init(void); 31 | void lcd_appinit(void); 32 | 33 | #define KEYPAD_ENUM(M) \ 34 | M(0x01, DIAL) \ 35 | M(0x04, UP) M(0x05, DOWN) M(0x06, LEFT) M(0x07, RIGHT) \ 36 | M(0x08, LSOFT) M(0x09, RSOFT) M(0x0d, CENTER) \ 37 | M(0x0e, CAMERA) M(0x1d, EXT_1D) M(0x1f, EXT_1F) \ 38 | M(0x21, EXT_21) M(0x23, HASH) M(0x24, VOLUP) M(0x25, VOLDOWN) \ 39 | M(0x29, EXT_29) M(0x2a, STAR) M(0x2b, PLUS) \ 40 | M(0x2c, EXT_2C) M(0x2d, MINUS) M(0x2f, EXT_2F) \ 41 | M(0x30, 0) M(0x31, 1) M(0x32, 2) M(0x33, 3) M(0x34, 4) \ 42 | M(0x35, 5) M(0x36, 6) M(0x37, 7) M(0x38, 8) M(0x39, 9) 43 | 44 | -------------------------------------------------------------------------------- /fpbuild/helper.make: -------------------------------------------------------------------------------- 1 | 2 | ZIPDIR = . 3 | jfbuild_hash = efd88d9cc24f753038a28479c9d8e7ac398909c8 4 | jfmact_hash = 1f0746a3b9704906669d8aaed2bbb982053a393e 5 | jfduke3d_hash = 41cd46bc00633e7457d07d88c8add9f99a7d9d41 6 | jfsw_hash = 1282878348bff97c5cf92401c1253f81da290cc4 7 | NBlood_hash = 5917ab82214a9f0fa8a9d408f9e40143ad72171b 8 | 9 | jfbuild_list = src/* include/* 10 | jfmact_list = * 11 | jfduke3d_list = src/* 12 | jfsw_list = src/* 13 | NBlood_list = source/blood/src/* 14 | 15 | .PHONY: all patch gitinit diff 16 | all: jfbuild jfmact jfduke3d jfsw NBlood 17 | download: $(patsubst %,$(ZIPDIR)/%.zip,jfbuild jfmact jfduke3d jfsw NBlood) 18 | 19 | .PRECIOUS: $(ZIPDIR)/jf%.zip 20 | $(ZIPDIR)/jf%.zip: 21 | wget -O $@ "https://github.com/jonof/$(@:$(ZIPDIR)/%.zip=%)/archive/$($(@:$(ZIPDIR)/%.zip=%)_hash).zip" 22 | 23 | $(ZIPDIR)/NBlood.zip: 24 | wget -O $@ "https://github.com/nukeykt/NBlood/archive/$(NBlood_hash).zip" 25 | 26 | %: $(ZIPDIR)/%.zip 27 | name="$@-$($@_hash)"; unzip -q $< $(patsubst %,"$$name/%",$($@_list)) && mv $$name $@ 28 | 29 | for_fn = \ 30 | for n in jfbuild jfmact jfduke3d jfsw NBlood; do \ 31 | test ! -d $$n || ($(1);); \ 32 | done 33 | 34 | patch: 35 | $(call for_fn, patch -p1 -d $$n < $$n.patch) 36 | cp eduke32/* NBlood/source/blood/src/ 37 | 38 | gitinit: 39 | $(call for_fn, cd $$n && git init && git add . && git commit -m "init") 40 | 41 | diff: 42 | $(call for_fn, cd $$n && git diff > ../$$n.patch2) 43 | 44 | -------------------------------------------------------------------------------- /fpdoom/sc6531e_fdl.ld: -------------------------------------------------------------------------------- 1 | /* ld-script : SC6531E FDL */ 2 | 3 | OUTPUT_FORMAT("elf32-littlearm") 4 | OUTPUT_ARCH(arm) 5 | 6 | EXTRA_START = 0x40000000; EXTRA_SIZE = 0x9000; 7 | /* IMAGE_START = 0x14000000; */ IMAGE_SIZE = 0x300000; 8 | 9 | ENTRY(_start) 10 | SECTIONS { 11 | .text IMAGE_START : { 12 | __image_start = .; 13 | *(.text._start) *(.text .text.*) 14 | 15 | . = ALIGN(4); 16 | __init_array_start = .; 17 | /* the linker from android-ndk-r15c doesn't support SORT_BY_INIT_PRIORITY */ 18 | /* this feature is not required for simple code */ 19 | /* KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) */ 20 | KEEP(*(.init_array.* .ctors.*)) 21 | KEEP(*(.init_array .ctors)) 22 | __init_array_end = .; 23 | 24 | *(.rodata .rodata.* .gnu.linkonce.r.*) 25 | *(.data .data.* .gnu.linkonce.d.*) 26 | . = ALIGN(4); 27 | __image_end = .; 28 | } 29 | .bss : { 30 | __bss_start = .; 31 | *(.bss .bss.* .gnu.linkonce.b.*) *(COMMON) 32 | . = ALIGN(4); 33 | __bss_end = .; 34 | } 35 | 36 | __image_size = __image_end - __image_start; 37 | __bss_size = __bss_end - __image_end; 38 | 39 | __stack_top = EXTRA_START; 40 | __stack_bottom = __stack_top + EXTRA_SIZE; 41 | 42 | ASSERT(__bss_end - IMAGE_START <= IMAGE_SIZE, "image overflow") 43 | 44 | /* Clang's linker tries to insert this section between .text and .bss if I don't list it here or discard it. */ 45 | .dynamic : { *(.dynamic) } 46 | } 47 | -------------------------------------------------------------------------------- /fpmenu/Makefile: -------------------------------------------------------------------------------- 1 | NAME = fpmenu 2 | TWO_STAGE = -1 3 | 4 | ifeq ($(PCTEST), 1) 5 | APP_SRCS = main 6 | APP_OBJS1 = $(APP_SRCS:%=$(OBJDIR)/app/%.o) 7 | APP_OBJS2 = 8 | include ../buildinc.make 9 | APP_CFLAGS += -std=c99 -pedantic 10 | APP_CFLAGS += -I$(SYSDIR) 11 | APP_CFLAGS += -DMENU_DEBUG=1 12 | else 13 | 14 | SYS_EXTRA = microfat sdio 15 | 16 | APP_SRCS = main 17 | ifeq ($(T117), 1) 18 | EXTRA_SRCS = start3_t117 readbin 19 | else 20 | EXTRA_SRCS = start3 readbin 21 | endif 22 | APP_OBJS1 = $(APP_SRCS:%=$(OBJDIR)/app/%.o) 23 | APP_OBJS2 = $(EXTRA_SRCS:%=$(OBJDIR)/app/%.o) 24 | 25 | SYS_SRCS1 = start entry $(SYS_SRCS) 26 | SYS_SRCS2 = asmcode common 27 | OBJS1 = $(SYS_SRCS1:%=$(OBJDIR)/sys/%.o) $(APP_OBJS1) 28 | OBJS2 = $(SYS_SRCS2:%=$(OBJDIR)/sys/%.o) $(APP_OBJS2) 29 | OBJS = $(OBJS1) $(OBJS2) 30 | 31 | include ../buildinc.make 32 | 33 | CFLAGS += -DSDIO_VERBOSE=0 -DSDIO_SHL=CHIPRAM_ADDR 34 | CFLAGS += -DMENU_DEBUG=0 35 | ifeq ($(T117), 1) 36 | CFLAGS += -DNO_ACTLR=1 37 | endif 38 | ifneq ($(LIBC_SDIO), 1) 39 | CFLAGS := $(filter-out -DFAT_WRITE=1, $(CFLAGS)) 40 | endif 41 | 42 | APP_CFLAGS += -std=c99 -pedantic -I$(SYSDIR) 43 | 44 | $(OBJDIR)/$(NAME)_part1.elf: $(OBJS1) 45 | $(CC) $(LFLAGS) $(OBJS1) -o $@ 46 | 47 | $(OBJDIR)/$(NAME)_part2.elf: $(OBJS2) 48 | $(CC) $(LFLAGS) $(OBJS2) -o $@ 49 | 50 | %.bin: %.elf 51 | $(OBJCOPY) -O binary -j .text $< $@ 52 | 53 | $(NAME).bin: $(patsubst %,$(OBJDIR)/$(NAME)_part%,2.bin 1.bin 1.rel) 54 | cat $^ > $@ 55 | 56 | endif 57 | -------------------------------------------------------------------------------- /fpdoom/Makefile: -------------------------------------------------------------------------------- 1 | NAME = fpdoom 2 | DOOM_DIR = ../doom_src 3 | USE_ASM = 1 4 | LTO = 0 5 | KEYTRN_PC = 1 6 | 7 | APP_SRCS = keytrn scr_update 8 | ifneq ($(USE_ASM), 0) 9 | APP_SRCS += doomasm 10 | endif 11 | 12 | DOOM_SRCS = \ 13 | doomdef doomstat dstrings tables f_finale f_wipe \ 14 | d_main d_net d_items g_game m_menu m_misc m_argv m_bbox \ 15 | m_fixed m_swap m_cheat m_random am_map p_ceilng p_doors \ 16 | p_enemy p_floor p_inter p_lights p_map p_maputl p_plats \ 17 | p_pspr p_setup p_sight p_spec p_switch p_mobj p_telept \ 18 | p_tick p_saveg p_user r_bsp r_data r_draw r_main r_plane \ 19 | r_segs r_sky r_things w_wad wi_stuff v_video st_lib \ 20 | st_stuff hu_stuff hu_lib s_sound z_zone info sounds \ 21 | i_system i_sound i_net i_video 22 | 23 | APP_OBJS1 = $(APP_SRCS:%=$(OBJDIR)/app/%.o) 24 | APP_OBJS2 = $(DOOM_SRCS:%=$(OBJDIR)/doom/%.o) 25 | 26 | include ../buildinc.make 27 | 28 | CFLAGS := $(filter-out -funsigned-char, $(CFLAGS)) -fsigned-char 29 | 30 | APP_CFLAGS += -std=c99 -pedantic 31 | ifneq ($(USE_ASM), 0) 32 | APP_CFLAGS += -DUSE_ASM 33 | endif 34 | 35 | DOOM_CFLAGS := $(APP_CFLAGS) -DNORMALUNIX -DLINUX 36 | DOOM_CFLAGS += -DNORANGECHECKING 37 | DOOM_CFLAGS += -Wno-unused-parameter -Wno-unused -Wno-missing-field-initializers 38 | DOOM_CFLAGS += -Wno-strict-prototypes 39 | 40 | APP_CFLAGS += -I$(SYSDIR) 41 | 42 | $(patsubst %,$(OBJDIR)/doom/%.o,i_system i_video): DOOM_CFLAGS += -I$(SYSDIR) 43 | 44 | $(OBJDIR)/doom/%.o: $(DOOM_DIR)/%.c | objdir 45 | $(call compile_cc,$(DOOM_CFLAGS)) 46 | 47 | -------------------------------------------------------------------------------- /gnuboy/port_hacks.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "defs.h" 5 | #include "pcm.h" 6 | #include "rc.h" 7 | #include "sys.h" 8 | 9 | #include "syscode.h" 10 | 11 | struct pcm pcm; 12 | 13 | static byte buf[4096]; 14 | 15 | rcvar_t pcm_exports[] = { 16 | RCV_END 17 | }; 18 | 19 | void pcm_init() { 20 | pcm.hz = 11025; 21 | pcm.buf = buf; 22 | pcm.len = sizeof(buf); 23 | pcm.pos = 0; 24 | } 25 | 26 | void pcm_close() { 27 | memset(&pcm, 0, sizeof(pcm)); 28 | } 29 | 30 | int pcm_submit() { 31 | pcm.pos = 0; 32 | return 0; 33 | } 34 | 35 | void pcm_pause(int dopause) {} 36 | 37 | rcvar_t joy_exports[] = { 38 | RCV_END 39 | }; 40 | 41 | void joy_init() {} 42 | void joy_close() {} 43 | void joy_poll() {} 44 | 45 | void *sys_timer() { 46 | uint32_t *tv; 47 | tv = malloc(sizeof(*tv)); 48 | *tv = sys_timer_ms(); 49 | return tv; 50 | } 51 | 52 | int sys_elapsed(struct timeval *prev) { 53 | uint32_t now, ms; 54 | now = sys_timer_ms(); 55 | ms = now - *(uint32_t*)prev; 56 | *(uint32_t*)prev = now; 57 | return ms * 1000; 58 | } 59 | 60 | void sys_sleep(int us) { 61 | if (us > 0) sys_wait_us(us); 62 | } 63 | 64 | void sys_checkdir(char *path, int wr) {} 65 | 66 | void sys_initpath() { 67 | char *buf = "."; 68 | rc_setvar("rcpath", 1, &buf); 69 | rc_setvar("savedir", 1, &buf); 70 | } 71 | 72 | void sys_sanitize(char *s) {} 73 | 74 | #if NO_MENU 75 | #include "menu.h" 76 | 77 | rcvar_t menu_exports[] = { 78 | RCV_END 79 | }; 80 | 81 | void menu_init(void) {} 82 | void menu_initpage(enum menu_page page) {} 83 | void menu_enter(void) {} 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /ums9117/ums9117_fdl2.ld: -------------------------------------------------------------------------------- 1 | /* ld-script : UMS9117 FDL2 */ 2 | 3 | OUTPUT_FORMAT("elf32-littlearm") 4 | OUTPUT_ARCH(arm) 5 | 6 | EXTRA_START = 0x80000000; EXTRA_SIZE = 0x100000; 7 | IMAGE_START = 0x80100000; IMAGE_SIZE = 0x300000; 8 | 9 | ENTRY(_start) 10 | SECTIONS { 11 | .text IMAGE_START : { 12 | __image_start = .; 13 | *(.text._start) *(.text .text.*) 14 | 15 | . = ALIGN(4); 16 | __init_array_start = .; 17 | /* the linker from android-ndk-r15c doesn't support SORT_BY_INIT_PRIORITY */ 18 | /* this feature is not required for simple code */ 19 | /* KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) */ 20 | KEEP(*(.init_array.* .ctors.*)) 21 | KEEP(*(.init_array .ctors)) 22 | __init_array_end = .; 23 | 24 | *(.rodata .rodata.* .gnu.linkonce.r.*) 25 | *(.data .data.* .gnu.linkonce.d.*) 26 | . = ALIGN(64); /* to properly align the second stage */ 27 | __image_end = .; 28 | } 29 | .bss : { 30 | __bss_start = .; 31 | *(.bss .bss.* .gnu.linkonce.b.*) *(COMMON) 32 | . = ALIGN(4); 33 | __bss_end = .; 34 | } 35 | 36 | __image_size = __image_end - __image_start; 37 | __bss_size = __bss_end - __image_end; 38 | 39 | __stack_top = EXTRA_START; 40 | __stack_bottom = __stack_top + EXTRA_SIZE; 41 | 42 | ASSERT(__bss_end - IMAGE_START <= IMAGE_SIZE, "image overflow") 43 | 44 | /* Clang's linker tries to insert this section between .text and .bss if I don't list it here or discard it. */ 45 | .dynamic : { *(.dynamic) } 46 | 47 | /* workaround for "relocation R_ARM_PREL31 out of range" */ 48 | /DISCARD/ : { *(.ARM.exidx .ARM.exidx.*) } 49 | } 50 | -------------------------------------------------------------------------------- /wolf3d/README.md: -------------------------------------------------------------------------------- 1 | ## Wolfenstein 3D port 2 | 3 | Port of the [Wolf4SDL](https://github.com/KS-Presto/Wolf4SDL). 4 | 5 | ### Build 6 | 7 | 1. Download specific sources and apply patches: 8 | `$ make -f helper.make all patch` 9 | 10 | 2. Use the same instructions as for `fpdoom`. Use `GAMEVER` option to select the game version, for example `GAMEVER="CARMACIZED UPLOAD"` for shareware v1.4, read [Wolf4SDL/version.h](https://github.com/KS-Presto/Wolf4SDL/blob/master/version.h) for a description of all options. 11 | 12 | ### Game controls 13 | 14 | | Key(s) | Action | 15 | |----------------|--------------------| 16 | | Left Soft Key | use | 17 | | Right Soft Key | open/close menu | 18 | | Direction Pad | movement | 19 | | D-pad Center | fire | 20 | | Dial Key | run on/off | 21 | | 2, 4, 5, 6 | up/left/down/right | 22 | | 1, 3 | strafe left/right | 23 | | 7, 9 | prev/next weapon | 24 | | Power + Center | use | 25 | | Power + Up | run on/off | 26 | | Power + Down | open/close menu | 27 | | Power + L/R | prev/next weapon | 28 | | Power + Dial | map | 29 | | Power + 4,5,6 | G, Y, M | 30 | 31 | * Cheats: G + Y toggles God Mode, M + Y gives all items. 32 | 33 | ### Issues 34 | 35 | * Each version of the game requires its own binary. 36 | 37 | * Saved games and config are not compatible with other ports. 38 | 39 | * For compatibility with Linux, the USB build will try to open file names in uppercase if opening in lowercase fails. 40 | 41 | -------------------------------------------------------------------------------- /ums9117/README.md: -------------------------------------------------------------------------------- 1 | ## FPDoom instructions for the UMS9117 chipset 2 | 3 | Here are the differences from phones on the SC6531 chipset. 4 | 5 | There is no support for reading NAND flash yet, but the binaries require the `pinmap` and `keymap` configs from the original firmware. 6 | 7 | So, first you need to dump the kernel part of the firmware from the phone (hints [here](https://github.com/ilyakurdyukov/spreadtrum_flash?tab=readme-ov-file#instructions-4g-feature-phones)): 8 | 9 | ``` 10 | ./spd_dump \ 11 | keep_charge 1 fdl fdl1.bin 0x6200 \ 12 | blk_size 0x1000 fdl fdl2.bin 0x801M \ 13 | read_flash 0x80000003 0 auto kernel.bin 14 | ``` 15 | 16 | * `fdl1.bin` and `fdl2.bin` here are the files from the firmware update file. 17 | 18 | Then process the kernel dump using the `fphelper_t117` tool (sources are [here](https://github.com/ilyakurdyukov/spreadtrum_flash/tree/main/fphelper_t117)). 19 | 20 | ``` 21 | ./fphelper_t117 kernel.bin extract 22 | ``` 23 | 24 | This should extract the `pinmap.bin` and `keymap.bin` files, which must be placed in `workdir` for the example below. 25 | 26 | ### How to run 27 | 28 | Use the [spreadtrum_flash](https://github.com/ilyakurdyukov/spreadtrum_flash) tool with the `t117_fdl1.bin` built from the same [repository](https://github.com/ilyakurdyukov/spreadtrum_flash/tree/main/t117_fdl). Note that the FDL load addresses are different. 29 | 30 | ``` 31 | $ ./spd_dump fdl t117_fdl1.bin 0x6200 fdl fpdoom.bin 0x801M 32 | $ cd workdir && ../libc_server -- --bright 50 --rotate 3 doom 33 | ``` 34 | 35 | ### Build 36 | 37 | When building binaries for UMS9117, add the `T117=1` option to make. 38 | -------------------------------------------------------------------------------- /fpdoom/keytrn_pc.c: -------------------------------------------------------------------------------- 1 | #include "../pctest/syscode.h" 2 | #include "doomkey.h" 3 | 4 | #include "SDL.h" 5 | #include "SDL_keyboard.h" 6 | 7 | int sys_event(int *rkey) { 8 | SDL_Event event; 9 | for (;;) { 10 | int ret, key; 11 | if (!SDL_PollEvent(&event)) return EVENT_END; 12 | switch (event.type) { 13 | case SDL_QUIT: return EVENT_QUIT; 14 | case SDL_KEYDOWN: ret = EVENT_KEYDOWN; goto mapkey; 15 | case SDL_KEYUP: ret = EVENT_KEYUP; 16 | mapkey: 17 | key = event.key.keysym.sym; 18 | if (key >= 0x100) 19 | switch (key) { 20 | #define X(sdl, game) \ 21 | case SDLK_##sdl: key = game; break; 22 | X(RETURN, KEY_ENTER) 23 | X(ESCAPE, KEY_ESCAPE) 24 | X(BACKSPACE, KEY_BACKSPACE) 25 | X(TAB, KEY_TAB) 26 | X(LALT, KEY_RALT) 27 | X(RALT, KEY_RALT) 28 | X(LCTRL, KEY_RCTRL) 29 | X(RCTRL, KEY_RCTRL) 30 | #if 0 31 | X(LSHIFT, KEY_RSHIFT) 32 | X(RSHIFT, KEY_RSHIFT) 33 | X(CAPSLOCK, KEY_CAPSLOCK) 34 | #else 35 | X(CAPSLOCK, KEY_RSHIFT) 36 | #endif 37 | X(UP, KEY_UPARROW) 38 | X(DOWN, KEY_DOWNARROW) 39 | X(LEFT, KEY_LEFTARROW) 40 | X(RIGHT, KEY_RIGHTARROW) 41 | X(PAGEUP, KEY_PGUP) 42 | X(PAGEDOWN, KEY_PGDN) 43 | X(INSERT, KEY_INS) 44 | X(DELETE, KEY_DEL) 45 | X(HOME, KEY_HOME) 46 | X(END, KEY_END) 47 | X(F1, KEY_F1) 48 | X(F2, KEY_F2) 49 | X(F3, KEY_F3) 50 | X(F4, KEY_F4) 51 | X(F5, KEY_F5) 52 | X(F6, KEY_F6) 53 | X(F7, KEY_F7) 54 | X(F8, KEY_F8) 55 | X(F9, KEY_F9) 56 | X(F10, KEY_F10) 57 | X(F11, KEY_F11) 58 | #undef X 59 | default: goto next; 60 | } 61 | *rkey = key; 62 | return ret; 63 | } 64 | next: 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /snes9x/helper.make: -------------------------------------------------------------------------------- 1 | 2 | ZIPDIR = . 3 | LINK_IDX = 2 4 | LINK0 = https://www.lysator.liu.se/snes9x/1.43/snes9x-1.43-src.tar.gz 5 | LINK1 = http://ftp.lip6.fr/pub/minix/distfiles/backup/snes9x-1.43-src.tar.gz 6 | CHECKSUM = cb60baaeabc28b68f7dfc8fd54453f6268b66aae33ea64eb1788c19df09be6f1 7 | LINK2 = https://old-releases.ubuntu.com/ubuntu/pool/multiverse/s/snes9x/snes9x_1.43.orig.tar.gz 8 | CHECKSUM2 = c1afb7804ca27af5ee580d4a45a197241bbb13b8d321ee1bf8b3abf516ff7ec1 9 | snes9x_list = snes9x-1.43-src/snes9x/* 10 | 11 | .PHONY: all patch gitinit diff 12 | all: snes9x_src snes9x_src/dsp1new.cpp 13 | 14 | LINK = $(LINK$(LINK_IDX)) 15 | ARCHIVE = $(notdir $(LINK)) 16 | ifeq ($(LINK_IDX),2) 17 | CHECKSUM = $(CHECKSUM2) 18 | snes9x_src: $(ZIPDIR)/$(ARCHIVE) 19 | mkdir -p $@ 20 | tar -xzf $< -C $@ --strip-components 3 --wildcards "snes9x-1.43.orig/$(snes9x_list)" 21 | else 22 | snes9x_src: $(ZIPDIR)/$(ARCHIVE) 23 | mkdir -p $@ 24 | tar -xzf $< -C $@ --strip-components 2 --wildcards "$(snes9x_list)" 25 | endif 26 | download: $(ZIPDIR)/$(ARCHIVE) 27 | $(ZIPDIR)/$(ARCHIVE): 28 | wget -O $@.tmp $(LINK) 29 | test "$$(openssl sha256 $@.tmp | cut -d " " -f 2)" = $(CHECKSUM) 30 | mv $@.tmp $@ 31 | 32 | $(ZIPDIR)/snes9x_dsp1.cpp: 33 | wget -O $@ https://raw.githubusercontent.com/snes9xgit/snes9x/96059dd45aed03859bff5a3e30f1d1b13136a8f9/dsp1.cpp 34 | snes9x_src/dsp1new.cpp: $(ZIPDIR)/snes9x_dsp1.cpp | snes9x_src 35 | cp $< $@ 36 | 37 | patch: snes9x_src 38 | patch -p1 -d snes9x_src < snes9x.patch 39 | 40 | gitinit: snes9x_src 41 | cd snes9x_src && git init && git add . && git commit -m "init" 42 | 43 | diff: snes9x_src/.git 44 | cd snes9x_src && git diff > ../snes9x.patch2 45 | 46 | -------------------------------------------------------------------------------- /fpmenu/readbin.c: -------------------------------------------------------------------------------- 1 | 2 | #undef SDIO_VERBOSE 3 | #define SDIO_VERBOSE 0 4 | 5 | #undef SDIO_SHL 6 | #define SDIO_SHL CHIPRAM_ADDR 7 | 8 | #include "common.h" 9 | #include "syscode.h" 10 | 11 | #if UMS9117 12 | #include "../ums9117/sdio.c" 13 | #else 14 | #include "sdio.c" 15 | #endif 16 | #ifdef FAT_WRITE 17 | #define FAT_WRITE_SYS break; 18 | #endif 19 | #define FAT_READ_SYS \ 20 | if (sdio_read_block(sector, buf)) break; 21 | #include "microfat.c" 22 | 23 | #undef DBG_LOG 24 | #if MENU_DEBUG 25 | #define DBG_LOG(...) printf(__VA_ARGS__) 26 | #define RAM_SHIFT 0x20000 27 | #define DBG_EXTRA_ARG(x) , x 28 | #else 29 | #define DBG_LOG(...) (void)0 30 | #define RAM_SHIFT 0 31 | #define DBG_EXTRA_ARG(x) 32 | #endif 33 | 34 | typedef int (*printf_t)(const char *fmt, ...); 35 | 36 | void entry_main(unsigned clust, unsigned size, uint8_t *ram, 37 | fatdata_t *old_fatdata DBG_EXTRA_ARG(printf_t printf)) { 38 | fatdata_t fatdata; 39 | uint32_t i = 0, n = sizeof(fatdata_t) / 4; 40 | // fatdata = *old_fatdata; 41 | do ((uint32_t*)&fatdata)[i] = ((uint32_t*)old_fatdata)[i]; 42 | while (i++ < n); 43 | 44 | #if UMS9117 45 | // Nokia TA-1543: Something is not synced properly. 46 | // Sometimes binaries fail to run, this delay helps. 47 | DELAY(1000) 48 | #endif 49 | DBG_LOG("clust = 0x%x, size = 0x%x, ram = %p\n", clust, size, ram); 50 | ram += RAM_SHIFT; 51 | 52 | n = fat_read_simple(&fatdata, clust, ram, size); 53 | DBG_LOG("n = 0x%x\n", n); 54 | if (n < size) for (;;); 55 | #if RAM_SHIFT 56 | ram -= RAM_SHIFT; 57 | memcpy(ram, ram + RAM_SHIFT, size); 58 | #endif 59 | clean_dcache(); 60 | invalidate_icache(); 61 | #if UMS9117 62 | ram += 0x200; 63 | #endif 64 | ((void(*)(void))ram)(); 65 | } 66 | -------------------------------------------------------------------------------- /gnuboy/README.md: -------------------------------------------------------------------------------- 1 | ## gnuboy port 2 | 3 | Port of [gnuboy](https://github.com/rofl0r/gnuboy). 4 | 5 | ### Build 6 | 7 | 1. Download specific sources and apply patches: 8 | `$ make -f helper.make all patch` 9 | 10 | 2. Use the same instructions as for `fpdoom`. 11 | 12 | ### Game controls 13 | 14 | | Key(s) | Action | 15 | |----------------|--------------------| 16 | | Left Soft Key | select | 17 | | Right Soft Key | start | 18 | | Direction Pad | movement | 19 | | D-pad Center | A | 20 | | Dial Key | A | 21 | | 2, 4, 5, 6 | up/left/down/right | 22 | | *, 0, # | A | 23 | | 1, 3, 7, 8, 9 | B | 24 | | Power + LSoft | start | 25 | | Power + Dial | exit | 26 | | Power + Up | reset | 27 | | Power + Down | exit | 28 | | Power + Left | select | 29 | | Power + Right | start | 30 | | Power + Center | B | 31 | | Power + 0 | force save SRAM | 32 | 33 | * The reset/exit keys must be held for 1 second to activate. This is to prevent accidental pressing. 34 | 35 | ### Issues 36 | 37 | * The emulator needs a patch with frame skip support to prevent slowing down on screens with slow refresh rate. 38 | 39 | * Some game cartridges have SRAM for saves, this memory is saved on exit or if you force save SRAM. If the device is turned off, the SRAM changes will be lost. 40 | 41 | * The FAT32 file system driver can't create files with long names, if you want to save SRAM the ROM file name must be in DOS 8.3 format or you need to create an empty file with the ROM name and the `.sav` extension in advance. 42 | 43 | -------------------------------------------------------------------------------- /sdboot_t117/README.md: -------------------------------------------------------------------------------- 1 | ## SD card boot (UMS9117) 2 | 3 | This is a bootloader that needs to be written to the beginning of the SD card. The code is executed when the phone is powered/rebooted, if the keys at positions (0,0), (0,1) and (1,0) is hold down. If a FAT32 formatted SD card is inserted, then the binary `fpbin_t117/fpmain.bin` is executed. The command-line arguments for the application is read from the file `fpbin_t117/config.txt`. This application can be either one of the games or a menu for selecting games (`fpmenu`). 4 | 5 | * The key for booting from USB is (0,0). The key positions are the intersections of traces on the PCB, not the physical buttons you see. 6 | 7 | * The keys (0,1) and (1,0) are the `bl_update` keys, `fphelper_t117` will print them in the log when analyzing the firmware kernel. 8 | 9 | * The bootloader must be signed for phones with Secure Boot enabled, for now there no way to boot from an SD card for such devices. 10 | 11 | ### How to install 12 | 13 | When writing the bootloader to the SD card, you need to preserve the MBR partitions. I don't know how to do the same on Windows. 14 | 15 | ```sh 16 | # the SD card reader device 17 | # for USB card readers, it is /dev/sdX 18 | # for internal laptop card readers, it might be /dev/mmcblkX 19 | dev=/dev/mmcblk0 20 | # backup the original MBR 21 | sudo dd if=$dev bs=512 count=64 > mbr_orig.bin 22 | 23 | tmp=mbr_new.bin 24 | cp sdboot_t117.bin $tmp 25 | # copy the MBR partitions 26 | dd if=mbr_orig.bin of=$tmp seek=440 skip=440 bs=1 count=72 conv=notrunc 27 | 28 | # write the result to the SD card 29 | sudo dd if=$tmp of=$dev bs=512 30 | ``` 31 | 32 | The `pinmap.bin` and `keymap.bin` extracted from the phone firmware must be copied to the `fpbin_t117` directory. 33 | 34 | -------------------------------------------------------------------------------- /ums9117/start.s: -------------------------------------------------------------------------------- 1 | @ -*- tab-width: 8 -*- 2 | .arch armv7-a 3 | .syntax unified 4 | 5 | .macro CODE32_FN name 6 | .section .text.\name, "ax", %progbits 7 | .p2align 2 8 | .code 32 9 | .type \name, %function 10 | .global \name 11 | \name: 12 | .endm 13 | 14 | CODE32_FN _start 15 | .ascii "DHTB" 16 | .long 1 17 | .org _start + 0x30, 0 18 | .long __image_size - 0x200 19 | .org _start + 0x200, 0 20 | 21 | // 0 : MMU enable 22 | // 1 : Alignment fault enable 23 | // 2 : Level 1 Data Cache enable 24 | // 12 : Instruction Cache enable 25 | 26 | mov r1, #0 27 | mcr p15, #0, r1, c7, c5, #0 // Invalidate ICache 28 | mrc p15, #0, r0, c1, c0, #0 // Read Control Register 29 | bic r0, #7 // 2 + 1 + 0 30 | orr r0, #0x1000 // 12 31 | mcr p15, #0, r0, c1, c0, #0 // Write Control Register 32 | msr CPSR_c, #0xdf // SYS mode 33 | ldr sp, 1f 34 | 35 | ldr r2, 3f 36 | ldr r1, 4f 37 | adr r0, _start 38 | subs r2, r0, r2 39 | push {r0-r1} 40 | add r1, r0 41 | blne apply_reloc 42 | pop {r0-r1} 43 | 44 | ldr r2, 5f 45 | ldr pc, 2f 46 | 2: .long entry_main 47 | 1: .long __stack_bottom 48 | 3: .long __image_start 49 | 4: .long __image_size 50 | 5: .long __bss_size 51 | 52 | .type apply_reloc, %function 53 | .global apply_reloc 54 | apply_reloc: 55 | // r0 = image, r1 = reloc, r2 = diff 56 | push {r4-r7,lr} 57 | mov r5, #1 58 | ldrb r6, [r1], #1 // nbits 59 | ldrb r7, [r1], #1 // maxrun 60 | 1: mov ip, #0 61 | mov lr, r7 62 | 2: ldrb r4, [r1], #1 63 | sub lr, lr, r4, lsl ip 64 | lsrs r4, r6 65 | add ip, r6 66 | beq 2b 67 | adds lr, lr, r5, lsl ip 68 | popeq {r4-r7,pc} 69 | asrs ip, lr, #1 70 | mvncc r3, #0 71 | movmi r3, lr 72 | 3: ldr r4, [r0, -r3, lsl #2]! 73 | add r4, r2 74 | str r4, [r0] 75 | subs ip, #1 76 | bpl 3b 77 | b 1b 78 | 79 | -------------------------------------------------------------------------------- /chocolate-doom/README.md: -------------------------------------------------------------------------------- 1 | ## Chocolate Doom port 2 | 3 | Port of [Chocolate Doom](https://github.com/chocolate-doom/chocolate-doom). 4 | 5 | ### Build 6 | 7 | 1. Download specific sources and apply patches: 8 | `$ make -f helper.make all patch` 9 | 10 | 2. Use the same instructions as for `fpdoom`. To select a game to build: use `GAME=name`, where name is `doom`, `heretic`, `hexen` or `strife`. 11 | 12 | * The Strife port is not ready yet. 13 | 14 | ### Chocolate Doom options 15 | 16 | * `-iwad ` - specify wad file. 17 | 18 | * `-mb N.NN` - set the cache size to N megabytes. 19 | 20 | ### Game controls 21 | 22 | | Key(s) | Action | 23 | |----------------|--------------------| 24 | | Left Soft Key | use | 25 | | Right Soft Key | open/close menu | 26 | | Direction Pad | movement | 27 | | D-pad Center | fire | 28 | | Dial Key | run on/off | 29 | | 2, 4, 5, 6 | up/left/down/right | 30 | | 1, 3 | strafe left/right | 31 | | 7, 9 | prev/next weapon | 32 | | # | fly up/jump | 33 | | * | fly down | 34 | | 0 | next item | 35 | | 8 | use item | 36 | | Power + Center | use | 37 | | Power + Up | run on/off | 38 | | Power + Down | open/close menu | 39 | | Power + L/R | prev/next weapon | 40 | | Power + LSoft | zoom in | 41 | | Power + RSoft | zoom out | 42 | | Power + Dial | map | 43 | | Power + 0 | gamma (0..4) | 44 | | Power + 1,2,3 | I, D, Q | 45 | | Power + 4,5,6 | K, F, A | 46 | 47 | * Heretic and Hexen are modified so that IDDQD/IDKFA cheats work like in Doom, IDKFA also gives all items. 48 | 49 | -------------------------------------------------------------------------------- /ums9117/start1.s: -------------------------------------------------------------------------------- 1 | @ -*- tab-width: 8 -*- 2 | .arch armv7-a 3 | .syntax unified 4 | 5 | .macro CODE32_FN name 6 | .section .text.\name, "ax", %progbits 7 | .p2align 2 8 | .code 32 9 | .type \name, %function 10 | .global \name 11 | \name: 12 | .endm 13 | 14 | CODE32_FN _start 15 | 16 | // 0 : MMU enable 17 | // 1 : Alignment fault enable 18 | // 2 : Level 1 Data Cache enable 19 | // 12 : Instruction Cache enable 20 | 21 | mov r1, #0 22 | mcr p15, #0, r1, c7, c5, #0 // Invalidate ICache 23 | mrc p15, #0, r0, c1, c0, #0 // Read Control Register 24 | bic r0, #7 // 2 + 1 + 0 25 | orr r0, #0x1000 // 12 26 | mcr p15, #0, r0, c1, c0, #0 // Write Control Register 27 | msr CPSR_c, #0xdf // SYS mode 28 | ldr sp, 1f 29 | 30 | ldr r2, 3f 31 | ldr r1, 4f 32 | adr r0, _start 33 | subs r2, r0, r2 34 | push {r0-r1} 35 | add r1, r0 36 | blne apply_reloc 37 | add r3, r1, #3 38 | pop {r0-r1} 39 | bic r3, #3 40 | 41 | ldr r2, 5f 42 | push {r4-r5} // r5 for alignement 43 | bl entry_main 44 | add sp, #8 45 | mov r3, r0 46 | mov r0, r4 47 | ldr r1, [r4, #0x210] 48 | ldr r2, [r4, #0x214] 49 | ldr pc, [r4, #0x218] // entry_main 50 | 51 | 1: .long __stack_bottom 52 | 3: .long __image_start 53 | 4: .long __image_size 54 | 5: .long __bss_size 55 | 56 | .type apply_reloc, %function 57 | .global apply_reloc 58 | apply_reloc: 59 | // r0 = image, r1 = reloc, r2 = diff 60 | push {r4-r7,lr} 61 | mov r5, #1 62 | ldrb r6, [r1], #1 // nbits 63 | ldrb r7, [r1], #1 // maxrun 64 | 1: mov ip, #0 65 | mov lr, r7 66 | 2: ldrb r4, [r1], #1 67 | sub lr, lr, r4, lsl ip 68 | lsrs r4, r6 69 | add ip, r6 70 | beq 2b 71 | adds lr, lr, r5, lsl ip 72 | popeq {r4-r7,pc} 73 | asrs ip, lr, #1 74 | mvncc r3, #0 75 | movmi r3, lr 76 | 3: ldr r4, [r0, -r3, lsl #2]! 77 | add r4, r2 78 | str r4, [r0] 79 | subs ip, #1 80 | bpl 3b 81 | b 1b 82 | 83 | -------------------------------------------------------------------------------- /gnuboy/Makefile: -------------------------------------------------------------------------------- 1 | NAME = gnuboy 2 | GNUBOYDIR = gnuboy 3 | USE_FILEMAP = 1 4 | USE_ASM = 1 5 | NO_FLOAT = 1 6 | NO_GZ = 1 7 | NO_XZ = 1 8 | NO_ZIP = 1 9 | NO_MENU = 1 10 | NO_DEH = 1 11 | 12 | APP_SRCS = port_hacks port_sys scr_update 13 | ifneq ($(USE_ASM), 0) 14 | APP_SRCS += gbasm 15 | endif 16 | 17 | GNUBOY_SRCS = lcd refresh lcdc palette cpu mem rtc hw sound \ 18 | events keytable loader save debug emu main \ 19 | rccmds rckeys rcvars rcfile exports \ 20 | split path 21 | 22 | ifeq ($(NO_NOMENU), 0) 23 | GNUBOY_SRCS += menu 24 | endif 25 | ifeq ($(NO_GZ), 0) 26 | GNUBOY_SRCS += inflate 27 | endif 28 | ifeq ($(NO_XZ), 0) 29 | GNUBOY_SRCS += xz_crc32 xz_crc64 xz_dec_lzma2 xz_dec_stream xz_dec_bcj 30 | endif 31 | ifeq ($(NO_ZIP), 0) 32 | GNUBOY_SRCS += miniz_tinfl 33 | endif 34 | 35 | APP_OBJS1 = $(APP_SRCS:%=$(OBJDIR)/app/%.o) 36 | APP_OBJS2 = $(GNUBOY_SRCS:%=$(OBJDIR)/gnuboy/%.o) 37 | 38 | include ../buildinc.make 39 | 40 | CFLAGS := $(filter-out -funsigned-char, $(CFLAGS)) -fsigned-char 41 | SYS_CFLAGS += -DATEXIT_MAX=2 42 | 43 | APP_CFLAGS += -std=c99 -pedantic 44 | GNUBOY_CFLAGS = -DIS_LITTLE_ENDIAN 45 | ifneq ($(NO_MENU), 0) 46 | GNUBOY_CFLAGS += -DNO_MENU 47 | endif 48 | ifneq ($(NO_GZ), 0) 49 | GNUBOY_CFLAGS += -DNO_GZ 50 | endif 51 | ifneq ($(NO_XZ), 0) 52 | GNUBOY_CFLAGS += -DNO_XZ 53 | endif 54 | ifneq ($(NO_ZIP), 0) 55 | GNUBOY_CFLAGS += -DNO_ZIP 56 | endif 57 | ifneq ($(NO_FLOAT), 0) 58 | GNUBOY_CFLAGS += -DNO_FLOAT=1 59 | endif 60 | GNUBOY_CFLAGS += -Wno-unused -Wno-sign-compare 61 | GNUBOY_CFLAGS += -Wno-unused-parameter -Wno-strict-prototypes -Wno-newline-eof 62 | GNUBOY_CFLAGS := $(APP_CFLAGS) $(GNUBOY_CFLAGS) 63 | 64 | APP_CFLAGS := $(GNUBOY_CFLAGS) -I$(SYSDIR) -I$(GNUBOYDIR) 65 | ifneq ($(USE_ASM), 0) 66 | APP_CFLAGS += -DUSE_ASM 67 | endif 68 | 69 | $(OBJDIR)/gnuboy/%.o: $(GNUBOYDIR)/%.c | objdir 70 | $(call compile_cc,$(GNUBOY_CFLAGS)) 71 | 72 | -------------------------------------------------------------------------------- /chocolate-doom/port_hacks.c: -------------------------------------------------------------------------------- 1 | #include "i_joystick.h" 2 | 3 | int use_analog = 0; 4 | int joystick_turn_sensitivity = 10; 5 | int joystick_move_sensitivity = 10; 6 | int joystick_look_sensitivity = 10; 7 | 8 | void I_InitJoystick(void) {} 9 | void I_UpdateJoystick(void) {} 10 | void I_BindJoystickVariables(void) {} 11 | 12 | #if NO_DEH 13 | #include "deh_main.h" 14 | 15 | void DEH_ParseCommandLine(void) {} 16 | void DEH_AutoLoadPatches(const char *path) {} 17 | #endif 18 | 19 | #if NO_NET 20 | #include "net_client.h" 21 | 22 | boolean net_client_connected = false; 23 | boolean drone = false; 24 | 25 | void NET_Init(void) {} 26 | void NET_CL_Run(void) {} 27 | void NET_SV_Run(void) {} 28 | void NET_BindVariables(void) {} 29 | #endif 30 | 31 | #if NO_SOUND 32 | #include "i_sound.h" 33 | 34 | int snd_pitchshift = -1; 35 | int snd_musicdevice = SNDDEVICE_SB; 36 | 37 | void I_SetOPLDriverVer(opl_driver_ver_t ver) {} 38 | void I_InitSound(GameMission_t mission) {} 39 | void I_ShutdownSound(void) {} 40 | int I_GetSfxLumpNum(sfxinfo_t *sfxinfo) { return 0; } 41 | void I_UpdateSound(void) {} 42 | void I_UpdateSoundParams(int channel, int vol, int sep) {} 43 | int I_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep, int pitch) { return 0; } 44 | void I_StopSound(int channel) {} 45 | boolean I_SoundIsPlaying(int channel) { return false; } 46 | void I_PrecacheSounds(sfxinfo_t *sounds, int num_sounds) {} 47 | void I_InitMusic(void) {} 48 | void I_ShutdownMusic(void) {} 49 | void I_SetMusicVolume(int volume) {} 50 | void I_PauseSong(void) {} 51 | void I_ResumeSong(void) {} 52 | void *I_RegisterSong(void *data, int len) { return NULL; } 53 | void I_UnRegisterSong(void *handle) {} 54 | void I_PlaySong(void *handle, boolean looping) {} 55 | void I_StopSong(void) {} 56 | boolean I_MusicIsPlaying(void) { return false; } 57 | void I_BindSoundVariables(void) {} 58 | #endif 59 | 60 | void I_Endoom(byte *endoom_data) {} 61 | 62 | -------------------------------------------------------------------------------- /wolf3d/wlsys_def.h: -------------------------------------------------------------------------------- 1 | //#include 2 | #ifndef SDL_MAJOR_VERSION 3 | typedef struct { uint8_t r, g, b, a; } SDL_Color; 4 | typedef uint8_t SDL_Surface; 5 | #define SDL_ALPHA_OPAQUE 255 6 | #define SDL_GetTicks sys_timer_ms 7 | #define SDL_Delay sys_wait_ms 8 | typedef struct { int dummy; } SDL_Joystick; 9 | #endif 10 | 11 | int CalcAngle(int32_t y, int32_t x); 12 | int ProjectionAngle(int32_t y, int32_t x); 13 | 14 | uint8_t *wlsys_init(void); 15 | void wlsys_end(void); 16 | void wlsys_setpal(SDL_Color *pal); 17 | void wlsys_refresh(const uint8_t *src, int type); 18 | 19 | FILE *fopen_fix(const char *path, const char *mode); 20 | 21 | #if !defined(WLSYS_MAIN) && LINUX_FN_FIX 22 | #define fopen fopen_fix 23 | #endif 24 | 25 | extern int force_refresh_type; 26 | extern int last_refresh_type; 27 | 28 | extern int RunInvert; 29 | extern int CalcRotateMult; 30 | 31 | extern uint16_t *framebuf; 32 | extern unsigned frameWidth, frameHeight; 33 | extern void (*fizzlePixel)(unsigned x, unsigned y, uint8_t *src); 34 | 35 | enum { 36 | sc_None = 0, 37 | sc_LControl, 38 | sc_LShift, 39 | sc_LAlt, 40 | sc_UpArrow, 41 | sc_DownArrow, 42 | sc_LeftArrow, 43 | sc_RightArrow, 44 | 45 | sc_BackSpace = 8, 46 | sc_Tab = 9, 47 | sc_CapsLock, 48 | sc_Return = 13, 49 | sc_Escape = 27, 50 | sc_Space = ' ', 51 | 52 | sc_1 = '1', sc_2, sc_3, sc_4, 53 | 54 | sc_G = 'g', 55 | sc_M = 'm', 56 | sc_N = 'n', 57 | sc_O = 'o', 58 | sc_P = 'p', 59 | sc_Y = 'y', 60 | 61 | sc_Delete = 127, 62 | sc_Last 63 | }; 64 | 65 | #ifndef WLSYS_MAIN 66 | enum { 67 | EVENT_KEYDOWN, EVENT_KEYUP, EVENT_END, EVENT_QUIT 68 | }; 69 | int sys_event(int *rkey); 70 | void sys_wait_refresh(void); 71 | void sys_start_refresh(void); 72 | unsigned sys_timer_ms(void); 73 | void sys_wait_ms(uint32_t delay); 74 | #else 75 | extern int16_t screenWidth, screenHeight; 76 | void initFizzle(void); 77 | #define GS_MODE 4 78 | 79 | #include "syscode.h" 80 | #endif 81 | 82 | -------------------------------------------------------------------------------- /fpdoom/include/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDIO 2 | #define __STDIO 3 | 4 | #include "stddef.h" 5 | #include "stdarg.h" 6 | #include "stdint.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | struct _IO_FILE; 13 | typedef struct _IO_FILE FILE; 14 | 15 | #define BUFSIZ 1024 16 | 17 | #define stdin _stdin 18 | #define stdout _stdout 19 | #define stderr _stderr 20 | 21 | extern FILE *stdin, *stdout, *stderr; 22 | 23 | #define EOF (-1) 24 | #define SEEK_SET 0 25 | #define SEEK_CUR 1 26 | #define SEEK_END 2 27 | 28 | int getchar(void); 29 | int putchar(int); 30 | int fgetc(FILE*); 31 | int ungetc(int, FILE*); 32 | int feof(FILE*); 33 | int fputc(int, FILE*); 34 | int puts(const char*); 35 | int fputs(const char*, FILE*); 36 | char *fgets(char*, int, FILE*); 37 | 38 | FILE *fopen(const char*, const char*); 39 | int fseek(FILE*, long, int); 40 | long ftell(FILE*); 41 | size_t fread(void*, size_t, size_t, FILE*); 42 | size_t fwrite(const void*, size_t, size_t, FILE*); 43 | int fclose(FILE*); 44 | int fflush(FILE*); 45 | void setbuf(FILE*, char*); 46 | 47 | #ifndef __GNUC__ 48 | #define __attribute__(attr) 49 | #endif 50 | 51 | __attribute__((__format__(__printf__, 1, 2))) 52 | int printf(const char*, ...); 53 | __attribute__((__format__(__printf__, 2, 3))) 54 | int sprintf(char*, const char*, ...); 55 | __attribute__((__format__(__printf__, 3, 4))) 56 | int snprintf(char*, size_t, const char*, ...); 57 | __attribute__((__format__(__printf__, 2, 3))) 58 | int fprintf(FILE*, const char*, ...); 59 | int vprintf(const char*, va_list); 60 | int vsprintf(char*, const char*, va_list); 61 | int vsnprintf(char*, size_t, const char*, va_list); 62 | int vfprintf(FILE*, const char*, va_list); 63 | 64 | __attribute__((__format__(__scanf__, 2, 3))) 65 | int sscanf(const char *, const char *, ...); 66 | __attribute__((__format__(__scanf__, 2, 3))) 67 | int fscanf(FILE*, const char*, ...); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /fpdoom/init_sc6530.h: -------------------------------------------------------------------------------- 1 | #ifdef SMC_INIT_BUF 2 | extern int sc6530_init_smc_asm[1]; 3 | extern int sc6530_init_smc_asm_end[1]; 4 | static void sc6530_init_smc(void) { 5 | // must be run from on-chip RAM 6 | int *p = sc6530_init_smc_asm; 7 | int n = sc6530_init_smc_asm_end - p; 8 | int *d = (int*)SMC_INIT_BUF, *f = d; 9 | do *d++ = *p++; while (--n); 10 | ((void(*)(void))(intptr_t)f)(); 11 | } 12 | #else 13 | static void sc6530_init_smc(void) { 14 | uint32_t base = 0x20000000, ps; 15 | 16 | ps = MEM_REMAP; 17 | ps = ps << 29 | ps << 28 | 0x04000000; 18 | 19 | MEM4(base + 0x00) = 0x22220000; 20 | MEM4(base + 0x04) = 0; 21 | MEM4(base + 0x20) = 0; 22 | MEM4(base + 0x24) = 0x00924ff0; 23 | MEM4(base + 0x28) = 0x0151ffff; 24 | MEM4(base + 0x2c) = 0x00a0744f; 25 | DELAY(100) 26 | MEM4(base + 0x00) = 0x222211e0; 27 | MEM4(base + 0x04) = 0x8080; 28 | DELAY(10) 29 | MEM4(base + 0x24) |= 0x20000; 30 | MEM2(ps + 0x10323e) = 0; 31 | MEM2(ps + 0x20) = 0; 32 | DELAY(10) 33 | MEM4(base + 0x24) &= ~0x20000; 34 | DELAY(10) 35 | MEM4(base + 0x24) = 0x00ac1fff; 36 | MEM4(base + 0x28) = 0x015115ff; 37 | MEM4(base + 0x2c) = 0x00501015; 38 | MEM4(base + 0x00) = 0x222210e0; 39 | MEM4(base + 0x04) = 0x8080; 40 | DELAY(100) 41 | } 42 | #endif 43 | 44 | static void sc6530_init_freq(void) { 45 | uint32_t a; 46 | #if 0 // what's this? 47 | MEM4(0x8b0000a0) = -2; 48 | MEM4(0x8b0000a8) = -2; 49 | #endif 50 | // CPU freq 51 | a = MEM4(0x8b000040); 52 | MEM4(0x8b000040) = a |= 4; 53 | MEM4(0x8b000040) = (a & ~3) | 1; // 208 MHz 54 | DELAY(100) 55 | } 56 | 57 | static void sc6530_init_adi(void) { 58 | MEM4(0x8b0000a0) = 1 << 24; // ADI enable 59 | // ADI reset 60 | MEM4(0x8b000060) = 1 << 19; 61 | DELAY(100) 62 | MEM4(0x8b000064) = 1 << 19; 63 | // init analog 64 | MEM4(0x82000000) &= ~(1 << 4); 65 | MEM4(0x82000004) = 0x55000; 66 | } 67 | 68 | static void init_sc6530(void) { 69 | sc6530_init_freq(); 70 | sc6530_init_smc(); 71 | sc6530_init_adi(); 72 | } 73 | 74 | -------------------------------------------------------------------------------- /ums9117/entry2.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "cmd_def.h" 3 | #include "usbio.h" 4 | #include "syscode.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #if LIBC_SDIO 10 | #include "sdio.h" 11 | #include "microfat.h" 12 | #include "fatfile.h" 13 | #endif 14 | 15 | void _debug_msg(const char *msg); 16 | void _malloc_init(void *addr, size_t size); 17 | void _stdio_init(void); 18 | int _argv_init(char ***argvp, int skip); 19 | int _argv_copy(char ***argvp, int argc, char *src); 20 | 21 | size_t app_mem_reserve(void *start, size_t size); 22 | void sys_set_handlers(void); 23 | int main(int argc, char **argv); 24 | 25 | #ifdef CXX_SUPPORT 26 | #include "cxx_init.h" 27 | #endif 28 | 29 | void entry_main2(char *image_addr, uint32_t image_size, uint32_t bss_size, int arg_skip) { 30 | int argc; char **argv = NULL; 31 | uint32_t ram_addr = (uint32_t)image_addr & 0xf0000000; 32 | uint32_t ram_size = MEM4(image_addr); 33 | 34 | memset(image_addr + image_size, 0, bss_size); 35 | 36 | #if LIBC_SDIO < 3 37 | usb_init(); 38 | _debug_msg("entry2"); 39 | #endif 40 | { 41 | char *addr = image_addr + image_size + bss_size; 42 | size_t size = ram_addr + ram_size - (uint32_t)addr; 43 | char *p; 44 | p = addr + size; 45 | #if LIBC_SDIO 46 | p -= sizeof(fatdata_t); 47 | memcpy(&fatdata_glob, p, sizeof(fatdata_t)); 48 | sdio_shl = MEM4(CHIPRAM_ADDR); 49 | #endif 50 | // load sys_data 51 | p -= sizeof(sys_data); 52 | memcpy(&sys_data, p, sizeof(sys_data)); 53 | #ifdef APP_MEM_RESERVE 54 | size = app_mem_reserve(addr, size); 55 | #endif 56 | _malloc_init(addr, size); 57 | } 58 | _stdio_init(); 59 | #if CHIPRAM_ARGS || LIBC_SDIO >= 3 60 | (void)arg_skip; 61 | { 62 | char *p = (char*)CHIPRAM_ADDR + 4; 63 | argc = _argv_copy(&argv, *(short*)p, p + sizeof(short)); 64 | } 65 | #else 66 | argc = _argv_init(&argv, arg_skip); 67 | #endif 68 | sys_set_handlers(); 69 | #ifdef CXX_SUPPORT 70 | cxx_init(argc, argv); 71 | #endif 72 | exit(main(argc, argv)); 73 | } 74 | 75 | -------------------------------------------------------------------------------- /fpdoom/start1.s: -------------------------------------------------------------------------------- 1 | @ -*- tab-width: 8 -*- 2 | .arch armv5te 3 | .syntax unified 4 | 5 | .macro CODE32_FN name 6 | .section .text.\name, "ax", %progbits 7 | .p2align 2 8 | .code 32 9 | .type \name, %function 10 | .global \name 11 | \name: 12 | .endm 13 | 14 | CODE32_FN _start 15 | 16 | // 0 : MMU enable 17 | // 1 : Alignment fault enable 18 | // 2 : Level 1 Data Cache enable 19 | // 8 : System protection 20 | // 9 : ROM protection 21 | // 12 : Instruction Cache enable 22 | // 13 : Location of exception vectors 23 | 24 | mov r1, #0 25 | mcr p15, #0, r1, c7, c5, #0 // Invalidate ICache 26 | mrc p15, #0, r0, c1, c0, #0 // Read Control Register 27 | bic r0, #5 // 2 + 0 28 | // SR=01, read-only 29 | bic r0, #0x100 // 8 30 | orr r0, #2 // 1 31 | orr r0, #0x3200 // 13 + 12 + 9 32 | mcr p15, #0, r0, c1, c0, #0 // Write Control Register 33 | msr CPSR_c, #0xdf // SYS mode 34 | ldr sp, 1f 35 | 36 | ldr r2, 3f 37 | ldr r1, 4f 38 | adr r0, _start 39 | subs r2, r0, r2 40 | push {r0-r1} 41 | add r1, r0 42 | blne apply_reloc 43 | add r3, r1, #3 44 | pop {r0-r1} 45 | bic r3, #3 46 | 47 | ldr r2, 5f 48 | push {r4-r5} // r5 for alignement 49 | bl entry_main 50 | add sp, #8 51 | mov r3, r0 52 | mov r0, r4 53 | ldr r1, [r4, #0x10] 54 | ldr r2, [r4, #0x14] 55 | ldr pc, [r4, #0x18] // entry_main 56 | 57 | 1: .long __stack_bottom 58 | 3: .long __image_start 59 | 4: .long __image_size 60 | 5: .long __bss_size 61 | 62 | .type apply_reloc, %function 63 | .global apply_reloc 64 | apply_reloc: 65 | // r0 = image, r1 = reloc, r2 = diff 66 | push {r4-r7,lr} 67 | mov r5, #1 68 | ldrb r6, [r1], #1 // nbits 69 | ldrb r7, [r1], #1 // maxrun 70 | 1: mov ip, #0 71 | mov lr, r7 72 | 2: ldrb r4, [r1], #1 73 | sub lr, lr, r4, lsl ip 74 | lsrs r4, r6 75 | add ip, r6 76 | beq 2b 77 | adds lr, lr, r5, lsl ip 78 | popeq {r4-r7,pc} 79 | asrs ip, lr, #1 80 | mvncc r3, #0 81 | movmi r3, lr 82 | 3: ldr r4, [r0, -r3, lsl #2]! 83 | add r4, r2 84 | str r4, [r0] 85 | subs ip, #1 86 | bpl 3b 87 | b 1b 88 | 89 | -------------------------------------------------------------------------------- /fpdoom/start.s: -------------------------------------------------------------------------------- 1 | @ -*- tab-width: 8 -*- 2 | .arch armv5te 3 | .syntax unified 4 | 5 | .macro CODE32_FN name 6 | .section .text.\name, "ax", %progbits 7 | .p2align 2 8 | .code 32 9 | .type \name, %function 10 | .global \name 11 | \name: 12 | .endm 13 | 14 | CODE32_FN _start 15 | 16 | // 0 : MMU enable 17 | // 1 : Alignment fault enable 18 | // 2 : Level 1 Data Cache enable 19 | // 8 : System protection 20 | // 9 : ROM protection 21 | // 12 : Instruction Cache enable 22 | // 13 : Location of exception vectors 23 | 24 | mov r1, #0 25 | mcr p15, #0, r1, c7, c5, #0 // Invalidate ICache 26 | mrc p15, #0, r0, c1, c0, #0 // Read Control Register 27 | bic r0, #5 // 2 + 0 28 | // SR=01, read-only 29 | bic r0, #0x100 // 8 30 | orr r0, #2 // 1 31 | orr r0, #0x3200 // 13 + 12 + 9 32 | mcr p15, #0, r0, c1, c0, #0 // Write Control Register 33 | msr CPSR_c, #0xdf // SYS mode 34 | .if 0 // remap flash to 0 35 | adr lr, 10f 36 | ldmia lr!, {r1-r4} 37 | stm r2, {r3-r4} 38 | ldr r0, [r1] 39 | bic r0, #1 40 | bic lr, #0xf0000000 41 | bx r2 42 | 10: .long 0x205000e0, 0x40009000 43 | str r0, [r1] 44 | bx lr 45 | .endif 46 | ldr sp, 1f 47 | 48 | ldr r2, 3f 49 | ldr r1, 4f 50 | adr r0, _start 51 | subs r2, r0, r2 52 | push {r0-r1} 53 | add r1, r0 54 | blne apply_reloc 55 | pop {r0-r1} 56 | 57 | ldr r2, 5f 58 | ldr pc, 2f 59 | 2: .long entry_main 60 | 1: .long __stack_bottom 61 | 3: .long __image_start 62 | 4: .long __image_size 63 | 5: .long __bss_size 64 | 65 | .type apply_reloc, %function 66 | .global apply_reloc 67 | apply_reloc: 68 | // r0 = image, r1 = reloc, r2 = diff 69 | push {r4-r7,lr} 70 | mov r5, #1 71 | ldrb r6, [r1], #1 // nbits 72 | ldrb r7, [r1], #1 // maxrun 73 | 1: mov ip, #0 74 | mov lr, r7 75 | 2: ldrb r4, [r1], #1 76 | sub lr, lr, r4, lsl ip 77 | lsrs r4, r6 78 | add ip, r6 79 | beq 2b 80 | adds lr, lr, r5, lsl ip 81 | popeq {r4-r7,pc} 82 | asrs ip, lr, #1 83 | mvncc r3, #0 84 | movmi r3, lr 85 | 3: ldr r4, [r0, -r3, lsl #2]! 86 | add r4, r2 87 | str r4, [r0] 88 | subs ip, #1 89 | bpl 3b 90 | b 1b 91 | 92 | -------------------------------------------------------------------------------- /fpbuild/a-new.c: -------------------------------------------------------------------------------- 1 | #include "a.h" 2 | #include "compat.h" 3 | 4 | #ifdef USE_ASM 5 | extern 6 | #endif 7 | struct { 8 | int bpl, transmode; 9 | int logx, logy, bxinc, byinc, pinc; 10 | unsigned char *buf, *pal, *hlinepal, *trans; 11 | } buildasm_data; 12 | #define g buildasm_data 13 | 14 | // Global variable functions 15 | void setvlinebpl(int dabpl) { g.bpl = dabpl; } 16 | void fixtransluscence(void *datransoff) { g.trans = datransoff; } 17 | void settransnormal(void) { g.transmode = 0; } 18 | void settransreverse(void) { g.transmode = 1; } 19 | 20 | // Ceiling/floor horizontal line functions 21 | void sethlinesizes(int logx, int logy, void *bufplc) 22 | { g.logx = logx; g.logy = logy; g.buf = bufplc; } 23 | void setpalookupaddress(void *paladdr) { g.hlinepal = paladdr; } 24 | void setuphlineasm4(int bxinc, int byinc) { g.bxinc = bxinc; g.byinc = byinc; } 25 | 26 | // Sloped ceiling/floor vertical line functions 27 | void setupslopevlin(int logylogx, void *bufplc, int pinc) { 28 | g.logx = logylogx & 255; g.logy = logylogx >> 8; 29 | g.buf = bufplc; g.pinc = pinc; 30 | } 31 | 32 | // Wall,face sprite/wall sprite vertical line functions 33 | void setupvlineasm(int neglogy) { g.logy = neglogy; } 34 | void setupmvlineasm(int neglogy) { g.logy = neglogy; } 35 | void setuptvlineasm(int neglogy) { g.logy = neglogy; } 36 | 37 | // Floor sprite horizontal line functions 38 | void msethlineshift(int logx, int logy) { g.logx = logx; g.logy = logy; } 39 | void tsethlineshift(int logx, int logy) { g.logx = logx; g.logy = logy; } 40 | 41 | // Rotatesprite vertical line functions 42 | void setupspritevline(void *paloffs, int bxinc, int byinc, int ysiz) { 43 | g.pal = paloffs; g.bxinc = bxinc; g.byinc = byinc; g.logy = ysiz; 44 | } 45 | 46 | void msetupspritevline(void *paloffs, int bxinc, int byinc, int ysiz) { 47 | g.pal = paloffs; g.bxinc = bxinc; g.byinc = byinc; g.logy = ysiz; 48 | } 49 | 50 | void tsetupspritevline(void *paloffs, int bxinc, int byinc, int ysiz) { 51 | g.pal = paloffs; g.bxinc = bxinc; g.byinc = byinc; g.logy = ysiz; 52 | } 53 | 54 | void setupdrawslab (int dabpl, void *pal) { 55 | g.bpl = dabpl; g.pal = pal; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /infones/README.md: -------------------------------------------------------------------------------- 1 | ## InfoNES port 2 | 3 | Port of the [InfoNES](https://github.com/jay-kumogata/InfoNES). 4 | 5 | I hope that the author of InfoNES will pay attention to the huge number of bugs in his code, such as writing element 0x4015 to an array of size 0x18. Also that "NES Emulator in C++" is complete nonsense, the code will not become written in C++ if you change the extension of the C source files to .cpp. 6 | 7 | ### Build 8 | 9 | 1. Download specific sources and apply patches: 10 | `$ make -f helper.make all patch` 11 | 12 | 2. Use the same instructions as for `fpdoom`. 13 | 14 | ### Game controls 15 | 16 | | Key(s) | Action | 17 | |----------------|--------------------| 18 | | Left Soft Key | select | 19 | | Right Soft Key | start | 20 | | Direction Pad | movement | 21 | | D-pad Center | A | 22 | | Dial Key | A | 23 | | 2, 4, 5, 6 | up/left/down/right | 24 | | *, 0, # | A | 25 | | 1, 3, 7, 8, 9 | B | 26 | | Power + LSoft | start | 27 | | Power + Dial | exit | 28 | | Power + Up | reset | 29 | | Power + Down | exit | 30 | | Power + Left | select | 31 | | Power + Right | start | 32 | | Power + Center | B | 33 | | Power + 0 | force save SRAM | 34 | 35 | * The reset/exit keys must be held for 1 second to activate. This is to prevent accidental pressing. 36 | 37 | ### Issues 38 | 39 | * InfoNES is far from the best emulator, half of the games don't work or are too glitchy. 40 | 41 | * Most games that use iNES Mapper 004 are unplayable due to serious graphical glitches. 42 | 43 | * This emulator only supports NTSC 60Hz mode. 44 | 45 | * Some game cartridges have SRAM for saves, this memory is saved on exit or if you force save SRAM. If the device is turned off, the SRAM changes will be lost. 46 | 47 | * The FAT32 file system driver can't create files with long names, if you want to save SRAM the ROM file name must be in DOS 8.3 format or you need to create an empty file with the ROM name and the `.srm` extension in advance. 48 | 49 | -------------------------------------------------------------------------------- /fpdoom/sfc.h: -------------------------------------------------------------------------------- 1 | #ifndef SFC_H 2 | #define SFC_H 3 | 4 | #include 5 | 6 | /* Serial Flash Controller */ 7 | #define SFC_BASE ((sfc_base_t*)0x20a00000) 8 | 9 | typedef volatile struct { 10 | uint32_t cmd_set, soft_req, tbuf_clr, int_clr; 11 | uint32_t status, timing, rd_sample, clk; 12 | uint32_t cs, lsb, io_dly, wp_hld_init; 13 | uint32_t dl0, dl1, dll, dummy_3c; 14 | uint32_t cmd[12], type_info[3], dummy_7c; 15 | } sfc_base_t; 16 | 17 | enum { 18 | SFC_BIT_MODE1 = 0, 19 | SFC_BIT_MODE2 = 1, 20 | SFC_BIT_MODE4 = 2, 21 | 22 | SFC_OP_WRITE = 0, 23 | SFC_OP_READ = 1, 24 | SFC_OP_HIGHZ = 2, 25 | }; 26 | 27 | void sfc_init(void); 28 | void sfc_cmdclr(sfc_base_t *sfc); 29 | uint32_t sfc_cmd_read(int cs, unsigned cmd, unsigned len); 30 | void sfc_write_status(int cs, unsigned val); 31 | void sfc_write_enable(int cs); 32 | void sfc_erase(int cs, int addr, int cmd, int addr_len); 33 | void sfc_write(int cs, int addr, const void *buf, unsigned size); 34 | void sfc_read(int cs, int addr, void *buf, unsigned size); 35 | void sfc_read_sfdp(int cs, int addr, void *buf, unsigned size); 36 | #define SFC_CMP_PRE 0 /* check if erasing is necessary */ 37 | #define SFC_CMP_POST ~0 /* check that the data was written correctly */ 38 | #define SFC_CMP_ERASE 1 39 | unsigned sfc_compare(int cs, int addr, const void *buf, unsigned size, uint32_t mode); 40 | void sfc_spiread(int cs); 41 | const char* sfc_getvendor(uint32_t id); 42 | const char* sfc_getname(uint32_t id); 43 | 44 | static inline uint32_t sfc_readid(int cs) { 45 | // Read JEDEC ID 46 | return sfc_cmd_read(cs, 0x9f, 3) >> 8; 47 | } 48 | 49 | static inline uint32_t sfc_read_status(int cs) { 50 | // Read Status Register 51 | return sfc_cmd_read(cs, 0x05, 1) >> 24; 52 | } 53 | 54 | #define SFC_CMDSET(sfc, bit, cmdbuf) do { \ 55 | sfc->cmd_set = (sfc->cmd_set & ~0x1e) | (SFC_BIT_MODE##bit << 1 | (7 - cmdbuf) << 3); \ 56 | } while (0) 57 | 58 | #define SFC_TYPEINFO(bit, num, op, send) \ 59 | (1 | SFC_BIT_MODE##bit << 1 | (num - 1) << 3 | SFC_OP_##op << 5 | send << 7) 60 | 61 | #define SFC_WRITE_WAIT(cs) do { \ 62 | sys_wait_us(30); \ 63 | /* wait for completion */ \ 64 | while (sfc_read_status(cs) & 1); \ 65 | } while (0) 66 | 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /wolf3d/Makefile: -------------------------------------------------------------------------------- 1 | NAME = wolf3d 2 | GAMESRC = Wolf4SDL 3 | USE_ASM = 1 4 | NO_FLOAT = 1 5 | 6 | ifeq ($(GAMEVER),) 7 | GAMEVER = CARMACIZED GOODTIMES # v1.4 8 | ifneq ($(filter %_apo,$(NAME)),) 9 | GAMEVER = CARMACIZED # v1.4 apogee 10 | else ifneq ($(filter %_sw,$(NAME)),) 11 | GAMEVER = CARMACIZED UPLOAD # sw v1.4 12 | else ifneq ($(filter %_sod,$(NAME)),) 13 | GAMEVER = CARMACIZED GOODTIMES SPEAR 14 | else ifneq ($(filter %_sdm,$(NAME)),) 15 | GAMEVER = CARMACIZED SPEAR SPEARDEMO 16 | endif 17 | endif 18 | ifneq ($(GAMEVER),) 19 | GAME_CFLAGS += -DVERSIONALREADYCHOSEN $(GAMEVER:%=-D%) 20 | endif 21 | 22 | APP_SRCS = extra scr_update wlsys_fp 23 | ifneq ($(USE_ASM), 0) 24 | APP_SRCS += wolfasm 25 | endif 26 | 27 | GAME_SRCS = \ 28 | id_ca id_in id_pm id_sd id_us id_vh id_vl \ 29 | signon wl_act1 wl_act2 wl_agent wl_atmos \ 30 | wl_cloudsky wl_debug wl_draw wl_game wl_inter \ 31 | wl_main wl_menu wl_parallax wl_plane wl_play \ 32 | wl_scale wl_shade wl_state wl_text wl_utils 33 | 34 | APP_OBJS1 = $(APP_SRCS:%=$(OBJDIR)/app/%.o) 35 | APP_OBJS2 = $(GAME_SRCS:%=$(OBJDIR)/game/%.o) 36 | 37 | include ../buildinc.make 38 | 39 | CFLAGS := $(filter-out -funsigned-char, $(CFLAGS)) -fsigned-char 40 | 41 | APP_CFLAGS += -std=gnu99 -pedantic 42 | 43 | GAME_CFLAGS += -DNO_SOUND=1 -DNO_MOUSE=1 -DNO_JOYSTICK=1 44 | GAME_CFLAGS += -DVIEWMAP -DREVEALMAP 45 | #GAME_CFLAGS += -DTRACE_UPDATE=1 46 | ifeq ($(LIBC_SDIO), 0) 47 | GAME_CFLAGS += -DLINUX_FN_FIX=1 48 | endif 49 | ifneq ($(USE_ASM), 0) 50 | GAME_CFLAGS += -DUSE_ASM 51 | endif 52 | ifneq ($(NO_FLOAT), 0) 53 | GAME_CFLAGS += -DNO_FLOAT=1 -I$(OBJDIR) 54 | endif 55 | GAME_CFLAGS += -I$(GAMESRC) -I. 56 | GAME_CFLAGS += -Wno-unused -Wno-unused-parameter 57 | GAME_CFLAGS += -Wno-strict-prototypes 58 | 59 | GAME_CFLAGS := $(APP_CFLAGS) $(GAME_CFLAGS) 60 | APP_CFLAGS := $(GAME_CFLAGS) -I$(SYSDIR) 61 | 62 | ifneq ($(NO_FLOAT), 0) 63 | $(OBJDIR)/game/wl_draw.o: $(OBJDIR)/wolf3d_tables.h 64 | 65 | $(OBJDIR)/calctables: calctables.c | $(OBJDIR) 66 | $(HOSTCC) -O2 $< -o $@ -lm 67 | 68 | $(OBJDIR)/wolf3d_tables.h: $(OBJDIR)/calctables 69 | $(OBJDIR)/calctables $@ 70 | endif 71 | 72 | $(OBJDIR)/game/%.o: $(GAMESRC)/%.c | objdir 73 | $(call compile_cc,$(GAME_CFLAGS)) 74 | 75 | -------------------------------------------------------------------------------- /wolf3d/calctables.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef int32_t fixed; 6 | 7 | #define PI 3.141592657 8 | 9 | #define GLOBAL1 (1l<<16) 10 | #define ANGLES 360 11 | #define ANGLEQUAD (ANGLES/4) 12 | #define FINEANGLES 3600 13 | 14 | const float radtoint = (float)(FINEANGLES/2/PI); 15 | 16 | int32_t finetangent[FINEANGLES/4]; 17 | fixed sintable[ANGLES+ANGLES/4]; 18 | 19 | void BuildTables (void) 20 | { 21 | int i; 22 | for(i=0;i= 2) fn = argv[1]; 58 | 59 | BuildTables(); 60 | init_atan2_tab(); 61 | 62 | f = fopen(fn, "wb"); 63 | if (!f) return 1; 64 | 65 | #define PRINTARR(arr, n) \ 66 | for (j = 0; j < (n); j++) { \ 67 | fprintf(f, "%d, ", arr[j]); \ 68 | if ((j + 1) % 8 == 0) fprintf(f, "\n"); \ 69 | } 70 | 71 | fprintf(f, "int32_t finetangent[FINEANGLES/4] = {\n"); 72 | PRINTARR(finetangent, FINEANGLES/4) 73 | fprintf(f, "};\n"); 74 | fprintf(f, "fixed sintable[ANGLES+ANGLES/4] = {\n"); 75 | PRINTARR(sintable, ANGLES+ANGLES/4) 76 | fprintf(f, "};\n"); 77 | fprintf(f, "const uint8_t atan2_tab[0x801] = {\n"); 78 | PRINTARR(atan2_tab, 0x801) 79 | fprintf(f, "};\n"); 80 | fclose(f); 81 | } 82 | 83 | -------------------------------------------------------------------------------- /fpbuild/calctables.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | unsigned char britable[16][256]; 6 | short sintable[2048], radarang[1280]; 7 | 8 | static uint32_t crc32once(const void *src, size_t n) { 9 | const uint8_t *s = src; int j; uint32_t c; 10 | for (c = ~0; n--;) 11 | for (c ^= *s++, j = 8; j--;) 12 | c = c >> 1 ^ ((0 - (c & 1)) & 0xedb88320); 13 | return ~c; 14 | } 15 | 16 | static void calcbritable(void) { 17 | int i, j; double a, b; 18 | for (i = 0; i < 16; i++) { 19 | a = (double)8 / ((double)i + 8); 20 | b = (double)255 / pow((double)255, a); 21 | for (j = 0; j < 256; j++) 22 | britable[i][j] = (unsigned char)(pow((double)j, a) * b); 23 | } 24 | } 25 | 26 | static int calctables(void) { 27 | int i; 28 | for (i = 0; i < 2048; i++) { 29 | sintable[i] = (short)(16384 * sin((double)i * 3.14159265358979 / 1024)); 30 | } 31 | for (i = 0; i < 640; i++) { 32 | radarang[i] = (short)(atan(((double)i - 639.5) / 160) * 64 * 1024 / 3.14159265358979); 33 | radarang[1279 - i] = -radarang[i]; 34 | } 35 | calcbritable(); 36 | 37 | if (crc32once(sintable, sizeof(sintable)) != 0xee1e7aba) { 38 | puts("Calculation of sintable yielded unexpected results."); 39 | return 1; 40 | } 41 | if (crc32once(radarang, sizeof(radarang)/2) != 0xee893d92) { 42 | puts("Calculation of radarang yielded unexpected results."); 43 | return 1; 44 | } 45 | return 0; 46 | } 47 | 48 | int main(int argc, char **argv) { 49 | const char *fn = "engine_tables.h"; 50 | unsigned i, j; 51 | FILE *f; 52 | if (argc >= 2) fn = argv[1]; 53 | 54 | if (calctables()) return 1; 55 | 56 | f = fopen(fn, "wb"); 57 | if (!f) return 1; 58 | 59 | #define PRINTARR(arr, n) \ 60 | for (j = 0; j < n; j++) { \ 61 | fprintf(f, "%i, ", arr[j]); \ 62 | if ((j + 1) % 8 == 0) fprintf(f, "\n"); \ 63 | } 64 | 65 | fprintf(f, "const unsigned char britable[16][256] = { {\n"); 66 | for (i = 0; i < 16; i++) { 67 | if (i) fprintf(f, "}, {\n"); 68 | PRINTARR(britable[i], 256) 69 | } 70 | fprintf(f, "} };\n"); 71 | fprintf(f, "const short sintable[2048] = {\n"); 72 | PRINTARR(sintable, 2048) 73 | fprintf(f, "};\n"); 74 | fprintf(f, "const short radarang[1280] = {\n"); 75 | PRINTARR(radarang, 1280) 76 | fprintf(f, "};\n"); 77 | fclose(f); 78 | } 79 | 80 | -------------------------------------------------------------------------------- /fpdoom/keytrn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #if EMBEDDED == 1 3 | #include "../pctest/syscode.h" 4 | #else 5 | #include "syscode.h" 6 | #endif 7 | #include "doomkey.h" 8 | 9 | #define X(num, name) KEYPAD_##name = num, 10 | enum { KEYPAD_ENUM(X) }; 11 | #undef X 12 | 13 | void keytrn_init(void) { 14 | uint8_t keymap[64], rkeymap[64]; 15 | static const uint8_t keys[] = { 16 | #define KEY(name, val) KEYPAD_##name, val, 17 | KEY(UP, KEY_UPARROW) 18 | KEY(LEFT, KEY_LEFTARROW) 19 | KEY(RIGHT, KEY_RIGHTARROW) 20 | KEY(DOWN, KEY_DOWNARROW) 21 | KEY(2, KEY_UPARROW) 22 | KEY(4, KEY_LEFTARROW) 23 | KEY(6, KEY_RIGHTARROW) 24 | KEY(5, KEY_DOWNARROW) 25 | KEY(LSOFT, KEY_ENTER) 26 | KEY(RSOFT, KEY_ESCAPE) 27 | KEY(CENTER, KEY_RCTRL) /* fire */ 28 | KEY(DIAL, KEY_RSHIFT) /* run toggle */ 29 | KEY(1, ',') /* strafe left */ 30 | KEY(3, '.') /* strafe right */ 31 | KEY(8, ' ') /* unused */ 32 | KEY(7, ';') /* prev weapon */ 33 | KEY(9, '\'') /* next weapon */ 34 | KEY(VOLUP, KEY_EQUALS) 35 | KEY(VOLDOWN, KEY_MINUS) 36 | KEY(PLUS, KEY_TAB) /* map */ 37 | }; 38 | static const uint8_t keys_power[] = { 39 | KEY(UP, KEY_RSHIFT) 40 | KEY(LEFT, ';') 41 | KEY(RIGHT, '\'') 42 | KEY(DOWN, KEY_ESCAPE) 43 | KEY(CENTER, KEY_ENTER) 44 | 45 | KEY(LSOFT, KEY_EQUALS) 46 | KEY(RSOFT, KEY_MINUS) 47 | KEY(DIAL, KEY_TAB) /* map */ 48 | KEY(0, KEY_F11) /* gamma */ 49 | /* for cheats */ 50 | KEY(1, 'i') 51 | KEY(2, 'd') 52 | KEY(3, 'q') 53 | KEY(4, 'k') 54 | KEY(5, 'f') 55 | KEY(6, 'a') 56 | #undef KEY 57 | }; 58 | int i, flags = sys_getkeymap(keymap); 59 | 60 | #define FILL_RKEYMAP(keys) \ 61 | memset(rkeymap, 0, sizeof(rkeymap)); \ 62 | for (i = 0; i < (int)sizeof(keys); i += 2) \ 63 | rkeymap[keys[i]] = keys[i + 1]; 64 | 65 | FILL_RKEYMAP(keys) 66 | 67 | #define KEY(name) rkeymap[KEYPAD_##name] 68 | // no center key 69 | if (!(flags & 1)) { 70 | KEY(UP) = KEY_RCTRL; /* fire */ 71 | KEY(DOWN) = KEY_RCTRL; /* fire */ 72 | } 73 | #undef KEY 74 | 75 | #define FILL_KEYTRN(j) \ 76 | for (i = 0; i < 64; i++) { \ 77 | unsigned a = keymap[i]; \ 78 | sys_data.keytrn[j][i] = a < 64 ? rkeymap[a] : 0; \ 79 | } 80 | 81 | FILL_KEYTRN(0) 82 | FILL_RKEYMAP(keys_power) 83 | FILL_KEYTRN(1) 84 | #undef FILL_RKEYMAP 85 | #undef FILL_KEYTRN 86 | } 87 | 88 | -------------------------------------------------------------------------------- /snes9x/Makefile: -------------------------------------------------------------------------------- 1 | USE_16BIT := $(if $(filter %_16bit,$(NAME)),1,0) 2 | NAME := snes9x$(if $(filter 0,$(USE_16BIT)),,_16bit) 3 | SNES9X = snes9x_src 4 | USE_FILEMAP = 1 5 | USE_ASM = 1 6 | NO_FLOAT = 1 7 | DSP1_NEW = 1 8 | NO_SA1 = 1 9 | NO_C4 = $(NO_FLOAT) 10 | NO_DSP1 = $(if $(filter 1,$(DSP1_NEW)),0,$(NO_FLOAT)) 11 | NO_DSP4 = $(NO_FLOAT) 12 | 13 | APP_SRCS = snes9x_fp extra scr_update 14 | ifneq ($(USE_ASM), 0) 15 | APP_SRCS += snesasm 16 | endif 17 | 18 | SNES_SRCS = apu cheats2 \ 19 | clip cpu cpuexec cpuops data dma dsp1 \ 20 | fxemu fxinst gfx globals memmap \ 21 | obc1 ppu sdd1 seta seta010 seta011 seta018 \ 22 | snapshot soundux spc700 spc7110 srtc tile 23 | 24 | ifeq ($(NO_SA1), 0) 25 | SNES_SRCS += sa1 sa1cpu 26 | endif 27 | ifeq ($(NO_C4), 0) 28 | SNES_SRCS += c4 c4emu 29 | endif 30 | 31 | APP_OBJS1 = $(APP_SRCS:%=$(OBJDIR)/app/%.o) 32 | APP_OBJS2 = $(SNES_SRCS:%=$(OBJDIR)/snes/%.o) 33 | 34 | include ../buildinc.make 35 | 36 | SYS_CFLAGS += -DCXX_SUPPORT 37 | CFLAGS := $(filter-out -funsigned-char, $(CFLAGS)) -fsigned-char 38 | CXXFLAGS := $(CFLAGS) -std=c++14 -fno-exceptions -fno-rtti -Wno-narrowing 39 | 40 | APP_CFLAGS += -DHAVE_STRINGS_H -DHAVE_STDINT_H -DRIGHTSHIFT_IS_SAR 41 | APP_CFLAGS += -DNOSOUND -DNDEBUG 42 | APP_CFLAGS += -DUSE_16BIT=$(USE_16BIT) 43 | APP_CFLAGS += -DVAR_CYCLES -DCPU_SHUTDOWN -DSPC700_C 44 | #APP_CFLAGS += -DSPC700_SHUTDOWN 45 | APP_CFLAGS += -I$(SNES9X) -I$(SNES9X)/unzip 46 | ifneq ($(USE_ASM), 0) 47 | APP_CFLAGS += -DUSE_ASM 48 | endif 49 | ifneq ($(NO_FLOAT), 0) 50 | APP_CFLAGS += -DNO_FLOAT=1 51 | endif 52 | ifneq ($(NO_SA1), 0) 53 | APP_CFLAGS += -DNO_SA1=1 54 | endif 55 | ifneq ($(NO_C4), 0) 56 | APP_CFLAGS += -DNO_C4=1 57 | endif 58 | ifneq ($(NO_DSP1), 0) 59 | APP_CFLAGS += -DNO_DSP1=1 60 | else ifneq ($(DSP1_NEW), 0) 61 | APP_CFLAGS += -DDSP1_NEW=1 62 | endif 63 | ifneq ($(NO_DSP4), 0) 64 | APP_CFLAGS += -DNO_DSP4=1 65 | endif 66 | APP_CFLAGS += -Wno-unused -Wno-unused-parameter 67 | APP_CFLAGS += -Wno-deprecated-register -Wno-null-pointer-subtraction 68 | APP_CFLAGS += -Wno-misleading-indentation 69 | APP_CFLAGS += -I$(SYSDIR) 70 | APP_CXXFLAGS := $(APP_CFLAGS) 71 | APP_CFLAGS += -std=c99 -pedantic 72 | 73 | $(OBJDIR)/app/%.o: %.cpp | objdir 74 | $(call compile_cxx,$(APP_CXXFLAGS)) 75 | 76 | $(OBJDIR)/snes/%.o: $(SNES9X)/%.cpp | objdir 77 | $(call compile_cxx,$(APP_CXXFLAGS)) 78 | 79 | -------------------------------------------------------------------------------- /fpdoom/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #include 5 | #include 6 | 7 | #define ALIGN(n) __attribute__((aligned(n))) 8 | 9 | void *memcpy(void *dst, const void *src, size_t count); 10 | void *memmove(void *dst, const void *src, size_t count); 11 | void *memset(void *dst, int ch, size_t count); 12 | 13 | unsigned fastchk16(unsigned crc, const void *src, int len); 14 | 15 | #define MEM1(addr) *(volatile uint8_t*)(addr) 16 | #define MEM2(addr) *(volatile uint16_t*)(addr) 17 | #define MEM4(addr) *(volatile uint32_t*)(addr) 18 | #define DELAY(n) { \ 19 | unsigned _count = n; \ 20 | do __asm__ __volatile__(""); while (--_count); \ 21 | } 22 | 23 | #define READ16_LE(p) ( \ 24 | ((uint8_t*)(p))[1] << 8 | \ 25 | ((uint8_t*)(p))[0]) 26 | 27 | #define READ32_LE(p) (uint32_t)( \ 28 | ((uint8_t*)(p))[3] << 24 | \ 29 | ((uint8_t*)(p))[2] << 16 | \ 30 | ((uint8_t*)(p))[1] << 8 | \ 31 | ((uint8_t*)(p))[0]) 32 | 33 | #define WRITE16_LE(p, a) do { \ 34 | ((uint8_t*)(p))[0] = (uint8_t)(a); \ 35 | ((uint8_t*)(p))[1] = (a) >> 8; \ 36 | } while (0) 37 | 38 | #define WRITE32_LE(p, a) do { \ 39 | ((uint8_t*)(p))[0] = (uint8_t)(a); \ 40 | ((uint8_t*)(p))[1] = (a) >> 8; \ 41 | ((uint8_t*)(p))[2] = (a) >> 16; \ 42 | ((uint8_t*)(p))[3] = (a) >> 24; \ 43 | } while (0) 44 | 45 | #define WRITE16_BE(p, a) do { \ 46 | ((uint8_t*)(p))[0] = (a) >> 8; \ 47 | ((uint8_t*)(p))[1] = (uint8_t)(a); \ 48 | } while (0) 49 | 50 | #define WRITE32_BE(p, a) do { \ 51 | ((uint8_t*)(p))[0] = (a) >> 24; \ 52 | ((uint8_t*)(p))[1] = (a) >> 16; \ 53 | ((uint8_t*)(p))[2] = (a) >> 8; \ 54 | ((uint8_t*)(p))[3] = (uint8_t)(a); \ 55 | } while (0) 56 | 57 | #define READ16_BE(p) ( \ 58 | ((uint8_t*)(p))[0] << 8 | \ 59 | ((uint8_t*)(p))[1]) 60 | 61 | #define READ32_BE(p) (uint32_t)( \ 62 | ((uint8_t*)(p))[0] << 24 | \ 63 | ((uint8_t*)(p))[1] << 16 | \ 64 | ((uint8_t*)(p))[2] << 8 | \ 65 | ((uint8_t*)(p))[3]) 66 | 67 | 68 | #ifndef __BYTE_ORDER__ 69 | #error 70 | #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 71 | uint16_t swap_be16(uint16_t v); 72 | uint32_t swap_be32(uint32_t v); 73 | #else 74 | static inline uint16_t swap_be16(uint16_t v) { return v; } 75 | static inline uint32_t swap_be32(uint32_t v) { return v; } 76 | #endif 77 | 78 | #if !CHIP 79 | extern int _chip; 80 | #else 81 | #define _chip CHIP 82 | #endif 83 | 84 | #endif // COMMON_H 85 | -------------------------------------------------------------------------------- /fpdoom/entry2.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "cmd_def.h" 3 | #include "usbio.h" 4 | #include "syscode.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #if LIBC_SDIO 10 | #include "sdio.h" 11 | #include "microfat.h" 12 | #include "fatfile.h" 13 | #endif 14 | 15 | void _debug_msg(const char *msg); 16 | void _malloc_init(void *addr, size_t size); 17 | void _stdio_init(void); 18 | int _argv_init(char ***argvp, int skip); 19 | int _argv_copy(char ***argvp, int argc, char *src); 20 | 21 | size_t app_mem_reserve(void *start, size_t size); 22 | void sys_set_handlers(void); 23 | int main(int argc, char **argv); 24 | 25 | #ifdef CXX_SUPPORT 26 | #include "cxx_init.h" 27 | #endif 28 | 29 | void entry_main2(char *image_addr, uint32_t image_size, uint32_t bss_size, int arg_skip) { 30 | int argc; char **argv = NULL; 31 | uint32_t fw_addr = (uint32_t)image_addr & 0xf0000000; 32 | uint32_t ram_addr = fw_addr + 0x04000000; 33 | uint32_t ram_size = MEM4(ram_addr); 34 | 35 | memset(image_addr + image_size, 0, bss_size); 36 | 37 | #if !CHIP 38 | { 39 | uint32_t tmp = MEM4(0x205003fc) - 0x65300000; 40 | int chip = 1; 41 | if (!(tmp >> 17)) 42 | chip = (int32_t)(tmp << 15) < 0 ? 2 : 3; 43 | _chip = chip; 44 | } 45 | #if LIBC_SDIO < 3 46 | usb_init_base(); 47 | #endif 48 | #endif 49 | 50 | #if LIBC_SDIO < 3 51 | // usb_init(); 52 | _debug_msg("entry2"); 53 | #endif 54 | { 55 | char *addr = image_addr + image_size + bss_size; 56 | size_t size = ram_addr + ram_size - (uint32_t)addr; 57 | char *p; 58 | #if INIT_MMU 59 | size -= 0x4000; // MMU table 60 | #endif 61 | p = addr + size; 62 | #if LIBC_SDIO 63 | p -= sizeof(fatdata_t); 64 | memcpy(&fatdata_glob, p, sizeof(fatdata_t)); 65 | sdio_shl = MEM4(CHIPRAM_ADDR); 66 | #endif 67 | // load sys_data 68 | p -= sizeof(sys_data); 69 | memcpy(&sys_data, p, sizeof(sys_data)); 70 | #ifdef APP_MEM_RESERVE 71 | size = app_mem_reserve(addr, size); 72 | #endif 73 | _malloc_init(addr, size); 74 | } 75 | _stdio_init(); 76 | #if CHIPRAM_ARGS || LIBC_SDIO >= 3 77 | (void)arg_skip; 78 | { 79 | char *p = (char*)CHIPRAM_ADDR + 4; 80 | argc = _argv_copy(&argv, *(short*)p, p + sizeof(short)); 81 | } 82 | #else 83 | argc = _argv_init(&argv, arg_skip); 84 | #endif 85 | sys_set_handlers(); 86 | #ifdef CXX_SUPPORT 87 | cxx_init(argc, argv); 88 | #endif 89 | exit(main(argc, argv)); 90 | } 91 | 92 | -------------------------------------------------------------------------------- /sdboot/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "common.h" 6 | #include "syscode.h" 7 | #include "sdio.h" 8 | #include "cmd_def.h" 9 | #include "usbio.h" 10 | 11 | #if LIBC_SDIO >= 3 12 | #define printf(...) (void)0 13 | #else 14 | int _argv_init(char ***argvp, int skip); 15 | static void libc_resetio(void) { 16 | uint16_t buf[2]; 17 | unsigned tmp = CMD_RESETIO | 1 << 8; 18 | buf[0] = tmp; tmp += CHECKSUM_INIT; 19 | buf[1] = tmp + (tmp >> 16); 20 | usb_write(&buf, sizeof(buf)); 21 | } 22 | #define FAT_READ_SYS \ 23 | if (sdio_read_block(sector, buf)) break; 24 | #endif 25 | #include "microfat.h" 26 | 27 | int sdmain(uint8_t *ram) { 28 | int argc; char **argv; 29 | fatdata_t fatdata; 30 | fat_entry_t *p; 31 | const char *bin_name = FPBIN_DIR "fpmain.bin"; 32 | #if LIBC_SDIO < 3 33 | argc = _argv_init(&argv, 0); 34 | if (argc > 1 && !strcmp(argv[0], "--bin")) { 35 | bin_name = argv[1]; 36 | argc -= 2; argv += 2; 37 | } 38 | #endif 39 | sdio_init(); 40 | if (sdcard_init()) return 1; 41 | SDIO_VERBOSITY(0); 42 | { 43 | uint8_t *mem = (uint8_t*)CHIPRAM_ADDR + 0x9000; 44 | fatdata.buf = mem; 45 | } 46 | if (fat_init(&fatdata, 0)) { 47 | printf("fat_init failed\n"); 48 | return 1; 49 | } 50 | p = fat_find_path(&fatdata, bin_name); 51 | if (!p || (p->entry.attr & FAT_ATTR_DIR)) { 52 | printf("file not found\n"); 53 | return 1; 54 | } 55 | { 56 | unsigned clust = fat_entry_clust(p); 57 | uint32_t size = p->entry.size, n; 58 | printf("start = 0x%x, size = 0x%x\n", clust, size); 59 | if (size > (2 << 20) - 0x10000) { 60 | printf("binary is too big\n"); 61 | return 1; 62 | } 63 | n = fat_read_simple(&fatdata, clust, ram, size); 64 | printf("read = 0x%x\n", n); 65 | if (n < size) { 66 | printf("fat_read failed\n"); 67 | return 1; 68 | } 69 | } 70 | { 71 | char *p = (char*)CHIPRAM_ADDR; 72 | #if LIBC_SDIO < 3 73 | MEM4(CHIPRAM_ADDR) = sdio_shl; 74 | #endif 75 | p += 4; 76 | #if LIBC_SDIO < 3 77 | libc_resetio(); 78 | if (argc) { 79 | size_t size = argv[argc - 1] - argv[0]; 80 | size += strlen(argv[argc - 1]) + 1; 81 | if (size >> 12) { 82 | printf("args is too big (%u)\n", size); 83 | return 1; 84 | } 85 | memcpy(p + sizeof(short), argv[0], size); 86 | } 87 | #else 88 | argc = 0; 89 | #endif 90 | *(short*)p = argc; 91 | clean_dcache(); 92 | ((void(*)(void))ram)(); 93 | } 94 | return 0; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /fpbuild/unistd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #ifndef O_BINARY 8 | #define O_BINARY 0 9 | #endif 10 | 11 | // in case of accidental compilation for PCTEST mode 12 | #if __LP64__ 13 | #error 14 | #endif 15 | 16 | #if UMS9117 17 | // RAM addresses are negative 18 | static inline FILE* fd2file(int fd) { return (FILE*)(fd << 2); } 19 | static inline int file2fd(FILE *f) { return (uint32_t)f >> 2; } 20 | #else 21 | static inline FILE* fd2file(int fd) { return (FILE*)fd; } 22 | static inline int file2fd(FILE *f) { return (uint32_t)f; } 23 | #endif 24 | 25 | int fstat(int fd, struct stat *buf) { 26 | FILE *f = fd2file(fd); 27 | long len, pos; 28 | pos = ftell(f); 29 | if (pos == -1) return -1; 30 | fseek(f, 0, SEEK_END); 31 | len = ftell(f); 32 | fseek(f, pos, SEEK_SET); 33 | 34 | buf->st_size = len; 35 | buf->st_mtime = 0; 36 | return 0; 37 | } 38 | 39 | int stat(const char *fn, struct stat *buf) { 40 | FILE *f; int ret; 41 | f = fopen(fn, "rw"); 42 | if (!f) return -1; 43 | ret = fstat(file2fd(f), buf); 44 | fclose(f); 45 | return ret; 46 | } 47 | 48 | int open(const char *name, int flags, ...) { 49 | const char *smode; 50 | int i = 1, a; 51 | char fmode[4]; 52 | switch (flags & (O_ACCMODE | O_CREAT | O_TRUNC)) { 53 | case O_RDONLY: a = 'r'; break; 54 | case O_RDWR: a = 'r'; break; 55 | case O_WRONLY | O_CREAT | O_TRUNC: a = 'w'; break; 56 | case O_RDWR | O_CREAT | O_TRUNC: a = 'w'; break; 57 | default: return -1; 58 | } 59 | 60 | fmode[0] = a; 61 | if ((flags & O_ACCMODE) == O_RDWR) fmode[i++] = '+'; 62 | if (!O_BINARY || (flags & O_BINARY)) fmode[i++] = 'b'; 63 | fmode[i] = 0; 64 | 65 | return file2fd(fopen(name, fmode)); 66 | } 67 | 68 | int close(int fd) { 69 | return fclose(fd2file(fd)); 70 | } 71 | 72 | int access(const char *name, int mode) { 73 | FILE *f; const char *fmode; 74 | switch (mode) { 75 | case F_OK: 76 | case R_OK: 77 | fmode = "rb"; break; 78 | default: return -1; 79 | } 80 | f = fopen(name, fmode); 81 | if (!f) return -1; 82 | fclose(f); 83 | return 0; 84 | } 85 | 86 | ssize_t read(int fd, void *buf, size_t count) { 87 | return fread(buf, 1, count, fd2file(fd)); 88 | } 89 | 90 | ssize_t write(int fd, const void *buf, size_t count) { 91 | return fwrite(buf, 1, count, fd2file(fd)); 92 | } 93 | 94 | off_t lseek(int fd, off_t off, int origin) { 95 | return fseek(fd2file(fd), off, origin); 96 | } 97 | 98 | // extra 99 | 100 | int sys_errno = 0; 101 | int *__errno(void) { return &sys_errno; } 102 | 103 | char *strerror(int errnum) { return ""; } 104 | 105 | -------------------------------------------------------------------------------- /fpbuild/eduke32/compat.cpp: -------------------------------------------------------------------------------- 1 | #include "compat.h" 2 | #include "palette.h" 3 | #include "baselayer.h" 4 | 5 | uint8_t basepaltable[BASEPALCOUNT][768]; 6 | 7 | void paletteSetColorTable(int32_t id, const uint8_t *table) { 8 | //Bmemcpy(basepaltable[id], table, 768); 9 | uint8_t *dpal = basepaltable[id]; 10 | for (int i = 0; i < 768; i++) 11 | dpal[i] = table[i] >> 2; 12 | } 13 | 14 | const char g_keyAsciiTable[128] = { 15 | 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 0, 16 | 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 0, 0, 'a', 's', 17 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', 39, '`', 0, 92, 'z', 'x', 'c', 'v', 18 | 'b', 'n', 'm', ',', '.', '/', 0, '*', 0, 32, 0, 0, 0, 0, 0, 0, 19 | 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', 20 | '2', '3', '0', '.' 21 | }; 22 | 23 | const char g_keyAsciiTableShift[128] = { 24 | 0, 0, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0, 0, 25 | 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 0, 0, 'A', 'S', 26 | 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|', 'Z', 'X', 'C', 'V', 27 | 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, 32, 0, 0, 0, 0, 0, 0, 28 | 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', 29 | '2', '3', '0', '.' 30 | }; 31 | 32 | int32_t G_CheckCmdSwitch(int32_t argc, char const * const * argv, const char *str) { 33 | int32_t i; 34 | for (i = 0; i < argc; i++) { 35 | if (str && !Bstrcasecmp(argv[i], str)) 36 | return 1; 37 | } 38 | return 0; 39 | } 40 | 41 | void fnlist_clearnames(fnlist_t *fnl) { 42 | klistfree(fnl->finddirs); 43 | klistfree(fnl->findfiles); 44 | 45 | fnl->finddirs = fnl->findfiles = NULL; 46 | fnl->numfiles = fnl->numdirs = 0; 47 | } 48 | 49 | // dirflags, fileflags: 50 | // -1 means "don't get dirs/files", 51 | // otherwise ORed to flags for respective klistpath 52 | int32_t fnlist_getnames(fnlist_t *fnl, const char *dirname, const char *pattern, 53 | int32_t dirflags, int32_t fileflags) { 54 | BUILDVFS_FIND_REC *r; 55 | fnlist_clearnames(fnl); 56 | 57 | if (dirflags != -1) 58 | fnl->finddirs = klistpath(dirname, "*", BUILDVFS_FIND_DIR | dirflags); 59 | if (fileflags != -1) 60 | fnl->findfiles = klistpath(dirname, pattern, BUILDVFS_FIND_FILE | fileflags); 61 | 62 | for (r = fnl->finddirs; r; r = r->next) fnl->numdirs++; 63 | for (r = fnl->findfiles; r; r = r->next) fnl->numfiles++; 64 | return 0; 65 | } 66 | 67 | int win_priorityclass; 68 | int paletteloaded; 69 | int Numsprites = 0; 70 | char *g_defNamePtr = NULL; 71 | int CONTROL_BindsEnabled; 72 | 73 | uint32_t wrandomseed = 1; 74 | 75 | // JFBuild 76 | int nextvoxid = 0; 77 | -------------------------------------------------------------------------------- /fpbuild/README.md: -------------------------------------------------------------------------------- 1 | ## FPBuild: Build Engine for feature phones 2 | 3 | Port of games on the Build Engine. Using [jfbuild](https://github.com/jonof/jfbuild) code by Jonathon Fowler. 4 | 5 | ### Build 6 | 7 | 1. Download specific sources and apply patches: 8 | `$ make -f helper.make all patch` 9 | 10 | 2. Use the same instructions as for `fpdoom`. To select a game to build: use `GAME=duke3d` (Duke Nukem 3D), `GAME=sw` (Shadow Warrior) or `GAME=blood` (Blood). 11 | 12 | * The patch for NBlood is based on [NBlood-Amiga](https://github.com/BSzili/NBlood-Amiga). 13 | 14 | ### Build Engine options 15 | 16 | * `-cachesize N`, set the cache size to N kilobytes. Shadow Warrior and Blood run with freezes on phones with 4MB memory due to frequent loading of textures. The default cache size leaves some memory for allocations, you can try increasing it until you encounter out of memory errors. 17 | 18 | * `-playanm 1`, to enable "video" playback (requires a lot of cache, you need an 8 MB phone). 19 | 20 | ### Game controls 21 | 22 | | Key(s) | Action | 23 | |----------------|--------------------| 24 | | Left Soft Key | use | 25 | | Right Soft Key | open/close menu | 26 | | Direction Pad | movement | 27 | | D-pad Center | fire | 28 | | Dial Key | run on/off | 29 | | 2, 4, 5, 6 | up/left/down/right | 30 | | 1, 3 | strafe left/right | 31 | | 7, 9 | prev/next weapon | 32 | | # | jump | 33 | | * | crouch | 34 | | 0 | next item | 35 | | 8 | use item | 36 | | Power + Center | use | 37 | | Power + Up | run on/off | 38 | | Power + Down | open/close menu | 39 | | Power + L/R | prev/next weapon | 40 | | Power + LSoft | zoom in | 41 | | Power + RSoft | zoom out | 42 | | Power + Dial | map | 43 | | Power + 0 | gamma (0..7) | 44 | 45 | ### Issues 46 | 47 | * Make sure the `.grp` filename is in all lowercase or uppercase, otherwise it will not work with `libc_server` running on Linux. 48 | 49 | * Very low frame rate for a few seconds at the beginning of the level. 50 | 51 | * Saved games depend on specific compile-time constants, which are reduced to fit the game in the small RAM of a feature phone. So saved games are incompatible with other versions of the game. 52 | 53 | * Previews of saved games often glitches, most likely unloaded from memory due to lack of free cache. 54 | 55 | * The fifth episode of "Duke Nukem 3D 20th Anniversary Edition" is not supported, `jfduke3d` does not support it. However, `duke3d.grp` from "20th Anniversary Edition" is supported, but works like "Atomic Edition" with four episodes. Just don't copy ".con" scripts to the working directory. 56 | 57 | -------------------------------------------------------------------------------- /fpmenu/config.txt: -------------------------------------------------------------------------------- 1 | # This is a config file for running binaries from the FPDoom project from an SD card. 2 | 3 | # Comments begin with a hash sign. 4 | # The first non-empty line specifies the arguments to run the flat binary named "fpbin/fpmain.bin": 5 | 6 | --bright 50 --charge 2 7 | 8 | # If the "fpmenu" is located in this path, it will read the config file further. 9 | 10 | # Variables must begin with a dollar sign. 11 | # You can wrap long lines using blackslash. 12 | # First arguments are stored in the $@ variable. 13 | # You can define and redefine variables: 14 | 15 | $@ = $@ --rotate 3 16 | 17 | # Menu colors (0xRRGGBB): bg text sel_bg sel_text 18 | # $_colors = 0x00003f 0x0000ff 0x3f0000 0xff0000 19 | 20 | $nes_args = --dir games/nes infones 21 | # "--scaler 49" means auto resolution + widescreen scaler 22 | $nes = fpbin/infones.bin $@ --scaler 49 $nes_args 23 | # Workaround for some games to display correctly. 24 | $nes2 = $nes --scanline_step 113 25 | # This crops the top and bottom tiles, there is garbage in some games. 26 | $nes_crop = fpbin/infones.bin $@ --scaler 149 $nes_args 27 | 28 | $gnuboy_args = --dir games/gameboy gnuboy 29 | $gnuboy = fpbin/gnuboy.bin $@ $gnuboy_args 30 | 31 | $snes_args = --dir games/snes snes9x --crc 0 --nocheck 32 | $snes_pal = fpbin/snes9x.bin $@ --scaler 49 $snes_args 33 | $snes = fpbin/snes9x.bin $@ --scaler 149 $snes_args 34 | $snes16_pal = fpbin/snes9x_16bit.bin $@ --scaler 49 $snes_args 35 | $snes16 = fpbin/snes9x_16bit.bin $@ --scaler 149 $snes_args 36 | 37 | $doom = fpbin/fpdoom.bin $@ 38 | 39 | # Menu items are defined using this pattern: 40 | # |Name| path/to/app.bin arg1 arg2 arg3 41 | 42 | |=== Ports ===| 43 | |Doom 1| $doom --dir games/doom1 doom # -timedemo demo1 44 | |Duke 3D| fpbin/fpduke3d.bin $@ --dir games/duke3d duke3d # -cachesize 1648 45 | |Shadow Warrior| fpbin/fpsw.bin $@ --dir games/sw sw # -cachesize 1552 46 | |Blood| fpbin/fpblood.bin $@ --dir games/blood blood # -cachesize 1648 47 | |Wolfenstein 3D| fpbin/wolf3d.bin $@ --dir games/wolf3d wolf3d 48 | # Use the "-mb x.xx" option to change the cache size for Chocolate Doom. 49 | #|Chocolate Doom| fpbin/chocolate-doom.bin $@ --dir games/doom1 doom -iwad doom1.wad 50 | |Heretic| fpbin/chocolate-heretic.bin $@ --dir games/heretic heretic -iwad HERETIC1.WAD 51 | |Hexen| fpbin/chocolate-hexen.bin $@ --dir games/hexen hexen -iwad HEXEN.WAD 52 | 53 | #1234567890123456# 128px = 16 chars 54 | #12345678901234567890# 160px = 20 chars 55 | #123456789012345678901234567890# 240px = 30 chars 56 | 57 | |=== SNES ===| 58 | |SNES Example 1| $snes "Example 1.smc" 59 | |SNES Example 2| $snes16 "Example 2.smc" 60 | 61 | |=== GameBoy ===| 62 | |GB Example 1| $gnuboy "Example 1.gbc" 63 | 64 | |=== NES ===| 65 | |NES Example 1| $nes "Example 1.nes" 66 | |NES Example 2| $nes2 "Example 2.nes" 67 | |NES Example 3| $nes_crop "Example 3.nes" 68 | 69 | -------------------------------------------------------------------------------- /wolf3d/extra.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define ANGLES 360 7 | #define FINEANGLES 3600 8 | // the original code doesn't round 9 | #define ROUNDANGLE 1 10 | 11 | int CalcRotateMult; 12 | 13 | #if NO_FLOAT 14 | extern const uint8_t atan2_tab[0x801]; 15 | 16 | static unsigned frac_divide(unsigned y, unsigned x, int n) { 17 | unsigned a = 0; 18 | do { 19 | a <<= 1; 20 | if (y >= x) y -= x, a++; 21 | y <<= 1; 22 | } while (--n >= 0); 23 | // round to nearest even 24 | if (y + (a & 1) > x) a++; 25 | return a; 26 | } 27 | 28 | static int atan2i(int y, int x) { 29 | unsigned t, f = 0x10123432 | 0x80080880; 30 | if (y < 0) y = -y, f >>= 16; 31 | if (x < 0) x = -x, f >>= 8; 32 | if (x < y) t = x, x = y, y = t, f >>= 4; 33 | x = frac_divide(y, x, 11); 34 | x += atan2_tab[x]; 35 | if (f & 8) x = -x; 36 | return ((f & 7) << 12) + x; 37 | } 38 | 39 | // 7.5% chance of deviation by 1 40 | 41 | int CalcAngle(int32_t y, int32_t x) { 42 | int angle = atan2i(y, x) - 0x2000; 43 | if (angle < 0) angle += 0x4000; 44 | angle *= ANGLES; 45 | if (ROUNDANGLE) angle += 0x2000; 46 | return angle >> 14; 47 | } 48 | 49 | int ProjectionAngle(int32_t y, int32_t x) { 50 | int angle = atan2i(y, x) - 0x2000; 51 | angle *= FINEANGLES; 52 | if (ROUNDANGLE) angle += 0x2000; 53 | else if (angle < 0) angle += 0x3fff; 54 | return angle >> 14; 55 | } 56 | #else 57 | #include 58 | 59 | int CalcAngle(int32_t y, int32_t x) { 60 | float angle = atan2f(y, x); 61 | if (angle < 0) angle += (float)(M_PI * 2); 62 | angle *= (float)(ANGLES / (M_PI * 2)); 63 | if (ROUNDANGLE) angle += 0.5f; 64 | return angle; 65 | } 66 | 67 | int ProjectionAngle(int32_t y, int32_t x) { 68 | float angle = atan2f(y, x); 69 | angle *= (float)(FINEANGLES / (M_PI * 2)); 70 | if (ROUNDANGLE) angle += angle >= 0 ? 0.5f : -0.5f; 71 | return angle; 72 | } 73 | #endif 74 | 75 | #if LINUX_FN_FIX 76 | FILE *fopen_fix(const char *path, const char *mode) { 77 | FILE *f = fopen(path, mode); 78 | // printf("!!! fopen(\"%s\", \"%s\")\n", path, mode); 79 | if (!f && *mode == 'r') { 80 | char buf[64]; unsigned i = 0, a; 81 | do { 82 | if (i >= sizeof(buf)) return f; 83 | a = path[i]; buf[i++] = toupper(a); 84 | } while (a); 85 | f = fopen(buf, mode); 86 | } 87 | return f; 88 | } 89 | #endif 90 | 91 | void Error(const char *str) { 92 | printf("error: %s\n", str); 93 | } 94 | 95 | void Help(const char *str) { 96 | printf("info: %s\n", str); 97 | } 98 | 99 | #if TRACE_UPDATE 100 | void print_trace(const char *file, int line) { 101 | static const char *file1; 102 | static int line1; 103 | if (line != line1 || !file1 || strcmp(file, file1)) { 104 | file1 = file; line1 = line; 105 | printf("%s:%u\n", file, line); 106 | } 107 | } 108 | #endif 109 | 110 | -------------------------------------------------------------------------------- /sdboot/README.md: -------------------------------------------------------------------------------- 1 | ## SD card boot (SC6530/SC6531) 2 | 3 | * SD boot for UMS9117 in the [sdboot_t117](../sdboot_t117) directory. 4 | 5 | This is a small section that is added to the free space in the firmware. The code is executed when the phone is powered/rebooted, if one of the keys at positions (0,1), (1,0) or (1,1) is hold down. If a FAT32 formatted SD card is inserted, then the binary `fpbin/fpmain.bin` is executed. The command-line arguments for the application is read from the file `fpbin/config.txt`. This application can be either one of the games or a menu for selecting games (`fpmenu`). 6 | 7 | * The key for booting from USB is (0,0). The key positions are the intersections of traces on the PCB, not the physical buttons you see. 8 | 9 | ### How to install 10 | 11 | First you need to dump the phone firmware using the [spreadtrum_flash](https://github.com/ilyakurdyukov/spreadtrum_flash) tool. The most common flash memory size is 4MB, but expensive models can have 8 and 16MB. So far, the flash size cannot be determined automatically, so specify 16MB, if the size is less, the dump will simply be repeated in the file several times. 12 | 13 | `./spd_dump fdl nor_fdl1.bin 0x40004000 read_flash 0x80000003 0 16M flash.bin` 14 | 15 | Then use the `fphelper` utility from the `spreadtrum_flash` set: 16 | 17 | `./fphelper flash.bin scan` 18 | 19 | This will scan the firmware and among various information will tell you what the phone's boot key is, as well as the keys for booting from the SD card. For example: 20 | 21 | ``` 22 | 0x71b0c: keymap, bootkey = 0x08 (LSOFT), sdboot keys = 0x2a 0x01 0x30 (STAR, DIAL, 0) 23 | ``` 24 | 25 | Then run: 26 | 27 | `./fphelper flash.bin sdboot` 28 | 29 | This will print instructions on how to flash `sdboot` to your phone. 30 | 31 | ### Build 32 | 33 | Prebuilt binaries can be found in [Releases](https://github.com/ilyakurdyukov/spreadtrum_flash/releases). 34 | 35 | Use the same instructions as for `fpdoom`. Add the `CHIP=N` option to make, where N is the chip type (1 = SC6531E, 2 = SC6531DA, 3 = SC6530), as a result you will get a binary `sdbootN.bin`, which you can use in the instructions that `fphelper` writes. 36 | 37 | To run from SD card all applications must be compiled with the `LIBC_SDIO=3` option (by default USB mode is set, it is `LIBC_SDIO=0`). 38 | 39 | * The chip independent version (`CHIP=0`) doesn't fit in 4KB, do not try to use it, it's unfinished. 40 | 41 | ### Issues 42 | 43 | * To ensure fast reading of resources from the SD card, FAT32 cluster chains are cached, which takes 4 bytes per cluster. For example, if a file takes 40MB and the cluster size is 4KB, then 40KB of memory will be needed to store the cluster chain. For games on the Build engine, this can be significant on a phone with 4MB of RAM. If the clusters are arranged sequentially, then no memory is spent on storing the cluster chain. Defragment the file system to straighten the cluster chains. 44 | 45 | -------------------------------------------------------------------------------- /snes9x/README.md: -------------------------------------------------------------------------------- 1 | ## Snes9x port 2 | 3 | Port of Snes9x v1.43. This older version is more lightweight and has 8-bit rendering mode. The DSP1 emulation [code](https://github.com/snes9xgit/snes9x/blob/96059dd45aed03859bff5a3e30f1d1b13136a8f9/dsp1.cpp) is taken from the upstream Snes9x, where it has been rewritten to integer calculations. 4 | 5 | ### Build 6 | 7 | 1. Download specific sources and apply patches: 8 | `$ make -f helper.make all patch` 9 | 10 | 2. Use the same instructions as for `fpdoom`. The `USE_16BIT={0|1}` option selects 8 or 16-bit rendering mode. 8-bit mode is faster, but doesn't handle various graphical effects (that many games don't use). 16-bit mode is slower but provides accurate rendering. 11 | 12 | ### Usage 13 | 14 | `[system options] snes9x [emulator options] romfile.smc` 15 | 16 | #### Emulator options 17 | 18 | `--crc 0x12345678` replace ROM CRC32 with the value specified, only used for logging and fixing some games. Calculating CRC32 takes significant time for large ROMs. 19 | `--nocheck` don't check ROM checksum, which takes significant time for large ROMs. 20 | 21 | ### Game controls 22 | 23 | | Key(s) | Action | 24 | |----------------|--------------------| 25 | | Left Soft Key | select | 26 | | Right Soft Key | start | 27 | | Direction Pad | movement | 28 | | D-pad Center | B | 29 | | Dial Key | A | 30 | | 2, 4, 5, 6 | up/left/down/right | 31 | | 1, 3 | TL, TR | 32 | | *, 0, # | A, B, A | 33 | | 7, 8, 9 | X, Y, X | 34 | | Power + LSoft | start | 35 | | Power + Dial | exit | 36 | | Power + Up | reset | 37 | | Power + Down | exit | 38 | | Power + Left | select | 39 | | Power + Right | start | 40 | | Power + Center | B | 41 | | Power + 0 | force save SRAM | 42 | 43 | * The reset/exit keys must be held for 1 second to activate. This is to prevent accidental pressing. 44 | 45 | ### Issues 46 | 47 | * SC6531 with 312MHz can emulate regular games at 1x speed. SC6530/SC6531E with 208MHz will skip frames. 48 | 49 | * SA1 - disabled. 50 | 51 | * DSP1 games run at half speed. SuperFX works, but very slow. 52 | 53 | * C4/DSP4 - disabled, because emulation uses floating point operations that are not supported by the phone's CPU. This can be solved by rewriting to integer calculations or using floating point emulation. 54 | 55 | * Some game cartridges have SRAM for saves, this memory is saved on exit or if you force save SRAM. If the device is turned off, the SRAM changes will be lost. 56 | 57 | * The FAT32 file system driver can't create files with long names, if you want to save SRAM the ROM file name must be in DOS 8.3 format or you need to create an empty file with the ROM name and the `.srm` extension in advance. 58 | 59 | -------------------------------------------------------------------------------- /sdboot_t117/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "common.h" 6 | #include "syscode.h" 7 | #include "sdio.h" 8 | #include "cmd_def.h" 9 | #include "usbio.h" 10 | 11 | #if LIBC_SDIO >= 3 12 | #define printf(...) (void)0 13 | #else 14 | int _argv_init(char ***argvp, int skip); 15 | static void libc_resetio(void) { 16 | uint16_t buf[2]; 17 | unsigned tmp = CMD_RESETIO | 1 << 8; 18 | buf[0] = tmp; tmp += CHECKSUM_INIT; 19 | buf[1] = tmp + (tmp >> 16); 20 | usb_write(&buf, sizeof(buf)); 21 | } 22 | #define FAT_READ_SYS \ 23 | if (sdio_read_block(sector, buf)) break; 24 | #endif 25 | #include "microfat.h" 26 | 27 | int sdmain(void) { 28 | uint8_t *ram = (uint8_t*)0x80000000; 29 | uint8_t *bin_addr = ram + (1 << 20); 30 | int argc; char **argv; 31 | fatdata_t fatdata; 32 | fat_entry_t *p; 33 | const char *bin_name = FPBIN_DIR "fpmain.bin"; 34 | #if LIBC_SDIO < 3 35 | argc = _argv_init(&argv, 0); 36 | if (argc > 1 && !strcmp(argv[0], "--bin")) { 37 | bin_name = argv[1]; 38 | argc -= 2; argv += 2; 39 | } 40 | #endif 41 | sdio_init(); 42 | if (sdcard_init()) return 1; 43 | SDIO_VERBOSITY(0); 44 | { 45 | uint8_t *mem = (uint8_t*)(ram + 0x8000); 46 | fatdata.buf = mem; 47 | } 48 | if (fat_init(&fatdata, 0)) { 49 | printf("fat_init failed\n"); 50 | return 1; 51 | } 52 | p = fat_find_path(&fatdata, bin_name); 53 | if (!p || (p->entry.attr & FAT_ATTR_DIR)) { 54 | printf("file not found\n"); 55 | return 1; 56 | } 57 | { 58 | unsigned clust = fat_entry_clust(p); 59 | uint32_t size = p->entry.size, n; 60 | printf("start = 0x%x, size = 0x%x\n", clust, size); 61 | if (size > (15 << 20) - 0x10000) { 62 | printf("binary is too big\n"); 63 | return 1; 64 | } 65 | n = fat_read_simple(&fatdata, clust, bin_addr, size); 66 | printf("read = 0x%x\n", n); 67 | if (n < size) { 68 | printf("fat_read failed\n"); 69 | return 1; 70 | } 71 | if (MEM4(bin_addr) != 0x42544844) { 72 | printf("no DHTB header\n"); 73 | return 1; 74 | } 75 | } 76 | { 77 | char *p = (char*)CHIPRAM_ADDR; 78 | #if LIBC_SDIO < 3 79 | MEM4(CHIPRAM_ADDR) = sdio_shl; 80 | #endif 81 | p += 4; 82 | #if LIBC_SDIO < 3 83 | libc_resetio(); 84 | if (argc) { 85 | size_t size = argv[argc - 1] - argv[0]; 86 | size += strlen(argv[argc - 1]) + 1; 87 | if (size >> 12) { 88 | printf("args is too big (%u)\n", size); 89 | return 1; 90 | } 91 | memcpy(p + sizeof(short), argv[0], size); 92 | } 93 | #else 94 | (void)argv; 95 | argc = 0; 96 | #endif 97 | *(short*)p = argc; 98 | #if 0 99 | // reset ACTLR to default 100 | __asm__ __volatile__( 101 | "mcr p15, #0, %0, c1, c0, #1" 102 | :: "r"(0x6000)); 103 | #endif 104 | clean_dcache(); 105 | ((void(*)(void))(bin_addr + 0x200))(); 106 | } 107 | return 0; 108 | } 109 | 110 | -------------------------------------------------------------------------------- /sdboot_t117/entry.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "cmd_def.h" 3 | #include "usbio.h" 4 | #include "syscode.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "init_t117.h" 11 | 12 | void _debug_msg(const char *msg); 13 | void _malloc_init(void *addr, size_t size); 14 | void _stdio_init(void); 15 | 16 | int sdmain(void); 17 | 18 | /* dcache must be disabled for this function */ 19 | static uint32_t get_ram_size(uint32_t addr) { 20 | uint32_t v1 = 0x12345678, i = 3; 21 | do MEM4(addr + (i << 24)) = i + v1; while (--i); 22 | do i++; while (i < 4 && MEM4(addr + (i << 24)) == i + v1); 23 | return i << 24; // 16M, 32M, 48M, 64M 24 | } 25 | 26 | extern char __bss_start[]; 27 | extern char __bss_end[]; 28 | extern uint32_t _start[]; 29 | 30 | void init_chip(void); 31 | int sdram_init(void); 32 | 33 | void entry_main(void) { 34 | uint32_t ram_addr = 0x80000000, ram_size; 35 | 36 | init_t117(); 37 | 38 | #if LIBC_SDIO < 3 39 | // clear USB interrupts from BROM 40 | { 41 | uint32_t b = 0x20201be0 + (15 + 6) * 32; 42 | MEM4(b + 8) |= 0x14000000; 43 | } 44 | memset(__bss_start, 0, __bss_end - __bss_start); 45 | { 46 | static const uint8_t fdl_ack[8] = { 47 | 0x7e, 0, 0x80, 0, 0, 0xff, 0x7f, 0x7e }; 48 | static const struct { 49 | uint8_t hdr[5], str[0x22], end[5]; 50 | } fdl_ver = { 51 | { 0x7e, 0,0x81, 0,0x22 }, 52 | { "Spreadtrum Boot Block version 1.2" }, 53 | { 0xa9,0xe9, 0x7e } 54 | }; 55 | uint8_t buf[8]; 56 | usb_init(); 57 | usb_write(&fdl_ver, sizeof(fdl_ver)); 58 | usb_read(buf, 8, USB_WAIT); 59 | usb_write(fdl_ack, sizeof(fdl_ack)); 60 | } 61 | { 62 | char buf[4]; uint32_t t0, t1; 63 | for (;;) { 64 | usb_read(buf, 1, USB_WAIT); 65 | if (buf[0] == HOST_CONNECT) break; 66 | } 67 | t0 = sys_timer_ms(); 68 | do { 69 | t1 = sys_timer_ms(); 70 | if (usb_read(buf, 4, 0)) t0 = t1; 71 | } while (t1 - t0 < 10); 72 | } 73 | _debug_msg("sdboot"); 74 | #endif 75 | 76 | if (sdram_init()) { 77 | #if LIBC_SDIO < 3 78 | _debug_msg("sdram_init failed"); 79 | #endif 80 | for (;;); 81 | } 82 | 83 | ram_size = get_ram_size(ram_addr); 84 | #if INIT_MMU 85 | { 86 | volatile uint32_t *tab = (uint32_t*)ram_addr; 87 | uint32_t cb = 3 << 2; // Outer and Inner Write-Back, no Write-Allocate 88 | unsigned i; 89 | for (i = 0; i < 0x200; i++) tab[i] = 0; // no access 90 | for (; i < 0x800 + (ram_size >> 20); i++) 91 | tab[i] = i << 20 | 3 << 10 | 2; // read/write 92 | for (; i < 0x1000; i++) tab[i] = 0; // no access 93 | 94 | i = 0x00000000 >> 20; // IRAM 95 | tab[i] = i << 20 | 3 << 10 | cb | 2; // read/write 96 | 97 | for (i = 0; i < ram_size >> 20; i++) 98 | tab[ram_addr >> 20 | i] |= cb; 99 | #if 0 // !NO_ACTLR 100 | // setup ACTLR 101 | __asm__ __volatile__( 102 | "mcr p15, #0, %0, c1, c0, #1" 103 | :: "r"(0x6040)); 104 | #endif 105 | // domains: 0 - manager, 1..3 - client, 4..15 - no access 106 | enable_mmu((uint32_t*)((uint32_t)tab | 0x49), 0x57); 107 | } 108 | #endif 109 | #if LIBC_SDIO < 3 110 | { 111 | char *addr = (void*)(ram_addr + 0x10000); 112 | uint32_t size = 0x20000; // 128KB 113 | _malloc_init(addr, size); 114 | _stdio_init(); 115 | printf("malloc heap: %u bytes\n", size); 116 | } 117 | #endif 118 | sdmain(); 119 | sys_wdg_reset(SYS_RESET_DELAY); 120 | } 121 | 122 | -------------------------------------------------------------------------------- /fpbuild/jfmact.patch: -------------------------------------------------------------------------------- 1 | diff --git a/animlib.c b/animlib.c 2 | index b8df23e..81d5c67 100644 3 | --- a/animlib.c 4 | +++ b/animlib.c 5 | @@ -158,7 +158,11 @@ run: 6 | 7 | goto nextOp; 8 | longOp: 9 | +#ifdef EMBEDDED 10 | + wordCnt = read16u_le(srcP); 11 | +#else 12 | wordCnt = B_LITTLE16(*((uint16 *)srcP)); 13 | +#endif 14 | srcP += sizeof(uint16); 15 | if ((int16)wordCnt <= 0) 16 | goto notLongSkip; /* Do SIGNED test. */ 17 | @@ -222,7 +226,11 @@ void renderframe (uint16 framenumber, uint16 *pagepointer) 18 | ppointer+=anim->curlp.nRecords*2+offset; 19 | if(ppointer[1]) 20 | { 21 | +#ifdef EMBEDDED 22 | + ppointer += (read16u_le(ppointer + 2) + 4 + 1) & ~1; 23 | +#else 24 | ppointer += (4 + B_LITTLE16(((uint16 *)ppointer)[1]) + (B_LITTLE16(((uint16 *)ppointer)[1]) & 1)); 25 | +#endif 26 | } 27 | else 28 | { 29 | diff --git a/control.c b/control.c 30 | index abd3b88..53c9671 100644 31 | --- a/control.c 32 | +++ b/control.c 33 | @@ -482,6 +482,10 @@ void CONTROL_ClearAssignments( void ) 34 | { 35 | int32 i; 36 | 37 | +#if NO_MOUSE 38 | + memset(CONTROL_KeyMapping, KEYUNDEFINED, sizeof(CONTROL_KeyMapping)); 39 | + return; 40 | +#endif 41 | memset(CONTROL_MouseButtonMapping, BUTTONUNDEFINED, sizeof(CONTROL_MouseButtonMapping)); 42 | memset(CONTROL_JoyButtonMapping, BUTTONUNDEFINED, sizeof(CONTROL_JoyButtonMapping)); 43 | memset(CONTROL_KeyMapping, KEYUNDEFINED, sizeof(CONTROL_KeyMapping)); 44 | @@ -685,6 +689,10 @@ void CONTROL_PollDevices(ControlInfo *info) 45 | { 46 | int32 i; 47 | 48 | +#if NO_MOUSE 49 | + memset(info, 0, sizeof(ControlInfo)); 50 | + return; 51 | +#endif 52 | memcpy(CONTROL_LastMouseAxes, CONTROL_MouseAxes, sizeof(CONTROL_MouseAxes)); 53 | memcpy(CONTROL_LastJoyAxes, CONTROL_JoyAxes, sizeof(CONTROL_JoyAxes)); 54 | 55 | @@ -783,6 +791,7 @@ void CONTROL_GetUserInput( UserInput *info ) 56 | CONTROL_UserInputDelay = -1; 57 | 58 | if (GetTime() >= CONTROL_UserInputDelay) { 59 | +#if !NO_MOUSE 60 | if (CONTROL_MouseAxes[1].digital == -1) 61 | info->dir = dir_North; 62 | else if (CONTROL_MouseAxes[1].digital == 1) 63 | @@ -809,6 +818,7 @@ void CONTROL_GetUserInput( UserInput *info ) 64 | info->dir = dir_West; 65 | else if (CONTROL_JoyButtonState[joybutton_DpadRight]) 66 | info->dir = dir_East; 67 | +#endif 68 | 69 | if (KB_KeyDown[sc_kpad_8] || KB_KeyDown[sc_UpArrow]) 70 | info->dir = dir_North; 71 | @@ -872,8 +882,10 @@ void CONTROL_GetInput( ControlInfo *info ) 72 | CONTROL_PollDevices( info ); 73 | 74 | memset(periphs, 0, sizeof(periphs)); 75 | +#if !NO_MOUSE 76 | CONTROL_ButtonFunctionState(periphs); 77 | CONTROL_AxisFunctionState(periphs); 78 | +#endif 79 | 80 | CONTROL_ButtonHeldState1 = CONTROL_ButtonState1; 81 | CONTROL_ButtonHeldState2 = CONTROL_ButtonState2; 82 | @@ -914,6 +926,9 @@ boolean CONTROL_Startup(controltype which, int32 ( *TimeFunction )( void ), int3 83 | 84 | if (initinput()) return true; 85 | 86 | +#if NO_MOUSE 87 | + KB_Startup(); 88 | +#else 89 | CONTROL_MousePresent = CONTROL_MouseEnabled = false; 90 | CONTROL_JoyPresent = CONTROL_JoystickEnabled = false; 91 | CONTROL_NumMouseButtons = CONTROL_NumJoyButtons = 0; 92 | @@ -934,6 +949,7 @@ boolean CONTROL_Startup(controltype which, int32 ( *TimeFunction )( void ), int3 93 | buildprintf("CONTROL_Startup: Mouse Present\n"); 94 | if (CONTROL_JoyPresent) 95 | buildprintf("CONTROL_Startup: Joystick Present\n"); 96 | +#endif 97 | 98 | CONTROL_ButtonState1 = 0; 99 | CONTROL_ButtonState2 = 0; 100 | -------------------------------------------------------------------------------- /sdboot_t117/start.s: -------------------------------------------------------------------------------- 1 | @ -*- tab-width: 8 -*- 2 | .arch armv7-a 3 | .syntax unified 4 | 5 | .macro CODE16_FN name 6 | .section .text.\name, "ax", %progbits 7 | .p2align 1 8 | .code 16 9 | .type \name, %function 10 | .global \name 11 | .thumb_func 12 | \name: 13 | .endm 14 | 15 | .macro CODE32_FN name 16 | .section .text.\name, "ax", %progbits 17 | .p2align 2 18 | .code 32 19 | .type \name, %function 20 | .global \name 21 | \name: 22 | .endm 23 | 24 | // 0 : MMU enable 25 | // 2 : Level 1 Data Cache enable 26 | // 12 : Instruction Cache enable 27 | 28 | CODE32_FN _start 29 | .ascii "DHTB" 30 | .long 1 31 | .org _start + 0x30, 0 32 | .if 0 33 | .long __image_size - 0x200 34 | .endif 35 | .if 0 36 | .org _start + 0x1b8, 0 37 | .word 0 // signature 38 | .hword 0 39 | .word 0, 0xc, 0x20, 0x77ffe0 40 | .endif 41 | .org _start + 0x1fe, 0 42 | .hword 0xaa55 43 | 44 | adr r2, _start 45 | .if 1 // dummy signature 46 | b 9f 47 | 48 | .org _start + 0x210, 0 49 | .quad 0, 0x200, 0x234, 0x200 + 0x60 50 | .org _start + 0x260, 0 51 | .long 0, 2048, 0x01000100 52 | .long 0x735c69c2, 0xe075fd58, 0xcad0df27, 0x15f2aa4f 53 | .long 0xa21e64a8, 0x696900ac, 0xefa7090f, 0x797c9e7a 54 | .long 0x6f1cfc9a, 0x3fd1b908, 0x8f127e6e, 0x77ab476e 55 | .long 0xe5ab2d53, 0xd955b1b0, 0xbf2d8a07, 0x3506a962 56 | .long 0x90c4c2af, 0x8c637394, 0x7a56b0d6, 0xaa4784c1 57 | .long 0x97ac9952, 0x8853f713, 0xafa87044, 0x30440f86 58 | .long 0x99d25255, 0xaac57615, 0x14212968, 0xd10128e2 59 | .long 0x6a131ec0, 0x35618548, 0x041b724e, 0xa908937e 60 | .long 0x68b37f74, 0x6a073032, 0x03294b80, 0x4bd637e0 61 | .long 0x1e83ad33, 0xe2d8fcbb, 0x74c6d699, 0xe07415e3 62 | .long 0x0ffd5b7f, 0xe4bec84c, 0xfb3543bc, 0x43d255d4 63 | .long 0xcc10ff98, 0x26692098, 0xa0250298, 0xd894faf6 64 | .long 0xb80ee7be, 0x2198a857, 0xf3947de5, 0x64e20edb 65 | .long 0x3bc0c823, 0x2de2551f, 0x2739e226, 0xd52a086e 66 | .long 0x389bdcdf, 0x78943c85, 0x1c508c34, 0xf6782b1b 67 | .long 0x8006aa1e, 0xc2323454, 0xa5e24f65, 0xc7cebe0b 68 | .long 0x42c4b0e3, 0x141cfc98, 0xc8f4fb9a, 0x24b96f99 69 | .long 0xe441ae27, 0x4c939b64, 0x1b9995a4, 0x55b85278 70 | .long 1, ~0 71 | .long 0x22c37350, 0x14d52f1c, 0xe0140261, 0x503d84b9 72 | .long 0xafa46f54, 0x3fd9244d, 0x7f7369de, 0x0e019321 73 | .long 0x342bb1e7, 0xb03d0b38, 0xc666beb1, 0x781e3d57 74 | .long 0x0d5732ad, 0x43a9da59, 0xe90b4d33, 0xeefe4625 75 | .long 0x1d9dca38, 0xa8006ac2, 0x013fc263, 0x9c0d0af1 76 | .long 0xfc23e326, 0x2615e766, 0xc3570bc5, 0x73bf7a7b 77 | .long 0x044314a4, 0xe41c9542, 0xcf6f7c61, 0xba3d6623 78 | .long 0x1bbfb091, 0x089918ad, 0x9c1d626d, 0x9119ae11 79 | .long 0xe783f995, 0xc4af3490, 0x104e9136, 0x8e6572ef 80 | .long 0x34940cc8, 0x2a722ea1, 0xd7a1229b, 0x914445cf 81 | .long 0xd38c403e, 0xc9d813c0, 0x45f4a221, 0x6ad403e6 82 | .long 0x86c1aabc, 0x790917e4, 0x50ffe8b6, 0x7ee70179 83 | .long 0x7636018d, 0x3468bdb6, 0x51f16704, 0x405997ba 84 | .long 0x2900bc6c, 0xb6475918, 0x45a1cfac, 0x98bb853f 85 | .long 0xaaa0d639, 0x3adf643e, 0x2edecc92, 0xe5c53c00 86 | .long 0x78b06bd7, 0xa02859a8, 0x32c0c6a8, 0x71182b42 87 | 9: 88 | .endif 89 | ldr r0, 3f 90 | 4: cmp r2, r0 91 | bne 4b 92 | 93 | mrc p15, #0, r0, c1, c0, #0 // Read Control Register 94 | bic r0, #5 95 | .if 0 96 | bic r0, #0x1000 97 | .else // faster 98 | orr r0, #0x1000 99 | .endif 100 | mcr p15, #0, r0, c1, c0, #0 // Write Control Register 101 | 102 | mov r0, #0xf00000 103 | mcr p15, #0, r0, c1, c0, #2 104 | mov r0, #0x40000000 105 | vmsr FPEXC, r0 106 | isb sy 107 | mov r2, #0xd3 108 | msr CPSR_c, r2 109 | mov r0, #0x12000 110 | mov sp, r0 111 | 112 | // 24 - FZ (flush to zero) 113 | // 25 - DN (default NaN) 114 | mov r0, #0x3000000 115 | vmsr FPSCR, r0 116 | 117 | ldr pc, 2f 118 | 2: .long entry_main 119 | 3: .long __image_start 120 | 121 | -------------------------------------------------------------------------------- /gnuboy/gbasm.s: -------------------------------------------------------------------------------- 1 | @ -*- tab-width: 8 -*- 2 | .arch armv5te 3 | .syntax unified 4 | 5 | .macro CODE32_FN name 6 | .section .text.\name, "ax", %progbits 7 | .p2align 2 8 | .code 32 9 | .type \name, %function 10 | .global \name 11 | \name: 12 | .endm 13 | 14 | CODE32_FN scr_update_6x5d3_asm 15 | push {r4-r10,lr} 16 | sub r2, r1, #256 * 2 17 | ldr r10, =0x07e0f81f 18 | mov r3, #240 19 | bic lr, r10, r10, lsl #1 20 | 1: sub r3, #160 << 16 21 | 2: ldrb r5, [r0, #160] 22 | ldrb r4, [r0], #1 23 | lsl r5, #1 24 | lsl r4, #1 25 | ldrh r5, [r2, r5] 26 | ldrh r4, [r2, r4] 27 | orr r5, r5, r5, lsl #16 28 | orr r4, r4, r4, lsl #16 29 | str r4, [r1], #4 30 | str r5, [r1, #160 * 2 * 4 - 4] 31 | and r4, r10 32 | and r5, r10 33 | add r4, r5 34 | and r5, lr, r4, lsr #1 35 | add r4, r5 36 | ldrb r5, [r0, #160 * 2 - 1] 37 | and r4, r10, r4, lsr #1 38 | lsl r5, #1 39 | orr r4, r4, r4, ror #16 40 | ldrh r5, [r2, r5] 41 | str r4, [r1, #160 * 4 - 4] 42 | orr r5, r5, r5, lsl #16 43 | str r5, [r1, #160 * 3 * 4 - 4] 44 | str r5, [r1, #160 * 4 * 4 - 4] 45 | adds r3, #1 << 16 46 | bmi 2b 47 | add r0, #160 * 2 48 | add r1, #160 * 4 * 4 49 | subs r3, #5 50 | bhi 1b 51 | pop {r4-r10,pc} 52 | 53 | CODE32_FN scr_update_9x8d9_asm 54 | push {r4-r10,lr} 55 | sub r2, r1, #256 * 2 56 | ldr r10, =0x07e0f81f 57 | mov r3, #128 58 | bic lr, r10, r10, lsl #1 59 | ldr r9, =0x1fe 60 | 1: sub r3, #(160 * 7) << 16 61 | 2: ldr r7, [r0], #4 62 | adds r3, #4 << 16 63 | and r4, r9, r7, lsl #1 64 | and r5, r9, r7, lsr #7 65 | and r6, r9, r7, lsr #15 66 | and r7, r9, r7, lsr #23 67 | ldrh r4, [r2, r4] 68 | ldrh r5, [r2, r5] 69 | ldrh r6, [r2, r6] 70 | ldrh r7, [r2, r7] 71 | orr r4, r4, r5, lsl #16 72 | orr r6, r6, r7, lsl #16 73 | stmia r1!, {r4,r6} 74 | bmi 2b 75 | 76 | sub r3, #160 << 16 77 | 2: ldrb r5, [r0, #160] 78 | ldrb r4, [r0], #1 79 | lsl r5, #1 80 | lsl r4, #1 81 | ldrh r5, [r2, r5] 82 | ldrh r4, [r2, r4] 83 | adds r3, #1 << 16 84 | orr r4, r4, r5, lsl #16 85 | and r5, r10, r4, ror #16 86 | and r4, r10 87 | add r4, r5 88 | and r5, lr, r4, lsr #1 89 | add r4, r5 90 | and r4, r10, r4, lsr #1 91 | orr r4, r4, r4, lsr #16 92 | strh r4, [r1], #2 93 | bmi 2b 94 | add r0, #160 95 | subs r3, #8 96 | bhi 1b 97 | pop {r4-r10,pc} 98 | 99 | CODE32_FN scr_update_128x64_asm 100 | push {r4-r11,lr} 101 | sub r2, r1, #256 102 | mov r3, #144 103 | mov r10, #3 << 18 104 | ldr r11, =0x2d83 105 | mov r8, #0 // a0 106 | mov r9, #0 // a1 107 | mov lr, #0 108 | 1: sub r3, #128 << 16 109 | 2: 110 | 3: add lr, #9 111 | 4: ldrb r4, [r0, #1] 112 | ldrb r5, [r0, #3] 113 | ldrb r4, [r2, r4] 114 | ldrb r5, [r2, r5] 115 | ldrb r7, [r0, #2] 116 | orr r6, r4, r5, lsl #16 // t1 117 | ldrb r5, [r0, #4] 118 | ldrb r4, [r0], #160 // s2 += 160 119 | ldrb r5, [r2, r5] 120 | ldrb r4, [r2, r4] 121 | ldrb r7, [r2, r7] 122 | orr r4, r4, r5, lsl #16 // t0 123 | orr r7, r7, r7, lsl #16 // t2 124 | 125 | add r4, r6, r4, lsl #2 // t0 = t0 * 4 + t1 126 | add r7, r6 // t2 += t1 127 | add r5, r6, r7, lsl #1 // t1 += t2 * 2 128 | 129 | add r8, r8, r4, lsl #2 // a0 += t0 * 4 130 | add r9, r9, r5, lsl #2 // a1 += t1 * 4 131 | subs lr, #4 132 | bhi 4b 133 | mul r4, lr, r4 // t0 134 | mul r5, lr, r5 // t1 135 | add r6, r8, r4 // a0 136 | add r7, r9, r5 // a1 137 | rsb r8, r4, #0 // a0 138 | rsb r9, r5, #0 // a1 139 | 140 | lsr r5, r7, #16 // b 141 | eor r4, r7, r5, lsl #16 // a 142 | mla r5, r11, r5, r10 143 | mla r4, r11, r4, r10 144 | lsr r5, #20 145 | lsr r4, #20 146 | strb r5, [r1, #2] 147 | strb r4, [r1, #1] 148 | 149 | lsr r5, r6, #16 // b 150 | eor r4, r6, r5, lsl #16 // a 151 | mla r5, r11, r5, r10 152 | mla r4, r11, r4, r10 153 | lsr r5, #20 154 | lsr r4, #20 155 | strb r5, [r1, #3] 156 | strb r4, [r1], #128 157 | bne 3b 158 | sub r0, #160 * 9 159 | sub r1, #128 * 4 160 | add r0, #5 161 | add r1, #4 162 | adds r3, #4 << 16 163 | bmi 2b 164 | add r0, #160 * (9 - 1) 165 | add r1, #128 * (4 - 1) 166 | subs r3, #9 167 | bhi 1b 168 | pop {r4-r11,pc} 169 | 170 | -------------------------------------------------------------------------------- /release.make: -------------------------------------------------------------------------------- 1 | 2 | export 3 | 4 | BINDIR = release 5 | ZIPDIR = ../zipdir 6 | 7 | ifneq ($(words $(BINDIR)), 1) 8 | $(error BINDIR must not contain spaces in the name) 9 | endif 10 | ifneq ($(words $(ZIPDIR)), 1) 11 | $(error ZIPDIR must not contain spaces in the name) 12 | endif 13 | 14 | FPBIN = $(BINDIR)/sdcard/fpbin 15 | FPBIN_T117 = $(BINDIR)/sdcard/fpbin_t117 16 | APPS = fpdoom fpduke3d fpsw fpblood infones \ 17 | wolf3d wolf3d_sw snes9x snes9x_16bit \ 18 | chocolate-doom chocolate-heretic chocolate-hexen \ 19 | gnuboy 20 | BINS = \ 21 | $(patsubst %,$(BINDIR)/usb/%.bin,fptest $(APPS)) \ 22 | $(patsubst %,$(BINDIR)/usb_t117/%.bin,fptest $(APPS)) \ 23 | $(patsubst %,$(FPBIN)/%.bin,fpmain $(APPS)) $(FPBIN)/config.txt \ 24 | $(patsubst %,$(FPBIN_T117)/%.bin,fpmain $(APPS)) $(FPBIN_T117)/config.txt \ 25 | $(patsubst %,$(BINDIR)/sdboot%.bin,1 2 3 _t117) $(BINDIR)/jump4m.bin \ 26 | 27 | .PHONY: all clean 28 | all: $(BINS) 29 | 30 | clean: 31 | $(RM) $(BINS) 32 | 33 | define getsrc 34 | test -d $@ || ( cd $(1) && mkdir -p $(ZIPDIR) && $(MAKE) -f helper.make ZIPDIR="$(ZIPDIR)" all patch ) 35 | endef 36 | 37 | doom_src: 38 | $(call getsrc,fpdoom) 39 | 40 | fpbuild/jfbuild: 41 | $(call getsrc,fpbuild) 42 | 43 | infones/InfoNES: 44 | $(call getsrc,infones) 45 | 46 | wolf3d/Wolf4SDL: 47 | $(call getsrc,wolf3d) 48 | 49 | snes9x/snes9x_src: 50 | $(call getsrc,snes9x) 51 | 52 | chocolate-doom/chocolate-doom: 53 | $(call getsrc,chocolate-doom) 54 | 55 | gnuboy/gnuboy: 56 | $(call getsrc,gnuboy) 57 | 58 | define makebin 59 | cd $(1) && $(MAKE) clean $(2) 60 | cd $(1) && $(MAKE) all $(2) 61 | mkdir -p $(dir $@) 62 | mv $(1)/$(notdir $@) $@ 63 | cd $(1) && $(MAKE) clean $(2) 64 | endef 65 | 66 | # PCTEST build 67 | 68 | $(BINDIR)/sdl1/%: OPTS += PCTEST=1 GFX_MODE=SDL1 69 | $(BINDIR)/sdl2/%: OPTS += PCTEST=1 GFX_MODE=SDL2 70 | 71 | # USB mode 72 | 73 | $(BINDIR)/usb/%: OPTS += LIBC_SDIO=0 74 | $(BINDIR)/usb_t117/%: OPTS += T117=1 LIBC_SDIO=0 75 | 76 | # SD card mode 77 | 78 | $(FPBIN)/%: OPTS += LIBC_SDIO=3 79 | $(FPBIN_T117)/%: OPTS += T117=1 LIBC_SDIO=3 80 | 81 | $(BINDIR)/sdboot1.bin: 82 | $(call makebin,sdboot,CHIP=1) 83 | 84 | $(BINDIR)/sdboot2.bin: 85 | $(call makebin,sdboot,CHIP=2) 86 | 87 | $(BINDIR)/sdboot3.bin: 88 | $(call makebin,sdboot,CHIP=3) 89 | 90 | $(BINDIR)/jump4m.bin: 91 | $(call makebin,sdboot,NAME=jump4m) 92 | 93 | $(BINDIR)/sdboot_t117.bin: 94 | $(call makebin,sdboot_t117,) 95 | 96 | $(FPBIN)/config.txt: 97 | mkdir -p $(dir $@) 98 | cp fpmenu/$(notdir $@) $@ 99 | 100 | $(FPBIN_T117)/config.txt: 101 | mkdir -p $(dir $@) 102 | sed 's|fpbin/|fpbin_t117/|' fpmenu/$(notdir $@) > $@ 103 | 104 | %/fpmenu.bin: 105 | $(call makebin,fpmenu,$(OPTS)) 106 | 107 | %/fpmain.bin: 108 | $(call makebin,fpmenu,$(OPTS) NAME=fpmain) 109 | 110 | %/fptest.bin: 111 | $(call makebin,fptest,$(OPTS)) 112 | 113 | %/fpdoom.bin: doom_src 114 | $(call makebin,fpdoom,$(OPTS)) 115 | 116 | %/fpduke3d.bin: fpbuild/jfbuild 117 | $(call makebin,fpbuild,$(OPTS) GAME=duke3d) 118 | 119 | %/fpsw.bin: fpbuild/jfbuild 120 | $(call makebin,fpbuild,$(OPTS) GAME=sw) 121 | 122 | %/fpblood.bin: fpbuild/jfbuild 123 | $(call makebin,fpbuild,$(OPTS) GAME=blood) 124 | 125 | %/infones.bin: infones/InfoNES 126 | $(call makebin,infones,$(OPTS)) 127 | 128 | %/wolf3d.bin: wolf3d/Wolf4SDL 129 | $(call makebin,wolf3d,$(OPTS)) 130 | 131 | %/wolf3d_sw.bin: wolf3d/Wolf4SDL 132 | $(call makebin,wolf3d,$(OPTS) NAME=wolf3d_sw) 133 | 134 | %/snes9x.bin: snes9x/snes9x_src 135 | $(call makebin,snes9x,$(OPTS)) 136 | 137 | %/snes9x_16bit.bin: snes9x/snes9x_src 138 | $(call makebin,snes9x,$(OPTS) NAME=snes9x_16bit) 139 | 140 | %/chocolate-doom.bin: chocolate-doom/chocolate-doom 141 | $(call makebin,chocolate-doom,$(OPTS) GAME=doom) 142 | 143 | %/chocolate-heretic.bin: chocolate-doom/chocolate-doom 144 | $(call makebin,chocolate-doom,$(OPTS) GAME=heretic) 145 | 146 | %/chocolate-hexen.bin: chocolate-doom/chocolate-doom 147 | $(call makebin,chocolate-doom,$(OPTS) GAME=hexen) 148 | 149 | %/gnuboy.bin: gnuboy/gnuboy 150 | $(call makebin,gnuboy,$(OPTS)) 151 | 152 | -------------------------------------------------------------------------------- /fpdoom/microfat.h: -------------------------------------------------------------------------------- 1 | #ifndef MICROFAT_H 2 | #define MICROFAT_H 3 | 4 | #include 5 | 6 | #ifndef FAT_WRITE 7 | #define FAT_WRITE 0 8 | #endif 9 | 10 | #ifndef FAT_LFN_MAX 11 | #define FAT_LFN_MAX 20 12 | #endif 13 | 14 | #ifndef FAT_SHORT_FIND 15 | #define FAT_SHORT_FIND 0 16 | #endif 17 | 18 | #ifndef FAT_DEBUG 19 | #define FAT_DEBUG 0 20 | #endif 21 | 22 | typedef struct { 23 | uint8_t *buf, *buf2; 24 | uint32_t buf_pos, buf2_pos; 25 | uint32_t fat1, fat2, data_seg; 26 | uint32_t root, curdir, cnum; 27 | #if FAT_WRITE 28 | const char *lastname; uint32_t lastdir; 29 | #endif 30 | uint8_t csize, csh, flags; 31 | #ifdef FATDATA_EXTRA 32 | FATDATA_EXTRA 33 | #endif 34 | } fatdata_t; 35 | 36 | #define FAT_CLUST_ERR 0 37 | #define FAT_FLUSH_BUF1 0x10 38 | #define FAT_FLUSH_BUF2 0x20 39 | 40 | typedef union { 41 | uint8_t raw[16]; 42 | struct { 43 | uint8_t name[8], ext[3]; 44 | uint8_t attr, attr2, ctime10ms; 45 | uint16_t ctime, cdate, adate, clust_hi; 46 | uint16_t mtime, mdate, clust_lo; 47 | uint32_t size; 48 | } entry; 49 | struct { 50 | uint8_t seq, name1[5 * 2]; 51 | uint8_t attr, attr2, chk; 52 | uint8_t name2[6 * 2]; 53 | uint16_t clust_lo; 54 | uint8_t name3[2 * 2]; 55 | } lfn; 56 | } fat_entry_t; 57 | 58 | enum { 59 | FAT_ATTR_RO = 1, /* read only */ 60 | FAT_ATTR_HID = 2, /* hidden */ 61 | FAT_ATTR_SYS = 4, /* system */ 62 | FAT_ATTR_VOL = 8, /* volume label */ 63 | FAT_ATTR_DIR = 0x10, /* directory */ 64 | FAT_ATTR_ARC = 0x20, /* archive */ 65 | 66 | FAT_ATTR_LFN = 0xf /* long file name */ 67 | }; 68 | 69 | int fat_init(fatdata_t *fatdata, int part_num); 70 | uint8_t* fat_read_sec(fatdata_t *x, uint8_t *buf, uint32_t sector); 71 | #if !FAT_WRITE 72 | unsigned fat_next_clust(fatdata_t *fatdata, unsigned clust); 73 | #else 74 | uint8_t* fat_write_sec(fatdata_t *x, uint8_t *buf, uint32_t sector); 75 | void fat_flush_buf1(fatdata_t *fatdata); 76 | void fat_flush_buf2(fatdata_t *fatdata); 77 | unsigned fat_alloc_clust(fatdata_t *fatdata, unsigned clust, uint32_t *start); 78 | void fat_free_chain(fatdata_t *fatdata, unsigned clust, unsigned end); 79 | static inline 80 | unsigned fat_next_clust(fatdata_t *fatdata, unsigned clust) { 81 | return fat_alloc_clust(fatdata, clust, (void*)0); 82 | } 83 | #endif 84 | 85 | int fat_enum_name(fatdata_t *fatdata, unsigned clust, 86 | int (*cb)(void*, fat_entry_t*, const char*), void *cbdata); 87 | fat_entry_t* fat_find_name(fatdata_t *fatdata, unsigned clust, 88 | const char *name, int len); 89 | fat_entry_t* fat_find_path(fatdata_t *fatdata, const char *name); 90 | unsigned fat_dir_clust(fatdata_t *fatdata, const char *name); 91 | unsigned fat_read_simple(fatdata_t *fatdata, unsigned clust, 92 | void *buf, uint32_t size); 93 | #if FAT_WRITE 94 | fat_entry_t* fat_create_name(fatdata_t *fatdata, unsigned clust, 95 | const char *name); 96 | unsigned fat_make_dir(fatdata_t *fatdata, unsigned clust, 97 | const char *name); 98 | void fat_delete_entry(fatdata_t *fatdata, fat_entry_t *p); 99 | int fat_rmdir_check(fatdata_t *fatdata, unsigned clust); 100 | #endif 101 | 102 | static inline 103 | unsigned fat_entry_clust(fat_entry_t *p) { 104 | return p->entry.clust_hi << 16 | p->entry.clust_lo; 105 | } 106 | 107 | #if FAT_WRITE && defined(FAT_WRITE_SYS) 108 | uint8_t* fat_write_sec(fatdata_t *fatdata, uint8_t *buf, uint32_t sector) { 109 | (void)fatdata; 110 | do { 111 | FAT_WRITE_SYS 112 | return buf; 113 | } while (0); 114 | return NULL; 115 | } 116 | #endif 117 | 118 | #ifdef FAT_READ_SYS 119 | uint8_t* fat_read_sec(fatdata_t *fatdata, uint8_t *buf, uint32_t sector) { 120 | if (buf == fatdata->buf) { 121 | if (fatdata->buf_pos == sector) return buf; 122 | #if FAT_WRITE 123 | if (fatdata->flags & FAT_FLUSH_BUF1) { 124 | fat_flush_buf1(fatdata); 125 | buf = fatdata->buf; 126 | } 127 | #endif 128 | } 129 | do { 130 | FAT_READ_SYS 131 | if (buf == fatdata->buf) fatdata->buf_pos = sector; 132 | return buf; 133 | } while (0); 134 | if (buf == fatdata->buf) fatdata->buf_pos = ~0; // discard cache 135 | return NULL; 136 | } 137 | #endif 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /wolf3d/wlsys_fp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #define WLSYS_MAIN 6 | #include "wlsys_def.h" 7 | 8 | static void *framebuf_mem = NULL; 9 | uint16_t *framebuf; 10 | 11 | void lcd_appinit(void) { 12 | static const uint16_t dim[] = { 13 | 320, 240, 160, 128, 480, 320, 400, 240, 14 | }; 15 | struct sys_display *disp = &sys_data.display; 16 | unsigned scaler = sys_data.scaler - 1; 17 | unsigned w = disp->w1, h = disp->h1; 18 | if (h <= 68) { 19 | scaler = GS_MODE; 20 | if (h == 68) scaler = GS_MODE + 1; 21 | if (h == 48) scaler = GS_MODE + 2; 22 | } else { 23 | if (scaler >= GS_MODE) { 24 | switch (w) { 25 | case 400: scaler = 3; break; 26 | case 480: scaler = 2; break; 27 | case 240: case 320: 28 | scaler = 0; break; 29 | case 128: case 160: 30 | case 176: case 220: 31 | scaler = 1; break; 32 | default: 33 | fprintf(stderr, "!!! unsupported resolution (%dx%d)\n", w, h); 34 | exit(1); 35 | } 36 | } 37 | w = dim[scaler * 2]; 38 | h = dim[scaler * 2 + 1]; 39 | } 40 | sys_data.scaler = scaler; 41 | disp->w2 = w; 42 | disp->h2 = h; 43 | } 44 | 45 | void wlsys_end(void) { 46 | if (framebuf_mem) free(framebuf_mem); 47 | } 48 | 49 | uint8_t* wlsys_init(void) { 50 | struct sys_display *disp = &sys_data.display; 51 | int w = disp->w2, h = disp->h2; 52 | unsigned size, size1, size2; uint8_t *p; 53 | static const uint8_t pal_size[] = { 2, 4, 6, 6, 1, 1, 1 }; 54 | int scaler = sys_data.scaler; 55 | int w1 = w, h1 = h; 56 | if (scaler == 1) { 57 | w1 <<= 1; h1 <<= 1; 58 | } else if (h <= 68) { 59 | w1 = 320; h1 = 224; 60 | if (h == 68) h1 = 226; 61 | if (h == 48) h1 = 240; 62 | } 63 | frameWidth = w; 64 | frameHeight = h; 65 | screenWidth = w1; 66 | screenHeight = h1; 67 | size = w * h; 68 | size1 = w1 * h1; 69 | size2 = pal_size[scaler] << 8; 70 | p = malloc(size * 2 + size2 + size1 + 31); 71 | framebuf_mem = p; 72 | p += -(intptr_t)p & 31; 73 | p += size2; 74 | framebuf = (uint16_t*)p; 75 | p += size * 2; 76 | 77 | initFizzle(); 78 | sys_framebuffer(framebuf); 79 | sys_start(); 80 | 81 | return p; 82 | } 83 | 84 | #define X(num, name) KEYPAD_##name = num, 85 | enum { KEYPAD_ENUM(X) }; 86 | #undef X 87 | 88 | void keytrn_init(void) { 89 | uint8_t keymap[64], rkeymap[64]; 90 | static const uint8_t keys[] = { 91 | #define KEY(name, val) KEYPAD_##name, val, 92 | KEY(UP, sc_UpArrow) 93 | KEY(LEFT, sc_LeftArrow) 94 | KEY(RIGHT, sc_RightArrow) 95 | KEY(DOWN, sc_DownArrow) 96 | KEY(2, sc_UpArrow) 97 | KEY(4, sc_LeftArrow) 98 | KEY(6, sc_RightArrow) 99 | KEY(5, sc_DownArrow) 100 | KEY(LSOFT, sc_Return) 101 | KEY(RSOFT, sc_Escape) 102 | KEY(CENTER, sc_LControl) /* fire */ 103 | KEY(DIAL, sc_CapsLock) /* run toggle */ 104 | KEY(1, 'q') /* strafe left */ 105 | KEY(3, 'e') /* strafe right */ 106 | KEY(7, '[') /* prev weapon */ 107 | KEY(9, ']') /* next weapon */ 108 | KEY(PLUS, sc_O) /* map */ 109 | }; 110 | static const uint8_t keys_power[] = { 111 | KEY(UP, sc_CapsLock) 112 | KEY(LEFT, '[') 113 | KEY(RIGHT, ']') 114 | KEY(DOWN, sc_Escape) 115 | KEY(CENTER, sc_Return) 116 | KEY(DIAL, sc_O) /* map */ 117 | KEY(4, sc_G) /* G+Y: god mode */ 118 | KEY(5, sc_Y) 119 | KEY(6, sc_M) /* M+Y: all items */ 120 | #undef KEY 121 | }; 122 | int i, flags = sys_getkeymap(keymap); 123 | 124 | #define FILL_RKEYMAP(keys) \ 125 | memset(rkeymap, 0, sizeof(rkeymap)); \ 126 | for (i = 0; i < (int)sizeof(keys); i += 2) \ 127 | rkeymap[keys[i]] = keys[i + 1]; 128 | 129 | FILL_RKEYMAP(keys) 130 | 131 | #define KEY(name) rkeymap[KEYPAD_##name] 132 | // no center key 133 | if (!(flags & 1)) { 134 | KEY(UP) = sc_LControl; /* fire */ 135 | KEY(DOWN) = sc_LControl; /* fire */ 136 | } 137 | #undef KEY 138 | 139 | #define FILL_KEYTRN(j) \ 140 | for (i = 0; i < 64; i++) { \ 141 | unsigned a = keymap[i]; \ 142 | sys_data.keytrn[j][i] = a < 64 ? rkeymap[a] : 0; \ 143 | } 144 | 145 | FILL_KEYTRN(0) 146 | FILL_RKEYMAP(keys_power) 147 | FILL_KEYTRN(1) 148 | #undef FILL_RKEYMAP 149 | #undef FILL_KEYTRN 150 | } 151 | -------------------------------------------------------------------------------- /ums9117/syscomm.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "syscode.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define DBG_LOG(...) fprintf(stderr, __VA_ARGS__) 9 | #define ERR_EXIT(...) \ 10 | do { fprintf(stderr, "!!! " __VA_ARGS__); exit(1); } while (0) 11 | 12 | uint32_t *pinmap_addr, *gpiomap_addr; 13 | 14 | static uint8_t* loadfile(const char *fn, size_t *num) { 15 | size_t n, j = 0; uint8_t *buf = 0; 16 | FILE *fi = fopen(fn, "rb"); 17 | if (fi) { 18 | fseek(fi, 0, SEEK_END); 19 | n = ftell(fi); 20 | if (n) { 21 | fseek(fi, 0, SEEK_SET); 22 | buf = (uint8_t*)malloc(n); 23 | if (buf) j = fread(buf, 1, n, fi); 24 | } 25 | fclose(fi); 26 | } 27 | if (num) *num = j; 28 | return buf; 29 | } 30 | 31 | 32 | static uint32_t* gpiomap_check(uint32_t *p, unsigned size) { 33 | uint32_t *p0; 34 | if (size < 8 + 12) return NULL; 35 | // skip empty GPIO related table 36 | if (~p[0] || p[1] != 0xffff) return NULL; 37 | p0 = p += 2; size -= 8; 38 | for (; size >= 12; p += 3, size -= 12) { 39 | uint32_t a = p[0]; 40 | if (a & 0xfffeff80) { 41 | if (a != 0xffff || p[1] != 2 || p[2] != 5) break; 42 | return p0; 43 | } 44 | if (p[1] >= 2 || p[2] >= 6) break; 45 | } 46 | return NULL; 47 | } 48 | 49 | static int pinmap_check(uint32_t *p, uint32_t size) { 50 | if ((size < 8) || (size & 3)) return -1; 51 | for (; size > 8; size -= 8, p += 2) { 52 | uint32_t addr = p[0]; 53 | if (!(addr - 0x40608000 < 0x1000) && 54 | !(addr - 0x402a0000 < 0x1000)) 55 | break; 56 | } 57 | if (~(p[0] & p[1])) return -1; 58 | gpiomap_addr = gpiomap_check(p + 2, size - 8); 59 | return 0; 60 | } 61 | 62 | void scan_firmware(intptr_t fw_addr) { 63 | #if LIBC_SDIO 64 | const char *pinmap_fn = "/" FPBIN_DIR "pinmap.bin"; 65 | const char *keymap_fn = "/" FPBIN_DIR "keymap.bin"; 66 | #else 67 | const char *pinmap_fn = "pinmap.bin"; 68 | const char *keymap_fn = "keymap.bin"; 69 | #endif 70 | size_t size; 71 | (void)fw_addr; 72 | 73 | pinmap_addr = (uint32_t*)loadfile(pinmap_fn, &size); 74 | if (!pinmap_addr) ERR_EXIT("pinmap not found\n"); 75 | if (pinmap_check(pinmap_addr, size)) ERR_EXIT("pinmap check failed\n"); 76 | if (sys_data.gpio_init && !gpiomap_addr) 77 | ERR_EXIT("gpiomap not found\n"); 78 | 79 | if (!sys_data.keymap_addr) { 80 | FILE *f = fopen(keymap_fn, "rb"); 81 | if (f) { 82 | uint8_t *p = (uint8_t*)sys_data.keytrn; 83 | printf("keymap loaded from file\n"); 84 | sys_data.keymap_addr = (short*)p; 85 | memset(p, -1, 64 * 2); 86 | fread(p, 1, 64 * 2, f); 87 | fclose(f); 88 | } 89 | } 90 | } 91 | 92 | // system timer, 1ms step 93 | uint32_t sys_timer_ms(void) { 94 | return MEM4(0x4023000c); 95 | } 96 | 97 | void sys_wait_ms(uint32_t delay) { 98 | uint32_t start = sys_timer_ms(); 99 | while (sys_timer_ms() - start < delay); 100 | } 101 | 102 | void sys_wait_us(uint32_t delay) { 103 | delay *= 1000; 104 | sys_wait_clk(delay); 105 | } 106 | 107 | #define X(num, name) KEYPAD_##name = num, 108 | enum { KEYPAD_ENUM(X) }; 109 | #undef X 110 | 111 | int sys_getkeymap(uint8_t *dest) { 112 | short *keymap = sys_data.keymap_addr; 113 | int i, j, rotate = sys_data.rotate >> 4 & 3; 114 | static const unsigned char num_turn[][4 + 9] = { 115 | { "\004\005\006\007123456789" }, 116 | { "\007\006\004\005369258147" }, 117 | { "\005\004\007\006987654321" }, 118 | { "\006\007\005\004741852963" }, 119 | }; 120 | int nrow = sys_data.keyrows; 121 | int ncol = sys_data.keycols; 122 | int flags = 0; 123 | 124 | memset(dest, -1, 64); 125 | 126 | for (i = 0; i < ncol; i++) 127 | for (j = 0; j < nrow; j++) { 128 | unsigned a = keymap[i * nrow + j]; 129 | if (a - KEYPAD_UP < 4) 130 | a = num_turn[rotate][a - KEYPAD_UP]; 131 | else if (a - KEYPAD_1 < 9) 132 | a = num_turn[rotate][a - KEYPAD_1 + 4]; 133 | if (a > 0xff) a = 0xff; 134 | dest[j * 8 + i] = a; 135 | if (a == KEYPAD_CENTER) flags = 1; 136 | } 137 | if (sys_data.keyflags) 138 | flags = sys_data.keyflags; 139 | return flags; 140 | } 141 | 142 | struct sys_data sys_data; 143 | 144 | #if !CHIP 145 | int _chip; 146 | #endif 147 | 148 | -------------------------------------------------------------------------------- /ums9117/init_t117.h: -------------------------------------------------------------------------------- 1 | 2 | static void init_pmu0(void) { 3 | MEM4(0x40410014) |= 1; // ANLG_WRAP_G6 4 | // PMU 5 | MEM4(0x402b009c) &= ~0x300; 6 | MEM4(0x402b009c) |= 0x100; 7 | MEM4(0x402b00a0) &= ~0x300; 8 | MEM4(0x402b00a0) |= 0x100; 9 | } 10 | 11 | static void init_pmu1(void) { 12 | uint32_t b = 0x402b0000; // PMU 13 | MEM4(b + 0x80) |= 0x33; 14 | MEM4(b + 0x84) &= ~0x13; 15 | MEM4(b + 0x8c) |= 0x33; 16 | MEM4(b + 0x90) &= ~0x13; 17 | MEM4(b + 0x94) |= 1; 18 | MEM4(b + 0x98) |= 0x10; 19 | MEM4(b + 0x9c) |= 2; 20 | MEM4(b + 0x9c) &= ~1; 21 | MEM4(b + 0xa0) |= 0x33; 22 | MEM4(b + 0xa8) &= ~0x20; 23 | MEM4(b + 0xac) |= 0x33; 24 | } 25 | 26 | static void init_dbg_freq(unsigned freq) { 27 | uint32_t a = MEM4(0x20e00038) & ~0x70707; 28 | uint32_t q = (freq - 1) / 500000000; 29 | MEM4(0x20e00038) = a | q | q << 8 | q << 16; 30 | MEM4(0x402d0270) |= 3; 31 | } 32 | 33 | static void init_mcu_freq(unsigned freq) { 34 | uint32_t a0 = MEM4(0x403f0000) & ~0xc0; 35 | uint32_t a1 = MEM4(0x403f0004) & 0xc0000000; 36 | static const unsigned tab[] = { 936, 1248, /* 1600 */ ~0 }; 37 | unsigned i; 38 | uint32_t t0 = freq / 1000000, t1 = t0 / 26; 39 | 40 | t1 = (t1 & 0x7f) << 23 | ((t0 - t1 * 26) << 23) / 26; 41 | for (i = 0; tab[i] < t0;) i++; 42 | // ANLG_WRAP_G4 43 | MEM4(0x403f0000) = a0 | 5 | i << 6; 44 | MEM4(0x403f0004) = a1 | t1; 45 | DELAY(3200) 46 | } 47 | 48 | static void init_mcu(void) { 49 | unsigned freq = 1000000000; 50 | 51 | // AXI freq 52 | MEM4(0x402d0300) |= 3; 53 | DELAY(256) 54 | 55 | init_dbg_freq(freq); 56 | init_mcu_freq(freq); 57 | 58 | // APB freq 59 | MEM4(0x20e00054) = 3; 60 | DELAY(256) 61 | MEM4(0x21500020) |= 3; 62 | MEM4(0x402d0220) |= 3; 63 | MEM4(0x402d02f8) |= 1; 64 | } 65 | 66 | static void init_freq(void) { 67 | MEM4(0x402e00b0) |= 0x2800; 68 | // clk core 69 | MEM4(0x21500020) &= ~3; 70 | MEM4(0x402d0300) &= ~3; 71 | 72 | init_pmu0(); 73 | init_pmu1(); 74 | init_mcu(); 75 | MEM4(0x402e2004) = 0x30; 76 | } 77 | 78 | static void init_uart(void) { 79 | uint32_t a, b = 0x70100000; // UART1 base 80 | unsigned baud = 115200; 81 | 82 | MEM4(b + 0x10) = 0; 83 | MEM4(0x71300000) |= 0x6000; // APB base 84 | a = (26000000 + (baud >> 1)) / baud; 85 | MEM4(b + 0x24) = a & 0xffff; 86 | MEM4(b + 0x28) = a >> 16; 87 | MEM4(b + 0x18) = 28; 88 | MEM4(b + 0x1c) = 0; 89 | MEM4(b + 0x20) = 0; 90 | } 91 | 92 | static void init_timer(void) { 93 | MEM4(0x402e0000) |= 0x400; 94 | MEM4(0x402e0010) |= 8; 95 | } 96 | 97 | static void init_pmu2(void) { 98 | uint32_t b = 0x402b0000; // PMU 99 | MEM4(b + 0x00) &= ~0xffffff; 100 | MEM4(b + 0x00) |= 0x11004; 101 | MEM4(b + 0x70) = 0x2222; 102 | MEM4(b + 0x74) = 0x101; 103 | MEM4(b + 0x18) &= ~0xffffff; 104 | MEM4(b + 0x18) |= 0x10106; 105 | MEM4(b + 0x28) &= ~0xffffff; 106 | MEM4(b + 0x28) |= 0x10204; 107 | MEM4(b + 0x34) &= ~0xffffff; 108 | MEM4(b + 0x34) |= 0x10402; 109 | MEM4(b + 0x38) &= ~0xffffff; 110 | MEM4(b + 0x38) |= 0x10501; 111 | MEM4(b + 0x3c) &= ~0xffffff; 112 | MEM4(b + 0x3c) |= 0x10303; 113 | MEM4(b + 0x44) &= ~0xffffff; 114 | MEM4(b + 0x44) |= 0x10105; 115 | MEM4(b + 0x5c) &= ~0xffffff; 116 | MEM4(b + 0x5c) |= 0x10101; 117 | MEM4(b + 0x78) = 0x8080808; 118 | MEM4(b + 0x7c) = 0x80800; 119 | MEM4(b + 0x17c) = 0x80808; 120 | MEM4(b + 0x180) = 0x800; 121 | MEM4(b + 0x338) = 0; 122 | MEM4(b + 0x33c) = 0x7F; 123 | MEM4(b + 0x340) = 1; 124 | MEM4(b + 0x344) = 0x10101; 125 | MEM4(b + 0x35c) = (MEM4(b + 0x35c) & 0xf) | 0x10; 126 | } 127 | 128 | static void init_adi(void) { 129 | MEM4(0x402e1000) = 0x10000; 130 | MEM4(0x40600008) = 0; 131 | MEM4(0x4060000c) = 0; 132 | MEM4(0x40600024) |= 0x80000000; 133 | MEM4(0x40600020) &= ~0x40000000; 134 | } 135 | 136 | static void init_adi_por(void) { 137 | adi_write(0x40608e38, adi_read(0x40608e38) & ~0x100); 138 | adi_write(0x40608e38, adi_read(0x40608e38) & ~1); 139 | } 140 | 141 | static void init_adi_wdg(void) { 142 | adi_write(0x40608c08, adi_read(0x40608c08) | 4); // wdg 143 | adi_write(0x40608c10, adi_read(0x40608c10) | 4); // wdg rtc 144 | } 145 | 146 | static void init_t117(void) { 147 | init_freq(); 148 | init_uart(); 149 | init_timer(); 150 | init_pmu2(); 151 | 152 | init_adi(); 153 | init_adi_por(); 154 | init_adi_wdg(); 155 | } 156 | 157 | -------------------------------------------------------------------------------- /fpdoom/syscode.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSCODE_H 2 | #define SYSCODE_H 3 | 4 | #include 5 | 6 | #ifndef INIT_MMU 7 | #define INIT_MMU 1 8 | #endif 9 | 10 | #if UMS9117 11 | //#define CHIPRAM_ADDR 0 12 | // not chipram, used to store app args 13 | #define CHIPRAM_ADDR 0x80004000 14 | #define FPBIN_DIR "fpbin_t117/" 15 | 16 | #define KEYPAD_BASE ((keypad_base_t*)0x40250000) 17 | #define LCDC_BASE ((lcdc_base_t*)0x20800000) 18 | #else 19 | #define CHIPRAM_ADDR 0x40000000 20 | #define FIRMWARE_SIZE (4 << 20) 21 | #define FPBIN_DIR "fpbin/" 22 | 23 | #define KEYPAD_BASE ((keypad_base_t*)0x87000000) 24 | #define LCDC_BASE ((lcdc_base_t*)0x20d00000) 25 | #endif 26 | 27 | typedef volatile struct { 28 | uint32_t ctrl, int_en, int_raw, int_mask; 29 | uint32_t int_clr, dummy_14, polarity, debounce; 30 | uint32_t long_key, sleep_cnt, clk_divide, key_status; 31 | uint32_t sleep_stat, dbg_stat1, dbg_stat2; 32 | } keypad_base_t; 33 | 34 | typedef volatile struct { 35 | uint32_t ctrl, disp_size, lcm_start, lcm_size; 36 | uint32_t bg_color, fifo_status, sync_delay, dummy[1]; 37 | struct { // 0x20 38 | uint32_t ctrl, y_base_addr, uv_base_addr, size_xy; 39 | uint32_t pitch, disp_xy, dummy[6]; 40 | } img; 41 | struct { // 0x50, 0x80, 0xb0 42 | uint32_t ctrl, base_addr, alpha_base_addr, size_xy; 43 | uint32_t pitch, disp_xy, alpha, grey_rgb; 44 | uint32_t ck, dummy[3]; 45 | } ocd1, ocd2, ocd3; 46 | struct { // 0x80 47 | uint32_t ctrl, base_addr, start_xy, size_xy; 48 | uint32_t pitch, dummy[3]; 49 | } cap; 50 | struct { // 0x100 51 | uint32_t ctrl, contrast, saturation, brightness; 52 | } y2r; 53 | struct { // 0x110 54 | uint32_t en, clr, status, raw; 55 | } irq; 56 | } lcdc_base_t; 57 | 58 | /* from assembly code */ 59 | void enable_mmu(uint32_t *table, uint32_t domain); 60 | void set_cpsr_c(uint32_t a); 61 | 62 | int sys_lzma_decode(const uint8_t *src, unsigned src_size, 63 | uint8_t *dst, unsigned dst_size); 64 | void scan_firmware(intptr_t fw_addr); 65 | uint32_t sys_timer_ms(void); 66 | void sys_wait_ms(uint32_t delay); 67 | void sys_wait_us(uint32_t delay); 68 | void sys_wait_clk(uint32_t delay); 69 | int sys_getkeymap(uint8_t *dest); 70 | 71 | uint32_t adi_read(uint32_t addr); 72 | void adi_write(uint32_t addr, uint32_t val); 73 | void sys_init(void); 74 | void sys_start(void); 75 | int sys_event(int *rkey); 76 | void sys_brightness(unsigned val); 77 | void sys_framebuffer(void *base); 78 | void sys_start_refresh(void); 79 | void sys_wait_refresh(void); 80 | __attribute__((noreturn)) 81 | void sys_exit(void); 82 | __attribute__((noreturn)) 83 | #define SYS_RESET_DELAY (0x8000 / 2) /* 0.5 sec */ 84 | void sys_wdg_reset(unsigned val); 85 | 86 | void invalidate_icache(void); 87 | void clean_dcache(void); 88 | void clean_dcache_range(void *start, void *end); 89 | void clean_invalidate_dcache(void); 90 | void clean_invalidate_dcache_range(void *start, void *end); 91 | 92 | enum { 93 | EVENT_KEYDOWN, EVENT_KEYUP, EVENT_END, EVENT_QUIT 94 | }; 95 | 96 | // extern 97 | 98 | extern struct sys_data { 99 | short *keymap_addr; 100 | struct { uint32_t num, ver, adi; } chip_id; 101 | struct sys_display { uint16_t w1, h1, w2, h2; } display; 102 | uint16_t keytrn[2][64]; // must be aligned by 4 103 | uint8_t brightness, init_done; 104 | uint8_t keyrows, keycols, keyflags; 105 | uint8_t scaler; 106 | /* rotate = key << 4 | screen */ 107 | uint8_t rotate, lcd_cs; 108 | uint8_t spi_mode; 109 | int8_t charge; 110 | uint8_t gpio_init; 111 | #if UMS9117 112 | uint8_t bl_extra[4]; 113 | #else 114 | uint8_t bl_gpio; 115 | #endif 116 | uint16_t mac; 117 | uint32_t spi; 118 | uint32_t lcd_id; 119 | uint8_t *framebuf; 120 | uint8_t user[4]; 121 | } sys_data; 122 | 123 | // appinit 124 | 125 | void keytrn_init(void); 126 | void lcd_appinit(void); 127 | 128 | #define KEYPAD_ENUM(M) \ 129 | M(0x01, DIAL) \ 130 | M(0x04, UP) M(0x05, DOWN) M(0x06, LEFT) M(0x07, RIGHT) \ 131 | M(0x08, LSOFT) M(0x09, RSOFT) M(0x0d, CENTER) \ 132 | M(0x0e, CAMERA) M(0x1d, EXT_1D) M(0x1f, EXT_1F) \ 133 | M(0x21, EXT_21) M(0x23, HASH) M(0x24, VOLUP) M(0x25, VOLDOWN) \ 134 | M(0x29, EXT_29) M(0x2a, STAR) M(0x2b, PLUS) \ 135 | M(0x2c, EXT_2C) M(0x2d, MINUS) M(0x2f, EXT_2F) \ 136 | M(0x30, 0) M(0x31, 1) M(0x32, 2) M(0x33, 3) M(0x34, 4) \ 137 | M(0x35, 5) M(0x36, 6) M(0x37, 7) M(0x38, 8) M(0x39, 9) 138 | 139 | #endif // SYSCODE_H 140 | -------------------------------------------------------------------------------- /chocolate-doom/Makefile: -------------------------------------------------------------------------------- 1 | GAME = doom 2 | NAME = chocolate-$(GAME) 3 | OBJDIR = obj$(CHIP)_$(GAME) 4 | SRCDIR = chocolate-doom 5 | FPDOOM_DIR = ../fpdoom 6 | USE_ASM = 1 7 | NO_FLOAT = 1 8 | NO_DEH = 1 9 | KEYTRN_PC = 1 10 | 11 | APP_SRCS = port_hacks port_sys scr_update 12 | ifneq ($(USE_ASM), 0) 13 | APP_SRCS += doomasm 14 | endif 15 | 16 | COMMON_SRCS = i_system m_argv m_misc d_event \ 17 | d_iwad d_loop d_mode gusconf i_cdmus i_flmusic \ 18 | i_glob i_musicpack m_bbox m_cheat m_config m_controls \ 19 | m_fixed memio tables v_diskicon v_video w_main \ 20 | w_wad w_file w_file_stdc w_merge z_zone 21 | ifeq ($(NO_DEH), 0) 22 | COMMON_SRCS += deh_str deh_io deh_main deh_mapping deh_text 23 | endif 24 | 25 | ifeq ($(GAME), doom) 26 | GAME_CFLAGS += -DGAME_DOOM 27 | GAME_SRCS = am_map deh_misc d_items d_main d_net doomdef doomstat dstrings \ 28 | f_finale f_wipe g_game hu_lib hu_stuff info m_menu m_random p_ceilng \ 29 | p_doors p_enemy p_floor p_inter p_lights p_map p_maputl p_mobj \ 30 | p_plats p_pspr p_saveg p_setup p_sight p_spec p_switch p_telept \ 31 | p_tick p_user r_bsp r_data r_draw r_main r_plane r_segs r_sky \ 32 | r_things s_sound sounds statdump st_lib st_stuff wi_stuff 33 | ifeq ($(NO_DEH), 0) 34 | GAME_SRCS += deh_ammo deh_bexstr deh_cheat deh_doom \ 35 | deh_frame deh_ptr deh_sound deh_thing deh_weapon 36 | endif 37 | else ifeq ($(GAME), heretic) 38 | GAME_CFLAGS += -DGAME_HERETIC 39 | GAME_SRCS = am_map ct_chat d_main d_net \ 40 | f_finale g_game info in_lude m_random mn_menu p_ceilng \ 41 | p_doors p_enemy p_floor p_inter p_lights p_map p_maputl \ 42 | p_mobj p_plats p_pspr p_saveg p_setup p_sight p_spec \ 43 | p_switch p_telept p_tick p_user r_bsp r_data r_draw \ 44 | r_main r_plane r_segs r_things sb_bar sounds s_sound 45 | ifeq ($(NO_DEH), 0) 46 | GAME_SRCS += deh_ammo deh_frame deh_htext \ 47 | deh_htic deh_sound deh_thing deh_weapon 48 | endif 49 | else ifeq ($(GAME), hexen) 50 | GAME_CFLAGS += -DGAME_HEXEN 51 | GAME_SRCS = a_action am_map ct_chat d_net f_finale g_game \ 52 | h2_main info in_lude m_random mn_menu p_acs p_anim p_ceilng \ 53 | p_doors p_enemy p_floor p_inter p_lights p_map p_maputl p_mobj \ 54 | po_man p_plats p_pspr p_setup p_sight p_spec p_switch p_telept \ 55 | p_things p_tick p_user r_bsp r_data r_draw r_main r_plane r_segs \ 56 | r_things s_sound sb_bar sc_man sn_sonix sounds st_start sv_save 57 | else ifeq ($(GAME), strife) 58 | GAME_CFLAGS += -DGAME_STRIFE 59 | GAME_SRCS = am_map deh_misc d_items d_main \ 60 | d_net doomdef doomstat dstrings f_finale f_wipe g_game hu_lib \ 61 | hu_stuff info m_menu m_random m_saves p_ceilng p_dialog p_doors \ 62 | p_enemy p_floor p_inter p_lights p_map p_maputl p_mobj p_plats \ 63 | p_pspr p_saveg p_setup p_sight p_spec p_switch p_telept p_tick \ 64 | p_user r_bsp r_data r_draw r_main r_plane r_segs r_sky \ 65 | r_things s_sound sounds st_lib st_stuff wi_stuff 66 | ifeq ($(NO_DEH), 0) 67 | GAME_SRCS += deh_ammo deh_cheat deh_strife deh_frame \ 68 | deh_ptr deh_sound deh_thing deh_weapon 69 | endif 70 | else 71 | $(error unknown GAME) 72 | endif 73 | 74 | APP_OBJS1 = $(APP_SRCS:%=$(OBJDIR)/app/%.o) 75 | APP_OBJS2 = $(COMMON_SRCS:%=$(OBJDIR)/common/%.o) 76 | APP_OBJS2 += $(GAME_SRCS:%=$(OBJDIR)/$(GAME)/%.o) 77 | 78 | include ../buildinc.make 79 | 80 | CFLAGS := $(filter-out -funsigned-char, $(CFLAGS)) -fsigned-char 81 | 82 | APP_CFLAGS += -std=gnu99 -pedantic 83 | ifneq ($(USE_ASM), 0) 84 | APP_CFLAGS += -DUSE_ASM 85 | endif 86 | 87 | GAME_CFLAGS += -DDISABLE_SDL2NET=1 -DDISABLE_SDL2MIXER=1 88 | GAME_CFLAGS += -DNO_SOUND=1 -DNO_MOUSE=1 -DNO_NET=1 89 | GAME_CFLAGS += -DNORANGECHECKING 90 | ifneq ($(NO_DEH), 0) 91 | GAME_CFLAGS += -DNO_DEH=1 92 | endif 93 | ifneq ($(NO_FLOAT), 0) 94 | GAME_CFLAGS += -DNO_FLOAT=1 95 | endif 96 | GAME_CFLAGS += -I$(SRCDIR)/src -I$(SRCDIR)/textscreen 97 | GAME_CFLAGS += -I. -ISDL2_dummy 98 | GAME_CFLAGS += -Wno-unused -Wno-sign-compare 99 | GAME_CFLAGS += -Wno-unused-parameter -Wno-strict-prototypes -Wno-newline-eof 100 | 101 | GAME_CFLAGS := $(APP_CFLAGS) $(GAME_CFLAGS) 102 | APP_CFLAGS := $(GAME_CFLAGS) -I$(SYSDIR) 103 | 104 | $(OBJDIR)/app/%.o: $(FPDOOM_DIR)/%.c | objdir 105 | $(call compile_cc,$(APP_CFLAGS)) 106 | 107 | $(OBJDIR)/app/%.o: $(FPDOOM_DIR)/%.s | objdir 108 | $(call compile_asm,) 109 | 110 | $(OBJDIR)/common/%.o: $(SRCDIR)/src/%.c | objdir 111 | $(call compile_cc,$(GAME_CFLAGS)) 112 | 113 | $(OBJDIR)/$(GAME)/%.o: $(SRCDIR)/src/$(GAME)/%.c | objdir 114 | $(call compile_cc,$(GAME_CFLAGS)) 115 | 116 | -------------------------------------------------------------------------------- /fpbuild/Makefile: -------------------------------------------------------------------------------- 1 | GAME = duke3d 2 | NAME = fp$(GAME) 3 | OBJDIR = obj$(CHIP)_$(GAME) 4 | GAMESRC = jf$(GAME)/src 5 | ENGINEROOT = jfbuild 6 | MACTROOT = jfmact 7 | AUDIOLIBROOT = jfaudiolib 8 | USE_ASM = $(if $(PCTEST),0,1) 9 | NO_FLOAT = 1 10 | 11 | ifeq ($(GAME), duke3d) 12 | GAME_SRCS = \ 13 | game actors gamedef global menues \ 14 | player premap sector config \ 15 | osdfuncs osdcmds grpscan sounds \ 16 | version 17 | else ifeq ($(GAME), sw) 18 | GAME_SRCS = \ 19 | actor ai anim border break bunny \ 20 | cache cheats colormap config console \ 21 | coolg coolie copysect demo draw eel \ 22 | game girlninj goro grpscan hornet \ 23 | interp interpsh inv jplayer jsector \ 24 | jweapon lava light mclip menus miscactr \ 25 | morph net ninja osdcmds osdfuncs panel \ 26 | player predict quake ripper ripper2 rooms \ 27 | rotator save scrip2 sector serp \ 28 | setup skel skull slidor sounds spike \ 29 | sprite sumo swconfig sync text track \ 30 | vator vis wallmove warp weapon zilla \ 31 | zombie saveable version 32 | else ifeq ($(GAME), blood) 33 | GAMESRC = NBlood/source/blood/src 34 | GAME_SRCS = \ 35 | actor ai aibat aibeast aiboneel aiburn \ 36 | aicaleb aicerber aicult aigarg aighost \ 37 | aigilbst aihand aihound aiinnoc aipod \ 38 | airat aispid aitchern aizomba aizombf \ 39 | blood callback choke common config \ 40 | db demo dude endgame eventq fire fx \ 41 | gamemenu getopt gfx gib globals gui \ 42 | inifile iob levels loadsave map2d \ 43 | messages misc network player qav qheap \ 44 | sectorfx seq sound trig triggers \ 45 | warp weapon controls credits gameutil \ 46 | menu mirrors osdcmd replace resource \ 47 | tile view screen compat version 48 | else 49 | $(error unknown GAME) 50 | endif 51 | 52 | BUILD_SRCS = \ 53 | asmprot baselayer cache1d \ 54 | compat crc32 defs engine \ 55 | mmulti_null osd pragmas scriptfile \ 56 | textfont talltextfont smalltextfont \ 57 | version 58 | 59 | MACT_SRCS = \ 60 | util_lib file_lib control keyboard \ 61 | mouse mathutil scriplib animlib 62 | 63 | APP_SRCS = fp_layer 64 | ifneq ($(PCTEST), 1) 65 | APP_SRCS += unistd 66 | endif 67 | ifeq ($(USE_ASM), 0) 68 | BUILD_SRCS += a-c 69 | else 70 | APP_SRCS += buildasm a-new 71 | endif 72 | 73 | APP_OBJS1 = $(APP_SRCS:%=$(OBJDIR)/app/%.o) 74 | APP_OBJS2 = $(GAME_SRCS:%=$(OBJDIR)/game/%.o) 75 | APP_OBJS2 += $(BUILD_SRCS:%=$(OBJDIR)/jfbuild/%.o) 76 | APP_OBJS2 += $(MACT_SRCS:%=$(OBJDIR)/jfmact/%.o) 77 | 78 | include ../buildinc.make 79 | 80 | ifeq ($(GAME), blood) 81 | SYS_CFLAGS += -DCXX_SUPPORT 82 | endif 83 | 84 | CXXFLAGS := $(CFLAGS) -std=c++14 -fno-exceptions -fno-rtti -Wno-narrowing 85 | 86 | GAME_CFLAGS := $(APP_CFLAGS) -DNO_SOUND=1 -DNO_MOUSE=1 -DNO_NET=1 -DNO_OSD=1 87 | ifneq ($(USE_ASM), 0) 88 | GAME_CFLAGS += -DUSE_ASM 89 | endif 90 | ifneq ($(NO_FLOAT), 0) 91 | GAME_CFLAGS += -DNO_FLOAT=1 -I$(OBJDIR) 92 | endif 93 | GAME_CFLAGS += -DMAXXDIM=480 -DMAXYDIM=320 94 | GAME_CFLAGS += -DNO_NEWSTYLE=1 95 | # saves 256KB (slower voxels) 96 | GAME_CFLAGS += -DNO_DISTRECIP=1 97 | ifeq ($(GAME), duke3d) 98 | GAME_CFLAGS += -DGAME_DUKE3D 99 | # MAXYDIM >= 640 for ROTSCR 100 | GAME_CFLAGS += -DNO_ROTSCR=1 101 | # names=4944+5 102 | GAME_CFLAGS += -DMAXTILES=5120 -DMAXCACHEOBJECTS=MAXTILES 103 | # numwalls=5471 (E2L8), numsprites=1278 (E4L11) 104 | GAME_CFLAGS += -DMAXWALLS=6144 -DMAXSPRITES=2048 105 | # duke3d doesn't use voxels 106 | GAME_CFLAGS += -DNO_VOXELS=1 107 | else ifeq ($(GAME), sw) 108 | GAME_CFLAGS += -DGAME_SW 109 | GAME_CFLAGS += -DMAXTILES=6144 -DMAXCACHEOBJECTS=MAXTILES 110 | # numwalls=7492 (wanton:$shore), numsprites=1961 ($yamato) 111 | GAME_CFLAGS += -DMAXSPRITES=2048 112 | GAME_CFLAGS += -DNO_CONSOLE=1 113 | # saves 162KB 114 | GAME_CFLAGS += -DMAXWALLSB=2048 -DMAXSPRITESONSCREEN=1024 115 | else ifeq ($(GAME), blood) 116 | GAME_CFLAGS += -DGAME_BLOOD 117 | GAME_CFLAGS += -DMAXTILES=6144 -DMAXCACHEOBJECTS=MAXTILES 118 | # numwalls=8002 (cp09), numsprites=1200 (cp09) 119 | GAME_CFLAGS += -DMAXSPRITES=2048 120 | GAME_CFLAGS += -DMAXWALLSB=2048 -DMAXSPRITESONSCREEN=1024 121 | GAME_CFLAGS += -DNETCODE_DISABLE -DSMACKER_DISABLE 122 | GAME_CFLAGS += -D__AMIGA__ -U__ANDROID__ 123 | CXXFLAGS += -Wno-char-subscripts -Wno-missing-braces 124 | endif 125 | GAME_CFLAGS += -I$(GAMESRC) -I$(ENGINEROOT)/include -I$(MACTROOT) -I$(AUDIOLIBROOT)/include 126 | GAME_CFLAGS += -Wno-unused -Wno-unused-parameter 127 | GAME_CFLAGS += -Wno-strict-prototypes 128 | GAME_CXXFLAGS := $(GAME_CFLAGS) 129 | GAME_CFLAGS += -std=c99 -pedantic 130 | APP_CFLAGS := -I$(ENGINEROOT)/src -I$(SYSDIR) $(GAME_CFLAGS) 131 | 132 | ifneq ($(NO_FLOAT), 0) 133 | $(OBJDIR)/jfbuild/engine.o: $(OBJDIR)/engine_tables.h 134 | 135 | $(OBJDIR)/calctables: calctables.c | $(OBJDIR) 136 | $(HOSTCC) -O2 $< -o $@ -lm 137 | 138 | $(OBJDIR)/engine_tables.h: $(OBJDIR)/calctables 139 | $(OBJDIR)/calctables $@ 140 | endif 141 | 142 | $(OBJDIR)/game/%.o: $(GAMESRC)/%.c | objdir 143 | $(call compile_cc,$(GAME_CFLAGS)) 144 | 145 | $(OBJDIR)/game/%.o: $(GAMESRC)/%.cpp | objdir 146 | $(call compile_cxx,$(GAME_CXXFLAGS)) 147 | 148 | # code from a-c.c is important for performance 149 | $(OBJDIR)/jfbuild/a-c.o: CFLAGS := $(filter-out -mthumb,$(CFLAGS)) -O2 150 | 151 | $(OBJDIR)/jfbuild/%.o: $(ENGINEROOT)/src/%.c | objdir 152 | $(call compile_cc,$(GAME_CFLAGS)) 153 | 154 | $(OBJDIR)/jfmact/%.o: $(MACTROOT)/%.c | objdir 155 | $(call compile_cc,$(GAME_CFLAGS)) 156 | 157 | -------------------------------------------------------------------------------- /fpdoom/init_sc6531e.h: -------------------------------------------------------------------------------- 1 | static int sc6531e_smc_get_id(uint32_t base, uint32_t ps) { 2 | uint32_t a; 3 | 4 | MEM4(base + 0x88) = 3; 5 | MEM4(base + 0x8c) &= ~1; 6 | MEM4(base + 0x8c) |= 1; 7 | DELAY(1000) 8 | MEM4(base + 0x84) &= ~1; 9 | a = *(volatile uint8_t*)(ps + 1) & 0x1f; 10 | DELAY(100) 11 | MEM4(base + 0x84) |= 1; 12 | return a; 13 | } 14 | 15 | static void sc6531e_smc_save_id(uint32_t base, uint32_t ps, uint32_t id) { 16 | uint32_t a, b; 17 | 18 | MEM4(0x20500168) = 0; 19 | MEM4(base + 0x84) &= ~1; 20 | a = *(volatile uint8_t*)(ps + 1) & 0x20; 21 | DELAY(100) 22 | b = *(volatile uint8_t*)(ps + 2) & 7; 23 | DELAY(100) 24 | MEM4(base + 0x84) |= 1; 25 | MEM4(0x20500168) = id << 8 | a >> 2 | b; 26 | } 27 | 28 | #define sc6531e_smc_config_t smc_config_t 29 | 30 | typedef struct { 31 | uint32_t x04_18, x20_24, x45_48, x58_68; 32 | uint8_t x28, x2c, x30, x34, x38, x3c, x40; 33 | uint8_t x1c, x44, x4c, x50_54, x6c; 34 | } smc_config_t; 35 | 36 | #define SMC_CONFIG(x00, x04, x08, x0c, \ 37 | x10, x14, x18, x1c, x20, x24, x28, x2c, x30, x34, x38, x3c, \ 38 | x40, x44, x45, x46, x47, x48, x4c, \ 39 | x50, x54, x58, x5c, x60, x64, x68, x6c) { \ 40 | x04 << 28 | x08 << 24 | x0c << 20 | x10 << 16 | x14 << 11 | x18 << 6, \ 41 | x20 << 12 | x24, \ 42 | x45 << 20 | x47 << 11 | x47 << 7 | x46 << 8 | x46 << 4 | x48 << 2 | x48, \ 43 | x58 << 16 | x5c << 14 | x60 << 8 | x64 << 6 | x68, \ 44 | x28, x2c, x30, x34, x38, x3c, x40, \ 45 | x1c, x44, x4c, x50 << 2 | x54, x6c \ 46 | } 47 | 48 | // SRAM memory controller 49 | static void sc6531e_init_smc() { 50 | uint32_t id, a; 51 | 52 | const smc_config_t *conf; 53 | static const smc_config_t conf_06 = SMC_CONFIG( 54 | /* 0x00 */ 6, 5, 5, 5, /* 0x10 */ 5, 5, 2, 1, 55 | /* 0x20 */ 0, 0, 0, 0, /* 0x30 */ 0x50, 0x50, 0x50, 0, 56 | /* 0x40 */ 0, 2,4,7,1, 3, 0, /* 0x50 */ 5, 2, 6, 1, 57 | /* 0x60 */ 3, 1, 0x10, 0x34); 58 | static const smc_config_t conf_0d = SMC_CONFIG( 59 | /* 0x00 */ 13, 3, 3, 3, /* 0x10 */ 5, 4, 3, 1, 60 | /* 0x20 */ 0, 0, 0, 0, /* 0x30 */ 0x50, 0x50, 0x50, 0, 61 | /* 0x40 */ 0, 2,4,7,1, 3, 0, /* 0x50 */ 7, 1, 5, 1, 62 | /* 0x60 */ 3, 1, 0xA, 0x12); 63 | 64 | uint32_t base = 0x20000000; 65 | uint32_t ps; 66 | 67 | MEM4(base + 0x00) = 0x3333a0c0; 68 | MEM4(base + 0x04) = 7; 69 | MEM4(base + 0x20) = 15; 70 | MEM4(base + 0x24) = 15; 71 | MEM4(base + 0x28) = 15; 72 | MEM4(base + 0x2c) = 10; 73 | MEM4(base + 0x30) = 10; 74 | MEM4(base + 0x34) = 10; 75 | MEM4(base + 0x38) = 10; 76 | MEM4(base + 0x50) = 0x0acc177f; 77 | MEM4(base + 0x5c) = 0x1d000000; 78 | 79 | MEM4(base + 0x94) = 0x5434a; 80 | MEM4(base + 0x00) |= 0x100; 81 | MEM4(base + 0x00) &= ~0x100; 82 | DELAY(100) 83 | 84 | ps = MEM_REMAP << 28 | 0x04000000; 85 | 86 | id = sc6531e_smc_get_id(base, ps); 87 | if (id == 6) { 88 | MEM4(base + 0xa0) = 0x5a5a; 89 | MEM4(base + 0x80) |= 1; 90 | conf = &conf_06; 91 | } else if (id == 13) { 92 | MEM4(base + 0xa0) = 0x5a5a; 93 | MEM4(base + 0x80) &= ~1; 94 | conf = &conf_0d; 95 | } else for (;;); 96 | sc6531e_smc_save_id(base, ps, id); 97 | 98 | a = MEM4(base + 0x00) & ~0x333378c0; 99 | MEM4(base + 0x00) = a | conf->x04_18; 100 | MEM4(base + 0x20) &= ~0x7f; 101 | MEM4(base + 0x24) &= ~0x7f; 102 | MEM4(base + 0x28) &= ~0x7f; 103 | MEM4(base + 0x2c) &= ~0x7f; 104 | MEM4(base + 0x30) &= ~0x7f; 105 | MEM4(base + 0x34) &= ~0x7f; 106 | MEM4(base + 0x38) &= ~0x7f; 107 | 108 | MEM4(base + 0x20) |= conf->x28; 109 | MEM4(base + 0x24) |= conf->x2c; 110 | MEM4(base + 0x28) |= conf->x30; 111 | MEM4(base + 0x2c) |= conf->x34; 112 | MEM4(base + 0x30) |= conf->x38; 113 | MEM4(base + 0x34) |= conf->x3c; 114 | MEM4(base + 0x38) |= conf->x40; 115 | 116 | if (conf->x1c) { 117 | a = MEM4(base + 0x08) & ~0xf4ff; 118 | MEM4(base + 0x08) = a | conf->x20_24; 119 | MEM4(base + 0x28) |= 0x100; 120 | MEM4(base + 0x2c) |= 0x100; 121 | MEM4(base + 0x30) |= 0x100; 122 | MEM4(base + 0x08) |= 0x480; 123 | } 124 | 125 | if (conf->x44 == 2) 126 | MEM4(base + 0x50) |= 0x2800000; 127 | a = MEM4(base + 0x50) & ~0x700fff; 128 | MEM4(base + 0x50) = a | conf->x45_48; 129 | MEM4(base + 0x50) |= 0x80c0000; 130 | a = MEM4(base + 0x54) & ~0x3000000; 131 | MEM4(base + 0x54) = a | conf->x4c << 24; 132 | a = MEM4(base + 0x5c) & ~0x1f000000; 133 | MEM4(base + 0x5c) = a | conf->x50_54 << 24; 134 | a = MEM4(base + 0x94) & ~0x1fffff; 135 | MEM4(base + 0x94) = a | conf->x58_68; 136 | 137 | MEM4(base + 0x84) &= ~1; 138 | *(volatile uint8_t*)ps = conf->x6c; 139 | DELAY(100) 140 | MEM4(base + 0x84) |= 1; 141 | } 142 | #undef SMC_CONFIG 143 | #undef smc_config_t 144 | 145 | static void sc6531e_init_freq() { 146 | uint32_t a; 147 | // CPU freq 148 | a = MEM4(0x8b00004c); 149 | MEM4(0x8b00004c) = a &= ~4; 150 | MEM4(0x8b00004c) = a | 3; // 208 MHz 151 | DELAY(100) 152 | MEM4(0x8d20002c) = (MEM4(0x8d20002c) & ~7) | 2; 153 | MEM4(0x8d200030) = (MEM4(0x8d200030) & ~(3 << 8)) | (1 << 8); 154 | DELAY(100) 155 | } 156 | 157 | static void sc6531e_init_adi() { 158 | MEM4(0x8b0010a8) = 1 << 24; // ADI enable 159 | // ADI reset 160 | MEM4(0x8b001068) = 1 << 19; 161 | DELAY(100) 162 | MEM4(0x8b002068) = 1 << 19; 163 | // init analog 164 | MEM4(0x82000010) &= ~(1 << 30); 165 | MEM4(0x82000000) = 0; 166 | } 167 | 168 | static void init_sc6531e(void) { 169 | sc6531e_init_freq(); 170 | sc6531e_init_smc(); 171 | sc6531e_init_adi(); 172 | } 173 | 174 | -------------------------------------------------------------------------------- /fpdoom/init_sc6531da.h: -------------------------------------------------------------------------------- 1 | #define get_freq_2() (312000000 >> 1) 2 | 3 | #ifdef SMC_INIT_BUF 4 | extern int sc6531da_init_smc_asm[1]; 5 | extern int sc6531da_init_smc_asm_end[1]; 6 | #else 7 | static inline void sc6531da_init_smc_1(uint32_t base) { 8 | MEM4(base + 0x00) = 0x11110000; 9 | MEM4(base + 0x20) = 0; 10 | MEM4(base + 0x24) = 0; 11 | MEM4(base + 0x04) = 0x10; 12 | MEM4(base + 0x50) = 0x00904ff0; 13 | MEM4(base + 0x54) = 0x0151ffff; 14 | MEM4(base + 0x58) = 0x00a0744f; 15 | MEM4(base + 0x5c) = 0; 16 | } 17 | #endif 18 | 19 | static void sc6531da_init_smc(void) { 20 | uint32_t base = 0x20000000, a, ps; 21 | int conf0 = 0, conf1 = 3, conf2 = 0, conf3 = 1; 22 | int conf4 = 7, conf5 = 2, conf6 = 2; 23 | uint32_t freq = get_freq_2(); 24 | 25 | uint32_t freq2, div = 0, freq_div, ps_off1, ps_off2; 26 | uint32_t smc00 = 0, smc04 = 0, smc08 = 0, smc20 = 0, smc24 = 0; 27 | uint32_t smc50 = 0, smc54 = 0, smc58, smc5c = 0; 28 | 29 | freq2 = freq < 133000000 ? 3 : freq < 156000000 ? 4 : 5; 30 | ps_off1 = freq2 << 11; 31 | 32 | smc54 = (smc54 & (0xf << 20)) | (5 << 20); 33 | smc00 &= 0xffff800c; 34 | 35 | if (conf1 == 0) { 36 | smc54 |= 0xf00; 37 | smc54 = (smc54 & (0xf << 16)) | (1 << 16); 38 | smc54 &= ~(3 << 24); smc54 |= 1 << 24; 39 | smc54 &= ~(0xf << 12); smc54 |= 1 << 12; 40 | smc54 &= ~(0xf << 4); smc54 |= 1 << 4; 41 | 42 | smc58 = 0xa0744f; 43 | smc20 &= ~0x80; 44 | smc24 &= ~0x80; 45 | smc50 &= ~0x1000; 46 | ps_off1 |= 0x400; 47 | smc50 |= 0x4000; 48 | } else { 49 | smc00 |= 0x11e0; 50 | smc20 |= 0x80; 51 | smc24 |= 0x80; 52 | if (conf6 == 1) { 53 | smc54 &= ~0xf00; 54 | smc54 |= (freq2 + 2) << 9; 55 | smc54 &= ~0x3000000; smc54 |= 0x2000000; 56 | smc54 &= ~0xf000; smc54 |= 0x2000; 57 | smc54 &= ~0xf0; smc54 |= 0x20; 58 | 59 | smc58 = 0xa0202a; 60 | smc00 |= 0x10; 61 | } else if (conf6 == 2) { 62 | smc54 &= ~0xf00; 63 | smc54 |= (freq2 + 2) << 8; 64 | smc54 &= ~0x3000000; smc54 |= 0x1000000; 65 | smc54 &= ~0xf000; smc54 |= 0x1000; 66 | smc54 &= ~0xf0; smc54 |= 0x10; 67 | smc58 = 0x501015; 68 | 69 | smc00 &= ~0x20; 70 | smc54 &= ~0x500000; 71 | smc04 &= ~0xf; smc04 |= 7; 72 | smc20 &= ~0x80; 73 | smc24 &= ~0x80; 74 | } else { 75 | smc54 &= ~0xf00; 76 | smc54 |= (freq2 + 2) << 8; 77 | smc54 &= ~0x3000000; smc54 |= 0x1000000; 78 | smc54 &= ~0xf000; smc54 |= 0x1000; 79 | smc54 &= ~0xf0; smc54 |= 0x10; 80 | smc58 = 0x501015; 81 | } 82 | smc54 &= ~0xf0000; smc54 |= 0x20000; 83 | smc50 |= 0x1000; 84 | } 85 | 86 | if (conf0 == 1) { 87 | smc50 |= 0x8000000; 88 | smc08 |= 0x200; 89 | smc08 &= ~0xf000; 90 | smc08 |= 0x3580; 91 | smc00 |= 0x8000; 92 | 93 | smc54 &= ~0x3000000; smc54 |= 0x2000000; 94 | smc54 &= ~0xf00; 95 | smc54 |= (freq2 + 1) << 8; 96 | smc5c = 0xed000000; 97 | // unknown |= 0x80; 98 | div = 1; 99 | } 100 | 101 | freq_div = div ? freq / (7812500 / div) : 0; 102 | smc54 |= 0xf; 103 | 104 | smc00 |= 0x22220000; 105 | ps_off1 |= 0x80000; 106 | ps_off1 |= (conf1 == 0) << 15; 107 | ps_off1 |= conf2 << 14; 108 | ps_off1 |= conf0 << 9; 109 | ps_off1 |= conf3 << 3; 110 | ps_off1 |= conf4; 111 | ps_off1 |= 0x110; 112 | ps_off2 = 0x10; 113 | 114 | smc50 &= ~0x00700fff; 115 | smc50 |= conf5 << 20; // 3 116 | smc50 |= conf3 << 11 | conf4 << 8; // 1, 3 117 | smc50 |= conf3 << 7 | conf4 << 4; // 1, 3 118 | smc50 |= conf1 << 2 | conf1; // 2, 2 119 | smc50 |= 0x8c0000; 120 | smc04 |= 0x10; 121 | 122 | // must be run from on-chip RAM 123 | #ifdef SMC_INIT_BUF 124 | (void)a; (void)ps; (void)base; 125 | { 126 | int *p = sc6531da_init_smc_asm; 127 | int n = sc6531da_init_smc_asm_end - p; 128 | int *d = (int*)SMC_INIT_BUF, *f = d; 129 | do *d++ = *p++; while (--n); 130 | d[0] = ps_off1 << 1; d[1] = ps_off2 << 1; 131 | d[2] = freq_div | conf0 << 8; 132 | d[3] = smc08; d[4] = smc00; d[5] = smc20; 133 | d[6] = smc24; d[7] = smc04; 134 | d[8] = smc50; d[9] = smc54; d[10] = smc58; d[11] = smc5c; 135 | ((void(*)(void))(intptr_t)f)(); 136 | } 137 | #else 138 | sc6531da_init_smc_1(base); 139 | 140 | ps = MEM_REMAP; 141 | ps = ps << 29 | ps << 28 | 0x04000000; 142 | 143 | MEM4(base + 0x50) |= 0x20000; 144 | MEM2(ps + (ps_off1 << 1)) = 0; 145 | DELAY(10) 146 | MEM2(ps + (ps_off2 << 1)) = 0; 147 | DELAY(10) 148 | MEM4(base + 0x50) &= ~0x20000; 149 | DELAY(10) 150 | 151 | a = freq_div | conf0 << 8; 152 | MEM4(base + 0x24) |= a; 153 | MEM4(base + 0x28) |= a; 154 | MEM4(base + 0x2c) |= a; 155 | MEM4(base + 0x30) |= a; 156 | MEM4(base + 0x34) |= a; 157 | MEM4(base + 0x38) |= a; 158 | 159 | MEM4(base + 0x08) = smc08; 160 | MEM4(base + 0x08) &= ~0x100; 161 | MEM4(base + 0x00) = smc00; 162 | MEM4(base + 0x20) |= smc20; 163 | MEM4(base + 0x24) |= smc24; 164 | MEM4(base + 0x04) = smc04; 165 | 166 | MEM4(base + 0x50) = smc50; 167 | MEM4(base + 0x54) = smc54; 168 | MEM4(base + 0x58) = smc58; 169 | MEM4(base + 0x5c) = smc5c; 170 | MEM4(base + 0x00) &= ~0x100; 171 | DELAY(100) 172 | #endif 173 | } 174 | #undef get_freq_2 175 | 176 | static void sc6531da_init_freq(void) { 177 | uint32_t a; 178 | // CPU freq 179 | a = MEM4(0x8b00004c) | 4; 180 | if (MEM4(0x205003fc) == 0x65310001) a &= ~4; 181 | MEM4(0x8b00004c) = a; 182 | MEM4(0x8b00004c) = a | 3; // 312 MHz 183 | DELAY(100) 184 | MEM4(0x8b000044) = (MEM4(0x8b000044) & ~(3 << 19)) | 1 << 19; 185 | DELAY(100) 186 | } 187 | 188 | static void sc6531da_init_adi(void) { 189 | MEM4(0x8b0000a0) = 1 << 24; // ADI enable 190 | // ADI reset 191 | MEM4(0x8b000060) = 1 << 19; 192 | DELAY(100) 193 | MEM4(0x8b000064) = 1 << 19; 194 | // init analog 195 | MEM4(0x82000000) &= ~(1 << 4); 196 | MEM4(0x82000004) = 0x55000; 197 | } 198 | 199 | static void init_sc6531da(void) { 200 | sc6531da_init_freq(); 201 | sc6531da_init_smc(); 202 | sc6531da_init_adi(); 203 | } 204 | 205 | -------------------------------------------------------------------------------- /sdboot/entry.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "cmd_def.h" 3 | #include "usbio.h" 4 | #include "syscode.h" 5 | 6 | #if LIBC_SDIO >= 3 7 | #define MEM_REMAP (MEM4(0x205000e0) & 1) 8 | #else 9 | #define MEM_REMAP 0 10 | #endif 11 | #include "init_sc6531e.h" 12 | #include "init_sc6531da.h" 13 | #include "init_sc6530.h" 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | void _debug_msg(const char *msg); 20 | void _malloc_init(void *addr, size_t size); 21 | void _stdio_init(void); 22 | 23 | int sdmain(uint8_t *ram); 24 | 25 | /* dcache must be disabled for this function */ 26 | static uint32_t get_ram_size(uint32_t addr) { 27 | uint32_t size = 1 << 20; /* start from 2MB */ 28 | uint32_t v1 = 0x12345678; 29 | do { 30 | if (size >> 27) break; 31 | size <<= 1; 32 | MEM4(addr + size) = v1; 33 | MEM4(addr) = size; 34 | } while (MEM4(addr + size) == v1); 35 | return size; 36 | } 37 | 38 | extern char __bss_start[]; 39 | extern uint32_t _start[]; 40 | #if defined(SDBOOTKEY) && SDBOOTKEY < 0 41 | extern uint32_t sdbootkey; 42 | #undef SDBOOTKEY 43 | #define SDBOOTKEY sdbootkey 44 | #endif 45 | 46 | static int read_key(int chip) { 47 | keypad_base_t *kpd = KEYPAD_BASE; 48 | uint32_t tmp, add, rst, mask = 0; 49 | int ret; 50 | #ifdef SDBOOTKEY 51 | { 52 | uint32_t key = SDBOOTKEY; 53 | uint32_t col = key & 7, row = key >> 4, mask1; 54 | uint32_t a = 0x2c, e1 = 0x208a, e2 = 0x2001; // SC6531E 55 | mask1 = 1 << (row + 16); 56 | if (chip != 1) { 57 | a = 0x180; e1 = 0x18a; e2 = 0x101; // SC6530 58 | if (row >= 7) goto badkey; row += 8; 59 | if (chip == 2) a += 0x20, e1 = 0x60a, e2 = 0x401; // SC6531 60 | } else { 61 | if (col >= 5 || row >= 5) goto badkey; 62 | row += 5; 63 | } 64 | a += 0x8c000000; 65 | MEM4(a + col * 4) = e1; 66 | MEM4(a + row * 4) = e2; 67 | mask = 1 << (col + 8) | mask1; 68 | } 69 | badkey: 70 | #endif 71 | tmp = 0x8b0010a8; add = 0x1000; 72 | if (chip != 1) 73 | tmp = 0x8b0000a0, add = 4; 74 | MEM4(tmp) = 0x80040; // keypad power on 75 | rst = tmp + 0x60 - 0xa0; 76 | // reset 77 | MEM4(rst) = 1; 78 | DELAY(10) 79 | MEM4(rst + add) = 1; 80 | tmp += add; // power off 81 | 82 | kpd->int_clr = 0xfff; 83 | kpd->polarity = 0xffff; 84 | kpd->clk_divide = 0; 85 | kpd->debounce = 15; 86 | kpd->ctrl |= 1 | mask; // keypad enable 87 | sys_wait_ms(20); 88 | #if LIBC_SDIO >= 3 89 | ret = 0; 90 | #else 91 | ret = 0x100; 92 | #endif 93 | if (kpd->int_raw & 1) { 94 | ret = kpd->key_status & 0x77; 95 | #ifdef SDBOOTKEY 96 | { 97 | int key = SDBOOTKEY; 98 | if (key != -1) ret = ret == key; 99 | } 100 | #endif 101 | } 102 | kpd->int_clr = 0xfff; 103 | MEM4(tmp) = 0x40; // keypad power off 104 | return ret; 105 | } 106 | 107 | void entry_main(uint32_t load_addr) { 108 | uint32_t fw_addr, ram_addr, ram_size; 109 | int chip, key; 110 | 111 | #if CHIP 112 | chip = CHIP; 113 | #else 114 | { 115 | uint32_t tmp = MEM4(0x205003fc) - 0x65300000; 116 | chip = 1; 117 | if (!(tmp >> 17)) 118 | chip = (int32_t)(tmp << 15) < 0 ? 2 : 3; 119 | } 120 | #endif 121 | 122 | #if LIBC_SDIO < 3 123 | sys_wait_ms(1000); 124 | #endif 125 | key = read_key(chip); 126 | #if LIBC_SDIO >= 3 127 | key |= load_addr >> 30; // boot from CHIPRAM 128 | if (!key) goto end; 129 | #endif 130 | 131 | if (chip == 1) init_sc6531e(); 132 | if (chip == 2) init_sc6531da(); 133 | if (chip == 3) init_sc6530(); 134 | 135 | fw_addr = load_addr & 0xf0000000; 136 | if (fw_addr >> 30) // if run from CHIPRAM 137 | fw_addr = (chip == 1 ? 1 : 3) << 28; 138 | 139 | #if LIBC_SDIO < 3 140 | memset(__bss_start, 0, 0x4000); 141 | #endif 142 | #if !CHIP 143 | _chip = chip; 144 | #endif 145 | 146 | #if LIBC_SDIO < 3 147 | { 148 | static const uint8_t fdl_ack[8] = { 149 | 0x7e, 0, 0x80, 0, 0, 0xff, 0x7f, 0x7e }; 150 | static const struct { 151 | uint8_t hdr[5], str[0x22], end[5]; 152 | } fdl_ver = { 153 | { 0x7e, 0,0x81, 0,0x22 }, 154 | { "Spreadtrum Boot Block version 1.2" }, 155 | { 0xa9,0xe9, 0x7e } 156 | }; 157 | uint8_t buf[8]; 158 | usb_init(); 159 | usb_write(&fdl_ver, sizeof(fdl_ver)); 160 | usb_read(buf, 8, USB_WAIT); 161 | usb_write(fdl_ack, sizeof(fdl_ack)); 162 | } 163 | { 164 | char buf[4]; uint32_t t0, t1; 165 | for (;;) { 166 | usb_read(buf, 1, USB_WAIT); 167 | if (buf[0] == HOST_CONNECT) break; 168 | } 169 | t0 = sys_timer_ms(); 170 | do { 171 | t1 = sys_timer_ms(); 172 | if (usb_read(buf, 4, 0)) t0 = t1; 173 | } while (t1 - t0 < 10); 174 | } 175 | _debug_msg("sdboot"); 176 | #endif 177 | 178 | ram_addr = fw_addr + 0x04000000; 179 | { 180 | /* extra loader on Samsung B310E checks this value */ 181 | uint32_t old = MEM4(ram_addr); 182 | ram_size = get_ram_size(ram_addr); 183 | MEM4(ram_addr) = old; 184 | } 185 | #if INIT_MMU 186 | { 187 | volatile uint32_t *tab = (volatile uint32_t*)(ram_addr + ram_size - 0x4000); 188 | unsigned i; 189 | for (i = 0; i < 0x1000; i++) 190 | tab[i] = i << 20 | 3 << 10 | 0x12; // section descriptor 191 | // cached=1, buffered=1 192 | tab[CHIPRAM_ADDR >> 20] |= 3 << 2; 193 | for (i = 0; i < (ram_size >> 20); i++) 194 | tab[ram_addr >> 20 | i] |= 3 << 2; 195 | tab[load_addr >> 20] |= 3 << 2; 196 | enable_mmu((uint32_t*)tab, -1); 197 | } 198 | #endif 199 | #if LIBC_SDIO < 3 200 | #if INIT_MMU 201 | ram_size -= 0x4000; // MMU table 202 | #endif 203 | { 204 | uint32_t offs = ram_size - 0x20000; // 128KB 205 | char *addr = (void*)(ram_addr + offs); 206 | uint32_t size = ram_size - offs; 207 | _malloc_init(addr, size); 208 | _stdio_init(); 209 | printf("malloc heap: %u bytes\n", size); 210 | } 211 | printf("key = 0x%02x\n", key); 212 | #endif 213 | sdmain((uint8_t*)ram_addr); 214 | end: 215 | { 216 | uint32_t old = _start[1]; 217 | if (~old) ((void(*)(void))old)(); 218 | } 219 | for (;;); 220 | } 221 | 222 | -------------------------------------------------------------------------------- /fpmenu/readconf.h: -------------------------------------------------------------------------------- 1 | 2 | typedef struct { 3 | int argc, skip; char *end; 4 | } extract_args_t; 5 | 6 | static char* get_first_arg1(int depth, char *s) { 7 | int a, n; char *ret; 8 | n = *(uint8_t*)(s + 1) << 8 | *(uint8_t*)s; 9 | //printf("argc = %d\n", n); 10 | s += 2; 11 | for (; n; n--) { 12 | if (*s != 1) return s; 13 | a = *(uint8_t*)&s[1]; 14 | a |= *(uint8_t*)&s[2] << 8; 15 | a |= *(uint8_t*)&s[3] << 16; 16 | //printf("var: 0x%x, %p\n", a, s - a); 17 | if (depth >= 10) return (char*)~(uintptr_t)0; 18 | ret = get_first_arg1(depth + 1, s - a); 19 | if (ret) return ret; 20 | s += 4; 21 | } 22 | return NULL; 23 | } 24 | 25 | static inline char* get_first_arg(char *s) { 26 | s = get_first_arg1(0, s); 27 | if (!~(uintptr_t)s) s = NULL; 28 | return s; 29 | } 30 | 31 | static char* extract_args(int depth, extract_args_t *x, char *s, char *d) { 32 | int a, n; 33 | n = *(uint8_t*)(s + 1) << 8 | *(uint8_t*)s; 34 | //printf("argc = %d\n", n); 35 | s += 2; 36 | for (; n; n--) 37 | if (*s != 1) { 38 | int skip = x->skip; 39 | if (skip) { 40 | x->skip = skip - 1; 41 | while (*s++); 42 | } else { 43 | char *e = x->end; 44 | //printf("str: \"%s\"\n", s); 45 | do { 46 | a = *s++; 47 | if (d == e) return NULL; 48 | *d++ = a; 49 | } while (a); 50 | x->argc++; 51 | } 52 | } else { 53 | a = *(uint8_t*)&s[1]; 54 | a |= *(uint8_t*)&s[2] << 8; 55 | a |= *(uint8_t*)&s[3] << 16; 56 | //printf("var: 0x%x, %p\n", a, s - a); 57 | if (depth >= 10) return NULL; 58 | d = extract_args(depth + 1, x, s - a, d); 59 | if (!d) return d; 60 | s += 4; 61 | } 62 | return d; 63 | } 64 | 65 | static char* find_var(const char *s, char *vars) { 66 | unsigned a, i; 67 | do { 68 | char *p = vars + 4; 69 | //printf("enum: %s\n", p); 70 | i = 0; do { 71 | if ((a = p[i]) != (unsigned)s[i]) goto skip; 72 | i++; 73 | } while (a); 74 | //printf("found: %p\n", p + i); 75 | return p + i; 76 | skip: 77 | vars -= a = *(uint32_t*)vars; 78 | } while (a); 79 | return NULL; 80 | } 81 | 82 | static char* parse_var(char *d, char *e, char *vars, char *old) { 83 | if (e - d < 4) return NULL; 84 | //printf("var: %s\n", d); 85 | vars = find_var(d + 1, vars); 86 | if (vars) { 87 | uint32_t a = d - vars; 88 | *d = 1; d[1] = a; 89 | d[2] = a >> 8; 90 | d[3] = a >> 16; 91 | return d + 4; 92 | } 93 | return old; 94 | } 95 | 96 | static int read_args(FILE *fi, char **rd, char *e, char *vars) { 97 | int argc = 0, j, q = 0; 98 | char *d = *rd, *var = NULL; 99 | if (e - d < 2) return -1; 100 | d += 2; 101 | loop: 102 | if (var && !(d = parse_var(var, e, vars, d))) return -1; 103 | j = 1; var = NULL; 104 | for (;;) { 105 | int a = fgetc(fi); 106 | if (a == '#') { 107 | do { 108 | a = fgetc(fi); 109 | if (a == EOF) goto end; 110 | } while (a != '\n'); 111 | if (argc || vars) break; 112 | continue; 113 | } 114 | if (a <= 0x20) { 115 | if (a == '\r') continue; 116 | if (a != ' ' && a != '\t' && a != '\n') return -1; 117 | if (!q) { 118 | if (a == '\n' && (argc || vars)) break; 119 | if (j) continue; 120 | a = 0; 121 | } 122 | } else if (a == '"' || a == '\'') { 123 | if (!q) { q = a; argc += j; j = 0; continue; } 124 | if (q == a) { q = 0; continue; } 125 | } else if (a == '\\' && q != '\'') { 126 | do a = fgetc(fi); while (a == '\r'); 127 | if (a == '\n') continue; 128 | if (a == EOF || a < 0x20) return -1; 129 | } else if (a == '$' && j && vars) var = d; 130 | argc += j; j = 0; 131 | if (d == e) return -1; 132 | *d++ = a; if (!a) goto loop; 133 | } 134 | end: 135 | if (q) return -1; 136 | if (!j) *d++ = 0; 137 | if (var && !(d = parse_var(var, e, vars, d))) return -1; 138 | e = *rd; *rd = d; 139 | e[0] = argc; 140 | e[1] = argc >> 8; 141 | if (argc >> 16) return -1; 142 | //print_args(e); 143 | return argc; 144 | } 145 | 146 | static char* parse_config(FILE *fi, unsigned size) { 147 | char *buf, *end, *p; 148 | char *item, *vars; 149 | 150 | buf = malloc(size); 151 | if (!buf) return NULL; 152 | end = buf + size; 153 | item = buf; p = buf + 8; 154 | 155 | *(uint32_t*)p = 0; 156 | vars = p; p += 4; 157 | *p++ = '@'; *p++ = 0; 158 | if (read_args(fi, &p, end, NULL) < 0) goto err; 159 | 160 | for (;;) { 161 | int a = fgetc(fi), k; 162 | if (a == EOF) break; 163 | if (a == '#') { 164 | do { 165 | a = fgetc(fi); 166 | if (a == EOF) goto end; 167 | } while (a != '\n'); 168 | continue; 169 | } 170 | if (a == ' ' || a == '\t' || a == '\n' || a == '\r') continue; 171 | if (a == '$') { // variable 172 | p = (char*)(((intptr_t)p + 3) & ~3); 173 | if (end - p < 4) goto err; 174 | *(uint32_t*)p = p - vars; 175 | vars = p; p += 4; k = 0; 176 | for (;;) { 177 | if (p == end) goto err; 178 | a = fgetc(fi); 179 | if (a == '=') break; 180 | if (a == ' ' || a == '\t' || a == '\n' || a == '\r') { 181 | k = 1; continue; 182 | } 183 | if (a == EOF || a <= 0x20 || k) goto err; 184 | *p++ = a; 185 | } 186 | *p++ = 0; 187 | if (read_args(fi, &p, end, vars - *(uint32_t*)vars) < 0) goto err; 188 | continue; 189 | } 190 | if (a == '|') { // menu item 191 | p = (char*)(((intptr_t)p + 3) & ~3); 192 | if (end - p < 4) goto err; 193 | *(uint32_t*)item = p - item; 194 | item = p; p += 4; 195 | // name 196 | for (;;) { 197 | if (p == end) goto err; 198 | a = fgetc(fi); 199 | if (a == '|') break; 200 | if (a == EOF || a < 0x20) goto err; 201 | *p++ = a; 202 | } 203 | *p++ = 0; 204 | if (read_args(fi, &p, end, vars) < 0) goto err; 205 | } 206 | } 207 | end: 208 | *(uint32_t*)item = 0; // end of chain 209 | *(uint32_t*)(buf + 4) = vars - buf; 210 | return buf; 211 | err: 212 | fprintf(stderr, "parse_config: error at 0x%x\n", (int)ftell(fi)); 213 | free(buf); 214 | return NULL; 215 | } 216 | -------------------------------------------------------------------------------- /ums9117/lcd_spi.h: -------------------------------------------------------------------------------- 1 | enum { 2 | SPI_TXD = 0 3 | }; 4 | 5 | typedef volatile struct { 6 | uint32_t txd, clkd, ctl0, ctl1; // 0x00 7 | uint32_t ctl2, ctl3, ctl4, ctl5; 8 | uint32_t int_en, int_clr, int_raw, int_mask; // 0x20 9 | uint32_t sts1, sts2, dspwait, sts3; 10 | uint32_t ctl6, sts4, fifo_rst, ctl7; // 0x40 11 | uint32_t sts5, ctl8, ctl9, ctl10; 12 | uint32_t ctl11, ctl12, sts6, sts7; // 0x60 13 | uint32_t sts8, sts9; 14 | } spi_base_t; 15 | 16 | static void spi_set_clkd(spi_base_t *spi, int val) { 17 | spi->clkd = val; 18 | } 19 | 20 | static void spi_set_mode(spi_base_t *spi, int val) { 21 | spi->ctl7 = (spi->ctl7 & ~(7 << 3)) | val << 3; 22 | } 23 | 24 | static void spi_set_chnl_len(spi_base_t *spi, int val) { 25 | val &= 0x1f; 26 | spi->ctl0 = (spi->ctl0 & ~(0x1f << 2)) | val << 2; 27 | } 28 | 29 | static void spi_set_s3w_rd_strt(spi_base_t *spi, int val) { 30 | val &= 0x1f; 31 | spi->ctl2 = (spi->ctl2 & ~0x1f) | val; 32 | } 33 | 34 | static void spi_set_rtx_mode(spi_base_t *spi, int mode) { 35 | // 01 - recieve, 10 - transmit 36 | spi->ctl1 |= mode << 12; 37 | } 38 | 39 | static void spi_set_spi_cd_bit(spi_base_t *spi, int val) { 40 | // 0 - cmd, 1 - data 41 | spi->ctl8 = (spi->ctl8 & ~(1 << 15)) | val << 15; 42 | } 43 | 44 | // cs = 0..3 45 | static void spi_select_cs(spi_base_t *spi, unsigned cs, unsigned state) { 46 | uint32_t tmp = spi->ctl0 | 1 << (cs += 8); 47 | spi->ctl0 = tmp & ~(state << cs); 48 | } 49 | 50 | // data_len < (1 << 20) 51 | // dummy_len = 0..63 52 | static void spi_set_tx_len(spi_base_t *spi, int data_len, int dummy_len) { 53 | uint32_t a, b; 54 | a = spi->ctl8 & ~0x3ff; 55 | b = spi->ctl9 & ~0xffff; 56 | a |= dummy_len << 4 | data_len >> 16; 57 | spi->ctl8 = a; 58 | spi->ctl9 = b | (data_len & 0xffff); 59 | } 60 | 61 | static void spi_set_rx_len(spi_base_t *spi, int data_len, int dummy_len) { 62 | uint32_t a, b; 63 | a = spi->ctl10 & ~0x3ff; 64 | b = spi->ctl11 & ~0xffff; 65 | a |= dummy_len << 4 | data_len >> 16; 66 | spi->ctl10 = a; 67 | spi->ctl11 = b | (data_len & 0xffff); 68 | } 69 | 70 | static void spi_set_ctl12_tx_rx(spi_base_t *spi) { 71 | spi->ctl12 |= 3; // SW_TX_REQ(2) | SW_RX_REQ(1) 72 | } 73 | 74 | static void spi_wait_tx(spi_base_t *spi) { 75 | while (!(spi->int_raw & 1 << 8)); // TX_END_IRQ 76 | spi->int_clr |= 1 << 8; 77 | while (spi->sts2 & 1 << 8); // BUSY 78 | while (!(spi->sts2 & 1 << 7)); // TXF_REAL_EMPTY 79 | } 80 | 81 | static uint32_t spi_send_recv(spi_base_t *spi, int data, int data_len, int dummy_len) { 82 | spi_set_tx_len(spi, data_len, dummy_len); 83 | spi_set_rx_len(spi, data_len, dummy_len); 84 | spi_set_ctl12_tx_rx(spi); 85 | spi->txd = data; 86 | spi_wait_tx(spi); 87 | while (spi->sts2 & 1 << 5); // RXF_REAL_EMPTY 88 | return spi->txd; 89 | } 90 | 91 | static void spi_send(unsigned idx, unsigned data) { 92 | spi_base_t *spi = (spi_base_t*)sys_data.spi; 93 | if (!idx) spi_set_spi_cd_bit(spi, 0); 94 | spi_set_tx_len(spi, 1, 0); 95 | spi->ctl12 |= 2; 96 | spi->txd = data; 97 | spi_wait_tx(spi); 98 | if (!idx) spi_set_spi_cd_bit(spi, 1); 99 | } 100 | 101 | static void spi_refresh_init(uint32_t spi_base) { 102 | spi_base_t *spi = (spi_base_t*)spi_base; 103 | spi->ctl7 |= 0x80; // SPI_TX_HLD_EN 104 | spi_set_spi_cd_bit(spi, 1); 105 | if (sys_data.spi_mode == 2) { 106 | spi->ctl8 |= 1 << 13; // CD_DATA2_SEL 107 | spi->ctl7 |= 3 << 14; // DATA_LINE2_EN, RGB565_EN 108 | spi_set_chnl_len(spi, 8); 109 | } else if (sys_data.spi_mode < 3) { 110 | spi->ctl7 |= 1 << 14; // RGB565_EN 111 | spi_set_chnl_len(spi, 17); 112 | } else { 113 | spi_set_chnl_len(spi, 16); 114 | } 115 | } 116 | 117 | static void spi_refresh_next(uint32_t spi_base) { 118 | spi_base_t *spi = (spi_base_t*)spi_base; 119 | struct sys_display *disp = &sys_data.display; 120 | unsigned len = disp->w1 * disp->h1; 121 | while (!(spi->sts2 & 1 << 7)); // TXF_REAL_EMPTY 122 | while (spi->sts2 & 1 << 8); // BUSY 123 | spi_set_tx_len(spi, len, 0); 124 | spi->ctl12 |= 2; 125 | } 126 | 127 | static void lcm_exec(const uint8_t *cmd); 128 | static void lcdc_init(void); 129 | 130 | #define SPI_ID(spi) ((uint32_t)(spi) >> 20 & 1) 131 | 132 | static const lcd_config_t* lcd_spi_init(uint32_t spi_base) { 133 | spi_base_t *spi = (spi_base_t*)spi_base; 134 | const lcd_config_t *lcd; 135 | uint32_t id, tmp; 136 | 137 | if (!SPI_ID(spi)) { 138 | MEM4(0x71301000) = 0x20; // SPI0 enable 139 | // freq: 0 - 26M, 1 - 128M, 2 - 153.6M, 3 - 192M 140 | MEM4(0x21500048) = 3; 141 | tmp = 0x20; 142 | } else { 143 | APB_CR(0x1134) = 0x200; // SPI1 enable 144 | MEM4(0x21500054) = 3; 145 | tmp = 0x40; 146 | } 147 | DELAY(100) 148 | 149 | // SPI reset 150 | if (tmp) { 151 | MEM4(0x71301004) = tmp; 152 | DELAY(1000) 153 | MEM4(0x71302004) = tmp; 154 | DELAY(1000) 155 | } 156 | 157 | { 158 | uint32_t mode = 0; 159 | mode = (mode & 1 ? 1 : 2) | (mode & 2 ? 1 << 13 : 0); 160 | spi->int_en = 0; 161 | spi->ctl0 = 0xf00 | mode | 8 << 2; 162 | spi->ctl1 &= ~0x3000; 163 | spi->ctl4 = 0x8000; 164 | spi->ctl5 = 0; 165 | } 166 | 167 | spi_set_clkd(spi, 19); 168 | spi_set_mode(spi, sys_data.spi_mode < 3 ? 5 : 6); 169 | spi_set_chnl_len(spi, 16); 170 | spi_set_s3w_rd_strt(spi, 7); 171 | spi_set_rtx_mode(spi, 3); 172 | spi_set_spi_cd_bit(spi, 0); 173 | spi_select_cs(spi, sys_data.lcd_cs, 1); 174 | 175 | id = sys_data.lcd_id; 176 | if (!id) { 177 | id = (spi_send_recv(spi, 0xda << 8, 1, 0) & 0xff) << 16; 178 | id |= (spi_send_recv(spi, 0xdb << 8, 1, 0) & 0xff) << 8; 179 | id |= spi_send_recv(spi, 0xdc << 8, 1, 0) & 0xff; 180 | DBG_LOG("LCD(SPI%u): id = 0x%06x\n", SPI_ID(spi), id); 181 | } 182 | lcd = lcd_find_conf(id, 1); 183 | 184 | { 185 | unsigned spi_freq = 192000000; 186 | unsigned freq = lcd->spi.freq, clkd; 187 | clkd = spi_freq / (freq << 1); 188 | if (clkd) clkd--; 189 | spi_set_clkd(spi, clkd); 190 | } 191 | spi_set_chnl_len(spi, 8); 192 | spi_set_mode(spi, sys_data.spi_mode); 193 | return lcd; 194 | } 195 | 196 | -------------------------------------------------------------------------------- /fpdoom/libc/printf.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | char *buf; 3 | unsigned count, lim; 4 | } sprintf_param_t; 5 | 6 | typedef struct { 7 | FILE *file; 8 | unsigned count; 9 | } fprintf_param_t; 10 | 11 | static void sprintf_put(void *param, int ch) { 12 | sprintf_param_t *x = param; 13 | unsigned pos = x->count; 14 | if (pos < x->lim) 15 | x->buf[pos] = ch; 16 | x->count = pos + 1; 17 | } 18 | 19 | static void fprintf_put(void *param, int ch) { 20 | fprintf_param_t *x = param; 21 | x->count++; 22 | fputc(ch, x->file); 23 | } 24 | 25 | static void printf_putn(void (*put)(void*, int), void *param, int ch, int n) { 26 | while (n > 0) { put(param, ch); n--; } 27 | } 28 | 29 | static void printf_body(void (*put)(void*, int), void *param, const char *fmt, va_list va) { 30 | int a; 31 | for (;;) { 32 | const char *fmt1; 33 | const char *str; 34 | unsigned len, hex_alpha, flags = 0; 35 | int width, prec; 36 | uintptr_t num; 37 | 38 | #define PUT(a) put(param, a) 39 | 40 | a = *fmt++; 41 | if (!a) break; 42 | if (a != '%') { 43 | PUT(a); 44 | continue; 45 | } 46 | 47 | width = 0; prec = -1; 48 | fmt1 = fmt; 49 | a = *fmt++; 50 | // flags 51 | for (;;) { 52 | if (a == '0') flags |= 1; 53 | else if (a == '#') flags |= 2; 54 | else if (a == '-') flags |= 4; 55 | else if (a == '+') flags |= 8; 56 | else if (a == ' ') flags |= 16; 57 | else break; 58 | a = *fmt++; 59 | } 60 | // width 61 | if (a == '*') { 62 | width = va_arg(va, int); 63 | if (width >> 16) goto bad; 64 | a = *fmt++; 65 | } else 66 | while ((unsigned)a - '0' < 10) { 67 | width = width * 10 + (a - '0'); 68 | if (width >> 16) goto bad; 69 | a = *fmt++; 70 | } 71 | // prec 72 | if (a == '.') { 73 | a = *fmt++; 74 | prec = 0; 75 | if (a == '*') { 76 | prec = va_arg(va, int); 77 | if (prec >> 16) goto bad; 78 | a = *fmt++; 79 | } else 80 | while ((unsigned)a - '0' < 10) { 81 | prec = prec * 10 + (a - '0'); 82 | if (prec >> 16) goto bad; 83 | a = *fmt++; 84 | } 85 | } 86 | // length 87 | if (a == 'z') { // size_t 88 | a = *fmt++; 89 | } else if (a == 'l') { // long 90 | a = *fmt++; 91 | } 92 | // type 93 | if (a == 's') { 94 | str = va_arg(va, const char*); 95 | if (!str) str = "(null)"; 96 | str1: 97 | len = 0; 98 | while (len < (unsigned)prec && str[len]) len++; 99 | width -= len; 100 | if (!(flags & 4)) printf_putn(put, param, ' ', width); 101 | while (len) { PUT(*str++); len--; } 102 | 103 | } else if (a == 'u' || a == 'i' || a == 'd') { 104 | char buf[10]; // 32bit = 10, 64bit = 20 105 | int sign = 0; 106 | if (width < prec) width = prec; 107 | num = va_arg(va, unsigned); 108 | if (a != 'u') { 109 | sign = (int)num >> 31; 110 | num = ((int)num + sign) ^ sign; 111 | width += sign; 112 | sign &= '-'; 113 | if (!sign && (flags & (8 | 16))) { 114 | width -= 1; 115 | sign = flags & 8 ? '+' : ' '; 116 | } 117 | } 118 | len = 0; 119 | do { 120 | a = num + '0'; 121 | #ifndef __thumb__ 122 | num /= 10; 123 | #else // help the compiler not to call __aeabi_uidiv 124 | num = (num * 0xcccccccdull) >> (32 + 3); 125 | #endif 126 | buf[len++] = a - num * 10; 127 | } while (num); 128 | if (prec < (int)len) prec = len; 129 | if ((flags & 5) == 1 && width > prec) prec = width; 130 | width -= prec; 131 | if (!(flags & 4)) printf_putn(put, param, ' ', width); 132 | if (sign) PUT(sign); 133 | printf_putn(put, param, '0', prec - len); 134 | while (len) PUT(buf[--len]); 135 | 136 | } else if (a == 'c') { 137 | a = va_arg(va, int); 138 | width -= 1; 139 | if (!(flags & 4)) printf_putn(put, param, ' ', width); 140 | PUT(a); 141 | 142 | } else if (a == 'x' || a == 'X') { 143 | if (width < prec) width = prec; 144 | hex_alpha = 'a' - '0' - 10 - 'x' + a; 145 | num = va_arg(va, unsigned); 146 | do_hex: 147 | if (flags & 2) width -= 2; 148 | for (len = sizeof(void*) * 2; len > 1; len--) { 149 | if (num >> (sizeof(num) * 8 - 4)) break; 150 | num <<= 4; 151 | } 152 | if (prec < (int)len) prec = len; 153 | if ((flags & 5) == 1 && width > prec) prec = width; 154 | width -= prec; 155 | if (!(flags & 4)) printf_putn(put, param, ' ', width); 156 | if (flags & 2) { 157 | PUT('0'); PUT('x' - 'a' + '0' + 10 + hex_alpha); 158 | } 159 | printf_putn(put, param, '0', prec - len); 160 | while (len) { 161 | a = num >> (sizeof(num) * 8 - 4); 162 | num <<= 4; 163 | if (a >= 10) a += hex_alpha; 164 | PUT(a + '0'); 165 | len--; 166 | } 167 | 168 | } else if (a == 'p') { 169 | void *ptr = va_arg(va, void*); 170 | hex_alpha = 'a' - '0' - 10; 171 | if (!ptr) { str = "(nil)"; goto str1; } 172 | flags |= 2; 173 | num = (uintptr_t)ptr; 174 | goto do_hex; 175 | 176 | } else if (a == '%') { 177 | PUT(a); 178 | continue; 179 | } else goto bad; 180 | 181 | if (flags & 4) printf_putn(put, param, ' ', width); 182 | continue; 183 | bad: 184 | fmt = fmt1; 185 | PUT('%'); 186 | } 187 | } 188 | 189 | #undef PUT 190 | 191 | #define PRINTF_PARAM_s(a1, a2) \ 192 | sprintf_param_t param = { a1, 0, a2 } 193 | #define PRINTF_PARAM_f(a1, a2) \ 194 | fprintf_param_t param = { a1, 0 } 195 | 196 | #define PRINTF_END_s \ 197 | if (param.lim) \ 198 | param.buf[param.count < param.lim ? param.count : param.lim - 1] = 0; \ 199 | return param.count; 200 | #define PRINTF_END_f \ 201 | return param.count; 202 | 203 | #define PRINTF_DEF(name, type, a1, a2, ...) \ 204 | int PREFIX(name)(__VA_ARGS__, ...) { \ 205 | PRINTF_PARAM_##type(a1, a2); \ 206 | va_list va; \ 207 | va_start(va, fmt); \ 208 | printf_body(type##printf_put, ¶m, fmt, va); \ 209 | va_end(va); \ 210 | PRINTF_END_##type; \ 211 | } \ 212 | \ 213 | int PREFIX(v##name)(__VA_ARGS__, va_list va) { \ 214 | PRINTF_PARAM_##type(a1, a2); \ 215 | printf_body(type##printf_put, ¶m, fmt, va); \ 216 | PRINTF_END_##type; \ 217 | } 218 | 219 | PRINTF_DEF(printf, f, stdout, 0, const char *fmt) 220 | PRINTF_DEF(sprintf, s, buf, 0x7fffffff, char *buf, const char *fmt) 221 | PRINTF_DEF(snprintf, s, buf, size, char *buf, size_t size, const char *fmt) 222 | PRINTF_DEF(fprintf, f, file, 0, FILE *file, const char *fmt) 223 | 224 | #undef PRINTF_DEF 225 | 226 | -------------------------------------------------------------------------------- /ums9117/usbio.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "usbio.h" 3 | 4 | void clean_dcache_range(void *start, void *end); 5 | void invalidate_dcache_range(void *start, void *end); 6 | 7 | #define USB_BUFSIZE 12800 8 | 9 | static char usb_size64; // max bulk size 10 | unsigned usb_recv_idx, usb_recv_len; 11 | static uint8_t usb_recv_buf[USB_BUFSIZE] ALIGN(64); 12 | 13 | typedef struct { 14 | void *ptr; 15 | uint16_t len1, len2; 16 | uint32_t flags; 17 | } usb_trans_t; 18 | 19 | static usb_trans_t usb_send_trans ALIGN(16); 20 | static usb_trans_t usb_recv_trans ALIGN(16); 21 | 22 | static void usr_start_recv(void) { 23 | uint32_t b = 0x20201be0 + (15 + 6) * 32; 24 | MEM4(b + 8) |= 0x14; 25 | MEM4(b + 0x14) = (uint32_t)&usb_recv_trans; 26 | MEM4(b + 4) |= 1; 27 | } 28 | 29 | static const uint8_t dev_desc[] ALIGN(4) = { 30 | 0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 31 | 0x82, 0x17, 0x00, 0x4d, 0xff, 0xff, 0x00, 0x00, 32 | 0x00, 0x01 33 | }; 34 | 35 | static uint8_t config_desc[] ALIGN(4) = { 36 | 0x09, 0x02, 0x20, 0x00, 0x01, 0x01, 0x00, 0xc0, 0x32, 37 | 0x09, 0x04, 0x00, 0x00, 0x02, 0xff, 0x00, 0x00, 0x00, 38 | 0x07, 0x05, 0x85, 0x02, 0x00, 0x02, 0x00, 39 | 0x07, 0x05, 0x06, 0x02, 0x00, 0x02, 0x00 40 | }; 41 | 42 | static void usb_ep_config(void) { 43 | uint32_t b = 0x20200000; 44 | uint32_t n = usb_size64 ? 64 : 0x200; 45 | 46 | MEM1(b + 0xe) = 5; 47 | MEM2(b + 0x6) = 0x21; 48 | MEM2(b + 0x8) = 0x40; 49 | MEM1(b + 0x62) = 0x17; 50 | MEM2(b + 0x64) = 0x108; 51 | MEM2(b + 0x150) = n; 52 | MEM1(b + 0x152) = 0x48; 53 | MEM1(b + 0x153) = 0x20; 54 | MEM1(b + 0x153) |= 0x94; 55 | 56 | MEM1(b + 0xe) = 6; 57 | MEM1(b + 0x63) = 0x17; 58 | MEM2(b + 0x66) = 8; 59 | MEM2(b + 0x164) = n; 60 | MEM1(b + 0x166) = 0x90; 61 | MEM1(b + 0x167) |= 0xa8; 62 | } 63 | 64 | static void usb_send_desc(uint8_t *buf) { 65 | unsigned i, n, type; 66 | 67 | MEM1(0x20200012) |= 0x40; 68 | 69 | type = buf[3]; 70 | n = buf[6]; 71 | 72 | if (type == 1) { 73 | if (n > sizeof(dev_desc)) n = sizeof(dev_desc); 74 | for (i = 0; i < n; i++) 75 | MEM1(0x20200020) = dev_desc[i]; 76 | } else if (type == 2) { 77 | if (usb_size64) { 78 | config_desc[9 + 9 + 4] = 64; 79 | config_desc[9 + 9 + 5] = 0; 80 | config_desc[9 + 9 + 7 + 4] = 64; 81 | config_desc[9 + 9 + 7 + 5] = 0; 82 | } 83 | if (n > sizeof(config_desc)) n = sizeof(config_desc); 84 | for (i = 0; i < n; i++) 85 | MEM1(0x20200020) = config_desc[i]; 86 | } else return; 87 | MEM1(0x20200012) |= 0x0a; 88 | } 89 | 90 | static void usb_sys_events(void) { 91 | unsigned i, n; 92 | uint8_t buf[8]; 93 | 94 | if (!(MEM1(0x20200012) & 1)) return; 95 | 96 | for (i = 0; i < 8; i++) 97 | buf[i++] = MEM1(0x20200020); 98 | 99 | if (buf[0] & 0x60) { 100 | MEM1(0x20200012) |= 0x48; 101 | while (!(MEM2(0x20200002) & 1)); 102 | if ((buf[0] & 0x7f) == 0x21 && buf[2]) { 103 | usb_ep_config(); 104 | usr_start_recv(); 105 | } 106 | } else if (buf[1]) { 107 | switch (buf[1]) { 108 | case 5: 109 | MEM1(0x20200012) |= 0x48; 110 | while (!(MEM2(0x20200002) & 1)); 111 | MEM1(0x20200000) = buf[2]; 112 | break; 113 | case 6: 114 | usb_send_desc(buf); 115 | break; 116 | case 9: 117 | MEM1(0x20200012) |= 0x48; 118 | while (!(MEM2(0x20200002) & 1)); 119 | break; 120 | } 121 | } else { 122 | MEM1(0x20200012) |= 0x40; 123 | n = buf[6] | buf[7] << 8; 124 | for (i = 0; i < n; i++) 125 | MEM1(0x20200020) = 0; 126 | MEM1(0x20200012) |= 0x0a; 127 | } 128 | } 129 | 130 | static unsigned usb_handler(void) { 131 | uint32_t tmp; 132 | 133 | if (MEM1(0x2020000a) & 4) 134 | usb_size64 = (MEM1(0x20200001) & 0x10) == 0; 135 | 136 | tmp = MEM4(0x20201e88); 137 | if (MEM2(0x20200002) & 1) { 138 | MEM1(0x2020000e) = 0; 139 | usb_sys_events(); 140 | } 141 | if (!(tmp & 0x40000)) return 0; 142 | { 143 | uint32_t b = 0x20201be0 + (15 + 6) * 32; 144 | MEM4(b + 8) |= 0x14000000; 145 | tmp = USB_BUFSIZE - (MEM4(0x20201e90) >> 16); 146 | usb_recv_len = tmp; 147 | usb_recv_idx = 0; 148 | invalidate_dcache_range(usb_recv_buf, usb_recv_buf + tmp); 149 | MEM4(b + 8) |= 0x14; 150 | MEM4(b + 0x14) = (uint32_t)&usb_recv_trans; 151 | MEM4(b + 4) |= 1; 152 | } 153 | return 1; 154 | } 155 | 156 | void usb_init(void) { 157 | { 158 | usb_trans_t *tr = &usb_recv_trans; 159 | 160 | tr->ptr = usb_recv_buf; 161 | tr->len1 = 0x20; 162 | tr->len2 = USB_BUFSIZE; 163 | tr->flags = 5; 164 | 165 | // clean the cache from zeroing the BSS 166 | clean_dcache_range(usb_recv_buf, usb_recv_buf + USB_BUFSIZE); 167 | // orig code don't do this 168 | clean_dcache_range(tr, (char*)tr + 12); 169 | } 170 | usb_size64 = 0; 171 | usb_recv_idx = usb_recv_len = 0; 172 | #if 0 173 | // clear interrupts from BROM 174 | { 175 | uint32_t b = 0x20201be0 + (15 + 6) * 32; 176 | MEM4(b + 8) |= 0x14000000; 177 | } 178 | #endif 179 | usr_start_recv(); 180 | } 181 | 182 | int usb_getchar(int wait) { 183 | (void)wait; 184 | if (usb_recv_idx == usb_recv_len) 185 | while (!usb_handler()) 186 | if (!wait) return -1; 187 | return usb_recv_buf[usb_recv_idx++]; 188 | } 189 | 190 | int usb_read(void *dst, unsigned len, int wait) { 191 | uint8_t *d = (uint8_t*)dst; 192 | unsigned i, n; 193 | 194 | while (len) { 195 | if (usb_recv_idx == usb_recv_len) 196 | while (!usb_handler()); 197 | 198 | i = usb_recv_idx; 199 | n = usb_recv_len - i; 200 | if (n > len) n = len; 201 | len -= n; 202 | usb_recv_idx = i + n; 203 | memcpy(d, usb_recv_buf + i, n); 204 | if (!wait) break; 205 | } 206 | return d - (uint8_t*)dst; 207 | } 208 | 209 | int usb_write(const void *src, unsigned len) { 210 | int ep = 5; 211 | uint32_t a, b = 0x20201be0 + ep * 32; 212 | usb_trans_t *tr = &usb_send_trans; 213 | 214 | tr->ptr = (void*)src; 215 | tr->len1 = 0x20; 216 | tr->len2 = len; 217 | tr->flags = 5; 218 | 219 | clean_dcache_range((char*)src, (char*)src + len); 220 | clean_dcache_range(tr, (char*)tr + 12); 221 | 222 | MEM4(b + 8) |= 4; 223 | MEM4(b + 0x14) = (uint32_t)tr; 224 | MEM4(b + 4) |= 1; 225 | #if 1 226 | while (!((a = MEM4(b + 8)) & 1 << 18)); 227 | #else // orig code, that's why FDL1 is so slow! 228 | a = MEM4(b + 8); 229 | while (!(a & 1 << 18)) { 230 | a = MEM4(b + 8); 231 | DELAY(1000 << 10) 232 | } 233 | #endif 234 | MEM4(b + 8) = a | 1 << 26; 235 | return len; 236 | } 237 | 238 | -------------------------------------------------------------------------------- /fpdoom/lcd_spi.h: -------------------------------------------------------------------------------- 1 | enum { 2 | SPI_TXD = 0 3 | }; 4 | 5 | typedef volatile struct { 6 | uint32_t txd, clkd, ctl0, ctl1; // 0x00 7 | uint32_t ctl2, ctl3, ctl4, ctl5; 8 | uint32_t int_en, int_clr, int_raw, int_mask; // 0x20 9 | uint32_t sts1, sts2, dspwait, sts3; 10 | uint32_t ctl6, sts4, fifo_rst, ctl7; // 0x40 11 | uint32_t sts5, ctl8, ctl9, ctl10; 12 | uint32_t ctl11, ctl12, sts6, sts7; // 0x60 13 | uint32_t sts8, sts9; 14 | } spi_base_t; 15 | 16 | static void spi_set_clkd(spi_base_t *spi, int val) { 17 | spi->clkd = val; 18 | } 19 | 20 | static void spi_set_mode(spi_base_t *spi, int val) { 21 | spi->ctl7 = (spi->ctl7 & ~(7 << 3)) | val << 3; 22 | } 23 | 24 | static void spi_set_chnl_len(spi_base_t *spi, int val) { 25 | val &= 0x1f; 26 | spi->ctl0 = (spi->ctl0 & ~(0x1f << 2)) | val << 2; 27 | } 28 | 29 | static void spi_set_s3w_rd_strt(spi_base_t *spi, int val) { 30 | val &= 0x1f; 31 | spi->ctl2 = (spi->ctl2 & ~0x1f) | val; 32 | } 33 | 34 | static void spi_set_rtx_mode(spi_base_t *spi, int mode) { 35 | // 01 - recieve, 10 - transmit 36 | spi->ctl1 |= mode << 12; 37 | } 38 | 39 | static void spi_set_spi_cd_bit(spi_base_t *spi, int val) { 40 | // 0 - cmd, 1 - data 41 | spi->ctl8 = (spi->ctl8 & ~(1 << 15)) | val << 15; 42 | } 43 | 44 | // cs = 0..3 45 | static void spi_select_cs(spi_base_t *spi, unsigned cs, unsigned state) { 46 | uint32_t tmp = spi->ctl0 | 1 << (cs += 8); 47 | spi->ctl0 = tmp & ~(state << cs); 48 | } 49 | 50 | // data_len < (1 << 20) 51 | // dummy_len = 0..63 52 | static void spi_set_tx_len(spi_base_t *spi, int data_len, int dummy_len) { 53 | uint32_t a, b; 54 | a = spi->ctl8 & ~0x3ff; 55 | b = spi->ctl9 & ~0xffff; 56 | a |= dummy_len << 4 | data_len >> 16; 57 | spi->ctl8 = a; 58 | spi->ctl9 = b | (data_len & 0xffff); 59 | } 60 | 61 | static void spi_set_rx_len(spi_base_t *spi, int data_len, int dummy_len) { 62 | uint32_t a, b; 63 | a = spi->ctl10 & ~0x3ff; 64 | b = spi->ctl11 & ~0xffff; 65 | a |= dummy_len << 4 | data_len >> 16; 66 | spi->ctl10 = a; 67 | spi->ctl11 = b | (data_len & 0xffff); 68 | } 69 | 70 | static void spi_set_ctl12_tx_rx(spi_base_t *spi) { 71 | spi->ctl12 |= 3; // SW_TX_REQ(2) | SW_RX_REQ(1) 72 | } 73 | 74 | static void spi_wait_tx(spi_base_t *spi) { 75 | while (!(spi->int_raw & 1 << 8)); // TX_END_IRQ 76 | spi->int_clr |= 1 << 8; 77 | while (spi->sts2 & 1 << 8); // BUSY 78 | while (!(spi->sts2 & 1 << 7)); // TXF_REAL_EMPTY 79 | } 80 | 81 | static uint32_t spi_send_recv(spi_base_t *spi, int data, int data_len, int dummy_len) { 82 | spi_set_tx_len(spi, data_len, dummy_len); 83 | spi_set_rx_len(spi, data_len, dummy_len); 84 | spi_set_ctl12_tx_rx(spi); 85 | spi->txd = data; 86 | spi_wait_tx(spi); 87 | while (spi->sts2 & 1 << 5); // RXF_REAL_EMPTY 88 | return spi->txd; 89 | } 90 | 91 | static void spi_send(unsigned idx, unsigned data) { 92 | spi_base_t *spi = (spi_base_t*)sys_data.spi; 93 | if (!idx) spi_set_spi_cd_bit(spi, 0); 94 | spi_set_tx_len(spi, 1, 0); 95 | spi->ctl12 |= 2; 96 | spi->txd = data; 97 | spi_wait_tx(spi); 98 | if (!idx) spi_set_spi_cd_bit(spi, 1); 99 | } 100 | 101 | static void spi_refresh_init(uint32_t spi_base) { 102 | spi_base_t *spi = (spi_base_t*)spi_base; 103 | spi->ctl7 |= 0x80; // SPI_TX_HLD_EN 104 | spi_set_spi_cd_bit(spi, 1); 105 | if (sys_data.spi_mode < 3) { 106 | spi->ctl7 |= 1 << 14; // RGB565_EN 107 | spi_set_chnl_len(spi, 17); 108 | } else { 109 | spi_set_chnl_len(spi, 16); 110 | } 111 | } 112 | 113 | static void spi_refresh_next(uint32_t spi_base) { 114 | spi_base_t *spi = (spi_base_t*)spi_base; 115 | struct sys_display *disp = &sys_data.display; 116 | unsigned len = disp->w1 * disp->h1; 117 | while (!(spi->sts2 & 1 << 7)); // TXF_REAL_EMPTY 118 | while (spi->sts2 & 1 << 8); // BUSY 119 | spi_set_tx_len(spi, len, 0); 120 | spi->ctl12 |= 2; 121 | } 122 | 123 | static void lcm_exec(const uint8_t *cmd); 124 | static void lcdc_init(void); 125 | 126 | #define SPI_ID(spi) ((uint32_t)(spi) >> 24 & 1) 127 | 128 | static void spi_pin_grp_select(spi_base_t *spi, unsigned pin_gid) { 129 | uint32_t tmp = MEM4(0x8b0001e0); 130 | unsigned shl = SPI_ID(spi) ? 4 : 29; 131 | if (!pin_gid) FATAL(); // TODO 132 | tmp = (tmp & ~(3 << shl)) | pin_gid << shl; 133 | MEM4(0x8b0001e0) = tmp; 134 | DELAY(100) 135 | } 136 | 137 | static const lcd_config_t* lcd_spi_init(uint32_t spi_base) { 138 | spi_base_t *spi = (spi_base_t*)spi_base; 139 | const lcd_config_t *lcd; 140 | uint32_t id, tmp; 141 | 142 | if (!SPI_ID(spi)) { 143 | AHB_PWR_ON(0x4000); // SPI0 enable 144 | tmp = _chip == 1 ? 0x800 : 0; 145 | if (_chip == 1) { 146 | // freq: 3 - 75.6M, 4 - 104M, 5 - 104M (APLL) 147 | MEM4(0x8d200054) = (MEM4(0x8d200054) & ~0x307) | 5; 148 | } 149 | } else { 150 | AHB_PWR_ON(0x80000); // SPI1 enable 151 | tmp = IS_SC6530 ? 0x20 : 0x8000; 152 | if (_chip == 1) { 153 | // freq: 3 - 48M, 4 - 75.6M, 5 - 104M, 6 - 104M (APLL) 154 | MEM4(0x8d200058) = (MEM4(0x8d200058) & ~0x307) | 6; 155 | } 156 | } 157 | DELAY(100) 158 | 159 | // SPI reset 160 | if (tmp) { 161 | uint32_t rst = 0x20501040, add = 0x1000; 162 | if (_chip != 1) rst = 0x8b000060, add = 4; 163 | MEM4(rst) = tmp; 164 | DELAY(1000) 165 | MEM4(rst + add) = tmp; 166 | DELAY(1000) 167 | } 168 | 169 | if (_chip == 2) 170 | spi_pin_grp_select(spi, 1); 171 | 172 | { 173 | uint32_t mode = 0; 174 | mode = (mode & 1 ? 1 : 2) | (mode & 2 ? 1 << 13 : 0); 175 | spi->int_en = 0; 176 | spi->ctl0 = 0xf00 | mode | 8 << 2; 177 | spi->ctl1 &= ~0x3000; 178 | spi->ctl4 = 0x8000; 179 | spi->ctl5 = 0; 180 | } 181 | 182 | spi_set_clkd(spi, 15); 183 | spi_set_mode(spi, sys_data.spi_mode < 3 ? 5 : 6); 184 | spi_set_chnl_len(spi, 16); 185 | spi_set_s3w_rd_strt(spi, 7); 186 | spi_set_rtx_mode(spi, 3); 187 | spi_set_spi_cd_bit(spi, 0); 188 | spi_select_cs(spi, sys_data.lcd_cs, 1); 189 | 190 | id = sys_data.lcd_id; 191 | if (!id) { 192 | id = (spi_send_recv(spi, 0xda << 8, 1, 0) & 0xff) << 16; 193 | id |= (spi_send_recv(spi, 0xdb << 8, 1, 0) & 0xff) << 8; 194 | id |= spi_send_recv(spi, 0xdc << 8, 1, 0) & 0xff; 195 | DBG_LOG("LCD(SPI%u): id = 0x%06x\n", SPI_ID(spi), id); 196 | } 197 | lcd = lcd_find_conf(id, 1); 198 | 199 | { 200 | unsigned spi_freq = 104000000; 201 | unsigned freq = lcd->spi.freq, clkd; 202 | if (_chip != 1) 203 | spi_freq = !SPI_ID(spi) ? 78000000 : 48000000; 204 | clkd = spi_freq / (freq << 1); 205 | if (clkd) clkd--; 206 | spi_set_clkd(spi, clkd); 207 | } 208 | spi_set_chnl_len(spi, 8); 209 | spi_set_mode(spi, sys_data.spi_mode); 210 | return lcd; 211 | } 212 | 213 | --------------------------------------------------------------------------------