; PrintScreen V1.08
; (c) 1993 by Jan Hagqvist

; Utilizies the PrtSc-key and makes it to
; create a graphics dump to the printer

  XREF _LVOOpenLibrary
  XREF _LVOCloseLibrary
  XREF _LVOOpenDevice
  XREF _LVOCloseDevice
  XREF _LVODisplayAlert
  XREF _LVOCreateMsgPort
  XREF _LVODeleteMsgPort
  XREF _LVOCreateIORequest
  XREF _LVODeleteIORequest
  XREF _LVOSetRGB4
  XREF _LVOGetVPModeID
  XREF _LVODoIO
  XREF _LVODisplayBeep
  XREF _LVODelay


PrtSc
  move.l  4,a6
  moveq.l #0,d0
  lea     IntuitionName(pc),a1
  jsr     _LVOOpenLibrary(a6)
  move.l  d0,IntuitionBase
  cmp.l   #0,d0
  beq     Quit
  moveq.l #36,d0
  lea     GfxName(pc),a1
  jsr     _LVOOpenLibrary(a6)
  move.l  d0,GfxBase
  cmp.l   #0,d0
  beq     NoGfx36
  moveq.l #0,d0
  lea     DosName(pc),a1
  jsr     _LVOOpenLibrary(a6)
  move.l  d0,DosBase
  cmp.l   #0,d0
  beq     NoDos

  jsr     _LVOCreateMsgPort(a6)
  move.l  d0,MsgPort
  cmp.l   #0,d0
  beq     NoMsgPort
  move.l  d0,a0
  move.l  #62,d0
  jsr     _LVOCreateIORequest(a6)		; IODRPReq
  move.l  d0,Request
  cmp.l   #0,d0
  beq     NoRequest

  jsr     _LVOCreateMsgPort(a6)
  move.l  d0,MsgPort2
  cmp.l   #0,d0
  beq     NoMsgPort
  move.l  d0,a0
  move.l  #48,d0
  jsr     _LVOCreateIORequest(a6)		; IOStdReq
  move.l  d0,Request2
  cmp.l   #0,d0
  beq     NoRequest

  lea     KeyboardName(pc),a0
  move.l  Request2(pc),a1
  moveq.l #0,d0				; unit 0
  moveq.l #0,d1
  jsr     _LVOOpenDevice(a6)
  cmp.l   #0,d0
  bne     Quit

GetKey
  move.l  DosBase(pc),a6
  moveq.l #5,d1
  jsr     _LVODelay(a6)
  move.l  4,a6
  move.l  Request2(pc),a5
  lea     KeyMatrix(pc),a0
  move.l  a0,40(a5)
  move.l  #16,36(a5)
  move.w  #$a,28(a5)
  move.l  a5,a1
  jsr     _LVODoIO(a6)
  lea     KeyMatrix(pc),a0
  moveq.l #0,d0
  moveq.l #0,d1
  move.b  11(a0),d0
  move.b  12(a0),d1
  btst    #5,d0				; PrtSc?
  beq.s   GetKey4			; No, maybe Ctrl-Esc?
  btst    #0,d1				; LShift?
  bne.s   GetKey3			; Yes! LShift+PrtSc
  btst    #1,d1				; RShift?
  beq.s   GetKey4			; No, maybe Ctrl-Esc?
GetKey3
  bsr     DoTheDump			; Shift+PrtSc pressed
  bra.s   GetKey
GetKey4
  moveq.l #0,d0
  move.b  8(a0),d0
  btst    #5,d0				; Esc?
  beq.s   GetKey			; No, try again
  btst    #3,d1				; Ctrl?
  beq.s   GetKey			; No, try again

Quit					; Ctrl+Esc pressed, exit program
  move.l  4,a6
  move.l  DosBase(pc),a1
  cmp.l   #0,a1
  beq.s   Quit9
  jsr     _LVOCloseLibrary(a6)
Quit9
  move.l  Request2(pc),a1
  cmp.l   #0,a1
  beq.s   Quit8
  jsr     _LVOCloseDevice(a6)
Quit8
  move.l  Request2(pc),a0
  cmp.l   #0,a0
  beq.s   Quit7
  jsr     _LVODeleteIORequest(a6)
Quit7
  move.l  MsgPort2(pc),a0
  cmp.l   #0,a0
  beq.s   Quit6
  jsr     _LVODeleteMsgPort(a6)
