-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpitchbend.asm
619 lines (600 loc) · 10.3 KB
/
pitchbend.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
;config
list p=16f690
radix dec
include "p16f690.inc"
;flags
C EQU 0
DC EQU 1
Z EQU 2
IRP EQU 7
;macros
addshort macro a, b, c
movf a, W
addwf b, W
movwf c
movf (b+1), W
movwf (c+1)
movf (a+1), W
btfsc STATUS, C
incf (a+1), W
btfss STATUS, Z
addwf (c+1), F
endm
subshort macro a, b, c
movf a, W
subwf b, W
movwf c
movf (a+1), W
btfss STATUS, C
incf (a+1), W
subwf (b+1), W
movwf (c+1)
endm
;externs
extern PSAVE
extern SSAVE
extern WSAVE
extern STK12
extern STK11
extern STK10
extern STK09
extern STK08
extern STK07
extern STK06
extern STK05
extern STK04
extern STK03
extern STK02
extern STK01
extern STK00
extern _oscillator
;data
data_pitchbend udata
channel res 1
note res 1
pitch res 2
temp res 4
;code
code_pitchbend code
;void midi_pitchbend(unsigned char channel, unsigned short pitch)
_midi_pitch_bend
banksel channel
movwf channel
movf STK00, W
movwf pitch
movf STK01, W
movwf (pitch+1)
movf _oscillator, W
addlw 6*4
movwf FSR
next_oscillator
movlw 3
subwf FSR, F
;channel
banksel channel
movf channel, W
banksel _oscillator
xorwf INDF, W
btfss STATUS, Z
goto next_oscillator
decf FSR, F
;note
movf INDF, W
movwf note
xorlw 0xFF
btfsc STATUS, Z
goto next_oscillator
banksel channel
movf FSR, W
sublw _oscillator
btfss STATUS, Z
goto next_oscillator
return
end
; 2 exit points
; .line 287; "midi.c" void midi_pitch_bend(unsigned short pitch, unsigned char channel) {
BANKSEL r0x101F
MOVWF r0x101F
MOVF STK00,W
MOVWF r0x1020
MOVF STK01,W
MOVWF r0x1021
; .line 294; "midi.c" for(i=0; i<OSCILLATORS; i++) {
CLRF r0x1022
;unsigned compare: left < lit(0x6=6), size=1
_00182_DS_
MOVLW 0x06
BANKSEL r0x1022
SUBWF r0x1022,W
BTFSC STATUS,0
GOTO _00186_DS_
;genSkipc:3083: created from rifx:0x7ffff53d3e30
; .line 295; "midi.c" if(oscillator[i].note!=0xFF&&oscillator[i].channel==channel) {
MOVLW 0x04
MOVWF STK00
MOVF r0x1022,W
PAGESEL __mulchar
CALL __mulchar
PAGESEL $
BANKSEL r0x1023
MOVWF r0x1023
ADDLW (_oscillator + 0)
MOVWF r0x1024
MOVLW high (_oscillator + 0)
BTFSC STATUS,0
ADDLW 0x01
MOVWF r0x1025
MOVF r0x1024,W
MOVWF FSR
BCF STATUS,7
BTFSC r0x1025,0
BSF STATUS,7
MOVF INDF,W
MOVWF r0x1026
XORLW 0xff
BTFSC STATUS,2
GOTO _00184_DS_
MOVF r0x1023,W
ADDLW (_oscillator + 0)
MOVWF r0x1024
MOVLW high (_oscillator + 0)
BTFSC STATUS,0
ADDLW 0x01
MOVWF r0x1025
INCF r0x1024,F
BTFSC STATUS,2
INCF r0x1025,F
MOVF r0x1024,W
MOVWF FSR
BCF STATUS,7
BTFSC r0x1025,0
BSF STATUS,7
MOVF INDF,W
MOVWF r0x1026
XORWF r0x1021,W
BTFSS STATUS,2
GOTO _00184_DS_
; .line 296; "midi.c" chip=i/3;
MOVLW 0x03
MOVWF STK00
MOVF r0x1022,W
PAGESEL __divuchar
CALL __divuchar
PAGESEL $
BANKSEL r0x1024
MOVWF r0x1024
; .line 297; "midi.c" note=oscillator[i].note;
MOVF r0x1023,W
ADDLW (_oscillator + 0)
MOVWF r0x1023
MOVLW high (_oscillator + 0)
BTFSC STATUS,0
ADDLW 0x01
MOVWF r0x1025
MOVF r0x1023,W
MOVWF FSR
BCF STATUS,7
BTFSC r0x1025,0
BSF STATUS,7
MOVF INDF,W
MOVWF r0x1026
; .line 298; "midi.c" if(pitch==0x2000) {
MOVF r0x1020,W
XORLW 0x00
BTFSS STATUS,2
GOTO _00177_DS_
MOVF r0x101F,W
XORLW 0x20
BTFSS STATUS,2
GOTO _00177_DS_
; .line 299; "midi.c" freqdiv2=midi_freqdiv[note];
MOVLW 0x02
MOVWF STK00
MOVF r0x1026,W
RRF r0x1026, 1
BCF STATUS, 1
BANKSEL r0x1023
MOVWF r0x1023
CLRF r0x1025
MOVF r0x1023,W
ADDLW (_midi_freqdiv + 0)
MOVWF r0x1023
MOVLW 0x00
BTFSC STATUS,0
INCFSZ r0x1025,W
ADDLW high (_midi_freqdiv + 0)
MOVWF r0x1025
MOVF r0x1023,W
MOVWF STK01
MOVF r0x1025,W
MOVWF STK00
MOVLW 0x80
PAGESEL __gptrget2
CALL __gptrget2
PAGESEL $
BANKSEL r0x1027
MOVWF r0x1027
MOVF STK00,W
MOVWF r0x1028
GOTO _00178_DS_
;swapping arguments (AOP_TYPEs 1/2)
;unsigned compare: left >= lit(0x2001=8193), size=2
_00177_DS_
; .line 300; "midi.c" } else if(pitch>0x2000) {
MOVLW 0x20
BANKSEL r0x101F
SUBWF r0x101F,W
BTFSS STATUS,2
GOTO _00197_DS_
MOVLW 0x01
SUBWF r0x1020,W
_00197_DS_
BTFSS STATUS,0
GOTO _00174_DS_
;genSkipc:3083: created from rifx:0x7ffff53d3e30
; .line 302; "midi.c" pitch-=0x2000;
MOVLW 0xe0
BANKSEL r0x101F
ADDWF r0x101F,F
; .line 303; "midi.c" freqdiv1=midi_freqdiv[note];
MOVLW 0x02
MOVWF STK00
MOVF r0x1026,W
PAGESEL __mulchar
CALL __mulchar
PAGESEL $
BANKSEL r0x1023
MOVWF r0x1023
CLRF r0x1025
MOVF r0x1023,W
ADDLW (_midi_freqdiv + 0)
MOVWF r0x1023
MOVLW 0x00
BTFSC STATUS,0
INCFSZ r0x1025,W
ADDLW high (_midi_freqdiv + 0)
MOVWF r0x1025
MOVF r0x1023,W
MOVWF STK01
MOVF r0x1025,W
MOVWF STK00
MOVLW 0x80
PAGESEL __gptrget2
CALL __gptrget2
PAGESEL $
BANKSEL r0x1029
MOVWF r0x1029
MOVF STK00,W
MOVWF r0x102A
; .line 304; "midi.c" freqdiv2=midi_freqdiv[note+2];
MOVLW 0x02
ADDWF r0x1026,W
MOVWF r0x1023
MOVLW 0x02
MOVWF STK00
MOVF r0x1023,W
PAGESEL __mulchar
CALL __mulchar
PAGESEL $
BANKSEL r0x102B
MOVWF r0x102B
CLRF r0x102C
MOVF r0x102B,W
ADDLW (_midi_freqdiv + 0)
MOVWF r0x1023
MOVLW high (_midi_freqdiv + 0)
MOVWF r0x102D
MOVLW 0x00
BTFSC STATUS,0
INCFSZ r0x102C,W
ADDWF r0x102D,F
MOVF r0x1023,W
MOVWF STK01
MOVF r0x102D,W
MOVWF STK00
MOVLW 0x80
PAGESEL __gptrget2
CALL __gptrget2
PAGESEL $
BANKSEL r0x1027
MOVWF r0x1027
MOVF STK00,W
; .line 306; "midi.c" freqdiv2=(freqdiv1-freqdiv2);
MOVWF r0x1028
SUBWF r0x102A,W
MOVWF r0x1028
MOVF r0x1027,W
BTFSS STATUS,0
INCF r0x1027,W
SUBWF r0x1029,W
MOVWF r0x102B
MOVWF r0x1027
;;133 MOVF r0x1028,W
;;129 MOVF r0x1027,W
; .line 307; "midi.c" temp=freqdiv2;
CLRF r0x102C
CLRF r0x102D
;;131 MOVF r0x1020,W
;;123 MOVF r0x101F,W
; .line 308; "midi.c" temp*=pitch;
CLRF r0x1030
CLRF r0x1031
;;130 MOVF r0x102E,W
MOVF r0x1020,W
MOVWF r0x102E
MOVWF STK06
;;122 MOVF r0x102F,W
MOVF r0x101F,W
MOVWF r0x102F
MOVWF STK05
MOVLW 0x00
MOVWF STK04
MOVLW 0x00
MOVWF STK03
;;132 MOVF r0x1023,W
MOVF r0x1028,W
MOVWF r0x1023
MOVWF STK02
MOVF r0x102B,W
MOVWF STK01
MOVLW 0x00
MOVWF STK00
MOVLW 0x00
PAGESEL __mullong
CALL __mullong
PAGESEL $
BANKSEL r0x102D
MOVWF r0x102D
MOVF STK00,W
MOVWF r0x102C
MOVF STK01,W
MOVWF r0x102B
MOVF STK02,W
MOVWF r0x1023
; .line 309; "midi.c" temp>>=13;
SWAPF r0x102B,W
ANDLW 0x0f
MOVWF r0x1023
SWAPF r0x102C,W
MOVWF r0x102B
ANDLW 0xf0
IORWF r0x1023,F
XORWF r0x102B,F
SWAPF r0x102D,W
MOVWF r0x102C
ANDLW 0xf0
IORWF r0x102B,F
XORWF r0x102C,F
CLRF r0x102D
;shiftRight_Left2ResultLit:4862: shCount=1, size=4, sign=0, same=1, offr=0
BCF STATUS,0
RRF r0x102D,F
RRF r0x102C,F
RRF r0x102B,F
RRF r0x1023,F
;;111 MOVF r0x1023,W
;;113 MOVF r0x102B,W
;;110 MOVF r0x1028,W
; .line 311; "midi.c" freqdiv2=freqdiv1-freqdiv2;
MOVF r0x1023,W
MOVWF r0x1028
SUBWF r0x102A,W
MOVWF r0x1028
;;112 MOVF r0x1027,W
MOVF r0x102B,W
MOVWF r0x1027
BTFSS STATUS,0
INCF r0x1027,W
SUBWF r0x1029,W
MOVWF r0x1027
GOTO _00178_DS_
_00174_DS_
; .line 314; "midi.c" pitch=0x2000-pitch;
BANKSEL r0x1020
MOVF r0x1020,W
SUBLW 0x00
MOVWF r0x1020
MOVF r0x101F,W
BTFSS STATUS,0
INCF r0x101F,W
SUBLW 0x20
MOVWF r0x101F
; .line 315; "midi.c" freqdiv1=midi_freqdiv[note-2];
MOVLW 0xfe
ADDWF r0x1026,W
MOVWF r0x102E
MOVLW 0x02
MOVWF STK00
MOVF r0x102E,W
PAGESEL __mulchar
CALL __mulchar
PAGESEL $
BANKSEL r0x102F
MOVWF r0x102F
CLRF r0x1030
MOVF r0x102F,W
ADDLW (_midi_freqdiv + 0)
MOVWF r0x102E
MOVLW high (_midi_freqdiv + 0)
MOVWF r0x1031
MOVLW 0x00
BTFSC STATUS,0
INCFSZ r0x1030,W
ADDWF r0x1031,F
MOVF r0x102E,W
MOVWF STK01
MOVF r0x1031,W
MOVWF STK00
MOVLW 0x80
PAGESEL __gptrget2
CALL __gptrget2
PAGESEL $
BANKSEL r0x1029
MOVWF r0x1029
MOVF STK00,W
MOVWF r0x102A
; .line 316; "midi.c" freqdiv2=midi_freqdiv[note];
MOVLW 0x02
MOVWF STK00
MOVF r0x1026,W
PAGESEL __mulchar
CALL __mulchar
PAGESEL $
BANKSEL r0x102E
MOVWF r0x102E
CLRF r0x1031
MOVF r0x102E,W
ADDLW (_midi_freqdiv + 0)
MOVWF r0x1026
MOVLW high (_midi_freqdiv + 0)
MOVWF r0x102F
MOVLW 0x00
BTFSC STATUS,0
INCFSZ r0x1031,W
ADDWF r0x102F,F
MOVF r0x1026,W
MOVWF STK01
MOVF r0x102F,W
MOVWF STK00
MOVLW 0x80
PAGESEL __gptrget2
CALL __gptrget2
PAGESEL $
BANKSEL r0x1027
MOVWF r0x1027
MOVF STK00,W
; .line 318; "midi.c" freqdiv1=(freqdiv1-freqdiv2);
MOVWF r0x1028
SUBWF r0x102A,F
MOVF r0x1027,W
BTFSS STATUS,0
INCFSZ r0x1027,W
SUBWF r0x1029,F
;;128 MOVF r0x102A,W
;;119 MOVF r0x1029,W
; .line 319; "midi.c" temp=freqdiv1;
CLRF r0x102C
CLRF r0x102D
;;109 MOVF r0x1020,W
;;121 MOVF r0x101F,W
; .line 320; "midi.c" temp*=pitch;
CLRF r0x102F
CLRF r0x1030
;;108 MOVF r0x1026,W
MOVF r0x1020,W
MOVWF r0x1026
MOVWF STK06
;;120 MOVF r0x102E,W
MOVF r0x101F,W
MOVWF r0x102E
MOVWF STK05
MOVLW 0x00
MOVWF STK04
MOVLW 0x00
MOVWF STK03
;;127 MOVF r0x1023,W
MOVF r0x102A,W
MOVWF r0x1023
MOVWF STK02
;;118 MOVF r0x102B,W
MOVF r0x1029,W
MOVWF r0x102B
MOVWF STK01
MOVLW 0x00
MOVWF STK00
MOVLW 0x00
PAGESEL __mullong
CALL __mullong
PAGESEL $
BANKSEL r0x102D
MOVWF r0x102D
MOVF STK00,W
MOVWF r0x102C
MOVF STK01,W
MOVWF r0x102B
MOVF STK02,W
MOVWF r0x1023
; .line 321; "midi.c" temp>>=13;
SWAPF r0x102B,W
ANDLW 0x0f
MOVWF r0x1023
SWAPF r0x102C,W
MOVWF r0x102B
ANDLW 0xf0
IORWF r0x1023,F
XORWF r0x102B,F
SWAPF r0x102D,W
MOVWF r0x102C
ANDLW 0xf0
IORWF r0x102B,F
XORWF r0x102C,F
CLRF r0x102D
;shiftRight_Left2ResultLit:4862: shCount=1, size=4, sign=0, same=1, offr=0
BCF STATUS,0
RRF r0x102D,F
RRF r0x102C,F
RRF r0x102B,F
RRF r0x1023,F
;;115 MOVF r0x1023,W
;;117 MOVF r0x102B,W
;;114 MOVF r0x102A,W
; .line 323; "midi.c" freqdiv2=freqdiv2+freqdiv1;
MOVF r0x1023,W
MOVWF r0x102A
ADDWF r0x1028,F
;;116 MOVF r0x1029,W
MOVF r0x102B,W
MOVWF r0x1029
BTFSC STATUS,0
INCFSZ r0x1029,W
ADDWF r0x1027,F
_00178_DS_
; .line 326; "midi.c" loadreg(chip, (i%3)<<1);
MOVLW 0x03
MOVWF STK00
BANKSEL r0x1022
MOVF r0x1022,W
PAGESEL __moduchar
CALL __moduchar
PAGESEL $
BANKSEL r0x1023
MOVWF r0x1023
BCF STATUS,0
RLF r0x1023,W
MOVWF r0x1026
MOVWF STK00
MOVF r0x1024,W
CALL _loadreg
; .line 327; "midi.c" write(chip, freqdiv2);
BANKSEL r0x1028
MOVF r0x1028,W
MOVWF r0x1023
MOVWF STK00
MOVF r0x1024,W
CALL _write
; .line 328; "midi.c" loadreg(chip, ((i%3)<<1)+1);
BANKSEL r0x1026
INCF r0x1026,F
MOVF r0x1026,W
MOVWF STK00
MOVF r0x1024,W
CALL _loadreg
;;107 MOVF r0x1027,W
; .line 329; "midi.c" write(chip, freqdiv2>>8);
BANKSEL r0x1026
CLRF r0x1026
;;106 MOVF r0x1023,W
MOVF r0x1027,W
MOVWF r0x1023
MOVWF r0x1028
MOVWF STK00
MOVF r0x1024,W
CALL _write
_00184_DS_
; .line 294; "midi.c" for(i=0; i<OSCILLATORS; i++) {
BANKSEL r0x1022
INCF r0x1022,F
GOTO _00182_DS_
_00186_DS_
RETURN
; exit point of _midi_pitch_bend