-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgeoWrite-6.s
1908 lines (1708 loc) · 67 KB
/
geoWrite-6.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
; ----------------------------------------------------------------------------
; geoWrite V2.1 (C64)
; 06 navigation, search/replace, header/footer, repaginate
; ----------------------------------------------------------------------------
; reverse-engineered by Michael Steil, www.pagetable.com
; ----------------------------------------------------------------------------
.include "sym.inc"
.include "geosmac.inc"
.include "const.inc"
.include "zeropage.inc"
.include "geoWrite-0.inc"
; ----------------------------------------------------------------------------
.segment "CODE6": absolute
jmp previousPage ; 0
jmp nextPage ; 1
jmp gotoPage ; 2
jmp streamBlock ; 3
jmp readNextPage ; 4
jmp deleteAcrossPages ; 5
jmp updateDocument ; 6
jmp syncDocToDisk ; 7
jmp update ; 8
jmp readPage ; 9
jmp openHeader ; 10
jmp openFooter ; 11
jmp setFirstPage ; 12
jmp titlePage ; 13
jmp updateTitleNlqMenuSelection ; 14
jmp search ; 15
jmp findNext ; 16
jmp change ; 17
jmp nlqSpacing ; 18
jmp updatePageSizes ; 19
; ----------------------------------------------------------------------------
previousPage:
jsr pageChangeCommon
lda curPage
bne @1
lda #<txt_no_prev_page
ldy #>txt_no_prev_page
jsr showError
bcs @2 ; always
@1: dec curPage
@2: jmp readPage
; ----------------------------------------------------------------------------
pageChangeCommon:
jsr GotoFirstMenu
lda curPage
cmp #PAGE_HEADER
bcs @1 ; ignore while editing header/footer
jsr clearSelection
jsr syncPageToDisk
jmp testDiskNotFull2
@1: pla
pla
rts
; ----------------------------------------------------------------------------
nextPage:
jsr pageChangeCommon
lda curPage
sta r15L
@loop: inc curPage
lda curPage
cmp #PAGE_LAST_USABLE+1
bcs @error
jsr PointRecord
tya
bne @break ; exists
beq @loop ; skip empty records
@error: lda #<txt_no_next_page
ldy #>txt_no_next_page
jsr showError
dec r15L
@break: ldy r15L
iny
sty curPage
jmp readPage
; ----------------------------------------------------------------------------
gotoPage:
jsr pageChangeCommon
lda #<dlgbox_enter_page
ldx #>dlgbox_enter_page
jsr doDlgBoxInput
lda r0L
cmp #CANCEL
beq @cancl
jsr stringToInt
bcs @error
lda r1L
sub privFHData+privfhdata::startPageNo
tax
lda r1H
sbc privFHData+privfhdata::startPageNo+1
bcc @error
cpx #PAGE_LAST_USABLE+1
bcs @error
PushB curPage
txa
sta curPage
jsr PointRecord
pla
cpy #0
beq @ok
@cancl: jmp readPage
@ok: sta curPage
jsr PointRecord
@error: lda #<txt_cannot_go_to_page
ldy #>txt_cannot_go_to_page
jsr showError
jmp readPage
dlgbox_enter_page:
.byte DEF_DB_POS|1
.byte DBTXTSTR
.byte 16
.byte 16
.word txt_enter_page_to_go_to
.byte DBGETSTRING
.byte 16
.byte 32
.byte r5
.byte 3 ; max chars
.byte CANCEL
.byte 17
.byte 72
.byte NULL
;---------------------------------------------------------------
; streamBlock
;
; Function: Reads blocks from the page following the current
; one, one by one.
;
; Note: Calling this repeatedly will keep adding one block
; of the document's remainder at a time to the end
; of the page data in memory, crossing pages and
; skipping empty records.
;---------------------------------------------------------------
streamBlock:
jsr setDocDrive
LoadB r14L, 0
bit nextPageOpen
bmi @1
@loop: ldx curPage
inx ; next page
txa
jsr PointRecord ; does it exist?
tya
bne @found ; yes
jsr findNonEmptyRecord ; all pages after are empty?
bcs @eof ; yes
jsr deleteNextPage ; delete empty page
bra @loop ; repeat
@found: LoadB nextPageOpen, $FF
bne @cont ; always
@eof: IncW pageEndPtr2
ldy #0
tya
sta (pageEndPtr2),y ; terminating NULL
rts
@1: MoveW_y_ tmpTrkSec, r1 ; ???
@cont: sta r3L ; original value of !nextPageOpen
lda pageEndPtr2 ; r4 (buffer) = pageEndPtr2 - 1
sub #1
sta r4L
lda pageEndPtr2+1
sbc #0
sta r4H
ldy #0
lda (r4),y ; save last two bytes to save
pha ; them from overwriting by block's
iny ; link bytes
lda (r4),y
pha
jsr _GetBlock ; read one block of record
beqx :+
jmp showErrorReadingPage
: LoadB r2L, $FE
ldy #0
lda (r4),y ; end of chain?
bne @3 ; no
LoadB nextPageOpen, 0
iny
lda (r4),y ; number of valid bytes
sub #1
sta r2L
pha
PushW r4
PushB r3L ; we read all of it, so
jsr deleteNextPage ; delete the page
PopB r3L
PopW r4
PopB r2L ; number of valid bytes
@3: sta tmpTrkSec ; read and save link t/s
ldy #1
lda (r4),y
sta tmpTrkSec+1
pla
sta (r4),y ; restore 2 bytes from before
tax ; that were overwritten
dey ; by link bytes
pla
sta (r4),y
bit r3L
bpl @4
cpx #CR
beq @4
; first block of record
ldx #r4
stx r14L
lda #2
jsr addWIToZp ; r4 += 2
AddVW2 27, r4, r3 ; r3: skipped ruler
sec
lda r2L
sbc #26
sta r2H
ldy #0
@loop2: lda (r3),y ; copy everything up,
sta (r4),y ; overwriting ruler
iny
cpy r2H
bne @loop2
sec
lda r2L
sbc #27
sta r2L
@4: lda pageEndPtr2 ; add block of bytes to
add r2L ; end pointer
sta pageEndPtr2
lda pageEndPtr2+1
adc #0
sta pageEndPtr2+1
rts0: rts
;---------------------------------------------------------------
; deleteNextPage
;
; Function: Deletes the next page and moves all further pages
; up.
;---------------------------------------------------------------
deleteNextPage:
lda curPage
add #1
jsr PointRecord
jsr _DeleteRecord
lda #PAGE_LAST_USABLE
jsr PointRecord
jsr _InsertRecord
jsr _UpdateRecordFile
LoadB zp_DDb, 0
jmp setDirty
; ----------------------------------------------------------------------------
loopingRepaginateAll:
LoadB curPage, 0
@loop: lda curPage
jsr PointRecord
tya
beq @skip ; empty record, skip to next non-empty
jsr repaginateFromPage
@loopingRepaginateNext:
MoveB cursor3+cursor::srcline, curPage
@skip: jsr findNonEmptyRecord ; next valid page
bcs rts0 ; end reached
inc curPage
bne @loop ; loop always
loopingRepaginateNext = @loopingRepaginateNext
; ----------------------------------------------------------------------------
deleteAcrossPages:
lda curPage
cmp #PAGE_HEADER
bcs @rts
lda #<dlgbox_del_last_char ; allow user to cancel
ldx #>dlgbox_del_last_char ; the delete across pages
jsr doDlgBox
lda #0
ldx sysDBData
cpx #CANCEL
beq @rts
jsr syncPageToDisk
jsr testDiskNotFull2
dec curPage
jsr readPage
AddVW2 RULER_ESC_LENGTH, pageEndPtr2, cursor0+cursor::ptr
jsr copyCursor0To1
jsr setDirty
jsr streamBlock
lda r14L
beq @1
SubVW 27, cursor0+cursor::ptr
@1: lda #$FF
sta a4H
sta cursor0+cursor::srcline
sta cursor1+cursor::srcline
AddVW2 -134, usablePageHeight, pagePosY
lda #$FF
@rts: rts
; ----------------------------------------------------------------------------
dlgbox_del_last_char:
.byte DEF_DB_POS|1
.byte DBTXTSTR
.byte $10
.byte $10
.word txt_del_last_char
.byte DBTXTSTR
.byte $10
.byte $20
.word txt_of_prev_page
.byte OK
.byte $01
.byte $48
.byte CANCEL
.byte 17
.byte $48
.byte NULL
; ----------------------------------------------------------------------------
update: jsr GotoFirstMenu
jsr clearSelection
updateDocument:
LoadB a4H, $FF ; 34B6 A9 FF ..
jsr pushR15 ; 34BA 20 6C 28 l(
jsr syncPageToDisk ; 34BD 20 1F 35 .5
jsr testDiskNotFull2 ; 34C0 20 42 0E B.
jsr popR15 ; 34C3 20 7F 28 .(
@loop: jsr pushR15 ; 34C6 20 6C 28 l(
jsr readPage ; 34C9 20 58 37 X7
jsr popR15 ; 34CC 20 7F 28 .(
CmpW pageEndPtr2, r15
bcs @break ; 34D9 B0 1F ..
SubW zp_F2w, r15L ; 34DE E5 F2 ..
inc curPage ; 34E8 E6 D3 ..
SubVW2_ MEM_PAGE, pageEndPtr2, zp_F2w
bra @loop ; 34F8 50 CC P.
@break: CmpW pageEndPtr2, cursor0+cursor::ptr
bcs L3513 ; 3504 B0 0D ..
copy_XXX1:
SubW zp_F2w, cursor0+cursor::ptr
L3513: jmp copyCursor0To1 ; 3513 4C C0 28 L.(
;---------------------------------------------------------------
; syncDocToDisk
;
; Function: Update the document on disk to contain all state
; currently in memory. Can be called editing a page,
; the header or the footer.
;---------------------------------------------------------------
syncDocToDisk:
lda curPage
cmp #PAGE_HEADER
bcc syncPageToDisk
jmp closeHeaderFooter
;---------------------------------------------------------------
; syncPageToDisk
;
; Function: Update the document on disk to contain all state
; currently in memory. Can only be called when editing
; a page, not when editing the header or footer.
;---------------------------------------------------------------
syncPageToDisk:
lda hasPagePropMetadata
beq repaginateFromLoadedPage
PushB dirty
jsr repaginateFromLoadedPage
pla
bpl @rts
PushW zp_F2w
PushB curPage
jsr loopingRepaginateNext
PopB curPage
PopW zp_F2w
@rts: rts
; ----------------------------------------------------------------------------
repaginateFromPage:
jsr readPage
jsr setDirty ; first run flag???
repaginateFromLoadedPage:
PushB curPage
bit dirty
bpl @5 ; then skip repaginate, just update metadata
LoadW_ zp_F2w, 0
@loop: jsr measurePage ; read bytes across records until page full
jsr writePage ; write back page
CmpW pageEndPtr2, pageEndPtr1
php
jsr setPageHeader ; create header for new page
bcc @1 ; more data? yes
bit nextPageOpen
bpl @2 ; no more data from record pending [XXX already taken care of?]
@1: plp
inc curPage ; we're on the next page!
lda curPage
cmp #PAGE_LAST_USABLE + 1 ; overflow?
bne :+
dec curPage ; yes, go back; error will be caught again
: jsr setDocDrive
jsr calcusablePageHeight
lda #PAGE_LAST_USABLE
jsr PointRecord ; is document full?
tya
beq :+ ; we can extend by a page
jsr _showTooManyPages ; "text at the end will be lost" - we continue anyway
: jsr _DeleteRecord
lda curPage
jsr PointRecord
jsr _InsertRecord ; clear last usable page
bra @loop
; *** write remainder
@2: plp ; last page written has reached end?
beq @5 ; yes
inc curPage
lda curPage
cmp #PAGE_LAST_USABLE + 1
beq @3
jsr PointRecord
tya
bne @4 ; exists
MoveW pageEndPtr2, pageEndPtr1
jsr writePage
bra @4
@3: jsr _showTooManyPages ; "text at the end will be lost" - we continue anyway
@4: dec curPage
@5: MoveB curPage, cursor3+cursor::srcline
PopB curPage
jsr cleardirty_nextPageOpen
LoadB zp_DDb, $FF
jsr setDocDrive
jsr _UpdateRecordFile ; update time stamp
UpdateDocFileHeader:
jsr setDocDrive
MoveW docFileHeaderTrkSec, r1L
jsr ldR4DiskBlkBuf
jsr _GetBlock
jsr i_MoveData
.word privFHData
.word diskBlkBuf + O_GHP_PRIVATE
.word 9
MoveW docFileHeaderTrkSec, r1
jsr ldR4DiskBlkBuf
jmp _PutBlock
; ----------------------------------------------------------------------------
setPageHeader:
jsr setPageHeadRuler
ldy #<PAGE_CARDSET
ldx #>PAGE_CARDSET
sty r1L
stx r1H
AddVW2 1, pageEndPtr1, r0
CmpW r0, pageEndPtr2
bcc @1
beq @1 ; pageEndPtr1+1 <= pageEndPtr2
LoadB PAGE_CARDSET+cardset::magic, 0
ldy #<PAGE_CARDSET
sty pageEndPtr2
stx pageEndPtr2+1
jsr calcDiff_XXX1
sec ; bad
rts
@1: SubW3 pageEndPtr2, pageEndPtr1, r2
AddVW2 MEM_PAGE+page::ruler+ruler::unused3, r2, pageEndPtr2
ldy #0
lda (r0),y
cmp #ESC_GRAPHICS
bne @2
jsr setPageHeadCardSet
jsr incWR1
IncW pageEndPtr2
lda #CR
sta MEM_PAGE+page::text
bne @end
@2: cmp #ESC_RULER
bne @3
LoadW r1, MEM_PAGE
SubVW 27, pageEndPtr2
ldy #page::ruler+ruler::justification
lda rulerData1+ruler::justification
and #$10
sta r4L
lda (r0),y
and #$EF
ora r4L
sta (r0),y
bra @end
@3: cmp #NEWCARDSET
beq @end
cmp #PAGE_BREAK
beq @end
CmpW cursor0+cursor::ptr, r0
bne :+
jsr calcDiff_XXX1
: jsr setPageHeadCardSet
@end: jsr calcDiff_XXX1
jsr MoveData
clc ; good
rts
; ----------------------------------------------------------------------------
calcDiff_XXX1:
lda zp_F2w
ora zp_F2w+1 ; zp_F2W == 0?
bne @rts ; no
SubW3 r0, r1, zp_F2w ; zp_F2w = r0 - r1
@rts: rts
;---------------------------------------------------------------
; setPageHeadCardSet
;
; Function: Fill the header of the current page in memory
; with the current cardset.
;---------------------------------------------------------------
setPageHeadCardSet:
LoadB PAGE_CARDSET+cardset::magic, NEWCARDSET
MoveW curFont, PAGE_CARDSET+cardset::fontid
MoveB currentMode, PAGE_CARDSET+cardset::style
ldx #r1
jsr addWI4ToZp ; r1 += 4
ldx #pageEndPtr2
jmp addWI4ToZp ; pageEndPtr2 += 4
;---------------------------------------------------------------
; setPageHeadRuler
;
; Function: Fill the header of the current page in memory
; with the current ruler data.
;---------------------------------------------------------------
setPageHeadRuler:
ldy #.sizeof(ruler)-1
@loop: lda rulerData1,y
sta MEM_PAGE+page::ruler,y
dey
bpl @loop
lda PAGE_RULER+ruler::justification
and #$3F ; clear private bits
sta PAGE_RULER+ruler::justification
setRulerMagic:
lda #ESC_RULER ; set magic
sta MEM_PAGE+page::magic
rts4: rts
;---------------------------------------------------------------
; writePage
;
; Function: Writes a page into the document. If the record
; already exists, overwrite it.
;
; Pass: curPage page number
;---------------------------------------------------------------
writePage:
jsr drawPageNumber
jsr setDocDrive
lda curPage
jsr PointRecord
SubVW2 MEM_PAGE-1, pageEndPtr1, r2 ; length
jsr LoadR7MemPage
jsr swapUserZp
jsr WriteRecord
jsr swapUserZp
cpx #INSUFF_SPACE
beq @error
beqx rts4
lda #<txt_writing_page
ldy #>txt_writing_page
jsr showIOError
bcs @end
@error: lda #<txt_insufficient_disk_space ; this really shouldn't happen, because the app
ldy #>txt_insufficient_disk_space ; always checks whether there are at least
jsr showError ; 6 KB free before performing anything like this
@end: jsr _CloseRecordFile
jsr UpdateDocFileHeader
jmp restart
; ----------------------------------------------------------------------------
readNextPage:
jsr syncPageToDisk ; 3747 20 1F 35 .5
jsr testDiskNotFull2 ; 374A 20 42 0E B.
lda curPage ; 374D A5 D3 ..
cmp #PAGE_LAST_USABLE ; 374F C9 3C .<
beq readPage ; 3751 F0 05 ..
jsr copy_XXX1 ; 3753 20 06 35 .5
inc curPage ; 3756 E6 D3 ..
;---------------------------------------------------------------
; readPage
;
; Function: Reads a page into memory. If the record does not
; exist, create an empty page in memory.
;
; Pass: curPage page number
;---------------------------------------------------------------
readPage:
jsr calcusablePageHeight ; calc for curPage
lda loadOpt
and #ST_PR_DATA
bne :+
jsr drawPageNumber ; update UI
: jsr setDocDrive
lda curPage
jsr PointRecord
bnex pageReadError
tya
beq createEmptyPage ; if empty record
jsr LoadR7MemPage
LoadW r2, MEM_SIZE_PAGE ; max num bytes
jsr swapUserZp
jsr ReadRecord ; read
jsr swapUserZp
bnex pageReadError
SubVW2 1, r7, pageEndPtr2 ; pointer to last byte
lda curPage
cmp #PAGE_LAST_USABLE
bne cleardirty_nextPageOpen
; add NULL at the end
ldy #0
lda (pageEndPtr2),y ; last byte of file
beq cleardirty_nextPageOpen
cmp #PAGE_BREAK
beq :+ ; overwrite page break with NULL
IncW pageEndPtr2
: tya
sta (pageEndPtr2),y
cleardirty_nextPageOpen:
lda #0
sta dirty
sta nextPageOpen
rts
pageReadError:
lda loadOpt
and #ST_PR_DATA
bne _exitToDesktop2 ; print? then exit to desktop
cpx #BFR_OVERFLOW
bne showErrorReadingPage
lda #<txt_page_too_big ; geoWrite limits pages to 7000 bytes; this
ldy #>txt_page_too_big ; can only happen if anther app wrote the document
jsr showError ; (maybe old versions of geoWrite had a higher limit?)
bcs createEmptyPage ; always
showErrorReadingPage:
lda #<txt_reading_page
ldy #>txt_reading_page
jsr showIOError
jmp restart
; ----------------------------------------------------------------------------
_exitToDesktop2:
jmp _exitToDesktop
; ----------------------------------------------------------------------------
LoadR7MemPage:
LoadW r7, MEM_PAGE
rts
; ----------------------------------------------------------------------------
createEmptyPage:
; clear page header
jsr i_FillRam
.word 34
.word MEM_PAGE
.byte 0
jsr setRulerMagic
; set right margin and all 8 tabs to pageWidth1
ldx #2 * (8 + 1) - 1
@1: lda pageWidth1+1
sta PAGE_RULER+ruler::right_margin,x
dex
lda pageWidth1
sta PAGE_RULER+ruler::right_margin,x
dex
bpl @1
LoadB PAGE_RULER+ruler::justification, $10 ; left aligned, single spaced
LoadW pageEndPtr2, PAGE_CARDSET
jsr findNonEmptyRecord
bcs L381B
jsr i_MoveData
.word empty_page
.word PAGE_CARDSET
.word 5
LoadB pageEndPtr2, <PAGE_CARDSET+4
L381B: jmp setDirty
empty_page:
.byte NEWCARDSET
.word SYSTEM_FONT_ID
.byte SET_PLAINTEXT
.byte CR
;---------------------------------------------------------------
; findNonEmptyRecord
;
; Function: Find the first non-empty record after the current
; page.
;
; Return: c =0: found
; x number of non-empty record
; =1: end of pages reached and none found
; or: current page is header or footer
;---------------------------------------------------------------
findNonEmptyRecord:
ldx curPage
cpx #PAGE_HEADER
bcs @fail
@loop: cpx #PAGE_LAST_USABLE
beq @fail
inx
stx r2L
txa
jsr PointRecord
ldx r2L
tya
beq @loop ; loop if empty record
clc
rts
@fail: sec
rts
; ----------------------------------------------------------------------------
drawPageNumber:
lda currentMode
pha
LoadW r1, SYSTEM_FONT_ID
jsr setFontFromFile
jsr i_GraphicsString
.byte NEWPATTERN
.byte 0
.byte MOVEPENTO
.word 193
.byte 1
.byte RECTANGLETO
.word 206
.byte 14
.byte MOVEPENTO
.word 207
.byte 0
.byte LINETO
.word 207
.byte 15
.byte NEWPATTERN
.byte 2
.byte MOVEPENTO
.word 208
.byte 0
.byte RECTANGLETO
.word 211
.byte 13
.byte NULL
LoadB currentMode, 0
lda curPage
cmp #PAGE_HEADER
bcs @skip
; logical page number -> r0
add privFHData+privfhdata::startPageNo
sta r0L
lda #0
adc privFHData+privfhdata::startPageNo+1
sta r0H
; calc x pos for centering
LoadB r11H, 0 ; x pos hi
ldx #193
lda r0H
bne @1
lda r0L
cmp #100
bcs @1
ldx #195
cmp #10
bcs @1
ldx #197
@1: stx r11L ; x pos
LoadB r1H, 11 ; y pos
LoadW rightMargin, 212
lda #SET_LEFTJUST | SET_SURPRESS | 13 ; left justify, no leading zeros [XXX "13" has no function]
jsr PutDecimal
LoadW rightMargin, SC_PIX_WIDTH-1
@skip: pla
sta currentMode
rts
;---------------------------------------------------------------
; calcusablePageHeight
;
; Function: Calculate the height of the page minus
; header/footer for the current page.
;
; Pass: curPage page number
;
; Returns: usablePageHeight result
; usablePageHeightDiv13 result / 13
;---------------------------------------------------------------
calcusablePageHeight:
MoveW pageWidth1, pageWidth2
LoadW usablePageHeight, MAX_HEADER_FOOTER_HEIGHT
ldx curPage
cpx #PAGE_HEADER
bcs @2
lda hasPagePropMetadata
beq @1
lda widthForPage_lo,x ; get data from metadata table
sta pageWidth2
lda widthForPage_hi,x
sta pageWidth2+1
lda heightForPage_lo,x
sta usablePageHeight
lda heightForPage_hi,x
sta usablePageHeight+1
bpl @2
; calculate usable page height (page height - header - footer)
@1: lda privFHData+privfhdata::headerHeight
add privFHData+privfhdata::footerHeight
sta r0L
lda privFHData+privfhdata::headerHeight+1
adc privFHData+privfhdata::footerHeight+1
sta r0H
lda privFHData+privfhdata::pageHeight
sub r0L
sta usablePageHeight
lda privFHData+privfhdata::pageHeight+1
sbc r0H
sta usablePageHeight+1
; special case title page
lda privFHData+privfhdata::titleNlqFlag
bpl @2 ; no title page
lda curPage
bne @2 ; not first page
CmpWI privFHData+privfhdata::startPageNo, 1
bne @2 ; numbering doesn't start with 1
MoveW privFHData+privfhdata::pageHeight, usablePageHeight ; override usable page height with full page height
@2: MoveW usablePageHeight, usablePageHeightDiv13
LoadW r1, 13
ldx #usablePageHeightDiv13
ldy #r1
jmp Ddiv ; divide by 13
; ----------------------------------------------------------------------------
.include "stringtoint.inc"
; ----------------------------------------------------------------------------
.include "strings6.inc"
; ----------------------------------------------------------------------------
setFirstPage:
LoadB a4L, 0
jsr GotoFirstMenu
lda #<dlgbox_enter_page_number_for_first_page
ldx #>dlgbox_enter_page_number_for_first_page
jsr doDlgBoxInput
lda r0L
cmp #CANCEL
beq rts1
jsr stringToInt
bcs showBadValueError
MoveW r1, privFHData+privfhdata::startPageNo
jsr drawPageNumber
lda privFHData+privfhdata::titleNlqFlag
bpl rts1
jsr repaginate_XXX2
lda #A4L_20
sta a4L
rts1: rts
showBadValueError:
lda #<txt_bad_value
ldy #>txt_bad_value
jmp showError
; ----------------------------------------------------------------------------
doDlgBoxInput:
LoadW_y r5, fnBuffer ; default input to empty string
LoadB_y fnBuffer, 0
jmp doDlgBox
; ----------------------------------------------------------------------------
dlgbox_enter_page_number_for_first_page:
.byte DEF_DB_POS|1
.byte DBTXTSTR
.byte 16
.byte 16
.word txt_enter_page_number
.byte DBTXTSTR
.byte 16
.byte 32
.word txt_for_first_page
.byte DBGETSTRING
.byte 16
.byte 48
.byte r5
.byte 3 ; max chars
.byte CANCEL
.byte 17
.byte 72
.byte NULL
; ----------------------------------------------------------------------------
; toggle title page
titlePage:
jsr GotoFirstMenu
lda curPage
cmp #PAGE_HEADER
bcs rts1
lda privFHData+privfhdata::titleNlqFlag
eor #$80
sta privFHData+privfhdata::titleNlqFlag
lda privFHData+privfhdata::headerHeight
ora privFHData+privfhdata::headerHeight+1
ora privFHData+privfhdata::footerHeight
ora privFHData+privfhdata::footerHeight+1
beq updateTitleNlqMenuSelection
CmpWI privFHData+privfhdata::startPageNo, 1
bne updateTitleNlqMenuSelection
lda curPage
bne @1
jsr setDirty
jsr calcusablePageHeight
bra updateTitleNlqMenuSelection
@1: jsr repaginate_XXX2
updateTitleNlqMenuSelection:
ldy #'*'
bit privFHData+privfhdata::titleNlqFlag