NEW
  AUTO 3,1
				.LIST OFF
				.OP	65C02
				.OR	$2000
				.TF bin/mem
*--------------------------------------
				.INB INC/MACROS.I
				.INB INC/A2OSX.I
*--------------------------------------
				.DUMMY
				.OR ZPBIN
ZS.START
MemStat			.BS S.MSTAT
ZS.END			.ED
*--------------------------------------
*			File Header (16 Bytes)
*--------------------------------------
CS.START		cld
				jmp (.1,x)
				.DA #$61				6502,Level 1 (65c02)
				.DA #1					BIN Layout Version 1
				.DA 0
				.DA CS.END-CS.START		CS
				.DA DS.END-DS.START		DS
				.DA #64					SS
				.DA #ZS.END-ZS.START	Zero Page Size
				.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1				.DA CS.INIT
				.DA CS.RUN
				.DA CS.DOEVENT		
				.DA	CS.QUIT
L.MSG.Main		.DA MSG.Main
L.MSG.Aux		.DA MSG.Aux
L.MSG.Kernel	.DA MSG.Kernel
L.MSG.Stat		.DA MSG.Stat
L.MSG.End		.DA MSG.End
L.MemStat		.DA MemStat
				.DA 0
*--------------------------------------
CS.INIT			clc
				rts
*--------------------------------------
CS.RUN			>LDYA L.MemStat
				>SYSCALL GetMemStat

				>LDYA L.MSG.Main
				>SYSCALL puts

				lda MemStat+S.MSTAT.MF
				sec
				sbc MemStat+S.MSTAT.ML
				tay
				lda MemStat+S.MSTAT.MF+1
				sbc MemStat+S.MSTAT.ML+1
				ldx #S.MSTAT.ML
				jsr CS.RUN.PRINT
				>SLEEP

				>LDYA L.MSG.Aux
				>SYSCALL puts

				lda MemStat+S.MSTAT.XF
				sec
				sbc MemStat+S.MSTAT.XL
				tay
				lda MemStat+S.MSTAT.XF+1
				sbc MemStat+S.MSTAT.XL+1
				ldx #S.MSTAT.XL
				jsr CS.RUN.PRINT
				>SLEEP

				>LDYA L.MSG.Kernel
				>SYSCALL puts

				lda MemStat+S.MSTAT.DH
				sec
				sbc MemStat+S.MSTAT.DF
				tay
				lda MemStat+S.MSTAT.DH+1
				sbc MemStat+S.MSTAT.DF+1
				ldx #S.MSTAT.DL
				jsr CS.RUN.PRINT
				>LDYA L.MSG.END
				>SYSCALL puts
				lda #0
				sec
				rts
*--------------------------------------
CS.RUN.PRINT	pha
				phy
				>PUSHW L.MSG.Stat
					
				ldy #3
				
.1				>PUSHW MemStat,x
				>PUSHW MemStat,x
				inx
				inx
				dey
				bne .1
				
				ply
				pla
				>PUSHYA
				>PUSHBI 14
				>SYSCALL printf
				rts
*--------------------------------------
CS.DOEVENT		sec
				rts
*--------------------------------------
CS.QUIT			clc
				rts
*--------------------------------------
CS.END
MSG.Main		.AZ "--- Main Memory ----------------"
MSG.Aux			.AZ "--- Aux Memory -----------------"
MSG.Kernel		.AZ "--- Kernel (Drivers) Memory ----"
MSG.Stat		.AS " Low              : %5D (%H)\r\n"
				.AS " Free Ptr         : %5D (%H)\r\n"
				.AS " High             : %5D (%H)\r\n"
				.AZ " Available Memory : %5D Bytes\r\n"
MSG.End			.AZ "--------------------------------"
*--------------------------------------
				.DUMMY
				.OR 0
DS.START
DS.END
				.ED
*--------------------------------------
MAN
SAVE USR/SRC/BIN/MEM.S
ASM
