;http://www.cosmacelf.com/software/tbsourcep.txt  Aug 2017
SOURCE FILE NAME: TB-MON.ASM					    PAGE  1


		;------------------------------------------------------;
		;						       ;
		; TTTTT  I  N	N  Y   Y   BBBB    AAA	 SSSS  I  CCCC ;
		;   T	 I  NN	N  Y   Y   B   B  A   A  S     I  C    ;
		;   T	 I  N N N   Y Y    BBBB   AAAAA  SSSS  I  C    ;
		;   T	 I  N  NN    Y	   B   B  A   A     S  I  C    ;
		;   T	 I  N	N    Y	   BBBB   A   A  SSSS  I  CCCC ;
		;						       ;
		;------------------------------------------------------;
		;
		; TINY BASIC FOR THE COSMAC 1802 MICROCOMPUTER	 2/18/82
		; WRITTEN BY TOM PITTMAN
		; MODIFIED BY LEE A. HART
		; COPYRIGHT 1982 BY TECHNICAL MICRO SYSTEMS, INC.
		; ASSEMBLE WITH AVOCET XASM18 CROSS-ASSEMBLER
		;
		; REGISTER ASSIGNMENTS:
		;
		;	     0	; PC (VIA RESET) AT ENTRY
		;	     1	; INTERRUPT PROGRAM COUNTER
		;		    (USED FOR BREAKPOINTS)
		;	     2	; STACK POINTER
		;	     3	; NORMAL PROGRAM COUNTER
		;	     4	; MONITOR: RAM PAGE0 POINTER
		;		  BASIC: SCRT "CALL" PC
		;	     5	; MONITOR: MAIN PC
		;		  BASIC: SCRT "RETURN" PC
		;	     6	; BASIC: SCRT RETURN ADDR.
		;	     7	; BASIC: PC FOR "FECH"
 0008		XX:	EQU  8	; MONITOR: ?M VS. !M SWITCH
		;		  BASIC: WORK REGISTER
 0009		PC:	EQU  9	; IL PROGRAM COUNTER
 000A		AC:	EQU 10	; MONITOR: MEMORY POINTER
		;		  BASIC: 16-BIT ACCUMULATOR
 000B		BP:	EQU 11	; BASIC POINTER
 000C		DELAY:	EQU 12	; PC FOR DELAY SUBROUTINE
 000D		HEXX:	EQU 13	; MONITOR: HEX ADDR. ACCUMULATOR
 000D		PZ:	EQU 13	; BASIC: PAGE 0 POINTER
 000E		BAUD:	EQU 14	; RE.0=BAUD RATE CONSTANT
		;		  RE.1=USED FOR READ, TYPE
 000F		X:	EQU 15	; BASIC: SCRATCH REGISTER
 000F		ASCII:	EQU 15	; MONITOR: RF.1=ASCII I/O CHAR.
		;			   RF.0=USED FOR READ, TYPE

SOURCE FILE NAME: TB-MON.ASM					    PAGE  2


		; AVOCET XASM18 MACRO-ASSEMBLER SYNONYMS
		;
		;	CALL ADDRESS	IS A SYNONYM FOR     SEP R4, DW ADDR
		;	EXIT		IS A SYNONYM FOR     SEP R5
		;	POP		IS A SYNONYM FOR     LDXA
		;	PUSH		IS A SYNONYM FOR     STXD
		;	
		; EQUATES
		;
 0097		LDI0:	EQU  97H	; GHI R7 - CLEAR ACCUM. MACRO	  
 00D3		TYPA:	EQU  0D3H	; SEP R3 - TYPE CHAR. MACRO
 00D7		FECH:	EQU  0D7H	; SEP R7 - PAGE 0 MACRO
		;
		; SCRATCHPAD MEMORY ALLOCATION - OFFSET ADDED TO PAGE ADDRESS
		;
 1000		PAGE:	EQU  1000H	; WORKSPACE BEGINNING
 1006		KEYV:	EQU  PAGE+06H	; KEY-INPUT ROUTINE VECTOR
 1009		TYPEV:	EQU  PAGE+09H	; TYPE-OUTPUT ROUTINE VECTOR
 100C		BREAKV: EQU  PAGE+0CH	; BREAK-DETECTION ROUTINE VECTOR
		;	EQU	 +0FH	; UNUSED	  
 0013		BS:	EQU	 +13H	; BACKSPACE CHARACTER
 0014		CAN:	EQU	 +14H	; CANCEL CHARACTER
 0015		PAD:	EQU	 +15H	; NUMBER OF PAD CHARACTERS
 0000					; MSB=0 FOR NULL, =1 FOR DELETE 		       
		;		 +16H	; TAPE MODE ENABLE (80H=ENABLE)
 0017		SPARE:	EQU	 +17H	; STACK RESERVE
 0018		XEQ:	EQU	 +18H	; EXECUTION MODE FLAG
 0019		LEND:	EQU	 +19H	; INPUT LINE BUFFER END
 001A		AEPTR:	EQU	 +1AH	; ARITHMETIC EXPRESSION STACK POINTER 
		;			; AND INPUT LINE BUFFER
 001B		TTYCC:	EQU	 +1BH	; PRINT COLUMN, MSB=TAPE MODE FLAG
 001C		NXA:	EQU	 +1CH	; SAVED PC FOR "NXT"
 001E		AIL:	EQU	 +1EH	; START ADDRESS OF "IL"
 0020		BASIC:	EQU	 +20H	; START ADDRESS OF BASIC PROGRAM
 0022		STACK:	EQU	 +22H	; HIGHEST ADDRESS OF USER RAM
 0024		MEND:	EQU	 +24H	; END OF BASIC PROGRAM + STACK RESERVE
 0026		TOPS:	EQU	 +26H	; TOP OF GOSUB STACK
 0028		LINO:	EQU	 +28H	; CURRENT BASIC PROGRAM LINE NUMBER
 002A		WORK:	EQU	 +2AH	; MISC. TEMPORARY STORAGE (4 BYTES)
 002E		SP:	EQU	 +2EH	; SAVED POINTER
 1030		LINE:	EQU  PAGE+30H	; INPUT LINE BUFFER (BOTTOM; 80 BYTES)
 0080		AESTK:	EQU	 +80H	; ARITHMETIC EXECUTION STACK (TOP)
		;		 +82H	; BASIC VARIABLE A
		;		 +84H	; BASIC VARIABLE B
		;		 ...	;	...
		;		 +B4H	; BASIC VARIABLE Z
		;	     PAGE+B6H	; INTERPRETER TEMPORARIES (18 BYTES)
 10B8		SAVEREG:EQU PAGE+0B8H	; MONITOR: SAVED REGISTERS START
 00DF		SAVEND: EQU	+0DFH	;	SAVED REGISTERS END
 1100		USER:	EQU PAGE+100H	; START OF USER'S BASIC PROGRAM        

SOURCE FILE NAME: TB-MON.ASM					    PAGE  3


		;
		; EXECUTION BEGINS AT 0000H, FOLLOWING A POWER-ON RESET.  
		;	THE FIRST 3 BYTES CONTAIN A LONG BRANCH TO THE
		;	IDIOT MONITOR. TO ENTER BASIC, THE MONITOR THEN 
		;	BRANCHES TO "COLD" OR "WARM" START.
		;
 0000			ORG 0
 0000 71		DIS		; DISABLE INTERRUPTS
 0001 00		DB   0
 0002 E4		SEX  R4 	; SET X=R4
 0003 C00800		LBR  SAVER	; GO SAVE REGISTERS
 0006 C00940	KEYBD:	LBR  TTYRED	; JUMP TO KEY-INPUT ROUTINE
 0009 C009A4	TYPED:	LBR  TYPE	; JUMP TO KEY-OUTPUT ROUTINE
 000C C00666	TBRK:	LBR  TSTBR	; JUMP TO BREAK-DETECTION ROUTINE
 000F 08		DB   08H	; "BACKSPACE" CHARACTER
 0010 18		DB   18H	; "CANCEL" CHARACTER
 0011					; (ANY BUT 0AH, ODH, FFH, 00H)
 0011 82		DB   82H	; PAD CODE:	   
		;	      ^-------------LSD=# OF PAD CHARS AFTER CR
		;	     ^--------------MSD=8: PAD CHAR. IS NULL (00)
		;			       =0: PAD CHAR. IS DELETE (FFH)
 0012 80		DB   80H	; TAPE MODE
 0013 20		DB   20H	; SPARE STACK
		;
		; MEMORY PEEK AND POKE SUBROUTINES
		;
 0014 97	PEEK:	DB   LDI0	; SINGLE BYTE LOAD
 0015 BA		PHI  AC 	;   HI BYTE INTO ACCUM
 0016 48		LDA  XX 	;   LO BYTE INTO D
 0017 D5		EXIT		;   RETURN
		;
 0018 58	POKE:	STR  XX 	; STORE BYTE
 0019 D5		EXIT		;   RETURN
		;
 001A 0679		DW   TBIL	; ADDRESS OF IL
 001C 1100	CONST:	DW   USER	; BEGINNING OF USER PROGRAM
 001E 00		DB   0		; WRAP POINT
 001F 10		DB   HIGH PAGE	; PAGE ADDR. HI BYTE
		;
		; EXIT TO MACHINE-LANGUAGE MONITOR
		;
 0020 C0066F		LBR  MONITOR
		;
		; CPU I/O BIT ACCESS (EF1-4, Q)
		;
 0023 C00BFE		LBR  IOBIT
		;
		; I/O PORT ACCESS (IN1-7, OUT1-7)
		;
 0026 C00651		LBR  IO

SOURCE FILE NAME: TB-MON.ASM					    PAGE  4


		;---------------------------------------;
		;	COMMONLY-USED SUBROUTINES	; 
		;---------------------------------------;
		;
		; STANDARD CALL - USES R4 AS ITS PROGRAM COUNTER
		;
 0029 D3		SEP  R3 	; < EXIT:
 002A BF	CALL:	PHI  X		; > ENTRY: SAVE D
 002B E2		SEX  R2 	;   PUSH R6 ONTO STACK
 002C 86		GLO  R6
 002D 73		STXD
 002E 96		GHI  R6
 002F 73		STXD
 0030 83		GLO  R3 	;   SAVE OLD R3 IN R6
 0031 A6		PLO  R6
 0032 93		GHI  R3
 0033 B6		PHI  R6
 0034 46		LDA  R6 	;   LOAD SUBROUTINE
 0035 B3		PHI  R3 	;     ADDRESS INTO R3
 0036 46		LDA  R6
 0037 A3		PLO  R3
 0038 9F		GHI  X		;   RESTORE D
 0039 3029		BR   CALL-1	;   ...AND GO TO EXIT
		;
		; STANDARD RETURN - USES R5 AS ITS PROGRAM COUNTER
		;
 003B D3		SEP  R3 	; < EXIT:
 003C BF	RETRN:	PHI  X		; > ENTRY: SAVE D
 003D E2		SEX  R2 	;   COPY R6 INTO R3
 003E 96		GHI  R6
 003F B3		PHI  R3
 0040 86		GLO  R6
 0041 A3		PLO  R3
 0042 12		INC  R2 	;   POP R6 FROM STACK
 0043 42		LDA  R2
 0044 B6		PHI  R6
 0045 02		LDN  R2
 0046 A6		PLO  R6
 0047 9F		GHI  X		;   RESTORE D
 0048 303B		BR   RETRN-1	;   ...AND GO TO EXIT
		;
		; BASE PAGE RAM FETCH - USES R7 AS ITS PROGRAM COUNTER 
		;
 004A D3		SEP  R3 	; < EXIT:
 004B 43	FETCH:	LDA  R3 	; > ENTRY: SET PZ POINTER
 004C AD		PLO  PZ 	;     TO BASE PAGE
 004D F810		LDI  HIGH PAGE	;     PLUS OFFSET (FROM CALLER)
 004F BD		PHI  PZ
 0050 4D		LDA  PZ 	;   GET BYTE @ POINTER
 0051 ED		SEX  PZ 	;   INCREMENT PZ POINTER
 0052 304A		BR   FETCH-1	;   ...AND GO TO EXIT

SOURCE FILE NAME: TB-MON.ASM					    PAGE  5


		;---------------------------------------;
		;	OPCODE TABLE			;
		;---------------------------------------;
 0054 0198	TABLE:	DW  BACK
 0056 01A0		DW  HOP
 0058 021F		DW  MATCH
 005A 01DD		DW  TSTV
 005C 01F0		DW  TSTN
 005E 01D4		DW  TEND
 0060 0481		DW  RTN
 0062 0249		DW  HOOK
 0064 00ED		DW  WARM
 0066 044E		DW  XINIT
 0068 0104		DW  CLEAR
 006A 05A2		DW  INSRT
 006C 01D3		DW  RETN
 006E 01D3		DW  RETN
 0070 04AA		DW  GETLN
 0072 01D3		DW  RETN
 0074 01D3		DW  RETN
 0076 02C5		DW  STRNG
 0078 02D5		DW  CRLF
 007A 0303		DW  TAB
 007C 0279		DW  PRS
 007E 0318		DW  PRN
 0080 053C		DW  LIST
 0082 01D3		DW  RETN
 0084 0429		DW  NXT
 0086 036C		DW  CMPR
 0088 03CB		DW  IDIV
 008A 03A7		DW  IMUL
 008C 0398		DW  ISUB
 008E 039B		DW  IADD
 0090 040E		DW  INEG
 0092 0460		DW  XFER
 0094 046D		DW  RSTR
 0096 0581		DW  SAV
 0098 01B6		DW  STORE
 009A 0267		DW  IND
 009C 0348		DW  RSBP
 009E 034B		DW  SVBP
 00A0 01D3		DW  RETN
 00A2 01D3		DW  RETN
 00A4 01C9		DW  BPOP
 00A6 01C5		DW  APOP
 00A8 024E		DW  DUPS
 00AA 0244		DW  LITN
 00AC 0241		DW  LIT1
 00AE 01D3		DW  RETN
 00B0		TBEND:	EQU $		; OPCODES BACKWARDS FROM HERE

SOURCE FILE NAME: TB-MON.ASM					    PAGE  6


		;-----------------------------------------------;
		;	COLD & WARM START INITIALIZATION	;
		;-----------------------------------------------;
		;
		; COLD START; ENTRY FOR "NEW?" = YES
		;
 00B0 F8B3	COLD:	LDI  LOW $+3	; CHANGE PROGRAM COUNTER
 00B2 A3		PLO  R3 	;   FROM R0 TO R3
 00B3 F800		LDI  HIGH $
 00B5 B3		PHI  R3
 00B6 D3		SEP  R3
		; DETERMINE SIZE OF USER RAM
 00B7 BA		PHI  AC 	; GET LOW END ADDR.
 00B8 F81C		LDI  LOW CONST	;   OF USER PROGRAM
 00BA AA		PLO  AC 	;   RAM (AT "CONST")
 00BB 4A		LDA  AC
 00BC B2		PHI  R2 	; ..AND PUT IN R2
 00BD 4A		LDA  AC
 00BE A2		PLO  R2
 00BF 4A		LDA  AC 	; SET PZ TO WRAP POINT
 00C0 BD		PHI  PZ 	;   (END OF SEARCH)
 00C1 F800		LDI  0
 00C3 AD		PLO  PZ
 00C4 0D		LDN  PZ 	; ..AND SAVE BYTE
 00C5 BF		PHI  X		;   NOW AT ADDR. PZ
 00C6 E2	SCAN:	SEX  R2 	; REPEAT TO SEARCH RAM..
 00C7 12		INC  R2 	; - GET NEXT BYTE
 00C8 F0		LDX
 00C9 AF		PLO  X		; - SAVE A COPY
 00CA FBFF		XRI  0FFH	; - COMPLEMENT IT
 00CC 52		STR  R2 	; - STORE IT
 00CD F3		XOR		; - SEE IF IT WORKED
 00CE ED		SEX  PZ
 00CF C6		LSNZ		; - IF MATCHES, IS RAM
 00D0 9F		GHI  X		;     SET CARRY IF AT
 00D1 F3		XOR		;     WRAP POINT..
 00D2 FCFF		ADI  0FFH	; - ELSE IS NOT RAM
 00D4 8F		GLO  X		;     RESTORE ORIGINAL BYTE
 00D5 52		STR  R2
 00D6 3BC6		BNF  SCAN	; - ..UNTIL END OR WRAP POINT
 00D8 22		DEC  R2
 00D9 0A		LDN  AC 	; RAM SIZED: SET
 00DA BD		PHI  PZ 	;   POINTER PZ TO
 00DB F823		LDI  STACK+1	;   WORK AREA
 00DD AD		PLO  PZ
 00DE 82		GLO  R2 	; STORE RAM END ADDRESS
 00DF 73		STXD
 00E0 92		GHI  R2
 00E1 73		STXD		; GET & STORE RAM BEGINNIG
 00E2 2A		DEC  AC 	; REPEAT TO COPY PARAMETERS..
 00E3 2A		DEC  AC 	; - POINT TO NEXT

SOURCE FILE NAME: TB-MON.ASM					    PAGE  7


 00E4 0A		LDN  AC 	; - GET PARAMETER
 00E5 73		STXD		; - STORE IN WORK AREA
 00E6 8D		GLO  PZ
 00E7 FB12		XRI  BS-1	; - TEST FOR LAST PARAMETER
 00E9 3AE3		BNZ  $-6	; - ..UNTIL LAST COPIED
 00EB F6		SHR		; SET DF=0 FOR "CLEAR"
 00EC C8		LSKP
		;
		; WARM START: ENTRY FOR "NEW?" = NO
		;
 00ED FF00	WARM:	SMI  0		; SET DF=1 FOR "DON'T CLEAR"
 00EF F8F2		LDI  $+3
 00F1 A3		PLO  R3 	; BE SURE PROGRAM COUNTER IS R3
 00F2 F800		LDI  HIGH $
 00F4 B3		PHI  R3
 00F5 D3		SEP  R3
 00F6 B4		PHI  R4 	; INITIALIZE R4, R5, R7
 00F7 B5		PHI  R5
 00F8 B7		PHI  R7
 00F9 F82A		LDI  CALL
 00FB A4		PLO  R4
 00FC F83C		LDI  RETRN
 00FE A5		PLO  R5
 00FF F84B		LDI  FETCH
 0101 A7		PLO  R7
 0102 331A		BDF  PEND	; IF COLD START,
 0104 D720	CLEAR:	DB   FECH,BASIC ; - MARK PROGRAM EMPTY
 0106 BB		PHI  BP
 0107 4D		LDA  PZ
 0108 AB		PLO  BP
 0109 97		DB   LDI0	;   WITH LINE# = 0
 010A 5B		STR  BP
 010B 1B		INC  BP
 010C 5B		STR  BP
 010D D716		DB   FECH,SPARE-1; - SET MEND = START + SPARE
 010F 8B		GLO  BP 	;   GET START
 0110 F4		ADD		;   ADD LOW BYTE OF SPARE
 0111 BF		PHI  X		;   SAVE TEMPORARILY
 0112 D724		DB   FECH,MEND	;   GET MEND
 0114 9F		GHI  X
 0115 73		STXD		;   STORE LOW BYTE OF MEND
 0116 9B		GHI  BP
 0117 7C00		ADCI 0		;   ADD CARRY
 0119 73		STXD		;   STORE HIGH BYTE OF MEND
 011A D722	PEND:	DB   FECH,STACK ; SET STACK TO END OF MEMORY
 011C B2		PHI  R2
 011D 4D		LDA  PZ
 011E A2		PLO  R2
 011F D726		DB   FECH,TOPS
 0121 82		GLO  R2 	; SET TOPS TO EMPTY
 0122 73		STXD		; (I.E. STACK END)

SOURCE FILE NAME: TB-MON.ASM					    PAGE  8


 0123 92		GHI  R2
 0124 73		STXD
 0125 D402CC		CALL FORCE	; SET TAPE MODE "OFF"
 0128 D71E	IIL:	DB   FECH,AIL	; SET IL PC
 012A B9		PHI  PC
 012B 4D		LDA  PZ
 012C A9		PLO  PC 	; CONTINUE INTO "NEXT"
		;
		; EXECUTE NEXT INTERMEDIATE LANGUAGE (IL) INSTRUCTION
		;
 012D E2	NEXT:	SEX  R2 	; GET OPCODE
 012E 49		LDA  PC
 012F FF30		SMI  30H	; IF JUMP OR BRANCH,
 0131 334B		BDF  TBR	;   GO HANDLE IT
 0133 FDD7		SDI  0D7H	; IF STACK BYTE EXCHANGE,
 0135 3385		BDF  XCHG	;   GO HANDLE IT
 0137 FE		SHL		; ELSE MULTIPLY BY 2
 0138 FCB0		ADI  TBEND	;   TO POINT INTO TABLE
 013A A6		PLO  R6
 013B F82D		LDI  LOW NEXT	; & SET RETURN TO HERE
 013D 22		DEC  R2 	; (DUMMY STACK ENTRY)
 013E 22		DEC  R2
 013F 73		STXD
 0140 93		GHI  R3
 0141 73		STXD
 0142 97	DOIT:	GHI  R7 	; TABLE PAGE
 0143 B6		PHI  R6
 0144 46		LDA  R6 	; FETCH SERVICE ADDRESS
 0145 52		STR  R2
 0146 46		LDA  R6
 0147 A6		PLO  R6
 0148 F0		LDX
 0149 B6		PHI  R6
 014A D5		SEP  R5 	; GO DO IT
		;
 014B FF10	TBR:	SMI  10H	; IF JUMP OR CALL,
 014D 3B6A		BNF  TJMP	;   GO DO IT
 014F A6		PLO  R6 	; ELSE BRANCH; SAVE OPCODE
 0150 FA1F		ANI  1FH	;   COMPUTE DESTINATION
 0152 325C		BZ   TBERR	;   IF BRANCH ADDR = 0, GOTO ERROR
 0154 52		STR  R2 	; PUSH ADDRESS ONTO STACK 
 0155 89		GLO  PC 	; ADD RELATIVE OFFSET
 0156 F4		ADD		;   LOW BYTE
 0157 73		STXD
 0158 99		GHI  PC 	;   HIGH BYTE W. CARRY
 0159 7C00		ADCI 0
 015B 38		SKP
 015C 73	TBERR:	STXD		; STORE 0 FOR ERROR
 015D 73		STXD
 015E 86		GLO  R6 	; NOW COMPUTE SERVICE ADDRESS
 015F F6		SHR		;   WHICH IS HIGH 3 BITS

