; GT40 demo program.
; Generate test pattern 4-14 for adjustment of DPU display board.
; Adjust R131 on A320 module until vectors meet the vertical line
; Martin Guy, June 1988.

; Constants about machine.

COREND	= 40000		; 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

	; Constants held in registers for quick access
	MOV	#DPC,R5		; Address of DPU program counter

	; Set up interrupt vectors
	MOV	#STOPINTR,@#320	; DPU DSTOP instruction	(priority level 4)
	MOV	#200,@#322	; new CPU priority = 4 - no nested intrs

	JSR	PC,GENDPROG

	MOV     #DPROG,(R5)	; Start graphics processor
LOOP:	WAIT			; Mouch about...
	BR	LOOP

	

; display 0: figure 4-14: Horizontal Vector Angle Pattern
; display 1: figure 4-15: Vertical Vector Angle Pattern
; display 2: figure 4-12: Octagons pattern

; Locations of the three display files,
DISP0:	.WORD	1
DISP1:	.WORD	1	; display1: figure 4-15
DISP2:	.WORD	1

NDISP	= 2		; number of display patterns we have

	;		Create display program
GENDPROG:
	; R0 - next DPU program address to write to
	; R1 - Y coord for RHS of sloping vectors

	MOV	#END,R0	; start of new code

STEP	= 32.		; y increment.  Must be exact divisor of HEIGHT(=768)
XSIZE	= WIDTH-STEP
YSIZE	= HEIGHT-STEP

	MOV	R0,@#DISP0	; remember address of display 0

	; draw all lines in both directions: they should coincide.

	MOV	#POINT,(R0)+
	MOV	#XSIZE,(R0)+			; Line from Bottom right
	MOV	#0,(R0)+

	MOV	#LONGV,(R0)+	
	MOV	#INTX+0,(R0)+			; to top right
	MOV	#YSIZE,(R0)+

	MOV	#INTX+XSIZE+MINUSX,(R0)+	; to top left
	MOV	#0,(R0)+

	MOV	#INTX+XSIZE,(R0)+		; and back to top right
	MOV	#0,(R0)+

	MOV	#INTX+0,(R0)+			; and to bottom right
	MOV	#YSIZE+MINUSY,(R0)+

	; loop to draw sloping vectors
	MOV	#YSIZE,R1

	MOV	#POINT,(R0)+		; Move to bottom left
	MOV	#0,(R0)+
	MOV	#0,(R0)+

L5:	MOV	#LONGV,(R0)+		; line to rhs of screen
	MOV	#INTX+XSIZE,(R0)+
	MOV	R1,(R0)+

	MOV	#INTX+XSIZE+MINUSX,(R0)+	; and back
	MOV	R1,(R0)
	BIS	#MINUSY,(R0)+

	SUB	#STEP,R1
	BPL	L5

	MOV	#DSTOP,(R0)+	; End of DPU loop - check switches again

	;		Display1: vertical sloping lines

	MOV	R0,@#DISP1	; remember address of display 1

	MOV	#POINT,(R0)+
	MOV	#XSIZE,(R0)+			; Line from Bottom right
	MOV	#0,(R0)+

	MOV	#LONGV,(R0)+	
	MOV	#INTX+0,(R0)+			; to top right
	MOV	#YSIZE,(R0)+

	MOV	#INTX+XSIZE+MINUSX,(R0)+	; to top left
	MOV	#0,(R0)+

	MOV	#INTX+XSIZE,(R0)+		; and back to top right
	MOV	#0,(R0)+

	MOV	#INTX+0,(R0)+			; and to bottom right
	MOV	#YSIZE+MINUSY,(R0)+

	; Loop
	MOV	#XSIZE,R1

	MOV	#POINT,(R0)+	; Move to bottom left
	MOV	#0,(R0)+
	MOV	#0,(R0)+

L3:	MOV	#LONGV,(R0)+	; line to top of screen
	MOV	R1,(R0)		; no ()+ -- need to intensify it as well
	BIS	#INTX,(R0)+
	MOV	#YSIZE,(R0)+

	MOV	R1,(R0)		; and back
	BIS	#INTX+MINUSX,(R0)+
	MOV	#YSIZE+MINUSY,(R0)+

	SUB	#STEP,R1
	BPL	L3

	MOV	#DSTOP,(R0)+	; End of DPU loop - check switches again

	;		End of DPU code generator
	RTS	PC


; What to do on a Display Stop interrupt
STOPINTR:
L2:	; test switch register and select appropriate test program
	BIT	#1,@#177570
	BNE	L4
	; display 0
	MOV	@#DISP0,(R5)
	RTI

L4:	MOV     @#DISP1,(R5) 	; Restart graphics processor
	RTI


;		Display program
DPROG:
	; Set up, point mode, intensity 4, no light pen or
	; blink and solid lines. Move to (500, 500). Enter
	; long vector mode

	POINT+INT2+LPOFF+BLKOFF+LINE0
	STATSA+SINOFF+LPLITE+ITAL0
	DSTOP	; cause it all to happen

END:	.END
