Skip to content

Commit 930be86

Browse files
committed
ti/vars: add arcUnarcVariable() and deleteArchivedVariable().
1 parent fcd61c8 commit 930be86

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

src/ce/extravars.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <stdbool.h>
2+
#include <stdint.h>
3+
4+
// From <ti/error.h>
5+
int os_PushErrorHandler(void) __attribute__((returns_twice));
6+
void os_PopErrorHandler(void);
7+
// From <ti/vars.h>
8+
#define os_OP1 ((uint8_t*)0xD005F8)
9+
#define os_Flags ((uint8_t*)0xD00080)
10+
11+
void deleteArchivedVariable(void *entry, void *data)
12+
{
13+
int clobber_hl, clobber_de;
14+
asm volatile (
15+
"ld b, 1\n"
16+
"call 021434h\n" // DelVarArc
17+
: "=l" (clobber_hl),
18+
"=e" (clobber_de)
19+
: [hl] "l" (entry),
20+
[de] "e" (data),
21+
[flags] "iyl" (os_Flags)
22+
: "cc", "a", "bc", "ix", "iy"
23+
);
24+
}
25+
26+
bool arcUnarcVariable(uint8_t varType, uint8_t nameLen, const char *name)
27+
{
28+
const int err = os_PushErrorHandler();
29+
if (err) {
30+
// dbg_printf("[ERROR caught] [arcUnarcVariable] errno = %d\n", err);
31+
return false;
32+
}
33+
*(os_OP1) = varType;
34+
__builtin_memcpy((char*)(os_OP1+1), name, nameLen);
35+
*(os_OP1+1+nameLen) = '\0';
36+
asm volatile (
37+
"call 021448h\n" // Arc_Unarc
38+
:
39+
: [flags] "iyl" (os_Flags)
40+
: "cc", "a", "bc", "de", "hl", "ix", "iy"
41+
);
42+
os_PopErrorHandler();
43+
return true;
44+
}

src/ce/include/ti/vars.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,24 @@ void *os_NextSymEntry(void *entry, uint24_t *type, uint24_t *nameLength, char *n
291291
*/
292292
int os_DelSymEntry(void *entry);
293293

294+
/**
295+
* Delete a var from archive (Flash).
296+
*
297+
* @param[in] entry An entry as used in (or returned from) \c os_NextSymEntry or \c os_ChkFindSym.
298+
* @param[in] data Start of variable's data as used in (or returned from) \c os_NextSymEntry or \c os_ChkFindSym.
299+
*/
300+
void os_DelArchivedVar(void *entry, void *data);
301+
302+
/**
303+
* Archive (if in RAM) or Unarchive (if in Flash) a variable.
304+
*
305+
* @param[in] varType The variable type ID (like \c OS_TYPE_PROT_PRGM etc.)
306+
* @param[in] nameLen Length of the variable name
307+
* @param[in] name Variable name
308+
* @return true on success, false on failure.
309+
*/
310+
bool arcUnarcVariable(uint8_t varType, uint8_t nameLen, const char *name);
311+
294312
/**
295313
* Creates an TIOS Str.
296314
*

src/ce/makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,30 @@
1616

1717
include $(CURDIR)/../common.mk
1818

19-
WILDCARD_SRC = $(wildcard *.src)
19+
BUILD_SRC := $(patsubst %,build/%.src,$(wildcard *.c *.cpp))
20+
21+
EZCFLAGS := -S -ffreestanding -Wall -Wextra -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz
22+
EZCFLAGS += -D_EZ80 -isystem ../libc/include -mllvm -profile-guided-section-prefix=false
23+
EZCXXFLAGS := $(EZCFLAGS) -fno-exceptions -fno-rtti
24+
EZCXXFLAGS += -isystem ../libc/include/c++
25+
26+
WILDCARD_SRC = $(wildcard *.src) $(BUILD_SRC)
2027
WILDCARD_H = $(wildcard include/*.h)
2128
WILDCARD_HW_H = $(wildcard include/sys/*.h)
2229
WILDCARD_TI_H = $(wildcard include/ti/*.h)
2330

2431
WILDCARD_CXX_H = $(wildcard include/c++/*)
2532
WILDCARD_CXX_TI_H = $(wildcard include/ti/c++/*)
2633

27-
all:
34+
all: $(BUILD_SRC)
35+
36+
build/%.c.src: %.c
37+
$(Q)$(call MKDIR,build)
38+
$(Q)$(EZCC) $(EZCFLAGS) $< -o $@
39+
40+
build/%.cpp.src: %.cpp
41+
$(Q)$(call MKDIR,build)
42+
$(Q)$(EZCC) $(EZCXXFLAGS) $< -o $@
2843

2944
install: $(addprefix install-,$(TARGETS))
3045
$(Q)$(call MKDIR,$(INSTALL_H))

0 commit comments

Comments
 (0)