Skip to content

Commit

Permalink
First tests with Y=TOS and CPU flags
Browse files Browse the repository at this point in the history
  • Loading branch information
TG9541 committed Dec 7, 2016
1 parent a0072d8 commit 03996fb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 44 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
# STM8S eForth (stm8ef)

This is a heavily refactored port of Dr. C.H. Ting's eForth for the *STM8S Discovery* to STM8S *Value Line* µCs boards and the [SDCC toolchain](http://sdcc.sourceforge.net/). Mixing C, Forth, and assembler is possible.
This is an extended and refactored version of [Dr. C.H. Ting's eForth for the *STM8S Discovery*](http://www.forth.org/svfig/kk/07-2010.html) that turns STM8S *Value Line* µCs boards into an interactive Forth development environment. The [SDCC toolchain](http://sdcc.sourceforge.net/) is used for building the eForth core, which makes mixing Forth, assembly, and C possible.

The binary of the core interactive Forth system uses below 4400 bytes, including the overhead from SDCC, like C startup code, and interrupt tables. The binary size with a rich feature feature set, including *Compile to Flash*, *Background Task*, and *CREATE-DOES>* is below 5000 bytes!
The binary of an interactive eForth system uses below 4400 bytes, including the overhead from SDCC (C startup code and interrupt table). With a rich feature feature set (*Compile to Flash*, *Background Task*, and *CREATE-DOES>*) the binary size is below 5000 bytes.

Please refer to the [Wiki on GitHub](https://github.com/TG9541/stm8ef/wiki) for more information!

## Overview

New features:
Features:

* compile Forth to Non Volatile Memory (Flash IAP)
* preemotive background tasks for concurrent `INPUT-PROCESS-OUTPUT` processing with a fixed cycle time (5ms using TIM2)
* compile Forth to NVM (Non Volatile Memory with Flash IAP)
* autostart feature for embedded applications
* preemptive background tasks, e.g. for `INPUT-PROCESS-OUTPUT` proces with fixed cycle time (default 5ms)
* *CREATE-DOES>* pattern
* configurable vocabulary subsets for binary size reduction
* Extended vocabulary:
* STM8 ADC control: ADC! ADC@
* board keys, outputs, LEDs: OUT OUT!
* EEPROM, FLASH lock/unlock: LOCK ULOCK LOCKF ULOCKF
* native bit set/reset: BSR
* inverted byte order 16bit register access: BSR 2C@ 2C!
* compile to Flash memory: NVR RAM RESET 'BOOT
* inverted byte order 16bit register access: 2C@ 2C!
* compile to Flash memory: NVR RAM RESET
* autostart applications: 'BOOT
* ASCII file transfer: FILE HAND
* STC with native BRANCH and EXIT
* board support:
* Subroutine Threaded Code (STC) with native BRANCH and EXIT
* board supporti for Chinese made [STM8S based very low cost boards][WG1]:
* W1209 LED display & half-duplex with SW TX
* C0135 Relay-4 Board
* STM8S103F3 "$0.70" breakout board
* support for [boards with 7Seg-LED UI](https://github.com/TG9541/stm8ef/wiki/eForth-Background-Task): in a background task, `123 .` goes to the 7Seg-LED display, and `?KEY` reads board keys

Many changes to the original source are due to "board support" for Chinese made [STM8S based very low cost boards][WG1].

Canges that required refactoring the original code:

Expand Down Expand Up @@ -62,7 +63,7 @@ There is board suport for some easily available "Chinese gadgets". For details,
* `BOARD_W1209` W1209 low cost thermostat with LED display and half-duplex RS232 through sensor header (9600 baud)
* `BOARD_C0135` C0135 "Relay-4 Board" (can be used as a *Nano PLC*)

There is currently no support for the STM8S Discovery, since I don't have STM8S105C6T6 based boards for testing.
Currently, there is no support for the STM8S Discovery, since I don't have any STM8S105C6T6 based boards for testing.

### STM8S003F3 Core

Expand Down
58 changes: 25 additions & 33 deletions forth.asm
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ STORE:
ADDW X,#4 ; store w at a
RET

; @ ( a -- w )

; Push memory location to stack.

.dw LINK
Expand Down Expand Up @@ -887,7 +887,7 @@ CSTOR:
ADDW X,#4
RET

; C@ ( b -- c )
; C@ ( b -- c ) ; C@ sets Z and N
; Push byte in memory to stack.

.dw LINK
Expand All @@ -898,8 +898,8 @@ CAT:
LDW Y,X ; Y=b
LDW Y,(Y)
LD A,(Y)
LD (1,X),A
CLR (X)
LD (1,X),A
RET

.ifne WORDS_EXTRASTACK
Expand Down Expand Up @@ -2174,20 +2174,15 @@ TWOSL:
.ascii ">CHAR"
.endif
TCHAR:
CALL DOLITC
.db 0x07F
CALL ANDD
CALL DUPP ;mask msb
CALL DOLITC
.db 127
CALL BLANK
CALL WITHI ;check for printable
CALL QBRAN
.dw TCHA1
CALL DROP
CALL DOLITC
.db 0x05F ; "_" ;replace non-printables
TCHA1: RET
LD A,(1,X)
AND A,#0x7F
CP A,#0x7F
JREQ 1$
CP A,#(' ')
JRUGE 2$
1$: LD A,#('_')
2$: LD (1,X),A
RET

; DEPTH ( -- n )
; Return depth of data stack.
Expand Down Expand Up @@ -2361,12 +2356,11 @@ PAD:
.ascii "@EXECUTE"
.endif
ATEXE:
CALL AT
CALL QDUP ;?address or zero
CALL QBRAN
.dw EXE1
CALL EXECU ;execute if non-zero
EXE1: RET ;do nothing if zero
CALL AT ; @ sets Z and N
JRNE 1$
JP DROP
1$: JP EXECU ; execute if non-zero


; CMOVE ( b1 b2 u -- )
; Copy u bytes from b1 to b2.
Expand Down Expand Up @@ -4370,9 +4364,9 @@ DOESS:
.ascii "dodoes"
.endif
DODOES:
CALL LAST
CALL LAST ; ( link field of current word )
CALL AT
CALL NAMET ; ' ( 'last call nop )
CALL NAMET ; ' ( 'last )
CALL DOLITC
.db BRAN_OPC ; ' JP
CALL OVER ; ' JP '
Expand Down Expand Up @@ -4622,18 +4616,16 @@ SEE4: CALL NUFQ ;user control
.ascii "WORDS"
WORDS:
CALL CR
CALL CNTXT ;only in context
WORS1: CALL AT
CALL QDUP ;?at end of list
CALL QBRAN
.dw WORS2
CALL CNTXT ; only in context
WORS1: CALL AT ; @ sets Z and N
JREQ 1$ ; ?at end of list
CALL DUPP
CALL SPACE
CALL DOTID ;display a name
CALL DOTID ; display a name
CALL CELLM
JRA WORS1
CALL DROP
WORS2: RET
1$: CALL DROP
RET

;
Expand Down

0 comments on commit 03996fb

Please sign in to comment.