-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyamaha_dx9_rom.asm
executable file
·16301 lines (13773 loc) · 494 KB
/
yamaha_dx9_rom.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
; =============================================================================
; YAMAHA DX9 ROM DISASSEMBLY
; Annotated by AJXS: https://ajxs.me/ https://github.com/ajxs
; =============================================================================
.PROCESSOR HD6303
INCLUDE "dasm_includes.asm"
; =============================================================================
; Delay Short Macro.
; Delay by using a BRN instruction targeting the next memory address.
; This is used in numerous places in the DX9 ROM.
; =============================================================================
.MAC DELAY_SHORT
BRN *+2
.ENDM
; =============================================================================
; Delay Single Macro.
; Emits a single delay cycle.
; =============================================================================
.MAC DELAY_SINGLE
PSHX
PULX
.ENDM
TIMER_CTRL_EOCI: EQU 1 << 3
KEY_SWITCH_SCAN_DRIVER_SOURCE_BUTTONS_2: EQU %10
KEY_SWITCH_SCAN_DRIVER_SOURCE_PEDALS: EQU %11
KEY_SWITCH_SCAN_DRIVER_SOURCE_KEYBOARD: EQU %100
PORT_1_ADC_EOC: EQU 1 << 4
PORT_1_TAPE_REMOTE: EQU 1 << 5
PORT_1_TAPE_OUTPUT: EQU 1 << 6
PORT_1_TAPE_INPUT: EQU 1 << 7
KEY_SWITCH_LINE_0_BUTTON_YES: EQU 1
KEY_SWITCH_LINE_0_BUTTON_NO: EQU 2
KEY_SWITCH_LINE_0_BUTTON_FUNCTION: EQU 8
KEY_SWITCH_LINE_1_BUTTON_10: EQU 2
; =============================================================================
; These indexes are used as the null-terminating character of the parameter
; name strings.
; The string copy function will return these in ACCB, which is read by the
; menu printing function to determine what function to use to print the
; associated parameter value.
; =============================================================================
PRINT_PARAM_FUNCTION_NUMERIC: EQU 1
PRINT_PARAM_FUNCTION_BOOLEAN: EQU 2
PRINT_PARAM_FUNCTION_OSC_FREQ: EQU 3
PRINT_PARAM_FUNCTION_OSC_DETUNE: EQU 4
PRINT_PARAM_FUNCTION_KEY_TRANSPOSE: EQU 5
PRINT_PARAM_FUNCTION_BATTERY_VOLTAGE: EQU 6
PRINT_PARAM_FUNCTION_MONO_POLY: EQU 7
PRINT_PARAM_FUNCTION_PORTAMENTO_MODE: EQU 8
PRINT_PARAM_FUNCTION_LFO_WAVE: EQU 9
PRINT_PARAM_FUNCTION_AVAIL_UNAVAIL: EQU 10
PRINT_PARAM_FUNCTION_MIDI_CHANNEL: EQU 11
PRINT_PARAM_FUNCTION_OSC_MODE: EQU 12
; =============================================================================
; LCD Constants.
; These are constants related to the HD44780 LCD controller.
; =============================================================================
LCD_CLEAR: EQU 1
LCD_RETURN_HOME: EQU 1 << 1
LCD_ENTRY_MODE_SET: EQU 1 << 2
LCD_ENTRY_MODE_INCREMENT: EQU 1 << 1
LCD_DISPLAY_CONTROL: EQU 1 << 3
LCD_DISPLAY_ON: EQU 1 << 2
LCD_DISPLAY_CURSOR: EQU 1 << 1
LCD_DISPLAY_BLINK: EQU 1
LCD_FUNCTION_SET: EQU 1 << 5
LCD_FUNCTION_DATA_LENGTH: EQU 1 << 4
LCD_FUNCTION_LINES: EQU 1 << 3
LCD_SET_POSITION: EQU 1 << 7
ADC_SOURCE_PITCH_BEND: EQU 0
ADC_SOURCE_MOD_WHEEL: EQU 1
ADC_SOURCE_BREATH_CONTROLLER: EQU 2
ADC_SOURCE_SLIDER: EQU 3
ADC_SOURCE_BATTERY: EQU 4
; =============================================================================
; MIDI Status Codes.
; =============================================================================
MIDI_STATUS_NOTE_OFF: EQU $80
MIDI_STATUS_NOTE_ON: EQU $90
MIDI_STATUS_MODE_CHANGE: EQU $B0
MIDI_STATUS_PROGRAM_CHANGE: EQU $C0
MIDI_STATUS_PITCH_BEND: EQU $E0
MIDI_STATUS_SYSEX_START: EQU $F0
MIDI_STATUS_SYSEX_END: EQU $F7
MIDI_STATUS_ACTIVE_SENSING: EQU $FE
; =============================================================================
; MIDI SysEx Constants.
; =============================================================================
MIDI_SYSEX_FORMAT_BULK: EQU 9
MIDI_SYSEX_SUBSTATUS_PARAM_CHANGE: EQU $10
MIDI_MANUFACTURER_ID_YAMAHA: EQU $43
; =============================================================================
; MIDI CC Constants
; =============================================================================
MIDI_CC_DATA_ENTRY EQU 6
; =============================================================================
; Patch Edit Buffer Offsets.
; These offsets can be used to access an individual field inside the patch
; edit buffer, or an unpacked SysEx patch dump.
; =============================================================================
PATCH_OP_EG_RATE_1: EQU 0
PATCH_OP_EG_RATE_2: EQU 1
PATCH_OP_EG_RATE_3: EQU 2
PATCH_OP_EG_RATE_4: EQU 3
PATCH_OP_EG_LEVEL_1: EQU 4
PATCH_OP_EG_LEVEL_2: EQU 5
PATCH_OP_EG_LEVEL_3: EQU 6
PATCH_OP_EG_LEVEL_4: EQU 7
PATCH_OP_KBD_SCALE_LVL: EQU 8
PATCH_OP_KBD_SCALING_RATE: EQU 9
PATCH_OP_AMP_MOD_SENSE: EQU 10
PATCH_OP_LEVEL: EQU 11
PATCH_OP_FREQ_COARSE: EQU 12
PATCH_OP_FREQ_FINE: EQU 13
PATCH_OP_DETUNE: EQU 14
PATCH_OPERATOR_6: EQU 0
PATCH_OPERATOR_5: EQU 14
PATCH_OPERATOR_4: EQU 28
PATCH_OPERATOR_3: EQU 42
PATCH_ALGORITHM: EQU 60
PATCH_FEEDBACK: EQU 61
PATCH_OSC_SYNC: EQU 62
PATCH_LFO_SPEED: EQU 63
PATCH_LFO_DELAY: EQU 64
PATCH_LFO_PITCH_MOD_DEPTH: EQU 65
PATCH_LFO_AMP_MOD_DEPTH: EQU 66
PATCH_LFO_WAVE: EQU 67
PATCH_LFO_PITCH_MOD_SENS: EQU 68
PATCH_KEY_TRANSPOSE: EQU 69
PEDAL_INPUT_PORTA: EQU 1 << 6
PEDAL_INPUT_SUSTAIN: EQU 1 << 7
VOICE_STATUS_SUSTAIN: EQU 1
VOICE_STATUS_ACTIVE: EQU %10
EGS_VOICE_EVENT_ON: EQU 1
EGS_VOICE_EVENT_OFF: EQU 2
; =============================================================================
; Raw input button codes.
; These are the codes returned from scanning the front panel input.
; =============================================================================
INPUT_BUTTON_YES: EQU 1
INPUT_BUTTON_NO: EQU 2
INPUT_BUTTON_STORE: EQU 3
INPUT_BUTTON_FUNCTION: EQU 4
INPUT_BUTTON_EDIT: EQU 5
INPUT_BUTTON_PLAY: EQU 7
INPUT_BUTTON_1: EQU 8
INPUT_BUTTON_10: EQU 17
INPUT_BUTTON_20: EQU 27
BUTTON_EDIT_6: EQU 5
BUTTON_EDIT_7: EQU 6
BUTTON_EDIT_9: EQU 8
BUTTON_EDIT_10: EQU 9
BUTTON_EDIT_11: EQU 10
BUTTON_EDIT_12: EQU 11
BUTTON_EDIT_13: EQU 12
BUTTON_EDIT_14: EQU 13
BUTTON_EDIT_15: EQU 14
BUTTON_EDIT_17: EQU 16
BUTTON_EDIT_20: EQU 19
BUTTON_FUNCTION_1: EQU 20
BUTTON_FUNCTION_2: EQU 21
BUTTON_FUNCTION_4: EQU 23
BUTTON_FUNCTION_5: EQU 24
BUTTON_FUNCTION_6: EQU 25
BUTTON_FUNCTION_7: EQU 26
BUTTON_FUNCTION_10: EQU 29
BUTTON_FUNCTION_11: EQU 30
BUTTON_FUNCTION_19: EQU 38
BUTTON_FUNCTION_20: EQU 39
BUTTON_TEST_ENTRY_COMBO: EQU 40
EVENT_RELOAD_PATCH: EQU 1
EVENT_HALT_VOICES_RELOAD_PATCH: EQU 2
; =============================================================================
; UI Modes.
; These codes are used to determine the input mode of the synth's UI.
; =============================================================================
UI_MODE_FUNCTION: EQU 0
UI_MODE_EDIT: EQU 1
UI_MODE_PLAY: EQU 2
UI_MODE_UNKNOWN: EQU 3
io_port_1_dir: EQU 0
io_port_2_dir: EQU 1
io_port_1_data: EQU 2
io_port_2_data: EQU 3
io_port_4_dir EQU 5
timer_ctrl_status: EQU 8
free_running_counter: EQU 9
output_compare: EQU $B
rate_mode_ctrl: EQU $10
sci_ctrl_status: EQU $11
sci_rx: EQU $12
sci_tx: EQU $13
TIMER_CTRL_EOCI: EQU 1 << 3
RATE_MODE_CTRL_CC0: EQU 1 << 2
RATE_MODE_CTRL_CC1: EQU 1 << 3
SCI_CTRL_TE: EQU 1 << 1
SCI_CTRL_TIE: EQU 1 << 2
SCI_CTRL_RE: EQU 1 << 3
SCI_CTRL_RIE: EQU 1 << 4
SCI_CTRL_TDRE: EQU 1 << 5
SCI_CTRL_ORFE: EQU 1 << 6
; =============================================================================
; MIDI Error codes.
; These constants are used to track the status of the MIDI buffers. If an error
; condition occurs, these constants will be written to the appropriate memory
; location. They are referenced in printing error messages.
; This functionality is identical in the DX7 firmware.
; =============================================================================
MIDI_ERROR_BUFFER_FULL: EQU 1
MIDI_ERROR_OVERRUN: EQU 2
key_switch_scan_driver_input EQU $20
adc_data EQU $22
adc_source EQU $24
ops_mode EQU $26
ops_alg_feedback EQU $27
lcd_ctrl: EQU $28
lcd_data: EQU $29
led_1: EQU $2B
led_2: EQU $2C
egs_voice_frequency: EQU $1800
egs_operator_frequency: EQU $1820
egs_operator_detune: EQU $1830
egs_operator_eg_rate: EQU $1840
egs_operator_eg_level: EQU $1860
egs_operator_level: EQU $1880
egs_operator_keyboard_scaling: EQU $18E0
egs_amp_mod: EQU $18F0
egs_key_event: EQU $18F1
egs_pitch_mod_high: EQU $18F2
egs_pitch_mod_low: EQU $18F3
key_switch_scan_input: EQU $80
pedal_status_current: EQU $84
sustain_status: EQU $85
patch_activate_operator_number: EQU $86
patch_activate_operator_offset: EQU $87
updated_input_source: EQU $88
operator_keyboard_scaling_rate_scaled: EQU $89
operator_keyboard_scaling_level_scaled: EQU $8A
; These variables are used in places where the memcpy pointers are already
; used, such as tape patch serialisation routines.
copy_ptr_src: EQU $8B
copy_ptr_dest: EQU $8D
copy_counter: EQU $8F
; When this flag is set the next keypress event will be used to set the
; synth's key transpose.
key_transpose_set_mode_active: EQU $90
note_transpose_frequency_base: EQU $91
pedal_status_previous: EQU $93
keyboard_last_scanned_values: EQU $95
; This variable stores the number of the last incoming note received via MIDI.
; It also stores the last scanned key, and pending key event.
; If this value is 0xFF, it indicates there is no key event pending.
; If bit 7 of this byte is set, it indicates that this note event is a
; 'Key Down' event originating from the keyboard, otherwise it is a 'Key Up'.
note_number: EQU $A1
keyboard_scan_current_key: EQU $A2
keyboard_scan_octave: EQU $A3
; This is the base logarithmic frequency of the current note, before the
; current pitch EG level is added.
note_frequency: EQU $A4
note_frequency_low: EQU $A5
; The index of the selected voice during the 'Note On' subroutine.
; Once a free voice to hold the new note is found, its index is stored here.
note_on_voice_index: EQU $A6
egs_load_freq_note_freq: EQU $A7
egs_load_freq_voice_number: EQU $A9
egs_load_freq_operator_index: EQU $AA
tape_byte_counter: EQU $AB
tape_input_polarity_previous: EQU $AC
tape_input_pilot_tone_counter: EQU $AD
tape_input_read_byte: EQU $AE
tape_input_delay_length: EQU $AF
; This flag is set when a particular tape function is aborted by the user.
tape_function_aborted_flag: EQU $B0
portamento_rate_scaled: EQU $B1
lfo_phase_increment: EQU $B2
lfo_delay_increment: EQU $B4
lfo_mod_depth_pitch: EQU $B6
lfo_mod_depth_amp: EQU $B7
pitch_bend_amount: EQU $B8
pitch_bend_frequency: EQU $B9
portamento_frequency_base: EQU $BB
portamento_process_frequency_increment: EQU $BD
portamento_process_loop_counter: EQU $BF
portamento_process_voice_target_frequency: EQU $C0
lfo_delay_accumulator: EQU $C2
; The 'LFO delay fadein factor' variable is used to 'fade in' the LFO
; amplitude after the LFO delay has expired.
lfo_delay_fadein_factor: EQU $C4
lfo_phase_accumulator: EQU $C6
lfo_sample_and_hold_update_flag: EQU $C8
lfo_amplitude: EQU $C9
mod_wheel_input_scaled: EQU $CA
breath_controller_input_scaled: EQU $CB
mod_amount_total: EQU $CC
portamento_update_toggle: EQU $CD
memcpy_ptr_src: EQU $CE
memcpy_ptr_dest: EQU $D0
lcd_print_number_print_zero_flag: EQU $D2
lcd_print_number_divisor: EQU $D3
ui_btn_function_19_patch_init_prompt: EQU $D4
; Used to track the state of the 'Test Mode' button combination internally.
ui_test_mode_button_combo_state: EQU $D5
; The synth's current active voice count when in monophonic mode.
active_voice_count: EQU $D6
; The synth's current portamento direction.
; * 0: Down.
; * 1: Up.
portamento_direction: EQU $D7
porta_current_target_frequency: EQU $D8
midi_buffer_ptr_tx_write: EQU $D9
midi_buffer_ptr_tx_read: EQU $DB
midi_buffer_ptr_rx_write: EQU $DD
midi_buffer_ptr_rx_read: EQU $DF
midi_last_sent_command: EQU $E1
midi_last_command_received: EQU $E2
midi_rx_first_data_byte: EQU $E3
midi_sysex_substatus: EQU $E4
midi_sysex_format_param_grp: EQU $E5
; The received SysEx byte count MSB, in the case that the incoming SysEx
; message is data, or the parameter number if it is a parameter change
; message.
midi_sysex_byte_count_msb_param_number: EQU $E6
; The received SysEx byte count LSB, in the case that the incoming SysEx
; message is data, or the parameter data if it is a parameter change
; message.
midi_sysex_byte_count_lsb_param_data: EQU $E7
midi_rx_data_count: EQU $E8
midi_sysex_tx_checksum: EQU $E9
midi_sysex_patch_number: EQU $EA
midi_sysex_format_type: EQU $EB
midi_sysex_rx_checksum: EQU $EC
; The index of the current patch being received during a 32 voice SysEx
; bulk data dump.
midi_sysex_rx_bulk_patch_index: EQU $ED
midi_sysex_rx_active_flag: EQU $EE
midi_active_sensing_tx_counter: EQU $EF
midi_active_sensing_tx_pending_flag: EQU $F0
midi_sysex_voice_timeout_active: EQU $F1
midi_active_sensing_rx_counter: EQU $F2
midi_sysex_receive_data_active: EQU $F3
midi_error_code: EQU $F4
SEG.U ram_external
midi_buffer_tx: EQU $800
midi_buffer_tx_end: EQU #midi_buffer_tx + $2AA
midi_buffer_rx: EQU $AAA
midi_buffer_rx_end: EQU #midi_buffer_rx + $320
midi_buffer_sysex_tx_single: EQU $DCA
midi_buffer_sysex_rx_single: EQU $E65
midi_buffer_sysex_tx_bulk: EQU $F00
midi_buffer_sysex_rx_bulk: EQU $F80
patch_buffer: EQU $1000
patch_buffer_tape_temp: EQU $1500
tape_patch_output_counter: EQU $1540
tape_patch_checksum: EQU $1541
patch_buffer_compare: EQU $1543
patch_buffer_edit: EQU $1583
patch_edit_operator_4_keyboard_scaling_rate: EQU #patch_buffer_edit + PATCH_OP_KBD_SCALING_RATE
patch_edit_algorithm: EQU #patch_buffer_edit + PATCH_ALGORITHM
patch_edit_feedback: EQU #patch_buffer_edit + PATCH_FEEDBACK
patch_edit_oscillator_sync: EQU #patch_buffer_edit + PATCH_OSC_SYNC
patch_edit_lfo_speed: EQU #patch_buffer_edit + PATCH_LFO_SPEED
patch_edit_lfo_delay: EQU #patch_buffer_edit + PATCH_LFO_DELAY
patch_edit_key_transpose: EQU #patch_buffer_edit + PATCH_KEY_TRANSPOSE
; This value is used as a 'null' edit parameter.
; When it is selected as the active 'Edit Parameter', any data input will have
; no effect. It is used by the UI subroutines when data input needs to be
; disabled.
null_edit_parameter: EQU $15C9
; Unlike the DX7, which stores this variable in a WORD, all use of this
; variable involves shifting it left twice to get its internal value.
master_tune: EQU $15CA
mono_poly: EQU $15CB
pitch_bend_range: EQU $15CC
; Portamento Mode:
; Monophonic Mode:
; * 0: Full-time.
; * 1: Fingered.
portamento_mode: EQU $15CD
portamento_time: EQU $15CE
mod_wheel_range: EQU $15CF
mod_wheel_assign: EQU $15D0
mod_wheel_amp: EQU $15D1
mod_wheel_eg_bias: EQU $15D2
breath_control_range: EQU $15D3
breath_control_assign: EQU $15D4
breath_control_amp: EQU $15D5
breath_control_eg_bias: EQU $15D6
midi_rx_channel: EQU $15D7
sys_info_avail: EQU $15D8
tape_remote_output_polarity: EQU $15D9
; The synth's 'Memory Protect' state.
; When this variable is updated, the memory protection flag bits in the
; 'ui_state' variable are updated, which will prevent any UI operations
; modifying internal memory.
; This variable is referred to independently of the UI state when performing
; tape input operations.
memory_protect: EQU $15DA
tape_input_selected_patch_index: EQU $15DC
tape_patch_index: EQU $15DD
operator_4_enabled_status: EQU $15DF
operator_3_enabled_status: EQU $15E0
operator_2_enabled_status: EQU $15E1
operator_1_enabled_status: EQU $15E2
ui_mode_memory_protect_state: EQU $15E3
patch_index_current: EQU $15E4
ui_btn_numeric_last_pressed: EQU $15E5
ui_btn_numeric_previous_fn_mode: EQU $15E6
ui_btn_numeric_previous_edit_mode: EQU $15E7
ui_btn_numeric_previous_play_mode: EQU $15E8
operator_selected_src: EQU $15E9
ui_currently_selected_eg_stage: EQU $15EA
main_patch_event_flag: EQU $15EB
operator_selected_dest: EQU $15EC
; Edit mode button 5 sub-function:
; * 0: Algorithm
; * 1: Feedback
ui_btn_edit_5_sub_function: EQU $15ED
; Edit mode button 9 sub-function:
; * 0: LFO Amp Mod Depth
; * 1: LFO Pitch ""
ui_btn_edit_9_sub_function: EQU $15EE
; Edit mode button 10 sub-function:
; * 0: Amp Mod Sens
; * 1: Pitch ""
ui_btn_edit_10_sub_function: EQU $15EF
; Edit mode button 14 sub-function:
; * 0: Detune
; * 1: Oscillator Sync
ui_btn_edit_14_sub_function: EQU $15F0
; Function mode button 6 sub-function:
; * 0: MIDI Channel
; * 1: Sys Info
; * 2: MIDI Transmit
ui_btn_function_6_sub_function: EQU $15F1
; Function mode button 7 sub-function:
; * 0: Save to tape
; * 1: Verify tape
ui_btn_function_7_sub_function: EQU $15F2
; Function mode button 19 sub-function:
; * 0: Edit Recall
; * 1: Voice Init
; * 2: Battery Voltage
ui_btn_function_19_sub_function: EQU $15F3
; This flag appears to block the mode cycling of button 9 when the synth is
; in 'Edit Mode'.
; It is set when the synth is switched into 'Edit' mode, and is disabled by
; the next press of button 9. So effectively it stops the first press of
; button 9 from cycling the mode.
; The reason this is used is likely so that the user can see which mode is
; selected PRIOR to the mode being cycled.
ui_flag_disable_edit_btn_9_mode_select: EQU $15F4
; These two variables are used by the user interface to control the currently
; selected 'Edit Parameter', which will be edited by the data input controls.
; The address, and maximum value are loaded from lookup tables in the UI
; routines.
ui_active_param_address: EQU $15F5
ui_active_param_max_value: EQU $15F7
; This variable is used to store the previously recorded slider input.
; This is used in the slider parameter update routine.
analog_input_slider_previous: EQU $15F8
; This flag tracks whether the patch currently loaded into the patch
; edit buffer has been modified.
patch_current_modified_flag: EQU $15F9
patch_compare_mode_active: EQU $15FA
; This flag appears to disable 'Key Transpose' UI functionality.
ui_flag_blocks_key_transpose: EQU $15FB
lfo_waveform: EQU $15FC
lfo_pitch_mod_sensitivity: EQU $15FD
lfo_sample_hold_accumulator: EQU $15FE
led_contents: EQU $15FF
led_compare_mode_blink_counter: EQU $1601
patch_index_compare: EQU $1602
analog_input_source_next: EQU $1603
analog_input_previous: EQU $1604
analog_input_pitch_bend: EQU $1608
analog_input_mod_wheel: EQU $1609
analog_input_breath_controller: EQU $160A
analog_input_slider: EQU $160B
analog_input_battery_voltage: EQU $160C
operator_keyboard_scaling_level_curve_table: EQU $160D
lcd_buffer_current: EQU $1681
lcd_buffer_next: EQU $16A1
lcd_buffer_next_line_2: EQU #lcd_buffer_next + 16
lcd_buffer_next_end: EQU #lcd_buffer_next + 32
stack_bottom: EQU $16C1
stack_top: EQU $179F
voice_status: EQU $17A0
voice_frequency_target: EQU $17C0
voice_frequency_current: EQU $17E0
; In the DX9 firmware, variables used in the test subroutines share
; locations in memory with other variables. Presumably this is because they're
; unused during the diagnostic routines.
test_stage_current: EQU $D6
test_stage_sub: EQU $D7
test_stage_sub_2: EQU $D8
test_button_input: EQU $86
SEG rom
ORG $C000
; The 'ROM' diagnostic test performs a checksum of the ROM.
; It loops over each byte in the ROM in 256 byte blocks, adding the value of
; each byte to a total checksum byte. This checksum is expected to add up, with
; integer overflow, to '0'. This byte placed here is the final remainder byte
; that will cause the ROM checksum to total to '0'.
checksum_remainder_byte:
DC.B 225
; =============================================================================
; HANDLER_RESET
; =============================================================================
; LOCATION: 0xC001
;
; DESCRIPTION:
; Initialises all of the synthesiser's subsystems.
; This routine clears the volatile internal memory, and initialises all of the
; synth's peripheral devices.
;
; =============================================================================
handler_reset: SUBROUTINE
CLRA
STAA <timer_ctrl_status
LDS #stack_top
; Set IO Port 4 direction.
; Technically nothing is wired to port 4. This might have been some kind of
; remnant from Yamaha's development system.
LDAA #%11111111
STAA <io_port_4_dir
; Set Port 1 direction.
; A '1' bit specifies an output line.
; In this case, the input lines are the cassette interface input, and the
; ADC EOC line.
LDAA #%1101111
STAA <io_port_1_dir
; Set Port 2 direction.
CLR io_port_2_dir
; Clear both LEDs.
CLR led_1
CLR led_2
; Reset the EGS operator volumes.
JSR voice_reset_egs_operator_level
; Clear internal RAM.
; Unlike the external RAM, the processor's internal RAM is not powered, and
; thus will not persist when power cycled. In order to ensure a stable
; operating state, this memory is initialised to zero on reset.
LDX #key_switch_scan_input
LDAB #128
LDAA #0
.clear_internal_ram_loop:
STAA 0,x
INX
DECB
BNE .clear_internal_ram_loop
; Reset the internal voice frequency buffers.
JSR voice_reset_frequency_data
; Store 0xFF in the note number variable to indicate a 'NULL' value.
; This will be interpreted as a no-operation by the note handler in the main
; event loop.
LDAA #$FF
STAA <note_number
JSR midi_init
JSR handler_reset_init_peripherals
; Read, and store the battery voltage.
; This is the only point that the battery voltage is actually read.
LDAA <adc_data
DELAY_SINGLE
; Read the battery voltage to ready the system for the initial battery
; voltage check.
LDAB #ADC_SOURCE_BATTERY
JSR adc_set_source
JSR adc_read
STAA analog_input_battery_voltage
; Initialise the main system, and user-interface variables.
; This will set the event dispatch flag to reload the patch data to the EGS
; chip, which will be performed in the subsequent subroutine call.
JSR handler_reset_system_init
JSR main_process_events
; Read the slider input, and store this as the 'initial' previous slider
; input reading. This is necessary so that the next analog input update
; does not immediately trigger a slider input event.
; This would occur because the update compares the current reading against
; the previous to test for a change.
LDAB #ADC_SOURCE_SLIDER
JSR adc_set_source
JSR adc_read
STAA analog_input_previous + ADC_SOURCE_SLIDER
; Reset the free-running, and output compare counters.
LDD #0
STD <free_running_counter
LDD #2500
STD <output_compare
; Enable the output-compare interrupt, and clear condition flags.
LDAA #TIMER_CTRL_EOCI
STAA <timer_ctrl_status
CLRA
TAP
; Falls-through below to main loop.
; =============================================================================
; MAIN_LOOP
; =============================================================================
; LOCATION: 0xC065
;
; DESCRIPTION:
; Synth firmware executive main loop.
; This is where the bulk of the synth's functionality is implemented.
; The keyboard, and pedal input are first scanned here. Unlike other Yamaha
; FM synthesisers, the 'Note On', and 'Note Off' functionaliy is implemented
; via a flag set in the keyboard scan routine. This flag records whether a
; key on, or off event has occurred, and which key triggered it. After the
; input scan routine is completed, the 'Note On', and 'Note Off' handlers are
; invoked. which check this flag, and action key events accordingly.
; In the DX7 the keyboard event handling routines are triggered inside the
; main IRQ handler, which reads the physical keyboard input.
;
; =============================================================================
main_loop:
JSR main_update_keyboard_and_pedal_input
JSR keyboard_note_on_handler
JSR keyboard_note_off_handler
JSR adc_process
JSR main_input_handler
JSR main_process_events
JSR midi_process_incoming_data
JSR main_process_events
; The exact reason for this 'NOP' instruction will never be known, however it
; was likely put here to slightly decrease the polling rate of the synth's
; various peripherals.
NOP
BRA main_loop
; =============================================================================
; MAIN_UPDATE_KEYBOARD_AND_PEDAL_INPUT
; =============================================================================
; LOCATION: 0xC080
;
; DESCRIPTION:
; Updates the peripheral pedal input, and perform the main keyboard scan to
; determine if any keyboard notes have changed.
; The first updated key found will set the 'note_number' global, which is
; processed by the note on, and off handlers in the main loop.
;
; =============================================================================
main_update_keyboard_and_pedal_input: SUBROUTINE
JSR pedals_update
; The function reading pedal input returns the status in ACCB.
; A value of 0 indicates that no change in pedal status has occurred.
; a value of 1 indicates the sustain pedal has changed status, a value of 2
; indicates that the portamento pedal input has changed. The result of the
; change is stored in ACCA.
TSTB
BEQ keyboard_scan
; If this value is 1, it indicates sustain has updated.
; Any other value indicates portamento.
; Send the MIDI 'Mode Change' event accordingly.
CMPB #1
BNE .portamento_updated
JSR midi_tx_pedal_status_sustain
BRA keyboard_scan
.portamento_updated:
JSR midi_tx_pedal_status_portamento
; Falls-through below.
keyboard_scan:
; The keyboard circuitry is grouped by key, with the same key from each octave
; wired together. The individual keys of an octave are wired to lines 4-15 of
; the key switch scan driver. The value returned is the octave of the pressed
; key (1 << octave).
; This subroutine iterates over the 12 different keys, checking whether each
; read value has changed since the last call.
; If the value read for a key has changed, the value is rotated to find which
; octave changed.
LDX #keyboard_last_scanned_values
LDAB <io_port_1_data
ANDB #%11110000
ORAB #KEY_SWITCH_SCAN_DRIVER_SOURCE_KEYBOARD
STAB <keyboard_scan_current_key
; Iterate over each key group.
.scan_key_loop:
LDAB <keyboard_scan_current_key
STAB <io_port_1_data
DELAY_SINGLE
; Read the status of each octave for this key.
LDAA <key_switch_scan_driver_input
; Test if the value has changed since the last check.
EORA 0,x
BNE .key_changed
INX
LDAB <keyboard_scan_current_key
INCB
STAB <keyboard_scan_current_key
; Test if ACCB % 16 is zero.
; ACCB started at 4, so this will loop 12 times (once for each key).
ANDB #%1111
BNE .scan_key_loop
; If no keys have changed state, set the note number event dispatch
; flag to a null value.
LDAA #$FF
STAA <note_number
BRA .exit
.key_changed:
LDAB <keyboard_scan_current_key
ANDB #%1111
CLR keyboard_scan_octave
INC keyboard_scan_octave
.get_updated_octave:
; Rotate this value right until the carry bit is set, indicating that the
; updated octave has been reached.
RORA
BCS .get_updated_keycode
; 12 is added to the key value with each iteration on account of the number
; of keys in an octave. 21 (the base key value) is added to the final value
; to yield the final key code.
ADDB #12
ASL keyboard_scan_octave
BRA .get_updated_octave
.get_updated_keycode:
ADDB #21
STAB <note_number
LDAA <keyboard_scan_octave
; Test whether this key is being pressed. If so, set bit 7.
BITA 0,x
BNE .store_updated_value
OIMD #$80, note_number
; Store the updated input.
.store_updated_value:
EORA 0,x
STAA 0,x
.exit:
RTS
; =============================================================================
; MAIN_NOTE_ON_HANDLER
; =============================================================================
; LOCATION: 0xC0DF
;
; DESCRIPTION:
; Handles 'Note On' keyboard events.
; This is called periodically as part of the synth's main executive loop.
; This subroutine is controlled by the main 'Note Number' register. If a
; keyboard 'Key On' event is triggered, the note will be stored in this
; register, and this subroutine will trigger subsequently add the note's
; voice.
;
; ARGUMENTS:
; Memory:
; * note_number: The 'Note On Event' note number.
; If this value is 0xFF, it indicates there is no key event pending.
; If bit 7 of this byte is set, it indicates that this note event
; is a 'Key Up' event originating from the keyboard.
;
; =============================================================================
keyboard_note_on_handler: SUBROUTINE
LDAB <note_number
; Check whether bit 7 is clear, indicating that the pending key event is a key
; being released. In this case handle it is handled as a 'Key Off' event.
BPL .no_action_needed
; Test whether the pending note number is 0xFF, indicating that there is
; no pending note event to handle.
CMPB #$FF
BEQ .no_action_needed
; Mask the note number.
ANDB #%1111111
; Test whether the 'Set Key Transpose' mode is active.
; In this case the next keypress sets the root note.
LDAA <key_transpose_set_mode_active
BEQ .send_midi_message_and_add_new_note
; Test whether the note is below 48.
; If so, set to 48 to initialise the transpose key at the minimum.
CMPB #48
BMI .key_under_48
; Clamp the base transpose key at 72.
CMPB #72
BLS .set_transpose_key
LDAB #72
BRA .set_transpose_key
.key_under_48:
LDAB #48
.set_transpose_key:
SUBB #48
CMPB patch_edit_key_transpose
BEQ .clear_key_transpose_flag
STAB patch_edit_key_transpose
; After the key transpose has been set, send the new value via SysEx.
JSR midi_sysex_tx_key_transpose
JSR voice_set_key_transpose_base_frequency
; Set the patch edit buffer as having been modified.
LDAA #1
STAA patch_current_modified_flag
JSR ui_print_update_led_and_menu
.clear_key_transpose_flag:
CLR key_transpose_set_mode_active
.no_action_needed:
JMP voice_add_exit
.send_midi_message_and_add_new_note:
JSR midi_tx_note_on
; Falls-through below.
; ==============================================================================
; VOICE_ADD
; ==============================================================================
; LOCATION: 0xC11C
;
; DESCRIPTION:
; This subroutine is the main entry point to 'adding' a new voice event.
; It is effectively the entry point to actually playing a note over one of the
; synth's voices. This function branches to more specific functions, depending
; on whether the synth is in monophonic, or polyphonic mode.
; This subroutine is where a note keycode is converted to the EGS chip's
; internal representation of pitch. The various voice buffers related to pitch
; transitions are set, and reset here.
;
; ==============================================================================
voice_add: SUBROUTINE
LDX #table_midi_key_to_log_f
ABX
; Convert the key number value shared by the keyboard controller, and
; MIDI input, to the frequency value used internally by the EGS chip.
; The resulting frequency value is represented in logarithmic format, with
; 1024 values per octave.
; The conversion works by using the note number as an index into a lookup
; table, from which the most-significant byte of the pitch is retrieved. The
; lower byte is then created by shifting this value.
; The mechanism used in this subroutine is referenced in patent US4554857:
; "It is known in the art that a frequency number expressed in logarithm can
; be obtained by frequently adding data of two low bits of the key code KC
; to lower bits
; (e.g., Japanese Patent Preliminary Publication No. 142397/1980)."
LDAA 0,x
STAA <note_frequency
LDAB #3
ANDA #3
STAA <note_frequency_low
.get_log_note_frequency_loop:
ORAA <note_frequency_low
ASLA
ASLA
DECB
BNE .get_log_note_frequency_loop
STAA <note_frequency_low
LDAB mono_poly
BEQ voice_add_poly
JMP voice_add_mono
; Loop through the 16 entries in the voice status buffer, testing each
; to find a free voice.
; The voice number offset is not reset each time, and resumes at the same
; place it did in the last 'Note On' event. This variable is initialised on
; device reset.
voice_add_poly:
LDAA #16
LDAB <note_on_voice_index
; Test the status of each voice to find one that is marked as inactive.
.find_inactive_voice_loop:
LDX #voice_status
ABX
TIMX #VOICE_STATUS_ACTIVE, 1,x
BEQ .found_inactive_voice