TRS-80 DOS - NEWDOS/80 v2.0 for the Model III - SYS15/SYS Disassembled
Page Customization
Page Index
SYS15/SYS
Other Navigation
Introduction/Summary
NEWDOS/80 v2.0 SYS15/SYS Disassembly - FORMS and SETCOM (Model III)
SYS15/SYS holds two library commands: FORMS, which sets the printer's line width and page length, and SETCOM, which sets the RS-232 interface. Both always show the values in force when they end. Its five load records fill 4D00H-51E7H of the overlay area (1,256 bytes) and its transfer address is 4D00H; the code ends at 4FD2H and 4FD3H-51E7H are 00H.
The page shows every byte of the file once, in address order.
Commands
SYS1/SYS's command table gives both commands the RST 28H code F1H (function 7 of directory slot 11H) with a sub-function in Register C; any other code or sub-function gives error 2AH.
| Sub-Function | Command |
|---|---|
| 1 | FORMS[,WIDTH=w][,LINES=l], 4D11H |
| 2 | SETCOM[,OFF][,WORD=w][,BAUD=b][,STOP=s][,PARITY=p][,WAIT][,NOWAIT], 4D70H |
Both commands look their options up in a table (word, 00H, attribute byte, handler address) through 4EE7H, which reads the option's number when attribute bit 7 is set (bit 6: 16 bits, else 0-255; bit 5: not 0) and RETURNs into the handler. Numbers are decimal, or hexadecimal ended by H. A bad number is error 2FH (BAD PARAMETER(S)); an unknown option or a bad separator is error 34H (ILLEGAL KEYWORD OR SEPARATOR OR TERMINATOR). The values are shown as WORD=value items separated by commas through 4F7FH.
FORMS works on the printer control block 4025H-402CH: WIDTH (1-255) goes to 402BH, the most characters per line (255 means no limit to the ROM's printer driver), and 402AH, the characters printed on the line, is cleared; LINES (1-254; 255 keeps the current value) goes to 4028H as the lines per page plus 1, and 4029H, the lines printed, is cleared. FORMS shows WIDTH= and LINES= from 402BH and 4028H.
RS-232 Settings
SETCOM keeps the settings where the ROM's RS-232 initialization (005AH, through the control block at 41F5H) reads them: 41F8H the baud rate code (bits 7-4 sending, bits 3-0 receiving; SETCOM always sets both to the same code), 41F9H the configuration byte for the UART control port EAH, and 41FAH the wait switch. The options change copies of these in SYS15/SYS's own operands (4DF9H, 4DFAH and 4E02H); the result, with bits 1-0 cleared and bit 2 set in the configuration byte, is stored and the interface initialized (4E7EH). OFF, or a configuration byte of 00H when the state is shown, stores 0000H at 41F8H-41F9H and FFH at 41FAH and initializes the interface off (4E79H); the earlier settings are not kept.
| Option | Effect on the settings |
|---|---|
| WORD=5-8 | Configuration bits 6-5: 00 for 5, 10 for 6, 01 for 7, 11 for 8 bits (a value of 9-13 also passes the check and sets other bits) |
| BAUD= | One of 50, 75, 110, 134, 150, 300, 600, 1200, 1800, 2000, 2400, 3600, 4800, 7200, 9600, 19200 (codes 0-15, table 4EC7H) |
| STOP=1 or 2 | Configuration bit 4: set for two stop bits |
| PARITY=1, 2 or 3 | Odd (bit 3 clear, bit 7 clear), even (bit 3 clear, bit 7 set), none (bit 3 set) |
| WAIT, NOWAIT | Wait switch FFH or 00H |
| OFF | Must be the only option; turns the interface off |
Variables
Memory Outside SYS15/SYS
| Address Size | Contents |
|---|---|
| 4028H 1 byte | Printer Lines per Page The printer control block's +3, the lines per page plus 1 (4D2AH, 4D3DH, 4D4FH). |
| 4029H 1 byte | Printer Line Count The printer control block's +4, the lines printed; set to 00H with a new page length (4D3DH). |
| 402AH 1 byte | Printer Character Count The printer control block's +5, the characters printed on the line; set to 00H by FORMS with options (4D43H). |
| 402BH 1 byte | Printer Width The printer control block's +6, the most characters per line, 255 for no limit (4D16H, 4D43H, 4D46H). |
| 41F8H 1 byte | RS-232 Baud Rate Code Bits 7-4 the sending rate, bits 3-0 the receiving rate, codes 0-15 (4D76H, 4E30H, 4E7EH). |
| 41F9H 1 byte | RS-232 Configuration The byte the ROM sends to the UART control port EAH: bit 7 even parity, bits 6-5 word length, bit 4 two stop bits, bit 3 no parity, bit 2 break, bits 1-0 RTS and DTR; 00H when off (4D76H, 4E0FH, 4E7EH). |
| 41FAH 1 byte | RS-232 Wait Switch Not 00H for WAIT, 00H for NOWAIT as SETCOM shows it (4D7EH, 4E6BH, 4E81H). |
SYS15/SYS Tables
| Address Size | Contents |
|---|---|
| 4D5BH-4D6FH 21 bytes | FORMS Option Table WIDTH= and LINES=, also the texts shown. |
| 4E87H-4EC6H 64 bytes | SETCOM Option Table OFF, WORD=, BAUD=, STOP=, PARITY=, WAIT and NOWAIT, also the texts shown. |
| 4EC7H-4EE6H 32 bytes | Baud Rate Table The 16 rates in the order of their codes. |
| 4FC3H-4FCAH 8 bytes | Powers of Ten Minus 10000, 1000, 100 and 10 for the decimal display. |
Operands Changed at Run Time
| Address Size | Contents |
|---|---|
| 4D37H 1 byte | Page Length Plus 1 The operand of LD HL at 4D36H: 00H in the file (no LINES=), stored at 4D2DH. |
| 4D42H 1 byte | Width The operand of LD HL at 4D40H: stored at 4D19H (the current width) and 4D22H (WIDTH=). |
| 4DF9H 1 byte | Baud Rate Code The operand of LD HL at 4DF8H (Register L): copied from 41F8H at 4D7AH, changed by BAUD= at 4DBEH. |
| 4DFAH 1 byte | Configuration The operand of LD HL at 4DF8H (Register H): copied from 41F9H at 4D7AH, changed by WORD=, STOP= and PARITY=. |
| 4E02H 1 byte | Wait Switch The operand of LD A at 4E01H: copied from 41FAH at 4D81H, changed by WAIT and NOWAIT at 4DEFH. |
| 4F81H 1 byte | Separator The operand of OR at 4F80H: 00H in the file, 2CH (a comma) after the first item is shown (4F87H). |
Outside Routines and Addresses
| Address | Contents |
|---|---|
| 0033H | ROM: display a character (4FCDH). |
| 005AH | ROM: initialize the RS-232 interface from the control block 41F5H (4E84H). |
| 4409H | SYS0/SYS: the DOS error exit (4F23H, 4F46H). |
| 4C6AH, 4C7AH | SYS0/SYS: compare a word (4F0FH), test for the end of the line or a separator (4D30H, 4DF2H, 4E08H). |
Disassembly
4D00H - Function Dispatcher
SYS15/SYS (directory slot 11H) is loaded by the SYS0/SYS RST 28H dispatcher (4B67H) into 4D00H-51E7H and entered at 4D00H by the CALL at 4BC2H, with Register A = the RST 28H code, Register C = the sub-function, Register Pair HL = the command line after the command word, and 4BC5H (the dispatcher's tail) on top of the stack. The only code it accepts is F1H (function 7 of slot 11H), which SYS1/SYS's command table gives to FORMS (sub-function 1) and SETCOM (sub-function 2).
4D11H - FORMS Command
FORMS[,WIDTH=w][,LINES=l] sets the printer's line width and page length in the printer control block at 4025H and always shows them. WIDTH and LINES must be 1-255; WIDTH goes to 402BH (the printer control block's +6, the most characters per line; 255 means no limit to the ROM's printer driver); LINES plus 1 goes to 4028H (+3), the line counter at 4029H (+4) and the character counter at 402AH (+5) are set to 00H; LINES=255 keeps the page length. The options store their values straight into the operands 4D42H and 4D37H.
Store Register A (the current width) at 4D42H, the operand of the LD HL,0000H at 4D40H, so that the width is written back unchanged when no WIDTH= is given.
Option Loop
Register Pair HL = the command line at the next option.
Store Register A at 4D42H, the operand of the LD HL,0000H at 4D40H.
Store Register A (the page length plus 1) at 4D37H, the operand of the LD HL,0000H at 4D36H. 4D28H comes here.
Load Register Pair HL with 0000H in the file: the page length plus 1 in Register L (the operand 4D37H, 00H in the file, stored at 4D2DH) and 00H in Register H.
Load Register Pair HL with 0000H in the file: the width in Register L (the operand 4D42H, stored at 4D19H and by WIDTH= at 4D22H) and 00H in Register H. 4D3BH comes here.
4D5BH - FORMS Option Table (Data)
Read by 4EE7H from 4D1CH. Each entry: the option word with its = sign, 00H, an attribute byte and the handler's address. Attribute bits: 7 a number follows, 6 the number is 16 bits (else 0-255), 5 the number must not be 0. The words are also the texts shown by 4D49H and 4D52H.
4D70H - SETCOM Command
SETCOM[,OFF][,WORD=w][,BAUD=b][,STOP=s][,PARITY=p][,WAIT][,NOWAIT] sets the RS-232 interface through the ROM's initialization routine 005AH and always shows its state. The ROM keeps the settings in the RS-232 initialization control block 41F5H-41FCH: 41F8H the baud rate code (bits 7-4 sending, 3-0 receiving), 41F9H the configuration byte the ROM sends to the UART control port EAH (bit 7 even parity, bits 6-5 word length, bit 4 two stop bits, bit 3 no parity, bit 2 break, bits 1-0 RTS and DTR; 00H means the interface is off), 41FAH the wait switch (not 00H = wait, 00H = no wait in this command's handling). The current values are copied into the operands 4DF9H, 4DFAH and 4E02H, each option changes them, and the result is stored and the interface initialized. OFF stores 0000H and FFH instead, which turns the interface off.
Store Register Pair DE at 4DF9H-4DFAH, the operand of the LD HL,0000H at 4DF8H: Register L will be the baud rate code and Register H the configuration byte, changed by the options.
Store Register A (the wait switch) at 4E02H, the operand of the LD A,00H at 4E01H, changed by WAIT and NOWAIT.
Option Loop
Register Pair HL = the command line at the next option.
Baud Rate Search
Register Pair HL = the table entry, Register A = its code in both nibbles.
Store Register A (the code, the same in the sending and receiving nibbles) at 4DF9H, the baud rate code in the operand of the LD HL at 4DF8H. 4DB5H comes here.
Store Register A (FFH for WAIT, 00H for NOWAIT) at 4E02H, the operand of the LD A,00H at 4E01H. 4DECH comes here.
Load Register Pair HL with 0000H in the file: the new settings: Register L = the baud rate code (operand 4DF9H) and Register H = the configuration byte (operand 4DFAH), copied from 41F8H-41F9H at 4D7AH and changed by the options.
Load Register A with the new wait switch: the operand 4E02H was copied from 41FAH at 4D81H and changed by WAIT or NOWAIT.
4E0FH - Show the RS-232 State
Shows OFF when the configuration byte at 41F9H is 00H (and then initializes the interface off again), otherwise WORD=w,BAUD=b,STOP=s,PARITY=p and WAIT or NOWAIT, all decoded from 41F8H-41FAH.
4E79H - Set the RS-232 Control Block
4E79H turns the interface off: the baud rate code and the configuration byte become 00H and the wait switch FFH. 4E7EH stores Register Pair HL (Register L = the baud rate code, Register H = the configuration byte) at 41F8H-41F9H and Register A at 41FAH. Both then jump to the ROM routine 005AH, which loads Register Pair DE with 41F5H (the RS-232 initialization control block) and sends it through the ROM's output dispatcher; the ROM's driver programs the UART from 41F8H-41FAH, or turns it off for a configuration byte of 00H, and returns to the caller.
4E87H - SETCOM Option Table (Data)
Read by 4EE7H from 4D84H. Each entry: the option word, 00H, an attribute byte (bit 7 a number follows, bit 6 the number is 16 bits, bit 5 the number must not be 0) and the handler's address. The words are also the texts 4E0FH shows.
4EC7H - Baud Rate Table (Data)
The 16 baud rates as 16-bit numbers, in the order of the codes 0-15 that the ROM sends to the baud rate port. Searched by 4DA6H, indexed by 4E36H.
4EE7H - Look Up an Option and Run Its Handler
Register Pair BC = an option table, Register Pair HL = the command line. The word at Register Pair HL is looked up (error 34H if it is not in the table); the handler's address is pushed and the routine RETURNs into it. An option without a number (attribute bit 7 clear) goes there at once. Otherwise the number after the word is read: with attribute bit 5 it must not be 0, with bit 6 it is passed in Register Pair DE, else it must be 0-255 and is passed in Register A. A bad number is error 2FH. Register Pair HL is past the option when the handler starts.
Search Loop
Register Pair BC = the table entry, Register Pair HL = the word in the command line, Register D = the bytes after each 00H.
4F26H - Read a Number
Reads a number at Register Pair HL into Register Pair DE: decimal digits, or hexadecimal digits ended by H. The digits are first read as decimal; if a letter A-H follows them, the number is read again from its start as hexadecimal, and must then end with H. No digit, a missing H or a value above FFFFH is error 2FH. Register Pair HL returns past the number. Called by 4EF9H.
4F49H - Read Digits
Register Pair HL = the text, Register B bit 0 = hexadecimal. The digits are added up in Register Pair DE (times 10, or times 16, plus the digit); Register A collects every carry out of bit 15, and any carry is error 2FH. Bit 1 of Register B is set when a digit is read. Returns at the first character that is not a digit, with Register Pair HL pointing at it.
Digit Loop
Register Pair HL = the next character, Register Pair DE = the value so far.
4F7FH - Show an Item
4F7FH shows a comma before every item except the first (the operand 4F81H is 00H until the first item has been shown) and then the 00H-ended text at Register Pair HL. 4F93H takes the number in Register A, 4F94H in Register E, 4F96H in Register Pair DE, and shows it in decimal after the text, without leading zeros.
OR Register A with the operand 4F81H: 00H in the file, 2CH (a comma) after 4F87H has stored it. The NZ FLAG is set once an item has been shown.
Store Register A (2CH) at 4F81H, the operand of the OR at 4F80H, so that every later item is preceded by a comma.
Show the Text
Register Pair HL = the text, ended by 00H.
Digit Loop
Register Pair DE = what is left of the number, Register Pair HL = the next power of ten in the table.
4FCBH - Show a Character
Shows the character in Register A through the ROM routine 0033H, keeping Register Pairs AF and DE.
4FD3H - End of the File
The rest of the five load records.