_TERSE: A TINY REAL-TIME OPERATING SYSTEM_ by Barry Kauler Listing One node0: ;node-0 is the error-handler ;test for DEADLINE/SHUTDOWN/RESTART.... jnb flags.0,nodead jnb flags.1,nosh2 ;SHUTDOWN. If responding remote or local broadcast msg, it has ;already been forwarded, so now do local response... ;...PUT ALL I/O INTO A SHUTDOWN STATE myself: ajmp myself nosh2: jnb flags.2,nore2 ;RESTART. If responding remote or local broadcast msg, it ;has already been forwarded, so now do local response... mov sp,#emptyst ajmp start1 ;restart program. nore2: ;DEADLINE OVERRUN. ;could maybe broadcast a global shutdown, or some error msg... ajmp nodereturn ;do this to carry-on regardless. nodead: ;test for wait-state.... jnb flags.5,notwait ;can perform deadline timeout if required, else just return... ajmp nodereturn notwait: ;...process more msgs ;default behaviour of node-0... mov sp,#emptyst ;dump any msgs left on stack. ;for consistency, error-handler should *not* post any msgs. ;By emptying stack, after exit from here execution will restart ;from whatever node corresponds to signature=0 in the lookup table. ajmp nodereturn ;................................................................... node1: ;assuming this is starting-node, it will not have any i/p msgs. ;...code... POSTMSG 1,2,1,0,#34h ;pu-1,node-2,term-1,not-notif.,immediate-data. POSTMSG 1,3,1,0,#00h ;pu1,node3,term1,not-notif,immediate-data. ajmp nodereturn ;................................................................... node3: jnb flags.1,n31 ;jump if no msg on terminal-1. ;...msg is in r1...process it n31: POSTMSG 1,4,1,0,32h ;pu1,node4,term1,notnotif,direct-data. ajmp nodereturn ;.................................................................. node2: jnb flags.1,n21 ;jump if no msg on terminal-1. ;... msg is in r1...process it n21: POSTMSG 1,4,2,0,#00h ;pu1,node4,term2,0,immediate-data. ajmp nodereturn ;................................................................... node4: jnb flags.1,n41 ;jump if no msg on terminal-1. ;...msg is in r1...process it n41: jnb flags.2,n42 ;jump if no msg on terminal-2. ;...msg is in r2...process it n42: POSTMSG 2,1,1,0,#56h ;remote message! POSTMSG 1,2,2,1,#11 ;notification, back to node-2,term-2. ajmp nodereturn Listing Two signatures: DB 255,00,00h,0A0h,0C8h, 012 ;starting node has signature=0. sighigh: DB 255,00,03h, 00h, 00h, 034 nodenum: DB 0, 1, 3, 2, 4,WAIT nodeptr: ;these occupy 2 bytes each. ajmp node0 ;1st node in table is error-handler(always node-0). ajmp node1 ;this must be in ascending order ajmp node2 ;of node number. ajmp node3 ; ajmp node4 Listing Three .MODEL SMALL .STACK .DATA DB 10 DUP(0) asciitbl DB 7 DUP(0) DB "$","$" intromsg DB 0Ah,0Dh DB "Type-in active-set of messages, crtl-z to clear, crtl-x to quit" DB 0Ah,0Dh intr2 DB "Do not enter remote-output, nor Notification messages.",0Ah,0Dh intro3 DB "FOR TERSE51: Node range = 1 - 32. Terminal range = 1 - 4." DB 0Ah,0Dh DB "FOR TERSE51: Signature-calc starts from latest msg on stack." DB 0Ah,0Dh,0Ah,0Dh,"$" destnode DB "Destination-node: $" destterm DB " Destination-terminal: $" sigtxt DB " SIGNATURE:$" newline DB 0Dh,0Ah,"$" signature DW 0 ;16-bit signature input DB 0 ;binary input header DB 0 ;used for sig-calc .CODE start: mov ax,@DATA mov ds,ax start2: ;intro message... mov ah,9 lea dx,intromsg int 21h start3: ;Ask for destination node.... mov ah,9 lea dx,destnode int 21h call getinput ;comes back with "input", in binary... mov al,input and al,00011111b shl al,1 shl al,1 shl al,1 mov header,al ;ask for destination terminal... mov ah,9 lea dx,destterm int 21h call getinput mov al,input dec al ;as terminal no. stored as 0 - 3. and al,011b shl al,1 or header,al ;calculate the signature.... mov ax,signature test ax,8000h jz sig1 xor ax,0100010000010001b sig1: xor al,header rol ax,1 mov signature,ax ;convert it to ascii.... mov ax,signature mov dx,0 call bin2dec mov BYTE PTR asciitbl+7,"$" ;hex o/p stuffs this up. ;display result... mov ah,9 lea dx,sigtxt int 21h mov ah,9 lea dx,asciitbl int 21h ;also display signature in hex... mov bx,signature mov cl,4 rol bx,cl mov ax,bx and ax,000Fh cmp al,9 jbe xx add al,7 xx: add al,30h mov asciitbl+1,al rol bx,cl mov ax,bx and ax,000Fh cmp al,9 jbe yy add al,7 yy: add al,30h mov asciitbl+2,al rol bx,cl mov ax,bx and ax,000Fh cmp al,9 jbe zz add al,7 zz: add al,30h mov asciitbl+3,al rol bx,cl mov ax,bx and ax,000Fh cmp al,9 jbe mm add al,7 mm: add al,30h mov asciitbl+4,al mov BYTE PTR asciitbl+5,"h" mov BYTE PTR asciitbl+6,0Ah mov BYTE PTR asciitbl+7,0Dh mov BYTE PTR asciitbl+8,"$" mov ah,9 lea dx,asciitbl int 21h jmp start3 getout: mov ax,4C00h int 21h getinput: mov input,0 getinput2: mov ah,0 int 16h cmp ax,2C1Ah ;crtl-z jne notcrtlz mov signature,0 mov ah,9 lea dx,newline int 21h pop ax ;dump return address jmp start2 notcrtlz: cmp ax,2D18h ;crtl-x jne notcrtlx mov ah,9 lea dx,newline int 21h jmp getout notcrtlx: ;test if outside range 0-9... cmp al,30h jb below0 cmp al,39h ja above9 inrange: ;echo it to screen... mov ah,0Eh push ax mov bx,02 int 10h pop ax and al,0Fh ;convert to binary mov ah,input and ah,0Fh ;see if 2nd char already there jnz second ;mov cl,4 ;shl al,cl mov input,al ;save in lo-nibble. jmp getinput2 second: mov cl,4 shl input,cl mov ah,input or al,ah ;combine them mov input,al ;save. ...value is in bcd format. below0: ;any char outside range, terminates entry above9: ; / ;convert input to binary.... mov al,input and al,0F0h mov cl,4 ror al,cl mov dl,10 mul dl ;result --> ax mov bl,input and bl,0Fh add al,bl ;now have binary value. mov input,al ; / ret ;................................................................... bin2dec PROC ;requires binary number in dx:ax... lea di,asciitbl mov bx,di add di,6 ;8 ;mov BYTE PTR [di],0 ;dec di ssss: mov cx,10 div cx add dl,30h sssss: mov [di],dl dec di mov dx,0 cmp ax,0 jne ssss mov dl," " cmp bx,di jbe sssss ret bin2dec ENDP END start