TweetFollow Us on Twitter

Serial I/O
Volume Number:5
Issue Number:7
Column Tag:Assembly Lab

Related Info: Serial Drivers

Cerial (Serial) I/O

By Frank Henriquez, Los Angeles, CA

Programming The Serial Ports

The Macintosh serial ports are a neglected programming subject. Few (if any) books on programming cover them, and this lack of information is compounded by an absence of source code to study.

The simplest way of programming the serial ports is to use a high level language and fool the compiler into thinking that the ports are disk files. Then you can use the language’s generic file I/O routines for serial I/O. While this solution provides a simple way of dealing with the serial ports, it may not provide the speed or flexibility that may be required in certain applications.

I thought that a better approach would be to write a set of low level routines that can be linked with compiler generated code, or with assembly language. How difficult could this be? All I’d need was the hardware manual for the Mac’s serial port chip, a copy of Inside Macintosh, a steady source of caffeine and a few hours of coding...right?

I quickly discovered that the task of writing drivers for the Mac is serious business. Life is too short for the hassles involved in trying to write a driver for the the complex (and bizarre) serial port chip, a Zilog 8530 SCC. Besides, it’s already been done; Kirk Austin’s excellent articles “A Midi Library for Pascal” and “Midi Demo Uses Midi Library” in the July, 1987 and December, 1987 issues of MacTutor show how to write drivers for this chip, if you’re interested in working close to the bare metal of the machine.

How I Learned To Stop Complaining And Love The Device Manager or “Gee, I didn’t realize it would be this easy”

Midi has certain timing and handshaking constraints that demand specialized serial drivers. I needed something a lot simpler; a set of routines that could send and receive data, at baud rates that would probably never exceed 19200 kilobaud. There had to be a way of doing this that didn’t involve writing a complex driver. As often happens when programming the Macintosh, a solution became obvious only after re-reading several chapters of Inside Macintosh (or to put it another way: “when all else fails, read the manual”). While the Serial Drivers chapter would seem like the obvious place to look for information on using the serial ports, the Device Manager chapter is far more important; the Macintosh treats the serial ports as devices, so accessing the drivers requires using the Device Manager I/O routines.

The Device Manager can be divided into Pascal based file I/O routines, and low level traps. The high level Pascal routines (they can also be called from C. But you already knew that) have an extremely simple calling sequence, and insulate the programmer from the inner workings of the Device Manager. However, since these routines are not in the ROMs, the glue routines have to be linked with any assembly language program that uses them.

The low level Device Manager traps require more work to use, but they provide greater control over the I/O. I could have used the high level routines in my program, but since I had to use a low level Device Manager trap to configure the serial port, I decided to write everything using the other low level traps; the code is smaller and probably a bit faster.

The serial ports have been assigned four driver reference numbers, which are used by the Device Manager to identify the device it is working with:

Modem port input ( port A ) -6

Modem port output ( port A ) -7

Printer port input ( port B ) -8

Printer port output ( port B ) -9

I’ve used these reference numbers directly in the code, instead of using the reference numbers returned by the _Open trap (the numbers should be the same). It simplifies the coding, at the risk of making the routines non-functional if and when Apple decides to change the reference numbers.

The Device Manager traps use a block of memory (pointed at by register A0) called a parameter block. It holds the pointers, commands and flags that may be required by the Device Manager trap being called. Depending on the call, it may also contain information returned from a device. A generic parameter block can be up to 80 bytes long, but when calling the serial ports most of the parameter block entries can be ignored. This still means that my routines have to set up and maintain a parameter block each time they are called. At first, even this small overhead in execution time and memory requirements made me uncomfortable; however this is an acceptable compromise considering the amount of code required to write a low level serial driver.

In retrospect, using the Device Manager to control the serial ports turned out to be an easy task, although I spent more time than I’m willing to admit learning how to write these serial I/O routines. In the process, I discovered that Apple provides serial port drivers in a resource called SERD (built into the ROMs of the more recent Macs). At the time I wrote my routines, SERD was not in ROM and its use was (and still is) poorly documented. It was also more code than I had expected, so I went ahead with my routines.

One of my first attempts at using the Device Manager was a simple terminal program written in Turbo Pascal. It worked, but I decided to re-write it in assembly because (I know many of you will cringe) I enjoy writing in assembly language! I realize that it’s an acquired taste and that most of you would prefer to keep your contacts with assembly language to a minimum, so these routines have been written to make them accessible from Pascal. The routines will also work with C, but you may have to modify them to match the C parameter passing protocol. I’ve also written a small terminal program that shows the routines in use. The bulk of the program consists of code to use TextEdit, manipulate the clipboard and code to do the usual housekeeping routines. You’ll almost need a magnifying glass to find the calls to the serial routines!

Serial I/O Routines

The serial I/O routines make extensive use of the stack, for parameter passing and for holding the parameter block required by the Device Manager routines they’ll be calling.

Parameter blocks are common structures, and can be found in most Macintosh I/O routines. In assembly language, we can define a parameter block as a buffer in the global variable space, or we can use the approach used by many high level language compilers and define the parameter block as a temporary structure on the stack. On entry, each routine sets aside a small section of the stack, known as a stack frame, and points to it with register A6. This private section of memory is then set aside as a parameter block.

Making the parameter block a temporary structure on the stack saves us from having to declare it as part of the global variable space; the local stack frame and all its contents are discarded when the routine terminates. Using this technique increases the complexity of the routines, but their portability and ease of use far outweighs the minor increase in execution time and code size.

Before we use a serial port, its driver must be open and the port must be configured. OpenSerial opens the specified serial port driver (either the modem or the printer port) and kills any pending I/O operations to it. The routine uses the driver’s input reference number (-6 for the modem port and -8 for the printer port) to open both the input and output sections, and expects to find the appropriate number on the stack. Figure 1 shows the local stack for the OpenSerial routine.

OpenSerial starts by setting up the stack frame and allocating the space for the parameter block. It then makes register A0 point to the parameter block, as expected by the Device Manager. OpenSerial uses the Device Manager _Open trap which at most has only three entries in it’s parameter block. Since none of these serial I/O routines are making asynchronous calls to the Device Manager, OpenSerial can ignore the ioCompletion pointer. It can also ignore the ioPermssn byte, leaving only ioNamePtr, which is filled after OpenSerial checks which port is to be opened. Since both the input and output sides of a port must be opened, OpenSerial calls the Device Manager _Open trap twice. Once this is done, the routine saves the result code (returned in the parameter block at ioResult) on the return stack and calls the Device Manager one more time, to kill any pending I/O operations to the port. Since the parameter block remains unchanged, OpenSerial can call the _KillIO trap directly. Before returning to the calling program, OpenSerial discards the local stack (and the parameter block) and clears the port number from the return stack, leaving only the result word.

The code segment below shows the calling sequence for OpenSerial (PortA refers to the modem port driver and was set to -6 by an equate statement somewhere else in the program).


clr.w   -(sp)  ; room for result
move.w  #PortA,-(sp) ; modem port
tst.w   (sp); leave result on stack

Since OpenSerial is usually followed by the configuration routine, I leave the result code on the stack (it will be zero if the port opened successfully) and use it to mark the space for the the next routine’s result code. Config resets the serial port and sets it to the new baud rate, data bits, stop bits and parity desired. Config doesn’t modify some of the other important serial port parameters (mainly handshaking) since the default parameters suited my needs. Like OpenSerial, Config expects to see the port’s input driver reference number on the stack. It also expects to see a configuration word, which represents the baud rate, data bits, stop bits and parity being set. Figure 2 shows the local stack for Config and the code section below shows its calling sequence.


