Printing randomly takes a few minutes

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Ivan
Posts: 127
Joined: Tue 07 May 2019, 16:47

Printing randomly takes a few minutes

Post by Ivan »

I'm currently writing a program to calculate which amount of fabric is needed.

Right now I'm writing the printing routine and it does what I want. But ones in a while I'll have to wait a minute or more before the print start.

The program had delivered the print job to print spooler and and does not hang.

But i'm thinking i'm not using printer related commands correctly.

Anyone who can advise me to optimize the way print commands are used?

Code: Select all

      rem Sample code from fabric.bbc
      rem Print rectangles and text using sys
      rem Canon MF8200C Series UFRII LT
      rem Formatting because of dyslextic issues

      mode 22

      Titel$         = "Projekt: Upside-down"
      Titel_xp%      = 10
      Titel_yp%      = 10

      Total_members% = 10
      Member%        =  1
      Total_objects% = 10
      scale%         =  2
      Object%        =  1

      dim Item_{(Total_objects%, Total_members%) Name$, Xpos%, Ypos%, Length%, Height%}

      restore (info)
      repeat
        read Item_{(Object%, Member%)}.Name$
        read Item_{(Object%, Member%)}.Xpos%
        read Item_{(Object%, Member%)}.Ypos%
        read Item_{(Object%, Member%)}.Length%
        read Item_{(Object%, Member%)}.Height%
        Member% += 1
      until Member% > Total_members%

      rem name, xpos, ypos, lenght, height
      (info)
      data "Sheet a",    0,    0,  200, 300
      data "Sheet b",  666,  300,  300, 800
      data "Sheet c", 1444,  200,  200, 300
      data "Sheet d", 1800,  500,  400, 800
      data "Sheet e", 2145,  100,  800, 300
      data "Sheet f",    0,  700,  500, 800
      data "Sheet g", 1000, 1200,  100, 300
      data "Sheet h", 2300, 1100,  600, 800
      data "Sheet i",  100, 1700,  800, 300
      data "Sheet j", 1200, 2000, 1600, 100

      proc_landscape

      Left_margin%   = @vdu%!232
      Bottom_margin% = @vdu%!244
      Right_margin%  = @vdu%!236
      Top_margin%    = @vdu%!240

      *OUTPUT 15
      *PRINTERFONT Courier New,8
      *MARGINS
      vdu 2,32


      rem rectangel coordinate corners:
      rem x1%,y2%        x2%,y2%
      rem
      rem x1%,y1%        x2%,y1%

      for Member% = 1 to Total_members%
  
        x1% = Left_margin%                 + Item_{(Object%, Member%)}.Xpos%   * scale%
        y1% = Bottom_margin% - Top_margin% - Item_{(Object%, Member%)}.Ypos%   * scale%
        x2% = x1%                          + Item_{(Object%, Member%)}.Length% * scale%
        y2% = y1%                          - Item_{(Object%, Member%)}.Height% * scale%
  
        Label$ = Item_{(Object%, Member%)}.Name$
  
        sys "MoveToEx", @prthdc%, x1%, y1%, 0
        sys "TextOut",  @prthdc%, x1%, y1%, Label$, len(Label$)
        sys "LineTo",   @prthdc%, x1%, y2%
        sys "LineTo",   @prthdc%, x2%, y2%
        sys "LineTo",   @prthdc%, x2%, y1%
        sys "LineTo",   @prthdc%, x1%, y1%
  
      next

      sys "TextOut",  @prthdc%, Titel_xp%, Titel_yp%, Titel$, len(Titel$)

      *OUTPUT 0
      vdu 3, 12

      quit


      rem from manual
      def proc_landscape

      local psd%, dm%
      dim psd% local 83
      !psd% = 84
      psd%!16 = 1024
      sys "PageSetupDlg", psd%
      sys "GlobalLock", psd%!8 to dm%
      dm%!40 = 1
      dm%?44 = 2
      sys "ResetDC", @prthdc%, dm%
      sys "GlobalUnlock", psd%!8
      sys "GlobalFree", psd%!8
      sys "GlobalFree", psd%!12
      *MARGINS 10,10,10,10

      endproc
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.
Ivan
Posts: 127
Joined: Tue 07 May 2019, 16:47

Re: Printing randomly takes a few minutes

Post by Ivan »

The program had delivered the print job to print spooler and and does not hang.
Thats not exactly correct: It takes a long time to deliver to the print spooler when the probelm occurs. :)
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.
RichardRussell

Re: Printing randomly takes a few minutes

Post by RichardRussell »

Ivan wrote: Thu 22 Oct 2020, 13:36 Anyone who can advise me to optimize the way print commands are used?
On a quick scan of your program I don't see you sending a Form Feed ('end of page') anywhere. If you don't explicitly indicate that the page is complete it will only be printed after a timeout:

Code: Select all

      VDU 2,1,12,3 : REM End-of-page
Ivan
Posts: 127
Joined: Tue 07 May 2019, 16:47

Re: Printing randomly takes a few minutes

Post by Ivan »

I thought this line did a form feed:

Code: Select all

 vdu 3, 12
but your advice works immediately three times in a row:

Code: Select all

      VDU 2,1,12,3 : REM End-of-page
Thanks.
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.
Soruk
Posts: 23
Joined: Mon 30 Jul 2018, 20:24

Re: Printing randomly takes a few minutes

Post by Soruk »

Ivan wrote: Thu 22 Oct 2020, 17:35 I thought this line did a form feed:

Code: Select all

 vdu 3, 12
Unless I am mistaken, at least on the BBC/Arc, VDU3 disables printer output so all that will do is clear the screen.

Richard's code does: 2 - enable printer, 1 - send next code to printer only, 12 - Form Feed, 3 - disable printer (opposite of VDU2).
Ivan
Posts: 127
Joined: Tue 07 May 2019, 16:47

Re: Printing randomly takes a few minutes

Post by Ivan »

I don't think you are mistaken and thank for clearing that.

Of cource I'll have to send a form feed before I disable the printer.

I must admit after reading through the printer related stuff in the manual I don't have a clear vision or logic to program the printer.
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.