; Copyright 2018 faddenSoft. All Rights Reserved.
; See the LICENSE.txt file for distribution terms (Apache 2.0).
;
; Sources:
;   GS/OS Reference Manual
;   Orca/M 2.0 assembler manual
;   NiftyList data file
;   Brutal Deluxe "GS/OS Internals"

*SYNOPSIS GS/OS public addresses and constants.

gsos_inline_ent     @ $e100a8 4     ;GS/OS inline call entry point
gsos_stack_ent      @ $e100b0 4     ;GS/OS stack call entry point

*TAG AppleIIgs-GSOS-Functions

; Class 0 ProDOS 16 calls.
P16_ALLOC_INTERRUPT = $0031         ;(Int#,@Code)
P16_CHANGE_PATH     = $0004         ;(@Path1,@Path2)
P16_CLEAR_BACKUP_BIT = $000B        ;(@Path)
P16_CLOSE           = $0014         ;(Ref)
P16_CREATE          = $0001         ;(@Path,Acc,Typ,Aux/4,StT,CrD,CrT)
P16_DEALLOC_INTERTUPT = $0032       ;(Int#)
P16_DESTROY         = $0002         ;(@Path)
P16_D_INFO          = $002C         ;(Dev#,@DevName)
P16_ERASE_DISK      = $0025         ;(@DevName,@VolName,fsID)
P16_EXPAND_PATH     = $000E         ;(@PathIn,@PathOut,Flags)
P16_FLUSH           = $0015         ;(Ref)
P16_FORMAT          = $0024         ;(@DevName,@VolName,fsID)
P16_GET_BOOT_VOL    = $0028         ;(@Buff)
P16_GET_DEV_NUM     = $0020         ;(@DevName,Dev#)
P16_GET_DIR_ENTRY   = $001C         ;(Ref#,z,Bs,Dis,@Bf,dEnt/36)
P16_GET_EOF         = $0019         ;(Ref,EOF/4)
P16_GET_FILE_INFO   = $0006         ;(@P,a,t,xt/4,s,cDT,mDT,b/4)
P16_GET_LAST_DEV    = $0021         ;(Dev#)
P16_GET_LEVEL       = $001B         ;(Level)
P16_GET_MARK        = $0017         ;(Ref,Pos/4)
P16_GET_NAME        = $0027         ;(@Buff)
P16_GET_PREFIX      = $000A         ;(Pfx#,@Buff)
P16_GET_VERSION     = $002A         ;(Version)
P16_NEWLINE         = $0011         ;(Ref,Mask,Char)
P16_OPEN            = $0010         ;(Ref,@Path,xxx/4)
P16_QUIT            = $0029         ;(@Path,Flags)
P16_READ            = $0012         ;(Ref,@Where,Count/4,xfCount/4)
P16_READ_BLOCK      = $0022         ;(Dev#,@Where,Blk#/4)
P16_SET_EOF         = $0018         ;(Ref,EOF/4)
P16_SET_FILE_INFO   = $0005         ;(@P,a,t,xt/4,z,cD,cT,mD,mT)
P16_SET_LEVEL       = $001A         ;(Level)
P16_SET_MARK        = $0016         ;(Ref,Pos/4)
P16_SET_PREFIX      = $0009         ;(Pfx#,@Prefix)
P16_VOLUME          = $0008         ;(@DevN,@VolN,Blks/4,FreeBlks/4,fsID)
P16_WRITE           = $0013         ;(Ref,@Where,Count/4,xfCount/4)
P16_WRITE_BLOCK     = $0023         ;(Dev#,@Where,Blk#/4)

; Class 1 GS/OS calls.  Names match the macros defined in Orca/M's M16.GSOS
; (i.e. they all end with "GS" except for FSTSpecific).
AddNotifyProcGS     = $2034         ;(1:@proc)
BeginSessionGS      = $201D         ;(0:)
BindIntGS           = $2031         ;(3:IntNum,VecRefNum,@handler)
ChangePathGS        = $2004         ;(2-3:@P1,@P2,TrustMeFlag)
ClearBackupBitGS    = $200B         ;(1:@P)
CloseGS             = $2014         ;(1:ref)
CreateGS            = $2001         ;(1-7:@P,Acc,Typ,Aux/4,Stg,EOF/4,rEOF/4)
DControlGS          = $202E         ;(5:n,code,@ctlList,count/4,xfer/4)
DelNotifyProcGS     = $2035         ;(1:@proc)
DestroyGS           = $2002         ;(1:@P)
DInfoGS             = $202C         ;(2-10:n,@n,chr,B/4,sl,unit,ver,dTyp,@hd,@nx)
DReadGS             = $202F         ;(6:n,@bf,count/4,blk/4,blkSz,xfer/4)
DRenameGS           = $2036         ;(2:n,@newName)
DStatusGS           = $202D         ;(5:n,statusReq,@statList,count/4,xfer/4)
DWriteGS            = $2030         ;(6:n,@bf,count/4,blk/4,blkSz,xfer/4)
EndSessionGS        = $201E         ;(0:)
EraseDiskGS         = $2025         ;(1-6:@DevN,@VolN,gotFS,wantFS,flags,realVolName)
ExpandPathGS        = $200E         ;(2-3:@InPath,@OutPath,UpcaseFlg)
FlushGS             = $2015         ;(1-2:ref,flags)
FormatGS            = $2024         ;(1-6:@DevN,@VolN,gotFS,wantFS,flags,realVolName)
FSTSpecific         = $2033         ;(2+...)
GetBootVolGS        = $2028         ;(1:@n)
GetDevNumberGS      = $2020         ;(2:@DevN,devnum)
GetDirEntryGS       = $201C         ;(5-17:rf,fl,bs,ds,@n,n,T,EOF/4,b/4,c/8,m/8,A,X/4,FS,@o,resEOF/4,resBk/4)
GetEOFGS            = $2019         ;(2:ref,eof/4)
GetFileInfoGS       = $2006         ;(2-12:@P,A,T,X/4,S,c/8,m/8,@Opt,EOF/4,B/4,rEOF/4,rB/4)
GetFSTInfoGS        = $202B         ;(2-7:n,fs,@n,ver,attr,bSz,mxV/4,mxF/4)
GetLevelGS          = $201B         ;(1-2:level,levelMode)
GetMarkGS           = $2017         ;(2:ref,pos/4)
GetNameGS           = $2027         ;(1:@n)
GetPrefixGS         = $200A         ;(2:pfxNum,@Pfx)
GetRefInfoGS        = $2039         ;(2-5:ref,acc,@path,resNum,level)
GetRefNumGS         = $2038         ;(2-6:@path,ref,acc,res,case,disp)
GetStdRefNumGS      = $2037         ;(2:pfxNum,refNum)
GetSysPrefsGS       = $200F         ;(1:prefs)
GetVersionGS        = $202A         ;(1:version)
JudgeNameGS         = $2007         ;(3-6:fileSysID,Descr,@Rules,MaxLen,@Path,Result)
NewLineGS           = $2011         ;(4:ref,ANDmask,NumChars,@NLtable)
NullGS              = $200D         ;(0:)
OpenGS              = $2010         ;(2-15:ref,@P,Acc,fork,gotAcc,+GET_FILE_INFO)
OSShutdownGS        = $2003         ;(1:Flags)
QuitGS              = $2029         ;(0-2:@P,flags)
ReadGS              = $2012         ;(4-5:ref,@buff,count/4,xfer/4,cacheFlg)
ResetCacheGS        = $2026         ;(0:)
SessionStatusGS     = $201F         ;(1:status)
SetEOFGS            = $2018         ;(3:ref,base,displ/4)
SetFileInfoGS       = $2005         ;(2-12:@P,A,T,X/4,,c/8,m/8,@Opt,,,,)
SetLevelGS          = $201A         ;(1-2:level,levelMode)
SetMarkGS           = $2016         ;(3:ref,base,displ/4)
SetPrefixGS         = $2009         ;(1-2:pfxNum,@Pfx)
SetStdRefNum        = $203a         ;(2:pfxNum,refNum)
SetSysPrefsGS       = $200C         ;(1:prefs)
UnbindIntGS         = $2032         ;(1:IntNum)
VolumeGS            = $2008         ;(2-8:@DevN,@vnOut,blks/4,free/4,fSys,BlkSz,char,devID)
WriteGS             = $2013         ;(4-5:ref,@buff,count/4,xfer/4,cacheFlg)

; Shell calls.  These are used just like GS/OS calls.  See chapter 24
; in the Orca/M 2.0 manual and M16.Shell.
SH_ChangeVector     = $010C
SH_ConsoleOut       = $011A
SH_Direction        = $010F
SH_Error            = $0105
SH_Execute          = $010D
SH_ExpandDevices    = $0114
SH_Export           = $0116
SH_FastFile         = $010E
SH_GetCommand       = $011D
SH_GetIODevices     = $011C
SH_GetLang          = $0103
SH_GetLInfo         = $0101
SH_InitWildcard     = $0109
SH_Keypress         = $011E
SH_NextWildcard     = $010A
SH_PopVariables     = $0117
SH_PushVariables    = $0118
SH_ReadIndexed      = $0108
SH_ReadKey          = $011f
SH_ReadVariable     = $010B
SH_Redirect         = $0110
SH_Set              = $0106
SH_SetIODevices     = $011B
SH_SetLang          = $0104
SH_SetLInfo         = $0102
SH_SetStopFlag      = $0119
SH_Stop             = $0113
SH_UnsetVariable    = $0115
SH_Version          = $0107

SH_ChangeVectorGS   = $014C
SH_ConsoleOutGS     = $015A
SH_DirectionGS      = $014F
SH_ErrorGS          = $0145
SH_ExecuteGS        = $014D
SH_ExpandDevicesGS  = $0154
SH_ExportGS         = $0156
SH_FastFileGS       = $014E
SH_GetCommandGS     = $015D
SH_GetIODevicesGS   = $015C
SH_GetLangGS        = $0143
SH_GetLInfoGS       = $0141
SH_InitWildcardGS   = $0149
SH_KeypressGS       = $015E
SH_NextWildcardGS   = $014A
SH_PopVariablesGS   = $0157
SH_PushVariablesGS  = $0158
SH_ReadIndexedGS    = $0148
SH_ReadKeyGS        = $015f
SH_ReadVariableGS   = $014B
SH_RedirectGS       = $0150
SH_SetGS            = $0146
SH_SetIODevicesGS   = $015B
SH_SetLangGS        = $0144
SH_SetLInfoGS       = $0142
SH_SetStopFlagGS    = $0159
SH_StopGS           = $0153
SH_UnsetVariableGS  = $0155
SH_VersionGS        = $0147

*TAG

;
; Error codes.
;
; Most of these are public, defined in the GS/OS Reference Manual and
; the GS/OS Driver Reference.  In some case the names are slightly
; different, e.g. "drvrNoDevice" vs. "DrvrNoDev".
;
E_NO_ERROR          = $00       ;successful operation
E_BAD_SYSTEM_CALL   = $01       ;bad GS/OS call number
E_FST_LOAD_FAIL     = $02
E_INVALID_PCOUNT    = $04       ;parameter count out of range
E_GSOS_ACTIVE       = $07       ;GS/OS is busy
E_DEV_NOT_FOUND     = $10       ;device not found
E_INVALID_DEV_NUM   = $11       ;invalid device number (request)
E_DRVR_BAD_REQ      = $20       ;invalid request
E_DRVR_BAD_CODE     = $21       ;invalid control or status code
E_DRVR_BAD_PARM     = $22       ;bad call parameter
E_DRVR_NOT_OPEN     = $23       ;character device not open
E_DRVR_PRIOR_OPEN   = $24       ;character device already open
E_IRQ_TABLE_FULL    = $25       ;interrupt table full
E_DRVR_NO_RESRC     = $26       ;resources not available
E_DRVR_IO_ERROR     = $27       ;I/O error
E_DRVR_NO_DEV       = $28       ;no device connected
E_DRVR_BUSY         = $29       ;driver is busy
E_DRVR_WR_PROT      = $2b       ;device is write-protected
E_DRVR_BAD_COUNT    = $2c       ;invalid byte count
E_DRVR_BAD_BLOCK    = $2d       ;invalid block address
E_DRVR_DISK_SW      = $2e       ;disk has been switched
E_DRVR_OFF_LINE     = $2f       ;device off line or no media present
E_BAD_PATH_SYNTAX   = $40       ;invalid pathname syntax
E_INVALID_REF_NUM   = $43       ;invalid reference number
E_PATH_NOT_FOUND    = $44       ;subdirectory does not exist
E_VOL_NOT_FOUND     = $45       ;volume not found
E_FILE_NOT_FOUND    = $46       ;file not found
E_DUP_PATHNAME      = $47       ;create or rename with existing name
E_VOLUME_FULL       = $48       ;volume full
E_VOL_DIR_FULL      = $49       ;volume directory full
E_BAD_FILE_FORMAT   = $4a       ;incompatible file format (a/k/a version error)
E_BAD_STORE_TYPE    = $4b       ;unsupported (or incorrect) storage type
E_END_OF_FILE       = $4c       ;end-of-file encountered
E_OUT_OF_RANGE      = $4d       ;position out of range
E_INVALID_ACCESS    = $4e       ;access not allowed
E_BUFF_TOO_SMALL    = $4f       ;buffer too small
E_FILE_BUSY         = $50       ;file is already open
E_DIR_ERROR         = $51       ;directory error
E_UNKNOWN_VOL       = $52       ;unknown volume type
E_PARM_RANGE_ERR    = $53       ;parameter out of range
E_OUT_OF_MEM        = $54       ;out of memory
E_DUP_VOLUME        = $57       ;duplicate volume name
E_NOT_BLOCK_DEV     = $58       ;not a block device
E_INVALID_LEVEL     = $59       ;specified level outside legal range
E_DAMAGED_BITMAP    = $5a       ;block number too large
E_BAD_PATH_NAMES    = $5b       ;invalid path names for ChangePath
E_NOT_SYSTEM_FILE   = $5c       ;not an executable file
E_OS_UNSUPPORTED    = $5d       ;operating system not supported
E_STACK_OVERFLOW    = $5f       ;too many applications on stack
E_DATA_UNAVAIL      = $60       ;data unavailable
E_END_OF_DIR        = $61       ;end of directory has been reached
E_INVALID_CLASS     = $62       ;invalid FST call class
E_RES_NOT_FOUND     = $63       ;file does not contain required resource
E_INVALID_FST_ID    = $64       ;FST ID is invalid
E_INVALID_FST_OP    = $65
E_FST_CAUTION       = $66
E_DUP_DEVICE        = $67       ;device exists with same name as replacement name
E_DEV_LIST_FULL     = $68
E_SUP_LIST_FULL     = $69
E_FST_ERROR         = $6a
;
E_RESOURCE_EXIST    = $70       ;cannot expand file, resource fork already exists
E_RES_ADD_ERR       = $71       ;cannot add resource fork to this type of file
E_NETWORK_ERROR     = $88

;
; File system IDs.
;
FSID_PRODOS         = $0001     ;ProDOS/SOS
FSID_DOS33          = $0002
FSID_DOS32          = $0003     ;DOS 3.2 or 3.1
FSID_PASCAL         = $0004
FSID_MFS            = $0005
FSID_HFS            = $0006
FSID_LISA           = $0007
FSID_CPM            = $0008
FSID_CHARACTER      = $0009
FSID_MSDOS          = $000a
FSID_HIGH_SIERRA    = $000b
FSID_ISO_9660       = $000c
FSID_APPLESHARE     = $000d