SOURCE FILE NAME: TB-MON.ASM					    PAGE  9


 0160 F6		SHR
 0161 F6		SHR
 0162 F6		SHR
 0163 FAFE		ANI  0FEH
 0165 FC54		ADI  LOW TABLE	;   INDEX INTO TABLE
 0167 A6		PLO  R6
 0168 3042		BR   DOIT
		;
 016A FC08	TJMP:	ADI  8		; NOTE IF JUMP IN CARRY
 016C FA07		ANI  7		; GET ADDRESS
 016E B6		PHI  R6
 016F 49		LDA  PC
 0170 A6		PLO  R6
 0171 337A		BDF  JMP	; JUMP
 0173 89		GLO  PC 	; PUSH PC
 0174 73		PUSH
 0175 99		GHI  PC
 0176 73		PUSH
 0177 D40237		CALL STEST	; CHECK STACK DEPTH
		;
 017A D71E	JMP:	DB   FECH,AIL	; ADD JUMP ADDRESS TO IL BASE
 017C 86		GLO  R6
 017D F4		ADD
 017E A9		PLO  PC
 017F 96		GHI  R6
 0180 2D		DEC  PZ
 0181 74		ADC
 0182 B9		PHI  PC
 0183 302D		BR   NEXT
		;
 0185 FD07	XCHG:	SDI  7		; SAVE OFFSET
 0187 52		STR  R2
 0188 D71A		DB   FECH,AEPTR
 018A AD		PLO  PZ
 018B E2		SEX  R2
 018C F4		ADD
 018D A6		PLO  R6 	; R6 IS OTHER POINTER
 018E 9D		GHI  PZ
 018F B6		PHI  R6
 0190 0D		LDN  PZ 	; NOW SWAP THEM:
 0191 52		STR  R2 	;  SAVE OLD TOP
 0192 06		LDN  R6 	; GET INNER BYTE
 0193 5D		STR  PZ 	;  PUT ON TOP
 0194 02		LDN  R2 	; GET OLD TOP
 0195 56		STR  R6 	;  PUT IN
 0196 302D		BR   NEXT
		;
 0198 86	BACK:	GLO  R6 	; REMOVE OFFSET
 0199 FF20		SMI  20H	;   FOR BACKWARDS HOP
 019B A6		PLO  R6
 019C 96		GHI  R6

SOURCE FILE NAME: TB-MON.ASM					    PAGE 10


 019D 7F00		SMBI 0
 019F 38		SKP
		;
 01A0 96	HOP:	GHI  R6 	; FORWARD HOP
 01A1 C2027F	BZERR:	LBZ  ERR	; IF ZERO, GOTO ERROR
 01A4 B9		PHI  PC 	; ELSE PUT INTO PC
 01A5 86		GLO  R6
 01A6 A9		PLO  PC
 01A7 302D		BR   NEXT
		;
 01A9 1B		INC  BP 	; ADVANCE TO NEXT NON-BLANK CHAR.
 01AA 0B	NONBL:	LDN  BP 	; GET CHARACTER
 01AB FF20		SMI  20H	; IF BLANK,
 01AD 32A9		BZ   NONBL-1	;   INCREMENT POINTER AND TRY AGAIN
 01AF FF10		SMI  10H	; IF NUMERIC (0-9),
 01B1 C7		LSNF
 01B2 FD09		SDI  9		;   SET DF=1
 01B4 0B	NONBX:	LDN  BP 	;   GET CHARACTER
 01B5 D5		EXIT		;   AND RETURN
		;
 01B6 D401C5	STORE:	CALL APOP	; GET VARIABLE
 01B9 4D		LDA  PZ 	; GET POINTER
 01BA AD		PLO  PZ
 01BB 9A		GHI  AC 	; STORE THE NUMBER
 01BC 5D		STR  PZ
 01BD 1D		INC  PZ
 01BE 8A		GLO  AC
 01BF 5D		STR  PZ
 01C0 30C9		BR   BPOP	; GO POP POINTER
		;
 01C2 D401C5		CALL APOP	; POP 4 BYTES
 01C5 D401C9	APOP:	CALL BPOP	; POP 2 BYTES
 01C8 BA		PHI  AC 	;   FIRST BYTE TO AC.1
 01C9 D71A	BPOP:	DB   FECH,AEPTR ; POP 1 BYTE
 01CB 2D		DEC  PZ
 01CC FC01		ADI  1		; INCREMENT
 01CE 5D		STR  PZ
 01CF AD		PLO  PZ
 01D0 2D		DEC  PZ
 01D1 4D		LDA  PZ 	; LEAVE IT IN D
 01D2 AA		PLO  AC 	;   AND AC.0
 01D3 D5	RETN:	EXIT
		;
 01D4 D401AA	TEND:	CALL NONBL	; GET NEXT CHARACTER
 01D7 FB0D		XRI  0DH	; IF CARRIAGE RETURN,
 01D9 322D		BZ   NEXT	;   THEN FALL THRU IN IL
 01DB 30A0		BR   HOP	;   ELSE TAKE BRANCH
		;
 01DD D401AA	TSTV:	CALL NONBL	; GET NEXT CHARACTER
 01E0 FF41		SMI  41H	; IF LESS THAN 'A',
 01E2 3BA0		BNF  HOP	;   THEN HOP

SOURCE FILE NAME: TB-MON.ASM					    PAGE 11


 01E4 FF1A		SMI  1AH	; IF GREATER THAN 'Z'
 01E6 33A0		BDF  HOP	;   THEN HOP
 01E8 1B		INC  BP 	; ELSE IS LETTER A-Z
 01E9 9F		GHI  X		;   GET SAVED COPY
 01EA FE		SHL		;   CONVERT TO VARIABLE'S ADDRESS
 01EB D40259		CALL BPUSH	;   AND PUSH ONTO STACK
 01EE 302D		BR   NEXT
		;
 01F0 D401AA	TSTN:	CALL NONBL	; GET NEXT CHARACTER
 01F3 3BA0		BNF  HOP	; IF NOT A DIGIT, HOP
 01F5 97		DB   LDI0	; ELSE COMPUTE NUMBER
 01F6 BA		PHI  AC 	;   INITIALLY 0
 01F7 AA		PLO  AC
 01F8 D40254		CALL APUSH	;   PUSH ONTO STACK
 01FB 4B	NUMB:	LDA  BP 	; GET CHARACTER
 01FC FA0F		ANI  0FH	; CONVERT FROM ASCII TO NUMBER
 01FE AA		PLO  AC
 01FF 97		DB   LDI0
 0200 BA		PHI  AC
 0201 F80A		LDI  10 	; ADD 10 TIMES THE..
 0203 AF		PLO  X
 0204 ED		SEX  PZ
 0205 1D	NM10:	INC  PZ
 0206 8A		GLO  AC 	; ..PREVIOUS VALUE..
 0207 F4		ADD
 0208 AA		PLO  AC
 0209 9A		GHI  AC
 020A 2D		DEC  PZ 	; ..WHICH IS ON STACK.
 020B 74		ADC
 020C BA		PHI  AC
 020D 2F		DEC  X		; COUNT THE ITERATIONS
 020E 8F		GLO  X
 020F 3A05		BNZ  NM10
 0211 9A		GHI  AC 	; SAVE NEW VALUE
 0212 5D		STR  PZ
 0213 1D		INC  PZ
 0214 8A		GLO  AC
 0215 73		STXD
 0216 D401AA		CALL NONBL	; IF ANY MORE DIGITS,
 0219 C301FB		LBDF NUMB	;   THEN DO IT AGAIN
 021C C0012D	NHOP:	LBR  NEXT	; UNTIL DONE
		;
 021F 9B	MATCH:	GHI  BP 	; SAVE PB IN CASE NO MATCH
 0220 BA		PHI  AC
 0221 8B		GLO  BP
 0222 AA		PLO  AC
 0223 D401AA	MAL:	CALL NONBL	; GET A BYTE (IN CAPS)
		;
 0226 1B		INC  BP 	; COMPARE THEM
 0227 52		STR  R2
 0228 49		LDA  PC

SOURCE FILE NAME: TB-MON.ASM					    PAGE 12


 0229 F3		XOR
 022A 3223		BZ   MAL	; STILL EQUAL
 022C FB80		XRI  80H	; END?
 022E 321C		BZ   NHOP	; YES
 0230 9A		GHI  AC 	; NO GOOD
 0231 BB		PHI  BP 	; PUT POINTER BACK
 0232 8A		GLO  AC
 0233 AB		PLO  BP
 0234 C001A0	JHOP:	LBR  HOP	; THEN TAKE BRANCH
		;
 0237 D724	STEST:	DB   FECH,MEND	; POINT TO PROGRAM END
 0239 82		GLO  R2 	; COMPARE TO STACK TOP
 023A F5		SD
 023B 2D		DEC  PZ
 023C 92		GHI  R2
 023D 75		SDB
 023E 337F		BDF  ERR	; AHA; OVERFLOW
 0240 D5		EXIT		; ELSE EXIT
		;
 0241 49	LIT1:	LDA  PC 	; ONE BYTE
 0242 3059		BR   BPUSH
 0244 49	LITN:	LDA  PC 	; TWO BYTES
 0245 BA		PHI  AC 	; FIRST IS HIGH BYTE,
 0246 49		LDA  PC 	;   THEN LOW BYTE
 0247 3055		BR   APUSH+1	; PUSH RESULT ONTO STACK
		;
 0249 D40525	HOOK:	CALL HOOP	; GO DO IT, LEAVE EXIT HERE
 024C 3055		BR   APUSH+1	; PUSH RESULT ONTO STACK
		;
 024E D401C5	DUPS:	CALL APOP	; POP 2 BYTES INTO AC
 0251 D40254		CALL APUSH	; THEN PUSH TWICE
 0254 8A	APUSH:	GLO  AC 	; PUSH 2 BYTES
 0255 D40259		CALL BPUSH
 0258 9A		GHI  AC
 0259 52	BPUSH:	STR  R2 	; PUSH ONE BYTE (IN D)
 025A D719		DB   FECH,LEND	; CHECK FOR OVERFLOW
 025C F7		SM		; COMPARE AEPTR TO LEND
 025D 337F		BDF  ERR	; OOPS!
 025F F801		LDI  1
 0261 F5		SD
 0262 5D		STR  PZ 	
 0263 AD		PLO  PZ
 0264 02		LDN  R2 	; GET SAVED BYTE
 0265 5D		STR  PZ 	; STORE INTO STACK
 0266 D5	SEP5:	EXIT		; & RETURN
		;
 0267 D401C9	IND:	CALL BPOP	; GET POINTER
 026A AD		PLO  PZ
 026B 4D		LDA  PZ 	; GET VARIABLE
 026C BA		PHI  AC
 026D 4D		LDA  PZ

SOURCE FILE NAME: TB-MON.ASM					    PAGE 13


 026E 3055		BR   APUSH+1	; GO PUSH IT
		;
 0270 FB2F	QUOTE:	XRI  2FH	; TEST FOR QUOTE
 0272 3266		BZ   SEP5	; IF QUOTE, GO EXIT
 0274 FB22		XRI  22H	;   ELSE RESTORE CHARACTER
 0276 D402F4		CALL TYPER
 0279 4B	PRS:	LDA  BP 	; GET NEXT BYTE
 027A FB0D		XRI  0DH	; IF NOT CARRIAGE RETURN,
 027C 3A70		BNZ  QUOTE	;   THEN CONTINUE
 027E 29		DEC  PC 	;   ELSE CONTINUE INTO ERROR
		;
 027F D718	ERR:	DB   FECH,XEQ	; ERROR:
 0281 B8		PHI  XX 	; SAVE XEQ FLAG
 0282 D402CC		CALL FORCE	; TURN TAPE MODE OFF
 0285 F821		LDI  "!"	; PRINT "!" ON NEW LINE
 0287 D402F4		CALL TYPER
 028A D71E		DB   FECH,AIL
 028C 89		GLO  PC 	; CONVERT IL PC TO ERROR#
 028D F7		SM		;   BY SUBTRACTING
 028E AA		PLO  AC 	;   IL START FROM PC
 028F 99		GHI  PC
 0290 2D		DEC  PZ 	; X MUST POINT TO
 0291 77		SMB		;   PAGE0 REGISTER PZ=RD
 0292 BA		PHI  AC
 0293 D40315		CALL PRNA	; PRINT ERROR#
 0296 98		GHI  XX 	; GET XEQ FLAG
 0297 32A9		BZ   BELL	; IF XEQ SET,
 0299 F8BD		LDI  LOW ATMSG	; - THEN TYPE "AT"
 029B A9		PLO  PC
 029C 93		GHI  R3
 029D B9		PHI  PC
 029E D402C5		CALL STRNG
 02A1 D728		DB   FECH,LINO	; - GET LINE NUMBER
 02A3 BA		PHI  AC 	; - AND PRINT IT, TOO
 02A4 4D		LDA  PZ
 02A5 AA		PLO  AC
 02A6 D40315		CALL PRNA
 02A9 F807	BELL:	LDI  7		; RING THE BELL
 02AB D41009		CALL TYPEV
 02AE D402D5		CALL CRLF	; PRINT <CR><LF>
 02B1 D71A	FIN:	DB   FECH,TTYCC-1
 02B3 97		DB   LDI0	; TURN TAPE MODE OFF
 02B4 5D		STR  PZ
 02B5 D726	EXIT:	DB   FECH,TOPS	; RESET STACK POINTER
 02B7 B2		PHI  R2
 02B8 4D		LDA  PZ
 02B9 A2		PLO  R2
 02BA C00128		LBR  IIL	; RESTART IL FROM BEGINNING
		;
 02BD 20415420	ATMSG:	DB   ' AT ',0A3H; ERROR MESSAGE TEMPLATE
		;

SOURCE FILE NAME: TB-MON.ASM					    PAGE 14


 02C2 D402F2	TSTR:	CALL TYPER-2	; PRINT CHARACTER STRING
 02C5 49	STRNG:	LDA  PC 	; GET NEXT CHARACTER OF STRING
 02C6 FC80		ADI  80H	; IF HI BIT=0,
 02C8 3BC2		BNF  TSTR	;   THEN GO PRINT & CONTINUE
 02CA 30F2		BR   TYPER-2	;   PRINT LAST CHAR AND EXIT
		;
 02CC D719	FORCE:	DB   FECH,AEPTR-1
 02CE F880		LDI  AESTK	; CLEAR A.E.STACK
 02D0 73		STXD
 02D1 97		DB   LDI0	; SET "NOT EXECUTING"
 02D2 73		STXD		;   LEND=0 ZERO LINE LENGTH
 02D3 73		STXD		;   XEQ=0 NOT EXECUTING
 02D4 C8		LSKP		; CONTINUE TO CRLF
		;
 02D5 D71B	CRLF:	DB   FECH,TTYCC ; GET COLUMN COUNT
 02D7 FE		SHL		; IF IN TAPE MODE (MSB=1),
 02D8 3366		BDF  SEP5	;   THEN JUST EXIT
 02DA D715		DB   FECH,PAD	; GET # OF PAD CHARS
 02DC AA		PLO  AC 	;   & SAVE IT
 02DD F80D		LDI  0DH	; TYPE <CR>
 02DF D41009	PADS:	CALL TYPEV
 02E2 D71A		DB   FECH,TTYCC-1; POINT PZ TO COLUMN COUNTER
 02E4 8A		GLO  AC 	; GET # OF PADS TO GO
 02E5 FE		SHL		;   MSB SELECTS NULL OR DELETE
 02E6 32EF		BZ   PLF	; UNTIL NO MORE PADS..
 02E8 2A		DEC  AC 	;   DECREMENT # OF PADS TO GO
 02E9 97		DB   LDI0	;   PAD=NULL=0 IF MSB=0
 02EA C7		LSNF
 02EB F8FF		LDI  0FFH	;   PAD=DELETE=FFH IF MSB=1
 02ED 30DF		BR   PADS	;   ..REPEAT
		;
 02EF 73	PLF:	STXD		; SET COLUMN COUNTER TTYCC=0
 02F0 F88A		LDI  8AH	; TYPE <LF>
		;
 02F2 FF80		SMI  80H	; FIX HI BIT
 02F4 BF	TYPER:	PHI  X		; SAVE CHAR
 02F5 D71B		DB   FECH,TTYCC ; CHECK OUTPUT MODE
 02F7 2D		DEC  PZ
 02F8 FC81		ADI  81H	; INCREMENT COLUMN COUNTER TTYCC
 02FA FC80		ADI  80H	;   WITHOUT DISTURBING MSB
 02FC 3B66		BNF  SEP5	; IF MSB=1, IN TAPE MODE, NOT PRINTING
 02FE 5D		STR  PZ 	;   ELSE UPDATE COLUMN COUNTER
 02FF 9F		GHI  X		;   GET CHAR
 0300 C01009		LBR  TYPEV	;   AND GO TYPE IT
		;
 0303 D71B	TAB:	DB   FECH,TTYCC ; GET COLUMN COUNT
 0305 FA07		ANI  7		; LOW 3 BITS
 0307 FD08		SDI  8		; SUBTRACT FROM 8 TO GET
 0309 AA		PLO  AC 	;   NUMBER OF SPACES TO NEXT TAB
 030A 8A	TABS:	GLO  AC
 030B 3297		BZ   SKIP+1	; UNTIL 0..

SOURCE FILE NAME: TB-MON.ASM					    PAGE 15


 030D F820		LDI  ' '	;   PRINT A SPACE
 030F D402F4		CALL TYPER
 0312 2A		DEC  AC 	;   DECREMENT SPACES TO GO
 0313 300A		BR   TABS	;   ...REPEAT
		;
 0315 D40254	PRNA:	CALL APUSH	; NUMBER IN AC
 0318 D71A	PRN:	DB   FECH,AEPTR ; CHECK SIGN
 031A AD		PLO  PZ
 031B D40413		CALL DNEG	; IF NEGATIVE,
 031E 3B25		BNF  PRP
 0320 F82D		LDI  '-'	;   PRINT '-'
 0322 D402F4		CALL TYPER
 0325 97	PRP:	DB   LDI0	; PUSH ZERO FLAG
 0326 73		STXD		;   WHICH MARKS NUMBER END
 0327 BA		PHI  AC 	; PUSH 10 (=DIVISOR)
 0328 F80A		LDI  10
 032A D40255		CALL APUSH+1
 032D 1D		INC  PZ
 032E D403E3	PDVL:	CALL PDIV	; DIVIDE BY 10
 0331 8A		GLO  AC 	; REMAINDER IS NEXT DIGIT
 0332 F6		SHR		; BUT DOUBLED; HALVE IT
 0333 F930		ORI  30H	; CONVERT TO ASCII
 0335 73		STXD		; PUSH IT
 0336 1D		INC  PZ 	; IS QUOTIENT=0?
 0337 4D		LDA  PZ
 0338 ED		SEX  PZ
 0339 F1		OR
 033A 2D		DEC  PZ 	; RESTORE POINTER
 033B 2D		DEC  PZ
 033C 3A2E		BNZ  PDVL	; ..REPEAT
 033E 12	PRNL:	INC  R2 	; NOW, TO PRINT IT
 033F 02		LDN  R2 	; GET CHAR
 0340 C201C2		LBZ  APOP-3	; UNTIL ZERO (END FLAG)..
 0343 D402F4		CALL TYPER	;   PRINT IT
 0346 303E		BR   PRNL	;   ..REPEAT
		;
 0348 D72E	RSBP:	DB   FECH,SP	; GET SP
 034A 38		SKP
 034B 9B	SVBP:	GHI  BP 	; GET BP
 034C FB10		XRI  HIGH LINE	; IN THE LINE?
 034E 3A5E		BNZ  SWAP	; NO, NOT IN SAME PAGE
 0350 8B		GLO  BP
 0351 52		STR  R2
 0352 F0		LDX
 0353 FF80		SMI  LOW AESTK
 0355 335E		BDF  SWAP	; NO, BEYOND ITS END
 0357 D72E		DB   FECH,SP
 0359 8B		GLO  BP 	; YES, JUST COPY BP TO SP
 035A 73		STXD
 035B 9B		GHI  BP
 035C 5D		STR  PZ