move.w  #PortA,-(sp) ; modem port
move.w  #Config1200,-(sp)
tst.w   (sp); leave result on stack

Config uses the Device Manager _Control trap, which requires a few more parameters than OpenSerial. Two parameters, ioCompletion and ioVRefNum (serial ports don’t have volume names) can be ignored, but it must set the ioRefNum to that of the port being configured. Config uses the csCode parameter to tell the Device Manager to reset the port. The new configuration value is passed in csParam.

For some applications, opening and configuring the serial port is all you need to do to initialize it for use. Unfortunately, the default size of input driver’s buffer (set by the Device Manager) is a tiny 64 bytes, and this small buffer can become a major problem.

We all know that TextEdit is no speed demon. If you’re writing a communications program and use TextEdit to display the incoming text, characters may be received by the port faster than TextEdit can display them. The 64 byte serial input buffer will quickly overflow and you will lose some characters. Luckily, this input buffer can be resized using SetBuf. This routine, like OpenSerial and Config, requires a reference number for the port’s input driver. It also requires a long word that represents the buffer’s new size.

SetBuf, like all the other routines, starts by setting aside some room for the parameter block. It will then request a nonrelocatable block from the Memory Manager to serve as the new input buffer. If SetBuf succeeds in getting the new block, it tells the input driver to use this buffer through the Device Manager _Control trap. Figure 3 shows the local stack for SetBuf.


move.w  #PortA,-(sp) ; modem port
move.l  #512,-(sp) ; 512 byte buffer
move.w  (sp)+,d0 ; take result off stack

In this example, the input buffer is made 512 bytes long. Since SetBuf is usually the last step in initializing a serial port, the result word that was floating on the stack from the previous two routines (OpenSerial and Config) finally gets popped off. As we’ve come to expect, if SetBuf has a problem allocating the memory for the buffer, this word will be non-zero.

It’s important to set the input buffer back to the default value before terminating your program (the programmer’s motto should be “always leave things the way you found them”). This can be done with SetBuf by passing a value of 0 as the size of the buffer. The Device Manager will then set the input buffer back to its default value.

Once the serial port has been opened and initialized and the size of the serial input buffer has been increased, your program is ready to send and receive data through the port.

The input routine GetSerial takes two parameters, the port number and a pointer to the buffer that will hold the incoming data (note that this isn’t the same as the input driver buffer). GetSerial first checks to see if there are any characters waiting to be read by calling SerGetBuf, which is a special version of the Device Manager _Status trap. This Device Manager call returns a long word containing the number of characters in the driver’s input buffer. If the input buffer is empty, GetSerial will leave this zero count on the stack and end. If there are characters available (and if you use TextEdit, there will be quite a few backed up), GetSerial reads them into the new buffer using the Device Manager _Read trap. GetSerial then leaves the character count on the stack and ends. Figure 4 shows the local stack for GetSerial. Here’s an example from the terminal program:


clr.l -(sp) ; room for char count
move.w  #PortA,-(sp) ; use the modem port
peaIOBuf(a5); put data here
move.l  (sp)+,CharCnt(a5)  ; save count

PutSerial simply shoves data out the port, letting the Device Manager worry about errors (like overflowing the output buffer). Since we are calling PutSerial synchronously, this is not a serious shortcoming and PutSerial will work well, without problems.

PutSerial takes three parameters, the port number, a pointer to the buffer holding the data to be sent and the number of characters to be sent. Even though PutSerial ignores errors, it returns a “no errors” result value to the calling program; this is to keep it consistent with the other routines and to make room for a real error value if a future version of the routine does check for errors. The calling sequence is pretty simple:


clr.w   #0,-(sp) ; room for dummy 
move.w  #PortA,-(sp) ; modem port
peaIOBuf(a5); send data in buffer
peaCharCnt(a5) ; this many
move.w  (sp)+,d0 ; pop dummy 

These serial I/O routines are lacking in a few features (mainly better and more complete error checking) but since the interface to the calling program (be it a high level language or assembly) is consistent, these routines can be used as the basis for more complete routines, or used as-is, without any major changes to the calling program.

Using the Serial I/O Routines in the Real World: An Example

The easiest way to learn how to use the serial I/O routines is with an example. Term is an extremely simple terminal program; it sends characters typed at the keyboard out the modem port and uses TextEdit to display the incoming characters. Besides the standard File and Edit menus, Term has a Command menu with an Erase Screen item and four (300, 1200, 2400 and 9600) baud settings. It also uses the clipboard, so you can cut and paste text to and from its window. While the text that is pasted to the terminal window is displayed, it is not sent out the port (as my old calculus book would say “the solution to this problem is left to the reader”). The main window in Term is moveable, but not resizable. This is a minor annoyance, which can be easily fixed.

Term will run on almost any Macintosh (it doesn’t run on Macs with the old 64K ROMs) and is structured to serve as the skeleton of a more complex communications program. To maximize speed and reduce the need for global variable storage, most assembly language programmers store frequently used handles and pointers in unused CPU registers. Since I don’t know what you plan to do with Term, I’ve tried to minimize the use of registers for handle storage. Most of the menu and window handles are kept as global variables.

Macintosh applications often share the same basic structure and even some of the initialization and event parsing routines. Term is no exception. It is a quilt of routines that have been borrowed from other applications. Term begins by initializing the modem port and going through the usual ritual of setting up things and initializing managers. It finishes the initialization by copying the contents of the clipboard to the TextEdit scrap. Term ends when a non-zero value is passed to the event loop, either when the user selects Quit from the menu or clicks in the program window’s close box. Term then cleans up, resets the input buffer back to its default size and returns to the Finder.

Since Macintosh programs spend most of their time in the event loop, this is the best place for Term to check the modem port and display any new characters that may have been received. You may notice that the EventRecord is declared and used as a global variable. It used to be a common practice to declare the EventRecord as a constant; this saved a few keystrokes when typing in the program. The practice did not cause problems when the program was running because the 68000 doesn’t make any distinctions between the memory used for variable storage and that used for constants and code. With the 68020, 68030 and future CPUs, memory management becomes part of the computer hardware. With an MMU, an operating system could set aside memory to be used as storage for a program’s code and constants... and declare this memory to be read only. Imagine the surprise of a program trying to write to a write-protected EventRecord!

Term Routines

Instead of a detailed description of every routine in Term, I’ll focus on the routines that make it different.

PutScreen filters the characters in the input buffer, IOBuf, and transfers the displayable characters to Outbuf, the output buffer. The variable CharCnt is used to tell TextEdit how many characters are in the output buffer.

A communications program must be able to display characters on the screen quickly, especially at the higher baud rates, when data may be flooding in through the serial port. On the Macintosh, the quickest way to get a character on the screen is to use QuickDraw’s DrawChar function, and this is what I used in the early versions of Term. Unfortunately, DrawChar does little else besides drawing a character on the screen. All text manipulations (simple things like backspace and carriage return) must be handled with a stupendous amount of code. I knew that TextEdit could handle some of these simple functions, and TextEdit had the extra bonus of making it easy to cut and paste the text to the clipboard and back. Unfortunately, TextEdit is extremely slow. My initial attempts to use TextEdit were a miserable failure; I was losing most of the incoming data. The solution, of course, was to increase the size of the serial input buffer.

