/
led_cue.asm
executable file
·1648 lines (1428 loc) · 48.7 KB
/
led_cue.asm
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
;*****************************************************************************
; PIC18F family - cues and playback code
;*****************************************************************************
;
; Filename: led_cue.asm
; Author, Company: Alden Hart, Luke's Lights
; Chip Support: Supports PIC18F family
; Revision: 091130
;
;*****************************************************************************
; A CUE is a single lighting event that may involve a dynamic or repeating fade
; CUES are made of one or more individual commands (CMDs)
; A set of CUEs that run in sequence are a PLAYLIST (aka cue list, cue sheet)
; PLAYBACK is automatically playing one cue after another by detecting cue ends
;
; DISCUSSION OF TABLES AND POINTERS (see spreadsheet Playlists tab for details).
; There is a hierarchy of tables:
; - Playlist Master table
; - Playlist_XXX tables (one of which will be the "active" playlist)
; - Cue_XXX tables (one of which will be the "current" cue)
;
; The playlist master table is a collection of 16 bit pointers to one or more
; playlist tables, and is always terminated by PLAYLIST_DONE (0x0000). It is
; also be preceded by PLAYLIST_DONE to support backwards navigation.
;
; The play_master_ptr_hi/lo pointer (master prointer) is initialized to the
; first location of the master table. A helper function is provided to reset
; this pointer. The pointer is manipulated using the PLAY_GET_NEXT_PLAYLIST
; and PLAY_GET_PREV_PLAYLIST calls. GET_NEXT will wrap to the beginning of
; the table on overflow. GET_PREV will stick at the beginning. There are no
; looping or jump commands in this table. The master pointer can also be set
; directly using the PLAYLIST command from the serial port (or in a cue?).
;
; The playlist pointed to by the master pointer is considered the "active playlist".
;
; The play_ptr_hi/lo pointer (playlist pointer) points to the current cue in the
; active playlist. By convention the pointer is not advanced until it's needed
; (i.e. it's pre-incremented). The playlist pointer is manipulated using the
; PLAY_GET_NEXT_CUE function - which executes all increments, looping, jumps,
; DONE and CODA handling. There is no PLAY_GET_PREV_CUE command.
;
; The cue pointed to by the play_ptr_hi/lo is considered the "current cue".
;
; The cue_ptr_hi/lo pointer (cue pointer) points to the command in the
; current cue. Since all commands in a cue are run to completion, the cue
; pointer is a more dynamic pointer than the playlist pointers. The cue pointer
; is under the control of the CUE_RUN_NEXT_CUE and CUE_LOAD_CUE functions
; which use various navigation functions to move this pointer.
;
; I'm not sure if I have the dividing line between the playlist functions and
; the cue functions exactly right.
;----- Include files and other setup------
#include <global.inc> ; 1: global defines - must be first
#include <DEV_INCLUDE_FILE> ; 2: Our device include file
#include <LED_INCLUDE_FILE> ; 3: LED subsystem include file
#include <APP_INCLUDE_FILE> ; 4: Application include file
;------ Exports (globals) - specific to the clock application -----
global CUE_CLK_READOUT ; application specific routine
global cue_clk_min
global cue_clk_hour
;------ Needed to export these just so I could WATCH them. MPLAB bug?
global cue_clk_min_plus
global cue_clk_min_five
global cue_ptr_hi
global cue_ptr_lo
;------ Exports (globals) - not application specific -----
global PLAY_INIT
global cue_watch ; used by command loader only
global CUE_WATCHER
global UT_PLAY ; playlist and cues unit tests
;----- External variables and FUNCTIONS -----
extern chn_num ; channel number
extern chn_level ; circuit level
extern CKT_WRITE_CHANNEL ; write a mono value or RGB triplet to ckt table
extern cmd_buffer ; command input buffer
extern CMD_VALIDATE_CMDCODE ; validate command code
extern CMD_LOADER
extern FDR_TEST_FDR_DONE ; returns Z=1 if fader is done or inactive
extern temp_tblptrh
extern temp_tblptrl
;------ RAM definitions -----
;##### BANK 0 #####
UDATA_BANK_0_ACS udata_acs ; linker allocates space in bank 0
; application specific variables (clock application)
cue_clk_hour res 1 ; hour to read out
cue_clk_min res 1 ; minutes to read out
cue_clk_min_five res 1 ; minutes by 5 minutes counter (0-11)
cue_clk_min_plus res 1 ; minutes plus signs isolated (0-4)
; general variables
play_master_ptr_hi res 1 ; playlist master table pointer
play_master_ptr_lo res 1
play_ptr_hi res 1 ; active playlist table pointer
play_ptr_lo res 1
cue_ptr_hi res 1 ; current cue table pointer
cue_ptr_lo res 1
cue_num_hi res 1 ; cue number hi/lo
cue_num_lo res 1
cue_fsr1_temp_hi res 1 ; needed for GET_ARGUMENT
cue_fsr1_temp_lo res 1
;cue_loop_end_addr_hi res 1 ; end address of a CUE_LOOP command
;cue_loop_end_addr_lo res 1
cue_command res 1 ; command code (4 bits)
cue_argcount res 1 ; command argument count (4 bits)
cue_argnum res 1 ; argment number being processed
cue_argmask res 1 ; argument bitmask, args <7-0>
cue_argmask_hi res 1 ; argument bitmask, args <F-8>
cue_argvalue res 1 ; argument value as read from the table
cue_argflags res 1 ; set b0 to signal there are upper args
cue_loop_work res 1 ; working register for loop counting
cue_loop_counter res 1 ; counter for LOOP commands
cue_loop_table_hi res 1
cue_loop_table_lo res 1
cue_opcode res 1 ; argument opcode byte
cue_op1 res 1 ; argument operand 1
cue_op2 res 1 ; argument operand 2
cue_op3 res 1 ; argument operand 3
cue_watch res 1 ; cue DONE watch register
;##### BANK 3 #####
;UDATA_ARG_TABLE udata 0x300 ; argtable must be on a page boundary
; or you must change CUE_SET_ARG_ADDR
arg_table res 4*(ARG_NUM_MAX+1)
;###############################
;##### BEGIN CODE SECTION ######
;###############################
CODE_LED_CUE_CODE code
;*****************************************************************************
;***** WCLOCK APPLICATION SPECIFIC ROUTINES **********************************
;*****************************************************************************
;******************************************************************************
; CUE_CLK_READOUT - Read out the clock display from the clock registers
;
; Normally called from the main loop each time FLAG_MINUTE is set by CLK_ISR.
; It can also be called as part of setting the clock
;
; INPUTS (expected to be loaded when routine is called)
; - cue_clk_min ; minutes to read out
; - cue_clk_hour ; hour to read out
; USES: - cue_clk_min_five ; 5 minute marks (0-11)
; - cue_clk_min_plus ; minutes beyond the 5 minute mark (0-4)
;
; Generating the cue_clk_min_five and cue_clk_min_plus terms is tricky without
; having a ready division function. To generate the _five term, dividing by 5
; is the same as multiplying by 1/5, which is 256/5 = 51.2. Using 52 has an
; error term that's small enough not to present a problem in the 0-59 range.
; Result is in PRODH. (By the way, this breaks when you hit 64/5, so this
; method will not work above 63/5)
;
; The cue_clk_min_plus term can be derived by multiplying the remainder (PRODL)
; by 5 and picking the result out of PRODH.
CUE_CLK_READOUT
; generate the cue_clk_min_five and cue_clk_min_plus terms
movf cue_clk_min,W ; divide 0-59 by 5 (multiply by 52)
mullw .52 ; changes every 5 minutes...
movff PRODH,cue_clk_min_five ; ...varies from 0 - 11
movf PRODL,W ; now go get the _plus term
mullw .5 ; changes every minute...
movff PRODH,cue_clk_min_plus ; ...varies from 0 - 4
; removed next 2 instructions or time set functions won't work reliably
; movf PRODH,W ; test for 5 minute boundaries
; bnz CCR_EXIT ; only update on 5 minute marks
; adjust hours. We use an hour from twenty-five to, to half-past
movf cue_clk_min_five,W
sublw .6 ; find "twenty-five to" division
bnn CCR_DSP
movf cue_clk_hour,W
sublw .12 ; adjust hour forward, with rollover
btfsc STATUS,Z
clrf cue_clk_hour ; sets hour to 1 if it's 12 o'clock
incf cue_clk_hour,F
CCR_DSP ; display routines (see global.inc for macro listings)
call CUE_CLK_LOADER
; display minutes preamble and o'clock postfix
; tblindx CLK_MINUTES_MAP, cue_clk_min_five ; set index into MIN map
; tblread cue_ptr_hi, cue_ptr_lo ; set cue_ptr from MIN map
; call CUE_LOAD_CUE
; display hours
; tblindx CLK_HOURS_MAP, cue_clk_hour ; set index into HOURS map
; tblread cue_ptr_hi, cue_ptr_lo ; set cue_ptr from HOURS map
; call CUE_LOAD_CUE
CCR_EXIT
return
;--- CUE_CLK_LOADER -
; Load tables into channels
; First load the 5min values, then load the hours
CUE_CLK_LOADER
movlw CHN_NUM_MAX ; turn all channels off
movwf chn_num
CCL2 clrf chn_level
call CKT_WRITE_CHANNEL
decf chn_num
bnn CCL2
;#### THIS CODE SEGMENT CANNOT CROSS A 0x100 PROGRAM MEMORY BOUNDARY
movlw HIGH CCL_MIN
movwf PCLATH
rlncf cue_clk_min_five,W ; get index x2 into W...
addlw LOW CCL_MIN ;...this only works with BRAs
movwf PCL ;...GOTOs require x4
CCL_MIN bra _min00 ; dispatch to 00 minutes
bra _min05
bra _min10
bra _min15
bra _min20
bra _min25
bra _min30
bra _min35
bra _min40
bra _min45
bra _min50
bra _min55
CCL_HOURS
movlw HIGH CCL_HR
movwf PCLATH
rlncf cue_clk_hour,W ; get index x2 into W...
addlw LOW CCL_HR ;...this only works with BRAs
movwf PCL ;...GOTOs require x4
CCL_HR bra _hour00 ; NULL never happens
bra _hour01
bra _hour02
bra _hour03
bra _hour04
bra _hour05
bra _hour06
bra _hour07
bra _hour08
bra _hour09
bra _hour10
bra _hour11
bra _hour12
; #### TO HERE
ccload macro channel, level
movlw level
movwf chn_level
movlw channel
movwf chn_num
call CKT_WRITE_CHANNEL
endm
_min00 ccload OCLOCK, LIT
bra CCL_HOURS
_min05 ccload ITS, LIT
ccload FIVE_, LIT
ccload MINUTES, LIT
ccload PAST, LIT
bra CCL_HOURS
_min10 ccload ITS, LIT
ccload TEN_, LIT
ccload PAST, LIT
bra CCL_HOURS
_min15 ccload ITS, LIT
ccload QUARTER, LIT
ccload PAST, LIT
bra CCL_HOURS
_min20 ccload ITS, LIT
ccload TWENTY, LIT
ccload PAST, LIT
bra CCL_HOURS
_min25 ccload ITS, LIT
ccload TWENTY, LIT
ccload FIVE_, LIT
ccload MINUTES, LIT
ccload PAST, LIT
bra CCL_HOURS
_min30 ccload ITS, LIT
ccload HALF, LIT
ccload PAST, LIT
bra CCL_HOURS
_min35 ccload ITS, LIT
ccload TWENTY, LIT
ccload FIVE_, LIT
ccload TO_, LIT
bra CCL_HOURS
_min40 ccload ITS, LIT
ccload TWENTY, LIT
ccload MINUTES, LIT
ccload TO_, LIT
bra CCL_HOURS
_min45 ccload ITS, LIT
ccload QUARTER, LIT
ccload TO_, LIT
bra CCL_HOURS
_min50 ccload ITS, LIT
ccload TEN_, LIT
ccload MINUTES, LIT
ccload TO_, LIT
bra CCL_HOURS
_min55 ccload ITS, LIT
ccload FIVE_, LIT
ccload MINUTES, LIT
ccload TO_, LIT
bra CCL_HOURS
_hour00 ccload ONE, LIT
bra CCL_HOURS
_hour01 ccload ONE, LIT
bra CCL_HOURS
_hour02 ccload TWO, LIT
bra CCL_HOURS
_hour03 ccload THREE, LIT
bra CCL_HOURS
_hour04 ccload FOUR, LIT
bra CCL_HOURS
_hour05 ccload FIVE, LIT
bra CCL_HOURS
_hour06 ccload SIX, LIT
bra CCL_HOURS
_hour07 ccload SEVEN, LIT
bra CCL_HOURS
_hour08 ccload EIGHT, LIT
bra CCL_HOURS
_hour09 ccload NINE, LIT
bra CCL_HOURS
_hour10 ccload TEN, LIT
bra CCL_HOURS
_hour11 ccload ELEVEN, LIT
bra CCL_HOURS
_hour12 ccload TWELVE, LIT
bra CCL_HOURS
;*****************************************************************************
;***** PLAYLIST LEVEL FUNCTIONS **********************************************
;*****************************************************************************
;*****************************************************************************
; PLAY_INIT Init playback module and load first cue
;
; INPUTS: <none>
; RETURNS: <none>
PLAY_INIT
call _PLAY_RESET_MASTER_PTR ; init playlist master table pointer
call _PLAY_SET_PLAY_PTR ; set active playlist pointer from master
call _PLAY_SET_CUE_PTR ; set cue pointer from playlist pointer
call CUE_LOAD_CUE ; start playlist at first cue
return
;*****************************************************************************
; PLAY_GET_NEXT_PLAYLIST Advance to next playlist
; PLAY_GET_PREV_PLAYLIST Back up to previous playlist
;
; INPUTS: play_master_ptr_hi/lo current state
;
; RETURNS: play_master_ptr_hi/lo next/previous state
; play_ptr_hi/lo set to value in master playlist
;
; PLAYLIST_DONE is technically treated as a CODA (which also would test positive)
PLAY_GET_NEXT_PLAYLIST
call _PLAY_INCR_MASTER_PTR
bra PGP_01
PLAY_GET_PREV_PLAYLIST
call _PLAY_DECR_MASTER_PTR
PGP_01 call _PLAY_SET_PLAY_PTR
movf play_ptr_hi,W ; test pointer for master playlist DONE
xorlw HIGH PLAYLIST_DONE ; test for both list overflow and underflow
bz PGP_RESTART ; if MSByte is zer, restart the master list
return ; otehrwise return without pointer adjustment
PGP_RESTART
call _PLAY_RESET_MASTER_PTR
call _PLAY_SET_PLAY_PTR
return
;*****************************************************************************
; PLAY_RUN_NEXT_CUE Run next cue in active playlist
;
PLAY_RUN_NEXT_CUE
call PLAY_GET_NEXT_CUE ; get the next cue
bnz PRNC_OK ; if Z=0 exit with no cue load
call CUE_LOAD_CUE ; run the next cue
PRNC_OK return
;*****************************************************************************
; PLAY_GET_NEXT_CUE Get next cue in active playlist.
; Handles DONE, CODA, LOOPs and JUMPs.
;
; INPUTS: cue_ptr_hi/lo points to current cue in active playlist
;
; RETURNS: Z=1 pointer advanced successfully (cue should be exectuted)
; Z=0 pointer did not advance because: (do not run cue)
; - DONE encountered
; - error detected
PLAY_GET_NEXT_CUE
; read next cue pointer from active playlist
call _PLAY_INCR_PLAY_PTR ; increment play pointer to next cue
call _PLAY_SET_CUE_PTR ; set cue pointer from playlist pointer
; test cue pointer for playlist DONE or CODA
movf cue_ptr_hi,W
bnz PGNC_01 ; if MSbyte is not zero skip these tests
movf cue_ptr_lo,W
xorlw LOW PLAYLIST_DONE ; test for DONE
bz PGNC_DONE ; it's done - exit OK
movf cue_ptr_lo,W ; test for CODA
xorlw LOW PLAYLIST_CODA
bnz PGNC_ERR ; it's not DONE or CODA - error
call _PLAY_SET_PLAY_PTR ; it's a CODA. (Re)set playlist ptr from master
call _PLAY_SET_CUE_PTR ; set cue pointer from playlist pointer
PGNC_01 ; put looping controls here
PGNC_OK bsf STATUS,Z ; OK exit. Run next cue
retlw ERR_NO_ERROR
PGNC_DONE ; DONE exit. Do not run next cue
bcf STATUS,Z
retlw ERR_NO_ERROR
PGNC_ERR ; Error exit. Do not run next cue
bcf STATUS,Z
retlw ERR_BAD_COMMAND
;*****************************************************************************
; Playlist helper routines
;
_PLAY_RESET_MASTER_PTR ; reset playlist master pointer
movlw HIGH PLAYLIST_MASTER_TABLE
movwf play_master_ptr_hi
movlw LOW PLAYLIST_MASTER_TABLE
movwf play_master_ptr_lo
return
_PLAY_INCR_MASTER_PTR ; increment playlist master pointer
movlw 0x02
addwf play_master_ptr_lo,F
movlw 0x00
addwfc play_master_ptr_hi,F
return
_PLAY_DECR_MASTER_PTR ; decrement playlist master pointer
movlw 0x02
subwf play_master_ptr_lo,F
movlw 0x00
subwfb play_master_ptr_hi,F
return
_PLAY_SET_PLAY_PTR ; set playlist pointer from master pointer
movff play_master_ptr_hi,TBLPTRH
movff play_master_ptr_lo,TBLPTRL
tblrd*+
movff TABLAT,play_ptr_lo
tblrd*+
movff TABLAT,play_ptr_hi
return
_PLAY_INCR_PLAY_PTR ; increment playlist pointer
movlw 0x02
addwf play_ptr_lo,F
movlw 0x00
addwfc play_ptr_hi,F
return
_PLAY_SET_CUE_PTR ; set cue pointer from playlist pointer
movff play_ptr_hi,TBLPTRH
movff play_ptr_lo,TBLPTRL
tblrd*+
movff TABLAT,cue_ptr_lo
tblrd*+
movff TABLAT,cue_ptr_hi
return
;*****************************************************************************
;***** CUE LEVEL FUNCTIONS ***************************************************
;*****************************************************************************
;*****************************************************************************
; CUE_WATCHER Test cue_watch for cue done & run cue if needed
;
; See if the current cue is finished by checking the fade channel status.
; Run the next cue in the active playlist if this is true
;
; INPUTS: cue_watch watch state:
; 0x00 - 0xNN - Check fader NN for DONE & load cue if true
; 0xFE (NOW) - Load next cue right now.
; 0xFF (NEVER) - Never load next cue (disabled).
CUE_WATCHER
movf cue_watch,W ; test for NEVER condition
xorlw NEVER
bz CUW_EXIT_NO_CHANGE
movf cue_watch,W ; test for NOW condition
xorlw NOW
bz CUW_RUN_NEXT_CUE
call FDR_TEST_FDR_DONE ; test watched fader channel for completion status
bz CUW_EXIT_NO_CHANGE
CUW_RUN_NEXT_CUE
call PLAY_RUN_NEXT_CUE
CUW_EXIT_NO_CHANGE
return
;*****************************************************************************
; CUE_RUN_CUE Run a cue from cue table by mumber
;
; INPUTS cue_num_hi cue number to run
; cue_num_lo
;
; FUNCTION Calls CUE_LOAD_CUE with cue pointer from CUE_NUMBER_TABLE
CUE_RUN_CUE
tblindx CUE_NUMBER_TABLE, cue_num_lo ; set table pointer
tblrd*+
movff TABLAT,cue_ptr_lo
tblrd*
movff TABLAT,cue_ptr_hi
call CUE_LOAD_CUE
return
;*****************************************************************************
; CUE_LOAD_CUE Load an entire cue from cue_ptr_hi/lo cue pointer
;
CUE_LOAD_CUE
movff cue_ptr_lo,TBLPTRL ; setup the table pointer
movff cue_ptr_hi,TBLPTRH
movlw NEVER ; clear the watch register
movwf cue_watch
PLP_01 call CUE_GET_NEXT_COMMAND ; loop in the command
btfsc STATUS,Z
bra PLP_01
return
;*****************************************************************************
; CUE_GET_NEXT_COMMAND Get and execute next command from cue
;
; INPUTS TBLPTR points to CUE_xxxx in code space as per the following:
; - CUE_DONE
; - CUE_CMD
; - CUE_ARG
; - CUE_LOOP
; - CUE_LOOP_BLOCK
; - CUE_JUMP
;
; RETURN TBLPTR points to next CUE_xxxx byte in string
; - Z=0 signals an error occurred in processing (errcode in Z)
; - Z=1 signals processing occurred OK
;
; USES:
; - FSR1 primary memory pointer (trashed)
; - FSR2 used in some ARG cases (might be trashed)
;
; See CUE_GET_COMMAND for details of the command structure
CUE_GET_NEXT_COMMAND
tblrd*+ ; read CUE_xxx byte (with post increment)
movf TABLAT,W
sublw CUE_MAX+1
bc CGN_01
bcf STATUS,Z
retlw ERR_GET_NEXT_CMD_FAILED
CGN_01 rlncf TABLAT,W ; get CUE_xxxxx code x2 into W...
switch
data CGN_DONE
data CGN_COMMAND
data CGN_ARGUMENT
data CGN_LOOP
data CGN_LOOP_LOCAL
data CGN_LOOP_REMOTE
data CGN_JUMP
CGN_DONE
bcf STATUS,Z ; signal DONE
retlw ERR_NO_ERROR
CGN_COMMAND
call CUE_GET_COMMAND ; this will pass back OK or ERR condition
bra CGN_EXIT
CGN_ARGUMENT
call CUE_SET_ARGUMENT
bra CGN_EXIT
CGN_LOOP
tblrd*+ ; get repeat counter
movff TABLAT,cue_loop_counter
tblrd*+ ; read the CUE_COMMAND code
movf TABLAT,W
xorlw CUE_CMD
bz CGNL01
bcf STATUS,Z
retlw ERR_BAD_COMMAND ; return if error (with Z=0)
CGNL01 movff TBLPTRH,cue_loop_table_hi ; save the command starting address
movff TBLPTRL,cue_loop_table_lo
CGNL02 movff cue_loop_table_hi,TBLPTRH ; restore command starting address
movff cue_loop_table_lo,TBLPTRL
call CUE_GET_COMMAND ; this will pass back OK or ERR condition
btfss STATUS,Z
retlw ERR_BAD_COMMAND ; return if error (with Z=0)
decfsz cue_loop_counter
bra CGNL02
bra CGN_EXIT
CGN_LOOP_LOCAL
bra CGN_EXIT
CGN_LOOP_REMOTE
bra CGN_EXIT
CGN_JUMP
bra CGN_EXIT
CGN_EXIT
bsf STATUS,Z
return
;*****************************************************************************
; CUE_GET_COMMAND Get single command from cue (into FDR_LOADER buffer)
;
; INPUTS:
; - TBLPTR points to cmd byte in code space as per the following:
; CUE_CMD, cmd, argmask, arg0....argN (see below)
; RETURNS:
; - chn_num set to channel number of command
; - FSR1 points to beginning of command buffer --
; suitable for passing to FDR_LOADER
; - TBLPTR points to next byte in in-memory cue string
; - Z=0 signals an error occurred in processing
; - Z=1 signals processing occurred OK
;
; Commands are represented by the following bytes:
; - cmd full command w/arg count (see color64.inc for defs)
; MSdigit is command code, LSdigit is arg count (zero based)
;
; - argmask single-byte bitfield organized <b7-b0> corresponding to
; arg7 - arg0 for all commands except FADE 0x48, 0x49
; and 0x4A which require a preceding byte to encode the
; upper bits as <bF-b8> corresponding to arg 0x0F - 0x08.
; If a bit is clear the literal value present in the
; following arg string will be used. If a bit is set
; then the arg at that location will be treated as an
; arg number, and the value computed from the arg of that
; number. If the arg number is greater than the max arg
; number an error will be returned.
;
; - arg0 first arg in the arg string
; - arg1 second arg in the arg string
; ....
; - argN Nth arg in the arg string
;
CUE_GET_COMMAND
tblrd*+ ; read cmd
movf TABLAT,W
call CMD_VALIDATE_CMDCODE
btfss STATUS,Z
retlw ERR_BAD_COMMAND ; return if error (with Z=0)
; initialize context - each CGC_xxx gets the folling setup for them:
; - cue_command = command code in lower 4 bits
; - cue_argcount = number of args, 1 based
; - cue_argmask = lower argmask (or upper if there are 2 argmask bytes)
; - TBLPTR pointing to arg0 (or lower argmask if tehre are 2 argmask bytes)
;
lfsr 1,cmd_buffer ; initialize command buffer pointer
movwf POSTINC1 ; save command code in first byte
movwf cue_argcount ; isolate & save arg count...
movwf cue_command ;...and command digit
swapf cue_command,F
movlw 0x0F
andwf cue_argcount,F
andwf cue_command,F
tblrd*+ ; get first argument bitmask
movff TABLAT,cue_argmask ; will fix later if cmd has > 8 args
; dispatch on command codes
rlncf cue_command,W ; get command code x2 into W...
switch
data CGC_ERROR ; 00 = no command - error exit
data CGC_SET_BRT
data CGC_SET_HSB
data CGC_SET_RGB
data CGC_PATCH
data CGC_FADE
data CGC_WATCH
CGC_ERROR ; error return
bcf STATUS,Z
retlw ERR_GET_COMMAND_FAILED
;--- SET_BRT command handler ----
;--- SET_HSB command handler ----
;--- PATCH command handler ----
; Same code works for all commands
CGC_SET_BRT
CGC_SET_HSB
CGC_PATCH
movff cue_argcount,cue_loop_work
incf cue_loop_work,F ; increment to make counting easier
CGC_H1 tblrd*+ ; get and save arg value
movff TABLAT,cue_argvalue
btfsc cue_argmask,0 ; bit of interest in argmask is found in LSB
call CUE_GET_ARGUMENT ; perform arg reeplacement - returns in argvalue
movff cue_argvalue,POSTINC1 ; move the value in
rrncf cue_argmask,F ; shift next arg bitmask value into bit 0
decfsz cue_loop_work,F ; looping test
bra CGC_H1
call CGC_COMMON_EXIT ; load command into comamnd table and exit
return
;--- SET_HSB command handler ----
CGC_SET_RGB ; ++++++ not implemented
return
;--- WATCH command handler ----
CGC_WATCH
tblrd*+ ; get and save WATCH circuit or arg value
movff TABLAT,cue_argvalue ; save in arg_value
btfsc cue_argmask,0 ; bit of interest in argmask is found in LSB
call CUE_GET_ARGUMENT ; perform arg replacement - returns in argvalue
movff cue_argvalue,POSTINC1 ; move the value in
call CGC_COMMON_EXIT ; load command into comamnd table and exit
return
;--- FADE command handler ----
CGC_FADE
clrf cue_argflags ; initialize flags (ARG_HI_FLAG is zeroed)
movf cue_argcount,W
sublw 0x07 ; test if a larger argmask is required
bc CGC_P1
movff cue_argmask, cue_argmask_hi
tblrd+* ; get second argument bitmask
movff TABLAT,cue_argmask
bsf cue_argflags,ARG_HI_FLAG ; signal that there are upper args
movlw 0x08
movwf cue_loop_work ; set loop counter to do all 8 lo args
bra CGC_P2
; do lower (up to) 8 arguments
CGC_P1 movff cue_argcount,cue_loop_work
incf cue_loop_work,F ; increment to make counting easier
CGC_P2 tblrd*+ ; get and save arg value
movff TABLAT,cue_argvalue
btfsc cue_argmask,0 ; bit of interest in argmask is found in LSB
call CUE_GET_ARGUMENT ; perform arg replacement - returns in argvalue
movff cue_argvalue,POSTINC1 ; move the value in
rrncf cue_argmask,F ; shift next arg bitmask value into bit 0
decfsz cue_loop_work,F ; looping test
bra CGC_P2
; test for and do upper (up to) 8 arguments
btfss cue_argflags,ARG_HI_FLAG
bra CGC_COMMON_EXIT ; load command into command table
movlw 0x07 ; 8 minus 1
subwf cue_argcount,W
movwf cue_loop_work ; set loop counter
CGC_P3 tblrd*+ ; get and save arg value
movff TABLAT,cue_argvalue
btfsc cue_argmask_hi,0 ; bit of interest in argmask is found in LSB
call CUE_GET_ARGUMENT ; perform arg replacement - returns in argvalue
movff cue_argvalue,POSTINC1 ; move the value in
rrncf cue_argmask_hi,F ; shift next arg bitmask value into bit 0
decfsz cue_loop_work,F
bra CGC_P3
;---- COMMON EXIT for PGC routines ----
; Load command into the command table and exit with status propogated from loader
CGC_COMMON_EXIT
; load the command into the command table
lfsr 1,cmd_buffer ; initialize command buffer pointer
call CMD_LOADER ; load command (TBLPTR must be preserved)
; bsf STATUS,Z
return
;*****************************************************************************
; CUE_SET_ARGUMENT Load an argument structure into arg cell
;
; INPUTS:
; - TBLPTR points to argnum in code space as per the following:
; CUE_ARG, argnum, opcode, var1, [var2], [var3]
; RETURNS:
; - TBLPTR points to next CUE_xxxx byte in string
; - Z=0 signals an error occurred in processing
; - Z=1 signals processing occurred OK
; Command arguments (args) are 4 byte structures that perform substitutions
; for command variables during command loads. Args can perform literal
; substitution for variables or a variety of simple math functions. Structure:
;
; - Arg number args number 0 - N. Implicit based on location in table
; - Opcode operation to perform during argument substitution
; - Operand1 (op1) first operand interprested by opcode
; - Operand2 (op2) second operand interprested by opcode
; - Operand3 (op3) thirg operand interprested by opcode
;
; Op2 and op3 can be used as a 16 bit address - refered to as "addr".
; See Argument OPCODE definitions for opcode details
;
; opcode var1 var2 var3 usage
; OP_LIT value --- --- ; use op1 as literal value
; OP_INC start --- --- ; use op1, post increment & store in op1
; OP_INC_RANGE start max min ; inc by 1 [op2=max, op3=min], store in op1
; OP_INCX2_RANGE start max min ; inc by 2 [op2=max, op3=min], store in op1
; OP_INCX3_RANGE start max min ; inc by 3 [op2=max, op3=min], store in op1
; OP_INCX4_RANGE start max min ; inc by 4 [op2=max, op3=min], store in op1
; OP_DEC start --- --- ; use op1, post decrement & store in op1
; OP_DEC_RANGE start max min ; dec by 1 [op2=max, op3=min], store in op1
; OP_DECX2_RANGE start max min ; dec by 2 [op2=max, op3=min], store in op1
; OP_DECX3_RANGE start max min ; dec by 3 [op2=max, op3=min], store in op1
; OP_DECX4_RANGE start max min ; dec by 4 [op2=max, op3=min], store in op1
; OP_ADD start add --- ; (op1+op2), save result in op1
; OP_ADD_AND start add and ; (op1+op2), AND with op3, do not save result
; OP_ADD_AND_SAVE start add and ; (op1+op2), AND with op3l, save result in op1
; OP_ADD_IND start ind --- ; (op1+op2(op1)), do not save result
; OP_ADD_IND_SAVE start ind --- ; (op1+op2(op1)), save result in op1
; OP_ADD_IND_AND start ind and ; (op1+op2(op1)), AND with op3, do not save
; OP_ADD_IND_AND_SAVE srt ind and ; (op1+op2(op1)), AND with op3, save in op1
; OP_SUB start sub --- ; (op1-op2), save result in op1
; OP_SUB_AND start sub and ; (op1-op2), AND with op3, do not save result
; OP_SUB_AND_SAVE start sub and ; (op1-op2), AND with op3, save in op1
; OP_SUB_IND start ind --- ; (op1-op2(op1)), do not save result
; OP_SUB_IND_SAVE start ind --- ; (op1-op2(op1)), save result in op1
; OP_SUB_IND_AND start ind and ; (op1-op2(op1)), AND with op3, do not save
; OP_SUB_IND_AND_SAVE srt ind and ; (op1-op2(op1)), AND with op3, save in op1
; OP_RAND seed --- --- ; pseudo-random#, op1=seed, update seed
; OP_RAND_RANGE seed max min ; pseudo-random# [op2=max, op3=min], op1=seed
CUE_SET_ARGUMENT
tblrd*+ ; read argnum
movf TABLAT,W
call CUE_SET_ARG_ADDR ; set FSR to opcode in arg_table
tblrd*+ ; get the opcode (keep in TABLAT)
movf TABLAT,W
sublw OP_OPCODE_MAX ; test for error in opcode value
bc CSA_DSP
bcf STATUS,Z ; return with error
retlw ERR_BAD_OPCODE
; dispatch on opcode
CSA_DSP rlncf TABLAT,W ; get opcode x2 into W...
switch
data CSA_OP_LIT ; start --- ---
data CSA_OP_INC ; start --- ---
data CSA_OP_INC_RANGE ; start max min
data CSA_OP_INCX2_RANGE ; start max min
data CSA_OP_INCX3_RANGE ; start max min
data CSA_OP_INCX4_RANGE ; start max min
data CSA_OP_DEC ; start --- ---
data CSA_OP_DEC_RANGE ; start max min
data CSA_OP_DECX2_RANGE ; start max min
data CSA_OP_DECX3_RANGE ; start max min
data CSA_OP_DECX4_RANGE ; start max min
data CSA_OP_ADD ; start add ---
data CSA_OP_ADD_AND ; start add and
data CSA_OP_ADD_AND_SAVE ; start add and
data CSA_OP_ADD_IND ; start ind ---
data CSA_OP_ADD_IND_SAVE ; start ind ---
data CSA_OP_ADD_IND_AND ; start ind and
data CSA_OP_ADD_IND_AND_SAVE ; start ind and
data CSA_OP_SUB ; start sub ---
data CSA_OP_SUB_AND ; start sub and
data CSA_OP_SUB_AND_SAVE ; start sub and
data CSA_OP_SUB_IND ; start ind ---
data CSA_OP_SUB_IND_SAVE ; start ind ---
data CSA_OP_SUB_IND_AND ; start ind ---
data CSA_OP_SUB_IND_AND_SAVE ; start ind ---
data CSA_OP_RAND ; seed --- ---
data CSA_OP_RAND_RANGE ; seed max min
CSA_OP_INC_RANGE ; start max min
CSA_OP_INCX2_RANGE ; start max min
CSA_OP_INCX3_RANGE ; start max min
CSA_OP_INCX4_RANGE ; start max min
CSA_OP_DEC_RANGE ; start max min
CSA_OP_DECX2_RANGE ; start max min
CSA_OP_DECX3_RANGE ; start max min
CSA_OP_DECX4_RANGE ; start max min
CSA_OP_ADD_AND ; start add and
CSA_OP_ADD_AND_SAVE ; start add and
CSA_OP_ADD_IND_AND ; start ind and
CSA_OP_ADD_IND_AND_SAVE ; start ind and
CSA_OP_SUB_AND ; start sub and
CSA_OP_SUB_AND_SAVE ; start sub and
CSA_OP_SUB_IND_AND ; start ind and
CSA_OP_SUB_IND_AND_SAVE ; start ind and
CSA_OP_RAND_RANGE ; seed max min
; args w/ op1, op2, op3
tblrd*+ ; get op1
movff TABLAT,POSTINC1 ; move to arg table
; args w/ op1, op2
CSA_OP_ADD ; start add ---
CSA_OP_ADD_IND ; start ind ---
CSA_OP_ADD_IND_SAVE ; start ind ---
CSA_OP_SUB ; start sub ---
CSA_OP_SUB_IND ; start ind ---
CSA_OP_SUB_IND_SAVE ; start ind ---
tblrd*+ ; get op1 or op2
movff TABLAT,POSTINC1 ; move to arg table
; args w/ op1 only
CSA_OP_LIT ; start --- ---
CSA_OP_INC ; start --- ---
CSA_OP_DEC ; start --- ---
CSA_OP_RAND ; seed --- ---
tblrd*+ ; get op1 or op2 or op3
movff TABLAT,POSTINC1 ; move to arg table
bsf STATUS,Z ; return OK
return
;*****************************************************************************
; CUE_GET_ARGUMENT Get an arguemnt value from an arg cell
;
; INPUTS:
; - cue_argvalue contains the argument *number* to get
;
; RETURNS:
; - cue_argvalue returns the argument *value*
;
; USES:
; - uses FSR1 but restores it
CUE_GET_ARGUMENT
movf cue_argvalue,W ; validate arg number range
call CUE_CHECK_ARGNUM ; Note: validator destroys W
btfss STATUS,Z
retlw ERR_BAD_ARGNUM ; error return