File: shex.fs

package info (click to toggle)
gforth 0.7.0+ds2-0.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,808 kB
  • sloc: ansic: 8,506; sh: 3,660; lisp: 1,783; makefile: 993; yacc: 186; sed: 141; lex: 102; awk: 21
file content (99 lines) | stat: -rw-r--r-- 2,364 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
\ shex.fs Output Routines for Motorola S-Records		16jul97jaw

\ Copyright (C) 1998,2000,2003,2006,2007 Free Software Foundation, Inc.

\ This file is part of Gforth.

\ Gforth is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public License
\ as published by the Free Software Foundation, either version 3
\ of the License, or (at your option) any later version.

\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
\ GNU General Public License for more details.

\ You should have received a copy of the GNU General Public License
\ along with this program. If not, see http://www.gnu.org/licenses/.

\ this is a extention to cross.fs to save motorola s-records
\ the first part is generic to output s-records from and to any
\ destination
\ the second part is for the cross compiler

unlock >CROSS

decimal

\ only method to get information
defer @byte ' c@ IS @byte

\ only method to output
defer htype ' type IS htype

: hemit pad c! pad 1 htype ;
: hcr #lf hemit ;

: .## ( c -- ) 	     base @ swap hex s>d <# # # #> htype base ! ;
\ generic checksum support

variable csum
: csum+ ( c -- c )   dup csum +! ;
: .b  ( c -- ) 	     csum+ .## ;
: .w  ( w -- ) 	     dup 8 rshift .b 255 and .b ;
: .csum ( -- )	     csum @ 255 xor 255 and .b ;

2 constant adrlen
1 constant csumlen
32 constant maxline

: .smem ( destadr adr len type -- )
  'S hemit hemit 0 csum !
  dup adrlen + csumlen + .b
  rot .w
  bounds ?DO I @byte .b LOOP
  .csum hcr ;

: 3dup >r 2dup r@ -rot r> ;

: .sregion ( destadr adr len -- )
  BEGIN dup
  WHILE	3dup maxline min dup >r
	'1 .smem r@ /string rot r> + -rot
  REPEAT drop 2drop ;

: .startaddr ( adr -- )
  'S hemit '9 hemit 0 csum !
  adrlen csumlen + .b
  .w .csum hcr ;

\ specific for cross-compiler

0 value fd
: (htype) fd write-file throw ;
' (htype) IS htype

: tc@ X c@ ;
' tc@ IS @byte

variable start-addr

: save-region-shex ( adr len -- )
    bl parse w/o create-file throw to fd
\ PSC1000 trick:
\  'E hemit
\  2dup over swap 200 min .sregion
    0 0 0 '0 .smem
    over swap .sregion 
    start-addr @ .startaddr
    fd close-file throw ;

>MINIMAL

: cpu-start start-addr ! ;
: save-region-shex save-region-shex ;

>CROSS

lock