;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;  SystemTypes
;  script file for MPW
;
;  This file should have any useful macros for the debugger.
;  Examples of this are structures for the register maps in 
;  the processors, the globals, and other data formats.
;
;  History
;  Creator and origin unknown
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; These MPW script lines will do most of the work of converting
;   a C Structure type to Debugger format
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;find 
;replace  -c  /([A-Za-z]+)2[ t]+([_a-zA-Z0-9[]-]+)1;/ "> 2 "1""
;find 
;replace -c  //// ""
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; REVISION HISTORY:
;	6/2/98	vmk	Added AlmGlobals and AlmGlobalsV30 aliases
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Basic Types
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
typedef DWord 	"LocalID"
typedef SWord 	"Err"
typedef SWord 	"Int"
typedef Word  	"UInt"
typedef SDWord "Long"
typedef DWord  "ULong"
typedef Byte   @"Ptr"
typedef Ptr		"VoidPtr"
typedef Byte   @"BytePtr"
typedef Ptr		@"Handle"
typedef DWord	@"DWordPtr"
typedef Word	@"WordPtr"
typedef Byte   "Boolean"


typedef struct "M68KExcTableType"
	> DWord 					"initStack"
	> DWord 					"initPC"
	> DWord 					"busErr"
	> DWord 					"addressErr"
	> DWord 					"illegalInstr"
	> DWord 					"divideByZero"
	> DWord 					"chk"
	> DWord 					"trap"
	> DWord 					"privilege"
	> DWord 					"trace"
	> DWord 					"aTrap"
	> DWord 					"fTrap"
	> DWord 					"reserved12"
	> DWord 					"coproc"
	> DWord 					"formatErr"
	> DWord 					"unitializedInt"
	> DWord 					"reserved"[8] \-
	> DWord 					"spuriousInt"
	> DWord 					"autoVec1"
	> DWord 					"autoVec2"
	> DWord 					"autoVec3"
	> DWord 					"autoVec4"
	> DWord 					"autoVec5"
	> DWord 					"autoVec6"
	> DWord 					"autoVec7"
	> DWord 					"trapN"[#16] \-
	> DWord 					"unassigned"[#16] \-
	typeend
	
	
typedef struct "SysBatteryDataType"
	> Word	"sysBattDataStructVersion"
	> Word	"sysBattMildWrngVoltage"
	> Word	"sysBattSevereWrngVoltage"
	> Word	"sysBattShutdownEnVoltage"
	> Word	"sysBattShutdownDisVoltage"
	> Word	"sysBattMinIRVoltage"
	> DWord	"sysBattMildWrngTimeout"
	> DWord	"sysBattSevereWrngTimeout"
	> Word	"sysBattStepsPerVolt"
	> SWord	"sysBattVoltageStepOffset"
	> DWord	"sysBattReserved1"
	> DWord	"sysBattReserved2"
	> Word	"sysBattVoltageCurve"[11]
	typeend
	
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Generic Serial Manager defininitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

typedef struct "SerSettingsType"
	> ULong 					"baudRate"
	> ULong 					"flags"		\%
	> Long 					"ctsTimeout"
	typeend


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 68328 Serial Manager defininitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	
typedef struct "SerGlobalsType"
	> UInt 					"openCount"
	> Int						"port"
	> SerSettingsType	 	"settings"
	> Word 					"lineErrors"
	
	> Word 					"qStart"
	> Word 					"qEnd"
	> Word 					"qSize"
	> Ptr 					"qData"
	> Ptr						"defQData"
	
	> Ptr						"wakeupHandler"
	> DWord					"wakeupRefcon"
	> Word 					"smSignalSize"
	> Long 					"smID"
	> DWord 					"lastRcvTicks"
	
	> Word					"numReceived"
	> Word					"lastErrorStatus"
	> Word					"numRcvErrors"
	typeend
typedef SerGlobalsType	@"SerGlobalsPtr"



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 68681 Serial Manager defininitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

typedef struct "M681DuartRead"
>		Byte		"mra" \%
>		Byte	"u0" \-
>		Byte		"sra" \%
>		Byte	"u2" \-
>		Byte		"doNotAccess1"	\-
>		Byte	"u4" \-
>		Byte		"rba" \%
>		Byte	"u6" \-
>		Byte		"ipcr" \%
>		Byte	"u8" \-
>		Byte		"isr" \%
>		Byte	"uA" \-
>		Byte		"cur" \%
>		Byte	"uC" \-
>		Byte		"clr" \%
>		Byte	"uE" \-
>		Byte		"mrb" \%
>		Byte	"u10" \-
>		Byte		"srb" \%
>		Byte	"u12" \-
>		Byte		"doNotAccess2"	\-
>		Byte	"u14" \-
>		Byte		"rbb" \%
>		Byte	"u16" \-
>		Byte		"ivr" \%
>		Byte	"u18" \-
>		Byte		"ipr" \%
>		Byte	"u1A" \-
>		Byte		"startCtr"
>		Byte	"u1C" \-
>		Byte		"stopCtr"
>		Byte	"u1E" \-
	typeend
		
typedef struct "M681DuartWrite"
>		Byte		"mra"
>		Byte	"u0"
>		Byte		"csra"
>		Byte	"u2"
>		Byte		"cra"
>		Byte	"u4"
>		Byte		"tba"
>		Byte	"u6"
>		Byte		"acr" 
>		Byte	"u8"
>		Byte		"imr"
>		Byte	"uA"
>		Byte		"ctur"
>		Byte	"uC"
>		Byte		"ctlr"
>		Byte	"uE"
>		Byte		"mrb"
>		Byte	"u10"
>		Byte		"csrb"
>		Byte	"u12"
>		Byte		"crb"
>		Byte	"u14"
>		Byte		"tbb"
>		Byte	"u16"
>		Byte		"ivr"
>		Byte	"u18"
>		Byte		"opcr"
>		Byte	"u1A"
>		Byte		"opSet"
>		Byte	"u1C"
>		Byte		"opReset"
>		Byte	"u1E"
	typeend


typedef struct "Ser681DebugInfoType"
	> Word "lineErrorCount"
	> Word "numReceived"
	> Word "numSent"
	> Byte "lastReceived"
	> Byte "lastErrorStatus"	\%
	> Word "hwOverrunCount"
	> Word "parityErrorCount"
	> Word "framingErrorCount"
	typeend
	
typedef Ser681DebugInfoType	@"Ser681DebugInfoPtr";



typedef struct "Ser681GlobalsType"
	> DWord "openSignature"
													
	> UInt "openCount"
	> Int "port"
	> SerSettingsType "settings"
	> Word "lineErrors"
	
	> VoidPtr "chanP"
	
	> Word "qStart"
	> Word "qEnd"
	> Word "qSize"
	> Ptr "qData"
	> Ptr "defQData"
	
	
	> Word "smSignalSize"
	> DWord "smID"

	> DWord "lastRcvTicks"

	> Byte "currentIMR"
	> Ptr "oldIRQ3P"
	
	> Ser681DebugInfoType "debugInfo"
	
	typeend
	
typedef Ser681GlobalsType	@"Ser681GlobalsPtr"

var "hwrDuartBase"		$10E00000

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Serial Link Manager defininitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

typedef struct "SlkSocketListenType"
	> Ptr						"listenerP"
	> Ptr						"headerBufferP"
	> Ptr						"bodyBufferP"
	> ULong					"bodyBufferSize"
	typeend
	
typedef SlkSocketListenType  @"SlkSocketListenPtr"


typedef struct "SlkRefInfoType"
	> Byte					"refNum"
	> SByte					"destID"
	typeend

typedef struct "SlkGlobalsType"
	> UInt		  			"openCount"
	> Byte					"socketRefNum"[5]
	> Boolean				"socketOpen"[5]
	> SlkSocketListenPtr	"socketListenP"[5]
	> Word					"socketTimeout"[5]
	
	> SlkRefInfoType		"refInfo"[5]
	
	> Byte					"transId"
	> Long					"xmitSemaphoreID"
	> Word					"numReceived"
	typeend

typedef SlkGlobalsType  @"SlkGlobalsPtr"
	
	
typedef struct "M68KRegsType"
	> DWord					"d"[8]
	> DWord					"a"[7]
	> DWord					"usp"
	> DWord					"ssp"
	> DWord					"pc"
	> Word					"sr"
	typeend
	
typedef struct "BreakpointType"
	> Ptr						"addr"
	> Boolean				"enabled"
	> Boolean				"installed"
	typeend
	
	
typedef struct "DbgGlobalsType"
	> M68KRegsType			"reg"
	> Boolean				"romBP"
	> Boolean				"stepOverBP"
	> BreakpointType		"bp"[#6]
	> Word					"bpOpcode"[#6]
	> Word					"trapBreak"[#5]
	> Word					"trapParam"[#5]
	> DWord					"oldDispatcher"
	> Boolean				"breakingOnATrap"
	> Boolean				"ignoreDbgBreaks"
	> Boolean				"commOpened"
	> Boolean				"stepSpy"
	> DWord					"ssAddr"
	> DWord					"ssValue"
	> Word					"excType"
	> Byte					"reEntered"
	> Byte					"firstEntrance"
	> Byte					"serGlobals"[#32] \-
	> DWord					"busErrStack"[2] 
	> Byte					"stack"[300] \-
	> Word					"stackEnd"
	typeend
	
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Generic defininitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

typedef struct "PointType"
	> SWord					"x"
	> SWord					"y"
	typeend
	
	
typedef struct "RectangleType"
	> PointType				"topLeft"
	> PointType				"extent"
	typeend
	
typedef struct "PenQueueType"
	> Int 					"start"
	> Int 					"end"
	> Int 					"size"
	> UInt 					"strokeCount"
	> Boolean 				"returnedPenDown"
	> PointType 			"addLast"
	> Int  					"addStrokeStart"
	> UInt  					"strokesRemoved"
	> Int  					"rmvStrokeStage"
	> PointType  			"rmvLast"
	> PointType  			"rmvStartPt"
	> Byte		 			"data"
	typeend
typedef PenQueueType 	@"PenQueuePtr"
	
typedef struct "KeyQueueType"
	> UInt					"start"
	> UInt					"end"
	> UInt					"size"
	> Byte					"data"
	typeend
typedef KeyQueueType 	@"KeyQueuePtr"
	
	
typedef struct "SysEvtMgrGlobalsType"
	> Boolean 				"sendNullEvent"
	> Boolean  				"enableGraffiti"
	> Boolean  				"enableSoftKeys"
	> Boolean  				"removeTopStroke"
	> PenQueuePtr  		"penQP"
	> UInt  					"penQStrokesRemoved"
	> KeyQueuePtr  		"keyQP"
	> RectangleType  		"writingR"
	> UInt  					"appAreaBottom"
	> UInt  					"penX"
	> UInt  					"penY"
	> Boolean  				"penDown"
	> Boolean  				"displayingBatteryAlert"
	> UInt  					"lastPenX"
	> UInt  					"lastPenY"
	> Boolean  				"lastPenDown"
	> Boolean  				"needRemoteScrUpdate"
	> Byte 					"gremlinsFlags"
	> Boolean 				"idle"
	> Boolean 				"gotUserEvent"
	typeend														
	

typedef struct "RecordEntryType" 
	> LocalID 				"localChunkID"
	> Byte 					"attributes"
	> Byte					"uniqueID"[3]			
	typeend
typedef RecordEntryType	@"RecordEntryPtr"

typedef struct "RsrcEntryType" 
	> DWord 					"type"
	> Word 					"id"
	> Word 					"size"
	> LocalID 				"localChunkID"
	typeend
typedef RsrcEntryType	@"RsrcEntryPtr"

typedef struct "RecordListType" 
	> LocalID 				"nextRecordListID"
	> Word 					"numRecords"
	> Word 					"firstEntry"
	typeend
typedef RecordListType	@"RecordListPtr"



typedef struct "DatabaseHdrType" 
	> Char					"name"[20]		\-			
	> Word 					"attributes"
	> Word					"version"

	> DWord 				"creationDate"
	> DWord 				"modificationDate"
	> DWord 				"lastBackupDate"
	> DWord 				"modificationNumber"

	> LocalID 				"appInfoID"
	> LocalID 				"sortInfoID"

	> DWord 				"type"
	> DWord 				"creator"

	> DWord					"uniqueIDSeed"

	> RecordListType 		"recordList"
	typeend

typedef DatabaseHdrType	@"DatabaseHdrPtr"
typedef DatabaseHdrPtr	@"DatabaseHdrHand"


typedef struct  "DmOpenInfoType" 
	> Ptr		 				"next"
	> UInt 					"openCount"
	> ULong					"ownerTaskID"
	> Word 					"exclusive,writeAccess,resDB"
	> LocalID 				"hdrID"
	> DatabaseHdrHand 	"hdrH"
	> DatabaseHdrPtr	 	"hdrP"
	> UInt 					"cardNo"
	> UInt 					"numRecords"
	> RecordEntryPtr 		"recordP"
	> RsrcEntryPtr 		"resourceP"
	> Ptr 					"hdrMasterP"
	> UInt 					"numHandles"
	> Ptr						@"handleTableP"				
	typeend
typedef DmOpenInfoType		@"DmOpenInfoPtr"

typedef struct "DmAccessType"
	> DmAccessType			@"next"
	> UInt					"mode"
	> DmOpenInfoPtr		"openP"
	typeend
typedef DmAccessType		@"DmAccessPtr"


var 	"penNumSamples"			#5
typedef struct "PenGlobalsType"
	> Boolean				"calibrated"
	> Boolean				"filler"
	> UInt					"xOffset"
	> UInt					"yOffset"
	> UInt					"xScale"
	> UInt					"yScale"
	> PointType				"sample"[penNumSamples]
	> UInt					"delay"
	> UInt					"maxDDZ"
	> UInt					"maxSlop"
	> UInt					"maxEndBlip"
	typeend
typedef PenGlobalsType	@"PenGlobalsPtr"


typedef struct "KeyGlobalsType"
	> ULong					"lastKeyTicks"
	> Word					"keyState"
	> Word					"keyStateMask"
	> Byte					"usedPortDBits"
	> Byte					"keyUpCount"
	> Byte					"initDelay"
	> Byte					"period"
	> DWord					"turnOnTicks"
	> ULong					"doubleTapTicks"
	> Word					"doubleTapDelay"
	> Word					"doubleTapState"
	> Boolean				"queueAhead"
	typeend
typedef KeyGlobalsType	@"KeyGlobalsPtr"


typedef struct "TimGlobalsType"
	> ULong					"rtcHours"
	> ULong					"alarmSeconds"
	> Boolean				"rtcBugWorkaround"
	> Boolean				"rtcBugAsleep"
	> ULong					"rtcBugAlarm"
	> ULong					"rtcBugSeconds"
	> ULong					"rtcBugLastSeconds"
	typeend
typedef TimGlobalsType	@"TimGlobalsPtr"


; An entry in the alarm table in PalmOS v1.0 - 3.0
typedef struct "AlmEntryTypeV30"
	>	DWord				"ref"				; alarm reference value passed by caller;

	>	ULong				"alarmSeconds"	; alarm date/time in seconds since 1/1/1904;
												; a value of 0 indicates unused entry;
		
	>	LocalID			"dbID"				; creator app database ID;

	>	Word				"flags"	\%

	;;;;;;;;;;;;;;;;;;;;;;;;;;;;; represented by "flags"
	;	Word				cardNo : 1;		; creator app card number;
	;	
	;	Word				quiet : 1;		; 1 indicates that the caller wants
	;											; to be quietly notified when the alarm
	;											; goes off without all the alarm bells
	;											; and whistles;
	;
	;	Word				triggered : 1;	; 1 indicates the alarm has been triggered;
	;											
	;	Word				notified : 1;	; 1 indicates we notified the caller that
	;											; the alarm went off;
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	typeend


; An entry in the alarm table in current PalmOS
typedef struct "AlmEntryType"
	>	DWord				"ref"				; alarm reference value passed by caller;

	>	ULong				"alarmSeconds"	; alarm date/time in seconds since 1/1/1904;
												; a value of 0 indicates unused entry;
		
	>	LocalID			"dbID"			; creator app database ID
	>	Word				"cardNo"			; creator app card number

	>	Word				"flags"	\%

	;;;;;;;;;;;;;;;;;;;;;;;;;;;;; represented by "flags"
	;	Word				quiet : 1;		; 1 indicates that the caller wants
	;											; to be quietly notified when the alarm
	;											; goes off without all the alarm bells
	;											; and whistles;
	;
	;	Word				triggered : 1;	; 1 indicates the alarm has been triggered;
	;											
	;	Word				notified : 1;	; 1 indicates we notified the caller that
	;											; the alarm went off;
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	typeend


; The alarm table
typedef struct "AlmTableType"
	> SWord				"numEntries"	; Number of entries in alarm Table;
		
												; List of alarm entries;
												; This is a variable size field which
												; ***MUST BE LAST***
	> AlmEntryType		"list"[1]	\-	; 0 or more entries
	typeend

typedef AlmTableType@		"AlmTablePtr"
typedef AlmTablePtr@			"AlmTableHandle"


; This was the AlmGlobalsType structure in PalmOS v1.0 - 3.0
typedef struct "AlmGlobalsTypeV30"
	>	AlmTableHandle	"tableH"			; alarm table handle;

	>	ULong				"lastSoundSeconds"
												; alarm seconds of the last alarm for
												; which an alarm was sounded;
	>	Word				"displaying_triggered"	\%

	;;;;;;;;;;;;;;;;;;;;; represented by flags
	;	Word				displaying : 1;; 1 indicates we're blocked waiting for
	;											; some app to finish displaying an alarm
	;											; dialog box; set and cleared by
	;											; AlmDisplayNextAlarm();
	;											
	;	Word				triggered : 1;	; 1 indicates an alarm was triggered; this
	;											; field is set by the AlmAlarmCallback() and
	;											; is checked and cleared by AlmDisplayAlarm();
	;;;;;;;;;;;;;;;;;;;;;

	>	Byte				"disableCount"	; if this value is greater than zero, Alarm
												; notifications are disabled (see AlmEnableNotification);
	typeend

; This is the current AlmGlobalsType
typedef struct "AlmGlobalsType"
	> Handle					"tableH"
	> ULong					"lastSoundSeconds"
	> Word					"displaying_triggered"	\%
	> Byte					"disableCount"
	> Byte					"filler"
	> DWord					"resSemID"
	typeend
typedef AlmGlobalsType	@"AlmGlobalsPtr"


typedef struct "HwrBatGlobalsType"
	> Word					"charging_loaded_dbg1_dbg2"
	> DWord					"actTime"
	> DWord					"nextAlarmTime"
	> DWord					"turnOnTime"
	> Word					"lastBatLevel"
	> DWord					"lastChargeStart"
	> DWord					"lastChargeFinish"
	> Word					"lastChargePeak"
	> Word					"lastChargeFinal"
	> Word					"minLevel"
	> Word					"maxLevel"
	> Word					"nearPeakLevel"
	> Word					"minPeakDip"
	> Word					"minAlkLevel"
	typeend
typedef HwrBatGlobalsType	@"HwrBatGlobalsPtr"


typedef struct "SysAppInfoType"
	> Int						"cmd"
	> Ptr						"cmdPBP"
	> UInt					"launchFlags"
	
	> Long					"taskID"
	> Handle					"codeH"
	> Ptr						"dbP"
	> Ptr						"stackP"
	> Ptr						"globalsChunkP"

	> UInt					"memOwnerID"
	> Ptr						"dmAccessP"
	> SWord					"dmLastErr"
	> Ptr						"errExceptionP"

	> Ptr						"a5Ptr"
	> Ptr						"stackEndP"
	> Ptr						"globalEndP"
	> Ptr						"rootP"
	> Ptr						"extraP"
	typeend
typedef SysAppInfoType  @"SysAppInfoPtr"


typedef struct "SysNVParamsType"
	> DWord					"rtcHours"
	> DWord					"rtcHourMinSecCopy"
	> Byte					"hwrLCDContrastValue"
	typeend
	
	
typedef struct "StorageHeaderType"
	> DWord 					"signature"
	> Word 					"version"
	> Word 					"flags"
	> Char 					"name"[#32] 
	> DWord 					"creationDate"
	> DWord 					"backupDate"
	> DWord 					"heapListOffset"
	> DWord 					"initCodeOffset0"
	> DWord 					"initCodeOffset1"
	> LocalID 				"databaseDirID"
	> DWord	 				"rsvSpace"
	> DWord	 				"dynHeapSpace"
	> DWord	 				"firstRAMBlockSize"
	> SysNVParamsType	 	"nvParams"
	> Byte 					"reserved"[#168] \-
	typeend
typedef StorageHeaderType @"StorageHeaderPtr"
	

typedef struct "CardInfoType"
	> BytePtr				"baseP"
	> DWord					"size"
	> DWord					"firstRAMBlockSize"
	> DWord					"targetROMShift"
	> DWord					"cardHeaderOffset"
	> DWord					"rsvSpace"
	> DWord					"dynHeapSpace"
	> StorageHeaderPtr	"ramStoreP"
	> Word					"numRAMHeaps"
	> DWordPtr				"ramHeapOffsetsP"
	> Word					"numROMHeaps"
	> DWordPtr				"romHeapOffsetsP"
	typeend
typedef CardInfoType		@"CardInfoPtr"

typedef struct "CardHeaderType"
	> DWord					"initStack"
	> DWord					"resetVector"
	> DWord					"signature"
	> Word					"hdrVersion"
	> Word					"flags"
	> Byte					"name"[#32]
	> Byte					"manuf"[#32]
	> Word					"version"
	> DWord					"creationDate"
	> Word					"numRAMBlocks"
	> DWord					"blockListOffset"
	
	> DWord					"readWriteParmsOffset"
	> DWord					"readWriteParmsSize"
	> DWord					"readOnlyParmsOffset"
	> DWord					"bigROMOffset"
	> DWord					"checksumBytes"
	> Word					"checksumValue"

	> Byte					"reserved"[#142] \-
	typeend
typedef CardHeaderType 	@"CardHeaderPtr"

typedef struct "SysLibTblEntryType"
	> Ptr						@"dispatchTblP"
	> Ptr						"globalsP"
	> LocalID				"dbID"
	> Ptr						"codeRscH"
	typeend
typedef SysLibTblEntryType @"SysLibTblEntryPtr"

typedef struct "GraphicStateTypeV20"
	> Byte					"grafMode"
	> Boolean				"patternMode"
	> Boolean				"pattern"
	> Word					"customPtn"[4]
	> Byte					"fontId"
	> Ptr						"font"
	> Byte					"underlineMode"
	typeend
	
typedef struct "RGBColorType"
	> Byte					"unused" \-
	> Byte					"r"
	> Byte					"g"
	> Byte					"b"
	typeend

typedef struct "ColorTableType"
	> Word					"numEntries"
	> RGBColorType			"entry"[1]
	typeend
typedef ColorTableType @"ColorTablePtr"

typedef struct "GraphicStateType"
	> Byte					"grafMode"
	> Boolean				"patternMode"
	> Boolean				"pattern"
	> Word					"customPtn"[4]
	> Byte					"fontId"
	> Ptr						"font"
	> Byte					"underlineMode"
	> RGBColorType			"foreColor"
	> RGBColorType			"backColor"
	typeend
typedef GraphicStateType @"GraphicStatePtr"
	

typedef struct "AbsRectType"
	> SWord					"left"
	> SWord					"top"
	> SWord					"right"
	> SWord					"bottom"
	typeend
	
typedef Word "CustomPatternType"[4]


typedef struct "ScrGlobalsTypeV20"
	> UInt 					"width"
	> UInt 					"height"
	> UInt 					"rowBytes"
	> Ptr 					"baseAddr"
	> CustomPatternType	"grayPat"
	> Boolean 				"doDrawNotify"
	> AbsRectType 			"updateR"
	> Long 					"lastUpdate"
	typeend
typedef ScrGlobalsTypeV20	@"ScrGlobalsPtrV20"


typedef struct "GDeviceType"
	> VoidPtr				"baseAddr"
	> Word					"width"
	> Word					"height"
	> Word					"rowBytes"
	> Byte					"pixelSize"
	> Byte					"version"
	> Word					"flags"
	> ColorTablePtr		"cTableP"
	typeend
typedef GDeviceType @"GDevicePtr"

typedef struct "ScrGlobalsType"
	> GDeviceType			"gDevice"
	> CustomPatternType	"grayPat"
	> Boolean 				"doDrawNotify"
	> AbsRectType 			"updateR"
	> SDWord					"lastUpdate"
	> Word 					"expSrcSize"
	> BytePtr 				"expSrcP"
	typeend
typedef ScrGlobalsType	@"ScrGlobalsPtr"


typedef struct "ClipboardItem"
	> Ptr						"item"
	> Word					"length"
	typeend
	
typedef struct "FieldUndoType"
	> Byte					"mode"
	> Word					"start"
	> Word					"end"
	> Word					"bufferLen"
	> Ptr						"buffer"
	typeend
	
typedef struct "WindowType"
	> Word					"displayWidthV20"
	> Word					"displayHeightV20"
	> Ptr						"displayAddrV20"
	> Word					"windowFlags"
	> RectangleType		"windowBounds"
	> AbsRectType			"clipplingBounds"
	> GDevicePtr			"gDeviceP"
	> Word					"frameType"
	> GraphicStatePtr		"gstate"
	> Ptr						"nextWindow"
	typeend
typedef WindowType @"WinPtr"
typedef WindowType @"WinHandle"

typedef struct "FormType"
	> WindowType			"window"
	> Word					"formId"
	> Word					"attr"
	> WinPtr					"bitsBehindForm"
	> Ptr						"handler"
	> Word					"focus"
	> Word					"defaultButton"
	> Word					"helpRscId"
	> Word					"menuRscId"
	> Word					"numObjects"
	> Ptr						"objects"
	typeend
typedef FormType @"FormPtr"

	
typedef struct "TP3Data"
	> Ptr						"privateP"
	> Ptr						"glyphsP"
	> Ptr						"dictionaryP"
	> Ptr						"macrosP"
	typeend

typedef struct "TP3DictState"
	> Word					"lockFlags"
	> Byte					"lastGlyph"
	> Byte					"filler"
	> Word					"lastGlyphBranch"
	> Word					"top"
	> Word					"stack"[8] \-
	typeend
		
	
typedef struct "GrfGlobalsType"
	> TP3Data 				"p3Data"
	> TP3DictState 		"state"
	> Int 					"uncertain"
	> Word 					"glyphFlags"
	> Word 					"shiftState"
	
	> SWord 					"macroNameLen"
	> Byte 					"macroName"[#32] \-
	> Byte 					"lastChar"
	
	> ULong 					"globalsSize"
	> UInt					"flags"
	> Byte 					"upShiftGlyphID"
	> Handle 				"globalsH"
	> Handle					"templateH"
	> Handle 				"dictH"
	> Handle 				"macrosH"
	> DmAccessPtr 			"macrosDbP"
	typeend
	
typedef struct "FtrGlobalsType"
	> Handle					"romTableH"
	> Handle					"ramTableH"
	typeend
	

typedef struct "ScrBltInfoType"
	> Byte 					"op"
	> Int 					"height"
	> WordPtr				"dstBaseP"
	> UInt 					"dstRowBytes"
	> WordPtr 				"srcBaseP"
	> UInt 					"srcRowBytes"
	> Word 					"leftMask"
	> Word					"rightMask"
	> Int 					"midWords"
	> Int 					"dstRowDelta"
	> WordPtr 				"dstP"
	> Int 					"srcRowDelta"
	> WordPtr 				"srcP"
	> WordPtr				"patternP"
	> Word 					"solidPat"
	> Boolean 				"simple"
	> Word 					"pattern"[4]
	typeend
typedef ScrBltInfoType  @"ScrBltInfoPtr"


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Globals/UIGlobals from 2.0 devices
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

typedef struct "UIGlobalsTypeV20" 
	> Handle 				"activeWindow"
	> Handle 				"displayWindow"
	> Handle 				"drawWindow"
	> Handle 				"firstWindow"
	> Handle 				"exitWindowID"
	> Handle 				"enterWindowID"
	> Handle 				"exitedWindowID"
	> GraphicStateTypeV20 "gState"
	> Ptr						"eventQ"
	> Word 					"eventQIndex"
	> Word 					"eventQLength"
	> SWord 					"lastScreenX"
	> SWord 					"lastScreenY"
	> Boolean 				"lastPenDown"
	> Long 					"needNullTickCount"
	> Ptr	 					"uiCurrentFontPtr"
	> Ptr	 					"uiFontTable"[7]
	> Byte 					"uiCurrentFontID"
	> Ptr		 				"currentForm"
	> Boolean				"insPtIsEnabled"
	> Boolean 				"insPtOn"
	> PointType 			"insPtLoc"
	> SWord 					"insPtHeight"
	> Long					"insPtLastTick"
	> Handle		 			"insPtBitsBehind"
	> ClipboardItem 		"clipboard"[3]
	> Ptr			 			"uiCurrentMenu"
	> FieldUndoType 		"undoGlobals"
	> Byte 					"gsiState"
	> Boolean 				"gsiIsEnabled"
	> PointType 			"gsiLocation"
	typeend
typedef UIGlobalsTypeV20	@"UIGlobalsPtrV20"


typedef struct "GlobalsTypeV20" 
	> Byte					"memCardSlots"
	> Byte					"dbgWasEntered"
	> CardInfoPtr			"memCardInfoP"
	> DWord					"memSemaphoreID"
	> Word					"memDebugMode"
	
	> DmOpenInfoPtr		"dmOpenList"
	
	> Byte 					"dbgInDebugger"
	> Byte 					"dbgTracing"
	> Ptr 					"dbgGlobalsP"
	> Ptr						"dbgSerGlobalsP"
	
	> SysAppInfoPtr		"sysAppInfoP"
	> Ptr						"sysKernelDataP"
	> Ptr						"sysDispatchTableP"	
	> DWord					"sysOwnerIDsInUse"				
	> Ptr						"sysAMXAppInfoP"
	> DWord					"sysClockFreq"
	> DWordPtr				"sysHardKeyCreators"
	
	> SWord					"sysBatteryCheckTimer"
	> Byte					"sysBatteryMinThreshold"
	> Byte					"sysBatteryLevel"
	> SWord					"sysNextBatteryTimer"
	> Byte					"sysBatteryWarnThreshold"
	
	> Byte					"sysDispatchTableRev"
	> Word					"sysDispatchTableSize"
	
	> SysLibTblEntryPtr	"sysLibTableP"
	> Word					"sysLibTableEntries"
	> Ptr						"sysConsoleStackChunkP"
	> SysAppInfoPtr		"sysUIShellAppInfoP"
	
	> Long					"sysTimerID"
	> ULong					"sysAutoOffEvtTicks"
	> Word					"sysAutoOffSeconds"
	> Long					"sysRandomSeed"
	
	> Ptr						"slkGlobalsP"
	> Ptr				 		"serGlobalsP"
	> Ptr 					"scrGlobalsP"
	> Ptr 					"fplGlobalsP"
	> Ptr						"penGlobalsP"
	> Ptr 					"sysEvtMgrGlobalsP"
	> Ptr						"sndGlobalsP"
	> Ptr						"timGlobalsP"
	> Ptr						"almGlobalsP"
	> Ptr						"ftrGlobalsP"
	> Ptr						"grfGlobalsP"
	> Ptr						"keyGlobalsP"
	
	> Byte					"uiGlobals"[$B0] \-
	> Ptr 					"uiExtensionsP"
	
	> SysAppInfoPtr		"curUIAppInfoP"
	> DWord					"nextUIAppDBID"
	> Word					"nextUIAppCmd"
	> Ptr						"nextUIAppCmdPBP"
	> Byte					"nextUIAppCardNo"
	
	
	> SByte					"hwrDataWELevel"
	> Word					"hwrWakeUp"
	> Byte					"hwrCPUDutyCycle"
	> Byte					"hwrPenDown"
	> DWord					"hwrCurTicks"
	> DWord					"hwrTotalRAMSize"
	> DWord					"hwrDozeSubTicks"
	
	> DWord					"sndOffTicks"
	> Byte					"sysResetFlags"
	> Byte					"sysBatteryKind"
	
	> DWord					"memMinDynHeapFree"
	
	> Word					"sysPrefFlags"
	
	> Ptr						"sysGlobalsP"
	
	> Word					"sysMiscFlags"
	
	> Word					"sysLibNet"
	> Ptr						"netPktFreeQ"
	
	> DWord					"sysEvGroupID"

	> Ptr						"irq3GlobalsP"
	
	> DWord					"sysLastBatteryWarning"
	> DWord					"sysLowMemChecksum"
	
	> Word					"hwrHardwareRev"
	
	> Handle					"dmProtectListH"
	> Word					"hwrMiscFlags"
	
	> DWord					"sysProfilerRefcon"
	> Ptr						"sysProfilerProcP"
	
	> DWord					"flpSoftFPSCR"

	typeend


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Globals/UIGlobals from 3.0 device
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

typedef struct "UIGlobalsType" 
	> Handle 				"activeWindow"
	> Handle 				"displayWindow"
	> Handle 				"drawWindow"
	> Handle 				"firstWindow"
	> Handle 				"exitWindowID"
	> Handle 				"enterWindowID"
	> Handle 				"exitedWindowID"
	> GraphicStateType 	"gState"
	> Ptr						"eventQ"
	> Word 					"eventQIndex"
	> Word 					"eventQLength"
	> SWord 					"lastScreenX"
	> SWord 					"lastScreenY"
	> Boolean 				"lastPenDown"
	> Long 					"needNullTickCount"
	> Ptr	 					"uiCurrentFontPtr"
	> Ptr						"uiSysFontTablePtr"
	> Ptr						"uiAppFontTablePtr"
	> Word					"uiNumSysFonts"
	> Word					"uiNumAppFonts"
	> DWord					"uiReserved"[2] \-
	> Byte 					"uiCurrentFontID"
	> Ptr		 				"currentForm"
	> Boolean				"insPtIsEnabled"
	> Boolean 				"insPtOn"
	> PointType 			"insPtLoc"
	> SWord 					"insPtHeight"
	> Long					"insPtLastTick"
	> Handle		 			"insPtBitsBehind"
	> ClipboardItem 		"clipboard"[3]
	> Ptr			 			"uiCurrentMenu"
	> FieldUndoType 		"undoGlobals"
	> Byte 					"gsiState"
	> Boolean 				"gsiIsEnabled"
	> PointType 			"gsiLocation"
	typeend
typedef UIGlobalsType	@"UIGlobalsPtr"


typedef struct "GlobalsType" 
	> Byte					"memCardSlots"
	> Byte					"dbgWasEntered"
	> CardInfoPtr			"memCardInfoP"
	> DWord					"memSemaphoreID"
	> Word					"memDebugMode"
	
	> DmOpenInfoPtr		"dmOpenList"
	
	> Byte 					"dbgInDebugger"
	> Byte 					"dbgTracing"
	> Ptr 					"dbgGlobalsP"
	> Ptr						"dbgSerGlobalsP"
	
	> SysAppInfoPtr		"sysAppInfoP"
	> Ptr						"sysKernelDataP"
	> Ptr						"sysDispatchTableP"	
	> DWord					"sysOwnerIDsInUse"				
	> Ptr						"sysAMXAppInfoP"
	> DWord					"sysClockFreq"
	> DWordPtr				"sysHardKeyCreators"
	
	> SWord					"sysBatteryCheckTimer"
	> Byte					"sysBatteryMinThreshold"
	> Byte					"hwrBatteryLevel"
	> SWord					"sysNextBatteryTimer"
	> Byte					"sysBatteryWarnThreshold"
	
	> Byte					"sysDispatchTableRev"
	> Word					"sysDispatchTableSize"
	
	> SysLibTblEntryPtr	"sysLibTableP"
	> Word					"sysLibTableEntries"
	> Ptr						"sysConsoleStackChunkP"
	> SysAppInfoPtr		"sysUIShellAppInfoP"
	
	> Long					"sysTimerID"
	> ULong					"sysAutoOffEvtTicks"
	> Word					"sysAutoOffSeconds"
	> Long					"sysRandomSeed"
	
	> Ptr						"slkGlobalsP"
	> Ptr				 		"serGlobalsP"
	> Ptr 					"scrGlobalsP"
	> Ptr 					"fplGlobalsP"
	> Ptr						"penGlobalsP"
	> Ptr 					"sysEvtMgrGlobalsP"
	> Ptr						"sndGlobalsP"
	> Ptr						"timGlobalsP"
	> Ptr						"almGlobalsP"
	> Ptr						"ftrGlobalsP"
	> Ptr						"grfGlobalsP"
	> Ptr						"keyGlobalsP"
	
	> Byte					"uiGlobals"[$B0] \-
	> Ptr 					"uiExtensionsP"
	
	> SysAppInfoPtr		"curUIAppInfoP"
	> DWord					"nextUIAppDBID"
	> Word					"nextUIAppCmd"
	> Ptr						"nextUIAppCmdPBP"
	> Byte					"nextUIAppCardNo"
	
	
	> SByte					"hwrDataWELevel"
	> Word					"hwrWakeUp"
	> Byte					"hwrCPUDutyCycle"
	> Byte					"hwrPenDown"
	> DWord					"hwrCurTicks"
	> DWord					"hwrTotalRAMSize"
	> DWord					"hwrDozeSubTicks"
	
	> DWord					"sndOffTicks"
	> Byte					"sysResetFlags"
	> Byte					"sysBatteryKind"
	
	> DWord					"memMinDynHeapFree"
	
	> Word					"sysPrefFlags"
	
	> Ptr						"sysGlobalsP"
	
	> Word					"sysMiscFlags"
	
	> Word					"sysLibNet"
	> Ptr						"netPktFreeQ"
	
	> DWord					"sysEvGroupID"

	> Ptr						"irq3GlobalsP"
	
	> DWord					"sysLastBatteryWarning"
	> DWord					"sysLowMemChecksum"
	
	> Word					"hwrHardwareRev"
	
	> Handle					"dmProtectListH"
	> Word					"hwrMiscFlags"
	
	> DWord					"sysProfilerRefcon"
	> Ptr						"sysProfilerProcP"
	
	> DWord					"flpSoftFPSCR"
	
	> Ptr						"irLibGlobalsP"
	> Word					"exgActiveLib"
	> Word					"uiBusyCount"
	> Ptr						"irq1GlobalsP"
	> Ptr						"irq2GlobalsP"
	> Ptr						"irq6GlobalsP"

	> Ptr						"intlMgrGlobalsP"

	> Word					"inlineStart"						
	> Word					"inlineEnd"						
	> Boolean				"inlineActive"			
	> Byte					"inlineReservedFillerByte1"			
	> VoidPtr				"inlineStatus"
	> Word					"inlineLibRef"						
	> Word					"inlineHighlightLen"			

	> Ptr						"sysBatteryDataP"
	> Ptr						"sysBatteryValidKindsP"
	
	> Boolean				"sysInShutdown"		
	> Byte					"sysMinWakeupThreshold"
	
	> DWord					"hwrMiscFlagsExt"

	> Boolean				"sysUseCritWarnTimer"
	> Boolean				"sysCritWarnTimerRunning"
	> SWord					"sysCritWarnRTCDayStarted"
	> SDWord					"sysCritWarnTickTimer"
	> DWord					"sysCritWarnLastTick"
	> Boolean				"sysCharging"
	> Boolean				"sysUpdateVoltageLevel"

	> Handle					"notifyGlobalsH"

	> DWord					"sysReserved31DWord1"
	> DWord					"sysReserved31DWord2"
	> DWord					"sysReserved31DWord3"
	> DWord					"sysReserved31DWord4"

	typeend
	
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; LowMem structures from 2.0 devices
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

var 	"hwrNumCardSlots"			#1

typedef struct "LowMemTypeV20"
	> M68KExcTableType		"vectors" \-
	> GlobalsTypeV20			"globals"
	> CardInfoType				"memCardInfo"[hwrNumCardSlots]
	> SlkGlobalsType			"slkGlobals" \-
	> DbgGlobalsType			"dbgGlobals" \-
	> SysAppInfoType			"sysAppInfo" \-
	> Ptr							"sysDispatchTable"[2]
	typeend
	
	

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; LowMem structures from 3.0 device
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

typedef struct "LowMemHdrType"
	> M68KExcTableType		"vectors"
	> GlobalsType				"globals"
	typeend
	
typedef struct "LowMemType"
	> M68KExcTableType		"vectors" \-
	> GlobalsType				"globals"
	> CardInfoType				"memCardInfo"[hwrNumCardSlots]
	> SlkGlobalsType			"slkGlobals" \-
	> DbgGlobalsType			"dbgGlobals" \-
	> SysAppInfoType			"sysAppInfo" \-
	> Ptr							"sysDispatchTable"[2]
	typeend
	
	

;################################################################
; Macros
;##############################################################
alias "LowMem" 		"dm 0 LowMemType"
alias "LowMemV20" 	"dm 0 LowMemTypeV20"

alias "M68KExcTable" "dm 0 M68KExcTableType"
alias "Globals" 		"dm 100 GlobalsType"
alias "UIGlobals" 	"dm 18c UIGlobalsType"
alias "UIGlobalsV20" "dm 18c UIGlobalsTypeV20"

alias "SlkGlobals"	"dm 2dc SlkGlobalsType"
alias "DbgGlobals"	"dm 318 DbgGlobalsType"
alias "SysAppInfo"	"dm 6e6 SysAppInfoType"

; There's already a (slightly outdated) debugger command for this...
;alias "CardInfo"		"dm 2b0 CardInfoType"

alias "SysLibTbl"		"dw 00144 \n dm @00140 SysLibTblEntryType"

alias "ScrGlobals"		"dm @.l($00000164) ScrGlobalsType"
alias "Ser328Globals"	"dm @.l($00000160) SerGlobalsType"
alias "Ser681Globals"	"dm @.l($0000027C) Ser681GlobalsType"

;alias "NewROM"    	"load \"fakerom\" 20000 \n g @(.+4)"
;alias "NewROM1"   	"load \"fakerom\" 820000 \n g @(.+4)"


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Aliases for displaying the alarm table
;;
;; Alias name: AlmGlobalsV30		-- displays the alarm table for PalmOS v1.0-3.0
;; Alias name: AlmGlobals			-- displays the alarm table for the current PalmOS version
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ASSUMPTIONS:
; almGlobalsP is at $0000017C
; alarm table addr = @.a((@.a(@.a$0000017C))&$7fffffff)
; number of alarm table entries is @.w(alarm table addr)
; the first alarm entry is at (alarm table addr)+2
;
;; NOTES:
; executing the alias AlmGlobals or AlmGlobalsV30 will generate the warning:
; "WARNING: redefining variable: _AlmTabP"
; ignore it.
alias "AlmGlobalsV30" "var \"_AlmTabP\" @.a((@.a(@.a$0000017C))&$7fffffff) \n dm @.a$0000017C AlmGlobalsTypeV30 \n dm _AlmTabP AlmTableType \n dm _AlmTabP+2  @.w(_AlmTabP) AlmEntryTypeV30"
alias "AlmGlobals" "var \"_AlmTabP\" @.a((@.a(@.a$0000017C))&$7fffffff) \n dm @.a$0000017C AlmGlobalsType \n dm _AlmTabP AlmTableType \n dm _AlmTabP+2  @.w(_AlmTabP) AlmEntryType"