While TextEdit is an improvement over DrawChar, it will only recognize a limited number of control characters, so PutScreen must deal with any control characters it finds in IOBuf. In this version of PutScreen, only the carriage return (CR), Bell, Tab and backspace (BS) characters are recognized; all other control characters are discarded. By replacing the simple compare and branch code with a lookup table, PutScreen could be made to emulate a real terminal, like the VT-52 or VT-100.

PutScreen lets TextEdit handle carriage returns. To backspace, PutScreen decrements the output buffer pointer by one (to erase the previous character) and decrements the character count by two (to account for the deleted character and the backspace character). If the character count is zero, then no characters have to be displayed, and PutScreen passes control to the NextEvent routine. If CharCnt is greater than zero, there are still characters to be processed, and PutScreen goes on to the next character in IOBuf. If the CharCnt is less than zero, we are no longer dealing with “fresh” characters and must delete a character that has already been displayed. To do this, PutScreen passes the BS character directly to the _TEKey trap, which deletes the last character displayed. It then passes control to the NextEvent loop.

If the control character is a Bell (control G) PutScreen will generate a short beep, decrement the character count, and continue with the filtering.

Tabs are hard coded for five spaces. PutScreen places five spaces in the output buffer and increments the character count by four (we don’t want the tab character itself to be displayed) before continuing with the filtering.

Displayable characters are transferred from the IOBuf to the OutBuf, and the filtering continues until all the characters have been dealt with. PutScreen then uses _TEInsert to pass the OutBuf to TextEdit, which displays it. PutScreen also calls _TESelView, to scroll the window, if needed.

KeyDown takes characters typed at the keyboard and saves them in IOBuf. If the command key is pressed, it converts the character to a control character, and inserts it into the IOBuf. KeyDown then sends the character out the modem port.

InBaud is used to change the baud rate. This routine unchecks the previous menu item, checks the new one and sets the new baud rate, using the Config routine.

Possible Enhancements

Like most programs, Term has room for improvements. The easiest additions would be to make the window resizable and make the program MultiFinder friendly.

Term will operate at 19,200 baud; I was just too lazy to add it as a menu option. A menu option to change the default port might be useful, but dangerous. Since the printer port is used with networks and printers, the routine to switch ports must check to see if AppleTalk is active or if the printer port is being used by another program.

A slightly more difficult task would be to have Term send text pasted in it’s window, from the Clipboard, out the serial port. Another TextEdit related problem is a cosmetic one; I implemented a screen erase function in Term by clearing out the all the data in the TextEdit record. It works, but it makes the screen flash like an IBM PC screen...somewhat disconcerting.

A final improvement would be to add a file transferring capability, using the MacBinary extension to the XMODEM protocol. This wouldn’t be as difficult as it sounds; both the MacBinary and XMODEM protocols are well described. It would be a good idea to increase the input serial buffer to at least 1280 bytes, room enough to fit a 1K XMODEM block. This would speed up the data rates by allowing the program to work on one block of data while another block is being received in the background.

Borrowed Routines

A few of the routines and techniques that I used in Term were borrowed from other programs.

The code to deal with the clipboard is a slightly modified version of the code in the Clipboard chapter in Dan Weston’s “The Complete Book of Macintosh Assembly Language Programming, Volume II.” Some of the ideas on how to handle TextEdit came from Dan’s “The Complete Book of Macintosh Assembly Language Programming, Volume I.” It should be pretty obvious that these are two very useful (if somewhat dated) books on Macintosh assembly language programming.

Victor Barger’s Rose Curve Generator program is an excellent example of good code layout and presentation. I’ve tried to make Term as easy to read.


Dan Weston, “The Complete Book of Macintosh Assembly Language Programming” Volumes I and II.

Victor Barger, “Rose Curve Generator,” MacTutor, January 1987

Apple Computer, “Inside Macintosh” volumes I - V (mainly volumes I and II)

Apple Computer, Technical Note 130, ioCompletion

Kirk Austin, “A MIDI Library for Pascal,” MacTutor, July 1987

Kirk Austin, “MIDI Demo uses MIDI Library,” MacTutor, December 1987

Listing: term.job

asmterm.asm exec edit
link  execedit
rmaker  term.r termedit
/Output term.code

/Type ‘TEMP’ ‘????’


;All done
Listing:  SerI/O.asm

; File: SerI/O.asm
; SerI/O.asm consists of following stand-alone serial I/O routines:
; FunctionOpenSerial(Port: integer): OSErr
; FunctionConfig(Port, SerVal: integer): OSErr
; FunctionGetSerial(Port: integer; buffer: pointer): CharCnt
; FunctionPutSerial(Port: integer; CharBuf: pointer; count: longint): 
; FunctionSetBuf(Port: integer; BufSiz: long): OSErr
; Port refers to port reference number, which is -6 for modem 
; input port (port A) or -8 for printer input port  (port B)
; For description of how to write modular assembly language
; routines see Weston’s “Complete Book of Macintosh Assembly
; Language Programming Volume I”, Appendix D
;  1/14/88Working version of the routines
; written by Frank Henriquez
; Register usage:
; d0: general purpose. 
; d1, d2, d3, d4, d5, d6, d7 : not used.
; a0: general purpose, used for buffers and parameter blocks.
; a1: general purpose.
; a2, a3, a4: not used.
; a6: used as the local stack frame pointer
; a5, a7 : system use. 

Include Traps.D
Include SysEqu.D

 XDEF OpenSerial
 XDEF Config
 XDEF GetSerial
 XDEF PutSerial
 XDEF SetBuf 

; equates for each stack frame

pBlock  equ -ioQelSize

OpenPar equ  2   ; OpenSerial - # of parameter words on stack
OpenRes equ 10   ; OpenSerial - offset to result word
OpenPortequ  8   ; OpenSerial - offset to Port Reference #

ConfPar equ  4   ; Config - # of parameter words on stack
ConfRes equ 12   ; Config - offset to result word
ConfPortequ 10   ; Config - offset to port Reference #
ConfVal equ  8   ; Config - offset to port config value

GetPar  equ  6   ; you’ve probably figured the pattern
GetCnt  equ 14   ; offset to character count
GetPort equ 12   ; out by now...
GetBuf  equ  8   ; offset to character buffer pointer

PutPar  equ 10
PutPort equ 16
PutBuf  equ 12   ; offset to character buffer pointer
PutCnt  equ  8   ; offset to character count pointer
PutRes  equ 18   ; dummy result 

SetPar  equ  6
SetRes  equ 14   ; offset to SetBuf result word
SetPort equ 12
SetSiz  equ  8   ; offset to new buffer size

; misc. equates

SerResetequ  8   ; from Inside Macintosh
SerSetBuf equ   9; from Inside Macintosh
ioNamePtr equ  18; missing from MDS

;-------------- OpenSerial ------------------
; Opens the modem port for reads and writes.
; FunctionOpenSerial(Port: integer): OSErr

 link a6,#pBlock ; local space for parameter block
 lea  pBlock(a6),a0; point to parameter block
 lea  ‘.AIn’,a1  ; assume port A input
 cmpi.w #-6,OpenPort(a6)  ; open port B if not -6 (port A)
 beq.s  @1
 lea  ‘.Bin’,a1  ; open port B input
@1 bsr.sOpenit
 lea  ‘.AOut’,a1 ; assume port A output
 cmpi.w #-6,OpenPort(a6)
 beq.s  @2
 lea  ‘.Bout’,a1 ; open port B output
@2 bsr.sOpenit

OExit move.wd0,OpenRes(a6); procedure returns a 0 if no errors
 _KillIO; kill any pending calls
 unlk a6; discard local stack area
 move.l (sp)+,a0 ; get return address
 addq.l #OpenPar,sp; clean up stack
 jmp  (a0); end of InitSerial

 move.l a1,ioNamePtr(a0)  ; tell the Device Manager which
 _Open  ; port to open