Quit6
  move.l  Request(pc),a0
  cmp.l   #0,a0
  beq.s   Quit5
  jsr     _LVODeleteIORequest(a6)
Quit5
  move.l  MsgPort(pc),a0
  cmp.l   #0,a0
  beq.s   Quit4
  jsr     _LVODeleteMsgPort(a6)
Quit4
  move.l  GfxBase(pc),a1
  cmp.l   #0,a1
  beq.s   Quit3
  jsr     _LVOCloseLibrary(a6)
Quit3
  move.l  IntuitionBase(pc),a1
  cmp.l   #0,a1
  beq.s   Quit2
  jsr     _LVOCloseLibrary(a6)
Quit2
  moveq.l #0,d0
  rts

DoTheDump
  move.l  4,a6
  lea     PrinterName(pc),a0
  move.l  Request(pc),a1
  moveq.l #0,d0				; unit 0
  moveq.l #0,d1
  jsr     _LVOOpenDevice(a6)
  cmp.l   #0,d0
  bne     DoTheDump2

  move.l  IntuitionBase(pc),a5
  move.l  56(a5),a4
  move.l  a4,ActiveScreen
  add.l   #44,a4
  move.l  a4,ActiveVPort
  add.l   #40,a4
  move.l  a4,ActiveRPort
  move.l  GfxBase(pc),a6
  move.l  ActiveVPort(pc),a0
  jsr     _LVOGetVPModeID(a6)
  move.l  Request(pc),a5
  move.l  d0,40(a5)			; io_Modes
  move.l  ActiveRPort(pc),32(a5)	; io_RastPort
  move.l  ActiveScreen(pc),a4
  move.w  8(a4),44(a5)			; io_ScrX
  move.w  10(a4),46(a5)			; io_ScrY
  move.w  12(a4),48(a5)			; io_ScrWidth
  move.w  12(a4),d0
  swap    d0
  move.l  d0,52(a5)			; io_DestCols
  move.w  14(a4),50(a5)			; io_ScrHeight
  move.w  14(a4),d0
  swap    d0
  move.l  d0,56(a5)			; io_DestRows
  move.l  ActiveVPort(pc),a4
  move.l  4(a4),36(a5)			; io_ColorMap
  move.w  #$80+$800,60(a5)		; io_Special = ASPECT+NOFORMFEED
  move.w  #$b,28(a5)			; io_Command = PRD_DUMPRPORT

  move.l  4,a6
  move.l  a5,a1
  jsr     _LVODoIO(a6)

  move.l  4,a6
  move.l  Request(pc),a1
  cmp.l   #0,a1
  beq.s   DoTheDump2
  jsr     _LVOCloseDevice(a6)
DoTheDump2
  rts

NoDos
  lea     NoDosText(pc),a0
  bra.s   OpenAlert

NoRequest
  lea     NoRequestText(pc),a0
  bra.s   OpenAlert

NoMsgPort
  lea     NoMsgPortText(pc),a0
  bra.s   OpenAlert

NoGfx36
  lea     NoGfx36Text(pc),a0
  bra.s   OpenAlert
  nop

OpenAlert
  move.l  IntuitionBase(pc),a6
  moveq.l #0,d0
  moveq.l #24,d1
  jsr     _LVODisplayAlert(a6)
  bra     Quit

IntuitionBase	dc.l 0
GfxBase		dc.l 0
DosBase		dc.l 0
MsgPort		dc.l 0
Request		dc.l 0
ActiveScreen	dc.l 0
ActiveVPort	dc.l 0
ActiveRPort	dc.l 0
MsgPort2	dc.l 0
Request2	dc.l 0

IntuitionName	dc.b 'intuition.library',0
GfxName		dc.b 'graphics.library',0
DosName		dc.b 'dos.library',0
PrinterName	dc.b 'printer.device',0
KeyboardName	dc.b 'keyboard.device',0
NoGfx36Text	dc.b 0,170,14,'Can''t open graphics.library V36+',0,0
NoDosText	dc.b 0,210,14,'Can''t open dos.library',0,0
NoMsgPortText	dc.b 0,198,14,'Can''t create message port',0,0
NoRequestText	dc.b 0,210,14,'Can''t create IORequest',0,0
KeyMatrix	ds.b 16
VersionString	dc.b '$VER: PrintScreen V1.08  Wednesday 23-Jun-93 by Jan Hagqvist',10,0

  END
