;
; AlertHelp V0.55  Thursday, 23-Sep-1993
;
; (c) 1993 by Jan Hagqvist
;

;
; V0.05  Monday,   28-Jun-1993
; V0.35  Tuesday,  29-Jun-1993
; V0.40  Saturday, 03-Jul-1993		Now includes task name & address
; V0.45  Sunday,   19-Sep-1993		Guru, Reboot, Suspend / Thank you!
; V0.50  Monday,   20-Sep-1993		Some more specifics
; V0.55  Thursday, 20-Sep-1993		The rest of the specifics from exec/alerts.i
;


  XREF _LVOOldOpenLibrary
  XREF _LVOCloseLibrary
  XREF _LVOEasyRequestArgs
  XREF _LVOSetFunction
  XREF _LVOWait
  XREF _LVOFindTask
  XREF _LVOSignal
  XREF _LVOAllocSignal
  XREF _LVOFreeSignal
  XREF _LVOSetTaskPri
  XREF _LVOColdReboot


  SECTION 1,CODE


InstallAlertHelp
  move.l  4,a6
  lea     IntuitionName,a1
  jsr     _LVOOldOpenLibrary(a6)
  move.l  d0,IntuitionBase
  tst.l   d0
  beq     RemoveAlertHelp

  lea     TaskName,a1
  jsr     _LVOFindTask(a6)
  move.l  d0,a5
  tst.l   d0
  bne.s   TaskFound

  sub.l   a1,a1
  jsr     _LVOFindTask(a6)
  move.l  d0,a5
  move.l  #TaskName,10(a5)

  move.l  a5,a1
  move.b  #-5,d0
  jsr     _LVOSetTaskPri(a6)

  move.l  #AlertHelp,d0
  move.l  a6,a1
  move.w  #-$6c,a0
  jsr     _LVOSetFunction(a6)
  move.l  d0,OldAlert

  move.l  #-1,d0
  jsr     _LVOAllocSignal(a6)
  move.l  d0,88(a5)

DummyLoop
  jsr     _LVOWait(a6)

  move.l  OldAlert(pc),d0
  move.l  a6,a1
  move.w  #-$6c,a0
  jsr     _LVOSetFunction(a6)

  move.l  88(a5),d0
  jsr     _LVOFreeSignal(a6)

RemoveAlertHelp
  move.l  4,a6
  tst.l   IntuitionBase
  beq.s   RemoveAlertHelp2
  move.l  IntuitionBase,a1
  jsr     _LVOCloseLibrary(a6)
RemoveAlertHelp2
  moveq.l #0,d0
  rts

TaskFound
  move.l  IntuitionBase,a6
  sub.l   a0,a0
  lea     EasyStruct2,a1
  move.l  a0,a2
  lea     ArgList2,a3
  jsr     _LVOEasyRequestArgs(a6)
  cmp.b   #1,d0
  beq.s   TaskFound2

  move.l  4,a6
  move.l  88(a5),d0
  move.l  a5,a1
  jsr     _LVOSignal(a6)
TaskFound2
  bra.s   RemoveAlertHelp

AlertHelp
  move.l  d7,AlertNum
  movem.l d0-d7/a0-a6,-(sp)

  move.l  4,a6
  move.l  $114(a6),a0
  move.l  a0,AlertTask
  move.l  10(a0),AlertTaskName

  move.l  #GadgetFormat1,EasyStruct1Gadget
  move.l  #Recovery,AlertType
  cmp.l   #$80000000,d7
  bmi.s   ParseAlert
  sub.l   #$80000000,d7
  move.l  #DeadEnd,AlertType
  move.l  #GadgetFormat0,EasyStruct1Gadget
ParseAlert
  lea     SpecificAlerts,a0
ParseAlert2
  cmp.l   #0,(a0)
  beq.s   ParseAlert3
  cmp.l   (a0)+,d7
  beq.s   Specific
  addq.l  #4,a0
  bra.s   ParseAlert2
