;SYSPAG.68K	DEC-04-89
;System page module for Apex
;Written by Loren Blaney
;This is based on 6502 code written by P.J.R.Boyle.
;
;REVISION HISTORY:
;FEB-15-86, Original written for DFM Engineering
;MAY-05-86, Converted to ASM68K CONVENTIONS
;SEP-24-86, Revised
;DEC-08-86, Changed CURSORY to handle second terminal (device 1)
;FEB-16-87, Changed MEMTOP for Amiga system, also shifted comments to
; lowercase, changed VMON to VBUG.
;JUN-24-88, Added console variables.
;FEB-25-89, Added conditional assembly flag A1000.
;DEC-04-89, Added EOTFLG for XMODEM device.
;
;NOTES:
;This module defines the addresses of parameters which are common to
; many programs. Note that this module only defines locations, and it
; does not set the contents of these locations. The contents are set by
; other modules which INCLUDE this module to get these address
; definitions. Because many programs depend on these addresses, they
; should not be changed.
;
;This "page" (the frist 256 bytes) is saved along with a memory image as
; part of a .SAV file. It provides Apex with essential information for
; loading and starting a program contained in the .SAV file.
;
;-----------------------------------------------------------------------
;MISCELLANEOUS DEFINITIONS:
;
MEMTOP	EQU	$80000		;Highest memory location +1
				;Apex is loaded just below this point
;BOOLEANS:
FALSE	EQU	0
TRUE	EQU	~FALSE

A1000	EQU	TRUE		;Amiga-1000 is used (vs. 2000 or 500)

;ASCII CHARACTERS:
NUL	EQU	$00		;Null character
BEL	EQU	$07		;Bell
BS	EQU	$08		;Back space
TAB	EQU	$09		;Tab
LF	EQU	$0A		;Line feed
FF	EQU	$0C		;Form feed (screen clear)
CR	EQU	$0D		;Carriage return
FWDSP	EQU	$15		;Forward space (arrow)
EOF	EQU	$1A		;End of file
ESC	EQU	$1B		;Escape
SPACE	EQU	$20		;Space
CTRL	EQU	$40		;Amount subtracted to make control char
DEL	EQU	$7F		;Delete

;-----------------------------------------------------------------------
;PROGRAM START AND EXIT VECTORS:
;
SYSPAG	ORG	$0400		;Right above hardware vectors

VSTART	DS.W	3		;Program start entry point
VRSTRT	DS.W	3		;Program restart entry point
VEXIT	DS.W	3		;Program normal exit address (CTRL-C)
VERR	DS.W	3		;Program error exit address
VABORT	DS.W	3		;Program abort exit address (CTRL-P)
	DS.W	6		;Spares

;-----------------------------------------------------------------------
;These are the load parameters for .SAV files. The intrinsics FRUN,
; FGET, and FSAVE require them.
DSKMEM	DS.L	1		;Base address of memory image on disk
DSKSIZ	DS.L	1		;Size of the image in blocks (not
				; including SYSPAG)
;These are written by APEX.XPL (or set up by the user program) then
; copied to DSKMEM & DSKSIZ by FSAVE and FASAVE. (They are required
; because SCRATCH.SYS needs uncorrupted load parameters.)
USRMEM	DS.L	1		;Base address of user program
PROSIZ	DS.L	1		;User program size in blocks (not
				; including SYSPAG)
	DS.L	8		;Spares for more user program segments

;-----------------------------------------------------------------------
RERUNF	DS.B	1		;Rerun flag: cleared by FRUN; set by
				; RESTART intrinsic. Used to distinguish
				; a first-time start from a restart.
DEXTO	DS.B	3		;Default extension for output file
	DS.B	3
DEXTI	DS.B	3		;Default extension for input file
	DS.B	3
DEFAUL	DS.B	1		;Flags: backup, size limit, keep date
SYBOMB	DS.B	1		;Flag: user program bombs system
				; (=$55 if Apex is loaded)
	DS.L	1
HEAP	DS.L	1		;Base address of heap
STACK	DS.L	1		;User's stack grows down from here
	DS.L	4		;Spares

;-----------------------------------------------------------------------
;MEMORY SPACE ALLOCATED FOR DISK I/O BUFFERS:
OTBUF	DS.L	1		;Base of output buffer
OTBUFE	DS.L	1		;End of output buffer +1
INBUF	DS.L	1		;Base of input buffer
INBUFE	DS.L	1		;End of input buffer +1
	DS.L	8		;Spares for more input file buffer specs

;=======================================================================
;The rest of this system "page" is not saved with the .SAV file, but
; rather is loaded during the original bootup process.  It remains
; unchanged during normal operation.
;
	ORG	$0500
SYSENF	DS.B	1		;Sysem entry flag: shows re-entry mode
SYSUNT	DS.B	1		;Unit that SYSTEM.SYS is on
SYSBLK	DS.L	1		;Block where SYSTEM.SYS starts
SWPBLK	DS.L	1		;Block where SCRATCH.SYS starts
SYSDAT	DS.L	1		;System date (i.e: today)
	DS.L	1		;Spare

