A2osX/BIN/MEM.S.txt
Rémy GIBERT 62f272bbf2 Initial
2015-03-08 22:45:23 +01:00

286 lines
5.1 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PR#3
PREFIX /DATA/A2OSX
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF BIN/MEM
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/LIBSTR.I
*--------------------------------------
ZPPTR1 .EQ ZPBIN
ZPPTR2 .EQ ZPBIN+2
*--------------------------------------
* Main entry point
*--------------------------------------
* Code signature and INIT table
*--------------------------------------
* CLD $D8
* JMP (*,x) $7C
* #JMPTABLE
* /JMPTABLE
*--------------------------------------
CS.START cld
jmp (.1,x)
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBSTR .DA LIBSTR
L.MSG0 .DA MSG0
L.MSG1 .DA MSG1
L.MSG2 .DA MSG2
L.MSG3 .DA MSG3
L.MSG4 .DA MSG4
L.MSG5 .DA MSG5
L.MSG6 .DA MSG6
L.MSG7 .DA MSG7
.DA 0
.DA CS.END-CS.START Code Length To Relocate
.DA DS.END-DS.START Data Segment to Allocate
*--------------------------------------
CS.INIT >LIBLOADP L.LIBSTR
bcs .9
sta hLIBSTR
stz LINE.COUNT
stz MEM.COUNT
stz USED.COUNT
stz bSTOP
stz bCANCEL
lda (pPsContext)
ora #S.PS.F.EVENT Now accept events
sta (pPsContext)
clc
.9 rts
*--------------------------------------
CS.RUN lda bCANCEL
bne .99
lda bSTOP
bne .8
lda LINE.COUNT
bne .1
>PUSHW L.MSG0
>LIBCALL hLIBSTR,LIBSTR.PRINTF
.1 lda MEM.COUNT
>SYSCALL SYS.GetMemByIDA
>STYA ZPPTR1
lda (ZPPTR1)
bpl .2
inc USED.COUNT
.2 jsr CS.RUN.PRINTMEM
inc MEM.COUNT
lda MEM.COUNT
cmp MEMMGR.TABLESIZE
beq .9
.8
clc
rts
.9 jsr CS.RUN.PRINTEND
.99 sec
rts
*--------------------------------------
CS.RUN.PRINTMEM ldy #S.MEM.LEN
lda (ZPPTR1),y
pha
iny
lda (ZPPTR1),y
ply
>PUSHYA
ldy #S.MEM.PTR
lda (ZPPTR1),y
pha
iny
lda (ZPPTR1),y
ply
>PUSHYA
ldy #S.MEM.REFCNT
lda (ZPPTR1),y
>PUSHA
ldy #S.MEM.OWNERPID
lda (ZPPTR1),y
>PUSHA
lda (ZPPTR1)
>PUSHA
lda MEM.COUNT
>PUSHA
>PUSHW L.MSG1
>LIBCALL hLIBSTR,LIBSTR.PRINTF
ldy #S.MEM.BIN
lda (ZPPTR1),y
bne .3
ldy #S.MEM.PTR
lda (ZPPTR1),y
sta ZPPTR2
iny
lda (ZPPTR1),y
sta ZPPTR2+1
lda #"{"
jsr COUT
lda (ZPPTR2)
jsr PRBYTE
lda #"|"
jsr COUT
ldy #1
.1 lda (ZPPTR2),y
ora #$80
cmp #$A0
bcs .2
ora #$20
.2 jsr COUT
iny
cpy #40
bne .1
lda #"}"
jsr COUT
bra .4
.3 >SYSCALL SYS.GetMemPtrA
>PUSHYA
>LIBCALL hLIBSTR,LIBSTR.PRINTP
.4 jsr CROUT
inc LINE.COUNT
lda LINE.COUNT
cmp #22
bne .5
lda #$FF
sta bSTOP
stz LINE.COUNT
.5 rts
*--------------------------------------
CS.RUN.PRINTEND >PUSHB MEM.COUNT
>PUSHB USED.COUNT
>PUSHW L.MSG2
>LIBCALL hLIBSTR,LIBSTR.PRINTF
>PUSHW MEMMGR.LOMEM
>PUSHW L.MSG3
>LIBCALL hLIBSTR,LIBSTR.PRINTF
>PUSHW MEMMGR.MLLIMIT
>PUSHW L.MSG4
>LIBCALL hLIBSTR,LIBSTR.PRINTF
>PUSHW MEMMGR.MHLIMIT
>PUSHW L.MSG5
>LIBCALL hLIBSTR,LIBSTR.PRINTF
>PUSHW MEMMGR.HIMEM
>PUSHW L.MSG6
>LIBCALL hLIBSTR,LIBSTR.PRINTF
>PUSHW MEMMGR.MFREE
>PUSHW L.MSG7
>LIBCALL hLIBSTR,LIBSTR.PRINTF
rts
*--------------------------------------
CS.DOEVENT >PULLW pEvent
ldy #S.EVT.hDEV is Event from active IN device?
lda (pEvent),y
ldy #S.PS.hINDEV
cmp (pPsContext),y
bne .9
lda (pEvent)
and #S.EVT.F.KEY is it a KEY event?
beq .9
ldy #S.EVT.DATAHI is it an O or SAPPLE key ?
lda (pEvent),y
bne .9
ldy #S.EVT.DATALO
lda (pEvent),y
cmp #$03 Ctrl-C
bne .1
lda #$FF
sta bCANCEL
bra .8
.1 cmp #$13 Ctrl-S
bne .2
lda bSTOP
eor #$FF
sta bSTOP
bra .8
.2 lda bSTOP
beq .8
stz bSTOP
.8 >SYSCALL SYS.DestroyEvent
clc
rts
.9 sec
rts
*--------------------------------------
CS.QUIT lda hLIBSTR
>SYSCALL SYS.UnloadLibA
clc
rts
*--------------------------------------
PRBYTE pha
lsr
lsr
lsr
lsr
ora #$B0
cmp #$BA
bcc .1
adc #6
.1 jsr COUT
pla
and #$0F
ora #$B0
cmp #$BA
bcc COUT
adc #6
bra COUT
*--------------------------------------
CROUT lda #13
*--------------------------------------
COUT phx
phy
>PUSHA
ldy #S.PS.hOUTDEV
lda (pPsContext),y
>SYSCALL SYS.DevOutA
ply
plx
rts
*--------------------------------------
CS.END
DS.START
*--------------------------------------
hLIBSTR .BS 1
LINE.COUNT .BS 1
MEM.COUNT .BS 1
USED.COUNT .BS 1
bSTOP .BS 1
bCANCEL .BS 1
LIBSTR >PSTRING "libstr.o"
MSG0 >CSTRING "hMem Flags PID REF PTR LEN BINPATH/DATA\n"
MSG1 >CSTRING " %03d %b $%h $%h $%H $%H "
MSG2 >CSTRING "\nAllocated hMem:%d, Total:%d\n"
MSG3 >CSTRING "Low Memory: $%H\n"
MSG4 >CSTRING "Low Free PTR: $%H\n"
MSG5 >CSTRING "High Free PTR: $%H\n"
MSG6 >CSTRING "High Memory: $%H\n"
MSG7 >CSTRING "\nFree Memory: %D Bytes.\n"
DS.END
*--------------------------------------
MAN
SAVE BIN/MEM.S
ASM