ParseAlert3
  lea     GeneralAlerts,a0
  move.l  d7,d6
  and.l   #$00ff0000,d6
ParseAlert4
  cmp.l   #0,(a0)
  beq.s   Unknown
  cmp.l   (a0)+,d6
  beq.s   Specific
  addq.l  #4,a0
  bra.s   ParseAlert4
Unknown
  move.l  #UnknownAlert,AlertText
  bra.s   ParseSource
Specific
  move.l  (a0),AlertText
ParseSource
  move.l  #UnknownSource,AlertSource
  move.l  d7,d6
  and.l   #$ff000000,d6
  swap    d6
  asr.l   #8,d6
  lea     Sources,a0
ParseSource2
  cmp.l   #$ffffffff,(a0)
  beq.s   ParseSource4
  cmp.l   (a0)+,d6
  beq.s   ParseSource3
  addq.l  #4,a0
  bra.s   ParseSource2
ParseSource3
  move.l  (a0),AlertSource
ParseSource4

Inform
  move.l  IntuitionBase,a6
  sub.l   a0,a0
  lea     EasyStruct,a1
  move.l  a0,a2
  lea     ArgList,a3
  jsr     _LVOEasyRequestArgs(a6)
  tst.b   d0				; Suspend (Thank you!)?
  beq.s   Quit2				; Yep
  cmp.b   #2,d0				; Reboot?
  beq.s   Quit3				; Yep

Quit
  movem.l (sp)+,d0-d7/a0-a6
  dc.w    $4EF9			; jmp
OldAlert
  dc.l    0
Quit2
  movem.l (sp)+,d0-d7/a0-a6
  rts
Quit3
  move.l  4,a6
  jsr     _LVOColdReboot(a6)		; Never returns!


  SECTION 2,DATA


IntuitionBase		dc.l 0
EasyStruct		dc.l 20,0,AlertTitle,TextFormat
EasyStruct1Gadget	dc.l GadgetFormat1
EasyStruct2		dc.l 20,0,AlertTitle,TextFormat2,GadgetFormat2

ArgList
AlertTaskName		dc.l 0
AlertNum		dc.l 0
AlertTask		dc.l 0
AlertSource		dc.l 0
AlertText		dc.l 0
AlertType		dc.l 0
			dc.l 0

ArgList2		dc.l 0


Sources
	dc.l $0,Processor,$1,Exec,$2,Graphics,$3,Layers,$4,Intuition,$5,Math
	dc.l $7,Dos,$8,Ram,$9,Icon,$A,Expansion,$B,DiskFont,$C,Utility
	dc.l $10,Audio,$11,Console,$12,GamePort,$13,Keyboard,$14,TrackDisk
	dc.l $15,Timer,$20,Cia,$21,Disk,$22,Misc,$30,BootStrap,$31,Workbench
	dc.l $32,DiskCopy,$33,GadTools
	dc.l $ffffffff

GeneralAlerts
	dc.l $00010000,NoMemory,$00020000,MakeLib,$00030000,OpenLib
	dc.l $00040000,OpenDev,$00050000,OpenRes,$00060000,IOError
	dc.l $00070000,NoSignal,$00080000,BadParm,$00090000,CloseLib
	dc.l $000A0000,CloseDev,$000B0000,ProcCreate
	dc.l 0

