.MODEL SMALL .STACK 100h .CODE ASSUME es:@code ASSUME ds:@code Read EQU 1 Stx EQU <2> Etx EQU <2> ; Start ;-------------------------------------------------------------------- MOV AX,CS MOV ES,AX MOV DS,AX MOV SI,offset InBuf MOV DI,offset OutBuf DoToOwn MetaL: DW RunEntry DW MetaL DW WeaveSp DoEnd Object DB 0 InBuf DB '|^|x:. ' DB ' |1:. ' DB ' |0:. ' DB ' |str:|BX^xxxxxx01.' DB ' |BP^xxxxxx10.' DB ' . ' DB ' . ' DB 'BP ' DB 100 dup(0) ; The threader is the heart of the language ;-------------------------------------------------------------------- TDrop: POP BX TDataTOS:MOV BP,SP TNext: POP BX ADD BX,2 PUSH BX JMP [BX-2] DoToPrev EQU ;Address list following this begins executing. ;Parameters will be taken from save location ; as they were in previous code. DoToOwn EQU ;Address list following this begins executing. ;Parameters will be taken from inside the ; address list (immediate operands). DoEnd EQU ;Current address list stops. ;Parent code resumes executing. ;Parameters set to immediate Next EQU ;Current machine code stops. ;Parent code resumes executing. StdEntry: DoToPrev DW RunEntry DW RunMatch DW RunSucceed DoEnd WeaveSp: ;-------------------------------------------------------------------- DoToOwn DW StdEntry DW WeaveMatch DB " ",0 DW RunSp DoEnd RunSp: INC SI NEXT DoToOwn DW RunEntry DW WeaveMatch DW RunMatch DB " ",0 DW RunSucceed DW RunSp DoEnd WeaveMatch: ;-------------------------------------------------------------------- CLD CMP BYTE PTR [SI],Stx JNE WeaveEntry INC SI MOV AX,OFFSET MethodMatch STOSW JMP @F MMatch1: STOSB @@: LODSB CMP AL,Etx JNE MMatch1 XOR AL,AL STOSB NEXT Match: MethodMatch: CMP OBJECT,Read JE ReadMatch PUSH DI PUSH SI MOV DI,[BP+00] CALL RunMATCH MOV [BP+00],DI JC @F POP AX ; Succeed POP DI NEXT @@: POP SI ; Fail POP DI POP AX NEXT ReadMatch: ; BEGIN ; DW SelfInhertParms ; DW OutUnderline ; DW OutString ; DW OutEndUnderline ; DW End RunMATCH: CLD XOR CX,CX DEC CX REPZ CMPSB CMP BYTE PTR [DI-1],0 JZ @F XOR AX,AX REPNZ SCASB STC RET @@: DEC SI CLC RET WeaveEntry: ;-------------------------------------------------------------------- CMP BYTE PTR [SI],"|" JNE WeavePeriod CMP BP,SP JNZ @F SUB BP,4 @@: INC SI MOV AX,OFFSET RunEntry STOSW MOV BX,OFFSET LinkEntry POP AX PUSH AX PUSH DI PUSH BX PUSH AX ADD DI,2 NEXT LinkEntry: DW LEntry1 LEntry1: CMP BP,SP JNE @F ;if BP,SP insync ADD BP,4 ; keep it that way @@: POP BX POP BX MOV [BX],DI ; MOV AX,OFFSET RunSucceed ; STOSW NEXT Entry: RunEntry: ;Insert a FailTo pointer in the stack. CMP BP,SP JNZ @F SUB BP,2 @@: POP BX MOV CX,[BX] ADD BX,2 PUSH CX PUSH BX NEXT RunSucceed: ;Remove the FailTo pointer made by RunEntry. CMP BP,SP JNZ @F ADD BP,2 @@: POP AX POP BX PUSH AX NEXT ReadEntry: ; Con: LeftMargin Indent to CurPos ; Disp '|' ; . db ' ' WeavePeriod: ;-------------------------------------------------------------------- CMP BYTE PTR [SI],'.' JNE WeaveDefine INC SI MOV AX,OFFSET Leave STOSW JMP LEAVE ReadPeriod: ; Con: LeftMargin Outdent to Prev ; CrLf ; Disp '.' ; . DB 0 WeaveDefine: ;-------------------------------------------------------------------- CMP BYTE PTR [SI],":" JNE WeaveROL INC SI MOV AX,OFFSET RunDefine STOSW MOV AL,0E8h ; Call STOSB MOV AX,OFFSET TNext STOSW NEXT Define: RunDefine: POP AX STOSW NEXT ReadDefine: ; Con: Disp ':' ; . WeaveROL: CMP BYTE PTR [SI],11h JNE WeaveSTC INC SI MOV AX,OFFSET RunROL STOSW NEXT RunROL: ROL BYTE PTR [DI],1 NEXT WeaveSTC: CMP BYTE PTR [SI],17h JNE WeaveCLC INC SI MOV AX,OFFSET RunSTC STOSW NEXT RunSTC: STC ROL BYTE PTR [DI],1 NEXT WeaveCLC: CMP BYTE PTR [SI],12h JNE Continue INC SI MOV AX,OFFSET RunCLC STOSW NEXT RunCLC: CLC ROL BYTE PTR [DI],1 NEXT DB 0Eh DUP(11h) Continue: OutBuf DB 100 DUP(0) END