; SENDLPT
;
; Program for Proteus
;
; (C) 2003-2004 Simone Zanella Productions
;
; Send a file to parallel port (direct write, does not use Windows drivers).
#!proteus -z
!include "win32.prt"
!include "console.prt"
; Default parameters: LPT1
LptPort = "LPT1"
H2 = FOPEN(ARGV(5), 1)
IF EQ(H2, -1)
IF GE(ARGC, 5)
CONSOLELN "File " ARGV(5) " NOT found."
FI
CONSOLELN ""
CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " filename [/Pport]"
CONSOLELN ""
CONSOLELN "Purpose: send specified file to the requested parallel port."
CONSOLELN ""
CONSOLELN "Default: LPT1"
CONSOLELN ""
CONSOLELN "/Pport port = 1, 2, 3, .."
CONSOLELN ""
ABORT 0
FI
FOR X = 6 TO ARGC
SetParameters(ARGV(X))
NEXT
CheckParameters()
H = W32CREATEFILE(LptPort, W32_GENERIC_WRITE, 0, \
W32_OPEN_EXISTING, 0)
IF EQ(H, -1)
CONSOLELN "Could not open " LptPort "."
ABORT 2
FI
DISPSET(DISP_BLINK, DISP_BLINK_OFF)
DISPSET(DISP_FOREG, YELLOW)
DISPSET(DISP_BACKG, BLUE)
DISPSET(DISP_UNSFG, YELLOW)
DISPSET(DISP_SELBG, GREEN)
DISPSET(DISP_JUST, DISP_JUST_NONE)
DISPSET(DISP_JLEN, 0)
DISPSET(DISP_SHADOW, DISP_SHADOW_RIGHT)
DISPSET(DISP_SOUND, 0)
DISPSET(DISP_JLEN, 17)
DISPCLS()
DISPWRITE(1, 1, "Parallel port: " LptPort)
DISPWRITE(1, 2, "Sending: " ARGV(5))
Total = FSIZE(H2)
Prev = -1
Prev = ProgressBar(0, Total, 5, 1, Prev, 50, 3)
WHILE NOT(FEOF(H2))
N = FSEEK(H2, 0, 1)
L = FREAD(H2, 1024)
IF EQ(W32WRITEFILE(H, L), -1)
DISPWRITE(1, 8, "Error sending file.")
W32CLOSEHANDLE(H)
FCLOSE(H2)
ABORT 0
FI
Prev = ProgressBar(N, Total, 5, 1, Prev, 50, 3)
LOOP
Prev = ProgressBar(Total, Total, 5, 1, Prev, 50, 3)
W32CLOSEHANDLE(H)
FCLOSE(H2)
DISPWRITE(1, 8, "Done.")
ABORT 0
FUNCTION ProgressBar(value, total, starty, startx, prev, len, altezza)
; Write a progress bar
IF EQ(prev, -1)
FOR y1 = starty TO DEC(ADD(starty, altezza))
FOR x = startx TO DEC(ADD(startx, len))
DISPWRITE(x, y1, CHR(0xB0))
NEXT
NEXT
x = startx
ELSE
x = prev
FI
end = ADD(startx, IIF(total, FDIV(MUL(len, value), total), len))
FOR y1 = starty TO DEC(ADD(starty, altezza))
FOR x1 = x TO DEC(end)
DISPWRITE(x1, y1, CHR(0xDB))
NEXT
NEXT
RETURN end
FUNCTION CheckParameters()
; Check parameters
RETURN
FUNCTION SetParameters(s)
; Set port parameters
s = RESTFROM(s, 2)
SWITCH LEFT(s, 1) STRIEQ
ON "P"
; Select port
IF OR(LT(RESTFROM(s, 2), 1), GT(RESTFROM(s, 2), 20))
CONSOLELN "Wrong port: /" s
ABORT 1
FI
_LptPort = "LPT" RESTFROM(s, 2)
OTHER
CONSOLELN "Unknown parameter: /" s
ABORT 1
OFF
RETURN