;---------- Configure ports --------------
; Sets the Port to the baud rate, data length,
; parity, stops, etc. held in SerVal.
; FunctionConfig(Port, SerVal : integer) : OSErr

 link a6,#pBlock ; local space for parameter block
 lea  pBlock(a6),a0; point to parameter block
 move.w ConfPort(a6),d0   ; get Input Reference number
 bsr.s  doConf   ; configure the input side
 tst.w  d0; check for errors and
 bne.s  CExit    ; exit with the error flag in d0
 move.w ConfPort(a6),d0   ; get Input Ref number
 subq.w #1,d0    ; and make it the output ref num
 bsr.s  doConf   ; configure the output side

CExit move.wd0,ConfRes(a6); save result
 unlk a6
 move.l (sp)+,a0
 addq.l #ConfPar,sp; and clean up the stack
 jmp  (a0); end of Configure

doConf  move.w d0,ioRefNum(a0); port #
 move.w #SerReset,csCode(a0); reset port to
 move.w ConfVal(a6),csParam(a0)  ; these new settings

;---------------- SetBuf ------------------
; increases the size of the Port input buffer
; Function SetBuf(Port:Integer; BufSiz:long):OSErr

SetBuf  linka6,#pBlock    ; local space for parameter block
 move.l SetSiz(a6),d0
 beq.s  @1; if size = 0, reset input buffer
 _NewPtr; get a nonrelocatable block
 tst.l  d0; abort if couldn’t get it
 bne  Exit
 move.l a0,a1    ; save block ptr in a1
 move.l SetSiz(a6),d0; reload the buffer size
@1 lea  pBlock(a6),a0; point to parameter block
 move.w SetPort(a6),ioRefNum(a0)
 move.w #SerSetBuf,csCode(a0)
 move.l a1,csParam(a0)    ; pointer to new buffer
 move.w d0,csParam+4(a0)
Exit  move.wd0,SetRes(a6)
 unlk a6; standard exit routine
 move.l (sp)+,a0
 addq.l #SetPar,sp
 jmp  (a0); end of SetBuf

;-------------- GetSerial ----------------
; GetSerial checks the Port to see if any
; characters have been received, and proceeds
; to read them into the input buffer.
; If none have been received, GetSerial returns
; a 0 in the character count variable.
; FunctionGetSerial(Port:integer; buffer:pointer) : CharCnt: long

 link a6,#pBlock
 lea  pBlock(a6),a0
 move.w GetPort(a6),ioRefNum(a0)
 move.w #2,csCode(a0); call SerGetBuf
 move.l csParam(a0),d0    ; get # of characters received
 move.l d0,GetCnt(a6)
 beq.s  @2; if none, then leave, if there are
 ; characters available, read them.
@1 move.w GetPort(a6),ioRefNum(a0)
 move.l GetBuf(a6),ioBuffer(a0)  ; the input buffer
 move.l d0,ioReqCount(a0) ; read the characters
@2 unlk a6; standard exit routine
 move.l (sp)+,a0
 addq.l #GetPar,sp ; leave char count on stack
 jmp  (a0); end of GetSerial

;-------------- PutSerial ----------------
; PutSerial sends the characters in the buffer
; out the Port. This routine is pretty
; primitive - it ignores any pending writes
; and errors, works. It returns a dummy result.
; functionPutSerial(Port:integer; CharBuf:pointer; count: pointer): OSErr

 link a6,#pBlock ; local space for parameter block
 lea  pBlock(a6),a0; point to parameter block
 move.w PutPort(a6),d0    ; get the port ref #
 subq.w #1,d0    ; make it the port output ref num
 move.w d0,ioRefNum(a0)   ; modem output port
 move.l PutBuf(a6),ioBuffer(a0)  ; point to buffer
 move.l PutCnt(a6),a1; get pointer to char count
 move.l (a1),ioReqCount(a0) ; and put char count here
 move.w #0,PutRes(a6); save a 0 as a dummy result
 unlk a6; standard exit routine
 move.l (sp)+,a0
 adda.l #PutPar,sp
 jmp  (a0); end of PutSerial
Listing:  term.asm

; File: Term.asm
; Term.asm is simple terminal program, shows how to use low
; level serial I/O routines.
; written by Frank Henriquez
; code that handles transfers between clipboard and Text Edit
; is based on the code in chapter 3 of Dan Weston’s “Complete
;  Book of Macintosh Assembly Language Programming Vol. II”

; Some coding ideas were borrowed from the program “Rose.Asm”
; by Victor Barger, appeared in Jan. 1987 issue of MacTutor.
;  7/15/87Initial Turbo Pascal version, using Quickdraw.
;   9/1/87assembly language translation.
; 10/10/87modified to use TextEdit.
; 10/18/87fully functional version.
; 10/20/87text handling improved, Baud rates added.
;  1/14/88modified to use external serial I/O routines.
; Register usage:
; d0: general purpose, also holds the menu#.
; d1: general purpose, also menu item# and the Modify value.
; d2: general purpose.
; d3, d4, d5, d6, d7 : not used.

; a0: general purpose, used for buffers and parameter blocks.
; a1: general purpose.
; a2: holds TextEdit handle.
; a3: general purpose.
; a4, a6 : not used.
; a5, a7 : system use.
; pre-compiled routines from Serial I/O.asm

 XDEF OpenSerial
 XDEF Config
 XDEF GetSerial
 XDEF PutSerial
 XDEF SetBuf

; Standard include files

Include Traps.D
Include Toolequ.D
Include Sysequ.D
Include Quickequ.D

;---------- Program constants ------------

AppleMenu equ  1 ; Apple
AboutItem equ  1 ; First item in Apple menu

FileMenuequ 2    ; File
QuitItem  equ  1 ; First item in File menu

EditMenuequ 3    ; Edit
UndoItemequ 1    ; Items in Edit menu
CutItem equ 3
CopyItemequ 4
PasteItem equ  5
ClearItem equ  6

CmdMenu equ 4    ; Command menu
EraseItem equ  1 ; Erase screen

B300    equ 3    ;  300 baud
B1200   equ 4    ; 1200 baud
B2400   equ 5    ; 2400 baud
B9600   equ 6

AboutDialog equ  1 ; About dialog
ButtonItemequ  1 ; First item in DITL

WindID  equ 1

PortA   equ -6
PortB   equ -8

baud300 equ 380
baud1200equ 94
baud2400equ 46
baud9600equ 10
stop10  equ 16384
noParityequ 8192
data8   equ 3072

Config300 equ  baud300  + data8 + stop10 + noParity
Config1200equ  baud1200 + data8 + stop10 + noParity
Config2400equ  baud2400 + data8 + stop10 + noParity
Config9600equ  baud9600 + data8 + stop10 + noParity

;---------- Program starts here ------------

 bsr.s  InitSerial
 bsr  InitManagers
 bsr  SetupMenu
 bsr  SetupWindow
 bsr  SetupTextEdit
 bsr  CliptoTE

 _SystemTask; check for DA calls
 move.l a2,-(sp) ; get handle to text record
 _TEIdle; blink cursor etc.
 bsr  GetSerCh   ; get a character from the modem port
 bsr  PutScreen  ; and put it on the screen
 clr.w  -(sp)
 move.w #$0fff,-(sp) ; look for all events
 pea  EventRecord(a5)
 _GetNextEvent   ; get the next event (WaitNextEvent!?)
 move.w (sp)+,d0
 beq.s  EventLoop; loop until an event
 bsr  HandleEvent; take care of the event
 beq.s  EventLoop; time to quit if not zero
 move.l a2,-(sp)
 clr.w  -(sp)
 move.w #PortA,-(sp) ; modem port
 clr.l  -(sp)    ; reset default serial buffer
 jsr  SetBuf
 addq.l #2,sp

