mirror of
https://github.com/byteworksinc/ORCA-Pascal.git
synced 2024-09-29 11:54:39 +00:00
1 line
9.7 KiB
NASM
1 line
9.7 KiB
NASM
|
mcopy pcommon.macros
****************************************************************
*
* MMCom - common data area for the memory manager
*
****************************************************************
*
MMCom privdata
;
; constants
;
maxBuffSize equ 16*1024 size of a buffer
;
; data
;
buffSize ds 2 remaining bytes in the current buffer
currBuffHand ds 4 handle of current buffer
currBuffStart ds 4 pointer to start of current buffer
nextPtr ds 4 pointer to next byte in current buffer
end
****************************************************************
*
* BRK - break into the debugger
*
* Inputs:
* 4,S - break code
*
****************************************************************
*
BRK start
phb
plx
ply
pla
and #$00FF
xba
sta lb1
phy
phx
plb
lb1 brk $00
rtl
end
****************************************************************
*
* Calloc - allocate and clear a new memory area
*
* Inputs:
* size - # bytes to allocate
*
* Outputs:
* X-A - pointer to memory
*
* Notes: Assumes size > 2
*
****************************************************************
*
Calloc start
ptr equ 1 pointer to memory
sub (2:size),4
ph2 size allocate the memory
jsl Malloc
sta ptr
stx ptr+2
ldy size if there are an odd number of bytes then
tya
lsr A
bcc lb1
dey clear the last byte
short M
lda #0
sta [ptr],Y
long M
lb1 lda #0 clear the memory, one word at a time
lb2 dey
dey
sta [ptr],Y
bne lb2
ret 4:ptr
end
****************************************************************
*
* CompNames - Compare two names
*
* Inputs:
* name1, name2 - addresses of the two strings to compare
*
* Outputs:
* int - 0 if equal, -1 if name1<name2, 1 if name1>name2
*
****************************************************************
*
CompNames start
result equ 1
sub (4:name1,4:name2),2
short I,M
lda [name1] get the length of the shorter string
cmp [name2]
blt lb1
lda [name2]
lb1 tax
beq lb2a
ldy #1 compare the existing characters
lb2 lda [name1],Y
cmp [name2],Y
bne lb4
iny
dex
bne lb2
lb2a lda [name1] characters match -- compare the lengths
cmp [name2]
bne lb4
lb3 long I,M
lda #0 strings match
bra lb6
lb4 long I,M strings don't match -- set condition code
bge lb5
lda #-1
bra lb6
lb5 lda #1
lb6 sta result
ret 2:result
end
****************************************************************
*
* KeyPress - Has a key been presed?
*
* If a key has not been pressed, this function returns
* false. If a key has been pressed, it clears the key
* strobe. If the key was an open-apple ., a terminal exit
* is performed; otherwise, the function returns true.
*
****************************************************************
*
KeyPress start
KeyPressGS kpRec
lda kpAvailable
beq rts
ReadKeyGS rkRec
lda rkKey
cmp #'.'
bne lb1
lda rkModifiers
and #$0100
beq lb1
ph2 #0
ph4 #0
jsl TermError
lb1 lda #1
rts rtl
kpRec dc i'3'
kpKey ds 2
kpModifiers ds 2
kpAvailable ds 2
rkRec dc i'2'
rkKey ds 2
rkModifiers ds 2
end
****************************************************************
*
* Mark - mark the stack
*
* Inputs:
* ptr - location to place mark
*
****************************************************************
*
Mark start
using MMCom
sub (4:ptr),0
ldy #2 ptr^ := nextPtr
lda nextPtr
sta [ptr]
lda nextPtr+2
sta [ptr],Y
ret
end
****************************************************************
*
* MMInit - initialize the memory manager
*
****************************************************************
*
MMInit start
using MMCom
stz buffSize no bytes in current buffer
stz currBuffHand nil handle
stz currBuffHand+2
rtl
end
****************************************************************
*
* Malloc - allocate a new memory area
*
* Inputs:
* size - # bytes to allocate
*
* Outputs:
* X-A - pointer to memory
*
****************************************************************
*
Malloc start
using MMCom
ptr equ 1 pointer to memory
handle equ 5 new memory handle
lptr equ 9 work pointer
sub (2:size),12
lda buffSize if
|