-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSAVE.FTH
38 lines (33 loc) · 1.02 KB
/
SAVE.FTH
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
\ SAVE.FTH save entire Forth500 image to a file, reload with LOADM from BASIC
\ Author: Robert van Engelen
\ In Forth500 execute:
\ SAVE F:MYFORTH.BIN
\ In BASIC execute (assuming memory for Forth500 is still allocated):
\ LOADM "F:MYFORTH.BIN"
\ CALL &B0000 (or CALL &B9000 on an unexpanded machine)
.( Loading SAVE...)
ANEW _SAVE_
DECIMAL
: SAVE ( "name" -- )
PARSE-NAME W/O CREATE-FILE THROW >R
\ determine Forth500 start address and length up to HERE
['] (:) $ff00 AND HERE OVER -
\ create file header using HERE as a temporary buffer
HERE 16 ERASE
\ 255 0 6 1 16 SizeLow SizeHigh 0 StartLow StartHigh Segment 255 255 255 0 15
-1 HERE C!
262 HERE 2+ !
16 HERE 4 + C!
DUP HERE 5 + !
OVER HERE 8 + !
$b HERE 10 + C!
-1 HERE 11 + !
-1 HERE 13 + C!
15 HERE 15 + C!
\ write 16 byte header
HERE 16 R@ WRITE-FILE THROW
\ write Forth500 image from base address up to HERE
R@ WRITE-FILE THROW
\ close the file
R> CLOSE-FILE THROW
;