;-------------- InitSerial ------------------
; Open serial port for reads and writes, set
; the baud rate to 1200 baud and increase the
; size of the serial input buffer to 512 bytes

 clr.w  -(sp)    ; room for routine results
 move.w #PortA,-(sp) ; open the modem port (Port A)
 jsr  OpenSerial
 tst.w  (sp); if Open failed, beep and quit.
 bne.s  Abort
 move.w #PortA,-(sp)
 move.w #Config1200,-(sp) ; set modem port to 1200 baud
 jsr  Config
 tst.w  (sp); if Config failed, beep and quit.
 bne.s  Abort
 move.w #PortA,-(sp) ; make the serial input buffer
 move.l #512,-(sp) ; 512 bytes big. Prevents data loss.
 jsr  SetBuf
 move.w (sp)+,d0 ; clean up the stack, and abort if
 bne.s  Abort    ; SetBuf failed.

;-------------- Abort --------------------

 move.w #30,-(sp)
 _ExitToShell    ; jump back to Finder

;------------ InitManagers ----------------

 _MoreMasters    ; prevents heap fragmentation
 move.l #$ffffffff,d0
 _NewHandle ; compact heap
 pea  -4(a5); QuickDraw globals
 move.l #$0000ffff,d0; flush all events
 clr.l  -(sp)    ; no restart procedure

;------------ SetupMenu ------------------

;Apple menu:
 clr.l  -(sp)
 move.w #AppleMenu, -(sp)
 _GetRMenu; get Apple menu from the rsrc file
 move.l (sp),AppleMHdl(a5)  ; save handle to menu
 move.l (sp),-(sp)
 clr  -(sp)
 move.l #’DRVR’,-(sp)
 _AddResMenu; add DA’s to Apple menu

;File menu:
 clr.l  -(sp)
 move.w #FileMenu,-(sp)
 move.l (sp),FileMHdl(a5) ; save handle to menu
 clr  -(sp)

;Edit menu:
 clr.l  -(sp)
 move.w #EditMenu,-(sp)
 move.l (sp),EditMHdl(a5) ; save handle to menu
 clr  -(sp)

;Command menu:
 clr.l  -(sp)
 move.w #CmdMenu,-(sp)
 move.l (sp),CmdMHdl(a5)  ; save handle to menu
 clr  -(sp)
 move.l CmdMHdl(a5),-(sp) ; put handle on stack
 move.w #B1200,d0
 move.w d0,BaudChk(a5)
 move.w d0,-(sp)
 move.w #-1,-(sp); next to the 1200 baud item

;------------ SetupWindow ----------------

 clr.l  -(sp)
 move.w #WindID,-(sp)
 pea  WindowStorage(a5)
 move.l #-1,-(sp); make it the top window
 _GetNewWindow   ; load it from the rsrc file
 move.l (sp),WindowHdl(a5); save handle
 _SetPort ; make it the current port
 move.w #monaco,-(sp); Monaco
 move.w #9,-(sp) ; in 9 pt.

;----------  SetupTextEdit ----------------

 clr.l  -(sp)    ; space for text handle
 pea  DestRect   ; DestRect Rectangle
 pea  ViewRect   ; ViewRect Rectangle
 move.l (sp)+,a0 ; save text handle
 move.l a0,a2    ; in a2
 move.l (a0),a0
 move.b #-1,teCROnly(a0)
 move.w #-1,-(sp)
 move.l a2,-(sp) ; enable TE auto scroll (128K ROM)

;---------------- CliptoTE --------------
; CliptoTE copies text in the clipboard to the TE scrap

 move.l #0,a3    ; check for TEXT in the desk scrap
 bsr.s  @1
 bmi.s  @2; leave if none

 move.l #0,d0    ; lets get the scrap, but first
 _NewHandle ; get a handle for it
 move.l a0,a3
 bsr.s  @1
 move.l TEScrpHandle,a0   ; replace old handle to TEScrap
 move.l a3,TEScrpHandle   ; with ours
 move.l TEScrpHandle,a0
 _GetHandleSize  ; get length of our scrap
 move.w d0,TEScrpLength
@2 rts  ; leave  CliptoTE

@1 clr.l-(sp)    ; space for result
 move.l a3,-(sp)
 move.l #’TEXT’,-(sp); just check for TEXT
 pea  GSOffset(a5)
 move.l (sp)+,d0 ; return result

;-------------- GetSerCh ----------------

 clr.l  -(sp)    ; room for character count
 move.w #PortA,-(sp) ; if modem port has data, save it
 pea  IOBuf(a5)  ; in this buffer.
  jsr GetSerial
 move.l (sp)+,CharCnt(a5) ; get # of characters received.
 bra  NextEvent

;-------------- PutScreen ----------------
; PutScreen will display the characters in
; the buffer, taking care of some control
; characters. It uses TextEdit for display.

 move.l CharCnt(a5),d1    ; skip if no characters in buffer
 beq  NextEvent
 subq.l #1,d1    ; adjust character count for loop
PutTE lea IOBuf(a5),a0    ; point to the character buffers
 lea  Outbuf(a5),a1
TELoop  move.b (a0)+,d0   ; get a char from the input buffer
 andi.w #$7f,d0  ; clear out 8th bit
 cmpi.w #$20,d0  ; if less than space, then it
 blt.s  CtrlCh   ; must be a Ctrl character
inBuf move.bd0,(a1)+ ; printable character
inLoop  dbrad1,TELoop
 pea  Outbuf(a5) ; print the sanitized output buffer
 move.l CharCnt(a5),-(sp)
 move.l a2,-(sp)
 move.l a2,-(sp)
 _TESelView ; scroll if needed
 bra  NextEvent  ; exit PutScreen

;---- handle control characters ----------
; Control characters are serviced here. A
; lookup table would be more efficient, in
; particular if we were to emulate a real
; terminal (like a VT-52 or VT-100).

CtrlCh  cmpi.w #$0d,d0    ; let Text Edit take care of CR
 beq.s  inBuf
 cmpi.w #8,d0    ; backspace
 beq.s  BS
 cmpi.w #7,d0    ; bell
 beq.s  Bell
 cmpi.w #9,d0    ; tab
 beq.s  Tab
 subq.l #1,CharCnt(a5)    ; ignore anything else
 bra.s  inLoop

BS subq.l #1,a1  ; move back outbuf pointer by 1
 subq.l #2,CharCnt(a5)    ; 1 for BS char, 1 for erased char
 beq  NextEvent  ; no chars to print - all done.
 bgt.s  inLoop   ; continue filtering

 move.w d0,-(sp) ; use TEKey to force backspace
 move.l a2,-(sp) ; if backed out of input buffer
 bra  NextEvent

Bell  move.w#30,-(sp); make a beep
 subq.l #1,CharCnt(a5)    ; get rid of character
 bra.s  inLoop

