mirror of
https://github.com/antoinevignau/source.git
synced 2025-02-01 02:33:39 +00:00
1 line
16 KiB
Plaintext
1 line
16 KiB
Plaintext
|
LOAD 'Macros.dump'
INCLUDE 'SS.equ'
INCLUDE 'Driver.equ'
INCLUDE 'Heap.aii.i'
;-----------------------------------------------
;
; Imported addresses
;
;-----------------------------------------------
IMPORT D_AlertBox
IMPORT D_CmpStrings
IMPORT D_MemoryError
IMPORT D_NeedHand
IMPORT D_Sort
IMPORT S_ActiveWindow
IMPORT S_BuildSortUndo
IMPORT S_CalculateSheet
IMPORT S_CurBRMost
IMPORT S_CurBRSelect
IMPORT S_CurEditFlag
IMPORT S_CurRowBlock
IMPORT S_CurTLSelect
IMPORT S_DeltaMove
IMPORT S_DoSortDlog
IMPORT S_GetCellIndex
IMPORT S_InvalidCellStr
IMPORT S_MoveDestBR
IMPORT S_MoveDestTL
IMPORT S_MoveSrcBR
IMPORT S_MoveSrcTL
IMPORT S_RedrawCellRange
IMPORT S_SetBRMostCell
IMPORT S_SetUndoOn
IMPORT S_StartSortUndo
IMPORT S_SwapCell
IMPORT S_SwapIn
;-----------------------------------------------
;
; Forward addresses and entries
;
;-----------------------------------------------
ENTRY S_DoColSort
ENTRY S_DoRowSort
ENTRY S_SortCompare
ENTRY S_SwapColumns
ENTRY S_SwapRows
;-------------------------------------------------------------------------
;
;
S_SortData PROC EXPORT
EXPORT S_SortAscendDescendFlag
S_SortAscendDescendFlag DS.B 2
ENDP
;--------------------------------------------------------------------------
;
;
S_Sort PROC EXPORT
;Using S_CurrentData
;Using S_SortData
;Using S_MoveData
;Using S_ErrorData
local KeyCell:l,Type:w
error ErrFlag
BEGIN +b
Call S_SwapIn,in=(S_ActiveWindow:l)
; ascend: 0==decending,1==ascending
; rowcol: 0==col by row,1==row by col
; cell: 0 == Cancelled, 0 w/carry set == error
in S_CurTLSelect:l
out S_SortAscendDescendFlag:w,Type:w,KeyCell:l
XCall S_DoSortDlog
bcc doOK
Call D_AlertBox,in=(#OKBox:w,#S_InvalidCellStr:l),out=(a:w)
doOK
lda KeyCell
ora KeyCell+2
jeq Exit
lda S_CurEditFlag
and #S_BRMostBit
beq BRset
Call S_SetBRMostCell,in=(#0:w)
BRset
lda #S_BRMostBit
tsb S_CurEditFlag
MoveWord S_CurTLSelect,S_MoveDestTL
sta S_MoveSrcTL
MoveWord S_CurTLSelect+2,S_MoveDestTL+2
sta S_MoveSrcTL+2
MoveWord S_CurBRSelect,S_MoveDestBR
sta S_MoveSrcBR
MoveWord S_CurBRSelect+2,S_MoveDestBR+2
sta S_MoveSrcBR+2
lda Type
bne doRowSort
doColSort
ldx S_CurBRSelect+2
cpx S_CurBRMost+2
blt doCol2
ldx S_CurBRMost+2
doCol2
in S_CurTLSelect:l,x:w,S_CurBRSelect:w,KeyCell:w
XCall S_DoColSort,err=ErrFlag
bcc redraw
bra memError
doRowSort
ldx S_CurBRSelect
cpx S_CurBRMost
blt doRow2
ldx S_CurBRMost
doRow2
in S_CurTLSelect:l,S_CurBRSelect+2:w,x:w,KeyCell+2:w
XCall S_DoRowSort,err=ErrFlag
bcc redraw
memError
Call D_MemoryError
redraw
CmpWord S_MoveSrcBR+2,S_MoveDestBR+2
blt chkLeft
sta S_MoveDestBR+2
chkLeft
CmpWord S_MoveSrcTL+2,S_MoveDestTL+2
bge doDraw
sta S_MoveDestTL+2
doDraw
in S_MoveDestTL:l,S_MoveDestBR:l
XCall S_RedrawCellRange
Call S_SetUndoOn,in=(#S_UndoSortType:w)
lda S_CurEditFlag
and #S_ManCalcBit
bne Exit
Call S_CalculateSheet
Exit
RETURN
ENDP
;-----------------------------------------------------------------------------
;
;
S_DoRowSort PROC EXPORT
;Using S_CurrentData
input FCol:w,FRow:w,LCol:w,LRow:w,KeyCol:w
local ArrayHandle:l,ArrayPtr:l,ArraySize:w,Count:w
local ArrayOffset:w,TargOffset:w,CurRow:w,CellPtr:l
local TargRow:w,SrcRow:w
error ErrorFlag
BEGIN
stz ErrorFlag
SubWord LRow,FRow,a
inc a
sta Count
asl a
asl a
sta ArraySize
in #0:w,ArraySize:w
out ArrayHandle:l
XCall D_NeedHand,err=ErrorFlag
jcs Exit
; Set up the original array, filled with cell indices ;
MoveLong [ArrayHandle],ArrayPtr
MoveWord FRow,CurRow
stz ArrayOffset
bra startInit
initLoop
inc CurRow
AddWord ArrayOffset,#4,ArrayOffset
startInit
in KeyCol:w,CurRow:w
out [ArrayPtr]:ArrayOffset:l
XCall S_GetCellIndex
ldy ArrayOffset
ora [ArrayPtr],y
bne cmpInit
tya
|