Download Forth 7 Cross Compiler - MicroProcessor Engineering Ltd.
Transcript
Chapter 8: Generic I/O 41 8 Generic I/O 8.1 About Generic I/O Generic I/O allows the Forth words KEY, KEY?, EMIT, TYPE and CR to use any I/O device. The user variables IPVEC and OPVEC each contain the address of a structure for a device. This structure contains a list of Forth words used for the words above. By using different devices for input and output, input can be from a serial channel and output can be to an LCD screen. The selection can be changed at any time by the application. Because IPVEC and OPVEC are USER variables, i.e. are specific to each task, different tasks may have different I/O devices. The generic I/O structure consists of any array of five (six for Harvard targets) XTs. The XTs are for the words that perform the following basic functions. cell cell cell cell cell cell KEY action KEY? Action EMIT action TYPE action CR action TYPEC action; Harvard CPUs (e.g. 8051) only The CR and TYPE actions are provided to ease implementations of devices such as LCD output in which CR does not naturally correspond to 13 EMIT 10 EMIT, and for which TYPE will be much faster than repeated EMITs. The output functions update the USER variable OUT before calling the action. 8.2 Creating a new device cdata \ this table goes in CODE space create SerConsole \ -- addr ; OUT managed by upper driver ’ (serkey) , \ -- char ; schedule, receive char ’ (serkey?) , \ -- flag ; check receive char ’ (seremit) , \ -- char ; display char ’ (sertype) , \ caddr len -- ; display string ’ (sercr) , \ -- ; display new line ’ (sertypec) , \ caddr len -- ; display CDATA \ for Harvard targets only Generic I/O handles all use of OUT for the output functions. OUT is manipulated before the action is performed so that special cases can update OUT themselves. When the multi-tasker is used, a multi-tasking version of (SERKEY) must be used. Conditional compilation can be used in the primitive words. The equate Tasking? is set non-zero when multi-tasking is in use.