Tabmove.w #4,d2  ; 5 spaces for a tab
@1 move.b #$20,(a1)+ ; put them into the output buffer
 dbra d2,@1
 addq.l #4,CharCnt(a5)    ; adjust the character count
 bra.s  inLoop   ; ( # spaces, -1 for the tab char)

;------------ Handle Event  ------------
; This routine is the core of the program.
; The event number is used as an index into
; the EventTable. These entries cover all
; the events that could happen while the
; program is in the main loop.

 move.w Modify(a5),d1
 move.w What(a5),d0; get event number
 add.w  d0,d0    ; *2 for table index
 move.w EventTable(d0),d0 ; point to routine
 jmp  EventTable(d0) ; and jump to it


 dc.w NextEvent-EventTable;  0 (Null)
 dc.w MouseDown-EventTable;  1 mouse down
 dc.w NextEvent-EventTable;  2 mouse up      (Not used)
 dc.w KeyDown-EventTable  ;  3 key down
 dc.w NextEvent-EventTable;  4 key up              (Not used)
 dc.w KeyDown-EventTable  ;  5 auto-key
 dc.w Update-EventTable   ;  6 update
 dc.w NextEvent-EventTable;  7 disk inserted (Not used)
 dc.w Activate-EventTable ;  8 activate
 dc.w NextEvent-EventTable;  9 abort               (Not used)
 dc.w NextEvent-EventTable; 10 network             (Not used)
 dc.w NextEvent-EventTable; 11 I/O driver          (Not used)
 dc.w NextEvent-EventTable; 12 app1Evt       (Not used)
 dc.w NextEvent-EventTable; 13 app2Evt       (Not used)
 dc.w NextEvent-EventTable; 14 app3Evt       (Not used)
 dc.w NextEvent-EventTable; 15 app4Evt       (suspend/resume?)

;-------------- Mouse down ----------------

 clr.w  -(sp)    ; space for result
 move.l Point(a5),-(sp)   ; get mouse coordinates
 pea  WWindow(a5); Event Window
 move   (sp)+,d0 ; get region number
 add  d0,d0 ; *2 for index into table
 move.w WindowTable(d0),d0; point to routine offset
 jmp  WindowTable(d0); jump to routine

 dc.w NextEvent-WindowTable ; In Desk (Not used)
 dc.w InMenu-WindowTable  ; In Menu Bar
 dc.w SystemEvent-WindowTable ; In System Window
 dc.w Content-WindowTable ; In Content
 dc.w Drag-WindowTable    ; In Drag
 dc.w NextEvent-WindowTable ; In Grow (Not used)
 dc.w QuitRoutine-WindowTable ; In Go Away
 dc.w NextEvent-WindowTable ; In Zoom in box (Not used)
 dc.w NextEvent-WindowTable ; In Zoom Out box (Not used)

;---------------- in Menu ----------------
 clr.l  -(sp)    ; make room on stack
 move.l Point(a5),-(sp)   ; mouse event
 move.w (sp)+,d0 ; save menu
 move.w (sp)+,d1 ; and menu item

Choices ; called by command key too
 cmp.w  #AppleMenu,d0
 beq.s  InAppleMenu
 cmp.w  #FileMenu,d0
 beq.s  InFileMenu
 cmp.w  #EditMenu,d0
 beq.s  InEditMenu
 cmp.w  #CmdMenu,d0
 beq    InCmdMenu

 bsr  UnHiliteMenu ; unhighlight the menu bar
 bra  NextEvent

;-------------- in InAppleMenu ----------------
; In the Apple menu.  If it wasn’t About, it must have been a
; desk accessory.  If so, open the desk accessory.

 cmp.w  #AboutItem,d1; is it About?
 beq.s  About    ; if so go do About...
 move.l AppleMHdl(a5),-(sp) ; look in Apple Menu
 move.w d1,-(sp)
 pea  DeskName(a5) ; get Item Name
 clr  -(sp) ; space for opening result
 pea  DeskName(a5) ; open Desk Acc
 move.w (sp)+,d0 ; pop result


 bsr  SetOurPort
 bra.s  ChoiceReturn

;-------------- About --------------------
; Set up the About dialog box, and wait for
; the proper click or keypress.  End by
; closing the dialog box and setting the
; port to us.

 clr.l  -(sp)    ; space for dialog pointer
 move #AboutDialog,-(sp)  ; dialog rsrc #
 pea  DStorage(a5)
 move.l #-1,-(sp); dialog goes on top
 move.l (sp),-(sp) ; copy handle for Close
 _SetPort ; make dialog box the port
 move.l a2,-(sp)

 clr.l  -(sp)    ; clear space for handle
 pea  ItemHit(a5)
 _ModalDialog    ; wait for a response
 move.w ItemHit(a5),d0    ; look to see what was hit
 cmp.w  #ButtonItem,d0    ; was it OK?
 bne.s  WaitOK
 _CloseDialog    ; handle already on stack
  bra.s GoSetOurPort

;---------------- in FileMenu ----------------

 cmp.w  #QuitItem,d1 ; is it Quit?
 bne.s  ChoiceReturn ; no, go get next event
 bsr  UnHiliteMenu ; unhighlight the menu bar
 bra  RealQuit   ; go Quit

;---------------- in EditMenu ----------------
; The Edit Menu support routines transfer the
; TE scrap to the clipboard, and back. See the
; clipboard chapter in Dan Weston’s
; “Assembly Language Programming Volume II”

 bsr  SystemEdit ; Desk accessory active?
 bne.s  ChoiceReturn ; yes, SystemEdit handled it
 cmp.w  #CutItem,d1
 beq.s  Cut
 cmp.w  #CopyItem,d1
 beq.s  Copy
 cmp.w  #PasteItem,d1
 beq.s  Paste
 cmp.w  #ClearItem,d1
 beq.s  ClearIt
 bra  ChoiceReturn

 move.l a2,-(sp)
 _TECut ; Cut and copy text
 bra.s  Convert

 move.l a2,-(sp)
 _TECopy; Copy text to scap
 bra.s  Convert

 bsr  CliptoTE   ; from the clipboard
 move.l a2,-(sp)
 _TEPaste ; Paste
 bra  ChoiceReturn

 move.l a2,-(sp)
 _TEDelete; Clear without copying

 bsr.s  TEtoClip ; copy to clipboard
 bra  ChoiceReturn

;-------------- TEtoClip --------------------
; TEtoClip copies the TE scrap to the Clipboard

 move.l TEScrpHandle,a0
 _GetHandleSize  ; get length of our scrap
 move.l d0,a3    ; save length
 clr.l  -(sp)    ; space for result
 _ZeroScrap ; want to write over scrap
 move.l (sp)+,d0
 move.l TEScrpHandle,a0
 _Hlock ; lock pointer to our scrap
 clr.l  -(sp)    ; space for result
 move.l a3,-(sp)
 move.l #’TEXT’,-(sp); just check for TEXT
 move.l TEScrpHandle,a0
 move.l (a0),-(sp) ; save pointer to TE scrap
 move.l (sp)+,d0
 move.l TEScrpHandle,a0
 _HUnLock ; unlock handle
 rts    ; leave TEtoClip

;---------------- in CmdMenu ------------------

 cmp.w  #EraseItem,d1; baud rate change?
 bne.s  InBaud

; it wasn’t baud change command, fall through to erase screen

 move.l #0,-(sp) ; set Selection range to cover
 move.l #$ffff,-(sp) ; everything in this TE block.
 move.l a2,-(sp)
 bra.s  ClearIt  ; and clear them out

;---------------- in BaudMenu ----------------

 cmp.w  #B300,d1
 beq.s  @1
 cmp.w  #B1200,d1
 beq.s  @2
 cmp.w  #B2400,d1
 beq.s  @3
 cmp.w  #B9600,d1
 beq.s  @4
 bra  NextEvent

@1 move.w #Config300,SerCon(a5)
 bra.s  @5
@2 move.w #Config1200,SerCon(a5)
 bra.s  @5
@3 move.w #Config2400,SerCon(a5)
 bra.s  @5
@4 move.w #Config9600,SerCon(a5)
@5 move.l CmdMHdl(a5),-(sp)
 move.w BaudChk(a5),-(sp) ; uncheck previous item
 move.w d1,BaudChk(a5)    ; save new baud item
 move.w #0,-(sp)
 move.l CmdMHdl(a5),-(sp) ; put handle on stack
 move.w BaudChk(a5),-(sp) ; and place a check
 move.w #-1,-(sp); next to the current baud
 clr.w  -(sp)
 move.w #PortA,-(sp) ; set the new baud rate
 move.w SerCon(a5),-(sp)
 jsr  Config
 move.w (sp)+,d0 ; ignore the result
 bra  ChoiceReturn

;------------ UnhiliteMenu --------------

 clr.w  -(sp)    ; all menus

;-------------- SystemEdit ----------------

 clr  -(sp) ; space for result
 move.w d1,-(sp) ; get item in Edit menu
 subq #1,(sp)    ; SystemEdit is off by 1
 move.b (sp)+,d0

;-------------- SystemEvent --------------

 pea  EventRecord(a5)
 move.l WWindow(a5),-(sp)
 _SystemClick    ; let the system do it
 bra  NextEvent

;-------------- in Content ----------------

 clr.l  -(sp)    ; room for result
 move.l (sp)+,d0 ; front window pointer
 cmp.l  WindowHdl(a5),d0  ; same as our pointer?
 beq.s  @1; ignore it
 move.l WWindow(a5),-(sp)
 _SelectWindow   ; do it, fall through to NextEvent
 bra  NextEvent

@1 pea  Point(a5)
 move.l Point(a5),-(sp)
 btst #9,d1
 sne  d0
 move.b d0,-(sp)
 move.l a2,-(sp)
 bra  NextEvent

;---------------- in Drag ----------------

 move.l WWindow(a5),-(sp)
 move.l Point(a5),-(sp)
 pea  WBounds
 _DragWindow; drag window and fall through
 bra  NextEvent

;-------------- Quit Routine ----------------

 clr.w  -(sp)    ; room for result
 move.l WindowHdl(a5),-(sp) ; get pointer to open window
 move.l Point(a5),-(sp)   ; mouse point
 move.w (sp)+,d0
 beq  NextEvent  ; didn’t really want to quit

 move.l WindowHdl(a5),-(sp) ; did want to quit
 move.w #-1,d0   ; d0 is TRUE - ok to quit

;-------------- Key down ----------------

 move.w Message+2(a5),d0  ; get key code and character
 btst #8,d1 ; command key pressed?
 beq.s  SaveCh   ; yes, take care of it.
 andi.w #$001f,d0; convert to a control character
SaveCh  move.b d0,IOBuf(a5) ; save it in the buffer
 move.l #1,CharCnt(a5)    ; send the character typed
 clr.w  -(sp)    ; room for dummy result
 move.w #PortA,-(sp) ; in the input buffer
 pea  IOBuf(a5)
 pea  CharCnt(a5)
 jsr  PutSerial  ; and send it out the modem port
 move.w (sp)+,d0 ; get rid of dummy result
 bra.s  NextEvent

;---------------- Update ----------------

 move.l WindowHdl(a5),-(sp)
 pea  ViewRect   ; erase visible window
 pea  ViewRect
 move.l a2,-(sp)
 move.l WindowHdl(a5),-(sp)
 bra.s  NextEvent

;---------------- Activate ----------------

 move.l WindowHdl(a5),d0
 cmp.l  Message(a5),d0    ; our window?
 bne.s  NextEvent
 btst #0,d1 ; activate?
 beq.s  Deactivate ; no

 move.l a2,-(sp) ; move Text Handle To Stack
 move.l EditMHdl(a5),-(sp); get handle to the menu
 move.w #UndoItem,-(sp)   ; disable 1st item (undo)

 move.l WindowHdl(a5),-(sp)
 bra.s  NextEvent

; Deactivate window, turn off TextEdit, enable undo for the desk accessories.

 move.l a2,-(sp) ; get Text Handle
 move.l EditMHdl(a5),-(sp); get handle to the menu
 move.w #UndoItem,-(sp)   ; enable 1st item (undo)
;bra  NextEvent  ; *CAUTION!* if more code
; is added after this routine, remember to uncomment the line above!
;-------------- Next Event --------------

 moveq  #0,d0    ; say that it’s not Quit
 rts    ; return to EventLoop

;------------ Window stuff --------------

ViewRectdc.w   5,4,290,500; Text Record’s View Rect
DestRectdc.w   5,4,290,500; Text Record’s Dest Rect
WBounds dc.w   5,5,335,510

;------------ Event variables ------------
; IMPORTANT! remember, the EventRecord is
; very much a variable and NOT a constant.
; Never declare the EventRecord variables
; with a dc command.

EventRecord ds.w 0
What:   ds.w   1 ; event number
When:   ds.l1
Point:  ds.l1    ; mouse coordinates
Modify: ds.w   1 ; key and button state

;------ Application variables ------------

AppleMHdl ds.l 1 ; handle for apple menu
FileMHdlds.l1    ; handle for file menu 
EditMHdlds.l1    ; handle for edit menu 
CmdMHdl ds.l1    ; handle for command menu 

DeskNameds.w16   ; DA name
ItemHit ds.w1
WWindow ds.l1
WindowStorage  ds.wWindowSize
WindowHdl ds.l 1 ; handle to the window
GSOffsetds.l1    ; Get Scrap Offset dummy

;Serial port variables
IOBuf   ds.b512  ; general I/O buffer
Outbuf  ds.b512  ; sanitized version of IOBuf
SerCon  ds.w1    ; current serial port config
BaudChk ds.w1    ; current checked item
CharCnt ds.l1    ; # of characters read


Listing:  term.r

* This is the resource file for the program “Term”
* the \CA character generates a “hard” space.

* Give it a type APPL and creator FHMT.

* Get the code portion.
INCLUDE term.code
About Term...



Erase screen
1200 Baud
2400 Baud
9600 Baud

100 100 200 350
Visible  NoGoAway


60 100 90 150

15 40 59 238
Simple Terminal Program\0D\CAFrank Henriquez 1/88

44 7 337 507
Visible GoAway


Community Search:
MacTech Search:

Software Updates via MacUpdate

FileMaker Pro 19.4.2 - Quickly build cus...
FileMaker Pro is the tool you use to create a custom app. You also use FileMaker Pro to access your app on a computer. Start by importing data from a spreadsheet or using a built-in Starter app to... Read more
Adobe Illustrator 26.0.3 - Professional...
You can download Adobe Illustrator for Mac as a part of Creative Cloud for only $20.99/month. Adobe Illustrator for Mac is the vector graphics classics in the design industry. It is a digital... Read more
WhatRoute 2.4.9 - Geographically trace o...
WhatRoute is designed to find the names of all the routers an IP packet passes through on its way from your Mac to a destination host. It also measures the round-trip time from your Mac to the router... Read more
Notion 2.0.20 - A unified workspace for...
Notion is the unified workspace for modern teams. Notion Features: Integration with Slack Documents Wikis Tasks Release notes were unavailable when this listing was updated. Download Now]]> Read more
Monterey Cache Cleaner 17.0.2 - Clear ca...
Monterey Cache Cleaner is an award-winning general-purpose tool for macOS X. MCC makes system maintenance simple with an easy point-and-click interface to many macOS X functions. Novice and expert... Read more
Firetask Pro 4.6.8 - Innovative task man...
Firetask Pro represents the next generation of easy-to-use, project-oriented task management apps. By combining David Allen's powerful Getting Things Done (GTD®) approach with classical task... Read more
Smultron 13.0.4 - Easy-to-use, powerful...
Smultron 13 is the text editor for all of us. Smultron is powerful and confident without being complicated. Its elegance and simplicity helps everyone being creative and to write and edit all sorts... Read more
Box Sync 4.0.8057 - Online synchronizati...
Box Sync gives you a hard-drive in the Cloud for online storage. Note: You must first sign up to use Box. What if the files you need are on your laptop -- but you're on the road with your iPhone? No... Read more
Audio Hijack 3.8.10 - Record and enhance...
Audio Hijack (was Audio Hijack Pro) drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio... Read more
Direct Mail 6.0.1 - Create and send grea...
Direct Mail is an easy-to-use, fully-featured email marketing app purpose-built for macOS. Create, send, and track great looking email campaigns that get results. Start your newsletter by selecting... Read more

