Line: 1 to 1 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Calling C Functions from Forth and Vice Versa | ||||||||||||||||
Line: 17 to 17 | ||||||||||||||||
| ||||||||||||||||
Changed: | ||||||||||||||||
< < |
| |||||||||||||||
> > |
| |||||||||||||||
| ||||||||||||||||
Line: 57 to 57 | ||||||||||||||||
Calling Forth Words from C Functions | ||||||||||||||||
Changed: | ||||||||||||||||
< < | Data Stack Pointer SPS is in R7 and Top Of Stack TOS is in R6. R7 can't be a register variable, that's why R9 is used as a temporary storage. | |||||||||||||||
> > | Data Stack Pointer SPS is in R1 and Top Of Stack TOS is in R0 (first parameter). | |||||||||||||||
C function FS_include() from fs.c![]() FS_type and FS_evaluate .
| ||||||||||||||||
Line: 65 to 65 | ||||||||||||||||
* @brief![]() ![]() | ||||||||||||||||
Added: | ||||||||||||||||
> > | * forth_stack TOS (lower word) and SPS (higher word)
* @param![]() | |||||||||||||||
* str filename (w/ or w/o null termination)
* @param![]() ![]() | ||||||||||||||||
Changed: | ||||||||||||||||
< < | * None | |||||||||||||||
> > | * TOS (lower word) and SPS (higer word) | |||||||||||||||
*/ | ||||||||||||||||
Changed: | ||||||||||||||||
< < | void FS_include(uint8_t *str, int count) { | |||||||||||||||
> > | uint64_t FS_include(uint64_t forth_stack, uint8_t *str, int count) { | |||||||||||||||
FIL fil; /* File object */ FRESULT fr; /* FatFs return code */ | ||||||||||||||||
Added: | ||||||||||||||||
> > | uint64_t stack; stack = forth_stack; | |||||||||||||||
memcpy(path, str, count); line[count] = 0; | ||||||||||||||||
Line: 83 to 88 | ||||||||||||||||
if (fr) { // open failed strcpy(line, "Err: file not found"); | ||||||||||||||||
Changed: | ||||||||||||||||
< < | FS_type((uint8_t*)line, strlen(line)); return; | |||||||||||||||
> > | stack = FS_type(stack, (uint8_t*)line, strlen(line)); | |||||||||||||||
} /* Read every line and interprets it */ while (f_gets(line, sizeof line, &fil)) { // line without \n | ||||||||||||||||
Changed: | ||||||||||||||||
< < | FS_evaluate((uint8_t*)line, strlen(line)-1); | |||||||||||||||
> > | stack = FS_evaluate(stack, (uint8_t*)line, strlen(line)-1); | |||||||||||||||
} /* Close the file */ f_close(&fil); | ||||||||||||||||
Added: | ||||||||||||||||
> > | return stack; | |||||||||||||||
} | ||||||||||||||||
Line: 102 to 108 | ||||||||||||||||
@ ----------------------------------------------------------------------------- Wortbirne Flag_visible, "include" | ||||||||||||||||
Changed: | ||||||||||||||||
< < | @ ( "filename" any -- any ) Interprets the content of the file. // void FS_include(uint8_t *str, int count) | |||||||||||||||
> > | @ ( any "filename" -- any ) Interprets the content of the file. // uint64_t FS_include (uint64_t forth_stack, uint8_t *str, int count); | |||||||||||||||
@ ----------------------------------------------------------------------------- include: push {lr} bl token @ ( -- c-addr len ) incl: | ||||||||||||||||
Changed: | ||||||||||||||||
< < | movs r1, tos // len -> count | |||||||||||||||
> > | movs r3, tos // len -> count | |||||||||||||||
drop | ||||||||||||||||
Changed: | ||||||||||||||||
< < | movs r0, tos // c-addr -> str | |||||||||||||||
> > | movs r2, tos // c-addr -> str | |||||||||||||||
drop | ||||||||||||||||
Changed: | ||||||||||||||||
< < | movs r9, psp // get psp movs r8, tos // get tos | |||||||||||||||
> > | movs r0, tos // get tos movs r1, psp // get psp | |||||||||||||||
bl FS_include | ||||||||||||||||
Changed: | ||||||||||||||||
< < | movs psp, r9 // update psp movs tos, r8 // update tos | |||||||||||||||
> > | movs tos, r0 // update tos movs psp, r1 // update psp | |||||||||||||||
pop {pc}
The C function FS_include() from fs.c![]() evaluate by the FS_evaluate() function.
| ||||||||||||||||
Changed: | ||||||||||||||||
< < | // void FS_evaluate(uint8_t* str, int count); | |||||||||||||||
> > | // uint64_t FS_evaluate(uint64_t forth_stack, uint8_t* str, int count); | |||||||||||||||
.global FS_evaluate FS_evaluate: push {r4-r7, lr} | ||||||||||||||||
Changed: | ||||||||||||||||
< < | movs psp, r9 // get psp movs tos, r8 // get tos | |||||||||||||||
> > | movs tos, r0 // get tos movs psp, r1 // get psp | |||||||||||||||
pushdatos | ||||||||||||||||
Changed: | ||||||||||||||||
< < | movs tos, r0 // str | |||||||||||||||
> > | movs tos, r2 // str | |||||||||||||||
pushdatos | ||||||||||||||||
Changed: | ||||||||||||||||
< < | movs tos, r1 // count | |||||||||||||||
> > | movs tos, r3 // count | |||||||||||||||
bl evaluate | ||||||||||||||||
Changed: | ||||||||||||||||
< < | movs r9, psp // update psp movs r8, tos // update tos | |||||||||||||||
> > | movs r0, tos // update tos movs r1, psp // update psp | |||||||||||||||
pop {r4-r7, pc} |