diff options
Diffstat (limited to 'frontends/calculator/CEdev/include')
34 files changed, 7681 insertions, 0 deletions
diff --git a/frontends/calculator/CEdev/include/.linker_script b/frontends/calculator/CEdev/include/.linker_script new file mode 100644 index 0000000..e3a1887 --- /dev/null +++ b/frontends/calculator/CEdev/include/.linker_script @@ -0,0 +1,305 @@ +symbol __low_bss = bss.base +symbol __len_bss = bss.length +symbol __heaptop = bss.high +symbol __heapbot = bss.top +order header, icon, launcher, libs, startup, cleanup, exit, code, data, strsect, text +if STATIC + srcs "../../lib/static/atof.src" + srcs "../../lib/static/ceil.src" + srcs "../../lib/static/fabs.src" + srcs "../../lib/static/acos.src" + srcs "../../lib/static/cos.src" + srcs "../../lib/static/exp.src" + srcs "../../lib/static/log.src" + srcs "../../lib/static/ufltinfo.src" + srcs "../../lib/static/pow.src" + srcs "../../lib/static/strtod.src" + srcs "../../lib/static/asin.src" + srcs "../../lib/static/sinh.src" + srcs "../../lib/static/log10.src" + srcs "../../lib/static/sin.src" + srcs "../../lib/static/atan.src" + srcs "../../lib/static/atan2.src" + srcs "../../lib/static/fmod.src" + srcs "../../lib/static/tanh.src" + srcs "../../lib/static/tan.src" + srcs "../../lib/static/frexp.src" + srcs "../../lib/static/sqrt.src" + srcs "../../lib/static/floor.src" + srcs "../../lib/static/ldexp.src" + srcs "../../lib/static/modf.src" + srcs "../../lib/static/ufltrnd.src" +else + srcs "../../lib/linked/frexp.src" + srcs "../../lib/linked/atan2.src" + srcs "../../lib/linked/atof.src" + srcs "../../lib/linked/acos.src" + srcs "../../lib/linked/sqrt.src" + srcs "../../lib/linked/atan.src" + srcs "../../lib/linked/sinh.src" + srcs "../../lib/linked/tan.src" + srcs "../../lib/linked/floor.src" + srcs "../../lib/linked/ldexp.src" + srcs "../../lib/linked/ufltrnd.src" + srcs "../../lib/linked/fabs.src" + srcs "../../lib/linked/log10.src" + srcs "../../lib/linked/strtod.src" + srcs "../../lib/linked/fmod.src" + srcs "../../lib/linked/asin.src" + srcs "../../lib/linked/exp.src" + srcs "../../lib/linked/ufltinfo.src" + srcs "../../lib/linked/cosh.src" + srcs "../../lib/linked/modf.src" + srcs "../../lib/linked/log.src" + srcs "../../lib/linked/tanh.src" + srcs "../../lib/linked/ceil.src" + srcs "../../lib/linked/cos.src" + srcs "../../lib/linked/pow.src" + srcs "../../lib/linked/sin.src" +end if +srcs "../../lib/shared/os_textbuffer.src" +srcs "../../lib/shared/debugger.src" +srcs "../../lib/shared/zx7_Decompress.src" +srcs "../../lib/shared/random.src" +srcs "../../lib/shared/atomic_load_decreasing_32.src" +srcs "../../lib/shared/removeallbreakpoints.src" +srcs "../../lib/shared/removebreakpoint.src" +srcs "../../lib/shared/srandom.src" +srcs "../../lib/shared/tice.src" +srcs "../../lib/shared/removewatchpoint.src" +srcs "../../lib/shared/atomic_load_increasing_32.src" +srcs "../../lib/shared/setwatchpoint.src" +srcs "../../lib/shared/interrupts.src" +srcs "../../lib/shared/removeallwatchpoints.src" +srcs "../../lib/shared/getstringinput.src" +srcs "../../lib/shared/dzx7_turbo.src" +srcs "../../lib/shared/atomic_load_32.src" +srcs "../../lib/shared/setwritewatchpoint.src" +srcs "../../lib/shared/setreadwatchpoint.src" +srcs "../../lib/shared/os.src" +srcs "../../lib/shared/usb.src" +srcs "../../lib/shared/setreadwritewatchpoint.src" +srcs "../../lib/shared/abort.src" +srcs "../../lib/shared/setbreakpoint.src" +srcs "../../lib/shared/dzx7_standard.src" +srcs "../../lib/shared/delay.src" +srcs "../../lib/shared/frftoub.src" +srcs "../../lib/shared/fpupop1.src" +srcs "../../lib/shared/frimulu.src" +srcs "../../lib/shared/ladd.src" +srcs "../../lib/shared/atoi.src" +srcs "../../lib/shared/idivs.src" +srcs "../../lib/shared/isnan.src" +srcs "../../lib/shared/case24d.src" +srcs "../../lib/shared/isupper.src" +srcs "../../lib/shared/memmove.src" +srcs "../../lib/shared/frameset0.src" +srcs "../../lib/shared/sneg.src" +srcs "../../lib/shared/setjmp.src" +srcs "../../lib/shared/strcspn.src" +srcs "../../lib/shared/fpdiv.src" +srcs "../../lib/shared/istiy.src" +srcs "../../lib/shared/frstof.src" +srcs "../../lib/shared/abs.src" +srcs "../../lib/shared/frsmulu.src" +srcs "../../lib/shared/strdup.src" +srcs "../../lib/shared/sprintf.src" +srcs "../../lib/shared/sldix.src" +srcs "../../lib/shared/finite.src" +srcs "../../lib/shared/lnot.src" +srcs "../../lib/shared/imulu.src" +srcs "../../lib/shared/setflag.src" +srcs "../../lib/shared/iscntrl.src" +srcs "../../lib/shared/fpupop2.src" +srcs "../../lib/shared/ishrs.src" +srcs "../../lib/shared/fpsub.src" +srcs "../../lib/shared/fpmul.src" +srcs "../../lib/shared/case24.src" +srcs "../../lib/shared/isinf.src" +srcs "../../lib/shared/bldix.src" +srcs "../../lib/shared/ldiv.src" +srcs "../../lib/shared/strcmp.src" +srcs "../../lib/shared/strcasecmp.src" +srcs "../../lib/shared/sand.src" +srcs "../../lib/shared/strrchr.src" +srcs "../../lib/shared/sshrs.src" +srcs "../../lib/shared/tolower.src" +srcs "../../lib/shared/isgraph.src" +srcs "../../lib/shared/case8d.src" +srcs "../../lib/shared/snot.src" +srcs "../../lib/shared/round.src" +srcs "../../lib/shared/seqcased.src" +srcs "../../lib/shared/frbtof.src" +srcs "../../lib/shared/fruitof.src" +srcs "../../lib/shared/fritof.src" +srcs "../../lib/shared/log2.src" +srcs "../../lib/shared/fpultof.src" +srcs "../../lib/shared/bshrs.src" +srcs "../../lib/shared/seqcase.src" +srcs "../../lib/shared/bremu.src" +srcs "../../lib/shared/lmulu.src" +srcs "../../lib/shared/strncmp.src" +srcs "../../lib/shared/frbmuls.src" +srcs "../../lib/shared/scmpzero.src" +srcs "../../lib/shared/isxdigit.src" +srcs "../../lib/shared/bdivs.src" +srcs "../../lib/shared/strndup.src" +srcs "../../lib/shared/memset.src" +srcs "../../lib/shared/strncpy.src" +srcs "../../lib/shared/itol.src" +srcs "../../lib/shared/strstr.src" +srcs "../../lib/shared/sdivs.src" +srcs "../../lib/shared/lcmpu.src" +srcs "../../lib/shared/case8.src" +srcs "../../lib/shared/indcall.src" +srcs "../../lib/shared/sqrtf.src" +srcs "../../lib/shared/sstix.src" +srcs "../../lib/shared/fpftol.src" +srcs "../../lib/shared/rand.src" +srcs "../../lib/shared/lstix.src" +srcs "../../lib/shared/lrems.src" +srcs "../../lib/shared/ildiy.src" +srcs "../../lib/shared/lmuls.src" +srcs "../../lib/shared/fppack.src" +srcs "../../lib/shared/lor.src" +srcs "../../lib/shared/icmpzero.src" +srcs "../../lib/shared/strpbrk.src" +srcs "../../lib/shared/sstiy.src" +srcs "../../lib/shared/land.src" +srcs "../../lib/shared/ldivu.src" +srcs "../../lib/shared/frsmuls.src" +srcs "../../lib/shared/strtok.src" +srcs "../../lib/shared/iand.src" +srcs "../../lib/shared/ldivs.src" +srcs "../../lib/shared/ineg.src" +srcs "../../lib/shared/stoi.src" +srcs "../../lib/shared/sremu.src" +srcs "../../lib/shared/sldiy.src" +srcs "../../lib/shared/bstiy.src" +srcs "../../lib/shared/memchr.src" +srcs "../../lib/shared/ior.src" +srcs "../../lib/shared/fpneg.src" +srcs "../../lib/shared/isascii.src" +srcs "../../lib/shared/lldix.src" +srcs "../../lib/shared/smuls.src" +srcs "../../lib/shared/smulu.src" +srcs "../../lib/shared/isspace.src" +srcs "../../lib/shared/frftous.src" +srcs "../../lib/shared/sshl.src" +srcs "../../lib/shared/sdivu.src" +srcs "../../lib/shared/fpadd.src" +srcs "../../lib/shared/lsub.src" +srcs "../../lib/shared/bldiy.src" +srcs "../../lib/shared/ixor.src" +srcs "../../lib/shared/lstiy.src" +srcs "../../lib/shared/srand.src" +srcs "../../lib/shared/uldiv.src" +srcs "../../lib/shared/frftos.src" +srcs "../../lib/shared/frubtof.src" +srcs "../../lib/shared/ishru.src" +srcs "../../lib/shared/sshru.src" +srcs "../../lib/shared/atos.src" +srcs "../../lib/shared/iremu.src" +srcs "../../lib/shared/lshrs.src" +srcs "../../lib/shared/strspn.src" +srcs "../../lib/shared/strnlen.src" +srcs "../../lib/shared/bmuls.src" +srcs "../../lib/shared/sor.src" +srcs "../../lib/shared/imuls.src" +srcs "../../lib/shared/fpltof.src" +srcs "../../lib/shared/sxor.src" +srcs "../../lib/shared/istix.src" +srcs "../../lib/shared/bdivu.src" +srcs "../../lib/shared/bshl.src" +srcs "../../lib/shared/memcmp.src" +srcs "../../lib/shared/srems.src" +srcs "../../lib/shared/strchr.src" +srcs "../../lib/shared/ildix.src" +srcs "../../lib/shared/frustof.src" +srcs "../../lib/shared/lneg.src" +srcs "../../lib/shared/atol.src" +srcs "../../lib/shared/longjmp.src" +srcs "../../lib/shared/labs.src" +srcs "../../lib/shared/memcpy.src" +srcs "../../lib/shared/isalpha.src" +srcs "../../lib/shared/bshru.src" +srcs "../../lib/shared/isprint.src" +srcs "../../lib/shared/strcat.src" +srcs "../../lib/shared/div.src" +srcs "../../lib/shared/isalnum.src" +srcs "../../lib/shared/lshl.src" +srcs "../../lib/shared/case16d.src" +srcs "../../lib/shared/ispunct.src" +srcs "../../lib/shared/toupper.src" +srcs "../../lib/shared/frftoui.src" +srcs "../../lib/shared/idivu.src" +srcs "../../lib/shared/isdigit.src" +srcs "../../lib/shared/sbrk.src" +srcs "../../lib/shared/fpcmp.src" +srcs "../../lib/shared/lcmpzero.src" +srcs "../../lib/shared/stoiu.src" +srcs "../../lib/shared/inot.src" +srcs "../../lib/shared/frimuls.src" +srcs "../../lib/shared/lcmps.src" +srcs "../../lib/shared/irems.src" +srcs "../../lib/shared/lldiy.src" +srcs "../../lib/shared/ishl.src" +srcs "../../lib/shared/strncat.src" +srcs "../../lib/shared/bstix.src" +srcs "../../lib/shared/lxor.src" +srcs "../../lib/shared/lshru.src" +srcs "../../lib/shared/bmulu.src" +srcs "../../lib/shared/calloc.src" +srcs "../../lib/shared/frftoi.src" +srcs "../../lib/shared/islower.src" +srcs "../../lib/shared/case16.src" +srcs "../../lib/shared/frameset.src" +srcs "../../lib/shared/strcpy.src" +srcs "../../lib/shared/frftob.src" +srcs "../../lib/shared/strncasecmp.src" +srcs "../../lib/shared/brems.src" +srcs "../../lib/shared/lremu.src" +srcs "../../lib/shared/case.src" +srcs "../../lib/shared/strlen.src" +srcs "../../lib/shared/gamma.src" +srcs "../../lib/shared/uuitoa.src" +srcs "../../lib/shared/udtog.src" +srcs "../../lib/shared/uscan.src" +srcs "../../lib/shared/strtoul.src" +srcs "../../lib/shared/print_sputch.src" +srcs "../../lib/shared/print_putch.src" +srcs "../../lib/shared/strtol.src" +srcs "../../lib/shared/bsearch.src" +srcs "../../lib/shared/vsprintf.src" +srcs "../../lib/shared/print_putstring.src" +srcs "../../lib/shared/ustoa.src" +srcs "../../lib/shared/maptab.src" +srcs "../../lib/shared/ultoa.src" +srcs "../../lib/shared/usscan.src" +srcs "../../lib/shared/udtof.src" +srcs "../../lib/shared/realloc.src" +srcs "../../lib/shared/free.src" +srcs "../../lib/shared/udtoe.src" +srcs "../../lib/shared/uitoa.src" +srcs "../../lib/shared/qsort.src" +srcs "../../lib/shared/fpdata.src" +srcs "../../lib/shared/uustoa.src" +srcs "../../lib/shared/upscan.src" +srcs "../../lib/shared/malloc.src" +srcs "../../lib/shared/uprint.src" +srcs "../../lib/shared/ureverse.src" +srcs "../../lib/shared/uultoa.src" +srcs "../../lib/shared/print_globals.src" +srcs "../../lib/fileio/files.src" +srcs "../../lib/fileio/fclose.src" +srcs "../../lib/fileio/feof.src" +srcs "../../lib/fileio/fopen.src" +srcs "../../lib/fileio/fwrite.src" +srcs "../../lib/fileio/ftell.src" +srcs "../../lib/fileio/fputs.src" +srcs "../../lib/fileio/fgets.src" +srcs "../../lib/fileio/remove.src" +srcs "../../lib/fileio/fputc.src" +srcs "../../lib/fileio/fgetc.src" +srcs "../../lib/fileio/fread.src" +srcs "../../lib/fileio/fseek.src" diff --git a/frontends/calculator/CEdev/include/.makefile b/frontends/calculator/CEdev/include/.makefile new file mode 100644 index 0000000..8bc89e6 --- /dev/null +++ b/frontends/calculator/CEdev/include/.makefile @@ -0,0 +1,213 @@ +#---------------------------- +# Core C Makefile +#---------------------------- +CLEANUP ?= YES +BSSHEAP_LOW ?= D031F6 +BSSHEAP_HIGH ?= D13FD6 +STACK_HIGH ?= D1A87E +INIT_LOC ?= D1A87F +USE_FLASH_FUNCTIONS ?= YES +OUTPUT_MAP ?= YES +ARCHIVED ?= NO +OPT_MODE ?= -optsize +#---------------------------- +SRCDIR ?= src +OBJDIR ?= obj +BINDIR ?= bin +GFXDIR ?= src/gfx +#---------------------------- + +VERSION := 8.5 + +#---------------------------- +# try not to edit anything below these lines unless you know what you are doing +#---------------------------- + +#---------------------------- + +# define some common makefile things +empty := +space := $(empty) $(empty) +comma := , + +TARGET ?= $(NAME) +ICONPNG ?= $(ICON) +DEBUGMODE = NDEBUG +CCDEBUGFLAG = -nodebug + +# verbosity +V ?= 0 +ifeq ($(V),0) +Q = @ +else +Q = +endif + +# get the os specific items +ifeq ($(OS),Windows_NT) +SHELL := cmd.exe +MAKEDIR := $(CURDIR) +NATIVEPATH = $(subst /,\,$1) +WINPATH = $(NATIVEPATH) +WINRELPATH = $(subst /,\,$1) +RM = del /q /f 2>nul +CEDEV ?= $(call NATIVEPATH,$(realpath ..\..)) +BIN ?= $(call NATIVEPATH,$(CEDEV)/bin) +LD = $(call NATIVEPATH,$(BIN)/fasmg.exe) +CC = $(call NATIVEPATH,$(BIN)/ez80cc.exe) +CV = $(call NATIVEPATH,$(BIN)/convhex.exe) +PG = $(call NATIVEPATH,$(BIN)/convpng.exe) +CD = cd +CP = copy /y +MV = move /y >nul +NULL = >nul 2>&1 +RMDIR = call && (if exist $1 rmdir /s /q $1) +MKDIR = call && (if not exist $1 mkdir $1) +QUOTE_ARG = "$(subst ",',$1)"#' +TO_LOWER = $1 +else +MAKEDIR := $(CURDIR) +NATIVEPATH = $(subst \,/,$1) +WINPATH = $(shell winepath -w $1) +WINRELPATH = $(subst /,\,$1) +RM = rm -f +CEDEV ?= $(call NATIVEPATH,$(realpath ..\..)) +BIN ?= $(call NATIVEPATH,$(CEDEV)/bin) +CC = $(call NATIVEPATH,wine "$(BIN)/ez80cc.exe") +LD = $(call NATIVEPATH,$(BIN)/fasmg) +CV = $(call NATIVEPATH,$(BIN)/convhex) +PG = $(call NATIVEPATH,$(BIN)/convpng) +CD = cd +CP = cp +MV = mv +RMDIR = rm -rf $1 +MKDIR = mkdir -p $1 +QUOTE_ARG = '$(subst ','\'',$1)'#' +TO_LOWER = $(shell printf %s $(call QUOTE_ARG,$1) | tr [:upper:] [:lower:]) +endif +FASMG_FILES = $(subst $(space),$(comma) ,$(patsubst %,"%",$(subst ",\",$(subst \,\\,$(call NATIVEPATH,$1)))))#" + +# ensure native paths +SRCDIR := $(call NATIVEPATH,$(SRCDIR)) +OBJDIR := $(call NATIVEPATH,$(OBJDIR)) +BINDIR := $(call NATIVEPATH,$(BINDIR)) +GFXDIR := $(call NATIVEPATH,$(GFXDIR)) + +# generate default names +TARGETBIN := $(TARGET).bin +TARGETMAP := $(TARGET).map +TARGET8XP := $(TARGET).8xp +ICON_ASM := iconc.src + +# init conditionals +F_STARTUP := $(call NATIVEPATH,$(CEDEV)/lib/cstartup.src) +F_LAUNCHER := $(call NATIVEPATH,$(CEDEV)/lib/libheader.src) +F_CLEANUP := $(call NATIVEPATH,$(CEDEV)/lib/ccleanup.src) + +# source: http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html +rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)$(filter $(subst *,%,$2),$d)) + +# find all of the available C, H and ASM files (Remember, you can create C <-> assembly routines easily this way) +CSOURCES := $(call rwildcard,$(SRCDIR),*.c) +CPPSOURCES := $(call rwildcard,$(SRCDIR),*.cpp) +USERHEADERS := $(call rwildcard,$(SRCDIR),*.h *.hpp) +ASMSOURCES := $(call rwildcard,$(SRCDIR),*.asm) + +# create links for later +LINK_CSOURCES := $(CSOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.src) +LINK_CPPSOURCES := $(CPPSOURCES:$(SRCDIR)/%=$(OBJDIR)/%.src) +LINK_ASMSOURCES := $(ASMSOURCES) + +# files created to be used for linking +LINK_FILES := $(LINK_CSOURCES) $(LINK_CPPSOURCES) $(LINK_ASMSOURCES) +LINK_LIBS := $(wildcard $(CEDEV)/lib/libload/*.lib) +LINK_LIBLOAD := $(CEDEV)/lib/libload.lib + +# check if there is an icon present that we can convert; if so, generate a recipe to build it properly +ifneq ("$(wildcard $(ICONPNG))","") +F_ICON := $(OBJDIR)/$(ICON_ASM) +ICON_CONV := $(PG) -c $(ICONPNG)$(comma)$(call NATIVEPATH,$(F_ICON))$(comma)$(DESCRIPTION) +LINK_ICON = , $(call FASMG_FILES,$(F_ICON)) used +endif + +# determine if output should be archived or compressed +ifeq ($(ARCHIVED),YES) +CVFLAGS += -a +endif +ifeq ($(COMPRESSED),YES) +CVFLAGS += -x +endif +ifeq ($(CLEANUP),YES) +LINK_CLEANUP = , $(call FASMG_FILES,$(F_CLEANUP)) used +endif +ifeq ($(OUTPUT_MAP),YES) +LDMAPFLAG = -i map +endif + +# choose static or linked flash functions +ifeq ($(USE_FLASH_FUNCTIONS),YES) +STATIC := 0 +else +STATIC := 1 +endif + +# define the C flags used by the Zilog compiler +CFLAGS ?= \ + -noasm $(CCDEBUGFLAG) -nogenprint -keepasm -quiet $(OPT_MODE) -cpu:EZ80F91 -noreduceopt -nolistinc -nomodsect -define:_EZ80F91 -define:_EZ80 -define:$(DEBUGMODE) + +# these are the linker flags, basically organized to properly set up the environment +LDFLAGS ?= \ + $(call QUOTE_ARG,$(call NATIVEPATH,$(CEDEV)/include/fasmg-ez80/ld.fasmg)) \ + -i $(call QUOTE_ARG,include $(call FASMG_FILES,$(CEDEV)/include/.linker_script)) \ + $(LDDEBUGFLAG) \ + $(LDMAPFLAG) \ + -i $(call QUOTE_ARG,range bss $$$(BSSHEAP_LOW) : $$$(BSSHEAP_HIGH)) \ + -i $(call QUOTE_ARG,symbol __stack = $$$(STACK_HIGH)) \ + -i $(call QUOTE_ARG,locate header at $$$(INIT_LOC)) \ + -i $(call QUOTE_ARG,STATIC := $(STATIC)) \ + -i $(call QUOTE_ARG,srcs $(call FASMG_FILES,$(F_LAUNCHER)) used if libs.length$(LINK_ICON)$(LINK_CLEANUP)$(comma) $(call FASMG_FILES,$(F_STARTUP)) used$(comma) $(call FASMG_FILES,$(LINK_FILES))) \ + -i $(call QUOTE_ARG,libs $(call FASMG_FILES,$(LINK_LIBLOAD)) used if libs.length$(comma) $(call FASMG_FILES,$(LINK_LIBS))) + +# this rule is trigged to build everything +all: dirs $(BINDIR)/$(TARGET8XP) ; + +# this rule is trigged to build debug everything +debug: LDDEBUGFLAG = -i dbg +debug: DEBUGMODE = DEBUG +debug: CCDEBUGFLAG = -debug +debug: dirs $(BINDIR)/$(TARGET8XP) ; + +dirs: + @echo C CE SDK Version $(VERSION) && \ + $(call MKDIR,$(BINDIR)) && \ + $(call MKDIR,$(OBJDIR)) + +$(BINDIR)/$(TARGET8XP): $(BINDIR)/$(TARGETBIN) + $(Q)$(CD) $(BINDIR) && \ + $(CV) $(CVFLAGS) $(notdir $<) $(notdir $@) + +$(BINDIR)/$(TARGETBIN): $(LINK_FILES) $(F_ICON) + $(Q)$(LD) $(LDFLAGS) $@ + +# this rule handles conversion of the icon, if it is ever updated +$(OBJDIR)/$(ICON_ASM): $(ICONPNG) + $(Q)$(ICON_CONV) + +# these rules compile the source files into object files +$(OBJDIR)/%.src: $(SRCDIR)/%.c $(USERHEADERS) + $(Q)$(call MKDIR,$(call NATIVEPATH,$(@D))) && \ + $(CC) $(CFLAGS) $(call QUOTE_ARG,$(call WINPATH,$(addprefix $(MAKEDIR)/,$<))) && \ + $(MV) $(call QUOTE_ARG,$(call TO_LOWER,$(@F))) $(call QUOTE_ARG,$@) + +clean: + $(Q)$(call RMDIR,$(OBJDIR)) + $(Q)$(call RMDIR,$(BINDIR)) + @echo Cleaned build files. + +gfx: + $(Q)$(CD) $(GFXDIR) && convpng + +version: + @echo C SDK Version $(VERSION) + +.PHONY: all clean version gfx dirs debug diff --git a/frontends/calculator/CEdev/include/assert.h b/frontends/calculator/CEdev/include/assert.h new file mode 100644 index 0000000..04c3a34 --- /dev/null +++ b/frontends/calculator/CEdev/include/assert.h @@ -0,0 +1,19 @@ +#include <debug.h> +#include <stdio.h> +#include <stdlib.h> + +#ifdef assert +#undef assert +#endif + +#ifdef NDEBUG +#define assert(ignore) ((void)0) +#else +#define assert(e) \ + do { \ + if (!(e)) { \ + dbg_sprintf(dbgout, "Assertion failure: %s, file: %s, line %d\n", #e, __FILE__, __LINE__); \ + abort(); \ + } \ + } while (0) +#endif diff --git a/frontends/calculator/CEdev/include/compression.h b/frontends/calculator/CEdev/include/compression.h new file mode 100644 index 0000000..234d25d --- /dev/null +++ b/frontends/calculator/CEdev/include/compression.h @@ -0,0 +1,27 @@ +/** + * @file + * @author Matt "MateoConLechuga" Waltz + * @brief Optimized (de)compression routines + */ + +#ifndef COMPRESSION_H +#define COMPRESSION_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Decompress a block of zx7 encoded data + * + * @param dest Pointer to destination for uncompressed data + * @param src Pointer to compressed data +*/ +void zx7_Decompress(void *dest, void *src); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/frontends/calculator/CEdev/include/ctype.h b/frontends/calculator/CEdev/include/ctype.h new file mode 100644 index 0000000..215dae0 --- /dev/null +++ b/frontends/calculator/CEdev/include/ctype.h @@ -0,0 +1,30 @@ +#ifndef CTYPE_H +#define CTYPE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define TRUE 1 +#define FALSE 0 + +int isalnum(int c); +int isalpha(int c); +int iscntrl(int c); +int isdigit(int c); +int isgraph(int c); +int islower(int c); +int isprint(int c); +int ispunct(int c); +int isspace(int c); +int isupper(int c); +int tolower(int c); +int toupper(int c); +int isascii(int c); +int isxdigit(int c); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/debug.h b/frontends/calculator/CEdev/include/debug.h new file mode 100644 index 0000000..aabbd41 --- /dev/null +++ b/frontends/calculator/CEdev/include/debug.h @@ -0,0 +1,124 @@ +/** + * @file + * @author Matt "MateoConLechuga" Waltz + * @brief Contains useful debugging features for use with the integrated CEmu debugger + */ + +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * void dbg_sprintf(out, const char *format, ...) + * + * @brief Use to print to the emulator console. + * + * See the syntax for 'printf' for more information + * @param out Can be dbgout (black) or dbgerr (red) + * @param format Uses printf-formated specifier string + * @def dbg_sprintf + */ + +/** + * void dbg_ClearConsole(void) + * + * @brief Clears the emulator's console screen. + * @def dbg_ClearConsole + */ + +#ifndef NDEBUG + +/** + * Opens the emulator debugger + */ +void dbg_Debugger(void); + +/** + * Sets an emulated breakpoint at a particular address + * + * @param address The address of the breakpoint to remove + */ +void dbg_SetBreakpoint(void *address); + +/** + * Removes an emulated breakpoint at a particular address + * + * @param address The address of the breakpoint to remove + */ +void dbg_RemoveBreakpoint(void *address); + +/** + * Sets an emulated empty watchpoint at a particular address + * + * @param address The address of the watchpoint to set + * @param length The size of the data at the address (values 1-4) + */ +void dbg_SetWatchpoint(void *address, unsigned int length); + +/** + * Sets an emulated read watchpoint at a particular address + * + * @param address The address of the watchpoint to set + * @param length The size of the data at the address (values 1-4) + */ +void dbg_SetReadWatchpoint(void *address, unsigned int length); + +/** + * Sets an emulated write watchpoint at a particular address + * + * @param address The address of the watchpoint to set + * @param length The size of the data at the address (values 1-4) + */ +void dbg_SetWriteWatchpoint(void *address, unsigned int length); + +/** + * Sets an emulated read/write watchpoint at a particular address + * + * @param address The address of the watchpoint to set + * @param length The size of the data at the address (values 1-4) + */ +void dbg_SetReadWriteWatchpoint(void *address, unsigned int length); + +/** + * Removes an emulated watchpoint at a particular address + * + * @param address The address of the watchpoint to remove + */ +void dbg_RemoveWatchpoint(void *address); + +/** + * Removes all emulated watchpoints + */ +void dbg_RemoveAllWatchpoints(void); + +/** + * Removes all emulated breakpoints + */ +void dbg_RemoveAllBreakpoints(void); + +#define dbgout ((char*)0xFB0000) /**< Standard debug output */ +#define dbgerr ((char*)0xFC0000) /**< Error debug output */ +#define dbg_sprintf sprintf +#define dbg_ClearConsole() (*(unsigned char*)0xFD0000 = 1) +#else +#define dbg_Debugger(ignore) ((void)0) +#define dbg_SetBreakpoint(ignore) ((void)0) +#define dbg_RemoveBreakpoint(ignore) ((void)0) +#define dbg_SetWatchpoint(ignore,ignore) ((void)0) +#define dbg_SetReadWatchpoint(ignore,ignore) ((void)0) +#define dbg_SetWriteWatchpoint(ignore,ignore) ((void)0) +#define dbg_SetReadWriteWatchpoint(ignore,ignore) ((void)0) +#define dbg_RemoveWatchpoint(ignore) ((void)0) +#define dbg_RemoveAllWatchpoints(ignore) ((void)0) +#define dbg_RemoveAllBreakpoints(ignore) ((void)0) +#define dbg_sprintf if(0)(void) +#define dbg_ClearConsole(ignore) ((void)0) +#define dbgout (NULL) +#define dbgerr (NULL) +#endif + +#ifdef __cplusplus +} +#endif diff --git a/frontends/calculator/CEdev/include/decompress.h b/frontends/calculator/CEdev/include/decompress.h new file mode 100644 index 0000000..451008b --- /dev/null +++ b/frontends/calculator/CEdev/include/decompress.h @@ -0,0 +1,23 @@ +/** + * @file + * @author Matt "MateoConLechuga" Waltz + * @brief Optimized decompression routines + */ + +#ifndef DECOMPRESS_H +#define DECOMPRESS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#warning compatibility defines (do not use) +void dzx7_Turbo(void *src, void *dst); +void dzx7_Standard(void *src, void *dst); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/frontends/calculator/CEdev/include/errno.h b/frontends/calculator/CEdev/include/errno.h new file mode 100644 index 0000000..f72dfef --- /dev/null +++ b/frontends/calculator/CEdev/include/errno.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + * Modified by Matt "MateoConLechuga" Waltz for TI84+CE platform + */ +#ifndef ERRNO_H +#define ERRNO_H + +#define ERR_NOR 1 /* read not allowed for file */ +#define ERR_NOW 2 /* write not allowed for file */ +#define ERR_IO 3 /* io error */ +#define EDOM 4 /* domain error */ +#define ERANGE 5 /* range error */ +extern int errno; +#endif diff --git a/frontends/calculator/CEdev/include/fasmg-ez80/ez80.inc b/frontends/calculator/CEdev/include/fasmg-ez80/ez80.inc new file mode 100644 index 0000000..6e8e005 --- /dev/null +++ b/frontends/calculator/CEdev/include/fasmg-ez80/ez80.inc @@ -0,0 +1,862 @@ +define @ez80 @ez80 +macro @ez80.suffix @l, @il* + @ez80.l = @l + @ez80.il = @il + @ez80.lil = @ez80.l or @ez80.il shl 1 + @ez80.pre = @ez80.lil or @ez80.lil shl 3 or 100o +end macro +macro @ez80.byte @values*& + db @values +end macro +macro @ez80.offset @value* + local value + value = @value + if elementsof value + err 'invalid offset' + else if value < -200o | 200o <= value + err 'offset is out of range' + end if + db value +end macro +macro @ez80.word @value* + local value + value = @value + if elementsof value + err 'invalid immediate' + end if + emit word + @ez80.il: @value +end macro +macro @ez80.idxpre @regs*& + local pre + iterate @reg, @regs + pre = @reg metadata 1 scale 1 + if pre > 300o + @ez80.byte pre + break + end if + end iterate +end macro +macro @ez80.idxoff @reg* + local reg + reg = @reg + if reg metadata 1 scale 1 > 300o + @ez80.offset @reg scale 0 + else if reg scale 0 + err 'invalid arguments' + end if +end macro +macro @ez80.emit @values*& + if defined @ez80.pre + db @ez80.pre + end if + iterate @value, @values + @ez80.@value + end iterate +end macro +macro @ez80.nest @inst*& + if defined @ez80.pre + @ez80.pre =: @ez80.pre + end if + @inst +end macro +macro @ez80.check @ind*, @expr& + match @left ) @right, <@expr> + match @ ( @mid, <@left> + @ez80.check @ind, @mid @right + else + @ind =: 0 + end match + else + @ind =: 1 + end match +end macro +macro @ez80.classify @val, @ind*, @arg& + match, @arg + @ind =: 0 + else + @val =: @arg + match ( @ ), @arg + @ez80.check @ind, @ + else + @ind =: 0 + end match + end match +end macro + +long? = 3 +; FIXME: dup relocations +macro dw? @values*& + if @ez80.adl + emit word?: @values + else + match left =dup? right, @values + emit word?: @values + else + iterate @value, @values + @ez80.word @value + end iterate + end match + end if +end macro +macro dl? @values*& + if @ez80.adl + match left =dup? right, @values + emit long?: @values + else + iterate @value, @values + @ez80.word @value + end iterate + end match + else + emit long?: @values + end if +end macro +iterate @name, dw, rw, dl, rl + struc (name) @name? @values*& + label name: long? + @name? @values + end struc +end iterate +macro assume? @expr* + match =adl? == @adl, @expr + local adl + adl = @adl + if adl = adl and 1 + @ez80.l = adl + @ez80.il = adl + @ez80.adl = adl + else + err 'adl assume should be 0 or 1' + end if + else + err 'invalid assume statement' + end match +end macro +assume? adl = 1 + +element @ez80.breg +element b?: @ez80.breg * 003o + 030o +element nz?: @ez80.breg * 010o + 001o +element z?: @ez80.breg * 010o + 011o +element nc?: @ez80.breg * 010o + 021o +element c?: @ez80.breg * 003o + 031o +element po?: @ez80.breg * 010o + 041o +element pe?: @ez80.breg * 010o + 051o +nv? = po? +v? = pe? +element p?: @ez80.breg * 010o + 061o +element m?: @ez80.breg * 010o + 071o +element d?: @ez80.breg * 003o + 032o +element e?: @ez80.breg * 003o + 033o +element h?: @ez80.breg * 003o + 034o +element ixh?: @ez80.breg * 335o + 034o +element iyh?: @ez80.breg * 375o + 034o +element l?: @ez80.breg * 003o + 035o +element ixl?: @ez80.breg * 335o + 035o +element iyl?: @ez80.breg * 375o + 035o +element f?: @ez80.breg * 002o + 036o +element a?: @ez80.breg * 003o + 037o + +element @ez80.irmb +element i?: @ez80.irmb * 107o + 127o +element r?: @ez80.irmb * 117o + 137o +element mb?: @ez80.irmb * 155o + 156o + +element @ez80.wreg +element bc?: @ez80.wreg * 007o + 000o +element de?: @ez80.wreg * 007o + 020o +element hl?: @ez80.wreg * 007o + 040o +element ix?: @ez80.wreg * 335o + 040o +element iy?: @ez80.wreg * 375o + 040o +element sp?: @ez80.wreg * 006o + 060o +element af?: @ez80.wreg * 001o + 060o +element af'? + +@ez80.is_reg equ metadata 1 element 1 eq + +macro inst! @name*, @params& + restore @name? + define @name? @name? + @ez80.oplist equ @name? + namespace @name? + macro s? @args& + @ez80.suffix 0, @ez80.il + @name? @args + end macro + macro l? @args& + @ez80.suffix 1, @ez80.il + @name? @args + end macro + macro is? @args& + @ez80.suffix @ez80.l, 0 + @name? @args + end macro + macro il? @args& + @ez80.suffix @ez80.l, 1 + @name? @args + end macro + macro sis? @args& + @ez80.suffix 0, 0 + @name? @args + end macro + macro lis? @args& + @ez80.suffix 1, 0 + @name? @args + end macro + macro sil? @args& + @ez80.suffix 0, 1 + @name? @args + end macro + macro lil? @args& + @ez80.suffix 1, 1 + @name? @args + end macro + end namespace + local @temp + virtual + iterate @param, @params + match @arg @, @param* + @temp = string `@arg shr 8 + db 'local ', @temp, ', ', @temp, 'ind', 10 + match @arg &, @param + db 'iterate @, ', `@arg, 10, 9, 'indx %%-%+1', 10, 9 + end match + db '@ez80.classify ', @temp, ', ', @temp, 'ind, ' + match @@ &, @param + db '@', 10, 'end iterate', 10 + else + db `@arg, 10 + end match + end match + end iterate + load @temp: $ - $$ from $$ + end virtual + esc macro @name?: @params + local before, after, noerr + label before + eval @temp +end macro +macro end?.inst! + label after + if ~defined noerr & before = after + err 'invalid arguments' + end if + restore @ez80.pre + assume? adl = @ez80.adl + esc end macro +end macro + +iterate <@name, @opc*>, \ + nop, 000o, \ + rlca, 007o, \ + rrca, 017o, \ + rla, 027o, \ + rra, 037o, \ + daa, 047o, \ + cpl, 057o, \ + scf, 067o, \ + ccf, 077o, \ + halt, 166o, \ + exx, 331o, \ + di, 363o, \ + ei, 373o, \ + neg, <355o, 104o>, \ + retn, <355o, 105o>, \ + reti, <355o, 115o>, \ + rrd, <355o, 147o>, \ + rld, <355o, 157o>, \ + slp, <355o, 166o>, \ + stmix, <355o, 175o>, \ + rsmix, <355o, 176o>, \ + inim, <355o, 202o>, \ + otim, <355o, 203o>, \ + ini2, <355o, 204o>, \ + indm, <355o, 212o>, \ + otdm, <355o, 213o>, \ + ind2, <355o, 214o>, \ + inimr, <355o, 222o>, \ + otimr, <355o, 223o>, \ + ini2r, <355o, 224o>, \ + indmr, <355o, 232o>, \ + otdmr, <355o, 233o>, \ + ind2r, <355o, 234o>, \ + ldi, <355o, 240o>, \ + cpi, <355o, 241o>, \ + ini, <355o, 242o>, \ + outi, <355o, 243o>, \ + outi2, <355o, 244o>, \ + ldd, <355o, 250o>, \ + cpd, <355o, 251o>, \ + ind, <355o, 252o>, \ + outd, <355o, 253o>, \ + outd2, <355o, 254o>, \ + ldir, <355o, 260o>, \ + cpir, <355o, 261o>, \ + inir, <355o, 262o>, \ + otir, <355o, 263o>, \ + oti2r, <355o, 264o>, \ + lddr, <355o, 270o>, \ + cpdr, <355o, 271o>, \ + indr, <355o, 272o>, \ + otdr, <355o, 273o>, \ + otd2r, <355o, 274o>, \ + inirx, <355o, 302o>, \ + otirx, <355o, 303o>, \ + indrx, <355o, 312o>, \ + otdrx, <355o, 313o> + inst @name + @ez80.emit <byte @opc> + end inst +end iterate + +iterate @name, inc, dec + inst @name, @reg* + if regind + if reg relativeto reg element 1 & reg @ez80.is_reg @ez80.wreg \ + & reg metadata 1 scale 0 = 040o + @ez80.emit idxpre reg, byte 063o + %, idxoff reg + end if + else if reg eq reg element 1 + if reg @ez80.is_reg @ez80.wreg & reg metadata 1 scale 1 and 004o + @ez80.emit idxpre reg, byte reg metadata 1 scale 0 - 005o \ + + % shl 3 + else if reg @ez80.is_reg @ez80.breg \ + & reg metadata 1 scale 1 and 001o + @ez80.emit idxpre reg, byte reg metadata 1 scale 0 shl 3 \ + and 070o or % + 3 + end if + end if + end inst +end iterate + +inst ex, @arg1, @arg2* + if arg1ind + if arg2ind + err 'invalid indirection' + else if arg1 eq sp? & arg2 eq arg2 element 1 \ + & arg2 @ez80.is_reg @ez80.wreg & arg2 metadata 1 scale 0 = 040o + @ez80.emit idxpre arg2, byte 343o + end if + else if arg2ind + @ez80.nest ex? @arg2, @arg1 + else if (arg1 eq af? & arg2 eq af'?) | (arg1 eq af'? & arg2 eq af?) + @ez80.emit byte 010o + else if (arg1 eq de? & arg2 eq hl?) | (arg1 eq hl? & arg2 eq de?) + @ez80.emit byte 353o + end if +end inst + +inst djnz, @addr* + if addrind + err 'invalid indirection' + else + @ez80.emit byte 020o, offset addr - after + end if +end inst +inst jr, @arg1*, @arg2 + if arg1ind | arg2ind + err 'invalid indirection' + else if ~defined arg2 + @ez80.emit byte 030o, offset arg1 - after + else + if arg1 eq arg1 element 1 & arg1 @ez80.is_reg @ez80.breg \ + & arg1 metadata 1 scale 0 and 047o = 001o + @ez80.emit byte arg1 metadata 1 scale 0 and 030o or 040o, \ + offset arg2 - after + end if + end if +end inst +inst jq, @arg1*, @arg2 + local off, keep + if arg1ind | arg2ind + err 'invalid indirection' + else if ~defined arg2 + off = arg1 - before - 2 + if defined @ez80.pre + off = off - 1 + end if + if defined noerr & ~arg1 eq after | defined keep + define keep + end if + if defined after & arg1 eq after & ~defined keep + define noerr + else if ~elementsof off & -200o <= off & off < 200o + @ez80.emit byte 030o, offset off + else + @ez80.emit byte 303o, word arg1 + end if + else if arg1 eq arg1 element 1 & arg1 @ez80.is_reg @ez80.breg \ + & arg1 metadata 1 scale 0 and 007o = 001o + off = arg2 - before - 2 + if defined @ez80.pre + off = off - 1 + end if + if defined noerr & ~arg2 eq after | defined keep + define keep + end if + if defined after & arg2 eq after & ~defined keep + define noerr + else if arg1 metadata 1 scale 0 < 040o & ~elementsof off & -200o <= off & off < 200o + @ez80.emit byte arg1 metadata 1 scale 0 and 030o or 040o, \ + offset off + else + @ez80.emit byte arg1 metadata 1 scale 0 and 070o or 302o, \ + word arg2 + end if + end if +end inst + +inst ld, @dst, @src* + local opc + if dstind & srcind + err 'invalid indirection' + else if dstind + if dst relativeto dst element 1 & dst @ez80.is_reg @ez80.wreg + if dst metadata 1 scale 0 = 040o + if src eq src element 1 & src @ez80.is_reg @ez80.breg \ + & src metadata 1 scale 1 = 003o + @ez80.emit idxpre dst, byte src metadata 1 scale 0 \ + and 007o or 160o, idxoff dst + else if src eq src element 1 & src @ez80.is_reg @ez80.wreg \ + & src metadata 1 scale 1 and 005o = 005o + opc = src metadata 1 scale 0 or 017o + if src metadata 1 scale 1 > 300o + if dst metadata 1 scale 1 xor src metadata 1 scale 1 \ + and 040o + opc = opc + 017o + else + opc = opc + 020o + end if + end if + if dst metadata 1 scale 1 > 300o + @ez80.emit idxpre dst, byte opc, idxoff dst + else + @ez80.emit <byte 355o, opc> + end if + else + @ez80.emit idxpre dst, byte 066o, idxoff dst, byte src + end if + else if src eq a? & dst metadata 1 scale 0 < 040o + @ez80.emit byte dst metadata 1 scale 0 or 002o + end if + else if src eq a? + @ez80.emit byte 062o, word dst + else if src eq src element 1 & src @ez80.is_reg @ez80.wreg \ + & src metadata 1 scale 1 and 004o + if src metadata 1 scale 0 = 040o + @ez80.emit idxpre src, byte 042o, word dst + else + @ez80.emit <byte 355o, src metadata 1 scale 0 or 103o>, word dst + end if + end if + else if srcind + if ~dst eq dst element 1 + else if src relativeto src element 1 & src @ez80.is_reg @ez80.wreg + if src metadata 1 scale 0 = 040o + if dst @ez80.is_reg @ez80.breg & dst metadata 1 scale 1 = 003o + @ez80.emit idxpre src, byte dst metadata 1 scale 0 \ + shl 3 and 070o or 106o, idxoff src + else if dst @ez80.is_reg @ez80.wreg \ + & dst metadata 1 scale 1 and 005o = 005o + opc = dst metadata 1 scale 0 or 007o + if dst metadata 1 scale 1 > 300o + if dst metadata 1 scale 1 xor src metadata 1 scale 1 \ + and 040o + opc = opc + 012o + else + opc = opc + 020o + end if + end if + if src metadata 1 scale 1 > 300o + @ez80.emit idxpre src, byte opc, idxoff src + else + @ez80.emit <byte 355o, opc> + end if + end if + else if dst eq a? & src metadata 1 scale 0 < 040o + @ez80.emit byte src metadata 1 scale 0 or 012o + end if + else if dst eq a? + @ez80.emit byte 072o, word src + else if dst @ez80.is_reg @ez80.wreg & dst metadata 1 scale 1 and 004o + if dst metadata 1 scale 0 = 040o + @ez80.emit idxpre dst, byte 052o, word src + else + @ez80.emit <byte 355o, dst metadata 1 scale 0 or 113o>, word src + end if + end if + else if dst eq dst element 1 + if dst @ez80.is_reg @ez80.breg + if src eq src element 1 & src @ez80.is_reg @ez80.breg \ + & dst metadata 1 scale 1 and src metadata 1 scale 1 and 001o \ + & (dst metadata 1 scale 0 xor src metadata 1 scale 0 and 006o \ + | dst metadata 1 scale 1 = src metadata 1 scale 1) \ + & (~dst eq src | dst metadata 1 scale 0 > 033o) + @ez80.emit <idxpre dst, src>, \ + byte dst metadata 1 scale 0 shl 3 and 070o \ + + src metadata 1 scale 0 and 007o or 100o + else if src eq src element 1 & src @ez80.is_reg @ez80.irmb \ + & dst eq a? + @ez80.emit <byte 355o, src metadata 1 scale 0> + else if dst metadata 1 scale 1 and 001o + @ez80.emit idxpre dst, \ + byte dst metadata 1 scale 0 shl 3 and 070o or 006o, \ + byte src + end if + else if dst @ez80.is_reg @ez80.wreg & dst metadata 1 scale 1 and 004o + if dst eq sp? & src eq src element 1 & src @ez80.is_reg @ez80.wreg \ + & src metadata 1 scale 0 = 040o + @ez80.emit idxpre src, byte 371o + else if dst eq hl? & src eq i? + @ez80.emit <byte 355o, 327o> + else + @ez80.emit idxpre dst, byte dst metadata 1 scale 0 or 001o, \ + word src + end if + else if dst @ez80.is_reg @ez80.irmb & src eq a? + @ez80.emit <byte 355o, dst metadata 1 scale 1> + else if dst eq i? & src eq hl? + @ez80.emit <byte 355o, 307o> + end if + end if +end inst + +inst add, @arg1*, @arg2 + if ~defined arg2 + @ez80.nest a?, @arg1 + else if arg1ind + err 'invalid indirection' + else if arg1 eq a? + if arg2ind + if arg2 relativeto arg2 element 1 & arg2 @ez80.is_reg @ez80.wreg \ + & arg2 metadata 1 scale 0 = 040o + @ez80.emit idxpre arg2, byte 206o, idxoff arg2 + end if + else if arg2 eq arg2 element 1 & arg2 @ez80.is_reg @ez80.breg \ + & arg2 metadata 1 scale 1 and 001o + @ez80.emit idxpre arg2, byte arg2 metadata 1 scale 0 and 007o \ + or 200o + else + @ez80.emit <byte 306o, arg2> + end if + else if arg2ind + err 'invalid indirection' + else if arg1 eq arg1 element 1 & arg1 @ez80.is_reg @ez80.wreg \ + & arg2 eq arg2 element 1 & arg1 @ez80.is_reg @ez80.wreg \ + & arg1 metadata 1 scale 0 = 040o & arg2 metadata 1 scale 1 and 004o \ + & (arg1 metadata 1 scale 0 <> arg2 metadata 1 scale 0 \ + | arg1 metadata 1 scale 1 = arg2 metadata 1 scale 1) + @ez80.emit idxpre arg1, byte arg2 metadata 1 scale 0 or 011o + end if +end inst +iterate @name, adc, sbc + inst @name, @arg1*, @arg2 + if ~defined arg2 + if arg1 @ez80.is_reg @ez80.wreg + @ez80.nest hl?, @arg1 + else + @ez80.nest a?, @arg1 + end if + else if arg1ind + err 'invalid indirection' + else if arg1 eq a? + if arg2ind + if arg2 relativeto arg2 element 1 \ + & arg2 @ez80.is_reg @ez80.wreg \ + & arg2 metadata 1 scale 0 = 040o + @ez80.emit idxpre arg2, byte 176o + % shl 4, idxoff arg2 + end if + else if arg2 eq arg2 element 1 & arg2 @ez80.is_reg @ez80.breg \ + & arg2 metadata 1 scale 1 and 001o + @ez80.emit idxpre arg2, byte arg2 metadata 1 scale 0 and 007o \ + or 170o + % shl 4 + else + @ez80.emit <byte 276o + % shl 4, arg2> + end if + else if arg2ind + err 'invalid indirection' + else if arg1 eq hl? & arg2 eq arg2 element 1 \ + & arg2 @ez80.is_reg @ez80.wreg \ + & arg2 metadata 1 scale 1 and 002o + @ez80.emit <byte 355o, arg2 metadata 1 scale 0 + 122o - % shl 3> + end if + end inst +end iterate +iterate <@name, @opc*>, \ + sub, 220o, \ + and, 240o, \ + xor, 250o, \ + or, 260o, \ + cp, 270o + inst @name, @arg1*, @arg2 + if ~defined arg2 + if arg1ind + if arg1 relativeto arg1 element 1 \ + & arg1 @ez80.is_reg @ez80.wreg \ + & arg1 metadata 1 scale 0 = 040o + @ez80.emit idxpre arg1, byte @opc or 006o, idxoff arg1 + end if + else if arg1 relativeto arg1 element 1 \ + & arg1 @ez80.is_reg @ez80.breg \ + & arg1 metadata 1 scale 1 and 001o + @ez80.emit idxpre arg1, byte arg1 metadata 1 scale 0 and 007o \ + or @opc + else + @ez80.emit <byte @opc or 106o, arg1> + end if + else if arg1ind + err 'invalid indirection' + else if arg1 eq a? + @ez80.nest @name? @arg2 + end if + end inst +end iterate +inst tst, @arg1*, @arg2 + if ~defined arg2 + if arg1ind + if arg1 eq hl? + @ez80.emit <byte 355o, 064o> + end if + else if arg1 eq arg1 element 1 & arg1 @ez80.is_reg @ez80.breg \ + & arg1 metadata 1 scale 1 = 003o + @ez80.emit <byte 355o, \ + arg1 metadata 1 scale 0 shl 3 and 070o or 004o> + else + @ez80.emit <byte 355o, 144o, arg1> + end if + else if arg1ind + err 'invalid indirection' + else if arg1 eq a? + @ez80.nest tst? @arg2 + end if +end inst + +inst ret, @cond + if ~defined cond + @ez80.emit byte 311o + else if condind + err 'invalid indirection' + else if cond eq cond element 1 & cond @ez80.is_reg @ez80.breg \ + & cond metadata 1 scale 0 and 007o = 001o + @ez80.emit byte cond metadata 1 scale 0 and 070o or 300o + end if +end inst +iterate @name, pop, push + inst @name, @reg*& + while defined reg + regind + if regind + err 'invalid indirection' + else if reg eq reg element 1 & reg @ez80.is_reg @ez80.wreg \ + & reg metadata 1 scale 1 and 001o + @ez80.emit idxpre reg, \ + byte reg metadata 1 scale 0 + 275o + % shl 2 + else if `@name = 'push' + @ez80.nest pea? reg + else + err 'invalid argument' + end if + restore reg, regind + end while + end inst +end iterate + +inst jp, @arg1*, @arg2 + if ~defined arg2 + if ~arg1ind + @ez80.emit byte 303o, word arg1 + else if arg1 eq arg1 element 1 & arg1 @ez80.is_reg @ez80.wreg \ + & arg1 metadata 1 scale 0 = 040o + @ez80.emit idxpre arg1, byte 351o + end if + else if arg1ind | arg2ind + err 'invalid indirection' + else if arg1 eq arg1 element 1 & arg1 @ez80.is_reg @ez80.breg \ + & arg1 metadata 1 scale 0 and 007o = 001o + @ez80.emit byte arg1 metadata 1 scale 0 and 070o or 302o, word arg2 + end if +end inst +inst call, @arg1*, @arg2 + if arg1ind | arg2ind + err 'invalid indirection' + else if ~defined arg2 + @ez80.emit byte 315o, word arg1 + else if arg1 eq arg1 element 1 & arg1 @ez80.is_reg @ez80.breg \ + & arg1 metadata 1 scale 0 and 007o = 001o + @ez80.emit byte arg1 metadata 1 scale 0 and 070o or 304o, word arg2 + end if +end inst +inst rst, @addr* + if addrind + err 'invalid indirection' + else if addr = addr and 070o + @ez80.emit byte addr or 307o + else + err 'invalid rst target' + end if +end inst + +iterate <@name, @opc*>, \ + rlc, 000o, \ + rrc, 010o, \ + rl, 020o, \ + rr, 030o, \ + sla, 040o, \ + sra, 050o, \ + srl, 070o + inst @name, @reg* + if `@name = 'rl' & ~defined @ez80.pre & ~elementsof reg + rb long? * reg + define noerr + else if regind + if reg relativeto reg element 1 & reg @ez80.is_reg @ez80.wreg \ + & reg metadata 1 scale 0 = 040o + @ez80.emit idxpre reg, byte 313o, idxoff reg, byte @opc or 006o + end if + else if reg eq reg element 1 & reg @ez80.is_reg @ez80.breg \ + & reg metadata 1 scale 1 = 003o + @ez80.emit <byte 313o, reg metadata 1 scale 0 and 007o or @opc> + end if + end inst +end iterate +iterate @name, bit, res, set + inst @name, @bit, @reg* + if bitind + err 'invalid indirection' + else if regind + if reg relativeto reg element 1 & reg @ez80.is_reg @ez80.wreg \ + & reg metadata 1 scale 0 = 040o + @ez80.emit idxpre reg, byte 313o, idxoff bit shr 3 + reg, \ + byte bit shl 3 and 070o or % shl 6 or 006o + end if + else if reg eq reg element 1 + if reg @ez80.is_reg @ez80.breg & reg metadata 1 scale 1 = 003o \ + & bit = bit and 007o + @ez80.emit <byte 313o, reg metadata 1 scale 0 and 007o \ + or % shl 6 or bit shl 3> + else if reg @ez80.is_reg @ez80.wreg \ + & reg metadata 1 scale 1 = 007o & bit = bit and 017o + @ez80.emit <byte 313o, bit shl 3 and 070o or % shl 6 \ + or reg metadata 1 scale 0 shr 3 \ + or 001o and not bit shr 3> + end if + end if + end inst +end iterate + +inst out, @port, @reg* + if ~portind + err 'missing indirection' + else if regind + err 'invalid indirection' + else if port eq bc? | port eq c? + if reg eq reg element 1 & reg @ez80.is_reg @ez80.breg \ + & reg metadata 1 scale 1 = 003o + @ez80.emit <byte 355o, reg metadata 1 scale 0 shl 3 and 070o \ + or 101o> + else if ~reg + @ez80.emit <byte 355o, 161o> + end if + else if reg eq a? + @ez80.emit <byte 323o, port> + end if +end inst +inst in, @reg*, @port + if ~defined port + @ez80.nest in? f?, @reg + else if regind + err 'invalid indirection' + else if ~portind + err 'missing indirection' + else if port eq bc? | port eq c? & reg eq reg element 1 \ + & reg @ez80.is_reg @ez80.breg & reg metadata 1 scale 1 and 002o + @ez80.emit <byte 355o, reg metadata 1 scale 0 shl 3 and 070o \ + or 100o> + else if reg eq a? + @ez80.emit <byte 333o, port> + end if +end inst +inst in0, @reg*, @port + if ~defined port + @ez80.nest in0? f?, @reg + else if regind + err 'invalid indirection' + else if ~portind + err 'missing indirection' + else if reg eq reg element 1 & reg @ez80.is_reg @ez80.breg \ + & reg metadata 1 scale 1 and 002o + @ez80.emit <byte 355o, reg metadata 1 scale 0 shl 3 and 070o \ + or 000o, port> + end if +end inst +inst out0, @port, @reg* + if ~portind + err 'missing indirection' + else if regind + err 'invalid indirection' + else if reg eq reg element 1 & reg @ez80.is_reg @ez80.breg \ + & reg metadata 1 scale 1 = 003o + @ez80.emit <byte 355o, reg metadata 1 scale 0 shl 3 and 070o \ + or 001o, port> + end if +end inst +inst tstio, @src* + if srcind + err 'invalid indirection' + else + @ez80.emit <byte 355o, 164o, src> + end if +end inst + +inst lea, @dst, @src* + if dstind | srcind + err 'invalid indirection' + else if dst eq dst element 1 & src relativeto src element 1 \ + & dst @ez80.is_reg @ez80.wreg & src @ez80.is_reg @ez80.wreg \ + & dst metadata 1 scale 0 <> 060o & src metadata 1 scale 1 > 300o + local opc + if dst metadata 1 scale 1 and 002o + opc = src metadata 1 scale 1 shr 5 and 001o \ + or dst metadata 1 scale 0 or 002o + else if dst relativeto src + opc = dst metadata 1 scale 1 shr 5 and 001o or 062o + else + opc = dst metadata 1 scale 1 shr 5 and 001o or 124o + end if + @ez80.emit <byte 355o, opc>, offset src scale 0 + end if +end inst +inst pea, @src* + if srcind + err 'invalid indirection' + else if src relativeto src element 1 & src @ez80.is_reg @ez80.wreg \ + & src metadata 1 scale 1 > 300o + @ez80.emit <byte 355o, src metadata 1 scale 1 shr 5 and 001o + 145o>, \ + offset src scale 0 + end if +end inst + +inst im, @mode* + if modeind + err 'invalid indirection' + else if mode = 0 + @ez80.emit <byte 355o, 106o> + else if mode = 1 + @ez80.emit <byte 355o, 126o> + else if mode = 2 + @ez80.emit <byte 355o, 136o> + else + err 'invalid mode' + end if +end inst + +inst mlt, @reg* + if regind + err 'invalid indirection' + else if reg eq reg element 1 & reg @ez80.is_reg @ez80.wreg \ + & reg metadata 1 scale 1 and 002o + @ez80.emit <byte 355o, reg metadata 1 scale 0 or 114o> + end if +end inst + +purge inst +purge end?.inst diff --git a/frontends/calculator/CEdev/include/fasmg-ez80/ld.fasmg b/frontends/calculator/CEdev/include/fasmg-ez80/ld.fasmg new file mode 100644 index 0000000..e7bdbf8 --- /dev/null +++ b/frontends/calculator/CEdev/include/fasmg-ez80/ld.fasmg @@ -0,0 +1,759 @@ +assert "\"" = '"' ; check for patched fasmg +include 'tiformat.inc' +define ez80 ez80 +namespace ez80 + include 'ez80.inc' +end namespace +macro ?! $ : $ , \ + $@ : $@ , \ + $$ : $$ , \ + and : and , \ + assert : assert , \ + at : at , \ + break : break , \ + define : define , \ + defined : defined , \ + dup : dup , \ + else : else , \ + emit : emit , \ + end : end , \ + equ : equ , \ + err : err , \ + esc : esc , \ + ez80 : ez80 , \ + from : from , \ + if : if , \ + include : include , \ + irpv : irpv , \ + iterate : iterate , \ + label : label , \ + lengthof : lengthof , \ + load : load , \ + local : local , \ + macro : macro , \ + match : match , \ + mod : mod , \ + namespace: namespace, \ + not : not , \ + or : or , \ + purge : purge , \ + rb : rb , \ + repeat : repeat , \ + restore : restore , \ + restruc : restruc , \ + rawmatch : rawmatch , \ + segment : segment , \ + shl : shl , \ + shr : shr , \ + store : store , \ + struc : struc , \ + used : used , \ + virtual : virtual , \ + while : while , \ + xor : xor + local global, debug, files, segments, hex, output + global equ + segments equ + restore global, segments + + macro files.libs.parse file, offset, isused, anyused* + local private + namespace private + macro library?! name, version* + end if + if anyused + emit 1: $C0, name, 0, version + end if + if 0 + end macro + iterate each, export, export_pointer + macro each?! function* + end if + namespace ez80 + if used global._#function + isused = 1 + global._#function := $ + %-1 + jp offset + virtual + local name + emit 1: '_', `function + load name: $ - $$ from $$ + global equ name = global._#function + end virtual + end if + offset = offset + word + @ez80.il + end namespace + if 0 + end macro + end iterate + if 0 + esc include! file + end if + end namespace + end macro + macro files.libs.handle file, isused* + local offset, anyused + offset = 0 + files.libs.parse file, offset, isused, anyused + anyused := isused + end macro + + macro files.srcs.check file, isused* + local private + namespace private + iterate name, DEF, GLOBAL, PUBLIC, XDEF + iterate style, name, .name + macro style?! symbols*& + end if + iterate symbol, symbols + if used global.symbol + isused = 1 + end if + end iterate + if 0 + end macro + end iterate + end iterate + if 0 + esc include! file + end if + end namespace + end macro + macro files.srcs.parse file* + local private + namespace private + virtual segments.code.area + ?$ equ $ + ?XOR? equ xor + ?AND? equ and + ?OR? equ or + ?SHL? equ shl + ?SHR? equ shr + ?NOT? equ not + iterate name, LIST, NEWPAGE, NOLIST, PAGE + macro name? + end macro + end iterate + iterate name, CPU, TITLE + macro name? arg* + end macro + end iterate + iterate name, COPY, INCLUDE + macro name?! path* + include path + end macro + end iterate + iterate name, EXTERN, EXTERNAL, REF, XREF + macro name? symbols*& + match list : space, symbols + iterate symbol, list + symbol := global.symbol + end iterate + else + iterate symbol, symbols + symbol := global.symbol + end iterate + end match + end macro + end iterate + iterate name, DEF, GLOBAL, PUBLIC, XDEF + macro name? symbols*& + iterate symbol, symbols + global.symbol := symbol + virtual + local name + emit 1: `symbol + load name: $ - $$ from $$ + global equ name = global.symbol + end virtual + end iterate + end macro + end iterate + struc (symbol) EQU? expr* + local error + if ~defined error & defined symbol | error + err 'Symbol "', `symbol, '" already defined' + error = 1 + else + error = 0 + end if + ?symbol = expr + end struc + iterate name, VAR, SET + struc (symbol) name? expr* + ?symbol = expr + end struc + end iterate + macro DS? count + local c + c = count + rb c + end macro + struc DS? count + .: DS? count + end struc + iterate <def,blk,size*>, B,B,1, W,W,2, W24,P,3, L,L,4 + macro D#def? vals*& + local v + iterate val, vals + v = val + emit size: v + end iterate + end macro + macro BLK#blk? count*, init + local c, i + c = count + match, init + emit size: c dup ? + else + i = init + emit size: c dup i + end match + end macro + iterate name, D#def, BLK#blk + struc name? args& + .: name? args + end struc + end iterate + end iterate + iterate <name,alias*>, TRIO,DW24, DF,DL + macro name? vals*& + alias? vals + end macro + struc name? args& + .: name? args + end struc + end iterate + macro ALIGN? val* + local v + v = val + rb v-1 - ($ + v-1) mod v + end macro + macro SEGMENT? name* + segment name + end macro + macro ASSUME? expr* + namespace ez80 + assume? expr + end namespace + end macro + iterate register, B, NZ, Z, NC, C, PO, PE, P, M, D, E, \ + H, IXH, IYH, L, IXL, IYL, F, A, I, R, \ + MB, BC, DE, HL, IX, IY, SP, AF, AF' + register? := ez80.register? + end iterate + iterate suffix, , .s?, .l?, .is?, .il?, .sis?, .sil?, .lis?, .lil? + irpv name, ez80.@ez80.oplist + rawmatch rawname, name + define rawname rawname + macro rawname#suffix args& + namespace ez80 + name#suffix args + end namespace + end macro + end rawmatch + end irpv + macro LD? d, s* + namespace ez80 + @ez80.classify dst, dstind, d + @ez80.classify src, srcind, s + if ~dstind & dst eq dst element 1 & dst @ez80.is_reg @ez80.wreg \ + & dst metadata 1 scale 1 and 001o & ~srcind \ + & src relativeto src element 1 & src @ez80.is_reg @ez80.wreg + if src metadata 1 scale 1 = 007o + PUSH? s + POP? d + else + LEA? d, s + end if + else + LD? d, s + end if + end namespace + end macro + macro JR?#suffix args& + namespace ez80 + jq?#suffix args + end namespace + end macro + end iterate + iterate <name,carry>, UEXT,<OR? A?,A>, SEXT,RLA + macro name? reg* + carry? + SBC? reg, reg + end macro + end iterate + macro COMMENT?! delim*& + end match + local inside + inside = 0 + macro ?! line& + local length, text + length = 0 + if inside + length = lengthof `line + text = `line + else if `line = 'end match' + inside = 1 + length = lengthof `delim - 1 + text = `delim shr 8 + end if + repeat length + if ~text xor `delim and $FF + purge ? + break + end if + text = text shr 8 + end repeat + end macro + end macro + + if defined debug + debug.enabled = 0 + debug.startAddr = $ + iterate name, ALIAS, BASE, DEFINE, ENDREC, SPACE, TAG + macro name? str1* + if debug.enabled + virtual debug + debug.uleb128 debug.name + debug.string str1 + end virtual + end if + end macro + end iterate + iterate name, BEGFUNC, ENDFUNC + macro name? str1, num1, str2* + if debug.enabled + local line, addr + line = num1 + addr = $ + virtual debug + debug.uleb128 debug.name + debug.string str1, str2 + debug.uleb128 line - debug.line, addr - debug.addr + end virtual + debug.line = line + debug.addr = addr + end if + end macro + end iterate + macro BEGREC? str1, num1* + if debug.enabled + virtual debug + debug.uleb128 debug.BEGREC + debug.string str1 + debug.uleb128 num1 + end virtual + end if + end macro + iterate <name,signed>, CLASS,u, DIM,u, LENGTH,u, REG,u, SIZE,u, TYPE,s, VALUE,s + macro name? num1* + if debug.enabled + virtual debug + debug.uleb128 debug.name + debug.signed#leb128 num1 + end virtual + end if + end macro + end iterate + macro DEBUG? str1* + virtual debug + debug.uleb128 debug.FILE, lengthof debug.source + emit 1: debug.source + debug.uleb128 debug.startAddr - debug.addr, debug.DEBUG + debug.string str1 + end virtual + debug.enabled = 1 + debug.line = 0 + debug.addr = debug.startAddr + end macro + macro END?! + end if + if debug.enabled + local addr + segment code + addr = $ + virtual debug + debug.uleb128 debug.END, addr - debug.addr + end virtual + debug.addr = addr + end if + if 0 + end macro + macro ENDEF? + if debug.enabled + virtual debug + debug.uleb128 debug.ENDEF + end virtual + end if + end macro + macro FILE? str1* + debug.source = str1 + end macro + macro LINE? num1* + local line, addr + line = num1 + addr = $ + if line <> debug.line | addr <> debug.addr & debug.enabled + virtual debug + debug.uleb128 debug.LINE, line - debug.line, addr - debug.addr + end virtual + debug.line = line + debug.addr = addr + end if + end macro + else + iterate name, ALIAS, BASE, BEGFUNC, BEGREC, CLASS, DEBUG, \ + DEFINE, DIM, ENDEF, ENDFUNC, ENDREC, FILE, \ + LENGTH, LINE, REG, SIZE, SPACE, TAG, TYPE, VALUE + macro name? args& + end macro + end iterate + macro END?! + end if + if 0 + end macro + end if + + struc ? def::& + . def + end struc + macro ? line& + match .rest, line + rest + else match first= .rest, line + first rest + else + line + end match + end macro + if 1 + include file + end if + purge ? + restruc ? + end virtual + end namespace + end macro + macro files.srcs.handle file, isused* + if ~isused + files.srcs.check file, isused + end if + if isused + files.srcs.parse file + end if + end macro + + macro symbol? args*& + iterate arg, args + rawmatch symbol == value, arg + namespace segments + global.symbol := value + virtual + local name + emit 1: `symbol + load name: $ - $$ from $$ + global equ = name global.symbol + end virtual + end namespace + else + 'Syntax error in symbol arguments' + end rawmatch + end iterate + end macro + + iterate name, srcs, libs + macro files.name.add file, used* + local isused + rawmatch rawused, used + namespace segments + isused = rawused + end namespace + end rawmatch + if `file and $FF = "'" + files.name equ file, isused + else + files.name equ `file, isused + end if + end macro + macro name? args*& + local require + iterate arg, args + match file= =used? =if?= used, arg + files.name.add file, used + else match file= =used?, arg + files.name.add file, 1 + else + files.name.add arg, 0 + end match + end iterate + end macro + end iterate + + macro locate? args*& + iterate arg, args + rawmatch name =at? location, arg + segments equ segments.name? + namespace segments + name? := `name + name.base? := location + end namespace + else + err 'Syntax error in locate argument' + end rawmatch + end iterate + end macro + macro range? args*& + iterate arg, args + rawmatch name lower : upper, arg + locate name at lower + namespace segments + name.high? := upper + end namespace + else + err 'Syntax error in range arguments' + end rawmatch + end iterate + end macro + macro order?: args*& + match first =, second =, rest, args + order first, second + order second, rest + else match first =, second, args + locate second at first.base + first.length + else + err 'Not enough order arguments' + end match + end macro + macro merge? args*& + match name == list, args + order list + iterate segment, list + locate name at segment.base + indx %% + namespace segments + name.top? := segment.base + segment.length + if defined segment.high + name.high? := segment.high + end if + end namespace + break + end iterate + else + err 'Syntax error in merge arguments' + end match + end macro + + macro hex value*, leading: '0', digits: 6 + local val, zero, digit, char + emit 1: ' ' + val = value + zero = leading + repeat digits + digit = (val shr ((%% - %) shl 2)) and 0Fh + if digit < 10 + char = '0' + digit + else + char = 'A' + digit - 10 + end if + if digit + zero = '0' + else if % <> %% + char = zero + end if + emit 1: char + end repeat + end macro + + macro map? + local longest, name + postpone ? + virtual as 'map' + longest = lengthof "Segment" + irpv segment, segments + if longest < lengthof segment + longest = lengthof segment + end if + end irpv + emit 1: "Segment", longest - lengthof "Segment" + 1 dup ' ', "Base Top High Length", 10, longest dup '-', 4 dup " ------", '-', 10 + irpv segment, segments + namespace segment + if longest < lengthof segment + longest = lengthof segment + end if + emit 1: segment, longest - lengthof segment dup ' ' + hex base + hex top + if defined high + hex high + else + emit 1: 7 dup ' ' + end if + hex length, ' ' + emit 1: 'h', 10 + end namespace + end irpv + match any, global + longest = lengthof "Label" + irpv symbol, global + match name == value, symbol + if longest < lengthof name + longest = lengthof name + end if + end match + end irpv + emit 1: 10, "Label", longest - lengthof "Label" + 3 dup ' ', "Value", 10, longest dup '-', 3 dup ' ', 6 dup '-', 10 + irpv symbol, global + match name == value, symbol + emit 1: name, longest - lengthof name + 1 dup ' ', '=' + hex value + emit 1: 10 + end match + end irpv + end match + end virtual + end postpone + end macro + macro dbg? + virtual as 'dbg' + debug:: + end virtual + namespace debug + virtual at 0 + iterate name, EOF, ALIAS, BASE, BEGFUNC, BEGREC, CLASS, DEBUG, DEFINE, \ + DIM, END, ENDEF, ENDFUNC, ENDREC, FILE, LENGTH, LINE, \ + REG, SIZE, SPACE, STRINGS, TAG, TYPE, VALUE + name rb 1 + end iterate + end virtual + line = 0 + addr = 0 + macro uleb128 values*& + iterate value, values + local val + val = value + assert val >= 0 + while val shr 7 > 0 + emit 1: val and 07Fh or 080h + val = val shr 7 + end while + emit 1: val + end iterate + end macro + macro sleb128 values*& + iterate value, values + local val + val = value + while val shr 6 <> 0 & val shr 6 <> -1 + emit 1: val and 07Fh or 080h + val = val shr 7 + end while + emit 1: val and 07Fh + end iterate + end macro + restore strings + macro string values*& + iterate value, values + local count, unfound + count = 0 + unfound = 1 + irpv each, debug.strings + if each = value + unfound = 0 + debug.uleb128 % + break + end if + count = %% + end irpv + if unfound + debug.uleb128 count + 1 + debug.strings =: value + end if + end iterate + end macro + end namespace + end macro + + macro segment name* + end virtual + virtual segments.name.area + end macro + + if ~defined segments + err 'No segments defined' + else + restore output.base, output.top ; forbid forward reference + irpv segment, segments + namespace segment + virtual at base + area?:: + end virtual + if ~defined output.base | output.base > base & ~defined high + output.base = base + end if + end namespace + end irpv + irpv file, files.srcs + files = 0 + files.srcs.handle file + end irpv + if ~defined files + err 'Please pass the input files with -i\'srcs "file1" [if require1], "file2" [if require2], ...\'' + end if + irpv file, files.libs + virtual segments.libs.area + files.libs.handle file + end virtual + end irpv + + if defined debug + virtual debug + if defined debug.strings + debug.uleb128 debug.STRINGS + irpv string, debug.strings + if % = 1 + debug.uleb128 %% + end if + debug.uleb128 lengthof string + emit 1: string + end irpv + end if + debug.uleb128 debug.EOF + end virtual + end if + + irpv segment, segments + namespace segment + virtual area + top? := $ + length? := $ - $$ + initlen? := $@ - $$ + end virtual + if ~defined high + if ~defined output.top | output.top < top + output.top = top + end if + else if top > high + repeat 1, len: length, over: top - high, max: high - base + err 'Segment ', segment, ' is ', `len, ' bytes, ', \ + `over, ' bytes larger than the maximum of ', \ + `max, ' bytes' + end repeat + end if + end namespace + end irpv + org output.base + rb output.top - $ + postpone ? + irpv segment, segments + namespace segment + if ~defined high + load output: initlen from area: base + store output: initlen at base + end if + end namespace + end irpv + end postpone + end if + purge ? +end macro diff --git a/frontends/calculator/CEdev/include/fasmg-ez80/ti84pceg.inc b/frontends/calculator/CEdev/include/fasmg-ez80/ti84pceg.inc new file mode 100644 index 0000000..73b7fc1 --- /dev/null +++ b/frontends/calculator/CEdev/include/fasmg-ez80/ti84pceg.inc @@ -0,0 +1,61 @@ +macro ?! + ; assign needs to be local so that it is only + ; defined once (no purge!) so that it can be + ; forward referenced so that it can recurse + local assign + macro assign: name*, expr& + match left =% right, expr + assign name, left mod right + else match left =| right, expr + assign name, left or right + else match left =& right, expr + assign name, left and right + else match left =^ right, expr + assign name, left xor right + else match left =<=< right, expr + assign name, left shl right + else match left =>=> right, expr + assign name, left shr right + else match left =~ right, expr + assign name, left not right + else match =~ right, expr + assign name, not right + else + name? := expr + end match + end macro + struc (name) equ? expr& + assign name, expr + end struc + macro Ld args& + match =equ? expr, args + assign name, expr + end match + end macro + purge ? +end macro + +macro .list? +end macro +macro .nolist? +end macro +macro #define? name +end macro +macro #ifdef? name +end macro +macro #ifndef? name +end macro +macro #endif? +end macro + +element anovaf_vars? +include 'ti84pce.inc' + +restruc equ? +purge Ld +purge .list? +purge .nolist? +purge #define? +purge #ifdef? +purge #ifndef? +purge #endif? diff --git a/frontends/calculator/CEdev/include/fasmg-ez80/tiformat.inc b/frontends/calculator/CEdev/include/fasmg-ez80/tiformat.inc new file mode 100644 index 0000000..23ec697 --- /dev/null +++ b/frontends/calculator/CEdev/include/fasmg-ez80/tiformat.inc @@ -0,0 +1,105 @@ +macro format?.ti? clause& + local all, checkloc, checksum, cplx, data, exec, flag, head, name, process, prot, temp, type, ext, var + macro process: setting + match first rest, setting + process first + process rest + else match =ARCHIVED?, setting + flag = flag or 1 shl 7 + else match =EXECUTABLE?, setting + define exec + else match =PROTECTED?, setting + type = 6 + define prot + else match =REAL?, setting + type = 0 + ext = '8xn' + else match =LIST?, setting + if defined cplx + type = 13 + else + type = 2 + end if + ext = '8xl' + else match =MATRIX?, setting + type = 2 + ext = '8xm' + else match =EQUATION?, setting + type = 3 + ext = '8xy' + else match =STRING?, setting + type = 4 + ext = '8xs' + else match =PROGRAM?, setting + if defined prot + type = 6 + else + type = 5 + end if + ext = '8xp' + else match =PICTURE?, setting + type = 7 + ext = '8ci' + else match =GDB?, setting + type = 1 + ext = '8xd' + else match =COMPLEX?, setting + type = 12 + define cplx + ext = '8xc' + else match =APPVAR?, setting + type = 21 + ext = '8xv' + else match =GROUP?, setting + type = 23 + ext = '8xg' + else match =IMAGE?, setting + type = 26 + ext = '8ca' + else if setting eqtype 'name' + name = setting + else if setting eqtype 0 + type = setting + ext = '8x' + end if + end macro + name = 'A' + type = 6 + ext = '8xp' + flag = 0 + process clause + format binary as ext + assert ~$% & 'Unexpected data before format directive' + dq '**TI83F*' + db 26, 10, 0 + rb 42 + dw sizeof all + label all: checkloc - $% + dw sizeof head, sizeof data + label head: data - $ + db type + dq name + db 0, flag + dw sizeof data + label data: checkloc - $% + dw sizeof var + label var: checkloc - $% + if defined exec + dw 07BEFh + org 0D1A881h + else + org 0 + end if + postpone + label checkloc at $% + end postpone + postpone ? + assert checkloc = $% & 'Unexpected postpone before format directive' + checksum = 0 + repeat sizeof all + load temp: byte from: all + %-1 + checksum = (checksum + temp) and 0FFFFh + end repeat + dw checksum + end postpone +end macro diff --git a/frontends/calculator/CEdev/include/fileioc.h b/frontends/calculator/CEdev/include/fileioc.h new file mode 100644 index 0000000..e703143 --- /dev/null +++ b/frontends/calculator/CEdev/include/fileioc.h @@ -0,0 +1,509 @@ +/** + * @file + * @author Matt "MateoConLechuga" Waltz + * @brief Implements variable reading and writing routines + */ + +#ifndef H_FILEIOC +#define H_FILEIOC + +#include <stdint.h> +#include <stddef.h> +#include <stdlib.h> +#include <stdbool.h> +#include <stdio.h> +#include <tice.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Varible and flag definitions */ +#define TI_PRGM_TYPE (0x05) +#define TI_PPRGM_TYPE (0x06) +#define TI_TPRGM_TYPE (0x16) +#define TI_APPVAR_TYPE (0x15) +#define TI_REAL_TYPE (0x00) +#define TI_CPLX_TYPE (0x0C) +#define TI_MATRIX_TYPE (0x02) +#define TI_STRING_TYPE (0x04) +#define TI_EQU_TYPE (0x03) +#define TI_REAL_LIST_TYPE (0x01) +#define TI_CPLX_LIST_TYPE (0x0D) + +#ifndef EOF +#define EOF (-1) +#endif + +/** + * @brief Variable slot type + */ +typedef uint8_t ti_var_t; + +/** + * Closes all open slots + * @warning Call before you use any variable functions + */ +void ti_CloseAll(void); + +/** + * Opens a file + * + * An AppVar is used as default file storage + * @param name Name of file to open + * @param mode + * "r" - Opens a file for reading. The file must exist. Keeps file in archive if in archive. <br> + * "w" - Creates an empty file for writing. Overwrites file if already exists. <br> + * "a" - Appends to a file. Writing operations, append data at the end of the file. The file is created if it does not exist. <br> + * "r+" - Opens a file to update both reading and writing. The file must exist. Moves file from archive to RAM if in archive. <br> + * "w+" - Creates an empty file for both reading and writing. Overwrites file if already exists. <br> + * "a+" - Opens a file for reading and appending. Moves file from archive to RAM if in archive. Created if it does not exist. + * @returns Slot variable + * @note If there isn't enough memory to create the variable, or a slot isn't open, zero (0) is returned + */ +ti_var_t ti_Open(const char *name, const char *mode); + +/** + * Opens a variable + * + * Can open any type of program or appvar variable + * @param varname Name of variable to open + * @param mode + * "r" - Opens a file for reading. The file must exist. Keeps file in archive if in archive. <br> + * "w" - Creates an empty file for writing. Overwrites file if already exists. <br> + * "a" - Appends to a file. Writing operations, append data at the end of the file. The file is created if it does not exist. <br> + * "r+" - Opens a file to update both reading and writing. The file must exist. Moves file from archive to RAM if in archive. <br> + * "w+" - Creates an empty file for both reading and writing. Overwrites file if already exists. <br> + * "a+" - Opens a file for reading and appending. Moves file from archive to RAM if in archive. Created if it does not exist. + * @param type Specifies the type of variable to open + * @returns Slot variable + * @note If there isn't enough memory to create the variable, or a slot isn't open, zero (0) is returned + */ +ti_var_t ti_OpenVar(const char *varname, const char *mode, uint8_t type); + +/** + * Frees an open variable slot + * @returns Zero if closing failed + */ +int ti_Close(const ti_var_t slot); + +/** + * Returns the name of the file(s) that contains the string as the first part of the variable; + * which can then be used with ti_Open and other functions + * + * seach_pos should be set to NULL to begin a search, and is updated with each call + * + * @code + * char *var_name; + * uint8_t *search_pos = NULL; + * while((var_name = ti_Detect(&search_pos, "my_data")) != NULL) { + * ...do something with the name or search_pos... + * } + * @endcode + * @param curr_search_posistion Current offset in the VAT + * @param detection_string String to search for (NULL to search for all) + * @note If the return value is NULL, there are no more variables to find + */ +char *ti_Detect(void **curr_search_posistion, const char *detection_string); + +/** + * Returns the name of the file(s) that contains the string as the first part of the variable; + * which can then be used with ti_OpenVar and other functions + * + * seach_pos should be set to NULL to begin a search, and is updated with each call + * + * @code + * char *var_name; + * uint8_t *search_pos = NULL; + * while((var_name = ti_DetectVar(&search_pos, "my_data", TI_PRGM_TYPE)) != NULL) { + * ...do something with the name or search_pos... + * } + * @endcode + * @param curr_search_posistion Current offset in the VAT + * @param detection_string String to search for (NULL to search for all) + * @param var_type Type of variable to detect + * @note If the return value is NULL, there are no more variables to find + */ +char *ti_DetectVar(void **curr_search_posistion, const char *detection_string, uint8_t var_type); + +/** + * Returns the name of the file(s) that contains the string as the first part of the variable; + * which can then be used with ti_OpenVar and other functions + * + * seach_pos should be set to NULL to begin a search, and is updated with each call + * + * @code + * char *var_name; + * uint8_t *search_pos = NULL; + * uint8_t type; + * while((var_name = ti_DetectVar(&search_pos, "my_data", &type)) != NULL) { + * if (type == TI_PRGM_TYPE || type == TI_PPRGM_TYPE) { + * ...do something with the name or search_pos... + * } + * } + * @endcode + * @param curr_search_posistion Current offset in the VAT + * @param detection_string String to search for (NULL to search for all) + * @param var_type Type of variable found + * @note If the return value is NULL, there are no more variables to find + */ +char *ti_DetectAny(void **curr_search_posistion, const char *detection_string, uint8_t *var_type); + +/** + * Writes to the current variable slot + * + * @param data Pointer to data to write + * @param size Size (in bytes) of a single data chunk + * @param count Number of data chunks to write to the variable slot + * @param slot Variable slot to write the data to + * @returns The number of chunks written (should be equal to count) + */ +size_t ti_Write(const void *data, size_t size, size_t count, const ti_var_t slot); + +/** + * Reads from the current variable pointer + * + * @param data Pointer to data to read into + * @param size Size (in bytes) of a single data chunk + * @param count Number of data chunks to read from the variable slot + * @param slot Variable slot to read the data from + * @returns The number of chunks read (should be equal to count) + */ +size_t ti_Read(const void *data, size_t size, size_t count, const ti_var_t slot); + +/** + * Writes a character directly into the slot data pointer, and increments the offset + * + * @param c Character to write + * @param slot Variable slot to put the character to + * @returns The input c is returned if no error + * @returns 'EOF' if current offset is larger than file size, or memory isn't large enough + */ +int ti_PutC(const char c, const ti_var_t slot); + +/** + * Pulls a character directly from the slot data pointer, and increments the offset + * + * @param slot Variable slot to get the character from + * @returns 1 byte character at the current variable offset + * @returns 'EOF' if current offset is larger than file size + */ +int ti_GetC(const ti_var_t slot); + +/** + * Seeks to an offset + * + * @param offset Number of bytes to offest from (can be negative) + * @param origin + * SEEK_SET (0) - Seek from beginning of file <br> + * SEEK_CUR (1) - Seek from current offset in file <br> + * SEEK_END (2) - Seek from end of file + * @param slot Variable slot seeking in + * @returns 'EOF' on seek failure + */ +int ti_Seek(int offset, unsigned int origin, const ti_var_t slot); + +/** + * Seeks to the start of the given variable + * + * Basically an ti_Seek(0, SEEK_SET, slot); + * @param slot Variable slot to rewind + * @returns 'EOF' on rewind failure + */ +int ti_Rewind(const ti_var_t slot); + +/** + * Gets the offset in a slot + * + * @param slot Slot to test + * @returns The value of the current slot offset + */ +uint16_t ti_Tell(const ti_var_t slot); + +/** + * Gets the size of a slot + * + * @param slot Slot to test + * @returns The size of the slot variable + */ +uint16_t ti_GetSize(const ti_var_t slot); + +/** + * Resizes the slot variable + * + * @param slot Slot to resize + * @param new_size New size of slot + * @returns Resized size on success, 0 on failure, or -1 if the slot cannot be opened + * @note The variable offset is set to the beginning of the file + */ +int ti_Resize(size_t new_size, const ti_var_t slot); + +/** + * Tests if a slot is in the archive + * + * @param slot Slot to test + * @returns Zero (0) if the slot is not in the archive + */ +int ti_IsArchived(const ti_var_t slot); + +/** + * Sends the variable into either the archive or RAM if needed + * + * @param archived + * True - Send to Archive <br> + * False - Send to RAM + * @param slot Slot to send + * @returns Zero if the operation fails from not enough memory or another error + */ +int ti_SetArchiveStatus(bool archived, const ti_var_t slot); + +/** + * Deletes an AppVar + * + * @param name Name of AppVar to delete + * @returns 0 if failed + */ +int ti_Delete(const char *name); + +/** + * Deletes a variable given the name and type + * + * @param varname Name of variable to delete + * @param type Type of variable to delete + * @returns 0 if failed + */ +int ti_DeleteVar(const char *varname, const uint8_t type); + +/** + * Gets the string used for displaying a TI token + * + * @param length_of_string Pointer to variable to hold length of resulting string (Can be NULL if you don't care) + * @param length_of_token Pointer to variable to hold length of the token, used for determining the next read location (Can be NULL if you don't care) + * @param read_pointer Address of pointer to data to read + * @note read_pointer is updated to the next token, depending on if it is 1 or 2 bytes in length + */ +char *ti_GetTokenString(void **read_pointer, uint8_t *length_of_token, unsigned int *length_of_string); + +/** + * Gets a pointer to the data located at the current posistion in the slot; + * Good way for fast reading of data + * @param slot Variable slot to get pointer of + * @returns Pointer to variable data + */ +void *ti_GetDataPtr(const ti_var_t slot); + +/** + * Gets the VAT location of the slot + * + * @param slot Variable slot to get VAT location of + * @returns VAT location of variable + */ +void *ti_GetVATPtr(const ti_var_t slot); + +/** + * Gets the variable name of an already opened slot + * + * @param slot Variable slot to get name of + * @param name Buffer to store name in, generally at least 10 bytes including null terminator. + * @returns None + */ +void ti_GetName(char *name, const ti_var_t slot); + +/** + * Renames a file + * + * @param old Old name of file + * @param new New name of file + * @returns 0 if success, 1 if file already exists, 2 any other error occurs. + * @warning It is potentially hazardous to rename an open file. Be sure to close the open file before renaming, + */ +uint8_t ti_Rename(const char *old, const char *new); + +/** + * Renames a variable + * + * @param old Old name of variable + * @param new New name of variable + * @param type Type of variable to rename + * @returns 0 if success, 1 if variable already exists, 2 any other error occurs. + * @warning It is potentially hazardous to rename an open variable. Be sure to close the open variable before renaming, + */ +uint8_t ti_RenameVar(const char *old, const char *new, const uint8_t type); + +/** + * Sets a variable + * + * @param var_type Type of variable to set + * @param name Pointer to name of variable + * @param data Pointer to data to set + * @returns 0 if success + */ +uint8_t ti_SetVar(const ti_var_t var_type, const char *name, void *data); + +/** + * Stores a variable to another variable + * + * @param var_type_to Type of variable to store to + * @param to Pointer to data to store to + * @param var_type_from Type of variable to get from + * @param from Pointer to data to get from + * @returns 0 if success + */ +uint8_t ti_StoVar(const ti_var_t var_type_to, void *to, const ti_var_t var_type_from, void *from); + +/** + * Recalls a variable + * + * @param var_type Type of variable to recall + * @param var_name Pointer to name of variable to recall + * @param data_struct Address of pointer to variable structure + * @returns 0 if success + * @note data_struct is set to the variable's data + */ +uint8_t ti_RclVar(const uint8_t var_type, const char *var_name, void **data_struct); + +/** + * Allocates space for a real variable + * @returns Pointer to variable + */ +#define ti_MallocReal() ((real_t*)malloc(sizeof(real_t))) + +/** + * Allocates space for a complex variable + * @returns Pointer to variable + */ +#define ti_MallocCplx() ((cplx_t*)malloc(sizeof(cplx_t))) + +/** + * Allocates space for a string variable + * @param len Length of string + * @returns Pointer to variable + */ +#define ti_MallocString(len) ti_AllocString((len), ((void*)malloc)) + +/** + * Allocates space for a list variable + * @param dim Dimension of list + * @returns Pointer to variable + */ +#define ti_MallocList(dim) ti_AllocList((dim), ((void*)malloc)) + +/** + * Allocates space for a matrix variable + * @param rows Rows in matrix + * @param cols Columns in matrix + * @returns Pointer to variable + */ +#define ti_MallocMatrix(rows, cols) ti_AllocMatrix((rows), (cols), ((void*)malloc)) + +/** + * Allocates space for a complex list variable + * @param dim Dimension of complex list + * @returns Pointer to variable + */ +#define ti_MallocCplxList(dim) ti_AllocCplxList((dim), ((void*)malloc)) + +/** + * Allocates space for an equation variable + * @param len Length of equation variable + * @returns Pointer to variable + */ +#define ti_MallocEqu(len) ti_AllocEqu((len), ((void*)malloc)) + +string_t *ti_AllocString(unsigned len, void (*malloc_routine)(size_t)); +list_t *ti_AllocList(unsigned dim, void (*malloc_routine)(size_t)); +matrix_t *ti_AllocMatrix(uint8_t rows, uint8_t cols, void (*malloc_routine)(size_t)); +cplx_list_t *ti_AllocCplxList(unsigned dim, void (*malloc_routine)(size_t)); +equ_t *ti_AllocEqu(unsigned len, void (*malloc_routine)(size_t)); + +/* Some more definitions using Ans */ +#define TI_ANS_TYPE (0x00) +#define ti_Ans ("\x72\0") + +/* Some string definitions */ +#define ti_Str1 ("\xAA\x0\0") +#define ti_Str2 ("\xAA\x1\0") +#define ti_Str3 ("\xAA\x2\0") +#define ti_Str4 ("\xAA\x3\0") +#define ti_Str5 ("\xAA\x4\0") +#define ti_Str6 ("\xAA\x5\0") +#define ti_Str7 ("\xAA\x6\0") +#define ti_Str8 ("\xAA\x7\0") +#define ti_Str0 ("\xAA\x8\0") +#define ti_StrT ('\xAA') + +/* Some equation definitions */ +#define ti_Y1 ("\x5E\x10\0") +#define ti_Y2 ("\x5E\x11\0") +#define ti_Y3 ("\x5E\x12\0") +#define ti_Y4 ("\x5E\x13\0") +#define ti_Y5 ("\x5E\x14\0") +#define ti_Y6 ("\x5E\x15\0") +#define ti_Y7 ("\x5E\x16\0") +#define ti_Y8 ("\x5E\x17\0") +#define ti_Y9 ("\x5E\x18\0") +#define ti_Y0 ("\x5E\x19\0") +#define ti_EquT ('\x5E') + +/* Some real and complex defines */ +#define ti_A ("\x41\0\0") +#define ti_B ("\x42\0\0") +#define ti_C ("\x43\0\0") +#define ti_D ("\x44\0\0") +#define ti_E ("\x45\0\0") +#define ti_F ("\x46\0\0") +#define ti_G ("\x47\0\0") +#define ti_H ("\x48\0\0") +#define ti_I ("\x49\0\0") +#define ti_J ("\x4A\0\0") +#define ti_K ("\x4B\0\0") +#define ti_L ("\x4C\0\0") +#define ti_M ("\x4D\0\0") +#define ti_N ("\x4E\0\0") +#define ti_O ("\x4F\0\0") +#define ti_P ("\x50\0\0") +#define ti_Q ("\x51\0\0") +#define ti_R ("\x52\0\0") +#define ti_S ("\x53\0\0") +#define ti_T ("\x54\0\0") +#define ti_U ("\x55\0\0") +#define ti_V ("\x56\0\0") +#define ti_W ("\x57\0\0") +#define ti_X ("\x58\0\0") +#define ti_Y ("\x59\0\0") +#define ti_Z ("\x60\0\0") +#define ti_Theta ("\x61\0\0") + +/* Some matrix defines */ +#define ti_MatA ("\x5C\x0\0") +#define ti_MatB ("\x5C\x1\0") +#define ti_MatC ("\x5C\x2\0") +#define ti_MatD ("\x5C\x3\0") +#define ti_MatE ("\x5C\x4\0") +#define ti_MatF ("\x5C\x5\0") +#define ti_MatG ("\x5C\x6\0") +#define ti_MatH ("\x5C\x7\0") +#define ti_MatI ("\x5C\x8\0") +#define ti_MatJ ("\x5C\x9\0") +#define ti_MatT ('\x5C') + +/* Some list defines */ +#define ti_L1 ("\x5D\x0\0") +#define ti_L2 ("\x5D\x1\0") +#define ti_L3 ("\x5D\x2\0") +#define ti_L4 ("\x5D\x3\0") +#define ti_L5 ("\x5D\x4\0") +#define ti_L6 ("\x5D\x5\0") +#define ti_LT ('\x5D') + +/* Compatibility defines */ +#define ti_Program TI_PRGM_TYPE +#define ti_ProtectedProgram TI_PPRGM_TYPE +#define ti_TempProgram TI_TPRGM_TYPE +#define ti_AppVar TI_APPVAR_TYPE + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/float.h b/frontends/calculator/CEdev/include/float.h new file mode 100644 index 0000000..bd022b2 --- /dev/null +++ b/frontends/calculator/CEdev/include/float.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + * Modified by Matt "MateoConLechuga" Waltz for TI84+CE platform + */ +#ifndef FLOAT_H +#define FLOAT_H + +#define FLT_RADIX 2 /* radix of exponent representation */ + +#define FLT_ROUNDS 0 /* addition rounds to nearest */ + +/* number of base-FLT_RADIX digits in the mantissa */ + +#define FLT_MANT_DIG 24 +#define DBL_MANT_DIG FLT_MANT_DIG +#define LDBL_MANT_DIG FLT_MANT_DIG + +/* number of decimal digits of precision */ + +#define FLT_DIG 6 +#define DBL_DIG FLT_DIG +#define LDBL_DIG FLT_DIG + +/* minimum negative integer such that FLT_RADIX raised to that */ +/* power approximates a positive floating point number in the */ +/* range of representable values. */ + +#define FLT_MIN_EXP -125 +#define DBL_MIN_EXP FLT_MIN_EXP +#define LDBL_MIN_EXP FLT_MIN_EXP + +/* maximum integer such that FLT_RADIX raised to that power */ +/* approximates a floating point number in the range of */ +/* representable numbers. */ + +#define FLT_MAX_EXP 128 +#define DBL_MAX_EXP FLT_MAX_EXP +#define LDBL_MAX_EXP FLT_MAX_EXP + +/* maximum integer such that 10 raised to that power */ +/* approximates a floating point number in the range of */ +/* representable value ((int)log10(FLT_MAX),etc) */ + +#define FLT_MAX_10_EXP +38 +#define DBL_MAX_10_EXP FLT_MAX_10_EXP +#define LDBL_MAX_10_EXP FLT_MAX_10_EXP + +/* minimum negative integer such that 10 raised to that power */ +/* approximates a positive floating point number in the range */ +/* of representable values ((int)log10(FLT_MIN),etc.) */ + +#define FLT_MIN_10_EXP -37 +#define DBL_MIN_10_EXP FLT_MIN_10_EXP +#define LDBL_MIN_10_EXP FLT_MIN_10_EXP + +/* maximum representable floating point numbers */ + +#define FLT_MAX 3.40282347E+38 +#define DBL_MAX FLT_MAX +#define LDBL_MAX FLT_MAX + +/* minimum positive number x such that 1.0 + x != 1.0 (b ^ (1-p)) */ + +#define FLT_EPSILON 1.19209290E-07 +#define DBL_EPSILON FLT_EPSILON +#define LDBL_EPSILON FLT_EPSILON + +/* minimum representable positive floating point numbers */ + +#define FLT_MIN 1.17549435E-38 +#define DBL_MIN FLT_MIN +#define LDBL_MIN FLT_MIN + +#endif diff --git a/frontends/calculator/CEdev/include/format.h b/frontends/calculator/CEdev/include/format.h new file mode 100644 index 0000000..52a0e80 --- /dev/null +++ b/frontends/calculator/CEdev/include/format.h @@ -0,0 +1,109 @@ +/* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + * Modified by Matt "MateoConLechuga" Waltz for TI84+CE platform + */ +#ifndef FORMAT_H +#define FORMAT_H + +#include <stdarg.h> +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _PTR_ +#define _PTR_ * +#endif + +/* Note: 24 bits times log(2) is 7.224 decimal digits. + We only need 14 if and when we support doubles. <THH> */ +#define MAXDIGITS 10 +#define MINEXP -4 +#define DEFAULT_PRECISION 6 + +/* format status codes */ +#define FMT_OK 0 +#define FMT_ERR 1 +#define FMT_PASS_THRU 2 + +/* format flags */ +#define FMT_FLAG_MINUS 0x01 +#define FMT_FLAG_PLUS 0x02 +#define FMT_FLAG_SPACE 0x04 +#define FMT_FLAG_POUND 0x08 +#define FMT_FLAG_IGNORE 0x10 // scanf only. +#define FMT_FLAG_PRECISION 0x10 // Only needed for %s, as 0 is valid precision +#define FMT_FLAG_UPPERCASE 0x20 // Added. <THH> +#define FMT_FLAG_PAD_ZERO 0x40 +#define FMT_FLAG_STRIP 0x80 // Output only. <THH> +#define FMT_FLAG_SET 0x80 // Input only; maybe not needed if + // set_begin != 0 is used instead. <THH> + +/* structures and defines for format routines */ +/* NOTE: Some fields in this structure, and the bits in flags, are */ +/* known to the optimizer, If you change this, check out the */ +/* optimizer code in genprintf.c . */ + +struct fmt_type { + unsigned char status; /* status, OK, ERR, or PASS_THRU */ + unsigned char flags; /* flags bit mask */ + char size; /* size character h,l or L */ + char chr; /* pass thru character */ + char type; /* type of argument d,i,o,u,x ... */ + char field_width; /* field width */ + char precision; /* precision */ + char _PTR_ set_begin; /* pointer to first char in set */ + char _PTR_ set_end; /* pointer to last char in set */ + unsigned char pad_whole; + unsigned char pad_pre_fract; + unsigned char pad_post_fract; + char _PTR_ pad_at; + }; + +/* info flags */ +#define FLT_INFO_SIGN (1<<0) +#define FLT_INFO_INF (1<<1) +#define FLT_INFO_NAN (1<<2) + +/* Note: using char to represent the (decimal) exponent only works for + 4-byte floats. If we choose to support 8-byte doubles, then this must + be increased. <THH> */ +struct flt_info { + unsigned char flags; /* 1=sign, 2=inf, 4=nan */ + char exp; /* (signed) exponent (base 10) */ + unsigned char digits[MAXDIGITS]; /* max significant digits */ +}; + +extern struct fmt_type __print_fmt; +extern char __print_buff[]; +extern unsigned char __print_len; +extern char __print_leading_char; // Initial +, -, or space for number +extern void __print_send(); + +extern void _u_stoa(short); +extern void _u_ustoa(unsigned short); +extern void _u_itoa(int); +extern void _u_uitoa(unsigned int); +extern void _u_ltoa(long); +extern void _u_ultoa(unsigned long); +extern int _u_print(char _PTR_ src,char _PTR_ fmt,va_list); +extern int _u_scan(char _PTR_ src,char _PTR_ fmt,va_list ap); +extern void _u_dtof(double); +extern void _u_dtog(double); + +extern char _PTR_ _u_pscan(char _PTR_ fmt,struct fmt_type _PTR_ str, va_list _PTR_ argp); +extern char _PTR_ _u_sscan (char _PTR_ fmt,struct fmt_type _PTR_ str); + +extern void _u_reverse(char _PTR_ s); +extern char _PTR_ _u_dtoe(double); + +extern void _u_flt_info(double,struct flt_info _PTR_); +extern void _u_flt_rnd(struct flt_info _PTR_ , char); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/graphx.h b/frontends/calculator/CEdev/include/graphx.h new file mode 100644 index 0000000..bbcf697 --- /dev/null +++ b/frontends/calculator/CEdev/include/graphx.h @@ -0,0 +1,1514 @@ +/** + * @file + * @brief Contains optimized graphics operations and routines + * + * Example program template with best graphx buffer usage pattern: + * @code + * // Standard #includes omitted + * + * bool partial_redraw; + * + * // Implement us! + * void begin(); + * void end(); + * bool step(); + * void draw(); + * + * void main() { + * begin(); // No rendering allowed! + * gfx_Begin(); + * gfx_SetDrawBuffer(); // Draw to the buffer to avoid rendering artifats + * + * while (step()) { // No rendering allowed in step! + * if (partial_redraw) // Only want to redraw part of the previous frame? + * gfx_BlitScreen(); // Copy previous frame as a base for this frame + * draw(); // As little non-rendering logic as possible + * gfx_SwapDraw(); // Queue the buffered frame to be displayed + * } + * + * gfx_End(); + * end(); + * } + * @endcode + * + * @authors Matt "MateoConLechuga" Waltz + * @authors Jacob "jacobly" Young + * @authors Zachary "Runer112" Wassall + * @authors Patrick "tr1p1ea" Prendergast + * @authors "grosged" + */ + +#ifndef H_GRAPHX +#define H_GRAPHX + +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Sprite (image) type. + * + * Whether or not a sprite includes transparency is not explicitly encoded, and + * is determined only by usage. If used with transparency, transparent pixels + * are those with a certain color index, which can be set with + * gfx_SetTransparentColor(). + * + * @attention + * Displaying a gfx_rletsprite_t (which includes transparency) is significantly + * faster than displaying a gfx_sprite_t with transparency, and should be + * preferred. However, gfx_rletsprite_t does not support transformations, such + * as flipping and rotation. Such transformations can be applied to a + * gfx_sprite_t, which can then be converted to a gfx_rletsprite_t for faster + * display using gfx_ConvertToNewRLETSprite() or gfx_ConvertToRLETSprite(). + * + * @remarks + * Create at compile-time with a tool like + * <a href="https://github.com/MattWaltz/convpng" target="_blank">convpng</a>. + * Create at runtime (with uninitialized data) with gfx_MallocSprite(), + * gfx_UninitedSprite(), or gfx_TempSprite(). + */ +typedef struct { + uint8_t width; /**< Width of the image */ + uint8_t height; /**< Height of the image */ + uint8_t data[1]; /**< Image data array */ +} gfx_sprite_t; + +/** + * @brief Sprite (image) type with RLE transparency. + * + * @attention + * Displaying a gfx_rletsprite_t (which includes transparency) is significantly + * faster than displaying a gfx_sprite_t with transparency, and should be + * preferred. However, gfx_rletsprite_t does not support transformations, such + * as flipping and rotation. Such transformations can be applied to a + * gfx_sprite_t, which can then be converted to a gfx_rletsprite_t for faster + * display using gfx_ConvertToNewRLETSprite() or gfx_ConvertToRLETSprite(). + * + * @remarks + * Create at compile-time with a tool like + * <a href="https://github.com/MattWaltz/convpng" target="_blank">convpng</a>. + */ +typedef struct { + uint8_t width; /**< Width of the image */ + uint8_t height; /**< Height of the image */ + uint8_t data[1]; /**< Image data array */ +} gfx_rletsprite_t; + +/** + * @brief A simple structure for working with 2D points + */ +typedef struct { + int x; /**< x point */ + int y; /**< y point */ +} gfx_point_t; + +/** + * @brief Stores operating modes of this library + * @see gfx_Begin + */ +typedef enum { + gfx_8bpp = 0x27 /**< Enable 8 bits per pixel mode */ +} gfx_mode_t; + +/** + * Dynamically allocates memory for a sprite. + * + * Allocates the memory with \p malloc_routine. \p width and \p height will be + * set in the allocated sprite. Returns \c NULL upon allocation failure. + * + * @note + * If not used in a dynamic context and \p width and \p height are static, + * consider statically allocating the sprite instead with gfx_UninitedSprite() + * or gfx_TempSprite(). + * + * @remarks + * If using \c malloc as the \p malloc_routine, gfx_MallocSprite() can be used + * as a shortcut. + * + * @param width sprite width + * @param height sprite height + * @param malloc_routine malloc implementation to use + * @return pointer to the allocated sprite + */ +gfx_sprite_t *gfx_AllocSprite(uint8_t width, uint8_t height, void *(*malloc_routine)(size_t)); + +/** + * Dynamically allocates memory for a sprite using \c malloc. + * + * \p width and \p height will be set in the sprite. Returns \c NULL upon + * allocation failure. + * + * @note + * If not used in a dynamic context and \p width and \p height are static, + * consider statically allocating the sprite instead with gfx_UninitedSprite() + * or gfx_TempSprite(). + * + * @param width sprite width + * @param height sprite height + * @return pointer to the allocated sprite + * @see gfx_AllocSprite + */ +#define gfx_MallocSprite(width, height) \ +gfx_AllocSprite(width, height, malloc) + +/** + * Statically allocates unitialized memory for a sprite. + * + * Declares a <tt>gfx_sprite_t *</tt> with the given \p name pointing to the + * allocated memory. \p width and \p height will \b not be set in the sprite, + * unlike gfx_TempSprite(). + * + * @warning + * If used outside of a function body, the memory will be allocated in the + * global unitialized data segment (BSS). If used inside a function body, the + * memory will be allocated on the stack. If the sprite is sufficiently large, + * usage inside a function body will overflow the stack, so it is recommended + * that this normally be used outside of a function body. + * + * @param name name of declared <tt>gfx_sprite_t *</tt> + * @param width sprite width + * @param height sprite height + * @see gfx_MallocSprite + */ +#define gfx_UninitedSprite(name, width, height) \ +uint8_t name##_data[2 + (width) * (height)]; \ +gfx_sprite_t *name = (gfx_sprite_t *)name##_data + +/** + * Statically allocates memory for a sprite. + * + * Declares a <tt>gfx_sprite_t *</tt> with the given \p name pointing to the + * allocated memory. \p width and \p height will be set in the sprite, unlike + * gfx_UninitedSprite(). + * + * @attention + * Due to \p width and \p height being set, the memory will be allocated in the + * initialized data segment. If the compiled program is not compressed, then + * this could be a serious source of bloat and gfx_UninitedSprite() should be + * preferred. + * + * @param name name of declared <tt>gfx_sprite_t *</tt> + * @param width sprite width + * @param height sprite height + * @see gfx_MallocSprite + */ +#define gfx_TempSprite(name, width, height) \ +uint8_t name##_data[2 + (width) * (height)] = { (width), (height) }; \ +gfx_sprite_t *name = (gfx_sprite_t *)name##_data + +/** + * Dynamically allocates memory for a sprite with RLE transpareny. + * + * Allocates the memory with \p malloc_routine. Returns \c NULL upon allocation + * failure. + * + * \p data_size is the maximum predicted/calculated size of the sprite data + * (excuding the width and height bytes) that will be stored in the allocated + * sprite. Sprite data size could be up to <tt>(width + 1) * height * 3 / 2</tt> + * bytes in the worst case, in which pixels horizontally alternate between + * non-transparent and transparent and each row begins with a non-transparent + * pixel. But if the average length of a horizontal transparent run is at least + * 2, then the sprite data will be no larger than <tt>(width + 1) * height</tt> + * bytes. The exact data size necessary is <tt>2 * + * num_horizontal_transparent_runs + num_non_transparent_pixels + + * num_rows_beginning_with_non_transparent_pixel - + * num_rows_ending_with_transparent_pixel</tt> bytes. + * + * @note + * If not used in a dynamic context and \p data_size is static, consider + * statically allocating the sprite instead with gfx_UninitedRLETSprite() or + * gfx_TempRLETSprite(). + * + * @remarks + * If using \c malloc as the \p malloc_routine, gfx_MallocRLETSprite() can be + * used as a shortcut. + * + * @param data_size (maximum) sprite data size + * @param malloc_routine malloc implementation to use + * @return pointer to the allocated sprite + */ +#define gfx_AllocRLETSprite(data_size, malloc_routine) \ +(gfx_rletsprite_t *)(malloc_routine)(data_size) + +/** + * Dynamically allocates memory for a sprite with RLE transparency using \c + * malloc. + * + * \p data_size is the size to allocate for sprite data; see + * gfx_AllocRLETSprite() for information. Returns \c NULL upon allocation + * failure. + * + * @note + * If not used in a dynamic context and \p data_size is static, consider + * statically allocating the sprite instead with gfx_UninitedRLETSprite() or + * gfx_TempRLETSprite(). + * + * @param data_size (maximum) sprite data size + * @return pointer to the allocated sprite + * @see gfx_AllocRLETSprite + */ +#define gfx_MallocRLETSprite(data_size) \ +gfx_AllocRLETSprite(data_size, malloc) + +/** + * Statically allocates unitialized memory for a sprite with RLE transparency. + * + * Declares a <tt>gfx_rletsprite_t *</tt> with the given \p name pointing to the + * allocated memory. \p data_size is the size to allocate for sprite data; see + * gfx_AllocRLETSprite() for information. + * + * @warning + * If used outside of a function body, the memory will be allocated in the + * global unitialized data segment (BSS). If used inside a function body, the + * memory will be allocated on the stack. If the sprite is sufficiently large, + * usage inside a function body will overflow the stack, so it is recommended + * that this normally be used outside of a function body. + * + * @param name name of declared <tt>gfx_rletsprite_t *</tt> + * @param data_size (maximum) sprite data size + * @see gfx_MallocRLETSprite + */ +#define gfx_UninitedRLETSprite(name, data_size) \ +uint8_t name##_data[2 + (data_size)]; \ +gfx_rletsprite_t *name = (gfx_rletsprite_t *)name##_data + +/** + * Initializes the graphics library setup + */ +int gfx_Begin(); + +/** + * Closes the graphics setup + * + * Restores the LCD to 16bpp prefered by the OS and clears the screen. + */ +void gfx_End(void); + +/** + * Used for accessing the lcd palette directly + * + * This consists of 256 entries, each 2 bytes in size for a total of 512 bytes + */ +#define gfx_palette \ +((uint16_t*)0xE30200) + +/** + * Array of the LCD RAM + * + * Total of 153600 bytes in size + * @see gfx_vbuffer + */ +#define gfx_vram \ +((uint8_t*)0xD40000) + +/** + * Array of the current drawing buffer + * + * Total of 76800 bytes in size + * @see gfx_vram + */ +#define gfx_vbuffer \ +(**(uint8_t(**)[240][320])0xE30014) + +/** + * @brief Defines a rectangular graphics region + * + * @see gfx_GetClipRegion + */ +typedef struct { + int xmin; /**< Minimum x coordinate */ + int ymin; /**< Minimum y coordinate */ + int xmax; /**< Maximum x coordinate */ + int ymax; /**< Maximum y coordinate */ +} gfx_region_t; + +/** + * @brief Defines tilemap structure + * + * @see gfx_Tilemap + */ +typedef struct { + uint8_t *map; /**< Pointer to indexed map array */ + gfx_sprite_t **tiles; /**< Pointer to tiles */ + uint8_t tile_height; /**< Individual tile height */ + uint8_t tile_width; /**< Individual tile width */ + uint8_t draw_height; /**< Number of tiles per row to draw */ + uint8_t draw_width; /**< Number of tile per column to draw */ + uint8_t type_width; /**< Tile type height @see gfx_tilemap_type_t */ + uint8_t type_height; /**< Tile type width @see gfx_tilemap_type_t */ + uint8_t height; /**< Total number of rows in the tilemap */ + uint8_t width; /**< Total number of columns in the tilemap */ + uint8_t y_loc; /**< Y pixel location of tilemap */ + uint24_t x_loc; /**< X pixel location to tilemap */ +} gfx_tilemap_t; + +/** + * @brief Used for defining tile types + * + * @see gfx_tilemap_t + */ +typedef enum { + gfx_tile_no_pow2 = 0, /**< Set when using non powers of 2 */ + gfx_tile_2_pixel, /**< Set when using 2 pixel tiles */ + gfx_tile_4_pixel, /**< Set when using 4 pixel tiles */ + gfx_tile_8_pixel, /**< Set when using 8 pixel tiles */ + gfx_tile_16_pixel, /**< Set when using 16 pixel tiles */ + gfx_tile_32_pixel, /**< Set when using 32 pixel tiles */ + gfx_tile_64_pixel, /**< Set when using 64 pixel tiles */ + gfx_tile_128_pixel /**< Set when using 128 pixel tiles */ +} gfx_tilemap_type_t; + +/** + * Draws a tilemap given an initialized tilemap structure + * + * @param tilemap Pointer to initialized tilemap structure + * @param x_offset Offset in pixels from the left of the tilemap + * @param y_offset Offset in pixels from the top of the tilemap + * @see gfx_tilemap_t + */ +void gfx_Tilemap(gfx_tilemap_t *tilemap, uint24_t x_offset, uint24_t y_offset); + +/** + * Draws an unclipped tilemap given an initialized tilemap structure + * + * @param tilemap Pointer to initialized tilemap structure + * @param x_offset Offset in pixels from the left of the tilemap + * @param y_offset Offset in pixels from the top of the tilemap + * @see gfx_tilemap_t + */ +void gfx_Tilemap_NoClip(gfx_tilemap_t *tilemap, uint24_t x_offset, uint24_t y_offset); + +/** + * Draws a transparent tilemap given an initialized tilemap structure + * + * @param tilemap Pointer to initialized tilemap structure + * @param x_offset Offset in pixels from the left of the tilemap + * @param y_offset Offset in pixels from the top of the tilemap + * @see gfx_tilemap_t + */ +void gfx_TransparentTilemap(gfx_tilemap_t *tilemap, uint24_t x_offset, uint24_t y_offset); + +/** + * Draws an unclipped transparent tilemap given an initialized tilemap structure + * + * @param tilemap Pointer to initialized tilemap structure + * @param x_offset Offset in pixels from the left of the tilemap + * @param y_offset Offset in pixels from the top of the tilemap + * @see gfx_tilemap_t + */ +void gfx_TransparentTilemap_NoClip(gfx_tilemap_t *tilemap, uint24_t x_offset, uint24_t y_offset); + +/** + * Gets a pointer to a particular tile given an initialized tilemap structure and pixel offsets + * + * @param tilemap Pointer to initialized tilemap structure + * @param x_offset Offset in pixels from the left of the tilemap + * @param y_offset Offset in pixels from the top of the tilemap + */ +uint8_t *gfx_TilePtr(gfx_tilemap_t *tilemap, uint24_t x_offset, uint24_t y_offset); + +/** + * Sets a particular tile's value given an initialized tilemap structure and pixel offsets + * + * @param tilemap Pointer to initialized tilemap structure + * @param x_offset Offset in pixels from the left of the tilemap + * @param y_offset Offset in pixels from the top of the tilemap + * @param value Value to set tile to + */ +#define gfx_SetTile(tilemap, x_offset, y_offset, value) \ +(*(gfx_TilePtr((tilemap), (x_offset), (y_offset))) = (uint8_t)(value)) + +/** + * Gets a particular tile's value given an initialized tilemap structure and pixel offsets + * + * @param tilemap Pointer to initialized tilemap structure + * @param x_offset Offset in pixels from the left of the tilemap + * @param y_offset Offset in pixels from the top of the tilemap + */ +#define gfx_GetTile(tilemap, x_offset, y_offset) \ +(*(gfx_TilePtr((tilemap), (x_offset), (y_offset)))) + +/** + * Gets a pointer to a particular tile given an initialized tilemap structure and mapped offsets + * + * @param tilemap Pointer to initialized tilemap structure + * @param row Offset in bytes in the row + * @param col Offset in bytes in the column + */ +uint8_t *gfx_TilePtrMapped(gfx_tilemap_t *tilemap, uint8_t row, uint8_t col); + +/** + * Sets a particular tile's value given an initialized tilemap structure and mapped offsets + * + * @param tilemap Pointer to initialized tilemap structure + * @param row Offset in bytes in the row + * @param col Offset in bytes in the column + * @param value Value to set tile to + */ +#define gfx_SetTileMapped(tilemap, row, col, value) \ +(*(gfx_TilePtrMapped((tilemap), (row), (col))) = (uint8_t)(value)) + +/** + * Gets a particular tile's value given an initialized tilemap structure and mapped offsets + * + * @param tilemap Pointer to initialized tilemap structure + * @param row Offset in bytes in the row + * @param col Offset in bytes in the column + */ +#define gfx_GetTileMapped(tilemap, row, col) \ +(*(gfx_TilePtrMapped((tilemap), (row), (col)))) + +/** + * Sets the color index that drawing routines will use + * + * This applies to lines, rectangles, circles, etc + * @param index Color index to set + * @returns Previous set color index + */ +uint8_t gfx_SetColor(uint8_t index); + +/** + * Sets the transparent index that drawing routines will use + * + * This currently applies to transparent sprites, both scaled and unscaled + * @param index Transparent color index to set + * @returns The previous transparent color index + */ +uint8_t gfx_SetTransparentColor(uint8_t index); + +/** + * Sets up the default palette for the given mode + * + * @param mode Palette to use + */ +void gfx_SetDefaultPalette(gfx_mode_t mode); + +/** + * Sets entries in the palette + * + * @param palette Pointer to palette to use + * @param size Size of palette to store + * @param offset Offset in bytes to start at (Generally set to 0) + */ +void gfx_SetPalette(uint16_t *palette, uint24_t size, uint8_t offset); + +/** + * Fills the screen with a given palette index + * + * @param index Color index to fill with + */ +void gfx_FillScreen(uint8_t index); + +/** + * Implements a faster version of gfx_FillScreen(0) + * + * @see gfx_FillScreen + */ +void gfx_ZeroScreen(void); + +/** + * Sets a pixel to the global color index + * + * This is measured from the top left origin of the screen. + * Pixels are only clipped within the screen boundaries + * @param x X coordinate location + * @param y Y coordinate location + * @see gfx_SetColor + */ +void gfx_SetPixel(uint24_t x, uint8_t y); + +/** + * Gets a pixel's color index + * + * This is measured from the top left origin of the screen. + * Pixels are only clipped within the screen boundaries + * @param x X coordinate location + * @param y Y coordinate location + */ +uint8_t gfx_GetPixel(uint24_t x, uint8_t y); + +/** + * Draws a line + * + * This is measured from the top left origin of the screen. + * @param x0 First X coordinate + * @param y0 First Y coordinate + * @param x1 Second X coordinate + * @param y1 Second Y coordinate + */ +void gfx_Line(int x0, int y0, int x1, int y1); + +/** + * Draws an unclipped line + * + * This is measured from the top left origin of the screen. + * @param x0 First X coordinate + * @param y0 First Y coordinate + * @param x1 Second X coordinate + * @param y1 Second Y coordinate + */ +void gfx_Line_NoClip(uint24_t x0, uint8_t y0, uint24_t x1, uint8_t y1); + +/** + * Clips the points in a window region + * + * This is measured from the top left origin of the screen. + * @param x0 First X coordinate + * @param y0 First Y coordinate + * @param x1 Second X coordinate + * @param y1 Second Y coordinate + * @returns False if not within window, true otherwise + */ +bool gfx_CohenSutherlandClip(int *x0, int *y0, int *x1, int *y1); + +/** + * Draws a horizontal line + * + * This is measured from the top left origin of the screen. + * Performs faster than using @c gfx_Line + * @param x X coordinate + * @param y Y coordinate + * @param length Length of line + */ +void gfx_HorizLine(int x, int y, int length); + +/** + * Draws an unclipped horizontal line + * + * This is measured from the top left origin of the screen. + * Performs faster than using @c gfx_Line + * @param x X coordinate + * @param y Y coordinate + * @param length Length of line + */ +void gfx_HorizLine_NoClip(uint24_t x, uint8_t y, uint24_t length); + +/** + * Draws a vertical line + * + * This is measured from the top left origin of the screen. + * Performs faster than using @c gfx_Line + * @param x X coordinate + * @param y Y coordinate + * @param length Length of line + */ +void gfx_VertLine(int x, int y, int length); + +/** + * Draws an unclipped vertical line + * + * This is measured from the top left origin of the screen. + * Performs faster than using @c gfx_Line + * @param x X coordinate + * @param y Y coordinate + * @param length Length of line + */ +void gfx_VertLine_NoClip(uint24_t x, uint8_t y, uint24_t length); + +/** + * Draws a rectangle outline + * + * This is measured from the top left origin of the screen. + * @param x X coordinate + * @param y Y coordinate + * @param width Width of rectangle + * @param height Height of rectangle + */ +void gfx_Rectangle(int x, int y, int width, int height); + +/** + * Draws an unclipped rectangle outline + * + * This is measured from the top left origin of the screen. + * @param x X coordinate + * @param y Y coordinate + * @param width Width of rectangle + * @param height Height of rectangle + */ +void gfx_Rectangle_NoClip(uint24_t x, uint8_t y, uint24_t width, uint8_t height); + +/** + * Draws a filled rectangle + * + * This is measured from the top left origin of the screen. + * @param x X coordinate + * @param y Y coordinate + * @param width Width of rectangle + * @param height Height of rectangle + */ +void gfx_FillRectangle(int x, int y, int width, int height); + +/** + * Draws an unclipped filled rectangle + * + * This is measured from the top left origin of the screen. + * @param x X coordinate + * @param y Y coordinate + * @param width Width of rectangle + * @param height Height of rectangle + */ +void gfx_FillRectangle_NoClip(uint24_t x, uint8_t y, uint24_t width, uint8_t height); + +/** + * Draws a circle outline + * + * This is measured from the top left origin of the screen. + * @param x X coordinate + * @param y Y coordinate + * @param radius The radius of the circle + */ +void gfx_Circle(int x, int y, unsigned radius); + +/** + * Draws a filled circle + * + * This is measured from the top left origin of the screen. + * @param x X coordinate + * @param y Y coordinate + * @param radius The radius of the circle + */ +void gfx_FillCircle(int x, int y, unsigned radius); + +/** + * Draws an unclipped filled circle + * + * This is measured from the top left origin of the screen. + * @param x X coordinate + * @param y Y coordinate + * @param radius The radius of the circle + */ +void gfx_FillCircle_NoClip(uint24_t x, uint8_t y, unsigned radius); + +/** + * Draws an unclipped circle outline + * + * This is measured from the top left origin of the screen. + * @param x X coordinate + * @param y Y coordinate + * @param radius The radius of the circle + */ +#define gfx_Circle_NoClip(x, y, radius) \ +gfx_Circle((x), (y), (radius)) + +/** + * Draws a polygon outline + * + * Points are measured from the top left origin of the screen. + * @code + * int points[6] = { + * 160, 1, // (x0, y0) + * 1, 238, // (x1, y1) + * 318,238, // (x2, y2) + * }; + * num_points = 3; + * gfx_Polygon(points, num_points) + * @endcode + * @param points Pointer to x and y pairs + * @param num_points Number of x and y pairs + */ +void gfx_Polygon(int *points, unsigned num_points); + +/** + * Draws an unclipped polygon outline + * + * Points are measured from the top left origin of the screen. + * @code + * int points[6] = { + * 160, 1, // (x0, y0) + * 1, 238, // (x1, y1) + * 318,238, // (x2, y2) + * }; + * num_points = 3; + * gfx_Polygon_NoClip(points, num_points) + * @endcode + * @param points Pointer to x and y pairs + * @param num_points Number of x and y pairs + */ +void gfx_Polygon_NoClip(int *points, unsigned num_points); + +/** + * Draws a filled triangle + * + * Points are measured from the top left origin of the screen. + * @param x0 First X coordinate + * @param y0 First Y coordinate + * @param x1 Second X coordinate + * @param y1 Second Y coordinate + * @param x2 Third X coordinate + * @param y2 Third Y coordinate + */ +void gfx_FillTriangle(int x0, int y0, int x1, int y1, int x2, int y2); +void gfx_FillTriangle_NoClip(int x0, int y0, int x1, int y1, int x2, int y2); + +/** + * Forces all graphics routines draw location + * + * @param location Location routines should draw to + * @see gfx_draw_location_t + */ +void gfx_SetDraw(uint8_t location); + +/** + * @brief Different locations routines can be drawn to + */ +typedef enum { + gfx_screen = 0, /**< Screen */ + gfx_buffer /**< Buffer */ +} gfx_draw_location_t; + +/** + * Makes the subsequent GraphX drawing routines act on the buffer + */ +#define gfx_SetDrawBuffer() \ +gfx_SetDraw(gfx_buffer) + +/** + * Makes the subsequent GraphX drawing routines act on the screen + */ +#define gfx_SetDrawScreen() \ +gfx_SetDraw(gfx_screen) + +/** + * Gets current draw location + * + * @returns Location type enumeration + * @see gfx_draw_location_t + */ +uint8_t gfx_GetDraw(void); + +/** + * Swaps the roles of the screen and drawing buffers. + * + * Does not wait for the old screen buffer to finish being displayed. Instead, + * the next invocation of a graphx drawing function will block, waiting for this + * event. To block and wait explicitly, use gfx_Wait(). + * + * The LCD driver maintains its own screen buffer pointer for the duration of a + * refresh. The swap performed by this function will only be picked up at a + * point between refreshes. + * + * @remarks + * In practice, this function should be invoked immediately after finishing + * drawing a frame to the drawing buffer, and invocation of the first graphx + * drawing function for the next frame should be scheduled as late as possible + * relative to non-drawing logic. Non-drawing logic can execute during time when + * a drawing function may otherwise block. + */ +void gfx_SwapDraw(void); + +/** + * Waits for the screen buffer to finish being displayed after gfx_SwapDraw(). + * + * @remarks + * In practice, this function should not need to be invoked by user code. It + * should be invoked by custom drawing functions (as late as reasonably + * possible) before writing to the drawing buffer, gfx_vbuffer. + */ +void gfx_Wait(void); + +/** + * Copies the input buffer to the opposite buffer + * + * No clipping is performed; as it is a copy not a draw + * @param src drawing location to copy from + * @see gfx_draw_location_t + */ +void gfx_Blit(uint8_t src); + +/** + * Copies lines from the input buffer to the opposite buffer + * + * No clipping is performed; as it is a copy not a draw + * @param src drawing location to copy from + * @param y_loc Y Location to begin copying at + * @param num_lines Number of lines to copy + * @see gfx_draw_location_t + */ +void gfx_BlitLines(uint8_t src, uint8_t y_loc, uint8_t num_lines); + +/** + * Copies a rectangle from the input buffer to the opposite buffer + * + * No clipping is performed; as it is a copy not a draw + * @param src drawing location to copy from + * @param x X coordinate + * @param y Y coordinate + * @param width Width of rectangle + * @param height Height of rectangle + * @see gfx_draw_location_t + */ +void gfx_BlitRectangle(uint8_t src, uint24_t x, uint8_t y, uint24_t width, uint24_t height); + +/** + * Copies the screen to the buffer + */ +#define gfx_BlitScreen() \ +gfx_Blit(gfx_screen) + +/** + * Copies the buffer to the screen + */ +#define gfx_BlitBuffer() \ +gfx_Blit(gfx_buffer) + +/** + * Sets the scaling for text + * + * Values in the range from 1-5 are preferred. + * @param width_scale Text width scaling + * @param height_scale Text height scaling + */ +void gfx_SetTextScale(uint8_t width_scale, uint8_t height_scale); + +/** + * Prints a character + * + * Outputs a character at the current cursor position. + * @param c Character to print + * @note By default, no text clipping is performed (configurable with gfx_SetTextConfig) + */ +void gfx_PrintChar(const char c); + +/** + * Prints a signed integer + * + * Outputs at the current cursor position. Padded with leading zeros if + * necessary to satisfy the specified minimum length. + * @param n Integer to print + * @param length Minimum number of characters to print + * @note By default, no text clipping is performed (configurable with gfx_SetTextConfig) + * @note \c length must be between 1 and 8, inclusive + */ +void gfx_PrintInt(int n, uint8_t length); + +/** + * Prints an unsigned integer + * + * Outputs at the current cursor position. Padded with leading zeros if + * necessary to satisfy the specified minimum length. + * @param n Unsigned integer to print + * @param length Minimum number of characters to print + * @note By default, no text clipping is performed (configurable with gfx_SetTextConfig) + * @note \c length must be between 1 and 8, inclusive + */ +void gfx_PrintUInt(unsigned int n, uint8_t length); + +/** + * Prints a string + * + * Outputs a string at the current cursor position. + * @param string Pointer to string to print + * @note By default, no text clipping is performed (configurable with gfx_SetTextConfig) + */ +void gfx_PrintString(const char *string); + +/** + * Prints a string at coordinates + * + * Outputs a string at the supplied coordinates + * Posistion is measured from top left origin of screen. + * @param string Pointer to string to print + * @param x X coordinate + * @param y Y coordinate + * @note By default, no text clipping is performed (configurable with gfx_SetTextConfig) + */ +void gfx_PrintStringXY(const char *string, int x, int y); + +/** + * @returns The current text cursor X position + */ +int gfx_GetTextX(void); + +/** + * @returns The current text cursor Y position + */ +int gfx_GetTextY(void); + +/** + * Sets the text cursor XY position + * + * @param x X coordinate + * @param y Y coordinate + */ +void gfx_SetTextXY(int x, int y); + +/** + * Sets the configuration for the text routines + * + * @param config Set the options for the text mode + * @see gfx_text_options_t + * @note Scaled text does not clip + */ +void gfx_SetTextConfig(uint8_t config); + +/** + * @brief Different available text modes + */ +typedef enum { + gfx_text_clip = 1, /**< Text routines will clip against the defined clip window */ + gfx_text_noclip /**< Default, text routines do not clip (much faster) */ +} gfx_text_options_t; + +/** + * Sets text foreground color + * + * @param color Color index to set + * @returns Previous text foreground color index + * @note Default text foreground color index: 0 + */ +uint8_t gfx_SetTextFGColor(uint8_t color); + +/** + * Sets text background color + * + * @param color Color index to set + * @returns Previous text background color index + * @note Default text background color index: 255 + */ +uint8_t gfx_SetTextBGColor(uint8_t color); + +/** + * Sets text transparency color + * + * @param color Color index to set + * @returns Previous text transparency color index + * @note Default text transparency color index: 255 + */ +uint8_t gfx_SetTextTransparentColor(uint8_t color); + +/** + * Draws a sprite + * + * @param sprite Pointer to initialized sprite structure + * @param x X coordinate + * @param y Y coordinate + */ +void gfx_Sprite(gfx_sprite_t *sprite, int x, int y); + +/** + * Draws an unclipped sprite + * + * @param sprite Pointer to initialized sprite structure + * @param x X coordinate + * @param y Y coordinate + */ +void gfx_Sprite_NoClip(gfx_sprite_t *sprite, uint24_t x, uint8_t y); + +/** + * Draws a transparent sprite + * + * @param sprite Pointer to initialized sprite structure + * @param x X coordinate + * @param y Y coordinate + */ +void gfx_TransparentSprite(gfx_sprite_t *sprite, int x, int y); + +/** + * Draws an unclipped transparent sprite + * + * @param sprite Pointer to initialized sprite structure + * @param x X coordinate + * @param y Y coordinate + */ +void gfx_TransparentSprite_NoClip(gfx_sprite_t *sprite, uint24_t x, uint8_t y); + +/** + * Grabs the background behind a sprite + * + * This is useful for partial redraw. + * @param sprite_buffer Buffer used to store grabbed sprite + * @param x X coordinate to grab sprite + * @param y Y coordinate to grab sprite + * @returns A pointer to sprite_buffer + * @note sprite_buffer must be pointing to a large enough buffer to hold width*height number of bytes + */ +gfx_sprite_t *gfx_GetSprite(gfx_sprite_t *sprite_buffer, int x, int y); + +/** + * Grabs the background behind an unclipped sprite + * + * This is useful for partial redraw. + * @param sprite_buffer Buffer used to store grabbed sprite + * @param x X coordinate to grab sprite + * @param y Y coordinate to grab sprite + * @returns A pointer to sprite_buffer + * @note sprite_buffer must be pointing to a large enough buffer to hold width*height number of bytes + */ +#define gfx_GetSprite_NoClip(sprite_buffer, x, y) \ +gfx_GetSprite((sprite_buffer), (x), (y)) + +/** + * Scales an unclipped sprite + * + * Scaling factors must be greater than or equal to 1, and an integer factor + * @param sprite Pointer to initialized sprite structure + * @param x X coordinate + * @param y Y coordinate + * @param width_scale Width scaling factor + * @param height_scale Height scaling factor + * @note Useable with gfx_GetSprite in order to create clipped versions + */ +void gfx_ScaledSprite_NoClip(gfx_sprite_t *sprite, uint24_t x, uint8_t y, uint8_t width_scale, uint8_t height_scale); + +/** + * Scales an unclipped transparent sprite + * + * Scaling factors must be greater than or equal to 1, and an integer factor + * @param sprite Pointer to initialized sprite structure + * @param x X coordinate + * @param y Y coordinate + * @param width_scale Width scaling factor + * @param height_scale Height scaling factor + * @note Useable with gfx_GetSprite in order to create clipped versions + */ +void gfx_ScaledTransparentSprite_NoClip(gfx_sprite_t *sprite, uint24_t x, uint8_t y, uint8_t width_scale, uint8_t height_scale); + +/** + * Fixed Rotation with scaling fator for sprites + * + * @note A scale factor of 64 represents 100% scaling + * @warning This routine only accepts square input sprites + * @param sprite Input sprite to rotate/scale + * @param x X coordinate position + * @param x Y coordinate position + * @param angle 256 position angular integer + * @param scale Scaling factor; range is about 1% to 400% scale + * @returns The size of the sprite after scaling. This can be used for centering purposes. + */ +uint8_t gfx_RotatedScaledTransparentSprite_NoClip(gfx_sprite_t *sprite, uint24_t x, uint8_t y, uint8_t angle, uint8_t scale); + +/** + * Helper macro to only perform rotation using gfx_RotatedScaledTransparentSprite_NoClip + * + * @param sprite_in Input sprite to rotate + * @param sprite_out Pointer to where rotated sprite will be stored + * @param angle 256 position angular integer + * @see gfx_RotatedScaledTransparentSprite_NoClip + */ +#define gfx_RotatedTransparentSprite_NoClip(sprite, x, y, angle) gfx_RotatedScaledTransparentSprite_NoClip(sprite, x, y, angle, 64) + +/** + * Fixed Rotation with scaling fator for sprites without transparency + * + * @note A scale factor of 64 represents 100% scaling + * @warning This routine only accepts square input sprites + * @param sprite Input sprite to rotate/scale + * @param x X coordinate position + * @param x Y coordinate position + * @param angle 256 position angular integer + * @param scale Scaling factor; range is about 1% to 400% scale + * @returns The size of the sprite after scaling. This can be used for centering purposes. + */ +uint8_t gfx_RotatedScaledSprite_NoClip(gfx_sprite_t *sprite, uint24_t x, uint8_t y, uint8_t angle, uint8_t scale); + +/** + * Helper macro to only perform rotation using gfx_RotatedScaledSprite_NoClip + * + * @param sprite_in Input sprite to rotate + * @param sprite_out Pointer to where rotated sprite will be stored + * @param angle 256 position angular integer + * @see gfx_RotatedScaledTransparentSprite_NoClip + */ +#define gfx_RotatedSprite_NoClip(sprite, x, y, angle) gfx_RotatedScaledTransparentSprite_NoClip(sprite, x, y, angle, 64) + +/** + * Flips a sprite along the X axis + * + * @param sprite_in Input sprite to flip + * @param sprite_out Pointer to where flipped sprite will be stored + * @returns A pointer to sprite_out + * @note sprite_in and sprite_out cannot be the same + */ +gfx_sprite_t *gfx_FlipSpriteX(gfx_sprite_t *sprite_in, gfx_sprite_t *sprite_out); + +/** + * Flips a sprite along the Y axis + * + * @param sprite_in Input sprite to flip + * @param sprite_out Pointer to where flipped sprite will be stored + * @returns A pointer to sprite_out + * @note sprite_in and sprite_out cannot be the same + */ +gfx_sprite_t *gfx_FlipSpriteY(gfx_sprite_t *sprite_in, gfx_sprite_t *sprite_out); + +/** + * Rotates a sprite 90 degrees clockwise + * + * @param sprite_in Input sprite to rotate + * @param sprite_out Pointer to where rotated sprite will be stored + * @returns A pointer to sprite_out + * @note sprite_in and sprite_out cannot be the same + */ +gfx_sprite_t *gfx_RotateSpriteC(gfx_sprite_t *sprite_in, gfx_sprite_t *sprite_out); + +/** + * Rotates a sprite 90 degrees counter clockwise + * + * @param sprite_in Input sprite to rotate + * @param sprite_out Pointer to where rotated sprite will be stored + * @returns A pointer to sprite_out + * @note sprite_in and sprite_out cannot be the same + */ +gfx_sprite_t *gfx_RotateSpriteCC(gfx_sprite_t *sprite_in, gfx_sprite_t *sprite_out); + +/** + * Rotates a sprite 180 degrees + * + * @param sprite_in Input sprite to rotate + * @param sprite_out Pointer to where rotated sprite will be stored + * @returns A pointer to sprite_out + */ +gfx_sprite_t *gfx_RotateSpriteHalf(gfx_sprite_t *sprite_in, gfx_sprite_t *sprite_out); + +/** + * Resizes a sprite to new dimensions + * + * Place new image dimensions in sprite_out; i.e. sprite_out->width = 80; sprite_out->height = 20. + * @param sprite_in Input sprite to scale + * @param sprite_out Pointer to where scaled sprite will be stored + * @returns A pointer to \p sprite_out + */ +gfx_sprite_t *gfx_ScaleSprite(gfx_sprite_t *sprite_in, gfx_sprite_t *sprite_out); + +/** + * Fixed Rotation with scaling factor for sprites + * + * The output sprite is updated with the dimensions required for the implemented scaling factor. + * You must make sure that \p sprite_out has enough memory to store the needed output sprite. This can be + * found with the following formula: size = (max_scale / 64) * width * height + 2; + * + * @note A scale factor of 64 represents 100% scaling + * @warning This routine only accepts square input sprites + * @param sprite_in Input sprite to rotate/scale + * @param sprite_out Pointer to where rotated/scaled sprite will be stored + * @param angle 256 position angular integer + * @param scale Scaling factor; range is about 1% to 400% scale + * @returns A pointer to \p sprite_out + */ +gfx_sprite_t *gfx_RotateScaleSprite(gfx_sprite_t *sprite_in, gfx_sprite_t *sprite_out, uint8_t angle, uint8_t scale); + +/** + * Helper macro to only perform rotation using gfx_RotateScaleSprite + * + * @param sprite_in Input sprite to rotate + * @param sprite_out Pointer to where rotated sprite will be stored + * @param angle 256 position angular integer + * @returns A pointer to \p sprite_out + * @see gfx_RotateScaleSprite + */ +#define gfx_RotateSprite(sprite_in, sprite_out, angle) gfx_RotateScaleSprite(sprite_in, sprite_out, angle, 64) + +/** + * Creates a temporary character sprite + * + * This may be useful for performing rotations and other + * operations on characters. The sprite returned is always 8x8 pixels. + * @param c Character to generate + */ +gfx_sprite_t *gfx_GetSpriteChar(char c); + +/** + * Sets the font's character data + * + * Fonts can be created manually or and exported to a C-style format using 8x8 Pixel ROM Font Editor. + * (https://www.min.at/prinz/o/software/pixelfont/#download) + * + * @param data Pointer to formated 8x8 pixel font + * @returns Pointer to previous font data + * @note Format of font data is 8 bytes horizontally aligned. + */ +uint8_t *gfx_SetFontData(uint8_t *data); + +/** + * Sets the font data for a specific character + * + * @param index Character index to modify (if using default font, values range from 0-127, custom font can have indexes 0-255) + * @param data Pointer to formated 8x8 pixel font + * @returns Pointer to current character data if \p data is NULL, otherwise a pointer to next character data + * @note Format of font data is 8 bytes horizontally aligned. + * @see gfx_SetFontData + */ +uint8_t *gfx_SetCharData(uint8_t index, uint8_t *data); + +/** + * Sets the font spacing + * + * @param spacing Pointer to array of character spacing + */ +void gfx_SetFontSpacing(uint8_t *spacing); + +/** + * Sets the height in pixels of each character + * + * The default value is 8 pixels + * @param height New font height in pixels + * @returns Previous height of font in pixels + */ +uint8_t gfx_SetFontHeight(uint8_t height); + +/** + * Sets monospaced font + * + * @param spacing Distance between characters + * @note To disable monospaced font, set to 0 + */ +void gfx_SetMonospaceFont(uint8_t spacing); + +/** + * Gets the pixel width of the given string + * + * @param string Pointer to string + * @note Takes into account monospacing flag + */ +unsigned int gfx_GetStringWidth(const char *string); + +/** + * Gets the pixel width of the given character + * + * @param c Character to get width of + * @returns Width in pixels of character + * @note Takes into account monospacing flag + */ +unsigned int gfx_GetCharWidth(const char c); + +/** + * Sets the clipping window + * + * This window is used across all clipped routines + * @param xmin Minimum x coordinate + * @param ymin Minimum y coordinate + * @param xmax Maximum x coordinate + * @param ymax Maximum y coordinate + * @note This routine is exclusive + */ +void gfx_SetClipRegion(int xmin, int ymin, int xmax, int ymax); + +/** + * Clips a region to fit within the window + * + * @returns False if offscreen, true if onscreen + */ +bool gfx_GetClipRegion(gfx_region_t *region); + +/** + * Shifts the drawing window down + * + * @param pixels Number of pixels to shift + * @note Data left over is undefined (Must be drawn over) + */ +void gfx_ShiftDown(uint8_t pixels); + +/** + * Shifts the drawing window up + * + * @param pixels Number of pixels to shift + * @note Data left over is undefined (Must be drawn over) + */ +void gfx_ShiftUp(uint8_t pixels); + +/** + * Shifts the drawing window left + * + * @param pixels Number of pixels to shift + * @note Data left over is undefined (Must be drawn over) + */ +void gfx_ShiftLeft(uint24_t pixels); + +/** + * Shifts the drawing window right + * + * @param pixels Number of pixels to shift + * @note Data left over is undefined (Must be drawn over) + */ +void gfx_ShiftRight(uint24_t pixels); + +/** + * Lightens a given 1555 color; useful for palette color conversions. + * + * @param color Original color input in 1555 format + * @param amount Amount to lighten by + * @returns Lightened color + * @note 0 returns full white, 255 returns original color + */ +uint16_t gfx_Lighten(uint16_t color, uint8_t amount); + +/** + * Darkens a given 1555 color; useful for palette color conversions. + * + * @param color Original color input in 1555 format + * @param amount Amount to darken by + * @returns Darkened color + * @note 0 returns full black, 255 returns original color + */ +uint16_t gfx_Darken(uint16_t color, uint8_t amount); + +/** + * Fills an area with a color + * + * @param x X coordinate to begin filling at + * @param y Y coordinate to begin filling at + * @param color New color to fill with + * + * @note This routine performs clipping to stay within the window, but you must ensure it starts in the window. + */ +void gfx_FloodFill(unsigned int x, uint8_t y, uint8_t color); + +/** + * Draws a sprite with RLE transparency. + * + * @param sprite sprite to draw + * @param x x-coordinate + * @param y y-coordinate + */ +void gfx_RLETSprite(gfx_rletsprite_t *sprite, int x, int y); + +/** + * Draws an unclipped sprite with RLE transparency. + * + * @param sprite sprite to draw + * @param x x-coordinate + * @param y y-coordinate + */ +void gfx_RLETSprite_NoClip(gfx_rletsprite_t *sprite, uint24_t x, uint8_t y); + +/** + * Converts a sprite with RLE transpareny to a sprite with normal transparency. + * + * Width and height will be set in the converted sprite. + * + * The transparent color index in the converted sprite is controlled by + * gfx_SetTransparentColor(). + * + * @attention + * The output sprite must have been allocated with a large enough \c data field + * to hold the converted sprite data, which will be <tt>width * height</tt> + * bytes large. + * + * @param[in] sprite_in input sprite with RLE transparency + * @param[out] sprite_out converted sprite with normal transparency + * @returns the converted sprite + * @see gfx_ConvertMallocRLETSprite + * @see gfx_ConvertToRLETSprite + */ +gfx_sprite_t *gfx_ConvertFromRLETSprite(gfx_rletsprite_t *sprite_in, gfx_sprite_t *sprite_out); + +/** + * Converts a sprite with normal transpareny to a sprite with RLE transparency. + * + * Width and height will be set in the converted sprite. + * + * The transparent color index in the input sprite is controlled by + * gfx_SetTransparentColor(). + * + * @attention + * The output sprite must have been allocated with a large enough data field to + * hold the converted sprite data; see gfx_AllocRLETSprite() for information. + * + * @note + * To avoid needing to predict the output size and risking either the prediction + * being too high and wasting space, or being too low and corrupting memory, + * gfx_ConvertMallocRLETSprite() can be used instead to allocate the exact + * amount of necessary space for the converted sprite. + * + * @param[in] sprite_in input sprite with normal transparency + * @param[out] sprite_out converted sprite with RLE transparency + * @returns the converted sprite + * @see gfx_ConvertFromRLETSprite + */ +gfx_rletsprite_t *gfx_ConvertToRLETSprite(gfx_sprite_t *sprite_in, gfx_rletsprite_t *sprite_out); + +/** + * Converts a sprite with normal transpareny to a sprite with RLE transparency, + * allocating the exact amount of necessary space for the converted sprite. + * + * Allocates the memory with \p malloc_routine. Width and height will be set in + * the converted sprite. Returns \c NULL upon allocation failure. + * + * The transparent color index in the input sprite is controlled by + * gfx_SetTransparentColor(). + * + * @remarks + * If using \c malloc as the \p malloc_routine, gfx_ConvertMallocRLETSprite() + * can be used as a shortcut. + * + * @remarks + * A gfx_sprite_t can be converted into an appropriately large, + * already-allocated gfx_rletsprite_t using gfx_ConvertToRLETSprite(). + * + * @param sprite_in input sprite with normal transparency + * @param malloc_routine malloc implementation to use + * @returns a newly allocated converted sprite with RLE transparency + * @see gfx_ConvertFromRLETSprite + */ +gfx_rletsprite_t *gfx_ConvertToNewRLETSprite(gfx_sprite_t *sprite_in, void *(*malloc_routine)(size_t)); + +/** + * Converts a sprite with normal transpareny to a sprite with RLE transparency, + * allocating the exact amount of necessary space for the converted sprite using + * \c malloc. + * + * Width and height will be set in the converted sprite. Returns \c NULL upon + * allocation failure. + * + * The transparent color index in the input sprite is controlled by + * gfx_SetTransparentColor(). + * + * @remarks + * A gfx_sprite_t can be converted into an appropriately large, + * already-allocated gfx_rletsprite_t using gfx_ConvertToRLETSprite(). + * + * @param sprite_in input sprite with normal transparency + * @param malloc_routine malloc implementation to use + * @returns a newly allocated converted sprite with RLE transparency + * @see gfx_ConvertFromRLETSprite + */ +#define gfx_ConvertMallocRLETSprite(sprite_in) \ +gfx_ConvertToNewRLETSprite(sprite_in, malloc) + +/** + * Converts an RGB value to a palette color + * + * Conversion is not 100% perfect, but is quite close + */ +#define gfx_RGBTo1555(r,g,b) \ +((uint16_t)(((uint8_t)(r) >> 3) << 10) | \ +(((uint8_t)(g) >> 3) << 5) | \ +((uint8_t)(b) >> 3)) + +/** + * Checks if we are currently in a rectangular hotspot area + */ +#define gfx_CheckRectangleHotspot(master_x, master_y, master_width, master_height, test_x, test_y, test_width, test_height) \ +(((test_x) < ((master_x) + (master_width))) && \ +(((test_x) + (test_width)) > (master_x)) && \ +((test_y) < ((master_y) + (master_height))) && \ +(((test_y) + (test_height)) > (master_y))) + +/* Color definitions (try to avoid) */ +#define gfx_black 0x00 +#define gfx_red 0xE0 +#define gfx_orange 0xE3 +#define gfx_green 0x03 +#define gfx_blue 0x10 +#define gfx_purple 0x50 +#define gfx_yellow 0xE7 +#define gfx_pink 0xF0 +#define gfx_white 0xFF + +/* Compatability defines (don't use please) */ +typedef gfx_sprite_t gfx_image_t; +#define gfx_BlitArea gfx_BlitRectangle +void gfx_LZDecompress(uint8_t *in, uint8_t *out, unsigned int in_size); + +#define gfx_lcdWidth (320) +#define gfx_lcdHeight (240) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/intce.h b/frontends/calculator/CEdev/include/intce.h new file mode 100644 index 0000000..1184c29 --- /dev/null +++ b/frontends/calculator/CEdev/include/intce.h @@ -0,0 +1,93 @@ +/** + * @file + * @authors Matt "MateoConLechuga" Waltz + * @authors Jacob "jacobly" Young + * @brief Interrupt configuring and setting + */ + +#ifndef INTCE_H +#define INTCE_H + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enable global interrupts + */ +#define int_Enable() \ +asm("ei") + +/** + * @brief Diasble global interrupts + */ +#define int_Disable() \ +asm("di") + +/** + * @brief Blocking wait for an interrupt to trigger + */ +#define int_Wait() \ +asm("halt") + +#ifdef FORCE_INTERRUPTS +#warning TI has removed custom interrupt support on CE models with hardware revision >= I. Please check that this is acceptable. + +/** + * Initizalize to use custom interrupts + * @note Saves status of current interrupt state + * @warning TI has removed custom interrupt support on CE models with hardware revision >= I. + */ +void int_Initialize(void); + +/** + * Resets interrupts back to the OS expected values + * @warning Must have called int_Initialize before using + * @warning TI has removed custom interrupt support on CE models with hardware revision >= I. + */ +void int_Reset(void); + +/** + * Sets up an interrupt vector given an ISR + * @param ivect Interrupt vector to set + * @param handler Handler to interrupt service routine + * @warning TI has removed custom interrupt support on CE models with hardware revision >= I. + */ +void int_SetVector(uint8_t ivect, void (*handler)(void)); + +#endif + +#define ON_IVECT 0 /**< [on] key interrupt source */ +#define TIMER1_IVECT 1 /**< Timer 1 interrupt source */ +#define TIMER2_IVECT 2 /**< Timer 2 interrupt source */ +#define TIMER3_IVECT 3 /**< Timer 3 interrupt source */ +#define TIMEROS_IVECT 4 /**< Timer OS interrupt source */ +#define KEYBOARD_IVECT 10 /**< Keyboard interrupt source */ +#define LCD_IVECT 11 /**< LCD interrupt source */ +#define RTC_IVECT 12 /**< Real Time Clock interrupt source */ +#define USB_IVECT 13 /**< USB interrupt source */ + +#define INT_ON 1<<ON_IVECT /**< [on] key interrupt source mask */ +#define INT_TIMER1 1<<TIMER1_IVECT /**< Timer 1 interrupt source mask */ +#define INT_TIMER2 1<<TIMER2_IVECT /**< Timer 2 interrupt source mask */ +#define INT_TIMER3 1<<TIMER3_IVECT /**< Timer 3 interrupt source mask */ +#define INT_TIMEROS 1<<TIMEROS_IVECT /**< Timer OS interrupt source mask */ +#define INT_KEYBOARD 1<<KEYBOARD_IVECT /**< Keyboard interrupt source mask */ +#define INT_LCD 1<<LCD_IVECT /**< LCD interrupt source mask */ +#define INT_RTC 1<<RTC_IVECT /**< Real Time Clock interrupt source mask */ +#define INT_USB 1<<USB_IVECT /**< USB interrupt source mask */ + +#define int_RawStatus (*(volatile uint24_t*)0x0F00000) /**< State of interrupt signals */ +#define int_MaskedStatus (*(volatile uint24_t*)0x0F00014) /**< Masked state of interrupt signals */ +#define int_EnableConfig (*(uint24_t*)0x0F00004) /**< Enabled interrupt signals */ +#define int_LatchConfig (*(uint24_t*)0x0F0000C) /**< Latchable interrupt signals */ +#define int_InvertConfig (*(uint24_t*)0x0F00010) /**< Invertable interrupt signals */ +#define int_Acknowledge (*(uint24_t*)0x0F00008) /**< Acknowledge interrupt signals */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/iso646.h b/frontends/calculator/CEdev/include/iso646.h new file mode 100644 index 0000000..d8e83a5 --- /dev/null +++ b/frontends/calculator/CEdev/include/iso646.h @@ -0,0 +1,18 @@ +#ifndef __ISO646_H +#define __ISO646_H + +#ifndef __cplusplus +#define and && +#define and_eq &= +#define bitand & +#define bitor | +#define compl ~ +#define not ! +#define not_eq != +#define or || +#define or_eq |= +#define xor ^ +#define xor_eq ^= +#endif + +#endif
\ No newline at end of file diff --git a/frontends/calculator/CEdev/include/keypadc.h b/frontends/calculator/CEdev/include/keypadc.h new file mode 100644 index 0000000..1b92f1c --- /dev/null +++ b/frontends/calculator/CEdev/include/keypadc.h @@ -0,0 +1,255 @@ +/** + * @file + * @authors Matt "MateoConLechuga" Waltz + * @authors Shaun "Methsoft" McFall + * @brief Simple direct input keypad library + */ + +#ifndef H_KEYPADC +#define H_KEYPADC + +#include <stdint.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef uint8_t kb_key_t; ///< Normal key type +typedef uint16_t kb_lkey_t; ///< Long key type + +/** + * Scans the keyboard to update data values + * @note Disables interrupts + */ +void kb_Scan(void); + +/** + * Scans the given keyboard row and returns the row value + * @param row Row to scan + * @note Disables interrupts + */ +kb_key_t kb_ScanGroup(uint8_t row); + +/** + * Scans the keyboard quickly to tell if any key was pressed + * @note Disables interrupts + */ +uint8_t kb_AnyKey(void); + +/** + * Resets the keyboard + * @note Only use if you modify keyboard timers or number of rows + */ +void kb_Reset(void); + +/** + * @brief Sets the keypad scanning mode + * @see kb_scan_mode_t + */ +#define kb_SetMode(mode) \ +(kb_Config = ((kb_Config & ~3)|(mode))) + +/** + * @brief Gets the keypad scanning mode + * @see kb_scan_mode_t + */ +#define kb_GetMode() \ +(kb_Config & 3) + +/** + * Different available scanning modes + */ +typedef enum { + MODE_0_IDLE = 0, /**< Keypad scanning is idle */ + MODE_1_INDISCRIMINATE, /**< Indiscriminate key detection. Data registers are invalid, but whenever any key is pressed, interrupt KB_MODE_1_PRESS is set (and cannot be cleared until the key is released). */ + MODE_2_SINGLE, /**< Single scan. The keypad is scanned once, and then the mode returns to MODE_0_IDLE. */ + MODE_3_CONTINUOUS /**< Continuous scan. When scanning completes, it just starts over again after a delay. */ +} kb_scan_mode_t; + +#define kb_EnableInt \ +(*(uint8_t*)0xF5000C) /**< Enabled keypad interrupt signals */ +#define kb_IntAcknowledge \ +(*(volatile uint8_t*)0xF50008) /**< Acknowledege keypad interrupt signals */ +#define kb_IntStatus \ +(*(volatile uint8_t*)0xF50008) /**< Status of keypad interrupt signals */ +#define kb_Config \ +(*(uint8_t*)0xF50000) /**< Configuration of keypad controller */ + +/** + * Keypad Data registers + * + * | Offset | Bit 0 | Bit 1 | Bit 2 | Bit 3 | Bit 4 | Bit 5 | Bit 6 | Bit 7 | + * | -------| ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | + * | 1 | kb_Graph | kb_Trace | kb_Zoom | kb_Window | kb_Yequ | kb_2nd | kb_Mode | kb_Del | + * | 2 | | kb_Sto | kb_Ln | kb_Log | kb_Square | kb_Recip | kb_Math | kb_Alpha | + * | 3 | kb_0 | kb_1 | kb_4 | kb_7 | kb_Comma | kb_Sin | kb_Apps | kb_GraphVar| + * | 4 | kb_DecPnt | kb_2 | kb_5 | kb_8 | kb_LParen | kb_Cos | kb_Prgm | kb_Stat | + * | 5 | kb_Chs | kb_3 | kb_6 | kb_9 | kb_RParen | kb_Tan | kb_Vars | | + * | 6 | kb_Enter | kb_Add | kb_Sub | kb_Mul | kb_Div | kb_Power | kb_Clear | | + * | 7 | kb_Down | kb_Left | kb_Right | kb_Up | | | | | + * + * These data registers can be indexed just like an array. For example, if you want to check the status of the '2nd' key: + * @code + * if (kb_Data[1] & kb_2nd) { + * ... + * } + * @endcode + */ +#define kb_Data \ +(uint8_t)((uint16_t*)0xF50010) + +/** + * Different available interrupt signals + */ +typedef enum { + KB_SCAN_COMPLETE = 1, /**< Interrupt set when keypad is done scanning */ + KB_DATA_CHANGED = 2, /**< Interrupt set when data is changed on a press or a release */ + KB_MODE_1_PRESS = 4 /**< Interrupt set when a key is pressed in MODE_1_INDISCRIMINATE */ +} kb_int_signal_t; + +/* Keyboard group 1 */ +#define kb_Graph 1<<0 +#define kb_Trace 1<<1 +#define kb_Zoom 1<<2 +#define kb_Window 1<<3 +#define kb_Yequ 1<<4 +#define kb_2nd 1<<5 +#define kb_Mode 1<<6 +#define kb_Del 1<<7 + +/* Keyboard group 2 */ +#define kb_Sto 1<<1 +#define kb_Ln 1<<2 +#define kb_Log 1<<3 +#define kb_Square 1<<4 +#define kb_Recip 1<<5 +#define kb_Math 1<<6 +#define kb_Alpha 1<<7 + +/* Keyboard group 3 */ +#define kb_0 1<<0 +#define kb_1 1<<1 +#define kb_4 1<<2 +#define kb_7 1<<3 +#define kb_Comma 1<<4 +#define kb_Sin 1<<5 +#define kb_Apps 1<<6 +#define kb_GraphVar 1<<7 + +/* Keyboard group 4 */ +#define kb_DecPnt 1<<0 +#define kb_2 1<<1 +#define kb_5 1<<2 +#define kb_8 1<<3 +#define kb_LParen 1<<4 +#define kb_Cos 1<<5 +#define kb_Prgm 1<<6 +#define kb_Stat 1<<7 + +/* Keyboard group 5 */ +#define kb_Chs 1<<0 +#define kb_3 1<<1 +#define kb_6 1<<2 +#define kb_9 1<<3 +#define kb_RParen 1<<4 +#define kb_Tan 1<<5 +#define kb_Vars 1<<6 + +/* Keyboard group 6 */ +#define kb_Enter 1<<0 +#define kb_Add 1<<1 +#define kb_Sub 1<<2 +#define kb_Mul 1<<3 +#define kb_Div 1<<4 +#define kb_Power 1<<5 +#define kb_Clear 1<<6 + +/* Keyboard group 7 */ +#define kb_Down 1<<0 +#define kb_Left 1<<1 +#define kb_Right 1<<2 +#define kb_Up 1<<3 + +/* Keyboard group 1 */ +#define kb_KeyGraph (kb_lkey_t)(1 << 8 | 1<<0) +#define kb_KeyTrace (kb_lkey_t)(1 << 8 | 1<<1) +#define kb_KeyZoom (kb_lkey_t)(1 << 8 | 1<<2) +#define kb_KeyWindow (kb_lkey_t)(1 << 8 | 1<<3) +#define kb_KeyYequ (kb_lkey_t)(1 << 8 | 1<<4) +#define kb_Key2nd (kb_lkey_t)(1 << 8 | 1<<5) +#define kb_KeyMode (kb_lkey_t)(1 << 8 | 1<<6) +#define kb_KeyDel (kb_lkey_t)(1 << 8 | 1<<7) + +/* Keyboard group 2 */ +#define kb_KeyStore (kb_lkey_t)(2 << 8 | 1<<1) +#define kb_KeyLn (kb_lkey_t)(2 << 8 | 1<<2) +#define kb_KeyLog (kb_lkey_t)(2 << 8 | 1<<3) +#define kb_KeySquare (kb_lkey_t)(2 << 8 | 1<<4) +#define kb_KeyRecip (kb_lkey_t)(2 << 8 | 1<<5) +#define kb_KeyMath (kb_lkey_t)(2 << 8 | 1<<6) +#define kb_KeyAlpha (kb_lkey_t)(2 << 8 | 1<<7) + +/* Keyboard group 3 */ +#define kb_Key0 (kb_lkey_t)(3 << 8 | 1<<0) +#define kb_Key1 (kb_lkey_t)(3 << 8 | 1<<1) +#define kb_Key4 (kb_lkey_t)(3 << 8 | 1<<2) +#define kb_Key7 (kb_lkey_t)(3 << 8 | 1<<3) +#define kb_KeyComma (kb_lkey_t)(3 << 8 | 1<<4) +#define kb_KeySin (kb_lkey_t)(3 << 8 | 1<<5) +#define kb_KeyApps (kb_lkey_t)(3 << 8 | 1<<6) +#define kb_KeyGraphVar (kb_lkey_t)(3 << 8 | 1<<7) + +/* Keyboard group 4 */ +#define kb_KeyDecPnt (kb_lkey_t)(4 << 8 | 1<<0) +#define kb_Key2 (kb_lkey_t)(4 << 8 | 1<<1) +#define kb_Key5 (kb_lkey_t)(4 << 8 | 1<<2) +#define kb_Key8 (kb_lkey_t)(4 << 8 | 1<<3) +#define kb_KeyLParen (kb_lkey_t)(4 << 8 | 1<<4) +#define kb_KeyCos (kb_lkey_t)(4 << 8 | 1<<5) +#define kb_KeyPrgm (kb_lkey_t)(4 << 8 | 1<<6) +#define kb_KeyStat (kb_lkey_t)(4 << 8 | 1<<7) + +/* Keyboard group 5 */ +#define kb_KeyChs (kb_lkey_t)(5 << 8 | 1<<0) +#define kb_Key3 (kb_lkey_t)(5 << 8 | 1<<1) +#define kb_Key6 (kb_lkey_t)(5 << 8 | 1<<2) +#define kb_Key9 (kb_lkey_t)(5 << 8 | 1<<3) +#define kb_KeyRParen (kb_lkey_t)(5 << 8 | 1<<4) +#define kb_KeyTan (kb_lkey_t)(5 << 8 | 1<<5) +#define kb_KeyVars (kb_lkey_t)(5 << 8 | 1<<6) + +/* Keyboard group 6 */ +#define kb_KeyEnter (kb_lkey_t)(6 << 8 | 1<<0) +#define kb_KeyAdd (kb_lkey_t)(6 << 8 | 1<<1) +#define kb_KeySub (kb_lkey_t)(6 << 8 | 1<<2) +#define kb_KeyMul (kb_lkey_t)(6 << 8 | 1<<3) +#define kb_KeyDiv (kb_lkey_t)(6 << 8 | 1<<4) +#define kb_KeyPower (kb_lkey_t)(6 << 8 | 1<<5) +#define kb_KeyClear (kb_lkey_t)(6 << 8 | 1<<6) + +/* Keyboard group 7 */ +#define kb_KeyDown (kb_lkey_t)(7 << 8 | 1<<0) +#define kb_KeyLeft (kb_lkey_t)(7 << 8 | 1<<1) +#define kb_KeyRight (kb_lkey_t)(7 << 8 | 1<<2) +#define kb_KeyUp (kb_lkey_t)(7 << 8 | 1<<3) + +/* Compatibility defines */ +#define kb_DataArray ((uint16_t*)0xF50010) +#define kb_dataArray ((uint16_t*)0xF50010) +#define kb_Store 1<<1 +#define kb_KeyPgrm kb_KeyPrgm +#define kb_group_0 0 +#define kb_group_1 1 +#define kb_group_2 2 +#define kb_group_3 3 +#define kb_group_4 4 +#define kb_group_5 5 +#define kb_group_6 6 +#define kb_group_7 7 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/lib/ce/fileioc.h b/frontends/calculator/CEdev/include/lib/ce/fileioc.h new file mode 100644 index 0000000..8bb6ee4 --- /dev/null +++ b/frontends/calculator/CEdev/include/lib/ce/fileioc.h @@ -0,0 +1,2 @@ +#warning You are using a deprecated lib include path. Simply use #include <fileioc.h> instead +#include <fileioc.h> diff --git a/frontends/calculator/CEdev/include/lib/ce/graphx.h b/frontends/calculator/CEdev/include/lib/ce/graphx.h new file mode 100644 index 0000000..9a1343c --- /dev/null +++ b/frontends/calculator/CEdev/include/lib/ce/graphx.h @@ -0,0 +1,2 @@ +#warning You are using a deprecated lib include path. Simply use #include <graphx.h> instead +#include <graphx.h> diff --git a/frontends/calculator/CEdev/include/lib/ce/keypadc.h b/frontends/calculator/CEdev/include/lib/ce/keypadc.h new file mode 100644 index 0000000..7c2fd66 --- /dev/null +++ b/frontends/calculator/CEdev/include/lib/ce/keypadc.h @@ -0,0 +1,2 @@ +#warning You are using a deprecated lib include path. Simply use #include <keypadc.h> instead +#include <keypadc.h> diff --git a/frontends/calculator/CEdev/include/limits.h b/frontends/calculator/CEdev/include/limits.h new file mode 100644 index 0000000..2dbdab8 --- /dev/null +++ b/frontends/calculator/CEdev/include/limits.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + * Modified by Matt "MateoConLechuga" Waltz for TI84+CE platform + */ +#ifndef LIMITS_H +#define LIMITS_H + +#define CHAR_BIT 8 /* number of bits in byte */ +#define SCHAR_MAX 127 /* max value for signed char */ +#define SCHAR_MIN (-127-1) /* min value for signed char */ +#define UCHAR_MAX 0xFF /* max value for unsigned char */ +#ifdef __UNSIGNED_CHARS__ +#define CHAR_MAX UCHAR_MAX /* max value for char */ +#define CHAR_MIN 0 /* Min value for char */ +#else +#define CHAR_MAX SCHAR_MAX /* max value for char */ +#define CHAR_MIN SCHAR_MIN /* Min value for char */ +#endif + +#define SHRT_MAX 32767 /* max value for short int */ +#define SHRT_MIN (-32767-1) /* min value for short int */ +#define USHRT_MAX 0xFFFF /* max value for unsigned short */ + +#define INT_MAX 8388607 /* max value for int */ +#define INT_MIN (-8388607 - 1) /* min value for int */ +#define UINT_MAX 0xFFFFFF /* max value for unsigned int */ + +#define LONG_MAX 2147483647L /* max value for long int */ +#define LONG_MIN (-2147483647L - 1) /* min value for long int */ +#define ULONG_MAX 0xFFFFFFFFUL /* max value for unsigned long */ + +#define MB_LEN_MAX 1 /* max multibyte char length */ + +#endif diff --git a/frontends/calculator/CEdev/include/math.h b/frontends/calculator/CEdev/include/math.h new file mode 100644 index 0000000..3225311 --- /dev/null +++ b/frontends/calculator/CEdev/include/math.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + * Modified by Matt "MateoConLechuga" Waltz for TI84+CE platform + */ +#ifndef MATH_H +#define MATH_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern double _huge_val; +#define HUGE_VAL _huge_val /* overflow error */ + +#define M_E 2.71828182845904523536 /* e */ +#define M_LOG2E 1.44269504088896340736 /* log2(e) */ +#define M_LOG10E 0.434294481903251827651 /* log10(e) */ +#define M_LN2 0.693147180559945309417 /* ln(2) */ +#define M_LN10 2.30258509299404568402 /* ln(10) */ +#define M_PI 3.14159265358979323846 /* pi */ +#define M_PI_2 1.57079632679489661923 /* pi/2 */ +#define M_PI_4 0.785398163397448309616 /* pi/4 */ +#define M_1_PI 0.318309886183790671538 /* 1/pi */ +#define M_2_PI 0.636619772367581343076 /* 2/pi */ +#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ +#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ +#define M_SQRT1_2 0.707106781186547524401 /* 1/sqrt(2) */ +#define M_LOG_2M_PI 1.83787706640934548 /* log2(M_PI) */ + +double acos(double x); +double asin(double x); +double atan(double x); +double atan2(double y,double x); +double cos(double x); +double sin(double x); +double tan(double x); +double cosh(double x); +double sinh(double x); +double tanh(double x); +double exp(double x); +double ldexp(double x, int exp); +double log(double x); +double log10(double x); +double pow(double x,double y); +double sqrt(double x); +double ceil(double x); +double floor(double x); +double fabs(double x); +double fmod(double x, double y); +double round(double x); + +double frexp(double value, int *exp); +double modf(double value, double *iptr); + +int isinf(double n); +int isnan(double n); +int finite(double n); + +double tgamma(double x); +double log2(double x); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/setjmp.h b/frontends/calculator/CEdev/include/setjmp.h new file mode 100644 index 0000000..3858118 --- /dev/null +++ b/frontends/calculator/CEdev/include/setjmp.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + */ +#ifndef __SETJMP_H +#define __SETJMP_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned char jmp_buf[12]; + +int setjmp(jmp_buf env); +void longjmp(jmp_buf env, int val); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/stdarg.h b/frontends/calculator/CEdev/include/stdarg.h new file mode 100644 index 0000000..2938417 --- /dev/null +++ b/frontends/calculator/CEdev/include/stdarg.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + */ +#ifndef STDARG_H +#define STDARG_H + +typedef char * va_list; +#define _INTSIZEOF(n) (sizeof(n) + sizeof(int)-1-((sizeof(n)-1)%sizeof(int))) + +#define va_start(ap, parm) (ap = (char *)&parm + _INTSIZEOF(parm)) +#define va_arg(ap,type) (*(type *)((ap += _INTSIZEOF(type)) - _INTSIZEOF(type))) +#define va_end(ap) + +#endif diff --git a/frontends/calculator/CEdev/include/stdbool.h b/frontends/calculator/CEdev/include/stdbool.h new file mode 100644 index 0000000..0681e78 --- /dev/null +++ b/frontends/calculator/CEdev/include/stdbool.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + * Modified by Matt "MateoConLechuga" Waltz for TI84+CE platform + */ +#ifndef STDBOOL_H +#define STDBOOL_H + +#ifndef __bool_true_false_are_defined +#define __bool_true_false_are_defined + +#ifndef __cplusplus + +typedef unsigned char bool; + +#define _Bool bool +#define false 0 +#define true 1 + +#endif + +#endif +#endif diff --git a/frontends/calculator/CEdev/include/stddef.h b/frontends/calculator/CEdev/include/stddef.h new file mode 100644 index 0000000..1f277b7 --- /dev/null +++ b/frontends/calculator/CEdev/include/stddef.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + * Modified by Matt "MateoConLechuga" Waltz for TI84+CE platform + */ +#ifndef STDDEF_H +#define STDDEF_H + +#ifndef SIZE_T_DEFINED +#define SIZE_T_DEFINED +typedef unsigned int size_t; +#endif + +#ifndef NULL +#define NULL ((void *)0) +#endif +#define offsetof(type,member) ((size_t) &((type*)0)->member) + +typedef int ptrdiff_t; + +#ifndef __cplusplus +#ifndef WCHAR_T_DEFINED +#define WCHAR_T_DEFINED +typedef unsigned short wchar_t; +#endif +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/stdint.h b/frontends/calculator/CEdev/include/stdint.h new file mode 100644 index 0000000..5e48f60 --- /dev/null +++ b/frontends/calculator/CEdev/include/stdint.h @@ -0,0 +1,19 @@ +#ifndef __STDINT_H +#define __STDINT_H + +typedef signed char int8_t; +typedef unsigned char uint8_t; + +typedef signed short int16_t; +typedef unsigned short uint16_t; + +typedef signed int int24_t; +typedef unsigned int uint24_t; + +typedef signed long int32_t; +typedef unsigned long uint32_t; + +typedef int24_t intptr_t; +typedef uint24_t uintptr_t; + +#endif diff --git a/frontends/calculator/CEdev/include/stdio.h b/frontends/calculator/CEdev/include/stdio.h new file mode 100644 index 0000000..27de9cc --- /dev/null +++ b/frontends/calculator/CEdev/include/stdio.h @@ -0,0 +1,66 @@ +#ifndef STDIO_H +#define STDIO_H + +#include <stdarg.h> +#include <format.h> +#include <fileioc.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILENAME_MAX 9 +#define SYS_OPEN 5 /* max open files */ +#define FOPEN_MAX 5 + +#define SEEK_CUR 1 +#define SEEK_END 2 +#define SEEK_SET 0 + +/* ANSI prototypes */ +#ifndef SIZE_T_DEFINED +#define SIZE_T_DEFINED +typedef unsigned int size_t; +#endif + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#ifndef EOF +#define EOF (-1) /* end of file */ +#endif + +typedef struct __stdio_file { + unsigned char slot; +} FILE; + +extern FILE __stdio_files[FOPEN_MAX]; + +int sprintf(char *s, const char *format, ...); +int vprintf(const char *format, va_list arg); +int vsprintf(char *s, const char *format, va_list arg); + +/* stdio.h functions implemented using FILEIOC */ +int remove(const char *filename); +int fgetc(FILE *stream); +int fputc(int c, FILE *stream); +char *fgets(char *str, int num, FILE *stream); +int fputs(const char *str, FILE *stream); +size_t fread(void *ptr, size_t size, size_t count, FILE *stream); +size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream); +int fseek(FILE *stream, long int offset, int origin); +long int ftell(FILE *stream); +int fclose(FILE *stream); +FILE *fopen(const char *filename, const char *mode); +int feof(FILE *stream); +#define ferror(stream) (0) +#define fflush(ignore) ((void)0) +#define rewind(stream) ti_Rewind(stream->slot) +#define fcloseall() ti_CloseAll() + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/stdlib.h b/frontends/calculator/CEdev/include/stdlib.h new file mode 100644 index 0000000..b45077a --- /dev/null +++ b/frontends/calculator/CEdev/include/stdlib.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + * Modified by Matt "MateoConLechuga" Waltz for TI84+CE platform + */ +#ifndef STDLIB_H +#define STDLIB_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define EXIT_SUCCESS 0 +#define EXIT_FAILURE 1 + +typedef int onexit_t; + +#ifndef __cplusplus +#ifndef WCHAR_T_DEFINED +#define WCHAR_T_DEFINED +typedef unsigned short wchar_t; +#endif +#endif + +typedef struct { + int quot; + int rem; +} div_t; + +typedef struct { + long quot; + long rem; +} ldiv_t; + +/* Heap packet header for malloc */ + +typedef char __align; /* alignment type */ +union header { + struct { + union header *ptr; /* next free block */ + unsigned int size; /* size of block */ + } s; + __align x; +}; +typedef union header _HEADER; + +#define EDOM 4 /* domain error */ +#define ERANGE 5 /* range error */ +extern double _huge_val; +#define HUGE_VAL _huge_val /* overflow error */ + +#define RAND_MAX 8388607 /* maximum value returned by rand() */ + +#ifndef SIZE_T_DEFINED +#define SIZE_T_DEFINED +typedef unsigned int size_t; +#endif +#define HEADER _HEADER +#define allocp _allocp +#define NALLOC 50 + +#ifndef NULL +#define NULL ((void *)0) +#endif + +/* Dynamic memory functions */ +void *calloc(size_t, size_t); +void *malloc(size_t); +void *realloc(void *, size_t); +void free(void *); + +/* Character and string functions */ +double atof(char * nptr); +int atoi(char * nptr); +long atol(char * nptr); +double strtod(char * nptr,char ** endptr); +long strtol(char *nptr,char ** endptr,int base); +unsigned long strtoul(char *nptr,char ** endptr,int base); + +/* Random routines */ +void srand(unsigned int seed); +int rand(void); + +/* Binary search and quicksort */ +void *bsearch(void * key,void * base, size_t nmemb, size_t size, int (*compar)(void * ,void * )); +void qsort(void * base,size_t nmemb,size_t size, int (*compar)(void * ,void * )); + +/* Exit and abort */ +void abort(void); +void exit(int status); + +/* Absolutes and division */ +int abs(int j); +long labs(long j); +div_t div(int numer,int denom); +ldiv_t ldiv(long numer, long denom); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/string.h b/frontends/calculator/CEdev/include/string.h new file mode 100644 index 0000000..762eef7 --- /dev/null +++ b/frontends/calculator/CEdev/include/string.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + * Modified by Matt "MateoConLechuga" Waltz for TI84+CE platform + */ +#ifndef STRING_H +#define STRING_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef SIZE_T_DEFINED +#define SIZE_T_DEFINED +typedef unsigned int size_t; +#endif + +void *memcpy(void *, const void *, size_t); +void *memchr(const void *, int, size_t); +void *memset(void *, int, size_t); +void *memmove(void *, const void *, size_t); +int memcmp(const void *, const void *, size_t); + +char *strcpy(char *, const char *); +char *strncpy(char *, const char *, size_t); +char *strcat(char *, const char *); +char *strncat(char *, const char *, size_t); +char *strchr(const char *, int); +char *strpbrk(const char *, const char *); +char *strrchr(const char *, int); +char *strstr(const char *, const char *); +char *strtok(char *, const char *); +char *strerror(int errnum); +char *strdup(const char *); +char *strndup(const char *, size_t n); +size_t strcspn(const char *, const char *); +size_t strspn(const char *, const char *); +size_t strlen(const char *); +size_t strnlen(const char *, size_t); +int strcmp(const char *, const char *); +int strncmp(const char *, const char *, size_t); +int strcasecmp(const char *, const char *); +int strncasecmp(const char *, const char *, size_t); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/tice.h b/frontends/calculator/CEdev/include/tice.h new file mode 100644 index 0000000..b572c79 --- /dev/null +++ b/frontends/calculator/CEdev/include/tice.h @@ -0,0 +1,2082 @@ +/** + * @file + * @authors Matt "MateoConLechuga" Waltz + * @authors Jacob "jacobly" Young + * @brief Core CE define file + */ + +#ifndef H_TICE +#define H_TICE + +#include <stdbool.h> +#include <stdint.h> +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Hardware & custom macros/functions + */ + +/** + * Returns a pseudo-random 32-bit integer. + * + * @return the random integer + */ +uint32_t random(void); + +/** + * Seeds the pseudo-random number generator used by random() and rand() with the + * value seed. + * + * @param seed the seed value + */ +void srandom(uint32_t seed); + +/** + * Returns a pseudo-random integer in the range of \p min to \p max (inclusive). + */ +#define randInt(min, max) \ +((unsigned)random() % ((max) - (min) + 1) + (min)) + +/** + * Delays for a number of milliseconds. + * <p> + * Counts time spent while interrupted. Assumes a CPU clock speed of 48MHz. + * + * @param msec number of milliseconds + */ +void delay(uint16_t msec); + +/** + * "Atomically" loads from a volatile 32-bit value. + * + * @remarks + * The hardware does not provide a mechanism to truly atomically load from a + * 32-bit value. This "atomic" load is implemented by non-atomically reading the + * value twice and retrying if the values read differ. + * + * @attention + * If the maximum period between two value changes is 1us or less (assuming a + * CPU clock speed of 48MHz), then this function may never complete. For + * instance, the counter of a timer ticking at 1MHz or more should not be read + * using this function. In such a case of a purely increasing or decreasing + * value, atomic_load_increasing_32() or atomic_load_decreasing_32() may be + * appropriate instead. + * + * @param p pointer to 32-bit value + */ +uint32_t atomic_load_32(volatile uint32_t *p); + +/** + * "Atomically" loads from a volatile, increasing 32-bit value. + * + * @remarks + * The hardware does not provide a mechanism to truly atomically load from a + * 32-bit value. This "atomic" load is implemented by temporarily disabling + * interrupts while non-atomically reading the value twice and then returning + * the lesser of the two values read. + * + * @attention + * If the minimum period between two value changes is 5us or less and the + * value's maximum rate of change over a 5us period exceeds 256 (assuming a CPU + * clock speed of 48MHz), then the value returned may be incorrect. Of relevant + * note may be the fact that a 48MHz counter does not exceed this limit. + * + * @param p pointer to 32-bit value + */ +uint32_t atomic_load_increasing_32(volatile uint32_t *p); + +/** + * "Atomically" loads from a volatile, decreasing 32-bit value. + * + * @remarks + * The hardware does not provide a mechanism to truly atomically load from a + * 32-bit value. This "atomic" load is implemented by temporarily disabling + * interrupts while non-atomically reading the value twice and then returning + * the greater of the two values read. + * + * @attention + * If the minimum period between two value changes is 5us or less and the + * value's maximum rate of change over a 5us period exceeds 256 (assuming a CPU + * clock speed of 48MHz), then the value returned may be incorrect. Of relevant + * note may be the fact that a 48MHz counter does not exceed this limit. + * + * @param p pointer to 32-bit value + */ +uint32_t atomic_load_decreasing_32(volatile uint32_t *p); + +/** + * Gets a combination of the RTC time; useful for srand() + */ +#define rtc_Time() (*(volatile uint32_t*)0xF30044) + +/* RTC definitions */ +#define RTC_UNFREEZE (1<<7) +#define RTC_FREEZE (0<<7) +#define RTC_LOAD (1<<6) +#define RTC_ENABLE ((1<<0)|(RTC_UNFREEZE)) +#define RTC_DISABLE (0<<0) + +/* RTC registers */ +#define rtc_Seconds (*(volatile uint8_t*)0xF30000) +#define rtc_Minutes (*(volatile uint8_t*)0xF30004) +#define rtc_Hours (*(volatile uint8_t*)0xF30008) +#define rtc_Days (*(volatile uint16_t*)0xF3000C) +#define rtc_AlarmSeconds (*(uint8_t*)0xF30010) +#define rtc_AlarmMinutes (*(uint8_t*)0xF30014) +#define rtc_AlarmHours (*(uint8_t*)0xF30018) +#define rtc_Control (*(uint8_t*)0xF30020) +#define rtc_LoadSeconds (*(uint8_t*)0xF30024) +#define rtc_LoadMinutes (*(uint8_t*)0xF30028) +#define rtc_LoadHours (*(uint8_t*)0xF3002C) +#define rtc_LoadDays (*(uint16_t*)0xF30030) +#define rtc_IntStatus (*(volatile uint8_t*)0xF30034) +#define rtc_IntAcknowledge (*(volatile uint8_t*)0xF30034) +#define rtc_IsBusy() (rtc_Control & RTC_LOAD) + +/* RTC interrupt masks */ +#define RTC_ALARM_INT_SOURCE (1<<5) +#define RTC_DAY_INT_SOURCE (1<<4) +#define RTC_HR_INT_SOURCE (1<<3) +#define RTC_MIN_INT_SOURCE (1<<2) +#define RTC_SEC_INT_SOURCE (1<<1) + +/* RTC interrupt statuses */ +#define RTC_LOAD_INT (1<<5) +#define RTC_ALARM_INT (1<<4) +#define RTC_DAY_INT (1<<3) +#define RTC_HR_INT (1<<2) +#define RTC_MIN_INT (1<<1) +#define RTC_SEC_INT (1<<0) +#define RTC_INT_MASK (RTC_SEC_INT | RTC_MIN_INT | RTC_HR_INT | RTC_DAY_INT | RTC_ALARM_INT | RTC_LOAD_INT) + +/* Whole bunch of useful timer functions */ +#define TIMER1_ENABLE (1<<0) /* Enables Timer 1 */ +#define TIMER1_DISABLE (0<<0) /* Disables Timer 1 */ +#define TIMER1_32K (1<<1) /* Use the 32K clock for timer 1 */ +#define TIMER1_CPU (0<<1) /* Use the CPU clock rate for timer 1 */ +#define TIMER1_0INT (1<<2) /* Enable an interrupt when 0 is reached for the timer 1 */ +#define TIMER1_NOINT (0<<2) /* Disable interrupts for the timer 1 */ +#define TIMER1_UP (1<<9) /* Timer 1 counts up */ +#define TIMER1_DOWN (0<<9) /* Timer 1 counts down */ + +#define TIMER2_ENABLE (1<<3) /* Enables Timer 2 */ +#define TIMER2_DISABLE (0<<3) /* Disables Timer 2 */ +#define TIMER2_32K (1<<4) /* Use the 32K clock for timer 2 */ +#define TIMER2_CPU (0<<4) /* Use the CPU clock rate for timer 2 */ +#define TIMER2_0INT (1<<5) /* Enable an interrupt when 0 is reached for the timer 2 */ +#define TIMER2_NOINT (0<<5) /* Disable interrupts for the timer 2 */ +#define TIMER2_UP (1<<10) /* Timer 2 counts up */ +#define TIMER2_DOWN (0<<10) /* Timer 2 counts down */ + +#define TIMER3_ENABLE (1<<6) /* Enables Timer 3 */ +#define TIMER3_DISABLE (0<<6) /* Disables Timer 3 */ +#define TIMER3_32K (1<<7) /* Use the 32K clock for timer 3 */ +#define TIMER3_CPU (0<<7) /* Use the CPU clock rate for timer 3 */ +#define TIMER3_0INT (1<<8) /* Enable an interrupt when 0 is reached for the timer 3 */ +#define TIMER3_NOINT (0<<8) /* Disable interrupts for the timer 3 */ +#define TIMER3_UP (1<<11) /* Timer 3 counts up */ +#define TIMER3_DOWN (0<<11) /* Timer 3 counts down */ + +/* These defines can be used to check the status of the timer */ +#define TIMER1_MATCH1 (1<<0) /* Timer 1 hit the first match value */ +#define TIMER1_MATCH2 (1<<1) /* Timer 1 hit the second match value */ +#define TIMER1_RELOADED (1<<2) /* Timer 1 was reloaded (Needs TIMER1_0INT enabled) */ + +#define TIMER2_MATCH1 (1<<3) /* Timer 2 hit the first match value */ +#define TIMER2_MATCH2 (1<<4) /* Timer 2 hit the second match value */ +#define TIMER2_RELOADED (1<<5) /* Timer 2 was reloaded (Needs TIMER2_0INT enabled) */ + +#define TIMER3_MATCH1 (1<<6) /* Timer 3 hit the first match value */ +#define TIMER3_MATCH2 (1<<7) /* Timer 3 hit the second match value */ +#define TIMER3_RELOADED (1<<8) /* Timer 3 was reloaded (Needs TIMER3_0INT enabled) */ + +/* Timer registers */ +#define timer_1_Counter (*(volatile uint32_t*)0xF20000) +#define timer_1_ReloadValue (*(uint32_t*)0xF20004) +#define timer_1_MatchValue_1 (*(uint32_t*)0xF20008) +#define timer_1_MatchValue_2 (*(uint32_t*)0xF2000C) +#define timer_2_Counter (*(volatile uint32_t*)0xF20010) +#define timer_2_ReloadValue (*(uint32_t*)0xF20014) +#define timer_2_MatchValue_1 (*(uint32_t*)0xF20018) +#define timer_2_MatchValue_2 (*(uint32_t*)0xF2001C) +#define timer_3_Counter (*(volatile uint32_t*)0xF20020) +#define timer_3_ReloadValue (*(uint32_t*)0xF20024) +#define timer_3_MatchValue_1 (*(uint32_t*)0xF20028) +#define timer_3_MatchValue_2 (*(uint32_t*)0xF2002C) +#define timer_Control (*(uint16_t*)0xF20030) +#define timer_IntStatus (*(volatile uint16_t*)0xF20034) +#define timer_IntAcknowledge (*(volatile uint16_t*)0xF20034) +#define timer_EnableInt (*(uint16_t*)0xF20038) + +/* LCD defines */ +#define lcd_BacklightLevel (*(uint8_t*)0xF60024) +#define lcd_Timing0 (*(uint32_t*)0xE30000) +#define lcd_Timing1 (*(uint32_t*)0xE30004) +#define lcd_Timing2 (*(uint32_t*)0xE30008) +#define lcd_Timing3 (*(uint24_t*)0xE3000C) +#define lcd_UpBase (*(uint32_t*)0xE30010) +#define lcd_LpBase (*(uint32_t*)0xE30014) +#define lcd_Control (*(uint24_t*)0xE30018) +#define lcd_EnableInt (*(uint8_t*)0xE3001C) +#define lcd_IntStatus (*(uint8_t*)0xE30020) +#define lcd_IntStatusMasked (*(uint8_t*)0xE30024) +#define lcd_IntAcknowledge (*(volatile uint8_t*)0xE30028) +#define lcd_UpBaseCurr (*(volatile uint32_t*)0xE3002C) +#define lcd_LpBaseCurr (*(volatile uint32_t*)0xE30030) +#define lcd_Palette ((uint16_t*)0xE30200) +#define lcd_Ram ((uint16_t*)0xD40000) + +/** + * Width of LCD in pixels + */ +#define LCD_WIDTH \ +(320) + +/** + * Height of LCD in pixels + */ +#define LCD_HEIGHT \ +(240) + +/** + * Total number of pixels in LCD + */ +#define LCD_SIZE \ +(LCD_WIDTH*LCD_HEIGHT*2) + +/** + * @brief Structure of real variable type + */ +typedef struct { int8_t sign, exp; uint8_t mant[7]; } real_t; +/** + * @brief Structure of complex variable type + */ +typedef struct { real_t real, imag; } cplx_t; +/** + * @brief Structure of list variable type + */ +typedef struct { uint16_t dim; real_t items[1]; } list_t; +/** + * @brief Structure of complex list variable type + */ +typedef struct { uint16_t dim; cplx_t items[1]; } cplx_list_t; +/** + * @brief Structure of matrix variable type + */ +typedef struct { uint8_t cols, rows; real_t items[1]; } matrix_t; +/** + * @brief Structure of string variable type + */ +typedef struct { uint16_t len; char data[1]; } string_t; +/** + * @brief Structure of equation variable type + */ +typedef struct { uint16_t len; char data[1]; } equ_t; +/** + * @brief Structure of miscellaneous variable type + */ +typedef struct { uint16_t size; uint8_t data[1]; } var_t; + +/** + * Gets an element from a matrix + * + * @param matrix Structure of matrix + * @param row Row in matrix + * @param col Column in matrix + * @returns real_t containing element data + */ +#define matrix_element(matrix, row, col) ((matrix)->items[(row)+(col)*(matrix)->rows]) + +/** + * Resets the OS homescreen; accounts for split screen + */ +#define os_ClrHome() do { _OS(asm_ClrLCD); _OS(asm_HomeUp); _OS(asm_DrawStatusBar); } while (0) + +/** + * Resets the OS homescreen fully + */ +#define os_ClrHomeFull() do { _OS(asm_ClrLCDFull); _OS(asm_HomeUp); _OS(asm_DrawStatusBar); } while (0) + +/* + * Bootcode functions + */ + +/** + * Sets the calculator's date + * + * Performs checks to ensure date is within range + * @param day Day to set + * @param month Month to set + * @param year Year to set + */ +void boot_SetDate(uint8_t day, uint8_t month, uint16_t year); + +/** + * Gets the calculator's date + * + * @param day Pointer to variable to store day + * @param month Pointer to variable to store month + * @param year Pointer to variable to store year + */ +void boot_GetDate(uint8_t *day, uint8_t *month, uint16_t *year); + +/** + * Sets the calculator's time + * + * Performs checks to ensure time is within range + * @param seconds Seconds to set + * @param minutes Minutes to set + * @param hours Hours to set + */ +void boot_SetTime(uint8_t seconds, uint8_t minutes, uint8_t hours); + +/** + * Gets the calculator's time + * + * @param seconds Pointer to variable to store seconds + * @param minutes Pointer to variable to store minutes + * @param hours Pointer to variable to store hours + */ +void boot_GetTime(uint8_t *seconds, uint8_t *minutes, uint8_t *hours); + +/** + * Checks if past noon + * + * @returns True if past noon + */ +bool boot_IsAfterNoon(void); + +/** + * @returns Bootcode version major + */ +uint8_t boot_GetBootMajorVer(void); + +/** + * @returns Bootcode version minor + */ +uint8_t boot_GetBootMinorVer(void); + +/** + * @returns Hardware version + */ +uint8_t boot_GetHardwareVer(void); + +/** + * Turns all of VRAM into 0xFF (white) + */ +void boot_ClearVRAM(void); + +/** + * Checks if the [on] key was pressed + * + * @returns True is returned if [on] key was pressed + */ +bool boot_CheckOnPressed(void); + +/** + * Basically a reimplemented form of printf that prints to some debugging device + * + * @param string String to send to debug device + */ +void boot_DebugPrintf(const char *string); + +/** + * Turns off the calculator (probably not a good idea to use) + */ +void boot_TurnOff(void); + +/** + * Inserts a new line at the current cursor posistion on the homescreen + * Does not scroll. + */ +void boot_NewLine(void); + +/** + * @returns Current battery status + */ +uint8_t boot_GetBatteryStatus(void); + +/** + * Waits for ~10 ms + */ +void boot_WaitShort(void); + +/* + * OS Routines + */ + +/** + * Inserts a new line at the current cursor posistion on the homescreen + * Does scroll. + */ +void os_NewLine(void); + +/** + * Disables the OS cursor + */ +void os_DisableCursor(void); + +/** + * Enables the OS cursor + */ +void os_EnableCursor(void); + +/** + * Sets the foreground color used to draw text on the graphscreen + * @param color 565 BGR color to set text foreground to + */ +void os_SetDrawFGColor(uint24_t color); + +/** + * Gets the foreground color used to draw text on the graphscreen + * @returns 565 BGR color of text foreground + */ +uint24_t os_GetDrawFGColor(void); + +/** + * Sets the background color used to draw text on the graphscreen + * @param color 565 BGR color to set text background to + */ +void os_SetDrawBGColor(uint24_t color); + +/** + * Gets the background color used to draw text on the graphscreen + * + * @returns 565 BGR color of text nackground + * @warning Only useable in OS 5.2 and above; use at your own risk + */ +uint24_t os_GetDrawBGColor(void); + +/** + * Set the cursor posistion used on the homescreen + * + * @param curRow The row aligned offset + * @param curCol The column aligned offset + */ +void os_SetCursorPos(uint8_t curRow, uint8_t curCol); + +/** + * Gets the cursor posistion used on the homescreen + * + * @param curRow Pointer to store the row aligned offset + * @param curCol Pointer to store the column aligned offset + */ +void os_GetCursorPos(unsigned int *curRow, unsigned int *curCol); + +/** + * Selects the font to use when drawing on the graphscreen + * + * @param id + * 0: small font <br> + * 1: large monospace font + */ +void os_FontSelect(char id); + +/** + * Gets the font to use when drawing on the graphscreen + * + * @returns + * 0: small font <br> + * 1: large monospace font + */ +uint24_t os_FontGetID(void); + +/** + * @param string String to get pixel width of + * @returns The width of a string in the variable-width format + */ +uint24_t os_FontGetWidth(const char *string); + +/** + * @returns The height of the font characters + */ +uint24_t os_FontGetHeight(void); + +/** + * Draws text using the small font to the screen + * + * @param string String to draw + * @param col Column to start drawing at + * @param row Row to start drawing at + * @returns The end column + */ +uint24_t os_FontDrawText(const char *string, uint16_t col, uint8_t row); + +/** + * Draws transparent text using the small font to the screen + * + * @param string String to draw + * @param col Column to start drawing at + * @param row Row to start drawing at + * @returns The end column + */ +uint24_t os_FontDrawTransText(const char *string, uint16_t col, uint8_t row); + +/** + * Puts some text at the current homescreen cursor location + * + * @param string Test to put on homescreen + * @returns 1 if string fits on screen, 0 otherwise + */ +uint24_t os_PutStrFull(const char *string); + +/** + * Puts some text at the current homescreen cursor location + * + * @param string Test to put on homescreen + * @returns 1 if string fits on line, 0 otherwise + */ +uint24_t os_PutStrLine(const char *string); + +/** + * Set a particular flag variable + * + * @param offset Offset to particular flag in list + * @param set Bitmask of flag to set + */ +void os_SetFlagByte(int offset, uint8_t set); + +/** + * Get a particular flag variable + * + * @param offset Offset to particular flag in list + * @returns Bitmask of flag + */ +uint8_t os_GetFlagByte(int offset); + +/** + * Get amount of free ram in order to allocate extra ram + * + * @param free Set to start of free available ram + * @returns Size of available ram + */ +size_t os_MemChk(void **free); + +/** + * Throws an OS error + * + * @param error Error code to throw + */ +void os_ThrowError(uint8_t error); + +/** + * Gets a pointer to the system stats + * + * @returns + * [3] - Hardware version <br> + * [12-13] - Boot Version Major <br> + * [14] - Boot Version Minor <br> + * [15-16] - Boot Version Build <br> + * [28-37] - Calc ID (From certificate if exists) <br> + * [38-39] - Appears to be localization language + */ +void *os_GetSystemStats(void); + +/** + * This function can return twice (like setjmp). + * First return always happens with a return value of 0. + * Second return only happens if an error occurs before os_PopErrorHandler is called, + * with the errNo as the return value. + * + * @code + * int errno = os_PushErrorHandler(); + * if (errno) { + * // handle error, but no longer under the protection of the error handler so do not call os_PopErrorHandler() + * } else { + * // run some code that may error + * os_PopErrorHandler(); + * } + * @endcode + * + * @param routine Error handling routine + * @see os_PopErrorHandler + */ +int os_PushErrorHandler(void); + +/** + * Restores stack state after a call to os_PushErrorHandler. Must be called with stack in the same state + * as it was when os_PushErrorHandler returned with 0, and should not be called along the error path. + * + * @see os_PushErrorHandler + */ +void os_PopErrorHandler(void); + +/** + * @returns A pointer to symtable of the OS + */ +void *os_GetSymTablePtr(void); + +/** + * Creates an AppVar + * + * @param name Pointer to name of AppVar to create + * @param size Size of AppVar to create + * @returns A pointer to the AppVar data + * @note Returns NULL if creation failed for some reason, otherwise a pointer to the size bytes + */ +var_t *os_CreateAppVar(const char *name, uint16_t size); + +/** + * Returns next entry or NULL if no more entries, pass os_GetSymTablePtr() as first entry + */ +void *os_NextSymEntry(void *entry, uint24_t *type, uint24_t *nameLength, char *name, void **data); + +/** + * Locates a symbol in the symtable + * + * @param type Type of symbol to find + * @param name Pointer to name of symbol to find + * @param entry Can be NULL if you don't care + * @param data Can be NULL if you don't care + * @returns If file exists, returns 1 and sets entry and data, otherwise returns 0. + */ +int os_ChkFindSym(uint8_t type, const char *name, void **entry, void **data); + +/** + * Gets the Ans variable + * + * @param type This is set to the current variable type in ANS + * @returns Pointer to the data + * @note Returns NULL if Ans doesn't exist or type is NULL + */ +void *os_RclAns(uint8_t *type); + +/** + * Copies a real_t type + * + * @param src Pointer to original real_t + * @returns Copied real_t + */ +real_t os_RealCopy(const real_t *src); + +/* Unary operations used to interact with the OS math functions */ +real_t os_RealAcosRad(const real_t *arg); +real_t os_RealAsinRad(const real_t *arg); +real_t os_RealAtanRad(const real_t *arg); +real_t os_RealCosRad(const real_t *arg); +real_t os_RealRadToDeg(const real_t *arg); +real_t os_RealExp(const real_t *arg); +real_t os_RealFloor(const real_t *arg); +real_t os_RealFrac(const real_t *arg); +real_t os_RealRoundInt(const real_t *arg); +real_t os_RealLog(const real_t *arg); +real_t os_RealNeg(const real_t *arg); +real_t os_RealDegToRad(const real_t *arg); +real_t os_RealInv(const real_t *arg); +real_t os_RealSinRad(const real_t *arg); +real_t os_RealSqrt(const real_t *arg); +real_t os_RealTanRad(const real_t *arg); +real_t os_RealInt(const real_t *arg); +cplx_t os_CplxSquare(const cplx_t *arg); + +/* Binary operations used to interact with the OS math functions */ +real_t os_RealAdd(const real_t *arg1, const real_t *arg2); +real_t os_RealDiv(const real_t *arg1, const real_t *arg2); +real_t os_RealGcd(const real_t *arg1, const real_t *arg2); +real_t os_RealLcm(const real_t *arg1, const real_t *arg2); +real_t os_RealMax(const real_t *arg1, const real_t *arg2); +real_t os_RealMin(const real_t *arg1, const real_t *arg2); +real_t os_RealMul(const real_t *arg1, const real_t *arg2); +real_t os_RealNcr(const real_t *total, const real_t *num); +real_t os_RealNpr(const real_t *total, const real_t *num); +real_t os_RealPow(const real_t *base, const real_t *exp); +real_t os_RealRandInt(const real_t *min, const real_t *max); +real_t os_RealMod(const real_t *arg1, const real_t *arg2); +real_t os_RealSub(const real_t *arg1, const real_t *arg2); + +/** + * Rounds a real_t + * + * @note digits must be in the range 0 - 9 + */ +real_t os_RealRound(const real_t *arg, char digits); + +/** + * Compares two real_t + * + * @returns -1, 0, or 1 depending on the comparison + */ +int os_RealCompare(const real_t *arg1, const real_t *arg2); + +/** + * Converts a real_t to an integer + * @note Saturates on overflow + */ +int24_t os_RealToInt24(const real_t *arg); + +/** + * Converts an integer to a real_t + * @note Saturates on overflow + */ +real_t os_Int24ToReal(int24_t arg); + +/** + * Converts a real_t to a float + * @note Saturates on overflow + */ +float os_RealToFloat(const real_t *arg); + +/** + * Converts an float to a real_t + * @note Saturates on overflow + */ +real_t os_FloatToReal(float arg); + +/** This converts a ti-float to a ti-ascii string. + * + * @param result Zero terminated string copied to this address + * @param arg Real to convert + * @param maxLength + * <=0: use default max length (14) <br> + * >0: max length of result, minimum of 6 + * @param mode: + * 0: Use current mode for everything (digits ignored) <br> + * 1: Normal mode <br> + * 2: Sci mode <br> + * 3: Eng mode <br> + * >4: Use current Normal/Sci/Eng mode (digits still used) <br> + * @param digits + * -1: Float mode <br> + * 0-9: Fix # mode <br> + * @returns Length of result + */ +int os_RealToStr(char *result, const real_t *arg, int8_t maxLength, uint8_t mode, int8_t digits); + +/** + * This converts a ti-ascii string to a ti-float. + * + * String format regexp: / *[-\032+]?[0-9]*(\.[0-9]*)?([eE\033][-\032+]?[0-9]*)?/ + * @param string TI-ascii string to convert + * @param end If non-null, pointer to end of parsed number is stored here + * @returns resulting TI-float; on exponent overflow this is +-9.9999999999999e99 + */ +real_t os_StrToReal(const char *string, char **end); + +/** + * High 8 is unsigned offset, low 8 is bits to test + */ +int os_TestFlagBits(uint16_t offset_pattern); +void os_SetFlagBits(int16_t offset_pattern); +void os_ResetFlagBits(int16_t offset_pattern); + +/** + * Custom implementation input routine for use in conjunction with the TIOS. + * It is HIGHLY recommended you implement your own routine, this routine has + * some quirks. It is good enough for getting basic input however. + * + * @param string Input prompt string to be displayed to the user + * @param buf Storage location to store input string + * @param bufsize Available storage size for input string. -1 for null termination. + * @returns None + */ +void os_GetStringInput(char *string, char *buf, size_t bufsize); + +/** + * Gets a key from the OS + * + * @returns Key code + * @returns Extended key code in high byte + */ +uint16_t os_GetKey(void); + +/** + * Disable text buffering on the homescreen. C programs use this area by default for the BSS / Heap. + */ +void os_DisableHomeTextBuffer(void); + +/** + * Enables text buffering on the homescreen. C programs use this area by default for the BSS / Heap. + */ +void os_EnableHomeTextBuffer(void); + +/** + * @brief Scan code type + */ +typedef uint8_t sk_key_t; + +/** + * Performs an OS call to get the keypad scan code + * + * You can also use this function to get input from the user as a string like this: + * @code + * const char *chars = "\0\0\0\0\0\0\0\0\0\0\"WRMH\0\0?[VQLG\0\0:ZUPKFC\0 YTOJEB\0\0XSNIDA\0\0\0\0\0\0\0\0"; + * uint8_t key, i = 0; + * char buffer[50]; + * + * while((key = os_GetCSC()) != sk_Enter) { + * if(chars[key]) { + * buffer[i++] = chars[key]; + * } + * } + * @endcode + * Feel free to modify the string to suit your needs. + * @returns Key scan code + */ +sk_key_t os_GetCSC(void); + +/** + * Runs the calulator at 6 MHz + */ +void boot_Set6MHzMode(void); + +/** + * Runs the calulator at 48 MHz + */ +void boot_Set48MHzMode(void); + +/** + * Runs the calulator at 6 MHz (saves interrupt status) + */ +void boot_Set6MHzModeI(void); + +/** + * Runs the calulator at 48 MHz (saves interrupt status) + */ +void boot_Set48MHzModeI(void); + +/** + * Executes the assembly routine _ForceCmdNoChar + */ +void os_ForceCmdNoChar(void); + +/** + * Use this function to call assembly functions in the OS and Bootcode + * i.e. _OS( asm_ArcChk ); + */ +void _OS(void (*function)(void)); + +/** + * Assembly routine to scroll homescreen up + */ +void asm_MoveUp(void); + +/** + * Assembly routine to scroll homescreen down + */ +void asm_MoveDown(void); + +/** + * Assembly routine to move row and column posistion to (0,0) + */ +void asm_HomeUp(void); + +/** + * Assembly routine to turn on the Run Indicator + */ +void asm_RunIndicOn(void); + +/** + * Assembly routine to turn off the Run Indicator + */ +void asm_RunIndicOff(void); + +/** + * Assembly routine to turn off APD + */ +void asm_DisableAPD(void); + +/** + * Assembly routine to turn on APD + */ +void asm_EnableAPD(void); + +/** + * Assembly routine checks the amount of free archive + */ +void asm_ArcChk(void); + +/** + * Assembly routine to clear the homescreen lcd + */ +void asm_ClrLCDFull(void); + +/** + * Assembly routine to clear the homescreen lcd. + * Accounts for split screen + */ +void asm_ClrLCD(void); + +/** + * Assembly routine to redraw the status bar + */ +void asm_DrawStatusBar(void); + +/** + * Invalidate and clear stat variables + */ +void asm_DelRes(void); + +/** + * Invalidate and clear text shadow area + */ +void asm_ClrTxtShd(void); + +/** + * Colors used by the OS + */ +typedef enum { + OS_COLOR_BLUE = 10, + OS_COLOR_RED, + OS_COLOR_BLACK, + OS_COLOR_MAGENTA, + OS_COLOR_GREEN, + OS_COLOR_ORANGE, + OS_COLOR_BROWN, + OS_COLOR_NAVY, + OS_COLOR_LTBLUE, + OS_COLOR_YELLOW, + OS_COLOR_WHITE, + OS_COLOR_LTGRAY, + OS_COLOR_MEDGRAY, + OS_COLOR_GRAY, + OS_COLOR_DARKGRAY +} os_colors_t; + +#define os_RamStart ((uint8_t*)0xD00000) +#define os_Flags ((uint8_t*)0xD00080) +#define os_TextFlags (*(uint8_t*)0xD00080) +#define os_ApdFlags (*(uint8_t*)0xD00088) +#define os_RclFlags (*(uint8_t*)0xD0008E) + +#define os_AppData ((uint8_t*)0xD00429) + +#define os_KbdScanCode (*(uint8_t*)0xD00587) +#define os_KbdLGSC (*(uint8_t*)0xD00588) +#define os_KbdPSC (*(uint8_t*)0xD00589) +#define os_KbdWUR (*(uint8_t*)0xD0058A) +#define os_KbdDebncCnt (*(uint8_t*)0xD0058B) +#define os_KbdKey (*(uint8_t*)0xD0058C) +#define os_KbdGetKy (*(uint8_t*)0xD0058D) +#define os_KeyExtend (*(uint8_t*)0xD0058E) +#define os_Brightness (*(uint8_t*)0xD0058F) +#define os_ApdSubTimer (*(uint8_t*)0xD00590) +#define os_ApdTimer (*(uint8_t*)0xD00591) +#define os_CurRow (*(uint8_t*)0xD00595) +#define os_CurCol (*(uint8_t*)0xD00596) + +#define os_OP1 ((uint8_t*)0xD005F8) +#define os_OP2 ((uint8_t*)0xD00603) +#define os_OP3 ((uint8_t*)0xD0060E) +#define os_OP4 ((uint8_t*)0xD00619) +#define os_OP5 ((uint8_t*)0xD00624) +#define os_OP6 ((uint8_t*)0xD0062F) +#define os_OP7 ((uint8_t*)0xD0063A) + +#define os_ProgToEdit ((char*)0xD0065B) +#define os_NameBuff ((char*)0xD00663) + +#define os_TextShadow ((uint8_t*)0xD006C0) /**< Text buffer 260 bytes */ + +#define os_PromptRow (*(uint8_t*)0xD00800) +#define os_PromptCol (*(uint8_t*)0xD00801) +#define os_PromptIns (*(uint8_t*)0xD00802) +#define os_PromptShift (*(uint8_t*)0xD00803) +#define os_PromptRet (*(uint8_t*)0xD00804) +#define os_PromptValid (*(uint8_t*)0xD00807) + +#define os_PenCol (*(uint24_t*)0xD008D2) /**< Small font column location */ +#define os_PenRow (*(uint8_t*)0xD008D5) /**< Small font row location */ + +#define os_StatVars ((uint8_t*)0xD01191) +#define os_AsmPrgmSize (*(uint16_t*)0xD0118C) /**< Current size of executing program */ + +#define os_uXMin (*(real_t*)0xD01D61) +#define os_uXMax (*(real_t*)0xD01D6A) +#define os_uXScl (*(real_t*)0xD01D73) +#define os_uYMin (*(real_t*)0xD01D7C) +#define os_uYMax (*(real_t*)0xD01D85) +#define os_uYScl (*(real_t*)0xD01D8E) +#define os_uThetaMin (*(real_t*)0xD01D97) +#define os_uThetaMax (*(real_t*)0xD01DA0) +#define os_uThetaStep (*(real_t*)0xD01DA9) +#define os_uTmin (*(real_t*)0xD01DB2) +#define os_uTmax (*(real_t*)0xD01DBB) +#define os_uTStep (*(real_t*)0xD01DC4) +#define os_uPlotStart (*(real_t*)0xD01DCD) +#define os_unMax (*(real_t*)0xD01DD6) +#define os_uu0 (*(real_t*)0xD01DDF) +#define os_uv0 (*(real_t*)0xD01DE8) +#define os_unMin (*(real_t*)0xD01DF1) +#define os_uu02 (*(real_t*)0xD01DFA) +#define os_uv02 (*(real_t*)0xD01E03) +#define os_uw0 (*(real_t*)0xD01E0C) +#define os_uPlotStep (*(real_t*)0xD01E15) +#define os_uXres (*(real_t*)0xD01E1E) +#define os_uw02 (*(real_t*)0xD01E27) +#define os_XMin (*(real_t*)0xD01E33) +#define os_XMax (*(real_t*)0xD01E3C) +#define os_XScl (*(real_t*)0xD01E45) +#define os_YMin (*(real_t*)0xD01E4E) +#define os_YMax (*(real_t*)0xD01E57) +#define os_YScl (*(real_t*)0xD01E60) +#define os_ThetaMin (*(real_t*)0xD01E69) +#define os_ThetaMax (*(real_t*)0xD01E72) +#define os_ThetaStep (*(real_t*)0xD01E7B) +#define os_TMinPar (*(real_t*)0xD01E84) +#define os_TMaxPar (*(real_t*)0xD01E8D) +#define os_TStep (*(real_t*)0xD01E96) +#define os_PlotStart (*(real_t*)0xD01E9F) +#define os_NMax (*(real_t*)0xD01EA8) +#define os_u0 (*(real_t*)0xD01EB1) +#define os_V0 (*(real_t*)0xD01EBA) +#define os_NMin (*(real_t*)0xD01EC3) +#define os_u02 (*(real_t*)0xD01ECC) +#define os_V02 (*(real_t*)0xD01ED5) +#define os_W0 (*(real_t*)0xD01EDE) +#define os_PlotStep (*(real_t*)0xD01EE7) +#define os_XResO (*(real_t*)0xD01EF0) +#define os_W02 (*(real_t*)0xD01EF9) +#define os_un1 (*(real_t*)0xD01F02) +#define os_un2 (*(real_t*)0xD01F0B) +#define os_Vn1 (*(real_t*)0xD01F14) +#define os_Vn2 (*(real_t*)0xD01F1D) +#define os_Wn1 (*(real_t*)0xD01F26) +#define os_Wn2 (*(real_t*)0xD01F2F) +#define os_Fin_N (*(real_t*)0xD01F38) +#define os_Fin_I (*(real_t*)0xD01F41) +#define os_Fin_PV (*(real_t*)0xD01F4A) +#define os_Fin_PMT (*(real_t*)0xD01F53) +#define os_Fin_FV (*(real_t*)0xD01F5C) +#define os_Fin_PY (*(real_t*)0xD01F65) +#define os_Fin_CY (*(real_t*)0xD01F6E) +#define os_Cal_N (*(real_t*)0xD01F77) +#define os_Cal_I (*(real_t*)0xD01F80) +#define os_Cal_PV (*(real_t*)0xD01F89) +#define os_Cal_PMT (*(real_t*)0xD01F92) +#define os_Cal_FV (*(real_t*)0xD01F9B) +#define os_Cal_PY (*(real_t*)0xD01FA4) + +#define os_CmdShadow ((uint8_t*)0xD0232D) + +#define os_Y1LineType (*(uint8_t*)0xD024BF) +#define os_Y2LineType (*(uint8_t*)0xD024C0) +#define os_Y3LineType (*(uint8_t*)0xD024C1) +#define os_Y4LineType (*(uint8_t*)0xD024C2) +#define os_Y5LineType (*(uint8_t*)0xD024C3) +#define os_Y6LineType (*(uint8_t*)0xD024C4) +#define os_Y7LineType (*(uint8_t*)0xD024C5) +#define os_Y8LineType (*(uint8_t*)0xD024C6) +#define os_Y9LineType (*(uint8_t*)0xD024C7) +#define os_Y0LineType (*(uint8_t*)0xD024C8) +#define os_Para1LineType (*(uint8_t*)0xD024C9) +#define os_Para2LineType (*(uint8_t*)0xD024CA) +#define os_Para3LineType (*(uint8_t*)0xD024CB) +#define os_Para4LineType (*(uint8_t*)0xD024CC) +#define os_Para5LineType (*(uint8_t*)0xD024CD) +#define os_Para6LineType (*(uint8_t*)0xD024CE) +#define os_Polar1LineType (*(uint8_t*)0xD024CF) +#define os_Polar2LineType (*(uint8_t*)0xD024D0) +#define os_Polar3LineType (*(uint8_t*)0xD024D1) +#define os_Polar4LineType (*(uint8_t*)0xD024D2) +#define os_Polar5LineType (*(uint8_t*)0xD024D3) +#define os_Polar6LineType (*(uint8_t*)0xD024D4) +#define os_SecULineType (*(uint8_t*)0xD024D5) +#define os_SecVLineType (*(uint8_t*)0xD024D6) +#define os_SecWLineType (*(uint8_t*)0xD024D7) +#define os_Y1LineColor (*(uint8_t*)0xD024D8) +#define os_Y2LineColor (*(uint8_t*)0xD024D9) +#define os_Y3LineColor (*(uint8_t*)0xD024DA) +#define os_Y4LineColor (*(uint8_t*)0xD024DB) +#define os_Y5LineColor (*(uint8_t*)0xD024DC) +#define os_Y6LineColor (*(uint8_t*)0xD024DD) +#define os_Y7LineColor (*(uint8_t*)0xD024DE) +#define os_Y8LineColor (*(uint8_t*)0xD024DF) +#define os_Y9LineColor (*(uint8_t*)0xD024E0) +#define os_Y0LineColor (*(uint8_t*)0xD024E1) +#define os_Para1LineColor (*(uint8_t*)0xD024E2) +#define os_Para2LineColor (*(uint8_t*)0xD024E3) +#define os_Para3LineColor (*(uint8_t*)0xD024E4) +#define os_Para4LineColor (*(uint8_t*)0xD024E5) +#define os_Para5LineColor (*(uint8_t*)0xD024E6) +#define os_Para6LineColor (*(uint8_t*)0xD024E7) +#define os_Polar1LineColor (*(uint8_t*)0xD024E8) +#define os_Polar2LineColor (*(uint8_t*)0xD024E9) +#define os_Polar3LineColor (*(uint8_t*)0xD024EA) +#define os_Polar4LineColor (*(uint8_t*)0xD024EB) +#define os_Polar5LineColor (*(uint8_t*)0xD024EC) +#define os_Polar6LineColor (*(uint8_t*)0xD024ED) +#define os_SecULineColor (*(uint8_t*)0xD024EE) +#define os_SecVLineColor (*(uint8_t*)0xD024EF) +#define os_SecWLineColor (*(uint8_t*)0xD024F0) + +#define os_AppErr1 ((char*)0xD025A9) /**< String [1] for custom error */ +#define os_AppErr2 ((char*)0xD025B6) /**< String [2] for custom error */ + +#define os_CursorHookPtr (*(uint24_t*)0xD025D5) +#define os_LibraryHookPtr (*(uint24_t*)0xD025D8) +#define os_RawKeyHookPtr (*(uint24_t*)0xD025DB) +#define os_GetKeyHookPtr (*(uint24_t*)0xD025DE) +#define os_HomescreenHookPtr (*(uint24_t*)0xD025E1) +#define os_WindowHookPtr (*(uint24_t*)0xD025E4) +#define os_GraphHookPtr (*(uint24_t*)0xD025E7) +#define os_YEqualsHookPtr (*(uint24_t*)0xD025EA) +#define os_FontHookPtr (*(uint24_t*)0xD025ED) +#define os_RegraphHookPtr (*(uint24_t*)0xD025F0) +#define os_GraphicsHookPtr (*(uint24_t*)0xD025F3) +#define os_TraceHookPtr (*(uint24_t*)0xD025F6) +#define os_ParserHookPtr (*(uint24_t*)0xD025F9) +#define os_AppChangeHookPtr (*(uint24_t*)0xD025FC) +#define os_Catalog1HookPtr (*(uint24_t*)0xD025FF) +#define os_HelpHookPtr (*(uint24_t*)0xD02602) +#define os_CxRedispHookPtr (*(uint24_t*)0xD02605) +#define os_MenuHookPtr (*(uint24_t*)0xD02608) +#define os_Catalog2HookPtr (*(uint24_t*)0xD0260B) +#define os_TokenHookPtr (*(uint24_t*)0xD0260E) +#define os_LocalizeHookPtr (*(uint24_t*)0xD02611) +#define os_SilentLinkHookPtr (*(uint24_t*)0xD02614) +#define os_ActiveUSBHookPtr (*(uint24_t*)0xD0261A) + +#define os_TempFreeArc (*(uint24_t*)0xD02655) /**< Set after asm_ArcChk call */ + +#define os_TextBGcolor (*(uint16_t*)0xD02688) /**< Large font background color */ +#define os_TextFGcolor (*(uint16_t*)0xD0268A) /**< Large font foreground color */ + +#define os_DrawBGColor (*(uint16_t*)0xD026AA) /**< Small font background color */ +#define os_DrawFGColor (*(uint16_t*)0xD026AC) /**< Small font foreground color */ +#define os_DrawColorCode (*(uint8_t*)0xD026AE) + +#define os_BatteryStatus (*(uint8_t*)0xD02A86) + +#define os_GraphBGColor (*(uint16_t*)0xD02A98) /**< Graph background 565 color */ + +#define os_FillRectColor (*(uint16_t*)0xD02AC0) +#define os_StatusBarBGColor (*(uint16_t*)0xD02ACC) /**< Status bar 565 color */ + +#define os_TmpYears (*(real_t*)0xD02B01) +#define os_TmpMonths (*(real_t*)0xD02B0A) +#define os_TmpDays (*(real_t*)0xD02B13) +#define os_TmpHours (*(real_t*)0xD02B1C) +#define os_TmpMinutes (*(real_t*)0xD02B25) + +#define os_RamCode ((uint8_t*)0xD18C7C) /**< 1023 bytes free ram */ + +/* + * TI-OS Token definitions + */ + +#define tToDMS 0x01 +#define tToDEC 0x02 +#define tToAbc 0x03 +#define tStore 0x04 +#define tBoxPlot 0x05 +#define tLBrack 0x06 +#define tRBrack 0x07 +#define tLBrace 0x08 +#define tRBrace 0x09 +#define tFromRad 0x0A +#define tFromDeg 0x0B +#define tRecip 0x0C +#define tSqr 0x0D +#define tTrnspos 0x0E +#define tCube 0x0F +#define tLParen 0x10 +#define tRParen 0x11 +#define tRound 0x12 +#define tPxTst 0x13 +#define tAug 0x14 +#define tRowSwap 0x15 +#define tRowPlu 0x16 +#define tmRow 0x17 +#define tmRowPlus 0x18 +#define tMax 0x19 // 'max' +#define tMin 0x1A // 'min' +#define tRToPr 0x1B // 'R>Pr' +#define tRToPo 0x1C // 'R>Po' +#define tPToRx 0x1D // 'P>Rx' +#define tPToRy 0x1E // 'P>Ry' +#define tMedian 0x1F // 'MEDIAN' +#define tRandM 0x20 // 'randM' +#define tMean 0x21 // 'MEAN' +#define tRoot 0x22 // 'ROOT' +#define tSeries 0x23 // 'seq' +#define tFnInt 0x24 // 'fnInt' +#define tNDeriv 0x25 // 'fnIr' +#define tEvalF 0x26 +#define tFmin 0x27 +#define tFmax 0x28 +#define tSpace 0x29 // ' ' +#define tString 0x2A // '"' +#define tComma 0x2B // ',' +#define tii 0x2C // 'i' +#define tFact 0x2D // '!' +#define tCubicR 0x2E +#define tQuartR 0x2F +#define t0 0x30 +#define t1 0x31 +#define t2 0x32 +#define t3 0x33 +#define t4 0x34 +#define t5 0x35 +#define t6 0x36 +#define t7 0x37 +#define t8 0x38 +#define t9 0x39 +#define tDecPt 0x3A // '.' +#define tee 0x3B // 'e' +#define tOr 0x3C // '_or_' +#define tXor 0x3D +#define tColon 0x3E // ':' +#define tEnter 0x3F +#define tAnd 0x40 // '_and_' +#define tA 0x41 +#define tB 0x42 +#define tC 0x43 +#define tD 0x44 +#define tE 0x45 +#define tF 0x46 +#define tG 0x47 +#define tH 0x48 +#define tI 0x49 +#define tJ 0x4A +#define tK 0x4B +#define tL 0x4C +#define tM 0x4D +#define tN 0x4E +#define tO 0x4F +#define tP 0x50 +#define tQ 0x51 +#define tR 0x52 +#define tS 0x53 +#define tT 0x54 +#define tU 0x55 +#define tV 0x56 +#define tW 0x57 +#define tX 0x58 +#define tY 0x59 +#define tZ 0x5A +#define tTheta 0x5B +#define tProg 0x5F + +/* + * Mode settings tokens + */ +#define tRad 0x64 // 'Radian' +#define tDeg 0x65 // 'Degree' +#define tNormF 0x66 // 'Normal' +#define tSci 0x67 // 'Sci' +#define tEng 0x68 // 'Eng' +#define tFloat 0x69 // 'Float' +#define tFix 0x73 // 'Fix_' +#define tSplitOn 0x74 +#define tFullScreen 0x75 +#define tStndrd 0x76 // 'Func' +#define tParam 0x77 // 'Param' +#define tPolar 0x78 // 'Pol' +#define tSeqG 0x79 // ;79h +#define tAFillOn 0x7A // 'AUTO FILL ON' +#define tAFillOff 0x7B // 'AutoFill OFF' +#define tACalcOn 0x7C +#define tACalcOff 0x7D + +#define tEQ 0x6A // '=' +#define tLT 0x6B // '<' +#define tGT 0x6C // '>' +#define tLE 0x6D // LLE +#define tGE 0x6E // LGE +#define tNE 0x6F // LNE +#define tAdd 0x70 // '+' +#define tSub 0x71 // '-' +#define tAns 0x72 +#define tMul 0x82 // '*' +#define tDiv 0x83 // '/' + +#define tBoxIcon 0x7F +#define tCrossIcon 0x80 +#define tDotIcon 0x81 + +#define tTrace 0x84 // 'Trace' +#define tClDrw 0x85 // 'ClrDraw' +#define tZoomStd 0x86 // 'ZStd' +#define tZoomtrg 0x87 // 'Ztrg' +#define tZoomBox 0x88 // 'ZBOX' +#define tZoomIn 0x89 // 'ZIn' +#define tZoomOut 0x8A // 'ZOut' +#define tZoomSqr 0x8B // 'ZSqr' +#define tZoomInt 0x8C // 'ZInt' +#define tZoomPrev 0x8D // 'ZPrev' +#define tZoomDec 0x8E // 'ZDecm' +#define tZoomStat 0x8F // 'ZStat +#define tUsrZm 0x90 // 'ZRcl' +#define tPrtScrn 0x91 // 'PrtScrn' +#define tZoomSto 0x92 // 'ZSto' +#define tText 0x93 + +#define tnPr 0x94 // '_nPr_' +#define tnCr 0x95 // '_nCr_' + +// Graph Commands +#define tYOn 0x96 // 'FnOn_' +#define tYOff 0x97 // 'FnOff_' +#define tStPic 0x98 // 'StPic_' +#define tRcPic 0x99 // 'RcPic_' +#define tStoDB 0x9A // 'StGDB_' +#define tRclDB 0x9B // 'RcGDB_' +#define tLine 0x9C // 'Line' +#define tVert 0x9D // 'Vert_' +#define tPtOn 0x9E // 'PtOn' +#define tPtOff 0x9F // 'PtOff' +#define tPtChg 0xA0 // 'PtChg' +#define tPXOn 0xA1 +#define tPXOff 0xA2 +#define tPXChg 0xA3 +#define tShade 0xA4 // 'Shade' +#define tCircle 0xA5 // 'Circle' +#define tHorz 0xA6 // 'HORIZONTAL' +#define tTanLn 0xA7 // 'TanLn' +#define tDrInv 0xA8 // 'DrInv_' +#define tDrawF 0xA9 // 'DrawF_' + +// Functions with no argument +#define tRand 0xAB // 'rand' +#define tPi 0xAC // Lpi +#define tGetKey 0xAD // 'getKy' +#define tAPost 0xAE // ''' +#define tQuest 0xAF // '?' +#define tChs 0xB0 +#define tInt 0xB1 +#define tAbs 0xB2 +#define tDet 0xB3 +#define tIdent 0xB4 +#define tDim 0xB5 +#define tSum 0xB6 +#define tProd 0xB7 +#define tNot 0xB8 +#define tIPart 0xB9 +#define tFPart 0xBA + +// New 2 Byte Tokens +#define t2ByteTok 0xBB +#define tSqrt 0xBC +#define tCubRt 0xBD +#define tLn 0xBE +#define tExp 0xBF +#define tLog 0xC0 +#define tALog 0xC1 +#define tSin 0xC2 +#define tASin 0xC3 +#define tCos 0xC4 +#define tACos 0xC5 +#define tTan 0xC6 +#define tATan 0xC7 +#define tSinH 0xC8 +#define tASinH 0xC9 +#define tCoshH 0xCA +#define tACosH 0xCB +#define tTanH 0xCC +#define tATanH 0xCD + +// Some Programming Commands +#define tIf 0xCE // 'If_' +#define tThen 0xCF // 'Then_' +#define tElse 0xD0 // 'Else_' +#define tWhile 0xD1 // 'While_' +#define tRepeat 0xD2 // 'Repeat_' +#define tFor 0xD3 // 'For_' +#define tEnd 0xD4 // 'End' +#define tReturn 0xD5 // 'Return' +#define tLbl 0xD6 // 'Lbl_' +#define tGoto 0xD7 // 'Goto_' +#define tPause 0xD8 // 'Pause_' +#define tStop 0xD9 // 'Stop' +#define tISG 0xDA // 'IS>' +#define tDSL 0xDB // 'DS<' +#define tInput 0xDC // 'Input_' +#define tPrompt 0xDD // 'Prompt_' +#define tDisp 0xDE // 'Disp_' +#define tDispG 0xDF // 'DispG' +#define tOutput 0xE0 // 'Outpt' +#define tClLCD 0xE1 // 'ClLCD' +#define tConst 0xE2 // 'Fill' +#define tSortA 0xE3 // 'sortA_' +#define tSortD 0xE4 // 'sortD_' +#define tDispTab 0xE5 // 'Disp Table +#define tMenu 0xE6 // 'Menu' +#define tSendMBL 0xE7 // 'Send' +#define tGetMBL 0xE8 // 'Get' + +// Stat Plot Commands +#define tPlotOn 0xE9 // 'PLOTSON' +#define tPlotOff 0xEA // 'PLOTSOFF +#define tListName 0xEB // List Designator +#define tPlot1 0xEC +#define tPlot2 0xED +#define tPlot3 0xEE +#define tUnused01 0xEF // available? +#define tPower 0xF0 // '^' +#define tXRoot 0xF1 // LsupX,Lroot +#define tOneVar 0xF2 // 'OneVar_' +#define tTwoVar 0xF3 +#define tLR 0xF4 // 'LinR(A+BX)' +#define tLRExp 0xF5 // 'ExpR_' +#define tLRLn 0xF6 // 'LnR_' +#define tLRPwr 0xF7 // 'PwrR_' +#define tMedMed 0xF8 +#define tQuad 0xF9 +#define tClrLst 0xFA // 'Clear List' +#define tClrTbl 0xFB // 'Clear Table' +#define tHist 0xFC // 'Hist_' +#define txyLine 0xFD // 'xyline_' +#define tScatter 0xFE // 'Scatter_' +#define tLR1 0xFF // 'LINR(AX+B)' + +#define tGFormat 0x7E +// 2nd Half Of Graph Format Tokens +#define tSeq 0x00 // 'SeqG' +#define tSimulG 0x01 // 'SimulG' +#define tPolarG 0x02 // 'PolarGC' +#define tRectG 0x03 // 'RectGC' +#define tCoordOn 0x04 // 'CoordOn' +#define tCoordOff 0x05 // 'CoordOff' +#define tDrawLine 0x06 // 'DrawLine' +#define tDrawDot 0x07 // 'DrawDot' +#define tAxisOn 0x08 // 'AxesOn' +#define tAxisOff 0x09 // 'AxesOff' +#define tGridOn 0x0A // 'GridOn' +#define tGridOff 0x0B // 'GridOff' +#define tLblOn 0x0C // 'LabelOn' +#define tLblOff 0x0D // 'LabelOff' +#define tWebOn 0x0E // 'WebOn' +#define tWebOff 0x0F // 'WebOFF' +#define tuv 0x10 // U vs V +#define tvw 0x11 // V vs W +#define tuw 0x12 // U vs W + +#define tVarMat 0x5C +// 2nd Half Of User Matrix Tokens +#define tMatA 0x00 // MAT A +#define tMatB 0x01 // MAT B +#define tMatC 0x02 // MAT C +#define tMatD 0x03 // MAT D +#define tMatE 0x04 // MAT E +#define tMatF 0x05 // MAT F +#define tMatG 0x06 // MAT G +#define tMatH 0x07 // MAT H +#define tMatI 0x08 // MAT I +#define tMatJ 0x09 // MAT J + +#define tVarLst 0x5D +// 2nd Half Of User List Tokens +#define tL1 0x00 // LIST 1 +#define tL2 0x01 // LIST 2 +#define tL3 0x02 // LIST 3 +#define tL4 0x03 // LIST 4 +#define tL5 0x04 // LIST 5 +#define tL6 0x05 // LIST 6 + +#define tVarEqu 0x5E +// 2nd Half Of User Equation Tokens + +// Y Equations have bit 4 set +#define tY1 0x10 // Y1 +#define tY2 0x11 // Y2 +#define tY3 0x12 // Y3 +#define tY4 0x13 // Y4 +#define tY5 0x14 // Y5 +#define tY6 0x15 // Y6 +#define tY7 0x16 // Y7 +#define tY8 0x17 // Y8 +#define tY9 0x18 // Y9 +#define tY0 0x19 // Y0 + +// Param Equations Have Bit 5 Set +#define tX1T 0x20 // X1t +#define tY1T 0x21 // Y1t +#define tX2T 0x22 // X2t +#define tY2T 0x23 // Y2t +#define tX3T 0x24 // X3t +#define tY3T 0x25 // Y3t +#define tX4T 0x26 // X4t +#define tY4T 0x27 // Y4t +#define tX5T 0x28 // X5t +#define tY5T 0x29 // Y5t +#define tX6T 0x2A // X6t +#define tY6T 0x2B // Y6t + +// Polar Equations Have Bit 6 Set +#define tR1 0x40 // R1 +#define tR2 0x41 // R2 +#define tR3 0x42 // R3 +#define tR4 0x43 // R4 +#define tR5 0x44 // R5 +#define tR6 0x45 // R6 + +// Recursion Equations Have Bit 7 Set +#define tun 0x80 // Un +#define tvn 0x81 // Vn +#define twn 0x82 // Wn + +#define tVarPict 0x60 +// 2nd Half User Picture Tokens +#define tPic1 0x00 // PIC1 +#define tPic2 0x01 // PIC2 +#define tPic3 0x02 // PIC3 +#define tPic4 0x03 // PIC4 +#define tPic5 0x04 // PIC5 +#define tPic6 0x05 // PIC6 +#define tPic7 0x06 // PIC7 +#define tPic8 0x07 // PIC8 +#define tPic9 0x08 // PIC9 +#define tPic0 0x09 // PIC0 + +#define tVarGDB 0x61 +// 2nd Half User Graph Database Tokens +#define tGDB1 0x00 // GDB1 +#define tGDB2 0x01 // GDB2 +#define tGDB3 0x02 // GDB3 +#define tGDB4 0x03 // GDB4 +#define tGDB5 0x04 // GDB5 +#define tGDB6 0x05 // GDB6 +#define tGDB7 0x06 // GDB7 +#define tGDB8 0x07 // GDB8 +#define tGDB9 0x08 // GDB9 +#define tGDB0 0x09 // GDB0 + +#define tVarStrng 0xAA +// 2nd Half Of String Vars +#define tStr1 0x00 +#define tStr2 0x01 +#define tStr3 0x02 +#define tStr4 0x03 +#define tStr5 0x04 +#define tStr6 0x05 +#define tStr7 0x06 +#define tStr8 0x07 +#define tStr9 0x08 +#define tStr0 0x09 + +#define tVarOut 0x62 +// 2nd Half Of System Output Only Variables +#define tRegEq 0x01 // REGRESSION EQUATION +#define tStatN 0x02 // STATISTICS N +#define tXMean 0x03 // X MEAN +#define tSumX 0x04 // SUM(X) +#define tSumXSqr 0x05 // SUM(X^2) +#define tStdX 0x06 // STANDARD DEV X +#define tStdPX 0x07 // STANDARD DEV POP X +#define tMinX 0x08 // Min X VALUE +#define tMaxX 0x09 // Max X VALUE +#define tMinY 0x0A // Min Y VALUE +#define tMaxY 0x0B // Max Y VALUE +#define tYmean 0x0C // Y MEAN +#define tSumY 0x0D // SUM(Y) +#define tSumYSqr 0x0E // SUM(Y^2) +#define tStdY 0x0F // STANDARD DEV Y +#define tStdPY 0x10 // STANDARD DEV POP Y +#define tSumXY 0x11 // SUM(XY) +#define tCorr 0x12 // CORRELATION +#define tMedX 0x13 // MED(X) +#define tQ1 0x14 // 1ST QUADRANT OF X +#define tQ3 0x15 // 3RD QUADRANT OF X +#define tQuadA 0x16 // 1ST TERM OF QUAD POLY REG/ Y-INT +#define tQuadB 0x17 // 2ND TERM OF QUAD POLY REG/ SLOPE +#define tQuadC 0x18 // 3RD TERM OF QUAD POLY REG +#define tCubeD 0x19 // 4TH TERM OF CUBIC POLY REG +#define tQuartE 0x1A // 5TH TERM OF QUART POLY REG +#define tMedX1 0x1B // x1 FOR MED-MED +#define tMedX2 0x1C // x2 FOR MED-MED +#define tMedX3 0x1D // x3 FOR MED-MED +#define tMedY1 0x1E // y1 FOR MED-MED +#define tMedY2 0x1F // y2 FOR MED-MED +#define tMedY3 0x20 // y3 FOR MED-MED +#define tRecurn 0x21 // RECURSION N +#define tStatP 0x22 +#define tStatZ 0x23 +#define tStatT 0x24 +#define tStatChi 0x25 +#define tStatF 0x26 +#define tStatDF 0x27 +#define tStatPhat 0x28 +#define tStatPhat1 0x29 +#define tStatPhat2 0x2A +#define tStatMeanX1 0x2B +#define tStatStdX1 0x2C +#define tStatN1 0x2D +#define tStatMeanX2 0x2E +#define tStatStdX2 0x2F +#define tStatN2 0x30 +#define tStatStdXP 0x31 +#define tStatLower 0x32 +#define tStatUpper 0x33 +#define tStat_s 0x34 +#define tLRSqr 0x35 +#define tBRSqr 0x36 + +// These next tokens are only used to access the data +// They are display only and the user cannot access them at all +#define tF_DF 0x37 +#define tF_SS 0x38 +#define tF_MS 0x39 +#define tE_DF 0x3A +#define tE_SS 0x3B +#define tE_MS 0x3C + +#define tVarSys 0x63 +// 2nd Half Of System Input/Output Variables +#define tuXscl 0x00 +#define tuYscl 0x01 +#define tXscl 0x02 +#define tYscl 0x03 +#define tRecuru0 0x04 +#define tRecurv0 0x05 +#define tun1 0x06 +#define tvn1 0x07 +#define tuRecuru0 0x08 +#define tuRecurv0 0x09 +#define tXmin 0x0A +#define tXmax 0x0B +#define tYmin 0x0C +#define tYmax 0x0D +#define tTmin 0x0E +#define tTmax 0x0F +#define tThetaMin 0x10 +#define tThetaMax 0x11 +#define tuXmin 0x12 +#define tuXmax 0x13 +#define tuYmin 0x14 +#define tuYmax 0x15 +#define tuThetMin 0x16 +#define tuThetMax 0x17 +#define tuTmin 0x18 +#define tuTmax 0x19 +#define tTblMin 0x1A +#define tPlotStart 0x1B +#define tuPlotStart 0x1C +#define tnMax 0x1D +#define tunMax 0x1E +#define tnMin 0x1F +#define tunMin 0x20 +#define tTblStep 0x21 +#define tTStep 0x22 +#define tThetaStep 0x23 +#define tuTStep 0x24 +#define tuThetStep 0x25 +#define tDeltaX 0x26 +#define tDeltaY 0x27 +#define tXFact 0x28 +#define tYFact 0x29 +#define tTblInput 0x2A +#define tFinN 0x2B +#define tFinI 0x2C +#define tFinPV 0x2D +#define tFinPMT 0x2E +#define tFinFV 0x2F +#define tFinPY 0x30 +#define tFinCY 0x31 +#define tRecurw0 0x32 +#define tuRecurw0 0x33 +#define tPlotStep 0x34 +#define tuPlotStep 0x35 +#define tXres 0x36 +#define tuXres 0x37 +#define tRecuru02 0x38 +#define tuRecuru02 0x39 +#define tRecurv02 0x3C +#define tuRecurv02 0x3D +#define tRecurw02 0x3E +#define tuRecurw02 0x3F + +// 2nd Byte Of t2ByteTok Tokens +#define tFinNPV 0x00 +#define tFinIRR 0x01 +#define tFinBAL 0x02 +#define tFinPRN 0x03 +#define tFinINT 0x04 +#define tFinToNom 0x05 +#define tFinToEff 0x06 +#define tFinDBD 0x07 +#define tLCM 0x08 +#define tGCD 0x09 +#define tRandInt 0x0A +#define tRandBin 0x0B +#define tSubStrng 0x0C +#define tStdDev 0x0D +#define tVariance 0x0E +#define tInStrng 0x0F +#define tDNormal 0x10 +#define tInvNorm 0x11 +#define tDT 0x12 +#define tChI 0x13 +#define tDF 0x14 +#define tBINPDF 0x15 +#define tBINCDF 0x16 +#define tPOIPDF 0x17 +#define tPOICDF 0x18 +#define tGEOPDF 0x19 +#define tGEOCDF 0x1A +#define tNormalPDF 0x1B +#define tTPDF 0x1C +#define tChiPDF 0x1D +#define tFPDF 0x1E +#define tRandNorm 0x1F +#define tFinFPMT 0x20 +#define tFinFI 0x21 +#define tFinFPV 0x22 +#define tFinFN 0x23 +#define tFinFFV 0x24 +#define tConj 0x25 +#define tReal 0x26 +#define tImag 0x27 +#define tAngle 0x28 +#define tCumSum 0x29 +#define tExpr 0x2A +#define tLength 0x2B +#define tDeltaLst 0x2C +#define tRef 0x2D +#define tRRef 0x2E +#define tToRect 0x2F +#define tToPolar 0x30 +#define tConste 0x31 +#define tSinReg 0x32 +#define tLogistic 0x33 +#define tLinRegTTest 0x34 +#define tShadeNorm 0x35 +#define tShadeT 0x36 +#define tShadeChi 0x37 +#define tShadeF 0x38 +#define tMatToLst 0x39 +#define tLstToMat 0x3A +#define tZTest 0x3B +#define tTTest 0x3C +#define t2SampZTest 0x3D +#define t1PropZTest 0x3E +#define t2PropZTest 0x3F +#define tChiTest 0x40 +#define tZIntVal 0x41 +#define t2SampZInt 0x42 +#define t1PropZInt 0x43 +#define t2PropZInt 0x44 +#define tGraphStyle 0x45 +#define t2SampTTest 0x46 +#define t2SampFTest 0x47 +#define tTIntVal 0x48 +#define t2SampTInt 0x49 +#define tSetupLst 0x4A +#define tFinPMTend 0x4B +#define tFinPMTbeg 0x4C +#define tRealM 0x4D +#define tPolarM 0x4E +#define tRectM 0x4F +#define tExprOn 0x50 +#define tExprOff 0x51 +#define tClrAllLst 0x52 +#define tGetCalc 0x53 +#define tDelVar 0x54 +#define tEquToStrng 0x55 +#define tStrngToequ 0x56 +#define tDelLast 0x57 +#define tSelect 0x58 +#define tANOVA 0x59 +#define tModBox 0x5A +#define tNormProb 0x5B +#define tMGT 0x64 +#define tZFit 0x65 +#define tDiag_on 0x66 +#define tDiag_off 0x67 +#define tArchive 0x68 +#define tUnarchive 0x69 +#define tAsm 0x6A +#define tAsmComp 0x6B +#define tAsmPrgm 0x6C +#define tAsmCmp 0x6D +#define tLcapAAcute 0x6E +#define tLcapAGrave 0x6F +#define tLcapACaret 0x70 +#define tLcapADier 0x71 +#define tLaAcute 0x72 +#define tLaGrave 0x73 +#define tLaCaret 0x74 +#define tLaDier 0x75 +#define tLcapEAcute 0x76 +#define tLcapEGrave 0x77 +#define tLcapECaret 0x78 +#define tLcapEDier 0x79 +#define tLeAcute 0x7A +#define tLeGrave 0x7B +#define tLeCaret 0x7C +#define tLeDier 0x7D +#define tLcapIGrave 0x7F +#define tLcapICaret 0x80 +#define tLcapIDier 0x81 +#define tLiAcute 0x82 +#define tLiGrave 0x83 +#define tLiCaret 0x84 +#define tLiDier 0x85 +#define tLcapOAcute 0x86 +#define tLcapOGrave 0x87 +#define tLcapOCaret 0x88 +#define tLcapODier 0x89 +#define tLoAcute 0x8A +#define tLoGrave 0x8B +#define tLoCaret 0x8C +#define tLoDier 0x8D +#define tLcapUAcute 0x8E +#define tLcapUGrave 0x8F +#define tLcapUCaret 0x90 +#define tLcapUDier 0x91 +#define tLuAcute 0x92 +#define tLuGrave 0x93 +#define tLuCaret 0x94 +#define tLuDier 0x95 +#define tLcapCCed 0x96 +#define tLcCed 0x97 +#define tLcapNTilde 0x98 +#define tLnTilde 0x99 +#define tLaccent 0x9A +#define tLgrave 0x9B +#define tLdieresis 0x9C +#define tLquesDown 0x9D +#define tLexclamDown 0x9E +#define tLalpha 0x9F +#define tLbeta 0xA0 +#define tLgamma 0xA1 +#define tLcapDelta 0xA2 +#define tLdelta 0xA3 +#define tLepsilon 0xA4 +#define tLlambda 0xA5 +#define tLmu 0xA6 +#define tLpi 0xA7 +#define tLrho 0xA8 +#define tLcapSigma 0xA9 +#define tLphi 0xAB +#define tLcapOmega 0xAC +#define tLphat 0xAD +#define tLchi 0xAE +#define tLstatF 0xAF +#define tLa 0xB0 +#define tLb 0xB1 +#define tLc 0xB2 +#define tLd 0xB3 +#define tLsmalle 0xB4 +#define tLf 0xB5 +#define tLsmallg 0xB6 +#define tLh 0xB7 +#define tLi 0xB8 +#define tLj 0xB9 +#define tLk 0xBA +#define tLl 0xBC +#define tLm 0xBD +#define tLsmalln 0xBE +#define tLo 0xBF +#define tLp 0xC0 +#define tLq 0xC1 +#define tLsmallr 0xC2 +#define tLs 0xC3 +#define tLsmallt 0xC4 +#define tLu 0xC5 +#define tLv 0xC6 +#define tLw 0xC7 +#define tLx 0xC8 +#define tLy 0xC9 +#define tLz 0xCA +#define tLsigma 0xCB +#define tLtau 0xCC +#define tLcapIAcute 0xCD +#define tGarbageCollect 0xCE + +#define tExtTok 0xEF +// 2nd Byte Of tExtTok Tokens +#define tSetDate 0x00 +#define tSetTime 0x01 +#define tCheckTmr 0x02 +#define tSetDtFmt 0x03 +#define tSetTmFmt 0x04 +#define tTimeCnv 0x05 +#define tDayOfWk 0x06 +#define tGetDtStr 0x07 +#define tGetTmStr 0x08 +#define tGetDate 0x09 +#define tGetTime 0x0A +#define tStartTmr 0x0B +#define tGtDtFmt 0x0C +#define tGetTmFmt 0x0D +#define tIsClockOn 0x0E +#define tClockOff 0x0F +#define tClockOn 0x10 +#define tOpenLib 0x11 +#define tExecLib 0x12 +#define tInvT 0x13 +#define tChiSquaredTest 0x14 +#define tLinRegTInt 0x15 +#define tManualFit 0x16 +#define tZQuadrant 0x17 +#define tZFracHalf 0x18 +#define tZFracThird 0x19 +#define tZFracFourth 0x1A +#define tZFracFifth 0x1B +#define tZFracEighth 0x1C +#define tZFracTenth 0x1D +#define tFracSlash 0x2E +#define tFracMixedNum 0x2F +#define tSwapImProper 0x30 +#define tSwapFracDec 0x31 +#define tRemainder 0x32 +#define tSummationSigma 0x33 +#define tLogBase 0x34 +#define tRandIntNoRep 0x35 +#define tMathPrint 0x36 +#define tClassic 0x38 +#define tAutoAnswer 0x3B +#define tDecAnswer 0x3C +#define tFracAnswer 0x3D +#define tBlue 0x41 +#define tRed 0x42 +#define tBlack 0x43 +#define tMagenta 0x44 +#define tGreen 0x45 +#define tOrange 0x46 +#define tBrown 0x47 +#define tNavy 0x48 +#define tLtBlue 0x49 +#define tYellow 0x4A +#define tWhite 0x4B +#define tLtGray 0x4C +#define tMedGray 0x4D +#define tGray 0x4E +#define tDarkGray 0x4F +#define tGraphColor 0x65 +#define tTextColor 0x67 +#define tBackgroundOn 0x5B +#define tBackgroundOff 0x64 +#define tThin 0x74 +#define tBorderColor 0x6C +#define tAsm84CPrgm 0x68 +#define tAsm84CCmp 0x69 +#define tAsm84CeCmp 0x7B +#define tAsm84CePrgm 0x7A + +/* 2 byte extended tokens (tExtTok) present in OS 5.2 and above */ +#define tSEQn 0x8F /* 'SEQ(n)' */ +#define tSEQn1 0x90 /* 'SEQ(n+1)' */ +#define tSEQn2 0x91 /* 'SEQ(n+2)' */ +#define tLEFT 0x92 /* 'LEFT' */ +#define tCENTER 0x93 /* 'CENTER' */ +#define tRIGHT 0x94 /* 'RIGHT' */ +#define tInvBinom 0x95 /* 'invBinom(' */ +#define tWait 0x96 /* 'Wait_' */ +#define tToString 0x97 /* 'toString(' */ +#define tEval 0x98 /* 'eval(' */ + +/* + * --- TIOS System error codes --- + */ +#define OS_E_EDIT (1<<7) +#define OS_E_MASK (0x7F) +#define OS_E_OVERFLOW (1+OS_E_EDIT) +#define OS_E_DIVBY0 (2+OS_E_EDIT) +#define OS_E_SINGULARMAT (3+OS_E_EDIT) +#define OS_E_DOMAIN (4+OS_E_EDIT) +#define OS_E_INCREMENT (5+OS_E_EDIT) +#define OS_E_BREAK (6+OS_E_EDIT) +#define OS_E_NONREAL (7+OS_E_EDIT) +#define OS_E_SYNTAX (8+OS_E_EDIT) +#define OS_E_DATATYPE (9+OS_E_EDIT) +#define OS_E_ARGUMENT (10+OS_E_EDIT) +#define OS_E_DIMMISMATCH (11+OS_E_EDIT) +#define OS_E_DIMENSION (12+OS_E_EDIT) +#define OS_E_UNDEFINED (13+OS_E_EDIT) +#define OS_E_MEMORY (14+OS_E_EDIT) +#define OS_E_INVALID (15+OS_E_EDIT) +#define OS_E_ILLEGALNEST (16+OS_E_EDIT) +#define OS_E_BOUND (17+OS_E_EDIT) +#define OS_E_GRAPHRANGE (18+OS_E_EDIT) +#define OS_E_ZOOM (19+OS_E_EDIT) +#define OS_E_LABEL (20) +#define OS_E_STAT (21) +#define OS_E_SOLVER (22+OS_E_EDIT) +#define OS_E_SINGULARITY (23+OS_E_EDIT) +#define OS_E_SIGNCHANGE (24+OS_E_EDIT) +#define OS_E_ITERATIONS (25+OS_E_EDIT) +#define OS_E_BADGUESS (26+OS_E_EDIT) +#define OS_E_STATPLOT (27) +#define OS_E_TOLTOOSMALL (28+OS_E_EDIT) +#define OS_E_RESERVED (29+OS_E_EDIT) +#define OS_E_MODE (30+OS_E_EDIT) +#define OS_E_LNKERR (31+OS_E_EDIT) +#define OS_E_LNKMEMERR (32+OS_E_EDIT) +#define OS_E_LNKTRANSERR (33+OS_E_EDIT) +#define OS_E_LNKDUPERR (34+OS_E_EDIT) +#define OS_E_LNKMEMFULL (35+OS_E_EDIT) +#define OS_E_UNKNOWN (36+OS_E_EDIT) +#define OS_E_SCALE (37+OS_E_EDIT) +#define OS_E_IDNOTFOUND (38) +#define OS_E_NOMODE (39+OS_E_EDIT) +#define OS_E_VALIDATION (40) +#define OS_E_LENGTH (41+OS_E_EDIT) +#define OS_E_APPLICATION (42+OS_E_EDIT) +#define OS_E_APPERR1 (43+OS_E_EDIT) +#define OS_E_APPERR2 (44+OS_E_EDIT) +#define OS_E_EXPIREDAPP (45) +#define OS_E_BADADD (46) +#define OS_E_ARCHIVED (47+OS_E_EDIT) +#define OS_E_VERSION (48) +#define OS_E_ARCHFULL (49) +#define OS_E_VARIABLE (50+OS_E_EDIT) +#define OS_E_DUPLICATE (51+OS_E_EDIT) + +/* + * --- TI-OS os_GetCSC Scan Code Return Values --- + */ +#define sk_Down 0x01 +#define sk_Left 0x02 +#define sk_Right 0x03 +#define sk_Up 0x04 +#define sk_Enter 0x09 +#define sk_2nd 0x36 +#define sk_Clear 0x0F +#define sk_Alpha 0x30 +#define sk_Add 0x0A +#define sk_Sub 0x0B +#define sk_Mul 0x0C +#define sk_Div 0x0D +#define sk_Graph 0x31 +#define sk_Trace 0x32 +#define sk_Zoom 0x33 +#define sk_Window 0x34 +#define sk_Yequ 0x35 +#define sk_Mode 0x37 +#define sk_Del 0x38 +#define sk_Store 0x2A +#define sk_Ln 0x2B +#define sk_Log 0x2C +#define sk_Square 0x2D +#define sk_Recip 0x2E +#define sk_Math 0x2F +#define sk_0 0x21 +#define sk_1 0x22 +#define sk_4 0x23 +#define sk_7 0x24 +#define sk_2 0x1A +#define sk_5 0x1B +#define sk_8 0x1C +#define sk_3 0x12 +#define sk_6 0x13 +#define sk_9 0x14 +#define sk_Comma 0x25 +#define sk_Sin 0x26 +#define sk_Apps 0x27 +#define sk_GraphVar 0x28 +#define sk_DecPnt 0x19 +#define sk_LParen 0x1D +#define sk_Cos 0x1E +#define sk_Prgm 0x1F +#define sk_Stat 0x20 +#define sk_Chs 0x11 +#define sk_RParen 0x15 +#define sk_Tan 0x16 +#define sk_Vars 0x17 +#define sk_Power 0x0E + +/* Compatibility defines */ +#define prgm_CleanUp() +#define pgrm_CleanUp() +#define memset_fast memset + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/frontends/calculator/CEdev/include/usb.h b/frontends/calculator/CEdev/include/usb.h new file mode 100644 index 0000000..35d95d1 --- /dev/null +++ b/frontends/calculator/CEdev/include/usb.h @@ -0,0 +1,52 @@ +/** + * @file + * @authors Matt "MateoConLechuga" Waltz + * @authors Jacob "jacobly" Young + * @brief USB communication routines + */ + +#ifndef H_USB +#define H_USB + +#include <stdint.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @returns True if the usb bus line is powered, i.e. connected to a another calc + */ +bool usb_BusPowered(void); + +/** + * @returns True if the usb is self powered + */ +bool usb_SelfPowered(void); + +/** + * Resets the usb controller chip + */ +void usb_ResetChip(void); + +/** + * Disables the usb timer interrupt (timer 3) + */ +void usb_DisableTimers(void); + +/** + * Enables the usb timer interrupt (timer 3) + */ +void usb_EnableTimers(void); + +/** + * Resets the usb timer interrupt (timer 3) + */ +void usb_ResetTimers(void); + +#ifdef __cplusplus +} +#endif + +#endif |