Latest Forum Discussions

See All

Hopefully Not Jared’s Last Show – The To...
My suspicions from last week were correct, and after my two kids tested positive for Covid last week both my wife and I have now tested positive as well. It seems you just can’t escape this stuff lately. Thankfully the two little ones are pretty... | Read more »
TouchArcade Game of the Week: ‘Micro RPG...
I feel like idle games are one of those perfect fits for the mobile platform. Not that they replace more involved gaming experiences when you’re in the mood for that, but they do fit in alongside other types of games just fine as a “go to" when you... | Read more »
‘Phantom Blade: Executioners’ Closed Bet...
Phantom Blade: Executioners is holding a small-scale technical test that lets players get first dibs on the KungFuPunk action RPG. Offered to selected players only, S-Game’s first Closed Beta Test will provide players with limited edition in-game... | Read more »
New ‘Warhammer 40,000: Tacticus’ Video S...
Back in September Snowprint Studios, who you may know from their previous Legend of Solgard or Rivengard, announced that they’d partnered up with Games Workshop to put out a new tactical game in the Warhammer 40,000 universe titled Warhammer 40,000... | Read more »
SwitchArcade Round-Up: ‘Pokemon Legends:...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for January 28th, 2022. We’ve got a bunch of new releases to look at today, with a few big hitters, a few mid-level diversions, and a healthy supply of compost. Since it’s Friday, we... | Read more »
Phantom Blade: Executioners, S-Game...
S-Game has kicked off its first Closed Beta Test for Phantom Blade: Executioners, inviting a selected few to get first dibs on the upcoming KungFuPunk action RPG on mobile. The CBT officially begins this January 28th, and beta testers will receive... | Read more »
‘Infinite Galaxy’ First Anniversary: Cel...
Cultivating a new generation of valiant commanders across 240 countries worldwide, Infinite Galaxy has quenched players’ thirst to explore the vastness of space – and there are only more intergalactic adventures to embark on from here on out. Camel... | Read more »
War and Order: How to brave the cold in...
War and Order's 6th-anniversary celebrations are underway, and all in good time too - this season not only brings about fabulous festivities, but it also lets players experience the harsh winter in an entirely new way. [Read more] | Read more »
‘Hidden Folks+’ Is This Week’s New Apple...
The original Hidden Folks from Adriaan de Jongh is an excellent hidden objects game featuring hand drawn visuals. It is an absolute joy to play, and it has now released on Apple Arcade in the form of Hidden Folks+ () as an App Store great. If you’... | Read more »
Mini Metro’s First Big Update of 2022 Ad...
Last year saw great updates for Dinosaur Polo Club’s Mini Metro ($3.99) which is also available on Apple Arcade as an App Store Great. | Read more »

