Skip to content

Commit

Permalink
#285 board_io.inc macros
Browse files Browse the repository at this point in the history
  • Loading branch information
TG9541 committed Dec 16, 2019
1 parent 20d4fd8 commit f82ccd1
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 63 deletions.
90 changes: 36 additions & 54 deletions forth.asm
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,8 @@

.ifne HAS_BACKGROUND

.ifne HAS_LED7SEG
.if gt,(HAS_LED7SEG-1)
RamByte LED7GROUP ; index [0..(HAS_LED7SEG-1)] of 7-SEG digit group
.endif

DIGITS = HAS_LED7SEG*LEN_7SGROUP
RamBlck LED7FIRST,DIGITS ; leftmost 7S-LED digit
LED7LAST = RAMPOOL-1 ; save memory location of rightmost 7S-LED digit
.endif

RamWord BGADDR ; address of background routine (0: off)
RamWord TICKCNT ; 16 bit ticker (counts up)

.ifne HAS_KEYS
RamByte KEYREPET ; board key repetition control (8 bit)
.endif
RamWord TICKCNT ; "TICKCNT" 16 bit ticker (counts up)

BSPPSIZE = 32 ; Size of data stack for background tasks
PADBG = 0x5F ; PAD in background task growing down from here
Expand Down Expand Up @@ -266,7 +252,7 @@

; More core variables in zero page (instead of assigning fixed addresses)
RamWord USRHLD ; "HLD" hold a pointer of output string
RamWord YTEMP ; "YTEMP" extra working register for core words
RamWord YTEMP ; extra working register for core words
RamWord USRIDLE ; "'IDLE" idle routine in KEY

;***********************
Expand Down Expand Up @@ -356,6 +342,38 @@ _TRAP_Handler:

.endif

; ==============================================

; Includes for board support code
; Board I/O initialization and E/E mapping code
; Hardware dependent words, e.g. BKEY, OUT!
.include "boardcore.inc"

; ADC routines depending on STM8 family
.include "stm8_adc.inc"

; Generic board I/O: 7S-LED rendering, board key mapping
.include "board_io.inc"

; ==============================================

; Simulated serial I/O
; either full or half duplex

.ifeq HAS_TXSIM + HAS_RXSIM
_TIM4_IRQHandler:
; dummy for linker - can be overwritten by Forth application
.else
; include required serial I/O code
.ifne PNRX^PNTX
.include "sser_fdx.inc" ; Full Duplex serial
.else
.include "sser_hdx.inc" ; Half Duplex serial
.endif
.endif

; ==============================================

; TIM2 interrupt handler for background task
_TIM2_UO_IRQHandler:
.ifne (HAS_LED7SEG + HAS_BACKGROUND)
Expand Down Expand Up @@ -502,7 +520,7 @@ COLD:
LDW X,#RPP ; initialize return stack
LDW SP,X

CALLR BOARDINIT ; Board initialization (see "boardcore.inc")
CALL BOARDINIT ; Board initialization (see "boardcore.inc")

.ifne HAS_BACKGROUND
; init BG timer interrupt
Expand Down Expand Up @@ -573,14 +591,7 @@ 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
Board_IO_Init ; macro board_io initialization (7S-LED)

CALL PRESE ; initialize data stack, TIB

Expand All @@ -599,21 +610,6 @@ COLD:

; ==============================================

; Includes for board support code
; Board I/O initialization and E/E mapping code
; Hardware dependent words, e.g. BKEY, OUT!
.include "boardcore.inc"

; Generic board I/O: 7S-LED rendering, board key mapping
.include "board_io.inc"

; ==============================================

; ADC routines depending on STM8 family
.include "stm8_adc.inc"

; ==============================================

; Device dependent I/O

.ifne HAS_RXUART
Expand Down Expand Up @@ -652,20 +648,6 @@ TXSTOR:
RET
.endif

; Simulated serial I/O
; either full or half duplex

.ifeq HAS_TXSIM + HAS_RXSIM
_TIM4_IRQHandler:
; dummy for linker - can be overwritten by Forth application
.else
; include required serial I/O code
.ifne PNRX^PNTX
.include "sser_fdx.inc" ; Full Duplex serial
.else
.include "sser_hdx.inc" ; Half Duplex serial
.endif
.endif

; ==============================================

Expand Down
27 changes: 26 additions & 1 deletion inc/board_io.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

.ifne HAS_KEYS

RamByte KEYREPET ; board key repetition control (8 bit)

; ?KEYB ( -- c T | F ) ( TOS STM8: -- Y,Z,N )
; Return keyboard char and true, or false if no key pressed.

Expand Down Expand Up @@ -34,6 +36,15 @@ NOKEYB:

.ifne HAS_LED7SEG

.if gt,(HAS_LED7SEG-1)
RamByte LED7GROUP ; byte index of 7-SEG digit group
.endif

DIGITS = HAS_LED7SEG*LEN_7SGROUP
RamBlck LED7FIRST,DIGITS ; leftmost 7S-LED digit
LED7LAST = RAMPOOL-1 ; save memory location of rightmost 7S-LED digit


; 7-seg LED patterns, "70s chique"
PAT7SM9:
.db 0x00, 0x40, 0x80, 0x52 ; , - . / (',' as blank)
Expand Down Expand Up @@ -178,6 +189,20 @@ PUT7S:
CALL AFLAGS
LD LED7LAST,A
.endif

RET

.macro Board_IO_Init
.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
.endm

.else
.macro Board_IO_Init
; no LED-7Seg
.endm

.endif
19 changes: 11 additions & 8 deletions tools/genconst.awk
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ $1~/^00/ && $3!~/(LINK|RAMPOOL)/ && $4~/[=;]/ && $7~/^"/ {
next
}

# extract lines like:
# RamWord USREVAL ; "'EVAL" execution vector of EVAL
preLine~/RamWord/ && $3!~/RAMPOOL/ && $4=="=" && $5~/RAMPOOL/ {
# use case 1:
# RamWord USREVAL ; "'EVAL" execution vector of EVAL
# use case 2:
# RamByte LED7GROUP ; byte index of 7-SEG digit group
preLine~/Ram(Word|Byte|Blck)/ && $3!~/RAMPOOL/ && $4=="=" && $5~/RAMPOOL/ {
if (split(preLine,b,"\"") == 3) {
symbol = b[2]
symbol = b[2] # use case 1
comment = " \\ " b[3]
}
else {
symbol = $3
symbol = $3 # use case 2
split(preLine,a,";");
addr = "$" substr($1,3)
comment = " \\ " a[2]
}
split(preLine,a,";");
addr = "$" substr($1,3)
comment = " \\ " a[2]
print addr " CONSTANT " symbol comment > target symbol
next
}
Expand Down

0 comments on commit f82ccd1

Please sign in to comment.