; GT40 demo program.
; Display a blob of light which follows the light pen around the screen.
; (ie it can be dragged).
; 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
	MOV	#STARTY,R4	; Address of starting y coordinate in DPROG
	MOV	#DLOOP,R3	; continuation address for DPU after DSTOP

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

	MOV     #DPROG,(R5)	; Start graphics processor
LOOP:	WAIT			; Mouch about...
	BR	LOOP
	
; Display program: full-screen raster scan

; What to do on a Display Stop interrupt
STOPINTR:
	DEC	(R4)		; move down one raster line
	DEC	(R4)		; move down one raster line
	BMI	L1		; if off bottom of screen, start again at top
L2:	MOV     R3,(R5) 	; Restart graphics processor
	RTI
	
L1:	MOV	#HEIGHT-1,(R4)
	BR	L2


;		Light pen interrupt service routine
LPINTR:
	MOV	#1,(R5)		; Continue display
	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
	
DLOOP:
	POINT
STARTX:	0
STARTY:	HEIGHT-1
	LONGV
DX:	INTX+WIDTH-1		; left to right
DY:	0
	0			; down a line
	MINUSY+1
	INTX+MINUSX+WIDTH-1	; and back
	0
	DSTOP

END:	.END
