*********************************
*                               *
*          MEM.LIB  V1.3        *
*          by Ken Siders        *
* FILLMEM V1.4  (AMAC VERSION)  *
*********************************
;NUMBERS OR REG SEPERATED BY A /
;INDICATE LOW IN FIRST,HI IN 2ND
;
;
PROC

        JMP :SKIP
;
;
;++++++++++++++++++++++++
;+FILL MEM SUB ROUTINES +
;++++++++++++++++++++++++
;
*********XFILLMEM***************
*WILL FILL 205/206 BYTES OF MEM*
*AT LOCATION POINTED TO BY     *
*203/204 WITH VALUE IN "A" REG *
********************************
;
XFILLMEM
 STA 207
 LDA 205
 ORA 206
 BEQ :TERMFM ;NO BYTES TO FIL
 CLC 
 LDA 205
 ADC #255
 STA 205
 LDA 206
 ADC #0
 STA 206
 LDY #0
 LDX 205 ;# BYTES (LOW)
 LDA 207 ;FILL VALUE
:LPFILLMEM
 STA (203),Y
 INY 
 BNE :NOHI?1
 INC 204
:NOHI?1
 CPX #0 ;SEE IF DEC HI
 BNE :FIXLOW
 DEC 206 ;DEC HI COUNT
 BEQ :TERMFM ;BYTES=0 SO EXIT
:FIXLOW
 DEX  ;DEC LOW
 JMP :LPFILLMEM ;LOOP BACK
:TERMFM
 RTS  ;DONE
;
*********XZEROMEM***************
*WILL FILL 205/206 BYTES OF MEM*
*AT LOCATION POINTED TO BY     *
*203/204 WITH ZEROS            *
********************************
;
XZEROMEM
 LDA #0
 BEQ XFILLMEM
;
;
;++++++++++++++++++++++++++
;+ MEMORY CONTRACT ROUTINE+
;++++++++++++++++++++++++++
;
*********XCONTRACT**************
*WILL MOVE MEMORY FROM A HIGHER*
*ADDRESS TO A LOWER ADDRESS OR *
*EITHER WAY IF AREAS DO NOT    *
*OVERLAP.  MOVES FROM 203/204  *
*TO 205/206  A/X BYTES         *
********************************
;
XCONTRACT
 STA 207
 STX 208
CONT@LOOP
 LDY #0
 LDA 208
 BEQ :LASTPART@@
:LP1@CN
 LDA (203),Y
 STA (205),Y
 INY 
 BNE :LP1@CN
 INC 204
 INC 206
 DEC 208
 BNE :LP1@CN
:LASTPART@@
 LDX 207
 BEQ :NOLO@@
:LP2@CN
 LDA (203),Y
 STA (205),Y
 INY 
 DEX 
 BNE :LP2@CN
:NOLO@@
 RTS 
;+++++++++++++++++++++++++
;+ MEMORY EXPAND ROUTINE +
;+++++++++++++++++++++++++
;
**********XEXPAND***************
*WILL MOVE MEMORY FROM A LOWER *
*ADDRESS TO A HIGHER ADDRESS OR*
*EITHER WAY IF AREAS DO NOT    *
*OVERLAP.  MOVES FROM 203/204  *
*TO 205/206  A/X BYTES         *
********************************
;
XEXPAND
 STA 207 ;BYTES
 STX 208
 CLC 
 LDA 203 ;FIND END OF SOURC
 ADC 207
 STA 203
 LDA 204
 ADC 208
 STA 204
 CLC 
 LDA 205 ;FIND END OF DEST
 ADC 207
 STA 205
 LDA 206
 ADC 208
 STA 206
 DEC 204
 DEC 206
 LDY #255
:LP28
 LDA 207
 ORA 208
 BEQ :TERMEXPAND
 LDA (203),Y
 STA (205),Y
 LDA 207
 BNE :A29
 DEC 208
:A29 DEC 207
 DEY 
 CPY #255
 BNE :LP28
 DEC 204
 DEC 206
 JMP :LP28
:TERMEXPAND RTS 
;
;++++++++++++++++++++++++++++
;+ XMOVEMEM CALLS EXPAND OR +
;+ CONTRACT DEPENDING ON S/D+
;++++++++++++++++++++++++++++
;
;
*********XMOVEMEM***************
*WILL MOVE MEMORY FROM ANY     *
*ADDRESS TO ANOTHER ADDRESS.   *
*AUTO CALLS EXPAND OR CONTRACT *
*MOVES FROM 203/204 TO 205/206 *
*MOVES A/X BYTES               *
********************************
;
XMOVEMEM TAY  ;SAVE A REG
 SEC 
 LDA 205
 SBC 203
 LDA 206
 SBC 204
 PHP  ;SAVE STATUS REG
 TYA  ;RESTORE A REG
 PLP  ;REDTORE STATUS
 BCC XCONTRACT ;IF CLEAR DEST
;              IS SMALLER
 BCS XEXPAND
;END OF MOVEMEM

:SKIP


