dos_compilers/DX-FORTH v430/OVERLAY.SCR
2024-07-09 09:07:02 -07:00

1 line
6.0 KiB
Plaintext

\ Overlay - Information 001119es These screens shows how to implement an overlay system for DX-Forth. It allows the creation of applications larger than would otherwise be possible. WARNING: when running or debugging programs using overlays, do not attempt to execute a word in an overlay if that overlay is not currently loaded - it will cause the system to crash. This version is only suitable for MSDOS DX-FORTH 2. \ Overlay - Load screen 001119esFORTH DEFINITIONS DECIMAL APPLICATION CR .( loading the overlay words... ) 2 LOAD CR .( now creating 3 overlays... ) 4 LOAD CR .( now testing it... ) TEST \ Overlay - OBASE OSIZE FILE LOAD-OVERLAY 001119esFORTH DEFINITIONS DECIMAL APPLICATION VARIABLE OBASE \ base address of the overlay segment VARIABLE OSIZE \ size of largest overlay segment VARIABLE FILE 66 ALLOT \ filename buffer \ Load overlay : LOAD-OVERLAY ( c-addr u -- ior ) 2DUP FILE PLACE R/W OPEN-FILE ?DUP IF SWAP DROP EXIT THEN >R OBASE @ OSIZE @ R@ READ-FILE SWAP DROP R> CLOSE-FILE OR ; --> \ Overlay - OVERLAY 001119esSYSTEM \ Save overlay to disk and discard segment memory : OVERLAY ( <filename> -- ) BL WORD COUNT R/W CREATE-FILE ABORT" can't create overlay" OBASE @ HERE OVER - ROT over >R >R \ overlay size DUP OSIZE @ MAX OSIZE ! \ update max size R@ WRITE-FILE ABORT" can't write overlay" R> CLOSE-FILE ABORT" can't close overlay" R> NEGATE ALLOT ; \ discard memory APPLICATION \ Overlay - Demo 001119esAPPLICATION \ MUST be located in application space HERE OBASE ! \ overlay start address 0 OSIZE ! \ initial size : WORD1 ( -- ) CR ." This is WORD1 from SAMPLE1.OVL" ; OVERLAY SAMPLE1.OVL : WORD2 ( -- ) CR ." This is WORD2 from SAMPLE2.OVL" ; OVERLAY SAMPLE2.OVL : WORD3 ( -- ) CR ." This is WORD3 from SAMPLE3.OVL" ; OVERLAY SAMPLE3.OVL OSIZE @ ALLOT \ reserve memory for overlays --> \ Overlay - Demo 001119es\ Display file error msg and abort : FILE-ERROR ( c-addr u -- ) CR TYPE FILE COUNT TYPE ABORT ; \ Load overlay, handle any errors : OLOAD ( c-addr u -- ) LOAD-OVERLAY IF S" Error loading overlay: " FILE-ERROR THEN ; \ Create loader for each overlay : OVERLAY1 ( -- ) S" SAMPLE1.OVL" OLOAD ; : OVERLAY2 ( -- ) S" SAMPLE2.OVL" OLOAD ; : OVERLAY3 ( -- ) S" SAMPLE3.OVL" OLOAD ; \ Test the overlays : TEST ( -- ) OVERLAY1 WORD1 OVERLAY2 WORD2 OVERLAY3 WORD3 ;