This repository has been archived by the owner on Jan 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextEngine52.s
10766 lines (8519 loc) · 243 KB
/
TextEngine52.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
OPT c+, o-, l- ;Case sensitive, non-optimised, executable.
*****************************************************************************
* TextEngine V5.2 *
* GUI Generated by GadToolsBox by Jan van den Baard. *
* Code by Nicholas Harvey, © Copyright 2010. *
* Last changes made 02/09/2010. *
*****************************************************************************
*****************************************************************************
* Changes made to TextEngineGUI.s: *
* *
* 1. Added DC.L $80000093,1 to MainEditWindowWindowTags. *
* 2. Added DC.L $80080043,1 to MTags1. *
* 3. Added DC.L $80080006,0 to top of SpellCheckerGTags. *
*****************************************************************************
*****************************************************************************
* Exec library function offsets. *
*****************************************************************************
_SysBase EQU 4
OpenLib EQU -408
CloseLib EQU -414
AddTail EQU -246
RemTail EQU -264
WaitPort EQU -384
Wait EQU -318
FindTask EQU -294
CreateMsgPort EQU -666
DeleteMsgPort EQU -672
OpenDevice EQU -444
CloseDevice EQU -450
DoIO EQU -456
SendIO EQU -462
CheckIO EQU -468
AbortIO EQU -480
WaitIO EQU -474
AvailMem EQU -216
AllocMem EQU -198
FreeMem EQU -210
GetMsg EQU -372
ReplyMsg EQU -378
CurrentDir EQU -126
CreateIORequest EQU -654
DeleteIORequest EQU -660
MEMF_CLEAR EQU $00010000
MEMF_CHIP EQU $00000002
MEMF_FAST EQU $00000004
mp_SigBit EQU 15
mp_SigTask EQU 16
ln_Name EQU 10
ln_Type EQU 8
lib_Version EQU 20
*****************************************************************************
* DOS library function offsets. *
*****************************************************************************
MODE_OLDFILE EQU $000003ed
MODE_NEWFILE EQU $000003ee
Open EQU -30
Close EQU -36
Read EQU -42
Write EQU -48
NameFromLock EQU -402
Seek EQU -66
Delay EQU -198
Lock EQU -84
UnLock EQU -90
Examine EQU -102
SystemTagList EQU -606
CMD_READ EQU 2
CMD_WRITE EQU 3
CMD_UPDATE EQU 4
CMD_CLEAR EQU 5
wa_Lock EQU 0
wa_Name EQU 4
am_ArgList EQU 34
pr_CLI EQU 172
pr_MsgPort EQU 92
sm_ArgList EQU 36
sm_NumArgs EQU 28
fib_Size EQU 124
io_Offset EQU 44
io_Error EQU 31
io_ClipID EQU 48
io_Data EQU 40
io_Length EQU 36
io_Command EQU 28
io_Device EQU 20
io_Unit EQU 24
io_Actual EQU 32
*****************************************************************************
* ASL library function offsets. *
*****************************************************************************
AllocAslRequest EQU -48
FreeAslRequest EQU -54
AslRequest EQU -60
ASL_Hail EQU $80080001
ASL_OKText EQU $80080012
ASL_Pattern EQU $8008000a
ASL_FuncFlags EQU $80080014
ASL_Window EQU $80080002
FILF_PATGAD EQU $00000001
FILF_SAVE EQU $00000020
rf_File EQU 4
rf_Dir EQU 8
*****************************************************************************
* Graphics library function offsets. *
*****************************************************************************
RPort EQU 50
LinePtrn EQU 34
SetAPen EQU -342
SetBPen EQU -348
SetDrMd EQU -354
Move EQU -240
Draw EQU -246
*****************************************************************************
* GadTools library function offsets. *
*****************************************************************************
SpecialInfo EQU 34
LongInt EQU 28
Flags EQU 12
ItemFile EQU 18
GT_GetIMsg EQU -72
GT_ReplyIMsg EQU -78
GT_SetGadgetAttrsA EQU -42
Class EQU $14
Code EQU $18
GFLG_SELECTED EQU $00000080
*****************************************************************************
* Intuition library function offsets. *
*****************************************************************************
ActivateGadget EQU -462
ActivateWindow EQU -450
ItemAddress EQU -144
AddGList EQU -438
RemoveGList EQU -444
RefreshGList EQU -432
GetScreenDrawInfo EQU -690
FreeScreenDrawInfo EQU -696
SetGadgetAttrsA EQU -660
GetAttr EQU -654
SetAttrsA EQU -648
InitRequester EQU -138
Request EQU -240
EndRequest EQU -120
SetWindowTitles EQU -276
DisplayBeep EQU -96
EasyRequestArgs EQU -588
SetPointer EQU -270
ClearPointer EQU -60
SetWindowPointerA EQU -816
DrawImage EQU -114
UserPort EQU 86
RastPort EQU 50
IAddress EQU 28
GadgetID EQU 38
NextSelect EQU 32
Width EQU 8
Height EQU 10
BorderLeft EQU 54
BorderRight EQU 56
BorderTop EQU 55
BorderBottom EQU 57
MouseY EQU 12
MouseX EQU 14
ItemFill EQU 18
ITextFont EQU 8
IDCMP_NEWSIZE EQU $00000002
IDCMP_GADGETDOWN EQU $00000020
IDCMP_GADGETUP EQU $00000040
IDCMP_MENUPICK EQU $00000100
IDCMP_CLOSEWINDOW EQU $00000200
IDCMP_INTUITICS EQU $00400000
IDCMP_MOUSEBUTTONS EQU $00000008
IDCMP_MOUSEMOVE EQU $00000010
SELECTDOWN EQU $00000068
FirstItem EQU 18
CHECKED EQU $0100
WA_Left EQU $80000064
WA_Top EQU $80000065
WA_Width EQU $80000066
WA_Height EQU $80000067
WA_ScreenTitle EQU $8000006f
WA_Flags EQU $8000006b
WA_BusyPointer EQU $80000098
*****************************************************************************
* Workbench library function offsets. *
*****************************************************************************
AddAppWindow EQU -48
RemoveAppWindow EQU -54
*****************************************************************************
* Console device function offsets. *
*****************************************************************************
cu_TxHeight EQU 282
cu_TxWidth EQU 284
*****************************************************************************
* Offsets for text buffer structure. *
*****************************************************************************
tb_Next EQU 0
tb_Prev EQU 4
tb_LineLength EQU 8
tb_Text EQU 12
LineBlockLength EQU 253
*****************************************************************************
* Open the required Amiga libraries. *
*****************************************************************************
Begin: move.l a0,CommAdd
move.l d0,CommLen
move.l _SysBase,a6
move.l #0,a1
jsr FindTask(a6) ;Find the task.
move.l d0,Task
move.l Task,a4
tst.l pr_CLI(a4)
bne RunFromCLI ;Launched from the CLI.
lea pr_MsgPort(a4),a0
jsr WaitForPort ;Wait for WBMessage.
move.l _SysBase,a6
jsr GetMsg(a6)
move.l d0,WBMessage
RunFromCLI:
move.l #GadToolsName,a1
jsr OpenLibrary
move.l d0,_GadToolsBase
beq GadToolsFail ;Library not available.
move.l #IntuitionName,a1
jsr OpenLibrary
move.l d0,_IntuitionBase
beq IntuitionFail ;Library not available.
move.l #GfxName,a1
jsr OpenLibrary
move.l d0,_GfxBase
beq GfxFail ;Library not available.
move.l #UtilityName,a1
jsr OpenLibrary
move.l d0,_UtilityBase
beq UtilityFail ;Library not available.
move.l #ASLName,a1
jsr OpenLibrary
move.l d0,_ASLBase
beq ASLFail ;Library not available.
move.l #DOSName,a1
jsr OpenLibrary
move.l d0,_DOSBase
beq DOSFail ;Library not available.
move.l #WorkbenchName,a1
jsr OpenLibrary
move.l d0,_WorkbenchBase
beq WorkbenchFail ;Library not available.
move.l Task,a4
tst.l pr_CLI(a4)
bne RunFromCLI2 ;Launched from the CLI.
move.l WBMessage,a0
move.l sm_ArgList(a0),a0
move.l wa_Lock(a0),d1
move.l _DOSBase,a6
jsr CurrentDir(a6) ;Get workbench dir.
move.l d0,OldLock
RunFromCLI2:
jsr InitialiseTextBuffer ;Grab some memory.
cmp.l #0,FirstLinePtr
beq InitialiseTextBufferFail;Memory not avaiable.
jsr LoadPreferences ;Load user preferences file.
*****************************************************************************
* Open the display. *
*****************************************************************************
jsr SetupScreen
bne SetupScreenFail ;Screen not available.
jsr GetDrawInfo
jsr SizeMainEditWindow
jsr OpenMainEditWindowWindow
bne OpenMainEditWindowWindowFail ;Window not available.
jsr InitialiseLoadRequester
beq InitialiseLoadRequesterFail
jsr InitialiseInsertRequester
beq InitialiseInsertRequesterFail
jsr InitialiseSaveRequester
beq InitialiseSaveRequesterFail
jsr AdjustMenuItems
jsr OpenConsole
jsr MakeAppWindow
jsr GetWindowDimensions
jsr DrawBOOPSIGadgets
jsr DrawPrinterBorders
jsr DeterminePortIDs
;jsr WelcomeToTextEngine ;Display welcome picture.
*****************************************************************************
* Handle CLI and Workbench input arguments. *
*****************************************************************************
move.l Task,a4
tst.l pr_CLI(a4)
bne HandleCLIArgs ;Launched from the CLI.
move.l WBMessage,a0 ;Process event
cmp.l #1,sm_NumArgs(a0)
beq MainControlLoop ;No icons selected.
move.l sm_ArgList(a0),a0
add.l #8,a0 ;Get next argument.
move.l wa_Lock(a0),d1 ;Get file lock in d0.
cmp.l #0,d1
beq MainControlLoop ;Icon doesn't have a lock.
jsr BlockInput
move.l #0,imsg
move.l WBMessage,a5 ;Process event
move.l sm_ArgList(a5),a5
add.l #8,a5 ;Get next argument.
jmp AppWindowLoadFile
HandleCLIArgs:
move.l CommLen,d5
sub.l #1,d5
cmp.l #0,d5
ble MainControlLoop
sub.l #1,d5
cmp.l #300,d5
blo CLIArgShortEnough
move.l #299,d5
CLIArgShortEnough:
move.l CommAdd,a5
move.l #FileName,a6
CLIArgLoop:
cmp.b #$22,(a5)
beq CLIArgLoopAvoidSpeechMarks
move.b (a5),(a6)
add.l #1,a6
CLIArgLoopAvoidSpeechMarks:
add.l #1,a5
dbra d5,CLIArgLoop
jsr BlockInput
jmp OpenAppWindowFile
*****************************************************************************
* Load a file via the appwindow. *
*****************************************************************************
ProcessAppWindow:
move.l AppWindowPort,a0
move.l _SysBase,a6
jsr GetMsg(a6)
move.l d0,imsg
tst.l d0
beq MainControlLoop
move.l MainEditWindowWnd,a0
move.l _IntuitionBase,a6
jsr ActivateWindow(a6)
jsr BlockInput ;Block input to main edit window.
move.l imsg,a5 ;Process event
move.l am_ArgList(a5),a5
AppWindowLoadFile:
move.l wa_Lock(a5),d1 ;Get file lock in d1.
move.l #FileName,d2
move.l #300,d3
move.l _DOSBase,a6
jsr NameFromLock(a6)
move.l #300,d0
move.l #FileName,a0
AppWindowMakeFileName:
cmp.b #0,(a0)
beq AppWindowGotFilePath
sub.l #1,d0
add.l #1,a0
jmp AppWindowMakeFileName
AppWindowGotFilePath:
move.l wa_Name(a5),a1 ;Get file name in a1.
sub.l #1,d0
sub.l #1,a0
cmp.b #":",(a0)
bne AddAppWindowFileSlash
add.l #1,a0
AppWindowFinishFileName:
move.b (a1),(a0)
cmp.b #0,(a1)
beq AppWindowFinishedFileName
add.l #1,a0
add.l #1,a1
dbra d0,AppWindowFinishFileName
AppWindowFinishedFileName:
cmp.l #0,imsg
beq OpenAppWindowFile ;For WB startup use.
jsr ReplyExecMessage
jmp OpenAppWindowFile
AddAppWindowFileSlash:
add.l #1,a0
move.b #"/",(a0)+
jmp AppWindowFinishFileName
*****************************************************************************
* Close the display. *
*****************************************************************************
Quit: jsr RemoveBOOPSIObjects ;Remove BOOPSI objects.
jsr DestroyAppWindow
jsr CloseConsole ;Close console device.
jsr FreeSaveRequester ;Free save requester.
InitialiseSaveRequesterFail:
jsr FreeInsertRequester ;Free insert requester.
InitialiseInsertRequesterFail:
jsr FreeLoadRequester ;Free load requester
InitialiseLoadRequesterFail:
OpenMainEditWindowWindowFail:
jsr CloseMainEditWindowWindow ;Close window.
SetupScreenFail:
jsr CloseDownScreen ;Remove lock on screen.
*****************************************************************************
* Close the Amiga libraries. *
*****************************************************************************
move.l LastLinePtr,a1
jsr ReleaseTextBuffer ;Release text buffer memory.
InitialiseTextBufferFail:
move.l _WorkbenchBase,a1
jsr CloseLibrary
WorkbenchFail:
move.l _DOSBase,a1
jsr CloseLibrary
DOSFail:move.l _ASLBase,a1 ;Close ASL library.
jsr CloseLibrary
ASLFail:move.l _UtilityBase,a1
jsr CloseLibrary ;Close utility library.
UtilityFail:
move.l _GfxBase,a1
jsr CloseLibrary ;Close graphics library.
GfxFail:move.l _IntuitionBase,a1
jsr CloseLibrary ;Close intuition library.
IntuitionFail:
move.l _GadToolsBase,a1
jsr CloseLibrary ;Close gadtools library
GadToolsFail:
jsr FreeDictionary ;Release dictionay memory.
tst.l WBMessage
beq CLIQuit
move.l OldLock,d1
move.l _DOSBase,a6
jsr CurrentDir(a6)
move.l _SysBase,a6
jsr Forbid(a6)
move.l _SysBase,a6
move.l WBMessage,a1
jsr ReplyMsg(a6)
CLIQuit:move.l #0,d0
move.l #0,a0
rts ;**** End of program. ;End program execution.
*****************************************************************************
* Subroutines begin here. *
*****************************************************************************
*****************************************************************************
* Display welcome picture. *
*****************************************************************************
WelcomeToTextEngine:
jsr BlockInput
clr.l d0
clr.l d1
move.l Scr,a5
move.w 12(a5),d0 ;Width.
move.w 14(a5),d1 ;Height.
sub.l #316,d0
divu #2,d0
clr.l d5
move.w d0,d5
move.l d5,WelcomeLeft+4
sub.l #142,d1
divu #2,d1
clr.l d5
move.w d1,d5
move.l d5,WelcomeTop+4
move.l _IntuitionBase,a6
move.l #0,a0
move.l #WelcomeWindowTagList,a1
jsr OpenWindowTagList(a6)
move.l d0,WelcomeWindowWnd
beq WelcomeFail ;Window not open.
move.l #WelcomeImage4,a1
move.l WBDrawInfo1,a5
clr.l d5
move.w 12(a5),d5 ;Get screen depth.
cmp.w #2,d5
ble Draw4ColourPicture ;Screen depth <=2 planes.
move.l #WelcomeImage8,a1 ;Screen depth >=3 planes.
Draw4ColourPicture:
clr.l d0
clr.l d1
move.l _IntuitionBase,a6
move.l WelcomeWindowWnd,a0
move.l RastPort(a0),a0
jsr DrawImage(a6)
move.l _DOSBase,a6
move.l #100,d1 ;Wait for 2 seconds.
jsr Delay(a6)
move.l _IntuitionBase,a6
move.l WelcomeWindowWnd,a0
jsr CloseWindow(a6) ;Close the window.
WelcomeFail:
jsr UnBlockInput
rts
*****************************************************************************
* Size the main edit window to the screen resolution. *
*****************************************************************************
SizeMainEditWindow:
move.l Scr,a5
move.l #MainEditWindowWindowTags,a6
move.w 12(a5),92(a6)
move.w 14(a5),100(a6)
move.w OffY,d5
move.w OffX,d6
move.w #0,MainEditWindowLeft
move.w d5,MainEditWindowTop
move.w 12(a5),MainEditWindowWidth
;sub.w d6,MainEditWindowWidth
;sub.w d6,MainEditWindowWidth
move.w 14(a5),MainEditWindowHeight
sub.w #2,MainEditWindowHeight
sub.w d5,MainEditWindowHeight
sub.w d5,MainEditWindowHeight
rts
*****************************************************************************
* Subroutines to block and unblock input to main edit window. *
*****************************************************************************
BlockInput:
jsr SleepPointer
move.l _IntuitionBase,a6
move.l #BlockingRequester,a0
jsr InitRequester(a6) ;Initialise requester.
move.l _IntuitionBase,a6
move.l #BlockingRequester,a0
move.l MainEditWindowWnd,a1
jsr Request(a6) ;Open the requester.
rts
UnBlockInput:
move.l _IntuitionBase,a6
move.l #BlockingRequester,a0
move.l MainEditWindowWnd,a1
jsr EndRequest(a6) ;Close the requester.
jsr WakePointer
rts
*****************************************************************************
* Subroutines to block and unblock input to spell checker window. *
*****************************************************************************
BlockSpellInput:
move.l _IntuitionBase,a6
move.l #SpellBlockingRequester,a0
jsr InitRequester(a6) ;Initialise requester.
move.l _IntuitionBase,a6
move.l #SpellBlockingRequester,a0
move.l SpellCheckerWnd,a1
jsr Request(a6) ;Open the requester.
move.l _IntuitionBase,a0
move.w lib_Version(a0),d0 ;Get intuition version.
cmp.w #39,d0
blo OldBlockSpellInput ;Have to use lores pointer.
move.l #PointerSwitch,a0 ;Use prefs sleepy pointer.
move.l #-1,(a0)
move.l SpellCheckerWnd,a0
move.l #PointerTags,a1
move.l _IntuitionBase,a6
jsr SetWindowPointerA(a6)
rts
OldBlockSpellInput:
move.l SpellCheckerWnd,a0
move.l #SleepPointerImage,a1
move.l #16,d0
move.l #16,d1
move.l #-6,d2
move.l #0,d3
move.l _IntuitionBase,a6
jsr SetPointer(a6)
rts
UnBlockSpellInput:
move.l _IntuitionBase,a6
move.l #SpellBlockingRequester,a0
move.l SpellCheckerWnd,a1
jsr EndRequest(a6) ;Close the requester.
move.l _IntuitionBase,a0
move.w lib_Version(a0),d0 ;Get intuition version.
cmp.w #39,d0
blo OldUnBlockSpellInput ;Have to use lores pointer.
move.l #PointerSwitch,a0 ;Use prefs sleepy pointer.
move.l #0,(a0)
move.l SpellCheckerWnd,a0
move.l #PointerTags,a1
move.l _IntuitionBase,a6
jsr SetWindowPointerA(a6)
rts
OldUnBlockSpellInput:
move.l SpellCheckerWnd,a0
move.l _IntuitionBase,a6
jsr ClearPointer(a6)
rts
*****************************************************************************
* Subroutine to refresh text and bevel boxes in window. *
*****************************************************************************
RefreshWindowContents:
move.w #0,TextBlockMarked
jsr CloseConsole ;Re-size the
jsr OpenConsole ; console window.
jsr GetWindowDimensions ;Get new window size.
jsr UpdateBOOPSIGadgets ;Adjust slider gadgets.
jsr HideCursor
jsr DisplayVisibleText
jsr ResetCursor ;Place cursor in
move.w #0,MouseXCoord
move.w #0,MouseYCoord
move.l a5,CurrentLinePtr
move.l CurrentHorizTop,CurrentLineOffset
move.l tb_LineLength(a5),d6
cmp.l CurrentHorizTop,d6
bge RefreshWindowContentsCont
move.l d6,CurrentLineOffset
RefreshWindowContentsCont:
jsr ShowCursor
jmp ProcessMainWindowEvent
*****************************************************************************
* Load preferences file from disk. *
*****************************************************************************
LoadPreferences:
move.l #MODE_OLDFILE,d2
move.l #PreferencesFileName,d1
jsr OpenFile
move.l d0,TextFileHd
beq SetDefaultPrefs
move.l #Preferences,d2 ;Buffer for file contents
move.l #2875,d3 ;Length of read
move.l TextFileHd,d1
jsr ReadFile
move.l TextFileHd,d1
jsr CloseFile
SetDefaultPrefs:
;Spell checker string pointers:
move.l #SpellCheckerGTags,a0
move.l #SpellReplaceString,32(a0)
move.l #SpellUnknownString,52(a0)
;Find & replace string pointers.
move.l #FindTextGTags,a0
move.l #ReplaceTextString,12(a0)
move.l #FindTextString,FindTextStringPtr
move.l FindTextStringPtr,32(a0)
;Printer prefs defaults.
move.l #PrinterPrefsGTags,a0
move.l PrinterTopMargin,48(a0) ;Top margin = 0.
move.l PrinterBottomMargin,68(a0) ;Bottom margin = 0.
move.l PrinterPageHeight,88(a0) ;Page length = 70.
move.l PrinterLeftMargin,108(a0) ;Left margin = 5.
move.l PrinterRightMargin,128(a0) ;Right margin = 5.
move.l PrinterPageWidth,148(a0) ;Page width = 80.
move.l #PrintToString,168(a0) ;'Print to' string pointer.
move.l DraftPrintMode,12(a0) ;Draft print on.
move.l PropPrintMode,24(a0) ;Proportional off.
move.l DSPrintMode,36(a0) ;Double space off.
move.l NumOfCopies,188(a0) ;Num of copies.
;Function keys defaults.
move.l #FunctionKeysGTags,a0
move.l #F1String,12(a0)
move.l #F2String,32(a0)
move.l #F3String,52(a0)
move.l #F4String,72(a0)
move.l #F5String,92(a0)
move.l #F6String,112(a0)
move.l #F7String,132(a0)
move.l #F8String,152(a0)
move.l #F9String,172(a0)
move.l #F10String,192(a0)
;Colour prefs defaults.
move.l #InitConsoleText,a5 ;Change console colours.
add.l #4,a5 ;Text colour
move.w TextColour,d5
add.b #$30,d5
move.b d5,(a5) ;Insert text colour.
add.l #3,a5
move.w FieldColour,d5
add.b #$30,d5
move.b d5,(a5) ;Insert field colour.
add.l #3,a5
move.w FieldColour,d5
add.b #$30,d5
move.b d5,(a5) ;Insert field colour.
rts
*****************************************************************************
* Make menus reflect preferences. *
*****************************************************************************
AdjustMenuItems:
move.l _IntuitionBase,a6
move.l MainEditWindowWnd,a0
jsr ClearMenuStrip(a6) ;Clear menus.
move.l MainEditWindowMenus,a0 ;Address of first menu.
move.l (a0),a0 ;Address of second menu.
move.l (a0),a0 ;Address of third menu.
move.l (a0),a0 ;Address of fourth menu.
move.l (a0),a0 ;Address of fifth menu.
move.l (a0),a0 ;Address of sixth menu.
move.l (a0),a0 ;Address of seventh menu.
move.l FirstItem(a0),a0 ;Address of Word Wrap item.
move.w WordWrapMode,d0
move.w #%1111111011111111,d1
and.w d1,Flags(a0)
or.w d0,Flags(a0)
move.l (a0),a0 ;Get second menu item.
move.w ShowBordersMode,d0
move.w #%1111111011111111,d1
and.w d1,Flags(a0)
or.w d0,Flags(a0)
move.l Scr,a0
move.l 40(a0),a0 ;Get pointer to font (TextAttr structure).
move.l (a0),BoldFont ;Store font name.
move.l (a0),ItalicFont ;Store font name.
move.l (a0),UnderlineFont ;Store font size.
move.w 4(a0),BoldFont+4 ;Store font size.
move.w 4(a0),ItalicFont+4 ;Store font size.
move.w 4(a0),UnderlineFont+4 ;Store font size..
move.l MainEditWindowMenus,a0 ;Address of first menu.
move.l (a0),a0 ;Address of second menu.
move.l (a0),a0 ;Address of third menu.
move.l FirstItem(a0),a0 ;Address of Bold item.
move.l (a0),a1 ;Address of Italic item.
move.l (a1),a2 ;Address of Underline item.
move.l ItemFill(a0),a0 ;Address of text.
move.l ItemFill(a1),a1 ;Address of text.
move.l ItemFill(a2),a2 ;Address of text.
move.l #BoldFont,ITextFont(a0)
move.l #ItalicFont,ITextFont(a1)
move.l #UnderlineFont,ITextFont(a2)
move.l _IntuitionBase,a6
move.l MainEditWindowWnd,a0
move.l MainEditWindowMenus,a1
jsr SetMenuStrip(a6) ;Display new menus.
rts
*****************************************************************************
* Place cursor at mouse position. *
*****************************************************************************
MousePositionCursor:
cmp.w #SELECTDOWN,imsgCode
bne ProcessMainWindowEvent ;Check for LMB down.
cmp.w #1,TextBlockMarked
bne PositionCursorNoCurrentBlock
move.w #0,TextBlockMarked
jsr RefreshVisibleText
PositionCursorNoCurrentBlock:
jsr PositionTheCursor
tst.l d0
beq ProcessMainWindowEvent ;Mouse outside text area.
MousePositionCursorEventLoop:
move.l MainEditWindowWnd,a0
move.l UserPort(a0),a0
jsr WaitForPort ;Wait for a message.
move.l MainEditWindowWnd,a0
jsr GetGadToolsMessage ;Get the message.
move.l imsg,d0
tst.l d0
beq MousePositionCursorEventLoop ;No event occurred.
move.l imsg,a0 ;Process event
move.l Class(a0),imsgClass
move.w Code(a0),imsgCode
jsr ReplyGadToolsMessage ;Reply to message.
move.l imsgClass,d0
cmp.l #IDCMP_MOUSEBUTTONS,d0
beq ProcessMainWindowEvent ;Mouse button pressed.
cmp.l #IDCMP_MOUSEMOVE,d0
beq MarkTextBlock
jmp MousePositionCursorEventLoop
MarkTextBlock:
move.w #0,MouseXCoord ;Reset cursor to left of page.
move.l a5,CurrentLinePtr
move.l CurrentHorizTop,CurrentLineOffset
move.l tb_LineLength(a5),d6
cmp.l CurrentHorizTop,d6
bge MarkTextBlockCont
move.l d6,CurrentLineOffset
MarkTextBlockCont:
cmp.w #1,TextBlockMarked
beq MarkTextBlockCont2 ;Don't highlight current line.
move.l CurrentLinePtr,TextBlockTopPtr
move.l #0,TextBlockLength
move.w #1,TextBlockMarked
jsr HighlightCurrentLine
MarkTextBlockCont2:
clr.l d0
move.l MainEditWindowWnd,a0 ;Get mouse position
move.w MouseY(a0),d0
sub.w OffY,d0
bmi MarkTextMoveUp
divu CursorHeight,d0 ;Convert from pixels to chars.
cmp.w MouseYCoord,d0
beq MousePositionCursorEventLoop
cmp.w MouseYCoord,d0
bhi MarkTextMoveDown
cmp.w MouseYCoord,d0
blo MarkTextMoveUp
jmp MousePositionCursorEventLoop
MarkTextMoveUp:
clr.l d7
move.w MouseYCoord,d7
sub.w d0,d7
sub.l #1,d7
MarkTextMoveUpLoop:
cmp.l #0,TextBlockLength
beq MousePositionCursorEventLoop ;Don't go higher than
sub.l #1,TextBlockLength ; top of block.
jsr ClearCurrentLine
jsr MoveCursorUp
jsr HighlightCurrentLine
dbra d7,MarkTextMoveUpLoop
jmp MousePositionCursorEventLoop
MarkTextMoveDown:
clr.l d7
move.w d0,d7
sub.w MouseYCoord,d7
sub.l #1,d7
MarkTextMoveDownLoop:
move.l CurrentLinePtr,a0
cmp.l #0,tb_Next(a0)
beq MousePositionCursorEventLoop ;End of document reached.
add.l #1,TextBlockLength
jsr MoveCursorDown
jsr HighlightCurrentLine
dbra d7,MarkTextMoveDownLoop
jmp MousePositionCursorEventLoop
HighlightCurrentLine:
jsr HideCursor
move.l #WriteIOReq,a1 ;Invert the text.
move.l #InverseText,io_Data(a1)
move.l #3,io_Length(a1)
jsr SendChars
move.l #WriteIOReq,a1 ;Reset cursor X position.
move.l #CursorToX0Text,io_Data(a1)
move.l #1,io_Length(a1)
jsr SendChars
move.l CurrentLinePtr,a5
move.l CurrentLinePtr,a4
jsr DisplayVisibleLine
jsr ClearLine
move.l #WriteIOReq,a1 ;Reset cursor X position.
move.l #NormalText,io_Data(a1)
move.l #4,io_Length(a1)
jsr SendChars
move.l #WriteIOReq,a1 ;Reset cursor X position.
move.l #CursorToX0Text,io_Data(a1)
move.l #1,io_Length(a1)
jsr SendChars
jsr DrawPrinterBorders
jsr ShowCursor