SpecificAlerts
	; Processor
	dc.l $00000002,BusError,$00000003,AddrError,$00000004,IllegalInst
	dc.l $00000005,DivZero,$00000006,ChkError,$00000007,TrapError
	dc.l $00000008,Supervisor,$00000009,Trace
	; Exec
	dc.l $01000001,ExcptVect,$01000002,BaseChkSum,$01000003,LibChkSum
	dc.l $01000005,MemCorrupt,$01000006,IntrMem,$01000007,InitAPtr
	dc.l $01000008,SemCorrupt,$01000009,FreeTwice,$0100000A,BogusExcpt
	dc.l $0100000B,IOUsedTwice,$0100000C,MemoryInsane,$0100000D,IOAfterClose
	dc.l $0100000E,StackProbe,$0100000F,BadFreeAddr
	; Graphics
	dc.l $02010000,GfxNoMem,$02010001,GfxNoMemMspc,$02010006,LongFrame
	dc.l $02010007,ShortFrame,$02010009,TextTmpRas,$0201000A,BltBitMap
	dc.l $0201000B,RegionMemory,$02010030,MakeVPort,$0200000C,GfxNewError
	dc.l $0200000D,GfxFreeError,$02011234,GfxNoLCM,$02000401,ObsoleteFont
	; Layers
	dc.l $03010000,LayersNoMem
	; Intuition
	dc.l $04000001,GadgetType,$04010002,CreatePort,$04010003,ItemAlloc
	dc.l $04010004,SubAlloc,$04010005,PlaneAlloc,$04010006,ItemBoxTop
	dc.l $04010007,OpenScreen,$04010008,OpenScrnRast,$04010009,SysScrnType
	dc.l $0401000A,AddSWGadget,$0401000B,OpenWindow,$0400000C,BadState
	dc.l $0400000D,BadMessage,$0400000E,WeirdEcho,$0400000F,NoConsole
	; Dos
	dc.l $07010001,StartMem,$07000002,EndTask,$07000003,QPktFail
	dc.l $07000004,AsyncPkt,$07000005,FreeVec,$07000006,DiskBlkSeq
	dc.l $07000007,BitMap,$07000008,KeyFree,$07000009,BadChkSum
	dc.l $0700000A,DiskError,$0700000B,KeyRange,$0700000C,BadOverlay
	dc.l $0700000D,BadInitFunc,$0700000E,FileReclosed
	; RamLib
	dc.l $08000001,BadSegList
	; Expansion
	dc.l $0A000001,BadExpansionFree
	; Console
	dc.l $11000001,NoWindow
	; Trackdisk
	dc.l $14000001,TDCalibSeek,$14000002,TDDelay
	; Timer
	dc.l $15000001,TMBadReq,$15000002,TMBadSupply
	; Disk
	dc.l $21000001,DRHasDisk,$21000002,DRIntNoAct
	; BootStrap
	dc.l $30000001,BootError
	; Workbench
	dc.l $31000001,WBBadStartupMsg1,$31000002,WBBadStartupMsg2,$31000003,WBBadIOMsg
	dc.l $31010004,WBInitPotionAllocDrawer,$31010005,WBCreateWBMenusCreateMenus1,$31010006,WBCreateWBMenusCreateMenus2
	dc.l $31010007,WBLayoutWBMenusLayoutMenus,$31010008,WBAddToolMenuItem,$31010009,WBReLayoutToolMenu
	dc.l $3101000A,WBinitTimer,$3101000B,WBInitLayerDemon,$3101000C,WBinitWbGels
	dc.l $3101000D,WBInitScreenAndWindows1,$3101000E,WBInitScreenAndWindows2,$3101000F,WBInitScreenAndWindows3
	dc.l $31010010,WBMAlloc


