LOAD 'Macros.dump' INCLUDE 'SS.equ' INCLUDE 'Driver.equ' INCLUDE 'Heap.aii.i' INCLUDE 'Eval.aii.i' ;----------------------------------------------- ; ; Imported addresses ; ;----------------------------------------------- IMPORT D_AlertBox IMPORT D_BeachBall IMPORT D_DisableMItems IMPORT D_EnableMItems IMPORT D_FastMult IMPORT D_GetRefCon IMPORT D_GrowHandle IMPORT D_NeedHandle IMPORT D_NewCtl IMPORT D_SetCursor IMPORT D_SetFileChanged IMPORT X_FormatValue IMPORT S_ActivateScrlBars IMPORT S_ActiveWindow IMPORT S_AdjustTitleOffset IMPORT S_AworksMemError IMPORT S_BSRect IMPORT S_BScrollTemp IMPORT S_BuildColWdUndo IMPORT S_CalcAutoStr IMPORT S_ColLabRect IMPORT S_CurBRMost IMPORT S_CurBRSelect IMPORT S_CurBRTitle IMPORT S_CurBScrl IMPORT S_CurChangedList IMPORT S_CurChartCount IMPORT S_CurChartList IMPORT S_CurColumnWds IMPORT S_CurContHt IMPORT S_CurContRect IMPORT S_CurContWd IMPORT S_CurContXpt IMPORT S_CurContYpt IMPORT S_CurCopySize IMPORT S_CurDefColWd IMPORT S_CurDefFormat IMPORT S_CurEditFlag IMPORT S_CurFormat IMPORT S_CurGrow IMPORT S_CurHeap IMPORT S_CurLEHandle IMPORT S_CurMaxTLCell IMPORT S_CurRScrl IMPORT S_CurRowBlock IMPORT S_CurSheet IMPORT S_CurSheetInfo IMPORT S_CurTLCell IMPORT S_CurTLSelect IMPORT S_CurTLTitle IMPORT S_CurTwiceVertLines IMPORT S_CurVPageSize IMPORT S_CurVertLineHandSize IMPORT S_CurVertLines IMPORT S_CurWindow IMPORT S_GetCellPtr IMPORT S_GetCellTableEntry IMPORT S_GrowRect IMPORT S_GrowTemp IMPORT S_InsertLeftPadCells IMPORT S_InsertRightPadCells IMPORT S_LEDestRect IMPORT S_LEViewRect IMPORT S_NormalizeRange IMPORT S_RSRect IMPORT S_RSViewSize IMPORT S_RScrollTemp IMPORT S_RemovePadCells IMPORT S_ResetCircularBits IMPORT S_RowLabRect IMPORT S_ScrlUpdate IMPORT S_SetUndoOff IMPORT S_SheetSize IMPORT S_ViewDataStr ;----------------------------------------------- ; ; Forward addresses and entries ; ;----------------------------------------------- ENTRY S_FixPadCells ENTRY S_QTraverse ENTRY S_SetCellWidth ENTRY S_SwapOut ENTRY S_WhereCell ;--------------------------------------------------------------------------- ; S_CellWidth( Col:w ): Width:w ; ; This routine gets the width of a given cell in the current sheet. S_CellWidth PROC EXPORT ;Using S_CurrentData input Col:w output Width:w local WdArray:l error DefaultFlag BEGIN stz DefaultFlag lda S_CurColumnWds ora S_CurColumnWds+2 beq getDefault H_GetBlockPtr S_CurColumnWds,WdArray ldy Col lda [WdArray],y and #$00FF beq getDefault asl a asl a sta Width bra Exit getDefault MoveWord S_CurDefColWd,Width inc DefaultFlag Exit RETURN ENDP ;-------------------------------------------------------------------------- ; ; S_ChangeColWidth PROC EXPORT input Col:w,NewWidth:w local OldWidth:w error ErrFlag BEGIN stz ErrFlag Call S_BuildColWdUndo,in=(Col:w),err=ErrFlag bcs Exit Call S_CellWidth,in=(Col:w),out=(OldWidth:w) Call S_SetCellWidth,in=(Col:w,NewWidth:w),err=ErrFlag bcs Exit CmpWord OldWidth,NewWidth beq Exit Call S_AdjustTitleOffset in Col:w,#1:w,Col:w,#9999:w,#S_FixPadCells:l XCall S_QTraverse,err=ErrFlag Exit RETURN ENDP ;--------------------------------------------------------------------------- ; ; S_ChangeDef PROC EXPORT input Cell:l error ErrorFlag BEGIN stz ErrorFlag Call S_CellWidth,in=(Cell+2:w),out=(a:w) bcc Exit in Cell+2:w,#1:w,Cell+2:w,#9999:w,#S_FixPadCells:l XCall S_QTraverse,err=ErrorFlag Exit RETURN ENDP ;----------------------------------------------------------------------------- ; S_ColLab2Text ( Cell:a ) Text:a ; ; Input, an internal column number, is passed in the a-register, ; and output, a text form of the corsponding column, is returned in ; the a-register. S_ColLab2Text PROC EXPORT BEGIN dec a Tool _UDivide,in=(a:w,#26:w),out=(:w,:w) pla ; quotient beq OneChar xba ora 1,s ; remainder inc a xba ora #$4040 plx ; remainder bra Exit OneChar pla ; remainder inc a xba ora #$4020 Exit RETURN ENDP ;------------------------------------------------------------------------- ; S_CopyIn ; S_CopyIn PROC EXPORT ;Using S_CurrentData input DestPtr:l BEGIN in #S_CurWindow:l,DestPtr:l,#S_CurCopySize:l XTool _BlockMove RETURN ENDP ;------------------------------------------------------------------------- ; S_CopyOut ; S_CopyOut PROC EXPORT ;Using S_CurrentData input SrcPtr:l BEGIN in SrcPtr:l,#S_CurWindow:l,#S_CurCopySize:l XTool _BlockMove RETURN ENDP ;------------------------------------------------------------------------- ; S_FindRect ; S_FindRect PROC EXPORT ;Using S_CurrentData output TLCell:l,BRCell:l,Rect:r BEGIN PushLong TLCell PushLong BRCell Call S_NormalizeRange PullLong BRCell PullLong TLCell in TLCell:l out :w,:w,:w,:w XCall S_WhereCell pla bne OK1 lda S_CurContYpt OK1 sta Rect chk2 pla bne OK2 lda S_CurContXpt OK2 sta Rect+2 cont pla pla in BRCell:l out Rect+4:l,a:w,a:w XCall S_WhereCell RETURN ENDP ;----------------------------------------------------------------------------- ; ; S_FixPadCells PROC EXPORT input Cell:l,CellIndex:l error ErrFlag BEGIN stz ErrFlag ; I believe we could do some checks to see if all this is ; necessary. in Cell:l out ax:l,ax:l XCall S_RemovePadCells,err=ErrFlag bcs Exit in Cell:l out ax:l XCall S_InsertLeftPadCells,err=ErrFlag bcs Exit in Cell:l out ax:l XCall S_InsertRightPadCells,err=ErrFlag Exit RETURN ENDP ;------------------------------------------------------------------------- ; ; S_InitState PROC EXPORT ;Using S_CurrentData error ErrorFlag BEGIN H_NewHeap S_CurHeap,err=ErrorFlag jcs Exit ; Initialize all of the sheet fields ; MoveWord #1,S_CurTLCell MoveWord a,S_CurTLSelect MoveWord a,S_CurBRSelect MoveWord a,S_CurBRMost MoveWord a,S_CurTLCell+2 MoveWord a,S_CurTLSelect+2 MoveWord a,S_CurBRSelect+2 MoveWord a,S_CurBRMost+2 MoveWord #9988,S_CurMaxTLCell ; TLRow = 9989 MoveWord #$2B9,S_CurMaxTLCell+2 ; TLCol = ZU MoveWord #S_EditHeight+S_ColLabelHeight,S_CurContYPt MoveWord #S_NumLabelWidth,S_CurContXPt lda #0 MoveWord a,S_CurTLTitle MoveWord a,S_CurTLTitle+2 MoveWord a,S_CurBRTitle MoveWord a,S_CurBRTitle+2 MoveWord a,S_CurRowBlock MoveWord a,S_CurRowBlock+2 MoveWord a,S_CurChartCount MoveWord a,S_CurChartList MoveWord a,S_CurChartList+2 MoveWord a,S_CurChangedList MoveWord a,S_CurChangedList+2 MoveWord a,S_CurColumnWds MoveWord a,S_CurColumnWds+2 MoveWord a,S_CurEditFlag MoveWord #S_DefaultColWd,S_CurDefColWd MoveLong #S_DefDefFormat,S_CurDefFormat ; MoveWord #S_DefDefFormat,S_CurDefFormat ; MoveWord #^S_DefDefFormat,S_CurDefFormat+2 MoveWord S_CurContYpt,S_RowLabRect MoveWord S_CurContXpt,S_ColLabRect+2 Exit RETURN ENDP ;---------------------------------------------------------------------------- ; S_InsertControls ; ; This routine calculates the size of the scroll bars to be made and inserts ; them into the window. This routine also set the sheet's content sizes. S_InsertControls PROC EXPORT ;Using S_CurrentData ;Using S_WindowData local Rect:r error ErrFlag BEGIN stz ErrFlag ; Set the control rects to the appropriate values ; also set the sheet's content sizes. Tool _GetPortRect,in=(!Rect:l) MoveWord #S_EditHeight+1,S_RSRect MoveWord #-2,S_BSRect+2 lda Rect+4 inc a sta S_BSRect+4 sta S_GrowRect+4 SubWord a,#S_GrowHeight+1,S_BSRect sta S_GrowRect sta S_CurContHt inc a sta S_RSRect+4 lda Rect+6 inc a inc a sta S_RSRect+6 sta S_GrowRect+6 SubWord a,#S_GrowWidth+1,S_RSRect+2 sta S_GrowRect+2 sta S_CurContWd inc a inc a sta S_BSRect+6 ; Determine the ViewSizes of the right scroll bar SpaceWord SpaceWord SubWord S_GrowRect,S_CurContYpt,s PushWord #S_RowHeight Tool _UDivide pla sta S_CurVPageSize inc a sta S_RSViewSize pla ; Create the controls in #S_RScrollTemp:l,S_CurWindow:l out S_CurRScrl:l XCall D_NewCtl in #S_BScrollTemp:l,S_CurWindow:l out S_CurBScrl:l XCall D_NewCtl in #S_GrowTemp:l,S_CurWindow:l out S_CurGrow:l XCall D_NewCtl MoveWord S_CurContHt,S_RowLabRect+4 MoveWord S_CurContWd,S_ColLabRect+6 RETURN ENDP ;-------------------------------------------------------------------------- ; ; S_IsCellCircular PROC EXPORT input Cell:l local CellPtr:l error ErrFlag BEGIN stz ErrFlag in Cell:l out CellPtr:l XCall S_GetCellPtr ora CellPtr beq Exit MoveWord [CellPtr]:#S_CellFormat+2,a and #S_CellCircular sta ErrFlag Exit RETURN ENDP ;--------------------------------------------------------------------------- ; ; S_LoadAWorksInfo PROC EXPORT ;Using S_CurrentData ;Using S_AttrData ;Using S_ErrorData input MesgHdl:l local Message:l,Pos:w,Col:w,UpdateRgn:l error ErrFlag BEGIN stz ErrFlag MoveLong [MesgHdl],Message MoveWord [Message]:#16,a bne recalcSet lda S_CurEditFlag ora #S_ManCalcBit sta S_CurEditFlag Tool _SetMItemName,in=(#S_CalcAutoStr:l,#S_CalculateItem:w) Call D_EnableMItems,in=(#S_RecalcMI:w,#5:w) recalcSet MoveWord [Message]:#18,a beq showSet lda S_CurEditFlag ora #S_ViewFormulaBit sta S_CurEditFlag Tool _SetMItemName,in=(#S_ViewDataStr:l,#S_ViewItem:w) showSet MoveLong [Message]:#20,S_CurDefFormat ; Set the column widths ; MoveWord #24-2,Pos MoveWord #1-1,Col loop MoveLong [MesgHdl],Message inc Pos inc Pos lda Col inc a cmp #128 bge done sta Col MoveWord [Message]:Pos,a cmp #S_MinCellWidth blt setMin cmp #S_MaxCellWidth blt setWidth lda #S_MaxCellWidth bra setWidth setMin lda #S_MinCellWidth setWidth tax Call S_ChangeColWidth,in=(Col:w,x:w),err=ErrFlag bcs memError Call D_BeachBall bra loop memError Call D_SetCursor,in=(#ArrowCursor:w) Call D_AlertBox,in=(#OKBox:w,#S_AworksMemError:l),out=(a:w) done MoveLong [MesgHdl],Message MoveWord [Message]:#8,S_CurTLTitle MoveWord [Message]:#10,S_CurBRTitle MoveWord [Message]:#12,S_CurTLTitle+2 MoveWord [Message]:#14,S_CurBRTitle+2 Call S_AdjustTitleOffset Call S_ActivateScrlBars Tool _NewRgn,out=(UpdateRgn:l) Tool _RectRgn,in=(UpdateRgn:l,#S_CurContRect:l) Tool _EraseRect,in=(#S_CurContRect:l) Call S_ScrlUpdate,in=(UpdateRgn:l) Tool _DisposeRgn,in=(UpdateRgn:l) ; MoveLong [MesgHdl],Message ; MoveLong [Message],S_CurTLCell Call D_SetFileChanged,in=(S_CurWindow:l) RETURN ENDP ;----------------------------------------------------------------------------- ; S_NewSheet() ; ; At the moment this routine does nothing more than allocate the required ; space for a New spreadsheet, and then lock it down. S_NewSheet PROC EXPORT ;Using S_CurrentData error ErrorFlag BEGIN stz ErrorFlag in #S_SheetSize:l,#0:w out S_CurSheet:l XCall D_NeedHandle,err=ErrorFlag jcs Exit in #S_LEDestRect:l,#S_LEViewRect:l,#255:w out S_CurLEHandle:l XTool _LENew,err=ErrorFlag bcc Exit Exit2 Tool _DisposeHandle,in=(S_CurSheet:l) Exit RETURN ENDP ;--------------------------------------------------------------------------- ; S_QRTraverseTable (TLCell:l,BRCell:l,Routine:l) ; ; This routine traverses the range in the reverse order of QTraverseTable. ; The last cell of the last row is operated on first, and so on. The TraverseTable ; routines will invoke calls on any entry in the CellTable, while the QTraverse ; routine only calls real cells. TraverseRange invokes calls on all cells in the ; range. S_QRTraverseTable PROC EXPORT ;Using S_CurrentData input FCol:w,FRow:w,LCol:w,LRow:w,Routine:l local CurCol:w,RowIndex:l,RowPtr:l local ColOffset:w,ColIndex:l local RowBlock:l,RowBlockPtr:l,RowOffset:w error ErrorFlag BEGIN +b stz ErrorFlag lda #Callit+1 MoveWord RoutinePtr+1,>Callit+2 Call D_BeachBall PushWord FCol PushWord FRow Callit jsl * sta ErrorFlag bcs Exit CmpWord FCol,LCol blt loop1 CmpWord FRow,LRow blt loop2 Exit RETURN ENDP ;----------------------------------------------------------------------------- ; S_WhereCell ; S_WhereCell PROC EXPORT ;Using S_CurrentData input Cell:l output Rect:r local Temp:l BEGIN stz Rect stz Rect+2 stz Rect+4 stz Rect+6 MoveLong S_CurTLCell,Temp CmpWord Cell+2,S_CurTLCell+2 ; compare the columns blt CalcY MoveWord S_CurContXpt,Rect+2 loop CmpWord Temp+2,Cell+2 beq gotX Call S_CellWidth,in=(Temp+2:w),out=(a:w) inc Temp+2 AddWord a,Rect+2,Rect+2 cmp S_CurContWd bge OffRight bra loop gotX Call S_CellWidth,in=(Cell+2:w),out=(a:w) AddWord a,Rect+2,Rect+6 bra CalcY OffRight MoveWord S_CurContWd,Rect+2 sta Rect+6 CalcY SubWord Cell,Temp,a ; compare the rows blt Exit tax ldy #S_RowHeight Call D_FastMult sta Temp AddWord a,S_CurContYpt,Rect AddWord a,#S_RowHeight,Rect+4 CmpWord S_CurContHt,Rect bge Exit OffBottom sta Rect sta Rect+4 Exit RETURN ENDP ;----------------------------------------------------------------------------- ; S_WhichCell(Xin:w,Yin:w): Cell:l,Xout:w,Yout:w ; ; This routine determines which cell a given point is in. It also returns ; the point found in the upper left corner of the cell. S_WhichCell PROC EXPORT ;Using S_CurrentData input Xin:w,Yin:w output Cell:l,Xout:w,Yout:w BEGIN ; Start with the TLCell ; MoveWord S_CurContXpt,Xout MoveWord S_CurContYpt,Yout MoveLong S_CurTLCell,Cell ; Determine which column the point is in. ; bra start1 loop1 sta Xout inc Cell+2 start1 Call S_CellWidth,in=(Cell+2:w),out=(a:w) AddWord a,Xout,a cmp Xin bge done1 ldy Cell+2 cpy #$02BF blt loop1 done1 ; Determine which row the point is in. ; ldy Cell bra start2 loop2 sta Yout iny start2 AddWord #S_RowHeight,Yout,a cmp Yin bge done2 cpy #10000 blt loop2 done2 sty Cell RETURN ENDP END