; 2025-01-30 Modified to assemble online at asm80.com ; Changes: ; Decimal numbers had trailing 'D' removed. ; Assembles, but not checked yet. ; .cpu 8080 ; ;PROGRAMM TO WRITE INTO CHARACTER MEMORY ;BY MOSHE M. SHAVIT ;REV 0 3/6/78 STACK EQU 1FFH ;STACK POINTER FAR EQU 0FFH ;FIRST ADDRESS REGISTER O/P PORT CHARAD EQU 8000H ;CHARACTER MEMORY STARTS HERE ORG STACK+1 ;WORKING SPACE ABOVE STACK FA DS 1 ;FIRST ADDRESS CURAD DS 2 ;CURRENT ADDRESS FIL DS 2 ;A(FIRST CHARACTER IN LINE) ; ORG 100H ;PROGRAM STARTS HERE LXI SP,STACK LXI H,730H+CHARAD ;LAST LINE, FIRST CHARACTER SHLD FIL ; SHLD CURAD ;AND IN CURRENT ADDRESS BUFFER XRA A ;CLEAR A OUT FAR ;START ADDRESS=0 STA FA ;SAVE IN BUFFER CALL CLEAR ;CLEAR ALL CHAR. MEMORY MAIN: CALL CHARIN ;READ CHARACTER AND PUT IN CHAR. MEMORY JMP MAIN ;DO IT AGAIN CLEAR: MVI B,0 ;DATA=0 LXI H,CHARAD ;FIRST CHARACTER ADDRESS LXI D,2048 ;COUNTER CLEAR1: MOV M,B ;CLEAR THAT ADDRESS DCX D ;COUNT INX H ;NEXT ADDRESS MOV A,D ;CHECK ORA E ; IF DONE JNZ CLEAR1 ;NO, CONTINUE RET ;YES, BACK TO CALLER CHARIN: MVI C,1 ;CP/M READ CODE CALL 5 ;CP/M READ ROUTINE CPI 1AH ;CTL-Z? JZ 0 ;RETURN TO CPM IF YES LHLD CURAD ;FETCH CURRENT ADDRESS CPI 0DH ;CR? JZ CRLF ;YES. MOV M,A ;WRITE CHARACTER INX H ;INCREMENT SHLD CURAD ;STORE IN BUFFER RET ;BACK TO CALLER ; ; CRLF: PUSH H PUSH D PUSH B PUSH PSW MVI E,0AH MVI C,2 CALL 5 POP PSW POP B POP D POP H ;ROUTINE TO ECHO LF XCHG ;SAVE CURRENT ADDRESS IN DE LXI B,80 ;80 CHARACTERS/LINE LHLD FIL ;FETCH FIRST CH. IN LINE ADDRESS DAD B ;HL= A(NEXT LINE'S FIRST CH. ADD.) XCHG ;HL= CURRENT ADDR.,DE=A(NEXT LINE FIRST CH. ADDR) MVI B,0 ;DATA=0 CRLF2: MOV A,H ;MORE SIGNIFICANT CURRENT ADDRESS CMP D ;=NEXT LINE FIRST ADDRESS JNZ CRLF3 ;NO MOV A,L ;LESS SIGNIFICANT CURRENT ADDRESS CMP E ; IS CURRENT LINE FULL? JZ CRLF4 ;YES CRLF3: MOV M,B ;STORE 0 AT THAT ADDRESS INX H ;INCREMENT ADDRESS JMP CRLF2 ;GO CHECK AGAIN CRLF4: MOV A,H ;MORE SIGNIFICANT PART OF ADDRESS ANI 7 ;ONLY 3 LESS SIGNIFICANT BITS CPI 7 ;LAST LINE PASSED? JNZ CRLF5 ;NOT YET MOV A,L ;LESS SIGNIFICANT BYTE OF ADDRESS CPI 80H ;ARE WE AT 780H=1920D? JNZ CRLF5 ;NOT YET, SKIP LXI H,CHARAD ;YES, START WRITING AT BEGINNING OF CH. MEM. CRLF5: SHLD FIL ;STORE IN FIRST CH. IN LINE BUFFER SHLD CURAD ;AND IN CURRENT ADDRESS BUFFER LDA FA ;FETCH FIRST VISIBLE CHARACTER ADDRESS ADI 5 ;SCROLL CPI 120 ;TOO MUCH? CZ CRLF0 ;YES STA FA ;STORE IN FIRST ADDRESS BUFFER OUT FAR ;LOAD REGISTER RET ;RETURN TO CALLER ; ; CRLF0: XRA A ;FIRST ADDRESS=O RET