TaskName		dc.b 'AlertHelpTask',0
IntuitionName		dc.b 'intuition.library',0
VersionString		dc.b '$VER: AlertHelp V0.55 (23.09.93/13:33:00/055) ©1993 by Jan Hagqvist',0
AlertTitle		dc.b 'AlertHelp V0.55  23-Sep-1993',0
Recovery		dc.b 'RECOVERY',0
DeadEnd			dc.b 'DEADEND',0
Processor		dc.b 'The Processor',0
Exec			dc.b 'Exec',0
Graphics		dc.b 'Graphics',0
Layers			dc.b 'Layers',0
Intuition		dc.b 'Intuition',0
Math			dc.b 'Math',0
Dos			dc.b 'Dos',0
Ram			dc.b 'Ram',0
Icon			dc.b 'Icon',0
Expansion		dc.b 'Expansion',0
DiskFont		dc.b 'Diskfont',0
Utility			dc.b 'Utility',0
Audio			dc.b 'Audio',0
Console			dc.b 'Console',0
GamePort		dc.b 'Gameport',0
Keyboard		dc.b 'Keyboard',0
TrackDisk		dc.b 'Trackdisk',0
Timer			dc.b 'Timer',0
Cia			dc.b 'Cia',0
Disk			dc.b 'Disk',0
Misc			dc.b 'Misc',0
BootStrap		dc.b 'Bootstrap',0
Workbench		dc.b 'Workbench',0
DiskCopy		dc.b 'Diskcopy',0
GadTools		dc.b 'Gadtools',0
UnknownSource		dc.b 'an unknown source',0
UnknownAlert		dc.b 'Sorry, but I cannot help you',0
GadgetFormat0		dc.b ' Guru |Reboot|Suspend',0
GadgetFormat1		dc.b 'Thank you!',0
TextFormat		dc.b 'Notice:',10
			dc.b '-------',10,10
			dc.b 'A software failure has occurred in',10
			dc.b '%s.',10,10
			dc.b 'The alertnumber is #%08lx.',10
			dc.b 'Task address is    #%08lx.',10,10
			dc.b 'The message from %s:',10
			dc.b '%s.',10,10
			dc.b 'This is a %s alert.',0
GadgetFormat2		dc.b 'Cancel|Remove',0
TextFormat2		dc.b 'AlertHelp already installed.',10
			dc.b 'Do you want to remove it?',0