Price Scanner via

Apple has clearance 2020 13″ MacBook Airs ava...
Apple has clearance, Certified Refurbished, 2020 13″ Intel-based MacBook Airs in stock today starting at only $719 and up to $370 off original MSRP. Each MacBook features a new outer case, comes with... Read more
The cheapest iPhones for sale today at Apple...
Apple has restocked Apple Certified Refurbished iPhone 8 models starting at only $359. Each refurbished iPhone comes with a fresh external case, standard Apple 1-year warranty, and free shipping.... Read more
14″ MacBook Pro with Apple M1 Max CPU now in...
Looking for a new 14″ MacBook Pro with an Apple M1 Max CPU? Stock is finally trickling into Apple resellers. B&H has Silver 14″ M1 Max MacBook Pros in stock today for $2899 including free 1-2 day... Read more
14″ MacBook Pros with Apple M1 Pro CPUs are i...
Amazon is reporting stock of 14″ MacBook Pros with M1 Pro CPUs today with a $50 discount. Shipping is free, and delivery is available by February 1st for most configurations. Be sure to make your... Read more
Apple has restocked 13″ M1 MacBook Pros for $...
Apple has restocked a full line of 13″ M1 MacBook Pros available Certified Refurbished, starting at only $1099 and up to $230 off original MSRP. These are the cheapest M1 MacBook Pros for sale today... Read more
Apple’s AirPods Max headphones are on sale fo...
Amazon has Silver, Blue, and Space Gray Apple AirPods Max headphones on sale today for $100 off MSRP. Shipping is free, and all models are in stock today. Their price is the lowest currently... Read more
Open a new line of service at Verizon and get...
Verizon is giving away 64GB Apple iPhone 12 minis or your choice of an iPhone 11 to customers who choose one of these phones and open a new line of service. Offer is available online only, and no... Read more
Open-box 13″ M1 MacBook Airs now available st...
QuickShip Electronics has open-box return 13″ M1 MacBook Airs in stock and on sale for $200-$400 off MSRP on their eBay store right now with free express delivery. According to QuickShip, “The item... Read more
Verizon’s 2022 iPad promo: $100-$310 off any...
Verizon has cellular-capable iPads on sale for $100-$310 off MSRP when purchased with an Unlimited service plan. Sale price is applied to your account monthly over a 24 or 30 month period, depending... Read more
Sunday Sale: Apple AirPods are on sale for up...
Amazon has Apple AirPods on sale for $10-$100 off MSRP today, depending on the model. All are in stock today with free delivery: – AirPods Max headphones (Blue): $449 $100 off MSRP – AirPods Max... Read more

Jobs Board

Registered Nurse (RN) Employee Health PSJH -...
…is calling for a Registered Nurse (RN) Employee Health PSJH to our location in Apple Valley, CA.** We are seeking a Registered Nurse (RN) Employee Health PSJH to be Read more
Systems Administrator - Pearson (United State...
…and troubleshoot Windows operating systems (workstation and server), laptop computers, Apple iPads, Chromebooks and printers** + **Administer and troubleshoot all Read more
IT Assistant Level 1- IT Desktop Support Anal...
…providing tier-1 or better IT help desk support in a large Windows and Apple environment * Experience using IT Service Desk Management Software * Knowledge of IT Read more
Human Resources Business Partner PSJH - Provi...
…**is calling a** **Human Resources Business Partner, PSJH** **to our location in Apple Valley, CA.** **Applicants that meet qualifications will receive a text with Read more
Manager Community Health Investment Programs...
…is calling a Manager Community Health Investment Programs PSJH to our location in Apple Valley, CA.** **Qualified candidates will be invited to do a self-paced video Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.