home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_04 / 1n04083a < prev    next >
Text File  |  1990-07-25  |  3KB  |  149 lines

  1. DEFINT A-Z
  2. REM The TYPE -- END TYPE in Basic is the similar
  3. REM as a structure in C.
  4.  
  5. TYPE RegType
  6.      ax    AS INTEGER
  7.      bx    AS INTEGER
  8.      cx    AS INTEGER
  9.      dx    AS INTEGER
  10.      bp    AS INTEGER
  11.      si    AS INTEGER
  12.      di    AS INTEGER
  13.      flags AS INTEGER
  14. END TYPE
  15.  
  16. REM The DECLARE SUB Interrupt below is required because
  17. REM it is an external call to the Basic Library.
  18. REM In C or Assembly it would be defined as EXTERN
  19. REM In QuickBasic or Professional Basic the DECLARE
  20. REM is the same as ProtoTyping in C.
  21.  
  22. DECLARE SUB Interrupt (intnum AS INTEGER, inreg AS RegType, outreg AS RegType)
  23. DECLARE SUB PrintScreen ()
  24. DECLARE FUNCTION CheckPrinter% ()
  25. CONST False = 0, True = NOT False
  26. REM clear the screen
  27. CLS
  28. REM call to function to ok printer
  29. ok = CheckPrinter
  30. IF NOT ok THEN
  31.     PRINT "Printer Error. Screen Print not attempted."
  32. ELSEIF ok THEN
  33.     REM put something on the screen for test.
  34.     FOR i = 1 TO 5
  35.         PRINT "Lucy"    'My dog's name.
  36.     NEXT
  37.     CALL PrintScreen
  38.     REM check for error on Screen Print
  39.     REM set to low memory
  40.     DEF SEG = 0
  41.     REM peek byte @ 0050:0000
  42.     REM error codes
  43.     REM 0 = ok
  44.     REM 1 = Printing in Progress
  45.     REM 255 = Error on previous Screen Dump
  46.     status = PEEK(&H500)
  47.     REM restore segment
  48.     DEF SEG
  49.     SELECT CASE status
  50.         CASE 0, 1
  51.             PRINT "Screen Print Successful."
  52.         CASE 255
  53.             PRINT "Error occured. Screen Not Printed"
  54.     END SELECT
  55. END IF
  56. END
  57.  
  58. '
  59. '
  60. '
  61. FUNCTION CheckPrinter
  62.     DIM inregs AS RegType, outregs AS RegType
  63.     REM use Bios Interrupt 17h , Service 2
  64.     REM on entry ah = 2
  65.     REM          dx = Printer
  66.     REM Printer Number  0 = lpt1, 1 = lpt2, etc.
  67.     REM to set ah to 2
  68.     inregs.ax = &H200
  69.     REM using lpt1 which is 0
  70.     inregs.dx = &H0
  71.     REM set interrupt to 17h
  72.     interruptnum = &H17
  73.     CALL Interrupt(interruptnum, inregs, outregs)
  74.     REM split ax..  HiByte  LoByte
  75.     REM only HiByte is needed
  76.     IF outregs.ax < 0 THEN
  77.         Result& = outregs.ax + 65536
  78.     ELSE
  79.         Result& = outregs.ax
  80.     END IF
  81.     HiByte = Result& \ 256
  82.     REM LoByte = Result& AND &HFF
  83.     REM bit mask
  84.     REM 76543210
  85.     REM 1           Printer Not Busy
  86.     REM 0           Printer Busy
  87.     REM  1          Printer Acknowledgement
  88.     REM   1         Out Of Paper
  89.     REM    1        Printer Selected
  90.     REM     1       I/O error
  91.     REM      ??     Not Used
  92.     REM        1    Time-Out
  93.     IF (HiByte AND 128) = 128 THEN
  94.         REM  "Not busy"
  95.         CheckPrinter = True
  96.     ELSE
  97.         REM  "Busy"
  98.         CheckPrinter = False
  99.         EXIT FUNCTION
  100.     END IF
  101.     REM bit checking for other printer conditions
  102.     IF (HiByte AND 64) = 64 THEN
  103.         REM  "Acknowledge"
  104.     ELSE
  105.         REM  "No acknowledge"
  106.     END IF
  107.     IF (HiByte AND 32) = 32 THEN
  108.         REM  "Out of paper"
  109.         CheckPrinter = False
  110.         EXIT FUNCTION
  111.     ELSE
  112.         REM  "Not out of paper"
  113.     END IF
  114.     IF (HiByte AND 16) = 16 THEN
  115.         REM  "Selected"
  116.     ELSE
  117.         REM  "Not selected"
  118.         CheckPrinter = False
  119.         EXIT FUNCTION
  120.     END IF
  121.     IF (HiByte AND 8) = 8 THEN
  122.         REM  "I/O error"
  123.         CheckPrinter = False
  124.         EXIT FUNCTION
  125.     ELSE
  126.         REM  "No I/O error"
  127.     END IF
  128.     IF (HiByte AND 1) = 1 THEN
  129.         REM  "Time out"
  130.         CheckPrinter = False
  131.         EXIT FUNCTION
  132.     ELSE
  133.         REM  "No time out"
  134.     END IF
  135. END FUNCTION
  136.  
  137. '
  138. '
  139. '
  140. SUB PrintScreen
  141.     DIM inregs AS RegType, outregs AS RegType
  142.     REM use Bios Interrupt 5
  143.     REM Registers on entry not significant
  144.     REM Registers on return are unchanged
  145.     interruptnum = &H5
  146.     CALL Interrupt(interruptnum, inregs, outregs)
  147. END SUB
  148.  
  149.