; loadmeterml.dsm
; L. Stewart, January 10, 1984  9:08 PM, created
; L. Stewart, January 12, 1984  1:27 PM, add DoubleUMul

C←CODE SEGMENT

$INCLUDE(LoadMeter.d)

C←DATA	SEGMENT

; io device initialization strings

; The format of this stuff is <port address><byte count><bytes>
; port FF terminates the list

; first set up the 8255 and reset all its outputs
←IPIO LABEL BYTE
	DB	lmpioctl
	DB	1
	DB	082H	; Port A, C output, B input, all mode 0

; P1A (output)
; P1A7 LedP100
; P1A6 LedP30
; P1A5 LedP10
; P1A4 LedP3
; P1A3 LedB100
; P1A2 LedB30
; P1A1 LedB10
; P1A0 LedB3

	DB	lmpioa
	DB	1
	DB	000H

; switches (input)

	DB	lmpiob
	DB	1
	DB	000H

; P1C output
; P1C7 LedT10
; P1C6 LedT3
; P1C5 LedT1
; P1C4 LedT03
; P1C3 LedPAuto
; P1C2 LedBAuto
; P1C1 Unused
; P1C0 Unused

	DB	lmpioc
	DB	1
	DB	000H

; See Lark9513.txt for explanations
←ITimer LABEL BYTE
	DB	lmTimCtl
	DB	5
	DB	0FFH		; master reset
	DB	05FH		; load all counters (cookbook)
	DB	001H		; set dp (cookbook)
	DB	0E0H		; enable sequencing
	DB	017H		; set pointer to MM register

	DB	lmTimData
	DB	2
	DB	0C0H		; FOut from F2, no compare, TOD
	DB	088H		; BCD, enable sequencing, 8-bit
			; bus, FOut on, FOut / 8

	DB	lmTimCtl
	DB	6
	DB	0E1H		; set all outputs low
	DB	0E2H
	DB	0E3H
	DB	0E4H
	DB	0E5H

	DB	001H

; set up all counter channels
	DB	lmTimData
	DB	30

; meter 1
	DB	062H		; mode J, toggle
	DB	01BH		; no gate, F1
	DB	0F4H		; low for 1F4 (500 decimal)
	DB	001H
	DB	0F4H		; high for 1F4 (500 decimal)
	DB	001H

; meter 2
	DB	062H		; mode J, toggle
	DB	01BH		; no gate, F1
	DB	0F4H		; low for 1F4 (500 decimal)
	DB	001H
	DB	0F4H		; high for 1F4 (500 decimal)
	DB	001H

; packets per second
	DB	022H		; Mode D
	DB	003H		; no gate, input C3
	DB	000H		; loop 4000H
	DB	040H
	DB	000H
	DB	000H

; bits per second
	DB	022H		; Mode E, gated mode D
	DB	08DH		; high gate N, F3 (50 KHz)
	DB	000H		; loop 4000H
	DB	040H
	DB	000H
	DB	000H

; real time clock
	DB	022H		; Mode D
	DB	00EH		; no gate, input F4 (5 KHz)
	DB	000H		; loop 4000H
	DB	040H
	DB	000H
	DB	000H

	DB	lmTimCtl
	DB	2
	DB	05FH		; Load all counters
	DB	03FH		; Arm all counters

	DB	0FFH


C←DATA ENDS

; DoubleUMul(a, b)
; int a[2], b;
; multiply (long) a by b
; (result in a)
←DoubleUMul	PROC	NEAR
	PUSH	BP
	MOV	BP,SP
	MOV	SI,CX
	MOV	AX,[2+SI]
	OR	AX,AX
	JNZ	HiPart
	XOR	CX,CX
	JMP	NoHiPart
HiPart:
	MUL	BX
	MOV	CX,AX	;temp save result
NoHiPart:
	MOV	AX,[SI]
	MUL	BX
	ADD	DX,CX
	POP	BP
	RET
←DoubleUMul	ENDP

PUBLIC	←IPIO
PUBLIC	←ITimer
PUBLIC	←DoubleUMul

C←CODE ENDS
	END