VALUNT	DS.B	1		;Bit array: indicates valid units
LOKMSK	DS.B	1		;Bit array: shows write-locked units
UNTUPD	DS.B	1		;Bit array: units needing update, unused

DEFUNT	DS.B	1		;Default unit number (0-7)

	DS.W	1		;DEVHAN uses the low byte of a word
DEVICE	EQU	@-1		;Current byte I/O device number (0-7)

ERRTRAP	DS.B	1		;Flag: trap (report) errors
ERRUNT	DS.B	1		;Unit number when error occurred
ERRDEV	DS.B	1		;Device number when error occurred
ERRLOC	DS.L	1		;Address of error

	DS.L	8		;Spares

;-----------------------------------------------------------------------
;I/O PARAMETERS FOR UNIT HANDLERS:
;
	DS.W	1		;UNTHAN uses the low byte of a word
UNIT	EQU	@-1		;Unit number (0-7)
BLKNO	DS.L	1		;First block of file
BLKNOX	DS.L	1		;First block of file with offset added
NBLKS	DS.L	1		;Number of blocks to transfer
FADDR	DS.L	1		;Memory address
ENDBLK	DS.L	1		;Last block of file

;OUTPUT FILE PARAMETERS:
OTLBLK	DS.L	1		;First block of output file
OTHBLK	DS.L	1		;Last block of output file
OTFLG	DS.B	1		;Status flags (1 = SETUP)
OTNO	DS.B	1		;Directory number of output file
OTUNT	DS.B	1		;Unit number which output file is on

;INPUT FILE PARAMETERS:
INLBLK	DS.L	1		;First block of input file
INHBLK	DS.L	1		;Last block of input file
INFLG	DS.B	1		;Status flags
INNO	DS.B	1		;Directory number of input file
INUNT	DS.B	1		;Unit number which input file is on

	DS.L	6		;Spares

;-----------------------------------------------------------------------
;UNIT HANDLER TABLES
; These tables specify parameters for a maximum of 8 units.
;
;UNIT LIMIT TABLE:
; Contains the last physical block + 1 allocated for a sub-unit.
MAXTBL	DS.L	8
	DS.L	8		;Spares

;UNIT OFFSET TABLE:
; Contains the first physical block number for each unit. The logical
; blocks in a sub-directory are relative to these base blocks.
OFFTBL	DS.L	8
	DS.L	8		;Spares

;UNIT ENTRY POINT TABLE:
UNTTBL	DS.L	8
	DS.L	8		;Spares

;BYTE I/O DEVICE HANDLER ENTRY POINT TABLE:
DEVTBL	DS.L	8
	DS.L	8		;Spares

;-----------------------------------------------------------------------
;CONSOLE PARAMETERS:
;
HASH	DS.L	1		;Randomizer, spun by keyboard wait loop
CMDMOD	DS.B	1		;Flag: command file mode

;Cursor position coordinates. 0,0 = upper left corner.
; WARNING: These are not correct if a line > 80 chars is displayed.
CURSORX	DS.B	2		;X cursor positions for devices 0 and 1
CURSORY	DS.B	2		;Y cursor positions for devices 0 and 1

LINPTRF	DS.L	1		;Fill pointer for line buffer
LINPTRE	DS.L	1		;Empty pointer for line buffer
CMDPTR	DS.L	1		;Pointer into CMDBUF

CHKUSRF	DS.B	1		;Flag: enable CHKUSR, CTRL-C aborts etc.
	DS.B	1		;Spare
CONWIDE	DS.B	1		;Console width in characters
CONHIGH	DS.B	1		;Console height in characters
EOTFLG	DS.B	1		;Flag: EOT received by XMODEM
	DS.B	7		;Spares

LINBUF	DS.B	256		;Line buffer (256 characters)
LINBUFE	EQU	@		;Last location +1
CMDBUF	EQU	LINBUF		;.CMD files share the line buffer

;-----------------------------------------------------------------------
;LINK VECTORS TO RESIDENT ROUTINES:
;
VBUG	DS.W	3		;Debug monitor
VRELOD	DS.W	3		;Reload Apex from disk and start it
VRENTR	DS.W	3		;Re-enter Apex, reload it if bombed
VSAVER	DS.W	3		;Save memory image in SCRATCH.SYS and
				; reload
VFRUN	DS.W	3		;Load and start a .SAV file
VFGET	DS.W	3		;Load a .SAV file and start the monitor
VFSAVE	DS.W	3		;Load SCRATCH.SYS and write a .SAV file
VFASAVE	DS.W	3		;Write SYSTEM.SYS
VFSCAN	DS.W	3		;Scan directory for a file name

VUNTHAN	DS.W	3		;Main unit handler
VDEVHAN	DS.W	3		;Main device handler

VSHOERR	DS.W	3		;Record system error
VERROR	DS.W	3		;Display system error message

;----------------------------------------------------------------------
;
INTTBL	EQU	$800		;XPL intrinsics jump table

;End of SYSPAG
-----------------------------------------------------------
;
INTTBL	EQU	$800		;XPL in