NoMemory		dc.b 'No memory',0
MakeLib			dc.b 'Unable to create library',0
OpenLib			dc.b 'Unable to open library',0
OpenDev			dc.b 'Unable to open device',0
OpenRes			dc.b 'Unable to open resource',0
IOError			dc.b 'Input/Output error',0
NoSignal		dc.b 'NoSignal',0
BadParm			dc.b 'Bad parameters',0
CloseLib		dc.b 'Unable to close library',0
CloseDev		dc.b 'Unable to close device',0
ProcCreate		dc.b 'Process creation failed',0
BusError		dc.b 'Bus error',0
AddrError		dc.b 'Address error',0
IllegalInst		dc.b 'Illegal instruction',0
DivZero			dc.b 'Division by zero',0
ChkError		dc.b 'Chk-instruction',0
TrapError		dc.b 'Trapv-instruction',0
Supervisor		dc.b 'Supervisor instruction from',10,'User state',0
Trace			dc.b 'Trace',0
ExcptVect		dc.b '68000 exception vector checksum',0
BaseChkSum		dc.b 'Execbase checksum',0
LibChkSum		dc.b 'Library checksum failure',0
MemCorrupt		dc.b 'Corrupt memory list detected in',10,'FreeMem',0
IntrMem			dc.b 'No memory for interrupt servers',0
InitAPtr		dc.b 'InitStruct() of an APTR source',0
SemCorrupt		dc.b 'A semaphore is in an illegal state',10,'at ReleaseSemaphore()',0
FreeTwice		dc.b 'Freeing memory already freed',0
BogusExcpt		dc.b 'Illegal 68xxx exception taken',0
IOUsedTwice		dc.b 'Attempt to reuse active IORequest',0
MemoryInsane		dc.b 'Sanity check on memory list failed',10,'during AvailMem(MEMF_LARGEST)',0
IOAfterClose		dc.b 'IO attempted on closed IORequest',0
StackProbe		dc.b 'Stack appears to extend out of range',0
BadFreeAddr		dc.b 'Memory header not located. [Usually',10,'an invalid address passed to FreeMem()]',0
GfxNoMem		dc.b 'Graphics out of memory',0
GfxNoMemMspc		dc.b 'MonitorSpec alloc, no memory',0
LongFrame		dc.b 'Long frame, no memory',0
ShortFrame		dc.b 'Short frame, no memory',0
TextTmpRas		dc.b 'Text, no memory for TmpRas',0
BltBitMap		dc.b 'BltBitMap, no memory',0
RegionMemory		dc.b 'Regions, memory not available',0
MakeVPort		dc.b 'MakeVPort, no memory',0
GfxNewError		dc.b 'GfxNewError',0
GfxFreeError		dc.b 'GfxFreeError',0
GfxNoLCM		dc.b 'Emergency memory not available',0
ObsoleteFont		dc.b 'Unsupported font description used',0
LayersNoMem		dc.b 'Layers out of memory',0
GadgetType		dc.b 'Unknown gadget type',0
CreatePort		dc.b 'Create port, no memory',0
ItemAlloc		dc.b 'Item plane alloc, no memory',0
SubAlloc		dc.b 'Sub alloc, no memory',0
PlaneAlloc		dc.b 'Plane alloc, no memory',0
ItemBoxTop		dc.b 'Item box top < RelZero',0
OpenScreen		dc.b 'Open screen, no memory',0
OpenScrnRast		dc.b 'Open screen, raster alloc, no memory',0
SysScrnType		dc.b 'Open sys screen, unknown type',0
AddSWGadget		dc.b 'Add SW gadgets, no memory',0
OpenWindow		dc.b 'Open window, no memory',0
BadState		dc.b 'Bad State Return entering Intuition',0
BadMessage		dc.b 'Bad Message received by IDCMP',0
WeirdEcho		dc.b 'Weird echo causing incomprehension',0
NoConsole		dc.b 'Could not open the Console Device',0
StartMem		dc.b 'No memory at startup',0
EndTask			dc.b 'EndTask did not',0
QPktFail		dc.b 'Qpkt failure',0
AsyncPkt		dc.b 'Unexpected packet received',0
FreeVec			dc.b 'Freevec failed',0
DiskBlkSeq		dc.b 'Disk block sequence error',0
BitMap			dc.b 'Bitmap corrupt',0
KeyFree			dc.b 'Key already free',0
BadChkSum		dc.b 'Invalid checksum',0
DiskError		dc.b 'Disk error',0
KeyRange		dc.b 'Key out of range',0
BadOverlay		dc.b 'Bad overlay',0
BadInitFunc		dc.b 'Invalid init packet for CLI/Shell',0
FileReclosed		dc.b 'A filehandle was closed more than',10,'once',0
BadSegList		dc.b 'Overlays are illegal for library',10,'segments',0
BadExpansionFree	dc.b 'Freeed free region',0
NoWindow		dc.b 'Console cannot open initial window',0
TDCalibSeek		dc.b 'Calibrate: Seek error',0
TDDelay			dc.b 'Delay: Error on timer wait',0
TMBadReq		dc.b 'Bad request',0
TMBadSupply		dc.b 'Power supply -- no 50/60hz ticks',0
DRHasDisk		dc.b 'Get unit: Already has disk',0
DRIntNoAct		dc.b 'Interrupt: No active unit',0
BootError		dc.b 'Boot code returned an error',0
WBBadStartupMsg1	dc.b 'Bad startup message 1',0
WBBadStartupMsg2	dc.b 'Bad startup message 2',0
WBBadIOMsg		dc.b 'Bad IO message',0
WBInitPotionAllocDrawer	dc.b 'Init Potion Alloc Drawer',0
WBCreateWBMenusCreateMenus1	dc.b 'Create WBMenus 1',0
WBCreateWBMenusCreateMenus2	dc.b 'Create WBMenus 2',0
WBLayoutWBMenusLayoutMenus	dc.b 'Layout WBMenus',0
WBAddToolMenuItem	dc.b 'Add ToolMenu-Item',0
WBReLayoutToolMenu	dc.b 'ReLayout ToolMenu',0
WBinitTimer		dc.b 'Init timer',0
WBInitLayerDemon	dc.b 'Init layer demon',0
WBinitWbGels		dc.b 'Init Workbench gels',0
WBInitScreenAndWindows1	dc.b 'Init screen and windows 1',0
WBInitScreenAndWindows2	dc.b 'Init screen and windows 2',0
WBInitScreenAndWindows3	dc.b 'Init screen and windows 3',0
WBMAlloc		dc.b 'MAlloc',0

  END
