-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPT2.3F.s
26584 lines (24782 loc) · 481 KB
/
PT2.3F.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
; ProTracker v2.3F source code
; ============================
; 17th of November, 2024
;
; (tab width = 8 spaces)
;
; If you find any bugs, please email me at the email/Discord found on
; the website 16-bits.org.
;
; Original PT2.3D by Peter "CRAYON" Hanning, Detron and Lars "ZAP" Hamre
;
; PT2.3D raw disassemble by Per "Super-Hans" Johansson
; Re-source job and PT2.3E/PT2.3F version by Olav "8bitbubsy" Sorensen (me)
;
ERR_WAIT_TIME EQU 40
MOUSE_SPEED EQU 11 ; 1..16
SONG_SIZE_100PAT EQU 1084+(1024*100)
SONG_SIZE_64PAT EQU 1084+(1024*64)
RasterWait1_000 EQU 5-1
RasterWait1_020 EQU 7-1
RasterWait2_000 EQU 0
RasterWait2_020 EQU 40-1
; FileFormat
sd_sampleinfo EQU 20
sd_numofpatt EQU 950
sd_pattpos EQU 952
sd_magicid EQU 1080
sd_patterndata EQU 1084
; audXtemp offsets
n_note EQU 0 ; W (MUST be first!)
n_cmd EQU 2 ; W (MUST be second!)
n_cmdlo EQU 3 ; B (lower byte of cmd)
n_start EQU 4 ; L (aligned)
n_wavestart EQU 8 ; L
n_loopstart EQU 12 ; L
n_oldstart EQU 16 ; L
n_peroffset EQU 20 ; L (offset to finetuned period-LUT section)
n_dmabit EQU 24 ; W (aligned)
n_length EQU 26 ; W
n_replen EQU 28 ; W
n_period EQU 30 ; W
n_wantedperiod EQU 32 ; W
n_oldlength EQU 34 ; W
n_periodout EQU 36 ; W
n_repeat EQU 38 ; W
n_finetune EQU 40 ; B
n_volume EQU 41 ; B
n_toneportdirec EQU 42 ; B
n_toneportspeed EQU 43 ; B
n_vibratocmd EQU 44 ; B
n_vibratopos EQU 45 ; B
n_tremolocmd EQU 46 ; B
n_tremolopos EQU 47 ; B
n_wavecontrol EQU 48 ; B
n_glissfunk EQU 49 ; B
n_sampleoffset EQU 50 ; B
n_pattpos EQU 51 ; B
n_loopcount EQU 52 ; B
n_funkoffset EQU 53 ; B
n_trigger EQU 54 ; B
n_samplenum EQU 55 ; B
n_volumeout EQU 56 ; B
n_sampleoffset2 EQU 57 ; B
n_muted EQU 58 ; B
ChanStructSize EQU 60 ; (must be a multiple of 4!)
; Exec Library Offsets
_LVOFindTask EQU -294
_LVOFindName EQU -276
_LVOForbid EQU -132
_LVOPermit EQU -138
_LVOAddPort EQU -354
_LVORemPort EQU -360
_LVOWaitPort EQU -384
_LVOOpenLibrary EQU -552
_LVOCloseLibrary EQU -414
_LVOOpenDevice EQU -444
_LVOCloseDevice EQU -450
_LVODoIO EQU -456
_LVOSendIO EQU -462
_LVOGetMsg EQU -372
_LVOReplyMsg EQU -378
_LVOAllocMem EQU -198
_LVOFreeMem EQU -210
_LVOAvailMem EQU -216
_LVOAddIntServer EQU -168
_LVORemIntServer EQU -174
_LVOOpenResource EQU -498
_LVOSetIntVector EQU -162
_LVORemDevice EQU -438
_LVOOldOpenLibrary EQU -408
_LVOSetSignal EQU -306
_LVOWait EQU -318
_LVOSignal EQU -324
; CIA Resource Offsets
_AddICRVector EQU -6
_RemICRVector EQU -12
; DOS Library Offsets
_LVOOpen EQU -30
_LVOClose EQU -36
_LVORead EQU -42
_LVOWrite EQU -48
_LVODeleteFile EQU -72
_LVORename EQU -78
_LVOLock EQU -84
_LVOUnLock EQU -90
_LVOExamine EQU -102
_LVOExNext EQU -108
_LVOInfo EQU -114
_LVOSeek EQU -66
_LVOCreateDir EQU -120
_LVOCurrentDir EQU -126
_LVODateStamp EQU -192
_LVODelay EQU -198
_LVOExecute EQU -222
_LVOUnLoadSeg EQU -156
_LVOParentDir EQU -210
_LVODupLock EQU -96
_LVOCreateProc EQU -138
; Intuition Library Offsets
_LVOCloseScreen EQU -66
_LVOOpenScreen EQU -198
_LVOOpenWorkbench EQU -210
_LVOScreenToBack EQU -246
_LVOScreenToFront EQU -252
_LVOWBenchToFront EQU -342
; Graphics Library Offsets
_LVOWaitBlit EQU -228
_LVOOwnBlitter EQU -456
_LVODisownBlitter EQU -462
; Power Packer Library Offsets
_LVOppLoadData EQU -30
_LVOppAllocCrunchInfo EQU -96
_LVOppFreeCrunchInfo EQU -102
_LVOppCrunchBuffer EQU -108
_LVOppWriteDataHeader EQU -114
; DateStamp
ofib_DateStamp EQU $84
ds_Days EQU $00
ds_Minute EQU $04
ds_Tick EQU $08
; Memory Alloc Flags
MEMF_PUBLIC EQU $0001
MEMF_CHIP EQU $0002
MEMF_FAST EQU $0004
MEMF_CLEAR EQU $10000
MEMF_TOTAL EQU $80000
; IO Block Offsets
IO_COMMAND EQU $1C
IO_FLAGS EQU $1E
IO_ACTUAL EQU $20
IO_LENGTH EQU $24
IO_DATA EQU $28
IO_OFFSET EQU $2C
; Device Commands
CMD_READ EQU $2
CMD_WRITE EQU $3
CMD_UPDATE EQU $4
TD_MOTOR EQU $9
TD_FORMAT EQU $B
TD_CHANGESTATE EQU $E
TD_PROTSTATUS EQU $F
DirNameLength EQU 30
ConfigFileSize EQU 1024
KeyBufSize EQU 20
ThisTask EQU $114
pr_CLI EQU $AC
pr_MsgPort EQU $5C
sm_ArgList EQU $24
cli_CommandName EQU $10
SHARED_LOCK EQU -2
; -----------------------------------------------------------------------------
; RUNBACK HUNK (modified by ross)
; -----------------------------------------------------------------------------
SECTION ptrunback,CODE
rb_HunkStart
MOVE.L 4.W,A6
LEA DOSname,A1
JSR _LVOOldOpenLibrary(A6)
MOVE.L D0,A5 ; dosbase
MOVE.L ThisTask(A6),A3
MOVE.L pr_CLI(A3),D6 ; d6 = CLI or WB (NULL)
BNE.B .fromCLI
; Get startup message if we started from Workbench
LEA pr_MsgPort(A3),A0
JSR _LVOWaitPort(A6) ; wait for a message
LEA pr_MsgPort(A3),A0
JSR _LVOGetMsg(A6) ; then get it
MOVE.L D0,A3 ; a3 = WBStartup message
MOVE.L sm_ArgList(A3),A0
MOVE.L (A0),D5 ; (wa_Lock) FileLock on program dir
EXG A5,A6 ; _dos
BSR.B .common
; Reply to the startup message
JSR _LVOForbid(A6) ; it prohibits WB to unloadseg me
LEA (A3),A1
JMP _LVOReplyMsg(A6) ; reply to WB message and exit
.fromCLI
; Get FileLock via command name if we started from CLI
LINK A3,#-256
; Copy BCPL string to C-style string
LEA (SP),A1
LSL.L #2,D6
MOVE.L D6,A0
MOVE.L cli_CommandName(A0),A0
ADD.L A0,A0
ADD.L A0,A0
MOVE.B (A0)+,D0
.loop MOVE.B (A0)+,(A1)+
SUBQ.B #1,D0
BNE.B .loop
CLR.B (A1)
; Get a lock on the program and its parent
EXG A5,A6 ; _dos
MOVE.L SP,D1 ; d1 = STRPTR name (command string)
MOVEQ #SHARED_LOCK,D2 ; d2 = accessMode
JSR _LVOLock(A6)
MOVE.L D0,D7
MOVE.L D0,D1
JSR _LVOParentDir(A6)
MOVE.L D7,D1
MOVE.L D0,D6 ; d6 = Lock on CLI program dir
MOVE.L D0,D5 ; d5 = common Lock
JSR _LVOUnLock(A6)
UNLK A3
.common
MOVE.L D5,D1
JSR _LVODupLock(A6)
MOVE.L D0,rb_CurrentDir
MOVE.L #rb_Progname,D1
MOVEQ #0,D2
MOVE.B 9(A3),D2 ; priority
LEA rb_HunkStart-4(PC),A0
MOVE.L (A0),D3 ; ptr to next segment
CLR.L (A0) ; unlink next segment
MOVE.L #2048,D4 ; stack=2kB (big enough for this program)
JSR _LVOCreateProc(A6)
MOVE.L D6,D1 ; UnLock program dir or zero (from WB)
JSR _LVOUnLock(A6)
LEA (A6),A1
LEA (A5),A6
JSR _LVOCloseLibrary(A6)
MOVEQ #0,D0
RTS
; -----------------------------------------------------------------------------
; MAIN CODE
; -----------------------------------------------------------------------------
SECTION ptcode,CODE
PTStart
MOVEQ #0,D0
MOVE.L 4.W,A6
SUB.L A1,A1
JSR _LVOFindTask(A6)
MOVE.L D0,PTProcess
MOVE.L D0,A0
MOVE.L $B8(A0),PTProcessTmp
BSR.B Main
MOVE.L PTProcess(PC),A0
MOVE.L PTProcessTmp(PC),$B8(A0)
MOVE.L 4.W,A6
JSR _LVOForbid(A6)
MOVE.L DOSBase,A6
MOVE.L rb_CurrentDir(PC),D1
JSR _LVOUnLock(A6)
LEA PTStart-4(PC),A0
MOVE.L A0,D1
LSR.L #2,D1
JSR _LVOUnLoadSeg(A6)
MOVEQ #0,D0
RTS
Main
MOVE.L SP,StackSave ; important! (leaking memory without it, for some reason)
; ---------------------
MOVE.L 4.W,A6
MOVE.W 296(A6),D0
BTST #1,D0 ; CPU is 68000?
BNE.B not68k
MOVE.W #RasterWait1_000,WaitRasterLines1
MOVE.W #RasterWait2_000,WaitRasterLines2
ST CPUIs68000
BRA.B srwskip
not68k MOVE.W #RasterWait1_020,WaitRasterLines1
MOVE.W #RasterWait2_020,WaitRasterLines2
SF CPUIs68000
srwskip ; ---------------------
BSR.W OpenLotsOfThings
BSR.W SetVBInt
BSR.W SetMusicInt
JSR SetPatternPos
BSR.W SetNormalPtrCol
BSR.W StorePtrCol
BSR.W RedrawToggles
BSR.W DoShowFreeMem
BSR.W SetTempo
BSR.W SetInputHandler
BSR.W PTScreenToFront
BSR.W CheckInitError
BSR.W DirBrowseGadg2
MOVEQ #0,D3
MOVE.W DirPathNum(PC),D3
LEA dpnum(PC),A0
ADD.L D3,A0
MOVE.B #$FF,(A0)
BSR.W DirBrowseGadg2
LEA VersionText(PC),A0
JSR ShowStatusText
MOVE.L SongDataPtr,A0
MOVE.B #1,sd_numofpatt(A0)
BSR.W DisplayMainScreen
; fall-through
MainLoop
JSR CheckMIDIin
BSR.W DoKeyBuffer
BSR.W CheckToggleRasterbarKeys
BSR.W CheckPatternInvertKeys
BSR.W CheckTransKeys
BSR.W CheckCtrlKeys
BSR.W CheckAltKeys
BSR.W CheckListQuickJump
BSR.W CheckKeyboard
BSR.W CheckF1_F2
BSR.W CheckF3_F5
BSR.W CheckF6_F10
BSR.W CheckPlayKeys
BSR.W CheckHelpKey
BSR.W ArrowKeys2
BSR.W ShowTimer
BSR.W ShowFreeMem
BSR.W CheckBlockPos
JSR CheckSampleLength ; test if we need to alloc more mem
BSR.W CheckRedraw
TST.B SetSignalFlag
BNE.B .skip
MOVE.L 4.W,A6
MOVEQ #0,D0
MOVE.L #$30000000,D1
JSR _LVOSetSignal(A6)
MOVE.L #$70000000,D0
JSR _LVOWait(A6)
AND.L #$10000000,D0
BNE.B .skip2
.skip SF SetSignalFlag
BTST #6,$BFE001 ; left mouse button
BNE.W StopInputLoop
.skip2 BSR.W ArrowKeys
BRA.W CheckGadgets
BRA.W MainLoop
; used stop further key/mouse input for a while
StopInputLoop
TST.B StopInputFlag
BNE.B mskip
MOVEQ #8*2,D1
BSR.W WaitD1
BRA.B StopInputLoop
mskip TST.B ProgLockMode
BEQ.W MainLoop
CMP.B #1,ProgLockMode ; 1 = PT about to get locked
BNE.B mskip2
MOVE.W #$91,D0
BSR.W WaitForVBlank
LEA EnterPassText(PC),A0
JSR ShowStatusText
BSR.W CheckRedraw
BRA.B StopInputLoop
mskip2 CMP.B #2,ProgLockMode ; 2 = locked
BNE.B mskip3
MOVE.W #$91,D0
BSR.W WaitForVBlank
LEA PTLockedText(PC),A0
JSR ShowStatusText
BSR.W CheckRedraw
BRA.B StopInputLoop
mskip3 CMP.B #3,ProgLockMode ; 3 = password enterd, unlock PT
BNE.B StopInputLoop
CLR.B ProgLockMode
JSR ShowAllRight
CLR.W KeyBufPos
BRA.B StopInputLoop
EnterPassText dc.b "Enter password",0
PTLockedText dc.b "PT is locked",0
EVEN
CheckToggleRasterbarKeys
TST.W LeftAmigaStatus
BEQ.W Return1
TST.W CtrlKeyStatus
BEQ.W Return1
MOVE.B RawKeyCode,D0
CMP.B #48,D0 ; '<'
BNE.W Return1
EOR.B #1,ShowRasterbar
RTS
CNOP 0,4
PTProcess dc.l 0
PTProcessTmp dc.l 0
rb_CurrentDir dc.l 0
rb_PtDir dc.l 0
rb_Progname dc.b 'PT2.3F',0
VersionText dc.b 'ProTracker v2.3F',0
EVEN
; ---- Password Lock Routines ----
CheckLockSequence
TST.W GetLineFlag
BNE.W Return1
TST.B D0 ; D0 = raw key
BEQ.W Return1
MOVE.L LockPhrasePtr(PC),A3
MOVE.B -1(A3),D2
CMP.B D2,D0
BEQ.W Return1
ADD.B #$80,D2 ; also check if SHIFT was held
CMP.B D2,D0
BEQ.W Return1
MOVE.B (A3)+,D1
CMP.B D1,D0
BEQ.B clsskip
MOVE.L #LockPhrase,LockPhrasePtr
RTS
clsskip
CMP.B #$27,D0 ; the 'K' in "LOCK" (e.g. we completed the phrase)
BEQ.B clsskip2
MOVE.L A3,LockPhrasePtr
RTS
clsskip2
MOVE.L #LockPhrase,LockPhrasePtr
MOVE.B #1,ProgLockMode
CLR.L UnlockPhrase
CLR.L UnlockPhrase+4
CLR.B RawKeyCode
CLR.B LastRawkey
RTS
SetUnlockSequence
TST.B D0
BEQ.W Return1
BTST #7,D0
BNE.W Return1
MOVE.L UnlockPhrasePtr(PC),A3
CMP.B #$44,D0 ; ENTER/RETURN
BEQ.B mucskip
MOVE.B D0,(A3)+
CMP.B #$FF,(A3) ; end of password string
BEQ.B mucskip
MOVE.L A3,UnlockPhrasePtr
RTS
mucskip
CMP.L #UnlockPhrase,A3
BNE.B mucskip2
MOVE.B #3,ProgLockMode
BRA.B mucskip3
mucskip2
MOVE.B #$FF,(A3)
MOVE.B #2,ProgLockMode
mucskip3
MOVE.L #UnlockPhrase,UnlockPhrasePtr
CLR.B RawKeyCode
CLR.B LastRawkey
RTS
CheckUnlockSequence
TST.B D0
BEQ.W Return1
BTST #7,D0
BNE.W Return1
MOVE.L UnlockPhrasePtr(PC),A3
MOVE.B (A3)+,D1
CMP.B D1,D0
BEQ.B cusskip
MOVE.L #UnlockPhrase,UnlockPhrasePtr
RTS
cusskip
CMP.B #$FF,(A3) ; end of password string
BEQ.B cusskip2
MOVE.L A3,UnlockPhrasePtr
RTS
cusskip2
MOVE.L #UnlockPhrase,UnlockPhrasePtr
MOVE.B #3,ProgLockMode
CLR.B RawKeyCode
CLR.B LastRawkey
RTS
CNOP 0,4
UnlockPhrasePtr dc.l UnlockPhrase
LockPhrase dc.l $28183327 ; 'l', 'o', 'c', 'k' key sequence
LockPhrasePtr dc.l LockPhrase
UnlockPhrase dcb.b 10,$FF
ProgLockMode dc.b 0
InitError dc.b 0
EVEN
CheckInitError
MOVE.B InitError(PC),D0
BEQ.W Return1
BTST #0,D0
BEQ.B cieskp1
JSR PLSTMemErr
cieskp1
MOVE.B InitError(PC),D0
BTST #1,D0
BEQ.B cieskp2
JSR PLSTOpenErr
JSR FreePLST
cieskp2
MOVE.B InitError(PC),D0
BTST #2,D0
BEQ.B cieskp3
JSR ConfigErr
cieskp3
MOVE.B InitError(PC),D0
BTST #3,D0
BEQ.W Return1
JSR ConfigErr2
BSR.W SetNormalPtrCol
BRA.W StorePtrCol
CheckRedraw
TST.B UpdateTempo
BEQ.B chkredr
CLR.B UpdateTempo
BSR.W SetTempo
chkredr CMP.L #'patp',RunMode
BNE.W Return1
JSR ShowPosition
JSR RefreshPosEd
TST.B PattRfsh
BEQ.W Return1
MOVE.L PattRfshNum,PatternNumber
JMP RedrawPattern
; ----------------------------------------------------------------------------
; Allocates a block of memory
;
; Input:
; D0 - byteSize
; D1 - attributes
;
; Output:
; D0 - memoryBlock (0 if alloc failed)
; ----------------------------------------------------------------------------
PTAllocMem
MOVEM.L D1/A1/A6,-(SP)
MOVE.L 4.W,A6
JSR _LVOAllocMem(A6)
MOVEM.L (SP)+,D1/A1/A6
RTS
; ----------------------------------------------------------------------------
; Frees a block of memory
;
; Input:
; A1 - memoryBlock
; D0 - byteSize
; ----------------------------------------------------------------------------
PTFreeMem
MOVEM.L D0/D1/A1/A6,-(SP)
MOVE.L 4.W,A6
JSR _LVOFreeMem(A6)
MOVEM.L (SP)+,D0/D1/A1/A6
RTS
;---- Cleanup upon exit from PT ----
ExitCleanup
JSR StopIt
SF EdEnable
BSR.W EscPressed
BSR.W EscPressed
BSR.W ResetVBInt
BSR.W ResetMusicInt
BSR.W ResetInputHandler
BSR.W SetOldCopList
JSR CloseMIDI
JSR FreeCopyBuf
errorexit1
BSR.W PTScreenToBack
BSR.W ClosePTScreen
MOVE.L 4.W,A6
MOVE.L GfxBase,A1
JSR _LVOCloseLibrary(A6)
MOVE.L IntuitionBase,A1
JSR _LVOCloseLibrary(A6)
MOVE.L DOSBase,A1
JSR _LVOCloseLibrary(A6)
TST.L PPLibBase ; did we open powerpacker.library?
BEQ.B exex1 ; no, don't attempt to close it
MOVE.L PPLibBase,A1
JSR _LVOCloseLibrary(A6)
exex1
MOVE.L TextBplPtr,D1
BEQ.B exex2
MOVE.L D1,A1
MOVE.L #27760,D0
JSR PTFreeMem
exex2 MOVE.L SongDataPtr,D1
BEQ.B exex3
MOVE.L D1,A1
MOVE.L SongAllocSize,D0
JSR PTFreeMem
exex3 BSR.W FreeDirMem
BSR.W GiveBackInstrMem
JSR FreePLST
JSR TurnOffVoices
BCLR #1,$BFE001
MOVE.B LEDStatus,D0
AND.B #2,D0
OR.B D0,$BFE001 ; Restore LED Status
MOVEQ #0,D0
MOVE.W D0,$DFF0A8 ; clear voice #1 volume
MOVE.W D0,$DFF0B8 ; clear voice #2 volume
MOVE.W D0,$DFF0C8 ; clear voice #3 volume
MOVE.W D0,$DFF0D8 ; clear voice #4 volume
MOVE.L StackSave,SP ; important! (leaking memory without it, for some reason)
Return1 RTS
;---- Open Lots Of Things ----
SetDefaultSampleReplens
MOVE.L SongDataPtr,A0
LEA sd_sampleinfo(A0),A0
MOVEQ #31-1,D0
.loop MOVE.W #1,28(A0)
LEA 30(A0),A0
DBRA D0,.loop
RTS
OpenLotsOfThings
MOVE.B $BFE001,LEDStatus
BSET #1,$BFE001
JSR TurnOffVoices
MOVEQ #0,D0
MOVE.W D0,$DFF0A8 ; clear voice #1 volume
MOVE.W D0,$DFF0B8 ; clear voice #2 volume
MOVE.W D0,$DFF0C8 ; clear voice #3 volume
MOVE.W D0,$DFF0D8 ; clear voice #4 volume
MOVE.L 4.W,A6
LEA DOSname(PC),A1 ; Open DOS library
JSR _LVOOpenLibrary(A6)
MOVE.L D0,DOSBase
LEA GraphicsName(PC),A1 ; Open graphics library
MOVEQ #0,D0
JSR _LVOOpenLibrary(A6)
MOVE.L D0,GfxBase
LEA IntuitionName(PC),A1 ; Open Intuition library
MOVEQ #0,D0
JSR _LVOOpenLibrary(A6)
MOVE.L D0,IntuitionBase
BSR.W OpenPTScreen
BEQ.W errorexit1
MOVE.L DOSBase,A6
MOVE.L rb_CurrentDir(PC),D1
JSR _LVOCurrentDir(A6)
MOVE.L #27760,D0 ; Alloc 27k CHIP textbpl
MOVE.L #MEMF_CHIP!MEMF_CLEAR,D1
JSR PTAllocMem
MOVE.L D0,TextBplPtr
BEQ.W errorexit1
MOVE.W D0,NoteBplptrLow ; set low word
SWAP D0
MOVE.W D0,NoteBplptrHigh ; set high word
MOVE.L SongAllocSize,D0
MOVE.L #MEMF_PUBLIC!MEMF_CLEAR,D1
JSR PTAllocMem
MOVE.L D0,SongDataPtr
BEQ.W errorexit1
BSR.W SetDefaultSampleReplens
MOVE.L SongDataPtr,A0
MOVE.W #$017F,sd_numofpatt(A0)
MOVE.L #'M.K.',sd_magicid(A0) ; M.K. again...
MOVEQ #6,D0
MOVE.L D0,CurrSpeed
CLR.W PEDpos
MOVE.L #ModulesPath2,PathPtr
MOVE.L #CopCol1,CopListColorPtr
MOVE.L #CopListBpl4,CopListBpl4Ptr
MOVE.L #KbdTransTable2,KeyTransTabPtr
MOVE.L #NoteNames1,NoteNamesPtr
MOVE.L #VUmeterColors,TheRightColors
MOVE.L #BitplaneData,D0 ; Set pointers to bitplane data
LEA CopListBitplanes,A1
MOVE.W D0,6(A1)
SWAP D0
MOVE.W D0,2(A1)
SWAP D0
ADD.L #10240,D0
MOVE.W D0,14(A1)
SWAP D0
MOVE.W D0,10(A1)
BSR.W SetDefSpritePtrs
BSR.W UpdateCursorPos
JSR RedrawPattern
JSR ShowPosition
JSR ShowSongLength
MOVE.W #1,InsNum
JSR ShowSampleInfo
LEA TopMenusPos,A0
LEA TopMenusBuffer,A1
MOVEQ #44-1,D0
stmloop MOVEQ #25-1,D1
stmloop2
MOVE.B (A0)+,(A1)+
MOVE.B $27FF(A0),$044B(A1)
DBRA D1,stmloop2
LEA 15(A0),A0
DBRA D0,stmloop
JSR DoResetAll
JSR cfgupda
JSR LoadConfigOnStartup ; --PT2.3D bug fix: make sure cwd is correct at this point
MOVE.L #NoteNames1,NoteNamesPtr
TST.B Accidental
BEQ.B alotskip
MOVE.L #NoteNames2,NoteNamesPtr
alotskip
TST.B OneHundredPattFlag
BEQ.B alotskip3
MOVE.L SongDataPtr,D1
BEQ.B alotskip2
MOVE.L D1,A1
MOVE.L SongAllocSize,D0
JSR PTFreeMem
alotskip2
MOVE.L #SONG_SIZE_100PAT,SongAllocSize
MOVE.L #100-1,MaxPattern
MOVE.L SongAllocSize,D0
MOVE.L #MEMF_CLEAR!MEMF_PUBLIC,D1
JSR PTAllocMem
MOVE.L D0,SongDataPtr
BEQ.W errorexit1
BSR.W SetDefaultSampleReplens
alotskip3
TST.B LoadPLSTFlag
BEQ.B ChangeCopList
JSR DoLoadPLST
ChangeCopList
TST.W SamScrEnable
BNE.W Return1
BSR.W SetupAnaCols
SetupVUCols
TST.W SamScrEnable
BNE.W Return1
LEA CopListMark2,A0 ; VUmeter coloring
MOVE.W #$B907,D5 ; Start position
LEA VUmeterColors,A5
MOVEQ #48-1,D7 ; Change 48 lines
alotlp4 MOVE.W D5,(A0)+
MOVE.W #$FFFE,(A0)+
LEA VUmeterColRegs(PC),A1
MOVEQ #2-1,D6
alotlp5 MOVE.W (A5),D4
MOVE.W (A1)+,(A0)+
MOVE.W #3,FadeX
MOVE.W D4,D0
JSR FadeCol
MOVE.W D0,(A0)+
MOVE.W (A1)+,(A0)+
MOVE.W D4,(A0)+
MOVE.W (A1)+,(A0)+
MOVE.W #$FFFD,FadeX
MOVE.W D4,D0
JSR FadeCol
MOVE.W D0,(A0)+
DBRA D6,alotlp5
ADDQ #2,A5
ADD.W #$0100,D5 ; Next line...
DBRA D7,alotlp4
RTS
VUmeterColRegs
dc.w $01AA,$01AC,$01AE,$01B2,$01B4,$01B6
CNOP 0,4
CopListBpl4Ptr dc.l 0
CopListColorPtr dc.l 0
DOSname dc.b 'dos.library',0
IntuitionName dc.b 'intuition.library',0
GraphicsName dc.b 'graphics.library',0
EVEN
SetupAnaCols
LEA CopListAnalyzer,A5
MOVE.W ColorTable+12,D2
MOVEQ #40-1,D0 ; Change col 40 lines
MOVE.W #$687D,D1 ; Start pos
TST.B ScreenAdjustFlag
BEQ.B sacloop
SUBQ.W #8,D1
sacloop MOVE.W D1,(A5)+ ; Set wait
MOVE.W #$FFFE,(A5)+
MOVE.W #$018C,(A5)+ ; Set analyzer color
ADDQ #2,A5
ADD.W #$0060,D1 ; Move x-pos
MOVE.W D1,(A5)+ ; Wait
MOVE.W #$FFFE,(A5)+
MOVE.W #$018C,(A5)+ ; Set text color
MOVE.W D2,(A5)+
ADD.W #$A0,D1 ; Next line...
DBRA D0,sacloop
TST.B DisableAnalyzer
BNE.B ClearAnalyzerColors
SetAnalyzerColors
LEA CopListAnalyzer+6,A1
LEA AnalyzerColors,A0
MOVEQ #40-1,D0 ; 40 lines
sanclop MOVE.W (A0)+,(A1)
LEA 16(A1),A1
DBRA D0,sanclop
RTS
ClearAnalyzerColors
LEA CopListAnalyzer+6,A0
MOVE.W ColorTable+12,D1
MOVEQ #40-1,D0 ; 40 lines.
cacloop MOVE.W D1,(A0)
LEA 16(A0),A0
DBRA D0,cacloop
RTS
SetSamSpritePtrs
MOVE.L #LoopSpriteData1,Ch1SpritePtr
MOVE.L #LoopSpriteData2,Ch2SpritePtr
MOVE.L #PlayPosSpriteData,Ch3SpritePtr
MOVE.L #NoSpriteData,Ch4SpritePtr
BRA.B sdsp2
SetDefSpritePtrs
MOVE.L #VUSpriteData1,Ch1SpritePtr
MOVE.L #VUSpriteData2,Ch2SpritePtr
MOVE.L #VUSpriteData3,Ch3SpritePtr
MOVE.L #VUSpriteData4,Ch4SpritePtr
sdsp2
MOVE.L #CursorSpriteData,CursorPosPtr
MOVE.L #PointerSpriteData,PointerSpritePtr
MOVE.L #LineCurSpriteData,LineCurPosPtr
MOVE.L #NoSpriteData,NoSpritePtr
MOVE.L PointerSpritePtr(PC),SpritePtrsPtr
LEA SpritePtrsPtr,A0 ; Set pointers to spritedata
LEA CopList,A1
MOVEQ #16-1,D2
alotloop2
MOVE.W (A0)+,2(A1)
ADDQ #4,A1
DBRA D2,alotloop2
RTS
CNOP 0,4
PointerSpritePtr dc.l 0
;---- Vertical Blank Interrupt ----
SetVBInt
MOVEQ #5,D0
LEA VBIntServer(PC),A1
MOVE.L 4.W,A6
JSR _LVOAddIntServer(A6)
RTS
ResetVBInt
MOVEQ #5,D0
LEA VBIntServer(PC),A1
MOVE.L 4.W,A6
JSR _LVORemIntServer(A6)
RTS
vbint
TST.B ShowRasterbar
BEQ.B .skip1
MOVE.W #$125,$DFF180 ; rasterbars to measure frame time left
.skip1
MOVEM.L D0-D7/A0-A6,-(SP)
BSR.W CheckIfProgramIsActive
BEQ.W vbiend
BSR.W Scope ; draw scopes ASAP to lower chance of flicker
BSR.W UpdatePointerPos
TST.B RealVUMetersFlag
BEQ.B .skip2
BSR.W RealVUMeters
BRA.B vbint2
.skip2 BSR.W VUMeters
vbint2 BSR.W SpecAnaInt
BSR.W ArrowKeys
BSR.W CheckKeyRepeat
MOVE.L SongPosition,CurrPos
MOVE.L SongDataPtr,A0
LEA sd_pattpos(A0),A0
ADD.L CurrPos,A0
MOVE.B (A0),D1
MOVE.B D1,PattRfshNum+3
CMP.B LongFFFF+3,D1
BEQ.B vbiskip
ST PattRfsh
vbiskip
MOVE.B D1,LongFFFF+3
TST.B PattRfsh
BNE.B vbiskip2
TST.W BlockMarkFlag
BNE.B vbiskip2
TST.B UpdateTempo
BNE.B vbiskip2
TST.W KeyBufPos
BEQ.B vbiskip3
vbiskip2
MOVE.L 4.W,A6
MOVE.L PTProcess(PC),A1
MOVE.L #$20000000,D0
JSR _LVOSignal(A6)
vbiskip3
BTST #6,$BFE001 ; left mouse button
BNE.B vbiskip4
MOVE.L 4.W,A6
MOVE.L PTProcess(PC),A1
MOVE.L #$10000000,D0
JSR _LVOSignal(A6)
vbiskip4
; bit of a kludge to get scope muting working
TST.B RightMouseButtonHeld
BEQ.B rmbnotheld
rmbheld
BTST.B #10-8,$DFF016
BEQ.B rmbreleased
BRA.B vbiend
rmbnotheld
BTST.B #10-8,$DFF016
BEQ.B vbiend
ST RightMouseButtonHeld
BRA.B vbiend
rmbreleased
CLR.B RightMouseButtonHeld
BSR.W CheckScopeMuting
vbiend
JSR StackNumberText
BSR.W UpdateTicks
JSR SetBackNumberText
MOVEM.L (SP)+,D0-D7/A0-A6
TST.B ShowRasterbar
BEQ.B .skip2
MOVE.W #0,$DFF180 ; rasterbars to measure frame time left
.skip2
RTS
CNOP 0,4
VBIntServer
dc.l 0,0
dc.b 2,0 ; type, priority
dc.l vbintname
dc.l 0,vbint
vbintname dc.b 'ProTracker VBlank',0
EVEN
CheckRedraw2
MOVEM.L D0-D7/A0-A6,-(SP)