; Constants about machine.

COREND	= 8.*1024.	; First unusable word


WIDTH	= 1024.		; Height of display
HEIGHT	= 768.		; Width of display

; Address of registers.

DPC     = 172000        ; VT40 Program counter
DSR     = 172002        ; VT40 Status register
XSR     = 172004        ; X status register
YSR     = 172006        ; Y status register

; Recommended mnemomics

CHAR    = 100000        ; Character mode
SHORTV  = 104000        ; Short vector mode
LONGV   = 110000        ; Long vector mode
POINT   = 114000        ; Point mode
GRAPHX  = 120000        ; Graphplot X mode
GRAPHY  = 124000        ; Graphplot Y mode
RELATV  = 130000        ; Relative point mode

INT0    = 2000          ; Intensity modes
INT1    = 2200
INT2    = 2400
INT3    = 2600
INT4    = 3000
INT5    = 3200
INT6    = 3400
INT7    = 3600

LPOFF   = 100           ; Light pen off
LPON    = 140           ; and on

BLKOFF  = 20            ; Blink off
BLKON   = 30            ; and on

LINE0   = 4             ; Solid line
LINE1   = 5             ; Long dash
LINE2   = 6             ; Short dash
LINE3   = 7             ; Dot dash

DJMP    = 160000        ; Display jump
DNOP    = 164000        ; Display NOP

STATSA  = 170000        ; Load status A
DSTOP   = 173400        ; Display stop and interrupt

SINON   = 1400          ; Stop interrupt on
SINOFF  = 1000          ; Stop interrupt off
LPLITE  = 200           ; Light pen hit on
LPDARK  = 300           ; and off

ITAL0   = 40            ; Italics off
ITAL1   = 60            ; and on

SYNC    = 4             ; Halt and resume in Sync

STATSB  = 174000        ; Load status B
INCR    = 100           ; Graphplot increment

INTX    = 40000         ; Intensify vector or point
MAXX    = 1777          ; Max delta-x
MAXY    = 1377          ; Max delta-y

MINUSX  = 20000         ; -ve delta-x
MINUSY  = 20000         ; -ve delta-y

MAXSX   = 17600         ; Max delta-x in short mode
MAXSY   = 77            ; Max delta-y

MISVX   = 20000         ; -ve delta-x
MISVY   = 100           ; -ve delta-y

        .PSECT

;       Simple PDP-11 program

	MOV	#COREND-2,SP	; Set up stack
	JSR	PC,MAIN		; write DPROG
DISPLAY:
	MOV	#DJMP,(R3)+	; fix up end of display program
	MOV	#DLOOP,(R3)+

	MOV	#DPROG,@#DPC	; start displayprocessor runnig

MLOOP:	JSR	PC,MAIN
	BR	MLOOP

; R2 - x
; R3 - DPC when writing display file
MAIN:	MOV	#END,R3		; where to start writing point data
	CLR	R2		; start x at 0

LOOP:
	; compute next point on graph
	MOV	R2,R0
	MOV	@#177570,R1
	JSR	PC,DIVIDE
	MOV	R0,(R3)+
	INC	R2
	CMP	#WIDTH-1,R2
	BPL	LOOP		; loop until x>WIDTH-1
	RTS	PC


	; R0 := R0 / R1, remainder in R2, R1 is positivised
	; R0 is top, shifted into R2 one bit at a time.
	; R3 is the loop counter.
DIVIDE:
	MOV	R2,-(SP)
	MOV	R3,-(SP)
	TST	R1	; Validate divisor
	BEQ	DIV0	; divide by 0!
	BPL	DIV1
	NEG	R1
DIV1:
	CLR	R2
	MOV	#15.,R3		; 16 iterations
DIV2:
	ASL	R0
	ROL	R2
	CMP	R2,R1		; can we subtract bottom from top?
	BCS	DIV3		; no
	SUB	R1,R2		; yes - do it.
	BIS	#1,R0
DIV3:	DEC	R3
	BPL	DIV2

DIVEND:	MOV	(SP)+,R3
	MOV	(SP)+,R2
	RTS	PC

DIV0:	; divide by 0.  return 0. (any other ideas?)
	CLR	R0
	BR	DIVEND
; end of DIVIDE

DPROG:	
	STATSB+INCR+1

DLOOP:	POINT
	0
	0
	GRAPHY
END:	.END
	; rest of display program follows...
