Skip to content

Commit

Permalink
Merge pull request #166 from TG9541/add-wipe
Browse files Browse the repository at this point in the history
fixes #165 implement WIPE
  • Loading branch information
TG9541 authored Feb 25, 2018
2 parents 4b449d8 + b846117 commit c925877
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 74 deletions.
17 changes: 11 additions & 6 deletions docs/words.md
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,12 @@
; next word in input stream.
```

```
; [COMPILE] ( -- ; <string> )
; Compile next immediate
; word into code dictionary.
```

```
; , ( w -- )
; Compile an integer into
Expand All @@ -890,12 +896,6 @@
; as an integer literal.
```

```
; [COMPILE] ( -- ; <string> )
; Compile next immediate
; word into code dictionary.
```

```
; COMPILE ( -- )
; Compile next jsr in
Expand Down Expand Up @@ -1217,3 +1217,8 @@
; This should be the last word called in the interrupt handler
```

```
; WIPE ( -- ) ( TOS STM8: - )
; Return to RAM mode, claim VARIABLE RAM, init dictionary in RAM
```

76 changes: 44 additions & 32 deletions forth.asm
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
USREVAL = UPP+6 ; "'EVAL" execution vector of EVAL
USRPROMPT = UPP+8 ; "'PROMPT" point to prompt word (default .OK)
USRCP = UPP+10 ; "CP" point to top of dictionary
USRLAST = UPP+12 ; "LAST" currently last name in dictionary (init: to LASTN)
USRLAST = UPP+12 ; "LAST" currently last name in dictionary
NVMCP = UPP+14 ; point to top of dictionary in Non Volatile Memory

; Null initialized core variables (growing down)
Expand Down Expand Up @@ -511,45 +511,33 @@ COLD:
BSET PSIM+CR2,#PNRX ; enable PNRX external interrupt
.endif

.ifne HAS_LED7SEG
.if gt,(HAS_LED7SEG-1)
MOV LED7GROUP,#0 ; one of position HAS_LED7SEG 7-SEG digit groups
.endif
MOV LED7FIRST ,#0x66 ; 7S LEDs 4..
MOV LED7FIRST+1,#0x78 ; 7S LEDs .t.
MOV LED7FIRST+2,#0x74 ; 7S LEDs ..h
.endif

CALL PRESE ; initialize data stack, TIB

DoLitW UZERO
DoLitC USRRAMINIT
DoLitC (ULAST-UZERO)
CALL CMOVE ; initialize user area

.ifne HAS_CPNVM
EXGW X,Y
LDW X,USRCP ; reserve some space for user variable
LDW USRVAR,X
ADDW X,#32
LDW USRCP,X
LDW USRCTOP,X ; store new CTOP
EXGW X,Y
.endif
CALL WIPE ; initialize dictionary

.ifne HAS_OUTPUTS
CALL ZERO
CALL OUTSTOR
.endif

.ifne HAS_LED7SEG

.if gt,(HAS_LED7SEG-1)
MOV LED7GROUP,#0 ; one of position HAS_LED7SEG 7-SEG digit groups
.endif

MOV LED7FIRST ,#0x66 ; 7S LEDs 4..
MOV LED7FIRST+1,#0x78 ; 7S LEDs .t.
MOV LED7FIRST+2,#0x74 ; 7S LEDs ..h

.endif

; Hardware initialization complete
RIM ; enable interrupts

CALL [TBOOT+3] ; application boot
CALL OVERT ; initialize CONTEXT from USRLAST
JP QUIT ; start interpretation


Expand Down Expand Up @@ -3708,16 +3696,14 @@ SCOM2: CALL NUMBQ ; try to convert to number
OVERT:
.ifne HAS_CPNVM
LDW Y,USRLAST
JRPL 1$ ; skip if USRLAST points to RAM
LDW NVMCONTEXT,Y ; update NVMCONTEXT
LD A,[USRCTOP]
OR A,[USRCTOP+1]
JREQ 1$ ; re-link RAM dictionary?
LDW [USRCTOP],Y
JRMI 1$ ; check if USRLAST points to NVM
LDW USRCONTEXT,Y
RET
1$:
LDW USRCONTEXT,Y
LDW NVMCONTEXT,Y ; update NVMCONTEXT
LDW [USRCTOP],Y ; update link from RAM dictionary
RET

.else
LDW Y,USRLAST
LDW USRCONTEXT,Y
Expand Down Expand Up @@ -3855,7 +3841,7 @@ DOCON:
1$: RET
.endif

.ifeq NO_VARIABLE
.ifne HAS_VARIABLE
; VARIABLE ( -- ; <string> )
; Compile a new variable
; initialized to 0.
Expand All @@ -3880,7 +3866,7 @@ VARIA:
.endif


.ifeq NO_VARIABLE
.ifne HAS_VARIABLE
; ALLOT ( n -- )
; Allocate n bytes to code DICTIONARY.

Expand Down Expand Up @@ -4471,6 +4457,32 @@ RESTC:

.endif

; WIPE ( -- ) ( TOS STM8: - )
; Return to RAM mode, claim VARIABLE RAM, init dictionary in RAM

; HEADER WIPE "WIPE"
WIPE:
.ifne HAS_CPNVM
CALLR RAMM
PUSHW X
LDW X,COLDCTOP ; reserve some space for user variable
LDW USRVAR,X
ADDW X,#RAM_VARIABLE
LDW USRCTOP,X ; store new CTOP
LDW Y,COLDCONTEXT
LDW NVMCONTEXT,Y
LDW (X),Y ; create dummy word in RAM ...
INCW X
INCW X
CLR (X) ; ... with NULL string
LDW USRLAST,X ; prepare OVERT
INCW X
LDW USRCP,X ; done
POPW X
.endif
JP OVERT ; initialize CONTEXT from USRLAST


;===============================================================
LASTN = LINK ;last name defined

Expand Down
3 changes: 2 additions & 1 deletion inc/defconf.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
; ABORT" AFT AGAIN AHEAD BEGIN DO DUMP ELSE EXG FOR IF LEAVE
; LOOP MAX MIN NEXT OR REPEAT SEE SPACES THEN U. U.R UM+
; UNTIL WHILE WORDS [COMPILE] _TYPE dm+
NO_VARIABLE = 0 ; Disable VARIABLE and feature "VARIABLE in Flash allocates RAM"
HAS_VARIABLE = 1 ; VARIABLE and feature "VARIABLE in Flash allocates RAM"
RAM_VARIABLE = 32 ; Amount of RAM for VARIABLE claimed by WIPE

WORDS_LINKINTER = 0 ; Link interpreter words
WORDS_LINKCOMP = 0 ; Link compiler words: cp last OVERT $,n ?UNIQUE $COMPILE
Expand Down
7 changes: 4 additions & 3 deletions lib/CURRENT
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
\ requires stm8ef > 2.2.19

#require WIPE

RAM WIPE
WIPE

#require MARKER
#require ALIAS
Expand Down Expand Up @@ -211,8 +210,10 @@ HERE size @ - . .( NVM bytes used )
RAM

#require PERSIST
PERSIST

PERSIST RAM WIPE
#require WIPE
WIPE

\ ------------------------------------------------------------------------------
\ Last Revision: MM-180116 Bug fix in nTOKSNAME
Expand Down
12 changes: 8 additions & 4 deletions lib/VOC
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
\ requires stm8ef > 2.2.19

#require CURRENT \ persistent support for context switching
RAM
#require WIPE
WIPE

RAM WIPE

RAM VARIABLE size NVM HERE size ! \ for code size monitoring only
RAM VARIABLE size NVM HERE size ! \ for code size monitoring only

#require DEFINITIONS
#require FORTH
Expand Down Expand Up @@ -110,7 +111,10 @@ NVM

NVM HERE size @ - . .( NVM bytes used )

RAM WIPE

RAM
#require WIPE
WIPE

\ ------------------------------------------------------------------------------
\ Last Revision: MM-171220 License added
Expand Down
25 changes: 0 additions & 25 deletions lib/WIPE

This file was deleted.

5 changes: 2 additions & 3 deletions test/board.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include utils/tester.fs

\ expected vocabulary (including tester.fs)
T{e WORDS e-> 968 -1390 }T
T{e WORDS e-> 969 -1358 }T

\ core: string with capured EMIT
: test-."" ." abc123" ;
Expand Down Expand Up @@ -142,11 +142,10 @@ RAM
T{ 400 CD>TEST cdram -> }T
T{ cdram -> 800 }T

T{e WORDS e-> 1004 1711 }T
T{e WORDS e-> 1005 1743 }T


\ compile CURRENT and VOC as a test
COLD

#require CURRENT
#require VOC
Expand Down

0 comments on commit c925877

Please sign in to comment.