antoine-source/appleworksgs/WP/Src/memory.aii

1 line
9.1 KiB
Plaintext
Raw Normal View History

2023-03-04 02:45:20 +00:00
***************************************************************************************************** ; Memory.aii ; ; This file contains the routines that are called when WP is running low on memory. Currently two ; routines exist to free up memory: ; ; W_CollapseRulers - Compare all of the rulers and get rid of any duplicates. ; W_ShrinkTextBlocks - Shrink text blocks to fit the text in them. ; ***************************************************************************************************** load 'macros.dump' include 'driver.equ' include 'wp.equ' import D_Deref import D_BeachBall import W_SwitchData import W_View import W_Pptr import W_LastP import W_UseRuler import W_UnUseRuler import W_CurrentBlockHandle import W_CurrentBlockHandle2 import W_DocLocked import W_PHandle import W_StartRuler entry W_LockArrays entry W_UnlockArrays entry W_CompareRulers ***************************************************************************************************** ; W_CollapseRulers ( ) ; ; This routine will scan all the rulers in the current WP document and make sure that no duplicate ; rulers exist. For each document part ( body, header, and footer ) call the routine to collapse the ; rulers, then restore the original document view. W_CollapseRulers PROC EXPORT local SPtr:l,ParPtr:l,RulerHand:l,RulerPtr:l local TestHand:l,SPars:w,DPtr:l,DPars:w,CurView:w begin moveword W_View,curview call W_SwitchData,in=(#W_NormalOn:w) jsr DoCollapse call W_SwitchData,in=(#W_HeaderOn:w) jsr DoCollapse call W_SwitchData,in=(#W_FooterOn:w) jsr DoCollapse call W_SwitchData,in=(CurView:w) return ;...................................................................................................; DoCollapse ; Get paragraph array pointer for current body part whose rulers are being collapsed. Set the ; paragraph count at the first paragraph. movelong W_Pptr,SPtr moveword #1,SPars ; Get first ruler in document (skip page breaks which don't have rulers). findloop cmpw [SPtr]:#W_pAttr,#W_PgBrk bne foundrule addwl #W_pBytes,SPtr inc Spars cmpw W_LastP,Spars bge findloop bra goexit ; Get the ruler for the first paragraph. If ruler count is same as total number of paragraphs then ; nothing exists to be collapsed - exit. foundrule movelong [SPtr]:#W_pRulerHand,RulerHand movelong [RulerHand],RulerPtr cmpw W_LastP,[RulerPtr] bne markit goexit brl exit ; Mark this ruler by setting the high bit of the handle. Start comparison with ruler for second ; paragraph. Point DPtr to second paragraph in paragraph array. markit jsr MarkRuler addword Spars,#1,Dpars addlong Sptr,#W_pBytes,Dptr ; For each unmarked ruler repeatedly get the next ruler. Compare it with the current one. If it ; is the same then use the old ruler instead and unuse the new one. rulerloop jsl D_BeachBall cmpw W_LastP,Dpars jlt nextruler ; Get next test handle. ( skip over any page breaks ). cmpw [DPtr]:#W_pAttr,#W_PgBrk beq nexttest ; Get handle for current paragraph. If high bit set then ruler has already been collapsed so go to ; next handle to compare. If same handle then simply mark it. ldy #W_pRulerHand+2 lda [DPtr],y bmi nexttest sta TestHand+2 moveword [DPtr]:#W_pRulerHand,TestHand cmpl TestHand,RulerHand bne notsamehand jsr MarkTest bra nexttest ; Different ruler was found; now we will need to determine whether they are actually equivalent. notsamehand call W_CompareRulers,in=(RulerHand:l,TestHand:l) bcs nexttest ; Check if TestRuler was the current visable ruler if so we will need to update W_StartRuler. cmpl TestHand,W_StartRuler bne replaceit movelong RulerHand,W_StartRuler ; Replace test ruler with source ruler. Mark test ruler so we won't look at it again. replaceit call W_UseRuler,in=(#1:w,RulerHand:l) call W_UnUseRuler,in=(#1:w,TestHand:l) movelong Rulerhand,[DPtr]:#W_pRulerHand jsr MarkTest ; Get the next unmarked ruler. nexttest inc Dpars addwl #W_pBytes,Dptr brl rulerloop ; Scan for next ruler to be collapsed. Bump to next ruler and check if past last paragraph