SOURCE FILE NAME: TB-MON.ASM					    PAGE 16


 035D D5	TYX:	EXIT
		;
 035E D72E	SWAP:	DB   FECH,SP	; EXCHANGE BP AND SP
 0360 B8		PHI  XX 	; PUT SP IN TEMP
 0361 0D		LDN  PZ
 0362 A8		PLO  XX
 0363 8B		GLO  BP 	; STORE BP IN SP
 0364 73		STXD
 0365 9B		GHI  BP
 0366 5D		STR  PZ
 0367 98		GHI  XX 	; STORE TEMP IN BP
 0368 BB		PHI  BP
 0369 88		GLO  XX
 036A AB		PLO  BP
 036B D5		EXIT
		;
 036C D401C5	CMPR:	CALL APOP	; GET FIRST NUMBER
 036F 9A		GHI  AC 	; PUSH ONTO STACK WITH BIAS
 0370 FB80		XRI  80H	;   (FOR 2'S COMPLEMENT)
 0372 73		STXD		;   (BACKWARDS)
 0373 8A		GLO  AC
 0374 73		STXD
 0375 D401C9		CALL BPOP	; GET AND SAVE
 0378 AF		PLO  X		;   COMPARE BITS
 0379 D401C5		CALL APOP	; GET SECOND NUMBER
 037C 12		INC  R2
 037D 8A		GLO  AC 	; COMARE THEM
 037E F7		SM		;   LOW BYTE
 037F AA		PLO  AC
 0380 12		INC  R2
 0381 9A		GHI  AC 	;   HIGH BYTE
 0382 FB80		XRI  80H	; BIAS: 0 TO 65535 INSTEAD
 0384 77		SMB		;   OF -32768 TO +32767
 0385 52		STR  R2
 0386 3B92		BNF  CLT	; LESS IF NO CARRY OUT
 0388 8A		GLO  AC
 0389 F1		OR
 038A 328F		BZ   CEQ	; EQUAL IF BOTH BYTES 0
 038C 8F		GLO  X		; ELSE GREATER
 038D F6		SHR		; MOVE PROPER BIT
 038E 38		SKP
 038F 8F	CEQ:	GLO  X		; (BIT 1)
 0390 F6		SHR
 0391 38		SKP
 0392 8F	CLT:	GLO  X		; (BIT 0)
 0393 F6		SHR		; TO CARRY
 0394 C7		LSNF
 0395 C4		NOP
 0396 19	SKIP:	INC  PC 	; SKIP ONE BYTE IF TRUE
 0397 D5		EXIT
		;

SOURCE FILE NAME: TB-MON.ASM					    PAGE 17


 0398 D4040E	ISUB:	CALL INEG	; SUBTRACT IS ADD NEGATIVE
 039B D401C5	IADD:	CALL APOP	; PUT ADDEND IN AC
 039E ED		SEX  PZ
 039F 1D		INC  PZ 	; ADD TO AUGEND
 03A0 8A		GLO  AC
 03A1 F4		ADD
 03A2 73		STXD
 03A3 9A		GHI  AC 	; CARRY INTO HIGH BYTE
 03A4 74		ADC
 03A5 5D		STR  PZ
 03A6 D5		EXIT
		;
 03A7 D401C5	IMUL:	CALL APOP	; MULTIPLIER IN AC
 03AA F810		LDI  10H	; BIT COUNTER IN X
 03AC AF		PLO  X
 03AD 4D		LDA  PZ 	; MULTIPLICAND IN XX
 03AE B8		PHI  XX
 03AF 0D		LDN  PZ
 03B0 A8		PLO  XX
 03B1 0D	MULL:	LDN  PZ 	; SHIFT PRODUCT LEFT
 03B2 FE		SHL		;   (ON STACK)
 03B3 5D		STR  PZ
 03B4 2D		DEC  PZ
 03B5 0D		LDN  PZ
 03B6 7E		SHLC		; DISCARD HIGH 16 BITS
 03B7 5D		STR  PZ
 03B8 D40422		CALL SHAL	; GET A BIT
 03BB 3BC5		BNF  MULC	; NOT THIS TIME
 03BD ED		SEX PZ		; IF MULTIPLIER BIT=1,
 03BE 1D		INC  PZ
 03BF 88		GLO  XX 	; ADD MULTIPLICAND
 03C0 F4		ADD
 03C1 73		STXD
 03C2 98		GHI  XX
 03C3 74		ADC
 03C4 5D		STR  PZ
 03C5 2F	MULC:	DEC  X		; REPEAT 16 TIMES
 03C6 8F		GLO  X
 03C7 1D		INC  PZ
 03C8 3AB1		BNZ  MULL
 03CA D5		EXIT
		;
 03CB D401C5	IDIV:	CALL APOP	; GET DIVISOR
 03CE 9A		GHI  AC
 03CF 52		STR  R2 	; CHECK FOR DIVIDE BY ZERO
 03D0 8A		GLO  AC
 03D1 F1		OR
 03D2 C2027F		LBZ  ERR	; IF YES, FORGET IT
 03D5 0D		LDN  PZ 	; COMPARE SIGN OF DIVISOR
 03D6 F3		XOR
 03D7 73		STXD		; SAVE FOR LATER

SOURCE FILE NAME: TB-MON.ASM					    PAGE 18


 03D8 D40413		CALL DNEG	; MAKE DIVEDEND POSITIVE
 03DB 2D		DEC  PZ 	; SAME FOR DIVISOR
 03DC 2D		DEC  PZ
 03DD D40413		CALL DNEG
 03E0 1D		INC  PZ
 03E1 97		DB   LDI0
 03E2 C8		LSKP
 03E3 97	PDIV:	DB   LDI0	; MARK "NO SIGN CHANGE"    
 03E4 73		STXD		;   FOR PRN ENTRY
 03E5 AA		PLO  AC 	; CLEAR HIGH END
 03E6 BA		PHI  AC 	;   OF DIVIDEND IN AC
 03E7 F811		LDI  17 	; COUNTER TO X
 03E9 AF		PLO  X
 03EA ED	DIVL:	SEX  PZ 	; DO TRIAL SUBTRACT
 03EB 8A		GLO  AC
 03EC F7		SM
 03ED 52		STR  R2 	; HOLD LOW BYTE FOR NOW
 03EE 2D		DEC  PZ
 03EF 9A		GHI  AC
 03F0 77		SMB
 03F1 3BF6		BNF  $+5	; IF NEGATIVE, CANCEL  IT
 03F3 BA		PHI  AC 	; IF POSITIVE, MAKE IT REAL
 03F4 02		LDN  R2
 03F5 AA		PLO  AC
 03F6 1D		INC  PZ 	; SHIFT EVERYTHING LEFT
 03F7 1D		INC  PZ
 03F8 1D		INC  PZ
 03F9 F0		LDX
 03FA 7E		SHLC
 03FB 73		STXD
 03FC F0		LDX
 03FD 7E		SHLC
 03FE 73		STXD
 03FF 8A		GLO  AC 	; HIGH 16
 0400 7E		SHLC
 0401 D40424		CALL SHCL
 0404 2F		DEC  X		; DO IT 16 TIMES MORE
 0405 8F		GLO  X
 0406 CA03EA		LBNZ DIVL
 0409 12		INC  R2 	; CHECK SIGN OF QUOTIENT
 040A 02		LDN  R2
 040B FE		SHL
 040C 3B21		BNF  NEGX	; POSITIVE IS DONE
 040E D71A	INEG:	DB   FECH,AEPTR ; POINT TO STACK
 0410 AD		PLO  PZ
 0411 3018		BR   NEG
 0413 ED	DNEG:	SEX  PZ
 0414 F0		LDX		; FOR DIVIDE,
 0415 FE		SHL		;   TEST SIGN
 0416 3B21		BNF  NEGX	; IF POSITIVE, LEAVE IT ALONE
 0418 1D	NEG:	INC  PZ 	; IF NEGATIVE,

SOURCE FILE NAME: TB-MON.ASM					    PAGE 19


 0419 97		DB   LDI0	;   SUBTRACT IT FROM 0
 041A F7		SM
 041B 73		STXD
 041C 97		DB   LDI0
 041D 77		SMB
 041E 5D		STR  PZ
 041F FF00		SMI  0		;   AND SET CARRY=1
 0421 D5	NEGX:	EXIT
		;
 0422 8A	SHAL:	GLO  AC 	; USED BY MULTIPLY
 0423 FE		SHL
 0424 AA	SHCL:	PLO  AC 	;   AND DIVIDE
 0425 9A		GHI  AC
 0426 7E		SHLC
 0427 BA		PHI  AC
 0428 D5		EXIT
		;
 0429 D718	NXT:	DB   FECH,XEQ	; IF DIRECT EXECUTION,
 042B C202B1		LBZ  FIN	;   QUIT WITH DF=0
 042E 4B		LDA  BP 	; ELSE SCAN TO NEXT <CR>
 042F FB0D		XRI  0DH
 0431 3A2E		BNZ  $-3
 0433 D40598		CALL GLINO	; GET LINE NUMBER
 0436 324B		BZ   BERR	;   ZERO IS ERROR
 0438 D4000C	CONT:	CALL TBRK	; TEST FOR BREAK
 043B 3346		BDF  BREAK	; IF BREAK,
 043D D71C		DB   FECH,NXA	;   RECOVER RESTART POINT
 043F B9		PHI  PC 	;   WHICH WAS SAVED BY INIT
 0440 4D		LDA  PZ
 0441 A9		PLO  PC
 0442 D717	RUN:	DB   FECH,XEQ-1 ;   TURN OFF RUN MODE
 0444 5D		STR  PZ 	;   (NON-ZERO)
 0445 D5		EXIT
 0446			;
 0446 D71E	BREAK:	DB   FECH,AIL	; SET BREAK ADDR=0
 0448 B9		PHI  PC 	;   I.E. PC=IL START
 0449 4D		LDA  PZ
 044A A9		PLO  PC
 044B C0027F	BERR:	LBR  ERR
		;
 044E D720	XINIT:	DB   FECH,BASIC ; POINT TO START OF BASIC PROGRAM
 0450 BB		PHI  BP
 0451 4D		LDA  PZ
 0452 AB		PLO  BP
 0453 D40598		CALL GLINO	; GET LINE NUMBER
 0456 324B		BZ   BERR	; IF 0, IS ERROR (NO PROGRAM)
 0458 D71C		DB   FECH,NXA	; SAVE STATEMENT
 045A 89		GLO  PC 	;   ANALYZER ADDRESS
 045B 73		STXD
 045C 99		GHI  PC
 045D 5D		STR  PZ

SOURCE FILE NAME: TB-MON.ASM					    PAGE 20


 045E 3042		BR   RUN	; GO START UP
		;
 0460 D404FE	XFER:	CALL FIND	; GET THE LINE
 0463 3238		BZ   CONT	; IF WE GOT IT, GO CONTINUE
 0465 D728	GOAL:	DB   FECH,LINO	;   ELSE FAILED
 0467 8A		GLO  AC 	;   MARK DESTINATION
 0468 73		STXD
 0469 9A		GHI  AC
 046A 5D		STR  PZ
 046B 304B		BR   BERR	;   GO HANDLE ERROR
		;
 046D D4048B	RSTR:	CALL TTOP	; CHECK FOR UNDERFLOW
 0470 42		LDA  R2 	; GET THE NUMBER
 0471 BA		PHI  AC 	;   FROM STACK INTO AC
 0472 02		LDN  R2
 0473 AA		PLO  AC
 0474 D726		DB   FECH,TOPS
 0476 82		GLO  R2 	; RESET TOPS FROM R2
 0477 73		STXD
 0478 92		GHI  R2
 0479 73		STXD
 047A D40501		CALL FIND+3	; POINT TO THIS LINE
 047D 3A65		BNZ  GOAL	; NOT THERE ANY MORE
 047F 3088		BR   BNEXT	; OK
		;
 0481 D4048B	RTN:	CALL TTOP	; CHECK FOR UNDERFLOW
 0484 42		LDA  R2 	; (2 ALREADY INCLUDED)
 0485 B9		PHI  PC 	; PIP ADDRESS TO PC
 0486 02		LDN  R2
 0487 A9		PLO  PC
 0488 C0012D	BNEXT:	LBR  NEXT
		;
 048B D722	TTOP:	DB   FECH,STACK ; GET TOP OF STACK
 048D 12		INC  R2
 048E 12		INC  R2
 048F 82		GLO  R2 	; MATCH TO STACK POINTER
 0490 FC02		ADI  2		; (ADJUSTED FOR RETURN)
 0492 F3		XOR
 0493 2D		DEC  PZ
 0494 3A9C		BNZ  TTOK	; NOT EQUAL
 0496 92		GHI  R2
 0497 7C00		ADCI 0
 0499 F3		XOR
 049A 324B		BZ   BERR	; MATCH IS EMPTY STACK
		;
 049C 12	TTOK:	INC  R2 	; (ONCE HERE SAVES TWICE)
 049D D5		EXIT
		;
 049E D716	TAPE:	DB   FECH,PAD+1 ; TURN OFF TYPEOUT
 04A0 38		SKP
 04A1 97	NTAPE:	DB   LDI0	; TURN ON TYPEOUT

SOURCE FILE NAME: TB-MON.ASM					    PAGE 21


 04A2 FE		SHL		; (FLAG TO CARRY)
 04A3 D71A		DB   FECH,TTYCC-1
 04A5 97		DB   LDI0
 04A6 76		SHRC		; 00 OR 80H
 04A7 5D		STR  PZ
 04A8 30B2		BR   KLOOP
		
 04AA F830	GETLN:	LDI  LOW LINE	; POINT TO LINE
 04AC AB		PLO  BP
 04AD D40254		CALL APUSH	; MARK STACK LIMIT
 04B0 9D		GHI  PZ
 04B1 BB		PHI  BP
 04B2 D41006	KLOOP:	CALL KEYV	; GET AN ECHOED BYTE
 04B5 FA7F		ANI  7FH	; SET HIGH BIT TO 0
 04B7 32B2		BZ   KLOOP	; IGNORE NULL
 04B9 52		STR  R2
 04BA FB7F		XRI  7FH
 04BC 32B2		BZ   KLOOP	; IGNORE DELETE
 04BE FB75		XRI  75H	; IF <LF>,
 04C0 329E		BZ   TAPE	;   THEN TURN TAPE MODE ON
 04C2 FB19		XRI  19H	; IF <XOFF> (DC3=13H),
 04C4 32A1		BZ   NTAPE	;   THEN TURN TAPE MODE OFF
 04C6 D713		DB   FECH,CAN-1
 04C8 02		LDN  R2
 04C9 F3		XOR		; IF CANCEL,
 04CA 32D7		BZ   CANCL	;   THEN GO TO CANCEL
 04CC 2D		DEC  PZ
 04CD 02		LDN  R2
 04CE F3		XOR
 04CF 3ADD		BNZ  STOK	; NO
 04D1 2B		DEC  BP 	; YES
 04D2 8B		GLO  BP
 04D3 FF30		SMI  LOW LINE	; ANYTHING LEFT?
 04D5 33B2		BDF  KLOOP	; YES
 04D7 F830	CANCL:	LDI  LOW LINE	; IF NO, CANCEL THIS LINE
 04D9 AB		PLO  BP
 04DA F80D		LDI  0DH	; BY FORCING A <CR>
 04DC 38		SKP
 04DD 02	STOK:	LDN  R2 	; STORE CHARACTER IN LINE
 04DE 5B		STR  BP
 04DF D719		DB   FECH,AEPTR-1
 04E1 8B		GLO  BP 	; CHECK FOR OVERFLOW
 04E2 F7		SM
 04E3 3BEC		BNF  CHIN	; OK
 04E5 F807		LDI  7		; IF NOT, RING BELL
 04E7 D402F4		CALL TYPER
 04EA 0B		LDN  BP 	; NOW LOOK AT CHAR
 04EB 38		SKP
 04EC 4B	CHIN:	LDA  BP 	; INCREMENT POINTER
 04ED FB0D		XRI  0DH	; IF NOT <CR>,
 04EF 3AB2		BNZ  KLOOP	;   THEN GET ANOTHER

SOURCE FILE NAME: TB-MON.ASM					    PAGE 22


 04F1 D402D5		CALL CRLF	;   ELSE ECHO <LF>
 04F4 D718		DB   FECH,LEND-1;   AND MARK END
 04F6 8B		GLO  BP
 04F7 5D		STR  PZ
 04F8 F830		LDI  LOW LINE	;   RESET BP TO FRONT
 04FA AB		PLO  BP
 04FB C001C5		LBR  APOP	;   AND GO POP DUMMY
		;
 04FE D401C5	FIND:	CALL APOP	; GET LINE NUMBER
 0501 8A		GLO  AC
 0502 52		STR  R2 	; CHECK FOR ZERO
 0503 9A		GHI  AC
 0504 F1		OR
 0505 C2027F		LBZ  ERR	; IF 0, GO TO ERROR
 0508 D720	FINDX:	DB   FECH,BASIC ; START AT FRONT
 050A BB		PHI  BP
 050B 4D		LDA  PZ
 050C AB		PLO  BP
 050D D40598	FLINE:	CALL GLINO	; GET LINE NUMBER
 0510 C6		LSNZ		; NOT THER IF 0
 0511 8D		GLO  PZ 	; SET NON-ZERO,
 0512 D5	FEND:	EXIT		;   AND RETURN
 0513 ED		SEX  PZ
 0514 8A		GLO  AC 	; COMPARE THEM
 0515 F5		SD
 0516 52		STR  R2 	; (SAVE LOW BYTE OF DIFFERENCE)
 0517 9A		GHI  AC
 0518 2D		DEC  PZ
 0519 75		SDB
 051A E2		SEX  R2
 051B F1		OR		; (D=0 IF EQUAL)
 051C 3312		BDF  FEND	; LESS OR EQUAL IS END
 051E 4B		LDA  BP 	; NOT THERE YET
 051F FB0D		XRI  0DH	; SCAN TO NEXT <CR>
 0521 3A1E		BNZ  $-3
 0523 300D		BR   FLINE
		;
 0525 D40528	HOOP:	CALL HOOP+3	; ADJUST STACK
 0528 D401C5		CALL APOP	; SET UP PARAMETERS:
 052B 4D		LDA  PZ 	;   AC
 052C B8		PHI  XX 	;   MIDDLE ARGUMENT TO XX
 052D 4D		LDA  PZ
 052E A8		PLO  XX
 052F 4D		LDA  PZ 	; SUBROUTINE ADDRESS BECOMES
 0530 B6		PHI  R6 	;   "RETURN ADDRESS"
 0531 4D		LDA  PZ
 0532 A6		PLO  R6
 0533 8D		GLO  PZ 	; FIX STACK POINTER
 0534 52		STR  R2
 0535 D719		DB   FECH,AEPTR-1
 0537 02		LDN  R2 	; BY PUTTING CURRENT VALUE

SOURCE FILE NAME: TB-MON.ASM					    PAGE 23


 0538 5D		STR  PZ 	;   VALUE BACK INTO IT
 0539 AD		PLO  PZ 	; LEAVE PZ AT STACK TOP
 053A 8A		GLO  AC 	; LEAVE AC.0 IN D
 053B D5		EXIT		; GO DO IT
		;
 053C D72C	LIST:	DB   FECH,WORK+2
 053E 8B		GLO  BP 	; SAVE POINTERS
 053F 73		STXD
 0540 9B		GHI  BP
 0541 5D		STR  PZ
 0542 D404FE		CALL FIND	; GET LIST LIMITS
 0545 D72A		DB   FECH,WORK	; SAVE UPPER
 0547 8B		GLO  BP
 0548 73		STXD
 0549 9B		GHI  BP
 054A 73		STXD
 054B D404FE		CALL FIND	; TWO ITEMS MARK BOUNDS
 054E 2B		DEC  BP 	; BACK UP OVER LINE#
 054F 2B		DEC  BP
 0550 D72A	LLINE:	DB   FECH,WORK	; END?
 0552 8B		GLO  BP
 0553 F7		SM
 0554 2D		DEC  PZ
 0555 9B		GHI  BP
 0556 77		SMB
 0557 337B		BDF  LIX	; SO IF BP>BOUNDS,
 0559 4B		LDA  BP 	;   GET LINE#
 055A BA		PHI  AC
 055B 4B		LDA  BP
 055C AA		PLO  AC
 055D 3A62		BNZ  $+5
 055F 9A		GHI  AC
 0560 327B		BZ   LIX	; QUIT IF ZERO (PROGRAM END)
 0562 D40315		CALL PRNA	; ELSE PRINT LINE#
 0565 F82D		LDI  2DH	;   THEN A SPACE
 0567 FB0D	LLOOP:	XRI  0DH	;   (RESTORE BITS FROM <CR> TEST)
 0569 D402F4		CALL TYPER
 056C D4000C		CALL TBRK	;   TEST FOR BREAK
 056F 337B		BDF  LIX	;     IF YES, THEN QUIT
 0571 4B		LDA  BP 	;   NOW PRINT TEXT
 0572 FB0D		XRI  0DH	;     UNTIL <CR>
 0574 3A67		BNZ  LLOOP
 0576 D402D5		CALL CRLF	;   END LINE WITH <CR><LF>
 0579 3050		BR   LLINE	; ..REPEAT UNTIL DONE
		;
 057B D72C	LIX:	DB   FECH,WORK+2; RESTORE BP
 057D BB		PHI  BP
 057E 4D		LDA  PZ
 057F AB		PLO  BP
 0580 D5		EXIT
		;

SOURCE FILE NAME: TB-MON.ASM					    PAGE 24


 0581 D726	SAV:	DB   FECH,TOPS	; ADJUST STACK TOP
 0583 82		GLO  R2
 0584 73		STXD
 0585 92		GHI  R2
 0586 5D		STR  PZ
 0587 D718		DB   FECH,XEQ	; IF NOT EXECUTING,
 0589 2D		DEC  PZ
 058A CE		LSZ		;   USE ZERO INSTEAD
 058B D728		DB   FECH,LINO
 058D AA		PLO  AC 	; HOLD HIGH BYTE
 058E 4D		LDA  PZ 	; GET LOW BYTE
 058F 12		INC  R2
 0590 12		INC  R2
 0591 E2		SEX  R2
 0592 73		STXD		; PUSH ONTO STACK
 0593 8A		GLO  AC 	; NOW THE HIGH BYTE
 0594 73		STXD
 0595 C0012D		LBR  NEXT
		;
 0598 D727	GLINO:	DB   FECH,LINO-1; SETUP POINTER
 059A 4B		LDA  BP 	; GET 1ST BYTE
 059B 5D		STR  PZ 	; STORE IN RAM
 059C 1D		INC  PZ
 059D 4B		LDA  BP 	; 2ND BYTE
 059E 73		STXD
 059F F1		OR		; D=0 IF LINE#=0
 05A0 1D		INC  PZ
 05A1 D5		EXIT
		;
 05A2 D4035E	INSRT:	CALL SWAP	; SAVE POINTER IN NEW LINE
 05A5 D404FE		CALL FIND	; FIND INSERT POINT
 05A8 FCFF		ADI  0FFH	; IF DONE, SET DF
 05AA 97		DB   LDI0
 05AB AF		PLO  X		; X IS SIZE DIFFERENCE
 05AC 33BA		BDF  NEW
 05AE 9B		GHI  BP 	; SAVE INSERT POINT
 05AF BD		PHI  PZ
 05B0 8B		GLO  BP
 05B1 AD		PLO  PZ
 05B2 2F		DEC  X		; MEASURE OLD LINE LENGTH
 05B3 2F		DEC  X		; -3 FOR LINE# AND <CR>
 05B4 2F		DEC  X		; REPEAT..
 05B5 4D		LDA  PZ 	;   -1 FOR EACH BYTE OF TEXT
 05B6 FB0D		XRI  0DH	; ..UNTIL <CR>
 05B8 3AB4		BNZ  $-4
 05BA 2B	NEW:	DEC  BP 	; BACK OVER LINE#
 05BB 2B		DEC  BP
 05BC D4035E		CALL SWAP	; TRADE LINE POINTERS
 05BF D728		DB   FECH,LINO
 05C1 0B		LDN  BP
 05C2 FB0D		XRI  0DH	; IF NEW LINE IS NULL,

SOURCE FILE NAME: TB-MON.ASM					    PAGE 25


 05C4 73		STXD
 05C5 5D		STR  PZ
 05C6 32D9		BZ   HMUCH	;   THEN GO MARK IT
 05C8 9A		GHI  AC 	; ELSE SAVE LINE NUMBER
 05C9 5D		STR  PZ
 05CA 1D		INC  PZ
 05CB 8A		GLO  AC
 05CC 5D		STR  PZ
 05CD 9B		GHI  BP 	; MEASURE ITS LENGTH
 05CE BA		PHI  AC
 05CF 8B		GLO  BP
 05D0 AA		PLO  AC
 05D1 1F		INC  X		;   LINE#
 05D2 1F		INC  X		;   ENDING <CR>
 05D3 1F		INC  X
 05D4 4A		LDA  AC
 05D5 FB0D		XRI  0DH	;   AND ALL CHARS UNTIL FINAL <CR>
 05D7 3AD3		BNZ  $-4
 05D9 D72E	HMUCH:	DB   FECH,SP	; FIGURE AMOUNT OF MOVE
 05DB BA		PHI  AC
 05DC 4D		LDA  PZ
 05DD AA		PLO  AC
 05DE D724		DB   FECH,MEND	; =DISTANCE FROM INSERT
 05E0 8A		GLO  AC 	;   TO END OF PROGRAM
 05E1 F7		SM
 05E2 AA		PLO  AC 	; LEAVE IT IN AC, NEGATIVE
 05E3 2D		DEC  PZ
 05E4 9A		GHI  AC
 05E5 77		SMB
 05E6 BA		PHI  AC
 05E7 1D		INC  PZ
 05E8 8F		GLO  X		; NOW COMPUTE NEW MEND,
 05E9 F4		ADD		;   WHICH IS SUM OF OFFSET,
 05EA BF		PHI  X
 05EB 8F		GLO  X
 05EC FA80		ANI  80H	;   WITH SIGN EXTEND,
 05EE CE		LSZ
 05EF F8FF		LDI  0FFH
 05F1 2D		DEC  PZ
 05F2 74		ADC		;   PLUS OLD MEND
 05F3 E2		SEX  R2
 05F4 73		STXD		;   PUSH ONTO STACK
 05F5 B8		PHI  XX
 05F6 9F		GHI  X
 05F7 73		STXD		;     (BACKWARDS)
 05F8 52		STR  R2 	; CHECK FOR OVERFLOW
 05F9 82		GLO  R2
 05FA F5		SD
 05FB 98		GHI  XX
 05FC 52		STR  R2
 05FD 92		GHI  R2

SOURCE FILE NAME: TB-MON.ASM					    PAGE 26


 05FE 75		SDB
 05FF C3027E		LBDF ERR-1	; IF YES, THEN QUIT
 0602 8F		GLO  X		; ELSE NO, PREPARE TO MOVE
 0603 3230		BZ   STUFF	; NO MOVE NEEDED
 0605 52		STR  R2
 0606 FE		SHL
 0607 3B1E		BNF  MORE	; ADD SOME SPACE
 0609 D72E		DB   FECH,SP	; DELETE SOME
 060B BF		PHI  X		; X IS DESTINATION
 060C 4D		LDA  PZ
 060D AF		PLO  X
 060E E2		SEX  R2
 060F F7		SM
 0610 A8		PLO  XX 	; XX IS SOURCE
 0611 9F		GHI  X
 0612 7C00		ADCI 0
 0614 B8		PHI  XX
 0615 48		LDA  XX 	; NOW MOVE IT
 0616 5F		STR  X
 0617 1F		INC  X
 0618 1A		INC  AC
 0619 9A		GHI  AC
 061A 3A15		BNZ  $-5
 061C 3030		BR   STUFF
 061E 9F	MORE:	GHI  X		; SET UP POINTERS
 061F AF		PLO  X		; X IS DESTINATION
 0620 98		GHI  XX
 0621 BF		PHI  X
 0622 D724		DB   FECH,MEND
 0624 B8		PHI  XX
 0625 4D		LDA  PZ
 0626 A8		PLO  XX 	; XX IS SOURCE
 0627 2A		DEC  AC
 0628 EF		SEX  X		; NOW MOVE IT
 0629 08		LDN  XX
 062A 28		DEC  XX
 062B 73		STXD
 062C 1A		INC  AC
 062D 9A		GHI  AC
 062E 3A29		BNZ  $-5
 0630 D724	STUFF:	DB   FECH,MEND	; UPDATE MEND
 0632 12		INC  R2
 0633 42		LDA  R2
 0634 73		STXD
 0635 02		LDN  R2
 0636 5D		STR  PZ
 0637 D72E		DB   FECH,SP	; POINT INTO PROGRAM
 0639 BA		PHI  AC
 063A 4D		LDA  PZ
 063B AA		PLO  AC
 063C D728		DB   FECH,LINO	; INSERT NEW LINE

SOURCE FILE NAME: TB-MON.ASM					    PAGE 27


 063E AF		PLO  X
 063F F1		OR		; IF THERE IS ONE
 0640 324E		BZ   INSX	;   NO, EXIT
 0642 8F		GLO  X		; ELSE INSERT LINE NUMBER
 0643 5A		STR  AC
 0644 1A		INC  AC
 0645 4D		LDA  PZ
 0646 5A		STR  AC
 0647 1A		INC  AC
 0648 4B		LDA  BP 	; NOW REST OF LINE
 0649 5A		STR  AC
 064A FB0D		XRI  0DH	;   TO <CR>
 064C 3A47		BNZ  $-5
 064E C002B5	INSX:	LBR  EXIT
		;
		; I/O PORT DRIVER: CALL VIA USR(38,N,B)
		;	N=1 TO 7: OUT1-7 & OUTPUT B
		;	N=9 TO 15: IN1-7 RESPECTIVELY
		;
 0651 73	IO:	STXD		; PUSH OUT BYTE
 0652 52		STR  R2
 0653 97		DB   LDI0	; CLEAR AC
 0654 BA		PHI  AC
 0655 2D		DEC  PZ
 0656 43		LDA  R3 	; STORE RETURN IN RAM
 0657 D5		SEP  R5 	; (THIS IS NOT EXECUTED)
 0658 5D		STR  PZ
 0659 2D		DEC  PZ
 065A 88		GLO  XX 	; MAKE IO INSTRUCTION
 065B FA0F		ANI  0FH
 065D F960		ORI  60H
 065F 5D		STR  PZ
 0660 FA08		ANI  8
 0662 CE		LSZ
 0663 C4		NOP		; INPUT, SO
 0664 12		INC  R2 	;   DO INCREMENT NOW
 0665 DD		SEP  PZ 	; GO EXECUTE, RESULT IN D
		;
		; TEST FOR BREAK (TO ABORT LONG LISTINGS)
		;
 0666 FC00	TSTBR:	ADI  0		; SET DF=0
 0668 376E		B4   $+6	; IF BREAK (EF4=0, SO EF4 PIN HIGH),
 066A FF00		SMI  0		;   THEN SET DF=1
 066C 3F6C		BN4  $		;   WAIT FOR EF4 PIN TO RETURN LOW
 066E D5		EXIT		; EXIT
		;
		; MONITOR: CALL IDIOT MONITOR
		;
 066F 52	MONITOR:STR  R2 	; SAVE D
 0670 F8C5		LDI  LOW INTRUPT
 0672 A1		PLO  R1 	; SET R1 TO ENTRY POINT

SOURCE FILE NAME: TB-MON.ASM					    PAGE 28


 0673 F808		LDI  HIGH INTRUPT
 0675 B1		PHI  R1
 0676 02		LDN  R2
 0677 D1		SEP  R1 	; CALL MONITOR
 0678 D5		EXIT		; RETURN TO BASIC

SOURCE FILE NAME: TB-MON.ASM					    PAGE 29


		;-----------------------------------------------;
		;	TINY BASIC INTERMEDIATE LANGUAGE	;
		;-----------------------------------------------;
		;
		; INTERMEDIATE LANGUAGE OPERATION CODES
		;
 0000		SX:	EQU 00H  ; STACK EXCHANGE (00-07) BYTE N WITH BYTE 0
 0008		NO:	EQU 08H  ; NO OPERATION
 0009		LB:	EQU 09H  ; PUSH NEXT BYTE ONTO STACK
 000A		LN:	EQU 0AH  ; ADD NEXT NUMBER TO STACK (2 BYTES)
 000B		DS:	EQU 0BH  ; DUPLICATE NUMBER ON TOP OF STACK (2 BYTES)
 0010		SB:	EQU 10H  ; SAVE BASIC POINTER
 0011		RP:	EQU 11H  ; RESTORE BASIC POINTER (PITTMAN USED RB)
 0012		FV:	EQU 12H  ; FETCH VARIABLE
 0013		SV:	EQU 13H  ; STORE VARIABLE
 0014		GS:	EQU 14H  ; GOSUB SAVE
 0015		RS:	EQU 15H  ; RESTORE SAVED LINE
 0016		GO:	EQU 16H  ; GOTO
 0017		NG:	EQU 17H  ; NEGATE, TWO'S COMPLEMENT (PITTMAN USED NE)
 0018		AD:	EQU 18H  ; ADD
 0019		SU:	EQU 19H  ; SUBTRACT
 001A		MP:	EQU 1AH  ; MULTIPLY
 001B		DV:	EQU 1BH  ; DIVIDE
 001C		CP:	EQU 1CH  ; COMPARE
 001D		NX:	EQU 1DH  ; NEXT BASIC STATEMENT
 001F		LS:	EQU 1FH  ; LIST PROGRAM
 0020		PN:	EQU 20H  ; PRINT NUMBER
 0021		PQ:	EQU 21H  ; PRINT BASIC STRING
 0022		PT:	EQU 22H  ; PRINT TAB
 0023		NL:	EQU 23H  ; NEW LINE
 0024		PS:	EQU 24H  ; PRINT STRING, ENDING IN CHAR W. MSB=1
 0027		GL:	EQU 27H  ; GET INPUT LINE
 002A		IL:	EQU 2AH  ; INSERT BASIC LINE
 002B		MT:	EQU 2BH  ; MARK BASIC PROGRAM SPACE EMPTY
 002C		XQ:	EQU 2CH  ; EXECUTE
 002D		WS:	EQU 2DH  ; STOP
 002E		US:	EQU 2EH  ; MACHINE LANGUAGE SUBROUTINE CALL
 002F		RT:	EQU 2FH  ; IL SUBROUTINE RETURN
 3000		JS:	EQU 3000H; JUMP SUBROUTINE @ NEXTBYTE-STRT (3000-37FF)
 3800		JU:	EQU 3800H; JUMP TO LABEL AT NEXTBYTE-STRT (3800-3FFF)
 005F		BR:	EQU 5FH  ; BRANCH RELATIVE TO 5FH+LABEL-$ (40-7F)
 007F		BC:	EQU 7FH  ; BRANCH IF NO MATCH TO 7FH+LABEL-$ (80-9F)
 009F		BV:	EQU 9FH  ; BRANCH IF NOT A VARIABLE (A0-BF)
 00BF		BN:	EQU 0BFH ; BRANCH IF NOT NUMBER TO BFH+LABEL-$ (C0-DF)
 00DF		BE:	EQU 0DFH ; BRANCH IF NOT ENDLINE TO DFH+LABEL-$(E0-FF)

SOURCE FILE NAME: TB-MON.ASM					    PAGE 30


		;
		; BEGIN TINY BASIC INTERMEDIATE LANGUAGE PROGRAM
		;
 0679		TBIL:	EQU $
 0679 243A91	STRT:	DB  PS,":",91H	; PS ":<DC1>"	PRINT PROMPT
 067C 27		DB  GL		; GL		GET LINE
 067D 10		DB  SB		; SB		SAVE POINTER
 067E E1		DB  BE+L0-$	; BE L0 	IF EMPTY,
 067F 59		DB  BR+STRT-$	; BR STRT	  THEN START AGAIN
 0680 C3	L0:	DB  BN+GOTO-$	; BN GOTO	IF LINE NUMBER,
 0681 2A		DB  IL		; IL		  THEN INSERT LINE
 0682 56		DB  BR+STRT-$	; BR STRT	    AND START AGAIN
 0683 2C	X1:	DB  XQ		; XQ		ELSE EXECUTE LINE
		;
		; EXECUTE STATEMENT
		;
 0684 8A	GOTO:	DB  BC+GOSB-$	; BC GOSB "GOTO"
 0685 474F54CF		DB  "GOT",("O"+80H)
 0689 30D0		DW  JS+EXPR-STRT; JS EXPR	GET LINE NUMBER
 068B 10	XEC:	DB  SB		; SB		SAVE POINTERS
 068C 11		DB  RP		; RP		  FOR RUNN WITH
 068D EB		DB  BE+G1-$	; BE G1 	  CONCATENATED INPUT
 068E 6C		DB  BR+G2-$	; BR G2
 068F 8C	GOSB:	DB  BC+STMT-$	; BC STMT "GOSUB"
 0690 474F5355		DB  "GOSU"
 0694 C2		DB  ("B"+80H)
 0695 30D0		DW  JS+EXPR-STRT; JS EXPR
 0697 10		DB  SB		; SB
 0698 11		DB  RP		; RP
 0699 E0	G1:	DB  BE+1	; BE *
 069A 14		DB  GS		; GS
 069B 16	G2:	DB  GO		; GO
 069C 8B	STMT:	DB  BC+PRNT-$	; BC PRNT "LET"
 069D 4C45D4		DB  "LE",("T"+80H)
 06A0 A0		DB  BV+1	; BV *		MUST BE VARIABLE NAME
 06A1 80		DB  BC+1	; BC * "="
 06A2 BD		DB   ("="+80H)
 06A3 30D0	LET:	DW  JS+EXPR-STRT; JS EXPR	GO GET EXPRESSION
 06A5 E0		DB  BE+1	; BE *		IF STATEMENT,
 06A6 13		DB  SV		; SV		  STORE RESULT
 06A7 1D		DB  NX
 06A8 8C	PRNT:	DB  BC+SKIPIT-$ ; BC SKIPIT "PR"
 06A9 50D2		DB  "P",("R"+80H)
 06AB 83		DB  BC+P0-$	; BC P0 "INT"	IF PR OR PRINT,
 06AC 494ED4		DB  "IN",("T"+80H)
 06AF E1	P0:	DB  BE+P1-$	; BE P1
 06B0 62		DB  BR+P2-$	; BR P2
 06B1 85	P1:	DB  BC+P3-$	; BC P3 ":"
 06B2 BA		DB  (":"+80H)
 06B3 3853	P2:	DW  JU+P12-STRT ; JU P12
 06B5 3855	SKIPIT: DW  JU+IF-STRT	; JU IF

SOURCE FILE NAME: TB-MON.ASM					    PAGE 31


 06B7 83	P3:	DB  BC+P4-$	; BC P4 '"'
 06B8 A2		DB  ('"'+80H)
 06B9 21		DB  PQ		; PQ		QUOTE MARKS STRING
 06BA 63		DB  BR+P5-$	; BR P5
 06BB 30D0	P4:	DW  JS+EXPR-STRT; JS EXPR
 06BD 20		DB  PN		; PN
 06BE 83	P5:	DB  BC+P6-$	; BC P6 ","
 06BF AC		DB  (","+80H)
 06C0 22		DB  PT		; PT
 06C1 62		DB  BR+P7-$	; BR P7
 06C2 84	P6:	DB  BC+P9-$	; BC P9 ";"
 06C3 BB		DB  (";"+80H)
 06C4 E1	P7:	DB  BE+P8-$	; BE P8
 06C5 67		DB  BR+P11-$	; BR P11
 06C6 4A	P8:	DB  BR+P1-$	; BR P1
 06C7 83	P9:	DB  BC+P10-$	; BC P10 "^"
 06C8 DE		DB  ("^"+80H)
 06C9 2493		DB  PS,93H	; PS "<DC3>"	PRINT <DC3>=13H=^S
 06CB E0	P10:	DB  BE+1	; BE *
 06CC 23	P12:	DB  NL		; NL		THEN <CR><LF>
 06CD 1D	P11:	DB  NX		; NX
 06CE 91	IF:	DB  BC+INP-$	; BC INP "IF"
 06CF 49C6		DB  "I",("F"+80H)
 06D1 30D0		DW  JS+EXPR-STRT; JS EXPR
 06D3 311F		DW  JS+RELO-STRT; JS RELO
 06D5 30D0		DW  JS+EXPR-STRT; JS EXPR
 06D7 84		DB  BC+I1-$	; BC I1 "THEN"	(OPTIONAL)
 06D8 544845CE		DB  "THE",("N"+80H)
 06DC 1C	I1:	DB  CP		; CP
 06DD 1D		DB  NX		; NX
 06DE 380B		DW  JU+GOTO-STRT; JU STMT
		;
		; PROCESS INPUT STATEMENT
		;
 06E0 9B	INP:	DB  BC+RTRN-$	; BC RTRN "IN"
 06E1 49CE		DB  "I",("N"+80H)
 06E3 83		DB  BC+I2-$	; BC I2 "PUT"
 06E4 5055D4		DB  "PU",("T"+80H)
 06E7 A0	I2:	DB  BV+1	; BV *
 06E8 10		DB  SB		; SB
 06E9 E7		DB  BE+I4-$	; BE I4
 06EA 243F20	I3:	DB  PS,"? "	; PS "? <DC1>"	TYPE "?" PROMPT,
 06ED 91		DB  (11H+80H)	;		THEN <DC1>=11H=XON=^Q
 06EE 27		DB  GL		; GL		THEN READ INPUT LINE
 06EF E1		DB  BE+I4-$	; BE I4 	PROCESS IT
 06F0 59		DB  BR+I3-$	; BR I3 	IF NOT ENOUGH, REPEAT
 06F1 81	I4:	DB  BC+I5-$	; BC I5 ","	OPTIONAL COMMA?
 06F2 AC		DB  (","+80H)
 06F3 30D0	I5:	DW  JS+EXPR-STRT; JS EXPR	READ A NUMBER
 06F5 13		DB  SV		; SV		STORE IN VARIABLE
 06F6 11		DB  RP		; RB		SWAP

SOURCE FILE NAME: TB-MON.ASM					    PAGE 32


 06F7 82		DB  BC+I6-$	; BC I6 ","	IF ANOTHER COMMA,
 06F8 AC		DB  (","+80H)
 06F9 4D		DB  BR+I2-$	; BR I2 	  THEN PROCESS IT
 06FA E0	I6:	DB  BE+1	; BE *
 06FB 1D		DB  NX		; NX		  ELSE QUIT
		;
		; PROCESS RETURN STATEMENT
		;
 06FC 8A	RTRN:	DB  BC+END-$	; BC END "RET"
 06FD 5245D4		DB  "RE",("T"+80H)
 0700 83		DB  BC+RT1-$	; BC RT1 "URN"
 0701 5552CE		DB  "UR",("N"+80H)
 0704 E0	RT1:	DB  BE+1	; BE *
 0705 15		DB  RS		; RS
 0706 1D		DB  NX		; NX
 0707 85	END:	DB  BC+RUNN-$	; BC RUNN "END"
 0708 454EC4		DB  "EN",("D"+80H)
 070B E0		DB  BE+1	; BE *
 070C 2D		DB  WS		; WS
 070D 87	RUNN:	DB  BC+CLER-$	; BC CLER "RUN"
 070E 5255CE		DB  "RU",("N"+80H)
 0711 10		DB  SB		; SB
 0712 11		DB  RP		; RB
 0713 380A		DW  JU+X1-STRT	; JU X1
 0715 84	CLER:	DB  BC+LISTIT-$ ; BC LISTIT "NEW"
 0716 4E45D7		DB  "NE",("W"+80H)
 0719 2B		DB  MT		; MT
 071A 9F	LISTIT: DB  BC+REM-$	; BC REM "LIST"
 071B 4C4953D4		DB  "LIS",("T"+80H)
 071F E7		DB  BE+L2-$	; BE L2
 0720 0A0001	LISX:	DB  LN,0,1	; LN 1
 0723 0A7FFF		DB  LN,7FH,0FFH ; LN 32767
 0726 65		DB  BR+L1-$	; BR L1
 0727 30D0	L2:	DW  JS+EXPR-STRT; JS EXPR
 0729 30CB		DW  JS+ARG-STRT ; JS ARG
 072B E0		DB  BE+1	; BE *
 072C 24	L1:	DB  PS		; PS "^@^@^@^@^@^@^J^@"
 072D 00000000		DW  0,0 	;		SIX <NUL>,<LF>,<NUL>
 0731 00000A80		DB  0,0,0AH,80H ;		  AS A PUNCH LEADER,
 0735 1F		DB  LS		; LS		THEN LIST,
 0736 2493		DB  PS,93H	; PS "^S"	THEN TURN PUNCH OFF
 0738 23		DB  NL		; NL		   WITH <DC3>=XOFF=^S
 0739 1D		DB  NX		; NX
 073A 84	REM:	DB  BC+DFLT-$	; BC DFLT "REM"
 073B 5245CD		DB  "RE",("M"+80H)
 073E 1D		DB  NX		; NX
 073F A0	DFLT:	DB  BV+1	; BV *		IF NO KEYWORD,
 0740 80		DB  BC+1	; BC * "="	  TRY FOR "=" (LET)
 0741 BD		DB  ("="+80H)
 0742 382A		DW  JU+LET-STRT ; JU LET
		;

SOURCE FILE NAME: TB-MON.ASM					    PAGE 33


		; IL SUBROUTINES
		;
 0744 82	ARG:	DB  BC+E5-$	; BC E5 ","
 0745 AC		DB  (","+80H)
 0746 62		DB  BR+EXPR-$	; BR EXPR
 0747 0B	E5:	DB  DS		; DS
 0748 2F	E3:	DB  RT		; RT
 0749 85	EXPR:	DB  BC+E0-$	; BC E0 "-"	IF UNARY MINUS,
 074A AD		DB  ("-"+80H)
 074B 30E6		DW  JS+TERM-STRT; JS TERM	  GO PROCESS IT
 074D 17		DB  NG		; NE
 074E 64		DB  BR+E1-$	; BR E1
 074F 81	E0:	DB  BC+E4-$	; BC E4 "+"	IGNORE LEADING PLUS
 0750 AB		DB  ("+"+80H)
 0751 30E6	E4:	DW  JS+TERM-STRT; JS TERM
 0753 85	E1:	DB  BC+E2-$	; BC E2 "+"	TERMS SEPARATED BY +
 0754 AB		DB  ("+"+80H)
 0755 30E6		DW  JS+TERM-STRT; JS TERM
 0757 18		DB  AD		; AD
 0758 5A		DB  BR+E1-$	; BR E1
 0759 93	E2:	DB  BC+T2-$	; BC T2 "-"	TERM SEPARATED BY -
 075A AD		DB  ("-"+80H)
 075B 30E6		DW  JS+TERM-STRT; JS TERM
 075D 19		DB  SU		; SU
 075E 54		DB  BR+E1-$	; BR E1
		;
 075F 30F5	TERM:	DW  JS+FACT-STRT; JS FACT
 0761 85	T0:	DB  BC+T1-$	; BC T1 "*"	FACTORS SEPARATED
 0762 AA		DB  ("*"+80H)	;		  BY TIMES
 0763 30F5		DW  JS+FACT-STRT; JS FACT
 0765 1A		DB  MP		; MP
 0766 5A		DB  BR+T0-$	; BR T0
 0767 85	T1:	DB  BC+T2-$	; BC T2 "/"
 0768 AF		DB  ("/"+80H)
 0769 30F5		DW  JS+FACT-STRT; JS FACT
 076B 1B		DB  DV		; DV
 076C 54		DB  BR+T0-$	; BR T0
 076D 2F	T2:	DB  RT		; RT
 076E 88	FACT:	DB  BC+F2-$	; BC F2 "RND("
 076F 524E44A8		DB  "RND",("("+80H)
 0773 3115		DW  JS+F6-STRT	; JS F6
 0775 3944		DW  JU+RR7-STRT ; JU RR7
 0777 8E	F2:	DB  BC+F3-$	; BC F3 "USR("	3 ARGUMENTS POSSIBLE
 0778 555352A8		DB  "USR",("("+80H)
 077C 30D0		DW  JS+EXPR-STRT; JS EXPR	ONE REQUIRED
 077E 30CB		DW  JS+ARG-STRT ; JS ARG	2ND OPTIONAL
 0780 30CB		DW  JS+ARG-STRT ; JS ARG	3RD OPTIONAL
 0782 311C		DW  JS+FUNC-STRT; JU FUNC
 0784 2E		DB  US
 0785 2F		DB  RT
 0786 A2	F3:	DB  BV+F4-$	; BV F4 	IF A VARIABLE,

SOURCE FILE NAME: TB-MON.ASM					    PAGE 34


 0787 12		DB  FV		; FV		  THEN GET IT
 0788 2F		DB  RT		; RT
 0789 C1	F4:	DB  BN+F5-$	; BN F5 	IF A NUMBER,
 078A 2F		DB  RT		; RT		  THEN GET IT
 078B 80	F5:	DB  BC+1	; BC * "("	ELSE MUST BE
 078C A8		DB  ("("+80H)	;		  AN EXPRESSION
 078D 65		DB  BR+F7-$	; BR F7
 078E 30D0	F6:	DW  JS+EXPR-STRT; JS EXPR
 0790 0B		DB  DS		; DS
 0791 80		DB  BC+1	; BC * ","	ANOTHER ARGUMENT
 0792 AC		DB  (","+80H)
 0793 30D0	F7:	DW  JS+EXPR-STRT; JS EXPR
 0795 80	FUNC:	DB  BC+1	; BC * ")"	END OF PARENTHESES?
 0796 A9		DB  (")"+80H)
 0797 2F		DB  RT		; RT
 0798 84	RELO:	DB  BC+RR0-$	; BC RR0 "="	CONVERT RELATIONAL
 0799 BD		DB  ("="+80H)	;		  OPERATORS TO CODE
 079A 0902		DB  LB,2	; LB 2		  BYTE ON STACK
 079C 2F		DB  RT		; RT
 079D 83	RR0:	DB  BC+RR1-$	; BC RR1 "<>"
 079E 3CBE		DB  "<",(">"+80H)
 07A0 74		DB  BR+RR2-$	; BR RR2
 07A1 85	RR1:	DB  BC+RR3-$	; BC RR3 "<="
 07A2 3CBD		DB  "<",("="+80H)
 07A4 0903		DB  LB,3	; LB 3
 07A6 2F		DB  RT		; RT
 07A7 84	RR3:	DB  BC+RR4-$	; BC RR4 "<"
 07A8 BC		DB  ("<"+80H)
 07A9 0901		DB  LB,1	; LB 1
 07AB 2F		DB  RT		; RT
 07AC 85	RR4:	DB  BC+RR5-$	; BC RR5 ">="
 07AD 3EBD		DB  ">",("="+80H)
 07AF 0906		DB  LB,6	; LB 5
 07B1 2F		DB  RT		; RT
 07B2 85	RR5:	DB  BC+RR6-$	; BC RR6 "><"
 07B3 3EBC		DB  ">",("<"+80H)
 07B5 0905	RR2:	DB  LB,5	; LB 5
 07B7 2F		DB  RT		; RT
 07B8 80	RR6:	DB  BC+1	; BC * ">"
 07B9 BE		DB  (">"+80H)
 07BA 0904		DB  LB,4	; LB 4
 07BC 2F		DB  RT		; RT
 07BD 19	RR7:	DB  SU		; SU
 07BE 17		DB  NG		; NE
 07BF 0A0001		DB  LN,0,1	; LN 257*128	STACK POINTER
 07C2 18		DB  AD		; AD		  FOR STORE
 07C3 0980		DB  LB,80H	; LB 128
 07C5 0980		DB  LB,80H	; LB 128
 07C7 12		DB  FV		; FV		SET RANDOM NUMBER
 07C8 0A0929		DB  LN,09H,29H	; LN 2345	R:=R*2345+6789
 07CB 1A		DB  MP		; MP

SOURCE FILE NAME: TB-MON.ASM					    PAGE 35


 07CC 0A1A85		DB  LN,1AH,85H	; LN 6789
 07CF 18		DB  AD		; AD
 07D0 08		DB  NO		; NO
 07D1 13		DB  SV		; SV
 07D2 0980		DB  LB,80H	; LB 128	GET IT AGAIN
 07D4 12		DB  FV		; FV
 07D5 03		DB  SX+3	; SX 3
 07D6 01		DB  SX+1	; SX 1
 07D7 02		DB  SX+2	; SX 2
 07D8 316A		DW  JS+F1-STRT	; JS F1 	SKIPPING
 07DA 3175	F0:	DW  JS+ABS-STRT ; JS ABS
 07DC 1B		DB  DV		; DV
 07DD 1A		DB  MP		; MP
 07DE 19		DB  SU		; SU
 07DF 3175		DW  JS+ABS-STRT ; JS ABS
 07E1 18		DB  AD		; AD
 07E2 2F		DB  RT		; RT
 07E3 0B	F1:	DB  DS		; DS
 07E4 01		DB  SX+1	; SX 1		PUSH TOP INTO STACK
 07E5 05		DB  SX+5	; SX 5
 07E6 01		DB  SX+1	; SX 1
 07E7 04		DB  SX+4	; SX 4
 07E8 0B		DB  DS		; DS
 07E9 01		DB  SX+1	; SX 1
 07EA 07		DB  SX+7	; SX 7
 07EB 01		DB  SX+1	; SX 1
 07EC 06		DB  SX+6	; SX 6
 07ED 2F		DB  RT		; RT
 07EE 0B	ABS:	DB  DS		; DS		PERFORM ABS FUNCTION
 07EF 0906		DB  LB,6	; LB 6
 07F1 0A0000		DB  LN,0,0	; LN 0
 07F4 1C		DB  CP		; CP
 07F5 17		DB  NG		; NE
 07F6 2F		DB  RT		; RT
		;
		; END TINY BASIC INTERMEDIATE LANGUAGE PROGRAM

SOURCE FILE NAME: TB-MON.ASM					    PAGE 36


		;----------------------------------------------------------;
		; IDIOT4 MONITOR FOR THE 1802	WRITTEN: 6/23/82  L. HART  ;
		; COPYRIGHT 1982-1985 BY TMSI	LAST MOD: 3/28/86  L. HART ;
		;----------------------------------------------------------;
		;
		; IDIOT4 IS A 4-PAGE 1K MONITOR PROGRAM FOR TMSI TINY BASIC.
		; IT ALLOWS BASIC TO COMMUNICATE WITH A SERIAL TERMINAL, AND
		; PROVIDES AN RCA UT-XX COMPATIBLE MACHINE-LEVEL MONITOR.
		;
		; ON RESET, IT SAVES A COPY OF ALL CPU REGISTERS AND I/O BITS
		; IN RAM. IT THEN SEARCHES FOR A BASIC PROGRAM IN ROM, AND
		; EXECUTES IT IF FOUND. OTHERWISE, IT WAITS FOR THE USER TO
		; TYPE A <CR> OR <LF> SO IDIOT4 CAN DETERMINE THE BAUD RATE.
		; IT THEN TYPES "NEW?". TYPE "Y"<CR> TO BEGIN A NEW BASIC
		; PROGRAM, OR "N" TO KEEP AN EXISTING BASIC PROGRAM IN RAM.
		;
		; THE MACHINE-LEVEL MONITOR IS CALLED FROM BASIC BY "USR(32)".
		; IT CAN EXAMINE AND CHANGE MEMORY, REGISTERS, AND I/O; LOAD
		; AND RUN PROGRAMS; AND INTERRUPT AND RESUME PROGRAM EXECUTION
		; FOR DEBUGGING PURPOSES.
		;
		; SAVER - SAVE A COPY OF ALL CPU REGISTERS & I/O BITS IN RAM.
		;	ENTER WITH P=R0 OR R1, AND X=R4. SAVES ALL REGISTERS
		;	CORRECTLY EXCEPT P, X, D, R(P), AND R4.
		;
 0800			ORG  0800H
 0800 F810	SAVER:	LDI  HIGH PAGE	; > ENTRY VIA RESET OR INTERRUPT
 0802 B4		PHI  R4 	; SET POINTER TO BASE PAGE OF RAM
 0803 F8DF		LDI  LOW SAVEND
 0805 A4		PLO  R4
 0806 8F		GLO  RF 	; SAVE REGISTERS R0-RF IN RAM
 0807 73		STXD
 0808 9F		GHI  RF 	; RF 1ST, R0 LAST,
 0809 73		STXD		; WITH HI BYTE IN LOWER ADDRESS
 080A 8E		GLO  RE
 080B 73		STXD
 080C 9E		GHI  RE
 080D 73		STXD		; THE REGISTERS BEING USED FOR PROGRAM
 080E 8D		GLO  RD 	; COUNTER AND RAM POINTER ARE CHANGING
 080F 73		STXD		; DURING EXECUTION, SO THEIR STORED
 0810 9D		GHI  RD 	; VALUES WILL BE FIXED LATER.
 0811 73		STXD
 0812 8C		GLO  RC
 0813 73		STXD
 0814 9C		GHI  RC
 0815 73		STXD
 0816 8B		GLO  RB
 0817 73		STXD
 0818 9B		GHI  RB
 0819 73		STXD
 081A 8A		GLO  RA

SOURCE FILE NAME: TB-MON.ASM					    PAGE 37


 081B 73		STXD
 081C 9A		GHI  RA
 081D 73		STXD
 081E 89		GLO  R9
 081F 73		STXD
 0820 99		GHI  R9
 0821 73		STXD
 0822 88		GLO  R8
 0823 73		STXD
 0824 98		GHI  R8
 0825 73		STXD
 0826 87		GLO  R7
 0827 73		STXD
 0828 97		GHI  R7
 0829 73		STXD
 082A 86		GLO  R6
 082B 73		STXD
 082C 96		GHI  R6
 082D 73		STXD
 082E 85		GLO  R5
 082F 73		STXD
 0830 95		GHI  R5
 0831 73		STXD
 0832 73		STXD		; DON'T BOTHER WITH R4 (SAVES 2 BYTES)
 0833 73		STXD
 0834 83		GLO  R3
 0835 73		STXD
 0836 93		GHI  R3
 0837 73		STXD
 0838 82		GLO  R2
 0839 73		STXD
 083A 92		GHI  R2
 083B 73		STXD
 083C 81		GLO  R1
 083D 73		STXD
 083E 91		GHI  R1
 083F 73		STXD
 0840 80		GLO  R0
 0841 73		STXD
 0842 90		GHI  R0
 0843 73		STXD
 0844 F800		LDI  0		; LOAD 0
 0846 B3		PHI  R3 	; (& SAVE A COPY FOR LATER)
 0847 3F4B		BN4  $+4	; PACK STATUS OF EF4 & EF3 INTO 1 BYTE
 0849 F904		ORI  04H	; AND PUSH INTO RAM
 084B 3E4F		BN3  $+4	;   X4 - EF4 ACTIVE
 084D F930		ORI  30H	;   3X - EF3 ACTIVE
 084F 73		STXD
 0850 93		GHI  R3 	; PACK STATUS OF EF2 & EF1 INTO 1 BYTE
 0851 3D55		BN2  $+4	; AND PUSH INTO RAM
 0853 F902		ORI  02H	;   X2 - EF2 ACTIVE

SOURCE FILE NAME: TB-MON.ASM					    PAGE 38


 0855 3C59		BN1  $+4	;   1X - EF1 ACTIVE
 0857 F910		ORI  10H
 0859 73		STXD
 085A 93		GHI  R3 	; PUSH STATUS OF Q INTO RAM
 085B C5		LSNQ		;   1 - Q ACTIVE
 085C F901		ORI  1		;   0 - Q INACTIVE
 085E 73		STXD
 085F F801		LDI  1		; PUSH STATUS OF IE INTO RAM
 0861 CC		LSIE		;   1 - ENABLED
 0862 F800		LDI  0		;   0 - DISABLED ((COULD BE GHI R3))
 0864 73		STXD
 0865 93		GHI  R3 	; PUSH D(=0) TO RAM (DUMMY VALUE)
 0866 73		STXD
 0867 7C00		ADCI 0		; PUSH DF INTO RAM
 0869 73		STXD
 086A 78		SAV		; PUSH T INTO RAM
 086B 24		DEC  R4
 086C F8CF		LDI  LOW IFINT	; IF CALLED VIA INTERRUPT,
 086E A1		PLO  R1 	; < THEN RETURN
 086F 93		GHI  R3 	; ELSE PUSH STATUS=0,
 0870 54		STR  R4 	; < AND CONTINUE
		;
		; MOVIOV - MOVE I/O VECTORS FROM ROM TO RAM BASE PAGE. THESE
		;	VECTORS POINT TO THE SUBROUTINES USED BY BASIC FOR
		;	KEYBOARD INPUT (KEYBD:), PRINTED OUTPUT (TYPED:), AND
		;	BREAK DETECTION (TBRK:).
		;
 0871 F80E		LDI  LOW TBRK+2
 0873 A3		PLO  R3 	; R3=POINTS TO ROM I/O VECTORS
 0874 A4		PLO  R4 	; R4=DESTINATION IN PAGE0 RAM
 0875 03	MOVIOV: LDN  R3 	; REPEAT..
 0876 73		STXD		;  - MOVE A BYTE
 0877 23		DEC  R3 	;  - DECREMENT THE POINTERS
 0878 83		GLO  R3
 0879 FB05		XRI  KEYBD-1	;  - UNTIL 9 BYTES HAVE BEEN MOVED
 087B 3A75		BNZ  MOVIOV
		;
		; SEEKROM - ALLOWS A BASIC PROGRAM TO BE STORED IN ROM, AND
		;	BE AUTOMATICALLY EXECUTED UPON POWER-UP OR RESET.
		;	TINY BASIC AND THE IDIOT/4 MONITOR OCCUPY ABOUT 3K,
		;	LEAVING ABOUT 1K AVAILABLE IN A 4K ROM.
		;
		;	THE BASIC PROGRAM CAN START ON ANY PAGE BOUNDARY
		;	ABOVE THE OCCUPIED PART OF THIS ROM. THE ROM IS FOUND
		;	BY SEEKING THE 1ST NON-FF BYTE THAT ISN'T RAM (I.E.
		;	CAN'T BE CHANGED). THE 1ST 2 BYTES OF A BASIC PROGRAM
		;	ARE ITS 1ST LINE NUMBER IN HEX; IT MUST BE "+" SO ITS
		;	HI BYTE IS NOT FF(HEX).
		;
 087D A1		PLO  R1 	; LET R1=ROM PAGE#
 087E F80C		LDI  HIGH IOBIT2; START AT END OF IDIOT4 MONITOR ROM

SOURCE FILE NAME: TB-MON.ASM					    PAGE 39


 0880 FC01	SEEKROM:ADI  1		; REPEAT..
 0882 B1		PHI  R1 	;  - INCREMENT PAGE#
 0883 01		LDN  R1 	;  - READ M(PAGE#)
 0884 A3		PLO  R3 	;    AND SAVE A COPY
 0885 F8FF		LDI  0FFH	;  - TRY STORING FF
 0887 51		STR  R1
 0888 01		LDN  R1 	;  - IF IT WORKS, THEN SET DF	
 0889 FC01		ADI  1		;	 (I.E. IS RAM OR NOT MEMORY)
 088B 83		GLO  R3 	;  - FIX M(PAGE#) 
 088C 51		STR  R1
 088D 91		GHI  R1 	;  - IF PAGE# WRAPS TO 0 (NO ROM),
 088E C209F8		LBZ  COMMAND	;      THEN ENTER BASIC COMMAND MODE
 0891 3380		BDF  SEEKROM	;  ..UNTIL MEMORY FOUND THAT ISN'T RAM
		;
		; PROGRAM FOUND IN USER ROM: SET SPECIAL I/O VECTORS, AND COLD
		;	START BASIC. WHEN IT GETS A KEY, CHANGE BASIC'S START-
		;	OF PROGRAM VARIABLE TO POINT TO THE PROGRAM IN ROM,
		;	AND FEED BASIC A "RUN" COMMAND.
		;
 0893 14		INC  R4 	; POINT R4 TO PAGE0+KEYBD
 0894 F8D0		LDI  0D0H	; CHANGE KEYBD VECTOR TO "SEP R0"
 0896 54		STR  R4
 0897 14		INC  R4
 0898 14		INC  R4
 0899 14		INC  R4 	; POINT R4 TO PAGE0+TYPED
 089A F8D5		LDI  0D5H	; CHANGE TYPED VECTOR TO "SEP R5"
 089C 54		STR  R4 	;   (DO NOTHING AND RETURN)
 089D F8B0		LDI  0B0H	; COLD START BASIC
 089F A3		PLO  R3 	;   1ST KEYBD CALL WILL RETURN..
 08A0 D3		SEP  R3
 08A1 F852		LDI  "R"	;   ..HERE!
 08A3 D5		SEP  R5 	; SEND BASIC A "RUN" COMMAND
 08A4 F855		LDI  "U"
 08A6 D5		SEP  R5
 08A7 F84E		LDI  "N"
 08A9 D5		SEP  R5
 08AA 23		DEC  R3 	; RESTORE KEYBD VECTOR TO "LBR"
 08AB F8C0		LDI  0C0H
 08AD 53		STR  R3
 08AE 13		INC  R3
 08AF 13		INC  R3
 08B0 13		INC  R3
 08B1 53		STR  R3 	; RESTORE TYPED VECTOR TO "LBR"
 08B2 F820		LDI  LOW BASIC	; CHANGE BASIC'S START-OF-PROGRAM
 08B4 A3		PLO  R3 	;   POINTER TO THE USER'S ROM PAGE#
 08B5 91		GHI  R1
 08B6 53		STR  R3
 08B7 13		INC  R3
 08B8 81		GLO  R1
 08B9 53		STR  R3
		;

SOURCE FILE NAME: TB-MON.ASM					    PAGE 40


		; SET DEFAULT BAUD RATE AND HALF/FULL DUPLEX. VALUES SHOWN
		;	ARE FOR A 2 MHZ CLOCK. NUMBERS SHOWN FOR FULL DUPLEX:
		;	ADD 1 FOR HALF DUPLEX.
 08BA					;   75 BAUD = 0A2H
 08BA					;  110 BAUD = 06CH
 08BA F826		LDI 26H 	;  300 BAUD = 026H
 08BC					;  600 BAUD = 012H		
 08BC					; 1200 BAUD = 008H
 08BC BE		PHI  RE       
 08BD 90		GHI  R0 	; INITIALIZE DELAY SUBROUTINE PC
 08BE BC		PHI  RC
 08BF F8EF		LDI  LOW DELAY1
 08C1 AC		PLO  RC
 08C2 F80D		LDI  0DH	;   SEND <CR> TO BASIC
 08C4 D5		SEP  R5 	; < TO EXECUTE "RUN" COMMAND
		;
		; INTRUPT - INTERRUPT HANDLER FOR IDIOT MONITOR. HARDWARE
		;	INTERRUPT SAVES ALL REGISTERS EXCEPT T CORRECTLY. 
		;	A SOFTWARE INTERRUPT (D1=SEP R1) SAVES ALL BUT P AND
		;	X CORRECTLY. R2 MUST POINT TO A STACK WITH AT LEAST 
		;	4 FREE BYTES TO SAVE D AND R4 CORRECTLY.
		;
 08C5 E2	INTRUPT:SEX  R2 	; ENTRY: OLD P AND X DESTROYED
 08C6 22		DEC  R2 	; DEC. STACK POINTER TO FREE LOCATION
 08C7 73		STXD		; PUSH D
 08C8 94		GHI  R4 	; PUSH R4
 08C9 73		STXD
 08CA 84		GLO  R4
 08CB 52		STR  R2
 08CC E4		SEX  R4 	; < SET X=R4 AND GO TO SAVE REGISTERS
 08CD 3000		BR   SAVER
 08CF 94	IFINT:	GHI  R4 	; > RETURN HERE:
 08D0 73		STXD		; PUSH STATUS=10
 08D1 F8C9		LDI  0C9H	; CORRECT STORED CONTENTS OF R4
 08D3 A4		PLO  R4
 08D4 42		LDA  R2
 08D5 73		STXD
 08D6 42		LDA  R2
 08D7 73		STXD
 08D8 F8BB		LDI  0BBH	; CORRECT STORED CONTENTS OF D
 08DA A4		PLO  R4
 08DB 42		LDA  R2
 08DC 54		STR  R4
 08DD F8C5		LDI  0C5H	; FIX STORED VALUE OF STACK POINTER
 08DF A4		PLO  R4 	; TO ACTUAL VALUE @ TIME OF INTERRUPT
 08E0 82		GLO  R2
 08E1 73		STXD
 08E2 92		GHI  R2
 08E3 73		STXD
 08E4 F8C5		LDI  LOW INTRUPT; CORRECT STORED VALUE OF R1
 08E6 54		STR  R4

SOURCE FILE NAME: TB-MON.ASM					    PAGE 41


 08E7 F80A		LDI  HIGH RESTART; INITIALIZE R5
 08E9 B5		PHI  R5
 08EA F834		LDI  LOW RESTART
 08EC A5		PLO  R5
 08ED D5		SEP  R5 	; < AND RESTART MONITOR

SOURCE FILE NAME: TB-MON.ASM					    PAGE 42


		;-------------------------------------------------------;
		;	    SERIAL I/O READ AND TYPE ROUTINES		;
		;-------------------------------------------------------;
		;
		; THE FOLLOWING ROUTINES CREATE A "SOFTWARE UART". TIMING
		; IS VERY CRITICAL, SO MAKE CHANGES ONLY WITH EXTREME CARE.
		;
		; DELAY1 - USED BY THE READ AND TYPE ROUTINES TO GENERATE A
		;	TIME DELAY PROPORTIONAL TO THE BAUD RATE. THE LENGTH 
		;	OF THE DELAY (IN MACHINE CYCLES) IS SPECIFIED BY:
		;
		;		DELAY = 4 + 4(BAUD)(#BITS + 3)
		;
		;	WHERE "#BITS" IS AN IN-LINE BYTE FROM THE CALLING 
		;	PROGRAM AND "BAUD" IS THE BAUD RATE TIMING CONSTANT 
		;	FROM THE UPPER 7 BITS OF RE.1 (BAUD.1). "DELAY" USES 
		;	RC AS ITS DEDICATED PROGRAM COUNTER, AND RETURNS VIA 
		;	A "SEP R3" WITH DF=1, D=0, AND RE.0=0.
		;
 08EE			ORG  08EEH
 08EE D3		SEP  R3 	; RETURN TO CALLER
 08EF 9E	DELAY1: GHI  BAUD	; GET BAUD CONSTANT
 08F0 F6		SHR		; REMOVE ECHO FLAG
 08F1 AE		PLO  BAUD	; REPEAT...
 08F2 2E		DEC  BAUD	; - DECREMENT BAUD
 08F3 43		LDA  R3 	; - GET #BITS,
 08F4 FF01		SMI  1		;   DECREMENT UNTIL ZERO
 08F6 3AF4		BNZ  $-2
 08F8 8E		GLO  BAUD	; ...UNTIL BAUD=0
 08F9 32EE		BZ   $-11	; GO TO RETURN
 08FB 23		DEC  R3
 08FC 30F2		BR   $-10

SOURCE FILE NAME: TB-MON.ASM					    PAGE 43


		
		; TIMALC - CALCULATES BAUD RATE AND SETS ECHO FLAG BASED
		;	ON THE 1ST CHARACTER RECEIVED: CARRIAGE RETURN
		;	SELECTS FULL DUPLEX (ALL INPUTS ECHOED); LINE FEED
		;	SELECTS HALF DUPLEX (NO ECHO). "TIMALC" SETS UP RC
		;	AS PC FOR THE "DELAY1" ROUTINE, LOADS A CONSTANT
		;	PROPORTIONAL TO THE BAUD RATE IN THE UPPER 7 BITS
		;	OF "BAUD" (RE.1), AND SETS THE LEAST SIGNIFICANT
		;	BIT=0 FOR ECHO, OR =1 FOR NO ECHO.
		;
 08FE			ORG  08FEH
 08FE 93	TIMALC: GHI  R3 	; > ENTRY:
 08FF BC		PHI  DELAY	; POINT RC TO "DELAY"
 0900 F8EF		LDI  LOW DELAY1
 0902 AC		PLO  DELAY
 0903 F800		LDI  0		; LET BAUD=0
 0905 AE		PLO  BAUD
 0906 AF		PLO  ASCII	; LET ASCII=0
 0907 3707		B4   $		; WAIT FOR START BIT
 0909 3F09		BN4  $		; WAIT FOR 1ST NON-0 DATA BIT
 090B F803		LDI  3		; WAIT 14 MACHINE CYCLES
 090D FF01	TC:	SMI  1
 090F 3A0D		BNZ  TC
 0911 8F		GLO  ASCII
 0912 3A17		BNZ  ZTO1	; MEASURE LENGTH OF 1ST ZERO BIT
 0914 3719		B4   INCR	; BIT (SAME FOR BOTH <CR> AND <LF>)
 0916 1F		INC  ASCII
 0917 371E	ZTO1:	B4   DAUX
 0919 1E	INCR:	INC  BAUD
 091A F807		LDI  7
 091C 300D		BR   TC
 091E 2E	DAUX:	DEC  BAUD	; BAUD = #LOOPS IN 2 BIT TIMES
 091F 2E		DEC  BAUD
 0920 8E		GLO  BAUD
 0921 F901		ORI  1
 0923 BE		PHI  BAUD
 0924 DC		SEP  DELAY	; WAIT 1.5 BIT TIMES
 0925 0C		DB   0CH
 0926 3F2C		BN4  WAIT	; IF BIT=1, IS <LF>
 0928 9E		GHI  BAUD	;    THEN SET LSB OF BAUD=1
 0929 FAFE		ANI  0FEH	;    ELSE LSB BAUD=0
 092B BE		PHI  BAUD	; SAVE BAUD RATE
 092C DC	WAIT:	SEP  DELAY	; WAIT FOR END OF CHARACTER
 092D 26		DB   26H
 092E D5		SEP  R5 	; < AND RETURN

SOURCE FILE NAME: TB-MON.ASM					    PAGE 44


		
		; READ - READS A SERIAL CHARACTER VIA EF4 AND RETURNS WITH
		;	ITS ASCII CODE IN ASCII.1 AND D (BUT D WILL BE LOST
		;	IF SCRT CALL & RETURN IS USED). EXPECTS P=3; ALTERS
		;	DF, ASCII, AND BAUD.0; AND RETURNS WITH SEP R5. 
		;
		; TTYRED - SAME AS "READ", BUT WITH HANDSHAKING. "TTYRED"
		;	FIRST DOES AN "OUT 7, 80H" TO ENABLE A SERIAL INPUT
		;	DEVICE SUCH AS A PAPER TAPE READER. ONCE A CHARACTER
		;	HAS BEGUN, AN "OUT 7,40H" IS USED TO TURN THE SERIAL
		;	INPUT DEVICE OFF AGAIN.
		;
		; READAH - SAME AS "READ", BUT IF A HEX CHARACTER (0-9, A-F)
		;	IS RECEIVED, IT IS ALSO SHIFTED INTO THE LOW 4 BITS
		;	OF "HEXX" AND DF=1 IS RETURNED; IF NOT HEX, RETURNS
		;	DF=0. "READAH" USES P=R3, ALTERS D, DF, RF, RE.0,
		;	AND RETURNS WITH A "SEP R5" AND R3 POINTING TO THE
		;	"READAH" ENTRY POINT.
		;
		; NOTE: THE READ ROUTINES EXIT AT THE BEGINNING OF THE ECHOED 
		;	STOP BIT, & SET BAUD.0 (RE.0) >0 AS A DELAY FLAG FOR
		;	THE "TYPE" ROUTINES. THE "TYPE" ROUTINES CHECK THIS
		;	FLAG BEFORE TYPING THE NEXT BYTE, & IF SET, WILL
		;	FIRST SEND 2 STOP BITS. TAKE CARE NOT TO RESET THIS
		;	FLAG (BY USING THE DELAY ROUTINE OR RE.0) UNTIL
		;	ENOUGH TIME HAS PASSED SO NO FURTHER DELAY IS NEEDED.
		;
 092F FC07	CKDEC:	ADI  7		; IF CHARACTER IS 0-9 OR A-F,
 0931 3337		BDF  NFND
 0933 FC0A		ADI  0AH	;    THEN SHIFT IT IN
 0935 3388		BDF  FND	;    ELSE IS NON-HEX,
 0937 FC00	NFND:	ADI  0		;	SET DF=0
 0939 9F	REXIT:	GHI  ASCII	; PUT CHARACTER IN D
 093A D5		SEP  R5 	; RETURN WITH ENTRY FLAG SET:
 093B F880	READAH: LDI  80H	;   =80 IF VIA READAH
 093D 38		SKP
 093E 83	READ:	GLO  R3 	;   =3F IF VIA READ
 093F C8		LSKP
 0940 F800	TTYRED: LDI  0		;   =00 IF VIA TTYRED
 0942 AF		PLO  ASCII	; SAVE ENTRY FLAG
 0943 F880	READ2:	LDI  80H	; SET #BITS IN CHARACTER=7
 0945 BF		PHI  ASCII	; (7 SHIFTS CHANGES '80' INTO '01')
 0946 E3		SEX  R3
 0947 8F		GLO  ASCII	; GET ENTRY FLAG
 0948 C6		LSNZ		; IF TTYRED,
 0949 67		OUT  7		;    TURN READER ON
 094A 80		DB   80H
 094B 3F4B		BN4  $		; WAIT IF A STOP BIT
 094D 374D	TTY1	B4   $		; FIND A START BIT:
 094F DC		SEP  DELAY	; - DELAY 1/2 BIT TIME, TEST AGAIN
 0950 02		DB   2

SOURCE FILE NAME: TB-MON.ASM					    PAGE 45


 0951 374D		B4   TTY1	; - REPEAT IF GONE
 0953 8F		GLO  ASCII
 0954 C6		LSNZ		; - IF TTYRED, TURN READER OFF
 0955 67		OUT  7
 0956 40		DB   40H
		;
		; BEGIN SERIAL INPUT (DELAY+44 MC./LOOP)
		;
 0957 E2	NOBIT:	SEX  R2 	; EQUALIZE DELAYS
 0958 E2		SEX  R2
 0959 9E	BIT:	GHI  BAUD
 095A F6		SHR
 095B 3362		BDF  NOECHO	; IF ECHO=YES,
 095D 3761		B4   OUTBIT
 095F 7B		SEQ		;    SET Q IF BIT=1
 0960 C8		LSKP		;    RESET Q IF BIT=0
 0961 7A	OUTBIT: REQ
 0962 C4	NOECHO: NOP		; EQUALIZE DELAYS
 0963 C7		LSNF
 0964 E2		SEX  R2
 0965 E2		SEX  R2
 0966 E2		SEX  R2
 0967 C4		NOP
 0968 C4		NOP
 0969 DC		SEP  RC 	; WAIT 1 BIT TIME
 096A 07		DB   7
 096B 1E		INC  BAUD	; SET DELAY FLAG =1
 096C 9F		GHI  ASCII	; SHIFT ASCII CHARACTER 1 BIT
 096D F6		SHR
 096E BF		PHI  ASCII
 096F 3378		BDF  STOP	; IF MORE BITS TO GO,
 0971 F980		ORI  80H	;   THEN MASK CURRENT BIT INTO CHAR
 0973 3F57		BN4  NOBIT
 0975 BF		PHI  ASCII	;	CONTINUE LOOP
 0976 3059		BR   BIT
 0978 7A	STOP:	REQ		;    ELSE SET STOP BIT
 0979 3243		BZ   READ2	; REPEAT IF 00=NULL
 097B 8F		GLO  ASCII	; IF READ OR TTYRED,
 097C FE		SHL		;    THEN GO TO EXIT
 097D 3B39		BNF  REXIT	;    ELSE IS READAH:
 097F 9F		GHI  ASCII	; IF CHARACTER < "A",
 0980 FF41		SMI  41H	;    THEN GO CHECK FOR NUMBER (0-9)
 0982 3B2F		BNF  CKDEC
 0984 FF06		SMI  6		;    ELSE CHECK FOR LETTERS A-F
 0986 3337		BDF  NFND
 0988 FE	FND:	SHL		; CHARACTER IS HEX:
 0989 FE		SHL
 098A FE		SHL		;   SHIFT INTO LOWER 4 BITS OF HEXX
 098B FE		SHL
 098C FC08		ADI  8
 098E FE		SHL

SOURCE FILE NAME: TB-MON.ASM					    PAGE 46


 098F AE	FND1:	PLO  BAUD	; REPEAT FOUR TIMES..
 0990 8D		GLO  HEXX	; - SHIFT BIT INTO HEXX.0
 0991 7E		SHLC
 0992 AD		PLO  HEXX
 0993 9D		GHI  HEXX	; - SHIFT CARRY BIT INTO HEXX.1
 0994 7E		SHLC
 0995 BD		PHI  HEXX
 0996 8E		GLO  BAUD	; - GET NEXT BIT
 0997 FE		SHL		; ..UNTIL DONE
 0998 3A8F		BNZ  FND1
 099A 3039		BR   REXIT	; EXIT WITH DELAY FLAG SET

SOURCE FILE NAME: TB-MON.ASM					    PAGE 47


		
		; TYPE5 - TYPES BYTE AT THE MEMORY LOCATION POINTED TO
		;	BY R5, THEN INCREMENTS R5. IF DELAY FLAG IS SET
		;	(BAUD.0>1), "TYPE5" FIRST WAITS 2 BIT-TIMES SO ANY
		;	PREVIOUS READ OPERATION ENDS, TYPES THE BYTE, THEN
		;	RESETS THE DELAY FLAG=0 SO FURTHER TYPES ARE NOT
		;	DELAYED.
		;
		; TYPE6 - SAME, BUT USES & INCREMENTS R6.
		;
		; TYPE - SAME, BUT TYPES ASCII.1 (RF.1) 
		;
		; TYPE5D - SAME AS "TYPE5", BUT ALWAYS WAITS 2 BIT-TIMES.
		;
		; TYPE2 - SAME AS "TYPE5", BUT TYPES THE CONTENTS OF ASCII.1
		;	(RF.1) AS TWO HEX DIGITS (0-9, A-F).
		;
		;	ALL TYPE ROUTINES USE P=R3, EXIT VIA "SEP R5", & CAN
		;	USE THE SCRT CALL & RETURN. THE SERIAL OUTPUT USES
		;	"Q", WITH 1 START, 8 DATA, & 2 STOP BITS. LINE FEED
		;	<LF> IS FOLLOWED BY 3 NULLS (=0) IN CASE THE TERMINAL
		;	NEEDS TIME FOR THE <CR><LF> SEQUENCE. Q=0 IS "MARK"
		;	OR STOP BIT; Q=1 IS A "SPACE" OR START BIT. THE DELAY
		;	ROUTINE DETERMINES THE BAUD RATE. ALL ROUTINES ALTER
		;	D,DF, X, RD.0, RE.0, RF.0, & EXIT WITH R3 AT "TYPE5".
		;
		;  BAUD.0 = DELAY FLAG: =0 NO DELAY
		;			>0 DELAY 2 BITS
		; ASCII.0 = (LO 4 BITS) #BITS/CHARACTER
		;	  = (HI 4 BITS) 0= BYTE OUTPUT 
		;			1= 1ST HEX OUT 
		;			2= LAST HEX OUT
		;			5= <LF> OUTPUT 
 099C			ORG  099CH
 099C 9E	TYPE5D: GHI  BAUD	; IF TYPE5D,
 099D AE		PLO  BAUD	;   THEN SET DELAY FLAG TRUE (>0)
 099E 38		SKP
 099F D5	TYPEXIT:SEP  R5
 09A0 45	TYPE5:	LDA  R5 	; IF TYPE5, GET BYTE VIA R5, & INC.R5
 09A1 38		SKP
 09A2 46	TYPE6:	LDA  R6 	; IF TYPE6, GET BYTE VIA R6, & INC.R6
 09A3 38		SKP  
 09A4 9F	TYPE:	GHI  ASCII	; IF TYPE, GET BYTE IN ASCII.1
 09A5 AD		PLO  RD
		;
		; DETERMINE CODE BYTE
		;
 09A6 FB0A		XRI  0AH	; IF LINE FEED,
 09A8 3ABE		BNZ  TY2	;   THEN SET CODE=<LF>, 11 BITS
 09AA F85B		LDI  5BH
 09AC 30C0		BR   TY3

SOURCE FILE NAME: TB-MON.ASM					    PAGE 48


 09AE 9F	TYPE2:	GHI  ASCII	; IF TYPE2,
 09AF F6		SHR		;   THEN GET ASCII.1
 09B0 F6		SHR		;     EXTRACT UPPER 4 BITS
 09B1 F6		SHR
 09B2 F6		SHR
 09B3 FCF6		ADI  0F6H	;     CONVERT TO HEX:
 09B5 C7		LSNF		;     IF "A" OR MORE, ADD 37
 09B6 FC07		ADI  7
 09B8 FFC6		SMI  0C6H	;	ELSE ADD 30
 09BA AD		PLO  RD
 09BB F81B		LDI  1BH	;	CODE=HEX, 11 BITS
 09BD C8		LSKP
 09BE F80B	TY2:	LDI  0BH	;   ELSE SET CODE=BYTE, 11 BITS
 09C0 AF	TY3:	PLO  ASCII	;	SAVE CODE BYTE
		;
		; BEGIN SERIAL OUTPUT (DELAY + 44 MACHINE CYCLES PER LOOP)
		;
 09C1 8E	BEGIN:	GLO  BAUD	; IF DELAY FLAG > 0,
 09C2 CE		LSZ		;   WAIT 2 BIT-TIMES IN CASE
 09C3 DC		SEP  DELAY	;   PREVIOUS READ NOT DONE
 09C4 17		DB   23
 09C5 7B		SEQ		; BEGIN START BIT
 09C6 DC	NEXTBIT:SEP  RC 	; REPEAT...
 09C7 07		DB   7		; - WAIT 1 BIT-TIME
 09C8 C4		NOP		;   (RETURNS WITH D=0)
 09C9 C4		NOP
 09CA C4		NOP
 09CB C4		NOP
 09CC C4		NOP
 09CD C4		NOP
 09CE 2F		DEC  ASCII	; - DECREMENT #BITS
 09CF F5		SD		; - SET DF=1
 09D0 8D		GLO  RD 	; - GET NEXT BIT OF CHARACTER
 09D1 76		SHRC		;     LEAST SIGNIFICANT BIT FIRST
 09D2 AD		PLO  RD
 09D3 CF		LSDF		; - IF BIT=0,
 09D4 7B		SEQ		;      SET Q=1="SPACE"
 09D5 C8		LSKP
 09D6 7A		REQ		; - IF BIT=1,
 09D7 C4		NOP		;      SET Q=0="MARK"
 09D8 8F		GLO  ASCII	; ...UNTIL #BITS=0
 09D9 FA0F		ANI  0FH
 09DB 3AC6		BNZ  NEXTBIT
 09DD 8F	NXCHAR: GLO  ASCII	; GET CODE BYTE;
 09DE FCFB		ADI  0FBH	; DECREMENT CODE,
 09E0 AF		PLO  ASCII	; SET #BITS=11
 09E1 3B9F		BNF  TYPEXIT	; IF NO MORE, EXIT!
		;
		; TEST CODE BYTE TO SEE WHAT TO DO NEXT
		;
 09E3 FF1B		SMI  1BH	; IF CODE=1,

SOURCE FILE NAME: TB-MON.ASM					    PAGE 49


 09E5 329F		BZ   TYPEXIT	;    THEN WAS LAST NULL: EXIT
 09E7 F800		LDI  0		; IF CODE>1,
 09E9 33F5		BDF  HX22	;    THEN GET NULL & GO TYPE IT
 09EB					; IF CODE=0,
 09EB 9F	HEX2:	GHI  ASCII	;    GET BYTE
 09EC FA0F		ANI  00FH	;    MASK LOWER 4
 09EE FCF6		ADI  0F6H	;    CONVERT TO HEX
 09F0 C7		LSNF		;    IF "A" OR MORE,
 09F1 FC07		ADI  7		;	THEN ADD 37
 09F3 FFC6		SMI  0C6H	;	ELSE ADD 30
 09F5 AD	HX22:	PLO  RD 	;    LOAD BYTE
 09F6 30C1		BR   BEGIN	;    BEGIN TYPING IT

SOURCE FILE NAME: TB-MON.ASM					    PAGE 50


		; COMMAND - ENTERS THE BASIC INTERPRETER IN "COMMAND" MODE. 
		;	THE 1ST CHARACTER TYPED SETS THE BAUD RATE, AND MUST 
		;	BE A <CR> FOR FULL DUPLEX (ALL INPUTS ECHOED), OR 
		;	<LF> FOR HALF DUPLEX (INPUTS NOT ECHOED).
		;
		;	THE SYSTEM THEN PRINTS "NEW?" TO ASK IF YOU WANT TO 
		;	BEGIN WITH A NEW BASIC PROGRAM OR KEEP AN EXISTING
		;	ONE ALREADY IN MEMORY. TYPE "Y" FOR YES, OR "N" FOR
		;	NO, FOLLOWED BY <CR>. ONLY THE LAST KEY BEFORE THE
		;	<CR> COUNTS. IF ONLY <CR> IS TYPED, "YES" IS ASSUMED.
		;
 09F8 F8FF	COMMAND:LDI  LOW HERE	; > MAKE R5 THE PROGRAM COUNTER
 09FA A5		PLO  R5
 09FB F809		LDI  HIGH HERE
 09FD B5		PHI  R5
 09FE D5		SEP  R5
 09FF FF01	HERE:	SMI  1		; POINT R3 TO SUBROUTINE PAGE
 0A01 B3		PHI  R3
 0A02 E5		SEX  R5
 0A03 67		OUT  7		; TURN I/O DEVICE ON
 0A04 01		DB   1
 0A05 F8FE		LDI  LOW TIMALC ; CALL TIMALC TO SET BAUD RATE
 0A07 A3		PLO  R3
 0A08 D3		SEP  R3
 0A09 F89C	NEWM:	LDI  LOW TYPE5D ; TYPE THE MESSAGE:
 0A0B A3		PLO  R3
 0A0C D30D		DB   TYPA,0DH	;   <CR>
 0A0E D30A		DB   TYPA,0AH	;   <LF>
 0A10 D34E		DB   TYPA,"N"	;   "N"
 0A12 D345		DB   TYPA,"E"	;   "E"
 0A14 D357		DB   TYPA,"W"	;   "W"
 0A16 D33F		DB   TYPA,"?"	;   "?"
 0A18 D320		DB   TYPA," "	;   <SPACE>
		;
		; LOOK FOR A "Y" OR "N" RESPONSE
		;
 0A1A F83B		LDI  LOW READAH ; POINT TO READ SUBROUTINE
 0A1C A3		PLO  R3
 0A1D F84C		LDI  "Y"-0DH	; ASSUME KEY="Y":
 0A1F FC0D	NEWQ:	ADI  0DH	; REPEAT..
 0A21 A4		PLO  R4 	;  - SAVE LAST KEY
 0A22 D3		SEP  R3 	;  - GET ANOTHER KEY
 0A23 FF0D		SMI  0DH
 0A25 3A1F		BNZ  NEWQ	; ..UNTIL <CR>
 0A27 84		GLO  R4 	; IF LAST KEY WAS "Y",
 0A28 FF59		SMI  "Y"
 0A2A C200B0		LBZ  COLD	;   THEN COLD START
 0A2D FC0B		ADI  ("Y"-"N")	; IF LAST KEY WAS NOT "N",
 0A2F 3A09		BNZ  NEWM	;   TRY AGAIN
 0A31 C000ED		LBR  WARM	;   ELSE WAS "N", WARM START

SOURCE FILE NAME: TB-MON.ASM					    PAGE 51


		
		; IDIOT MONITOR MAIN PROGRAM - EXAMINE & CHANGE REGISTERS
		;	OR MEMORY, & EXECUTE PROGRAMS WITH BREAKPOINTS. AN
		;	"*" INDICATES THE MODITOR IS READY FOR A COMMAND.
		;	COMMANDS CONSIST OF "?", "!", OR "$" FOLLOWED BY THE
		;	LETTER "M","P", OR "R". ALL OTHER INPUTS ARE IGNORED.
		;	NUMBERS ARE HEX, AND LEADING ZEROS ARE UNNECESSARY.
		;	SPACES, LINE FEEDS, & CARRIAGE RETURNS CAN BE USED
		;	BETWEEN NUMBERS FOR READABILITY. THE COMMANDS ARE:
		;
		;  !M - CHANGE MEMORY
		;	  EXAMPLE:  !MA00 11 22 33 <CR>
		;	WRITES HEX BYTES (11,22,33) INTO MEMORY, STARTING AT
		;	THE SPECIFIED ADDRESS (0A00).
		;
		;  ?M - EXAMINE MEMORY
		;	  EXAMPLE:  ?MA00 3 <CR>
		;	    TYPES:  0A00 1122 33 <CR>
		;	TYPE THE SPECIFIED ADDRESS (0A00), THEN THE CONTENTS
		;	OF THE SPECIFIED NUMBER OF BYTES OF MEMORY (3). LONG
		;	LISTINGS CAN BE ABORTED BY TYPING A "BREAK".
		;
		;     - MOVE MEMORY
		;	  EXAMPLE:  ?MA00 3 !M800 <CR>
		;	MOVES A SPECIFIED NUMBER OF BYTES IN MEMORY (3) FROM
		;	FIRST ADDRESS (0A00) TO SECOND ADDRESS (0800). THE
		;	BLOCKS CAN OVERLAP WITHOUT ERROR.
		;
		;  ?R - EXAMINE CPU REGISTERS
		;	  EXAMPLE:  ?R <CR>
		;	    TYPES:  10B8 ID T  DF D  IE Q  EF1234
		;		    10C0 R0 R1 R2 R3 R4 R5 R6 R7
		;		    10D0 R8 R9 RA RB RC RD RE RF
		;	TYPES CONTENTS OF CPU REGISTERS SAVED AFTER THE LAST
		;	INTERRUPT, BREAKPOINT, OR RESET. "10B8" ETC. IS THE
		;	ADDRESS IN RAM WHERE THIS DATA IS STORED. REGISTER
		;	CONTENTS CAN BE CHANGED WITH A !M COMMAND, AND
		;	RESTORED WITH A $R COMMAND.
		;
		;  $P - RUN PROGRAM
		;	  EXAMPLE:  $PA00 <CR>
		;	BEGINS PROGRAM EXECUTION AT THE ADDRESS SPECIFIED
		;	(0A00) WITH P=X=R0 AND INTERRUPTS ENABLED.
		;
		;  $R - RUN REGISTERS
		;	  EXAMPLE:  $R23 <CR>
		;	BEGINS PROGRAM EXECUTION WITH THE CPU REGISTERS
		;	SET TO THE CONTENTS OF RAM LOCATIONS 10BA-10EF,
		;	AND X & P SET TO THE SPECIFIED VALUES (X=2, P=3).
		;
 0A34 F809	RESTART:LDI  HIGH TYPE5D; SET A POINTER TO TYPE5D

SOURCE FILE NAME: TB-MON.ASM					    PAGE 52


 0A36 B3		PHI  R3
 0A37 F89C		LDI  LOW TYPE5D
 0A39 A3		PLO  R3 	; TYPE "PROMPT" MESSAGE:
 0A3A D30D		DB   TYPA,13	; <CR>
 0A3C D30A		DB   TYPA,10	; <LF>
 0A3E D32A		DB   TYPA,'*'	; <*>
 0A40 F800	IGNORE: LDI  0
 0A42 BD		PHI  HEXX	; SET HEXX=0
 0A43 AD		PLO  HEXX
 0A44 F83B		LDI  LOW READAH ; REPEAT...
 0A46 A3		PLO  R3
 0A47 D3		SEP  R3 	; - GET A KEY
 0A48 FB24		XRI  '$'	; - IF "$",
 0A4A 32F2		BZ   DOLLAR	;	GO TO DOLLAR
 0A4C FB05		XRI  05H	; - IF "!",
 0A4E A8		PLO  R8 	;	SET SWITCH=0
 0A4F CE		LSZ		; - IF "?",
 0A50 FB1E		XRI  1EH	;	LEAVE SWITCH>0
 0A52 3A40		BNZ  IGNORE	; ...UNTIL ONE FOUND
		;
		; GET ADDRESS FOR ?M, !M, OR ?R COMMAND 
		;
 0A54 D3		SEP  R3 	; GET NEXT KEY
 0A55 FB52		XRI  'R'	; IF "R",
 0A57 3A65		BNZ  RDARGS
 0A59 F8B8		LDI  LOW SAVEREG;    SET ADDRESS TO SAVED REGISTERS
 0A5B AA		PLO  RA
 0A5C F810		LDI  HIGH SAVEREG	;; (COULD BE GHI R2)
 0A5E BA		PHI  RA
 0A5F F828		LDI  40 	;    SET #BYTES=40
 0A61 AD		PLO  HEXX	
 0A62 D3		SEP  R3 	;    GET NEXT KEY
 0A63 3081		BR   RD3	;    GO TYPE IT
 0A65 FB1F	RDARGS: XRI  1FH	; IF "M",
 0A67 3A40		BNZ  IGNORE
 0A69 D3	RD1:	SEP  R3 	;    IGNORE LEADING NON-HEX CHARS
 0A6A 3B69		BNF  $-1
 0A6C D3		SEP  R3 	;    ASSEMBLE HEX CHAR.INTO ADDRESS
 0A6D 336C		BDF  $-1
 0A6F FB20		XRI  20H	;    IF NEXT KEY NOT "SPACE",
 0A71 3AE7		BNZ  SYNERR	;	GO TO SYNTAX ERROR
 0A73 9D		GHI  HEXX
 0A74 BA		PHI  RA 	;    LET ADDRESS POINTER=HEXX
 0A75 8D		GLO  HEXX
 0A76 AA		PLO  RA 	; IF SWITCH=0,
 0A77 88		GLO  R8 	;    IS "!M" COMMAND;
 0A78 32D1		BZ   EX1	;    GO TO EX1
		;
		; ?M COMMAND - GET #BYTES TO TYPE
		;
 0A7A F800		LDI  0		; SET HEXX=0

SOURCE FILE NAME: TB-MON.ASM					    PAGE 53


 0A7C AD		PLO  HEXX
 0A7D BD		PHI  HEXX
 0A7E D3	RD2:	SEP  R3 	; GET KEYS & ASSEMBLE INTO HEX
 0A7F 337E		BDF  $-1
		;
		; DETERMINE IF TYPE OR MOVE COMMAND
		;
 0A81 8D	RD3:	GLO  HEXX	; SET #BYTES=HEXX
 0A82 A8		PLO  R8
 0A83 9D		GHI  HEXX
 0A84 B8		PHI  R8
 0A85 9F		GHI  ASCII	; GET LAST KEY
 0A86 FB21	RD5:	XRI  '!'	; IF "!",
 0A88 C20BB0		LBZ  MOVE	;    GO TO MOVE DATA
 0A8B FB01		XRI  01H	; IF "SPACE",
 0A8D 3A92		BNZ  $+5	;    IGNORE IT,
 0A8F D3		SEP  R3 	;    GET ANOTHER KEY
 0A90 3086		BR   RD5	;    REPEAT
 0A92 FB2D		XRI  2DH	; IF <CR>, GO TO TYPE
 0A94 3AE7		BNZ  SYNERR	;    ELSE SYNTAX ERROR
		;
		; TYPE SPECIFIED DATA
		;
 0A96 F89C	RD4:	LDI  LOW TYPE5D
 0A98 A3		PLO  R3
 0A99 D30A	NXLINE: DB   TYPA,0AH	; TYPE <LF>
 0A9B 3FE7		BN4  SYNERR	; IF "BREAK", GO TO SYNTAX ERROR
 0A9D 9A		GHI  RA 	; TYPE ADDRESS OF POINTER:
 0A9E BF		PHI  ASCII
 0A9F F8AE		LDI  LOW TYPE2
 0AA1 A3		PLO  R3
 0AA2 D3		SEP  R3 	; UPPER BYTE
 0AA3 8A		GLO  RA
 0AA4 BF		PHI  ASCII
 0AA5 F8AE		LDI  LOW TYPE2
 0AA7 A3		PLO  R3
 0AA8 D3		SEP  R3 	; LOWER BYTE
 0AA9 D320		DB   TYPA,' '	; TYPE A "SPACE"
 0AAB 4A	TLOOP:	LDA  RA 	; GET BYTE @ POINTER, & INC POINTER
 0AAC BF		PHI  ASCII
 0AAD F8AE		LDI  LOW TYPE2	; TYPE BYTE
 0AAF A3		PLO  R3
 0AB0 D3		SEP  R3
 0AB1 28		DEC  R8 	; DECREMENT #BYTES
 0AB2 88		GLO  R8
 0AB3 3AB8		BNZ  TL3	; IF #BYTES=0,
 0AB5 98		GHI  R8 	;    GO TO RESTART
 0AB6 3234		BZ   RESTART
 0AB8 8A	TL3:	GLO  RA 	; IF LINE IS FULL (ADDR IS XXX0),
 0AB9 FA0F		ANI  0FH
 0ABB 3AC3		BNZ  TL2

SOURCE FILE NAME: TB-MON.ASM					    PAGE 54


 0ABD D3		SEP  R3 	;    TYPE <;>
 0ABE 3B		DB   ';'	
 0ABF D3		SEP  R3 	;    TYPE <CR>
 0AC0 0D		DB   0DH
 0AC1 3099		BR   NXLINE	;    GO TO NEXT LINE
 0AC3 F6	TL2:	SHR		; IF ODD ADDRESS,
 0AC4 33AB		BDF  TLOOP	;    THEN TYPE NEXT BYTE
 0AC6 30A9		BR   TLOOP-2	;    ELSE GO TYPE A "SPACE" FIRST
		;
		; !M COMMAND - WRITES BYTES INTO MEMORY
		;
 0AC8 D3	EX3:	SEP  R3 	; GET KEYS UNTIL HEX
 0AC9 3BC8		BNF  $-1
 0ACB D3	EX2:	SEP  R3 	; GET 2ND HEX KEY
 0ACC 3BE7		BNF  SYNERR	; IF NOT HEX, SYNTAX ERROR
 0ACE 8D		GLO  HEXX	; STORE BYTE AT ADDRESS,
 0ACF 5A		STR  RA 	; INCREMENT ADDRESS
 0AD0 1A		INC  RA
 0AD1 D3	EX1:	SEP  R3 	; GET NEXT KEY
 0AD2 33CB		BDF  EX2	; IF HEX, SHIFT INTO ADDR & REPEAT
 0AD4 FB0D		XRI  0DH	; IF <CR>,
 0AD6 3234		BZ   RESTART	;    DONE: GO TO RESTART
 0AD8 FB21	EX4:	XRI  21H	; IF <,>,
 0ADA 32C8		BZ   EX3	;    CONTINUE ON NEW LINE
 0ADC FB17		XRI  17H	; IF <;>, CONTINUE
 0ADE 3AD1		BNZ  EX1	;    ELSE IGNORE KEY & REPEAT
 0AE0 D3		SEP  R3 	; IF <:>,
 0AE1 FB0D		XRI  0DH	;    IGNORE FURTHER KEYS UNTIL <CR>
 0AE3 3AE0		BNZ  $-3
 0AE5 3069		BR   RD1	; CONTINUE ON NEW LINE W. NEW ADDR
		;
		; SYNTAX ERROR
		;
 0AE7 F89C	SYNERR: LDI  LOW TYPE5D ; POINT TO TYPE5D
 0AE9 A3		PLO  R3
 0AEA D30D		DB   TYPA,0DH	; TYPE <CR>
 0AEC D30A		DB   TYPA,0AH	; <LF>
 0AEE D33F		DB   TYPA,'?'	; <?>
 0AF0 3034		BR   RESTART	; AND RESTART
		;
		; $P AND $R COMMANDS
		;
 0AF2 D3	DOLLAR: SEP  R3 	; GET KEY
 0AF3 FB52		XRI  'R'	; IF "R",
 0AF5 A8		PLO  R8 	;   SET SWITCH=0
 0AF6 CE		LSZ		; IF "P",
 0AF7 FB02		XRI  02H	;    LEAVE SWITCH>0
 0AF9 3A40		BNZ  IGNORE	; IGNORE ALL ELSE
		;
		; GET NUMBER FOR $R OR $P COMMAND
		;

SOURCE FILE NAME: TB-MON.ASM					    PAGE 55


 0AFB D3	D1:	SEP  R3 	; GET NEXT KEY
 0AFC 33FB		BDF  $-1	; IF HEX, ASSEMBLE ADDRESS & REPEAT
 0AFE FB0D		XRI  0DH	; IF NOT <CR>,
 0B00 CA0AE7		LBNZ SYNERR	;   GO TO SYNTAX ERROR
 0B03 9D		GHI  HEXX	; PUT NUMBER IN R0
 0B04 B0		PHI  R0
 0B05 8D		GLO  HEXX
 0B06 A0		PLO  R0
 0B07 F89C		LDI  LOW TYPE5D ; TYPE <LF>
 0B09 A3		PLO  R3
 0B0A D30A		DB   TYPA,0AH
 0B0C 88		GLO  R8 	; IF SWITCH>0,
 0B0D 3219		BZ   RESTORE	;    IS "$P" COMMAND; CONTINUE
		;
		; $P COMMAND - BEGIN EXECUTION AT SPECIFIED ADDRESS 
		;	WITH P=0, X=0, AND IE=1
		;
 0B0F F8C5		LDI  LOW INTRUPT; SET R1 FOR BREAKPOINT INTERRUPT
 0B11 A1		PLO  R1
 0B12 95		GHI  R5
 0B13 FF03		SMI  3
 0B15 B1		PHI  R1
 0B16 E5		SEX  R5 	; EXECUTE AT ADDRESS IN R0!
 0B17 70		RET
 0B18 00		DB   0
		;
		; $R COMMAND - RESTORE ALL CPU REGISTERS (EXCEPT "T")
		;	TO THE VALUES SAVED IN RAM, & EXECUTE WITH THE
		;	SPECIFIED VALUES OF X AND P.
		;
		;	NOTE: REGISTER NAMES IN PARENTHESES INDICATE THE
		;	VALUE IN RAM TO BE RESTORED TO THAT REGISTER.
		;
 0B19 F810	RESTORE:LDI  HIGH PAGE	; LET R2=POINTER TO RAM WHERE 
 0B1B B2		PHI  R2 	;   INITIALIZATION PROGRAM WILL
 0B1C B3		PHI  R3 	;   BE ASSEMBLED
 0B1D F8BF		LDI  LOW SAVEREG+7
 0B1F A2		PLO  R2
 0B20 E2		SEX  R2
 0B21 80		GLO  R0 	; ASSEMBLE LBR(R(P)) AS LAST OPCODE
 0B22 AD		PLO  HEXX
 0B23 FA0F		ANI  0FH	; - GET (P)
 0B25 FE		SHL		; - SET POINTER TO (R(P))
 0B26 FCC1		ADI  LOW SAVEREG+9
 0B28 A3		PLO  R3
 0B29 03		LDN  R3 	; - ASSEMBLE (R(P)) IN INIT. PROGRAM
 0B2A 73		STXD
 0B2B F89D		LDI  LOW RHERE	; - POINT ORIGINAL (R(P)) TO XX9E SO
 0B2D 53		STR  R3 	;   EXECUTION CONTINUES WHEN (P)=>P
 0B2E 23		DEC  R3
 0B2F 03		LDN  R3

SOURCE FILE NAME: TB-MON.ASM					    PAGE 56


 0B30 73		STXD
 0B31 95		GHI  R5
 0B32 53		STR  R3
 0B33 F0		LDX		; - RESTORE (Q) TO Q
 0B34 CE		LSZ		;   IF (Q)=1,
 0B35 7B		SEQ		;     THEN SET Q
 0B36 38		SKP		;     ELSE RESET Q
 0B37 7A		REQ
 0B38 F8C0		LDI  0C0H	; - FINISH TEMPLATE LBR INSTRUCTION
 0B3A 73		STXD
		;
		; ASSEMBLE LDI OPCODE TO INITIALIZE (D)
		;
 0B3B F0		LDX		; GET (IE) & SAVE FOR LATER
 0B3C BD		PHI  HEXX
 0B3D 22		DEC  R2 	; ASSMBLE LDI OPCODE TO INITIALIZE D
 0B3E 72		LDXA
 0B3F 73		STXD		; - ASSEMBLE (D)
 0B40 F8F8		LDI  0F8H	; - ASSEMBLE LDI
 0B42 73		STXD
 0B43 F0		LDX		; RESTORE (DF) TO DF
 0B44 F6		SHR
 0B45 F8A2		LDI  0A2H	; ASSEMBLE PLO R2 TO INITIALIZE R2.0
 0B47 73		STXD
 0B48 F8C5		LDI  LOW SAVEREG+13
 0B4A A3		PLO  R3 	; - ASSEMBLE (R2.0)
 0B4B 03		LDN  R3
 0B4C 73		STXD
 0B4D F8F8		LDI  0F8H	; - ASSEMBLE LDI
 0B4F 73		STXD
		;
		; NOW RESTORE ALL REGISTERS EXCEPT R2 & R5
		;
 0B50 F8C0		LDI  LOW SAVEREG+8
 0B52 A2		PLO  R2 	; SET R2 TO (R0)
 0B53 F0		LDX		; (R0)=>R0
 0B54 B0		PHI  R0
 0B55 9D		GHI  HEXX	; GET (IE) & SAVE IN (R0.1)
 0B56 52		STR  R2
 0B57 12		INC  R2
 0B58 F0		LDX
 0B59 A0		PLO  R0
 0B5A 8D		GLO  HEXX	; GET (XP) & SAVE IN (R0.0)
 0B5B 52		STR  R2
 0B5C 12		INC  R2
 0B5D 72		LDXA		; (R1)=>R1
 0B5E B1		PHI  R1
 0B5F 72		LDXA
 0B60 A1		PLO	R1
 0B61 60		IRX			; SKIP (R2)
 0B62 60		IRX

SOURCE FILE NAME: TB-MON.ASM					    PAGE 57


 0B63 72		LDXA			; (R3)=>R3
 0B64 B3		PHI	R3
 0B65 72		LDXA
 0B66 A3		PLO	R3
 0B67 72		LDXA			; (R4)=>R4
 0B68 B4		PHI	R4
 0B69 72		LDXA
 0B6A A4		PLO	R4
 0B6B 60		IRX			; SKIP (R5)
 0B6C 60		IRX
 0B6D 72		LDXA			; (R6)=>R6
 0B6E B6		PHI	R6
 0B6F 72		LDXA
 0B70 A6		PLO	R6
 0B71 72		LDXA			; (R7)=>R7
 0B72 B7		PHI	R7
 0B73 72		LDXA
 0B74 A7		PLO	R7
 0B75 72		LDXA			; (R8)=>R8
 0B76 B8		PHI	R8
 0B77 72		LDXA
 0B78 A8		PLO	R8
 0B79 72		LDXA			; (R9)=>R9
 0B7A B9		PHI	R9
 0B7B 72		LDXA
 0B7C A9		PLO	R9
 0B7D 72		LDXA			; (RA)=>RA
 0B7E BA		PHI	RA
 0B7F 72		LDXA
 0B80 AA		PLO	RA
 0B81 72		LDXA			; (RB)=>RB
 0B82 BB		PHI	RB
 0B83 72		LDXA
 0B84 AB		PLO	RB
 0B85 72		LDXA			; (RC)=>RC
 0B86 BC		PHI	RC
 0B87 72		LDXA
 0B88 AC		PLO	RC
 0B89 72		LDXA			; (RD)=>RD
 0B8A BD		PHI	RD
 0B8B 72		LDXA
 0B8C AD		PLO	RD
 0B8D 72		LDXA			; (RE)=>RE
 0B8E BE		PHI	RE
 0B8F 72		LDXA
 0B90 AE		PLO	RE
 0B91 72		LDXA			; (RF)=>RF
 0B92 BF		PHI	RF
 0B93 F0		LDX
 0B94 AF		PLO	RF
		;

SOURCE FILE NAME: TB-MON.ASM					    PAGE 58


		; CHANGE PROGRAM COUNTER TO DESIRED REGISTER
		;
 0B95 F8C0		LDI  LOW SAVEREG+8
 0B97 A2		PLO  R2 	; SET POINTER TO SAVED (IE)
 0B98 72		LDXA		;   GET IT
 0B99 CE		LSZ		;   IF (IE)=1,
 0B9A 70		RET		;     THEN SET IE=1, P=(P), X=(X)
 0B9B 38		SKP
 0B9C 71		DIS		;     ELSE SET IE=0
		;
		; NOW SET UP R5 (IF NOT PC), R2, & D 
		;
 0B9D 15	RHERE:	INC  R5 	; IF R5 IS NOT THE PROGRAM COUNTER,
 0B9E C8		LSKP
 0B9F 30A8		BR   R5PC
 0BA1 F8CA		LDI  LOW SAVEREG+18
 0BA3 A2		PLO  R2 	;   THEN SET POINTER TO (R5)
 0BA4 42		LDA  R2 	;     R5=(R5)
 0BA5 B5		PHI  R5
 0BA6 02		LDN  R2
 0BA7 A5		PLO  R5
 0BA8 F8C4	R5PC:	LDI  LOW SAVEREG+12
 0BAA A2		PLO  R2 	; R2.1=(R2.1)
 0BAB 02		LDN  R2
 0BAC B2		PHI  R2
 0BAD C010B8		LBR  SAVEREG	; JUMP TO TEMPLATE PROGRAM
		;
		; SAMPLE TEMPLATE PROGRAM CREATED IN RAM
		;
		;	ORG  10B8H
		;	LDI  (R2.0)	; RESTORE SAVED VALUE OF R2.0
		;	PLO  R2
		;	LDI  (D)	; SAVED VALUE OF D
		;	LBR  R(P)	; JUMP TO SAVED PROGRAM COUNTER
		;
		; BLOCK MOVE COMMAND  (?MXXXX XX !MXXXX)
		;
 0BB0 D3	MOVE:	SEP  R3 	; GET NEXT KEY
 0BB1 FB4D		XRI  'M'	; IF "M",
 0BB3 3ABA		BNZ  $+7	;    THEN CLEAR HEXX
 0BB5 BD		PHI  HEXX	;    ELSE SYNTAX ERROR
 0BB6 AD		PLO  HEXX
 0BB7 D3		SEP  R3 	; GET HEX ADDRESS OF DESTINATION
 0BB8 33B7		BDF  $-1
 0BBA FB0D		XRI  0DH	; IF NOT <CR>,
 0BBC CA0AE7		LBNZ SYNERR	;    GO TO SYNTAX ERROR
		;
		; TEST IF MOVE UP/MOVE DOWN (TRICKY WITHOUT RAM)
		;
 0BBF 9A		GHI  RA 	; COPY SOURCE ADDRESS INTO R3
 0BC0 B3		PHI  R3

SOURCE FILE NAME: TB-MON.ASM					    PAGE 59


 0BC1 8A		GLO  RA
 0BC2 A3		PLO  R3
 0BC3 9D		GHI  HEXX	; COPY DESTINATION INTO RF
 0BC4 BF		PHI  RF
 0BC5 8D		GLO  HEXX
 0BC6 AF		PLO  RF
 0BC7 93	UPDOWN: GHI  R3 	; - IF SOURCE=0,
 0BC8 3ACB		BNZ  $+3	;     SOURCE<DEST; MOVE DATA UP
 0BCA 83		GLO  R3
 0BCB 32E2		BZ   MOVEUP
 0BCD 23		DEC  R3 	; - DECREMENT SOURCE
 0BCE 9F		GHI  RF 	; - IF DESTINATION=0,
 0BCF 3AD2		BNZ  $+3	;     SOURCE>DESTINATION,
 0BD1 8F		GLO  RF 	;     MOVE DATA DOWN
 0BD2 2F		DEC  RF 	; - DECREMENT DESTINATION
 0BD3 3AC7		BNZ  UPDOWN
		;
		; SOURCE > DESTINATION: MOVE DATA DOWN
		;
 0BD5 98	MOVEDN: GHI  R8 	; REPEAT...
 0BD6 3AD9		BNZ  $+3	; ...UNTIL #BYTES=0
 0BD8 88		GLO  R8
 0BD9 C20A34		LBZ  RESTART	; THEN RESTART
 0BDC 4A		LDA  RA 	; - LOAD VIA SOURCE
 0BDD 5D		STR  HEXX	; - STORE VIA DESTINATION
 0BDE 1D		INC  HEXX	; - INCREMENT POINTERS
 0BDF 28		DEC  R8 	; - DECREMENT #BYTES
 0BE0 30D5		BR   MOVEDN
		;
		; SOURCE <= DESTINATION: MOVE DATA UP
		;
 0BE2 98	MOVEUP: GHI  R8 	; COPY #BYTES INTO R3
 0BE3 B3		PHI  R3
 0BE4 88		GLO  R8
 0BE5 A3		PLO  R3
 0BE6 C8		LSKP		; SET POINTERS TO HIGH END OF DATA
 0BE7 1A	UP:	INC  RA 	; REPEAT...
 0BE8 1D		INC  HEXX
 0BE9 23		DEC  R3 	; - INC. SOURCE
 0BEA 93		GHI  R3 	; - INC. DESTINATION
 0BEB 3AE7		BNZ  UP 	; - DEC. #BYTES
 0BED 83		GLO  R3
 0BEE 3AE7		BNZ  UP 	; ...UNTIL #BYTES=0
 0BF0 ED		SEX  HEXX	; REPEAT TO MOVE FROM TOP DOWN...
 0BF1 98	MUP:	GHI  R8 	; ...UNTIL #BYTES=0
 0BF2 3AF5		BNZ  $+3
 0BF4 88		GLO  R8
 0BF5 C20A34		LBZ  RESTART	; THEN RESTART
 0BF8 0A		LDN  RA 	; - LOAD VIA SOURCE
 0BF9 73		STXD		; - STORE VIA DESTINATION
 0BFA 2A		DEC  RA 	; - DECREMENT POINTERS

SOURCE FILE NAME: TB-MON.ASM					    PAGE 60


 0BFB 28		DEC  R8
 0BFC 30F1		BR   MUP
		;
		; IOBIT - TINY BASIC USR FUNCTION TO EXAMINE EF1-4 AND Q,
		;	AND SET/RESET Q. USAGE:
		;
		;	USR(35, EXPRESSION2, EXPRESSION3)
		;
 0BFE C20C06	IOBIT:	LBZ  IOBIT1	; 3RD EXPRESSION:
 0C01 F6		SHR		;   IF =0, LEAVE Q AS IS
 0C02 C6		LSNZ
 0C03 7B		SEQ		;   IF =1, SET Q
 0C04 38		SKP		;   IF >1, RESET Q
 0C05 7A		REQ
 0C06 88	IOBIT1: GLO  R8 	; 2ND EXPRESSION:
 0C07 C6		LSNZ		;   IF =0,
 0C08 3920		BNQ  IOBIT2	;     AND Q=0, RETURN 0
 0C0A FF01		SMI  1		;	ELSE RETURN 1
 0C0C C6		LSNZ		;   IF =1,
 0C0D 3C20		BN1  IOBIT2	;     AND EF1=0, RETURN 0
 0C0F FF01		SMI  1		;	ELSE RETURN 1
 0C11 C6		LSNZ		;   IF =2,
 0C12 3D20		BN2  IOBIT2	;     AND EF2=0, RETURN 0
 0C14 FF01		SMI  1		;	ELSE RETURN 1
 0C16 C6		LSNZ		;   IF =3,
 0C17 3E20		BN3  IOBIT2	;     AND EF3=0, RETURN 0
 0C19 FF01		SMI  1		;	ELSE RETURN 1
 0C1B C6		LSNZ		;   IF =4,
 0C1C 3F20		BN4  IOBIT2	;     AND EF4=0, RETURN 0
 0C1E F801		LDI  1		;	ELSE RETURN 1
 0C20 D5	IOBIT2: SEP  R5
		
 0000			END

SOURCE FILE NAME: TB-MON.ASM					    PAGE 61
---- SYMBOL TABLE ----

ABS	07EE	DFLT	073F	GOTO	0684	LINO	0028	P1	06B1
AC	000A	DIVL	03EA	GS	0014	LIST	053C	P10	06CB
AD	0018	DNEG	0413	HERE	09FF	LISTIT	071A	P11	06CD
AEPTR	001A	DOIT	0142	HEX2	09EB	LISX	0720	P12	06CC
AESTK	0080	DOLLAR	0AF2	HEXX	000D	LIT1	0241	P2	06B3
AIL	001E	DS	000B	HMUCH	05D9	LITN	0244	P3	06B7
APOP	01C5	DUPS	024E	HOOK	0249	LIX	057B	P4	06BB
APUSH	0254	DV	001B	HOOP	0525	LLINE	0550	P5	06BE
ARG	0744	E0	074F	HOP	01A0	LLOOP	0567	P6	06C2
ASCII	000F	E1	0753	HX22	09F5	LN	000A	P7	06C4
ATMSG	02BD	E2	0759	I1	06DC	LS	001F	P8	06C6
BACK	0198	E3	0748	I2	06E7	MAL	0223	P9	06C7
BASIC	0020	E4	0751	I3	06EA	MATCH	021F	PAD	0015
BAUD	000E	E5	0747	I4	06F1	MEND	0024	PADS	02DF
BC	007F	END	0707	I5	06F3	MONITOR	066F	PAGE	1000
BE	00DF	ERR	027F	I6	06FA	MORE	061E	PC	0009
BEGIN	09C1	EX1	0AD1	IADD	039B	MOVE	0BB0	PDIV	03E3
BELL	02A9	EX2	0ACB	IDIV	03CB	MOVEDN	0BD5	PDVL	032E
BERR	044B	EX3	0AC8	IF	06CE	MOVEUP	0BE2	PEEK	0014
BIT	0959	EX4	0AD8	IFINT	08CF	MOVIOV	0875	PEND	011A
BN	00BF	EXIT	02B5	IGNORE	0A40	MP	001A	PLF	02EF
BNEXT	0488	EXPR	0749	IIL	0128	MT	002B	PN	0020
BP	000B	F0	07DA	IL	002A	MULC	03C5	POKE	0018
BPOP	01C9	F1	07E3	IMUL	03A7	MULL	03B1	PQ	0021
BPUSH	0259	F2	0777	INCR	0919	MUP	0BF1	PRN	0318
BR	005F	F3	0786	IND	0267	NEG	0418	PRNA	0315
BREAK	0446	F4	0789	INEG	040E	NEGX	0421	PRNL	033E
BREAKV	100C	F5	078B	INP	06E0	NEW	05BA	PRNT	06A8
BS	0013	F6	078E	INSRT	05A2	NEWM	0A09	PRP	0325
BV	009F	F7	0793	INSX	064E	NEWQ	0A1F	PRS	0279
BZERR	01A1	FACT	076E	INTRUPT	08C5	NEXT	012D	PS	0024
CALL	002A	FECH	00D7	IO	0651	NEXTBIT	09C6	PT	0022
CAN	0014	FEND	0512	IOBIT	0BFE	NFND	0937	PZ	000D
CANCL	04D7	FETCH	004B	IOBIT1	0C06	NG	0017	QUOTE	0270
CEQ	038F	FIN	02B1	IOBIT2	0C20	NHOP	021C	R0	0000
CHIN	04EC	FIND	04FE	ISUB	0398	NL	0023	R1	0001
CKDEC	092F	FINDX	0508	JHOP	0234	NM10	0205	R2	0002
CLEAR	0104	FLINE	050D	JMP	017A	NO	0008	R3	0003
CLER	0715	FND	0988	JS	3000	NOBIT	0957	R4	0004
CLT	0392	FND1	098F	JU	3800	NOECHO	0962	R5	0005
CMPR	036C	FORCE	02CC	KEYBD	0006	NONBL	01AA	R5PC	0BA8
COLD	00B0	FUNC	0795	KEYV	1006	NONBX	01B4	R6	0006
COMMAND	09F8	FV	0012	KLOOP	04B2	NTAPE	04A1	R7	0007
CONST	001C	G1	0699	L0	0680	NUMB	01FB	R8	0008
CONT	0438	G2	069B	L1	072C	NX	001D	R9	0009
CP	001C	GETLN	04AA	L2	0727	NXA	001C	RA	000A
CRLF	02D5	GL	0027	LB	0009	NXCHAR	09DD	RB	000B
D1	0AFB	GLINO	0598	LDI0	0097	NXLINE	0A99	RC	000C
DAUX	091E	GO	0016	LEND	0019	NXT	0429	RD	000D
DELAY	000C	GOAL	0465	LET	06A3	OUTBIT	0961	RD1	0A69
DELAY1	08EF	GOSB	068F	LINE	1030	P0	06AF	RD2	0A7E

SOURCE FILE NAME: TB-MON.ASM					    PAGE 62
---- SYMBOL TABLE ----

RD3	0A81	RR7	07BD	STEST	0237	TBRK	000C	TYPE5D	099C
RD4	0A96	RS	0015	STMT	069C	TC	090D	TYPE6	09A2
RD5	0A86	RSBP	0348	STOK	04DD	TEND	01D4	TYPED	0009
RDARGS	0A65	RSTR	046D	STOP	0978	TERM	075F	TYPER	02F4
RE	000E	RT	002F	STORE	01B6	TIMALC	08FE	TYPEV	1009
READ	093E	RT1	0704	STRNG	02C5	TJMP	016A	TYPEXIT	099F
READ2	0943	RTN	0481	STRT	0679	TL2	0AC3	TYX	035D
READAH	093B	RTRN	06FC	STUFF	0630	TL3	0AB8	UP	0BE7
RELO	0798	RUN	0442	SU	0019	TLOOP	0AAB	UPDOWN	0BC7
REM	073A	RUNN	070D	SV	0013	TOPS	0026	US	002E
RESTART	0A34	SAV	0581	SVBP	034B	TSTBR	0666	USER	1100
RESTORE	0B19	SAVEND	00DF	SWAP	035E	TSTN	01F0	WAIT	092C
RETN	01D3	SAVER	0800	SX	0000	TSTR	02C2	WARM	00ED
RETRN	003C	SAVEREG	10B8	SYNERR	0AE7	TSTV	01DD	WORK	002A
REXIT	0939	SB	0010	T0	0761	TTOK	049C	WS	002D
RF	000F	SCAN	00C6	T1	0767	TTOP	048B	X	000F
RHERE	0B9D	SEEKROM	0880	T2	076D	TTY1	094D	X1	0683
RP	0011	SEP5	0266	TAB	0303	TTYCC	001B	XCHG	0185
RR0	079D	SHAL	0422	TABLE	0054	TTYRED	0940	XEC	068B
RR1	07A1	SHCL	0424	TABS	030A	TY2	09BE	XEQ	0018
RR2	07B5	SKIP	0396	TAPE	049E	TY3	09C0	XFER	0460
RR3	07A7	SKIPIT	06B5	TBEND	00B0	TYPA	00D3	XINIT	044E
RR4	07AC	SP	002E	TBERR	015C	TYPE	09A4	XQ	002C
RR5	07B2	SPARE	0017	TBIL	0679	TYPE2	09AE	XX	0008
RR6	07B8	STACK	0022	TBR	014B	TYPE5	09A0	ZTO1	0917

***** NO ERRORS DETECTED *****
