Commit ed87854

Nick committed on
Moving the driver to the designated repo
commit ed87854bfb5db5c04e216c043c6c64e07b20d0b2 parent eef1a8e
16 changed files +1−3015
Deleted4ify.py +0−19
@@ -1,19 +0,0 @@
1 file = 'test_wave'
2
3 orig = open(f'{file}.raw', 'rb').read()
4 newf = open(f'{file}2.raw', 'wb')
5 destf = open(f'{file}3.raw', 'wb')
6
7 ls1 = []
8 for byte in orig:
9 new = int((byte/255)*15)
10 ls1.append(new)
11 newf.write(bytes([new]))
12
13 for pair in zip(ls1[::2], ls1[1::2]):
14 h, l = pair
15 new = (h << 4) | l
16 destf.write(bytes([new]))
17
18 newf.close()
19 destf.close()
DeletedHARDWARE.INC +0−744
@@ -1,744 +0,0 @@
1 ;*
2 ;* Gameboy Hardware definitions
3 ;*
4 ;* Based on Jones' hardware.inc
5 ;* And based on Carsten Sorensen's ideas.
6 ;*
7 ;* Rev 1.1 - 15-Jul-97 : Added define check
8 ;* Rev 1.2 - 18-Jul-97 : Added revision check macro
9 ;* Rev 1.3 - 19-Jul-97 : Modified for RGBASM V1.05
10 ;* Rev 1.4 - 27-Jul-97 : Modified for new subroutine prefixes
11 ;* Rev 1.5 - 15-Aug-97 : Added _HRAM, PAD, CART defines
12 ;* : and Nintendo Logo
13 ;* Rev 1.6 - 30-Nov-97 : Added rDIV, rTIMA, rTMA, & rTAC
14 ;* Rev 1.7 - 31-Jan-98 : Added _SCRN0, _SCRN1
15 ;* Rev 1.8 - 15-Feb-98 : Added rSB, rSC
16 ;* Rev 1.9 - 16-Feb-98 : Converted I/O registers to $FFXX format
17 ;* Rev 2.0 - : Added GBC registers
18 ;* Rev 2.1 - : Added MBC5 & cart RAM enable/disable defines
19 ;* Rev 2.2 : Fixed NR42,NR43, & NR44 equates
20 ;* Rev 2.3 - : Fixed incorrect _HRAM equate
21 ;* Rev 2.4 - : Completed CART defines
22 ;* Rev 2.5 - : Fixed bug in CART defines
23
24 ; If all of these are already defined, don't do it again.
25
26 IF !DEF(HARDWARE_INC)
27 HARDWARE_INC SET 1
28
29 rev_Check_hardware_inc: MACRO
30 ;NOTE: REVISION NUMBER CHANGES MUST BE ADDED
31 ;TO SECOND PARAMETER IN FOLLOWING LINE.
32 IF \1 > 2.2 ;PUT REVISION NUMBER HERE
33 WARN "Version \1 or later of 'hardware.inc' is required."
34 ENDC
35 ENDM
36
37 _HW EQU $FF00
38
39 _VRAM EQU $8000 ; $8000->$A000
40 _SCRN0 EQU $9800 ; $9800->$9BFF
41 _SCRN1 EQU $9C00 ; $9C00->$9FFF
42 _RAM EQU $C000 ; $C000->$E000
43 _HRAM EQU $FF80 ; $FF80->$FFFE
44 _OAMRAM EQU $FE00 ; $FE00->$FE9F
45 _AUD3WAVERAM EQU $FF30 ; $FF30->$FF3F
46
47 ; *** MBC5 Equates ***
48
49 rRAMG EQU $0000 ; $0000->$1fff
50 rROMB0 EQU $2000 ; $2000->$2fff
51 rROMB1 EQU $3000 ; $3000->$3fff
52 rRAMB EQU $4000 ; $4000->$5fff
53
54
55 ; --
56 ; -- OAM flags
57 ; --
58
59 OAMF_PRI EQU %10000000 ; Priority
60 OAMF_YFLIP EQU %01000000 ; Y flip
61 OAMF_XFLIP EQU %00100000 ; X flip
62 OAMF_PAL0 EQU %00000000 ; Palette number; 0,1
63 OAMF_PAL1 EQU %00010000 ; Palette number; 0,1
64
65
66 ;***************************************************************************
67 ;*
68 ;* Custom registers
69 ;*
70 ;***************************************************************************
71
72 ; --
73 ; -- P1 ($FF00)
74 ; -- Register for reading joy pad info. (R/W)
75 ; --
76 rP1 EQU $FF00
77
78 P1F_5 EQU %00100000 ; P15 out port
79 P1F_4 EQU %00010000 ; P14 out port
80 P1F_3 EQU %00001000 ; P13 in port
81 P1F_2 EQU %00000100 ; P12 in port
82 P1F_1 EQU %00000010 ; P11 in port
83 P1F_0 EQU %00000001 ; P10 in port
84
85 ; --
86 ; -- SB ($FF01)
87 ; -- Serial Transfer Data (R/W)
88 ; --
89 rSB EQU $FF01
90
91 ; --
92 ; -- SC ($FF02)
93 ; -- Serial I/O Control (R/W)
94 ; --
95 rSC EQU $FF02
96
97 ; --
98 ; -- DIV ($FF04)
99 ; -- Divider register (R/W)
100 ; --
101 rDIV EQU $FF04
102
103
104 ; --
105 ; -- TIMA ($FF05)
106 ; -- Timer counter (R/W)
107 ; --
108 rTIMA EQU $FF05
109
110
111 ; --
112 ; -- TMA ($FF06)
113 ; -- Timer modulo (R/W)
114 ; --
115 rTMA EQU $FF06
116
117
118 ; --
119 ; -- TAC ($FF07)
120 ; -- Timer control (R/W)
121 ; --
122 rTAC EQU $FF07
123
124 TACF_START EQU %00000100
125 TACF_STOP EQU %00000000
126 TACF_4KHZ EQU %00000000
127 TACF_16KHZ EQU %00000011
128 TACF_65KHZ EQU %00000010
129 TACF_262KHZ EQU %00000001
130
131 ; --
132 ; -- IF ($FF0F)
133 ; -- Interrupt Flag (R/W)
134 ; --
135 rIF EQU $FF0F
136
137 ; --
138 ; -- LCDC ($FF40)
139 ; -- LCD Control (R/W)
140 ; --
141 rLCDC EQU $FF40
142
143 LCDCF_OFF EQU %00000000 ; LCD Control Operation
144 LCDCF_ON EQU %10000000 ; LCD Control Operation
145 LCDCF_WIN9800 EQU %00000000 ; Window Tile Map Display Select
146 LCDCF_WIN9C00 EQU %01000000 ; Window Tile Map Display Select
147 LCDCF_WINOFF EQU %00000000 ; Window Display
148 LCDCF_WINON EQU %00100000 ; Window Display
149 LCDCF_BG8800 EQU %00000000 ; BG & Window Tile Data Select
150 LCDCF_BG8000 EQU %00010000 ; BG & Window Tile Data Select
151 LCDCF_BG9800 EQU %00000000 ; BG Tile Map Display Select
152 LCDCF_BG9C00 EQU %00001000 ; BG Tile Map Display Select
153 LCDCF_OBJ8 EQU %00000000 ; OBJ Construction
154 LCDCF_OBJ16 EQU %00000100 ; OBJ Construction
155 LCDCF_OBJOFF EQU %00000000 ; OBJ Display
156 LCDCF_OBJON EQU %00000010 ; OBJ Display
157 LCDCF_BGOFF EQU %00000000 ; BG Display
158 LCDCF_BGON EQU %00000001 ; BG Display
159 ; "Window Character Data Select" follows BG
160
161
162 ; --
163 ; -- STAT ($FF41)
164 ; -- LCDC Status (R/W)
165 ; --
166 rSTAT EQU $FF41
167
168 STATF_LYC EQU %01000000 ; LYCEQULY Coincidence (Selectable)
169 STATF_MODE10 EQU %00100000 ; Mode 10
170 STATF_MODE01 EQU %00010000 ; Mode 01 (V-Blank)
171 STATF_MODE00 EQU %00001000 ; Mode 00 (H-Blank)
172 STATF_LYCF EQU %00000100 ; Coincidence Flag
173 STATF_HB EQU %00000000 ; H-Blank
174 STATF_VB EQU %00000001 ; V-Blank
175 STATF_OAM EQU %00000010 ; OAM-RAM is used by system
176 STATF_LCD EQU %00000011 ; Both OAM and VRAM used by system
177 STATF_BUSY EQU %00000010 ; When set, VRAM access is unsafe
178
179
180 ; --
181 ; -- SCY ($FF42)
182 ; -- Scroll Y (R/W)
183 ; --
184 rSCY EQU $FF42
185
186
187 ; --
188 ; -- SCY ($FF43)
189 ; -- Scroll X (R/W)
190 ; --
191 rSCX EQU $FF43
192
193
194 ; --
195 ; -- LY ($FF44)
196 ; -- LCDC Y-Coordinate (R)
197 ; --
198 ; -- Values range from 0->153. 144->153 is the VBlank period.
199 ; --
200 rLY EQU $FF44
201
202
203 ; --
204 ; -- LYC ($FF45)
205 ; -- LY Compare (R/W)
206 ; --
207 ; -- When LYEQUEQULYC, STATF_LYCF will be set in STAT
208 ; --
209 rLYC EQU $FF45
210
211
212 ; --
213 ; -- DMA ($FF46)
214 ; -- DMA Transfer and Start Address (W)
215 ; --
216 rDMA EQU $FF46
217
218
219 ; --
220 ; -- BGP ($FF47)
221 ; -- BG Palette Data (W)
222 ; --
223 ; -- Bit 7-6 - Intensity for %11
224 ; -- Bit 5-4 - Intensity for %10
225 ; -- Bit 3-2 - Intensity for %01
226 ; -- Bit 1-0 - Intensity for %00
227 ; --
228 rBGP EQU $FF47
229
230
231 ; --
232 ; -- OBP0 ($FF48)
233 ; -- Object Palette 0 Data (W)
234 ; --
235 ; -- See BGP for info
236 ; --
237 rOBP0 EQU $FF48
238
239
240 ; --
241 ; -- OBP1 ($FF49)
242 ; -- Object Palette 1 Data (W)
243 ; --
244 ; -- See BGP for info
245 ; --
246 rOBP1 EQU $FF49
247
248
249 ; --
250 ; -- WY ($FF4A)
251 ; -- Window Y Position (R/W)
252 ; --
253 ; -- 0 <EQU WY <EQU 143
254 ; --
255 rWY EQU $FF4A
256
257
258 ; --
259 ; -- WX ($FF4B)
260 ; -- Window X Position (R/W)
261 ; --
262 ; -- 7 <EQU WX <EQU 166
263 ; --
264 rWX EQU $FF4B
265
266
267 ; --
268 ; -- KEY 1 ($FF4D)
269 ; -- Select CPU Speed (R/W)
270 ; --
271 rKEY1 EQU $FF4D
272
273
274 ; --
275 ; -- VBK ($FF4F)
276 ; -- Select Video RAM Bank (R/W)
277 ; --
278 rVBK EQU $FF4F
279
280
281 ; --
282 ; -- HDMA1 ($FF51)
283 ; -- Horizontal Blanking, General Purpose DMA (W)
284 ; --
285 rHDMA1 EQU $FF51
286
287
288 ; --
289 ; -- HDMA2 ($FF52)
290 ; -- Horizontal Blanking, General Purpose DMA (W)
291 ; --
292 rHDMA2 EQU $FF52
293
294
295 ; --
296 ; -- HDMA3 ($FF53)
297 ; -- Horizontal Blanking, General Purpose DMA (W)
298 ; --
299 rHDMA3 EQU $FF53
300
301
302 ; --
303 ; -- HDMA4 ($FF54)
304 ; -- Horizontal Blanking, General Purpose DMA (W)
305 ; --
306 rHDMA4 EQU $FF54
307
308
309 ; --
310 ; -- HDMA5 ($FF55)
311 ; -- Horizontal Blanking, General Purpose DMA (R/W)
312 ; --
313 rHDMA5 EQU $FF55
314
315
316 ; --
317 ; -- RP ($FF56)
318 ; -- Infrared Communications Port (R/W)
319 ; --
320 rRP EQU $FF56
321
322
323 ; --
324 ; -- BCPS ($FF68)
325 ; -- Background Color Palette Specification (R/W)
326 ; --
327 rBCPS EQU $FF68
328
329
330 ; --
331 ; -- BCPD ($FF69)
332 ; -- Background Color Palette Data (R/W)
333 ; --
334 rBCPD EQU $FF69
335
336
337 ; --
338 ; -- BCPS ($FF6A)
339 ; -- Object Color Palette Specification (R/W)
340 ; --
341 rOCPS EQU $FF6A
342
343
344 ; --
345 ; -- BCPD ($FF6B)
346 ; -- Object Color Palette Data (R/W)
347 ; --
348 rOCPD EQU $FF6B
349
350
351 ; --
352 ; -- SVBK ($FF4F)
353 ; -- Select Main RAM Bank (R/W)
354 ; --
355 rSVBK EQU $FF70
356
357
358 ; --
359 ; -- IE ($FFFF)
360 ; -- Interrupt Enable (R/W)
361 ; --
362 rIE EQU $FFFF
363
364
365 IEF_HILO EQU %00010000 ; Transition from High to Low of Pin number P10-P13
366 IEF_SERIAL EQU %00001000 ; Serial I/O transfer end
367 IEF_TIMER EQU %00000100 ; Timer Overflow
368 IEF_LCDC EQU %00000010 ; LCDC (see STAT)
369 IEF_VBLANK EQU %00000001 ; V-Blank
370
371
372
373
374 ;***************************************************************************
375 ;*
376 ;* Sound control registers
377 ;*
378 ;***************************************************************************
379
380 ; --
381 ; -- AUDVOL/NR50 ($FF24)
382 ; -- Channel control / ON-OFF / Volume (R/W)
383 ; --
384 ; -- Bit 7 - Vin->SO2 ON/OFF (Vin??)
385 ; -- Bit 6-4 - SO2 output level (volume) (# 0-7)
386 ; -- Bit 3 - Vin->SO1 ON/OFF (Vin??)
387 ; -- Bit 2-0 - SO1 output level (volume) (# 0-7)
388 ; --
389 rNR50 EQU $FF24
390 rAUDVOL EQU rNR50
391
392
393 ; --
394 ; -- AUDTERM/NR51 ($FF25)
395 ; -- Selection of Sound output terminal (R/W)
396 ; --
397 ; -- Bit 7 - Output sound 4 to SO2 terminal
398 ; -- Bit 6 - Output sound 3 to SO2 terminal
399 ; -- Bit 5 - Output sound 2 to SO2 terminal
400 ; -- Bit 4 - Output sound 1 to SO2 terminal
401 ; -- Bit 3 - Output sound 4 to SO1 terminal
402 ; -- Bit 2 - Output sound 3 to SO1 terminal
403 ; -- Bit 1 - Output sound 2 to SO1 terminal
404 ; -- Bit 0 - Output sound 0 to SO1 terminal
405 ; --
406 rNR51 EQU $FF25
407 rAUDTERM EQU rNR51
408
409
410 ; --
411 ; -- AUDENA/NR52 ($FF26)
412 ; -- Sound on/off (R/W)
413 ; --
414 ; -- Bit 7 - All sound on/off (sets all audio regs to 0!)
415 ; -- Bit 3 - Sound 4 ON flag (doesn't work!)
416 ; -- Bit 2 - Sound 3 ON flag (doesn't work!)
417 ; -- Bit 1 - Sound 2 ON flag (doesn't work!)
418 ; -- Bit 0 - Sound 1 ON flag (doesn't work!)
419 ; --
420 rNR52 EQU $FF26
421 rAUDENA EQU rNR52
422
423
424 ;***************************************************************************
425 ;*
426 ;* SoundChannel #1 registers
427 ;*
428 ;***************************************************************************
429
430 ; --
431 ; -- AUD1SWEEP/NR10 ($FF10)
432 ; -- Sweep register (R/W)
433 ; --
434 ; -- Bit 6-4 - Sweep Time
435 ; -- Bit 3 - Sweep Increase/Decrease
436 ; -- 0: Addition (frequency increases???)
437 ; -- 1: Subtraction (frequency increases???)
438 ; -- Bit 2-0 - Number of sweep shift (# 0-7)
439 ; -- Sweep Time: (n*7.8ms)
440 ; --
441 rNR10 EQU $FF10
442 rAUD1SWEEP EQU rNR10
443
444
445 ; --
446 ; -- AUD1LEN/NR11 ($FF11)
447 ; -- Sound length/Wave pattern duty (R/W)
448 ; --
449 ; -- Bit 7-6 - Wave Pattern Duty (00:12.5% 01:25% 10:50% 11:75%)
450 ; -- Bit 5-0 - Sound length data (# 0-63)
451 ; --
452 rNR11 EQU $FF11
453 rAUD1LEN EQU rNR11
454
455
456 ; --
457 ; -- AUD1ENV/NR12 ($FF12)
458 ; -- Envelope (R/W)
459 ; --
460 ; -- Bit 7-4 - Initial value of envelope
461 ; -- Bit 3 - Envelope UP/DOWN
462 ; -- 0: Decrease
463 ; -- 1: Range of increase
464 ; -- Bit 2-0 - Number of envelope sweep (# 0-7)
465 ; --
466 rNR12 EQU $FF12
467 rAUD1ENV EQU rNR12
468
469
470 ; --
471 ; -- AUD1LOW/NR13 ($FF13)
472 ; -- Frequency lo (W)
473 ; --
474 rNR13 EQU $FF13
475 rAUD1LOW EQU rNR13
476
477
478 ; --
479 ; -- AUD1HIGH/NR14 ($FF14)
480 ; -- Frequency hi (W)
481 ; --
482 ; -- Bit 7 - Initial (when set, sound restarts)
483 ; -- Bit 6 - Counter/consecutive selection
484 ; -- Bit 2-0 - Frequency's higher 3 bits
485 ; --
486 rNR14 EQU $FF14
487 rAUD1HIGH EQU rNR14
488
489
490 ;***************************************************************************
491 ;*
492 ;* SoundChannel #2 registers
493 ;*
494 ;***************************************************************************
495
496 ; --
497 ; -- AUD2LEN/NR21 ($FF16)
498 ; -- Sound Length; Wave Pattern Duty (R/W)
499 ; --
500 ; -- see AUD1LEN for info
501 ; --
502 rNR21 EQU $FF16
503 rAUD2LEN EQU rNR21
504
505
506 ; --
507 ; -- AUD2ENV/NR22 ($FF17)
508 ; -- Envelope (R/W)
509 ; --
510 ; -- see AUD1ENV for info
511 ; --
512 rNR22 EQU $FF17
513 rAUD2ENV EQU rNR22
514
515
516 ; --
517 ; -- AUD2LOW/NR23 ($FF18)
518 ; -- Frequency lo (W)
519 ; --
520 rNR23 EQU $FF18
521 rAUD2LOW EQU rNR23
522
523
524 ; --
525 ; -- AUD2HIGH/NR24 ($FF19)
526 ; -- Frequency hi (W)
527 ; --
528 ; -- see AUD1HIGH for info
529 ; --
530 rNR24 EQU $FF19
531 rAUD2HIGH EQU rNR24
532
533
534 ;***************************************************************************
535 ;*
536 ;* SoundChannel #3 registers
537 ;*
538 ;***************************************************************************
539
540 ; --
541 ; -- AUD3ENA/NR30 ($FF1A)
542 ; -- Sound on/off (R/W)
543 ; --
544 ; -- Bit 7 - Sound ON/OFF (1EQUON,0EQUOFF)
545 ; --
546 rNR30 EQU $FF1A
547 rAUD3ENA EQU rNR30
548
549
550 ; --
551 ; -- AUD3LEN/NR31 ($FF1B)
552 ; -- Sound length (R/W)
553 ; --
554 ; -- Bit 7-0 - Sound length
555 ; --
556 rNR31 EQU $FF1B
557 rAUD3LEN EQU rNR31
558
559
560 ; --
561 ; -- AUD3LEVEL/NR32 ($FF1C)
562 ; -- Select output level
563 ; --
564 ; -- Bit 6-5 - Select output level
565 ; -- 00: 0/1 (mute)
566 ; -- 01: 1/1
567 ; -- 10: 1/2
568 ; -- 11: 1/4
569 ; --
570 rNR32 EQU $FF1C
571 rAUD3LEVEL EQU rNR32
572
573
574 ; --
575 ; -- AUD3LOW/NR33 ($FF1D)
576 ; -- Frequency lo (W)
577 ; --
578 ; -- see AUD1LOW for info
579 ; --
580 rNR33 EQU $FF1D
581 rAUD3LOW EQU rNR33
582
583
584 ; --
585 ; -- AUD3HIGH/NR34 ($FF1E)
586 ; -- Frequency hi (W)
587 ; --
588 ; -- see AUD1HIGH for info
589 ; --
590 rNR34 EQU $FF1E
591 rAUD3HIGH EQU rNR34
592
593
594 ; --
595 ; -- AUD4LEN/NR41 ($FF20)
596 ; -- Sound length (R/W)
597 ; --
598 ; -- Bit 5-0 - Sound length data (# 0-63)
599 ; --
600 rNR41 EQU $FF20
601 rAUD4LEN EQU rNR41
602
603
604 ; --
605 ; -- AUD4ENV/NR42 ($FF21)
606 ; -- Envelope (R/W)
607 ; --
608 ; -- see AUD1ENV for info
609 ; --
610 rNR42 EQU $FF21
611 rAUD4ENV EQU rNR42
612
613
614 ; --
615 ; -- AUD4POLY/NR43 ($FF22)
616 ; -- Polynomial counter (R/W)
617 ; --
618 ; -- Bit 7-4 - Selection of the shift clock frequency of the (scf)
619 ; -- polynomial counter (0000-1101)
620 ; -- freqEQUdrf*1/2^scf (not sure)
621 ; -- Bit 3 - Selection of the polynomial counter's step
622 ; -- 0: 15 steps
623 ; -- 1: 7 steps
624 ; -- Bit 2-0 - Selection of the dividing ratio of frequencies (drf)
625 ; -- 000: f/4 001: f/8 010: f/16 011: f/24
626 ; -- 100: f/32 101: f/40 110: f/48 111: f/56 (fEQU4.194304 Mhz)
627 ; --
628 rNR43 EQU $FF22
629 rAUD4POLY EQU rNR43
630
631
632 ; --
633 ; -- AUD4GO/NR44 ($FF23)
634 ; -- (has wrong name and value (ff30) in Dr.Pan's doc!)
635 ; --
636 ; -- Bit 7 - Inital
637 ; -- Bit 6 - Counter/consecutive selection
638 ; --
639 rNR44 EQU $FF23
640 rAUD4GO EQU rNR44 ; silly name!
641
642 ;***************************************************************************
643 ;*
644 ;* Cart related
645 ;*
646 ;***************************************************************************
647
648 CART_ROM EQU 0 ; ROM
649 CART_ROM_MBC1 EQU 1 ; ROM+MBC1
650 CART_ROM_MBC1_RAM EQU 2 ; ROM+MBC1+RAM
651 CART_ROM_MBC1_RAM_BAT EQU 3 ; ROM+MBC1+RAM+BATTERY
652 CART_ROM_MBC2 EQU 5 ; ROM+MBC2
653 CART_ROM_MBC2_BAT EQU 6 ; ROM+MBC2+BATTERY
654 CART_ROM_RAM EQU 8 ; ROM+RAM
655 CART_ROM_RAM_BAT EQU 9 ; ROM+RAM+BATTERY
656 CART_ROM_MMM EQU $b ; ROM+MMM01
657 CART_ROM_RAM_MMM EQU $c ; ROM+RAM+MMM01
658 CART_ROM_RAM_MMM_BAT EQU $d ; ROM+RAM+MMM01+BATTERY
659 CART_ROM_MBC3_TIM_BAT EQU $f ; ROM+MBC3+TIMER+BATTERY
660 CART_ROM_MBC3_TIM_RAM_BAT EQU $10 ; ROM+MBC3+TIMER+RAM+BATTERY
661 CART_ROM_MBC3 EQU $11 ; ROM+MBC3
662 CART_ROM_MBC3_RAM EQU $12 ; ROM+MBC3+RAM
663 CART_ROM_MBC3_RAM_BAT EQU $13 ; ROM+MBC3+RAM+BATTERY
664 CART_ROM_MBC4 EQU $15 ; ROM+MBC4
665 CART_ROM_MBC4_RAM EQU $16 ; ROM+MBC4+RAM
666 CART_ROM_MBC4_RAM_BAT EQU $17 ; ROM+MBC4+RAM+BATTERY
667 CART_ROM_MBC5 EQU $19 ; ROM+MBC5
668 CART_ROM_MBC5_RAM EQU $1a ; ROM+MBC5+RAM
669 CART_ROM_MBC5_RAM_BAT EQU $1b ; ROM+MBC5+RAM+BATTERY
670 CART_ROM_MBC5_RUM EQU $1c ; ROM+MBC5+RUMBLE
671 CART_ROM_MBC5_RUM_RAM EQU $1d ; ROM+MBC5+RUMBLE+RAM
672 CART_ROM_MBC5_RUM_RAM_BAT EQU $1e ; ROM+MBC5+RUMBLE+RAM+BATTERY
673 CART_CAMERA EQU $fc ; Camera ROM
674 CART_TAMA5 EQU $fd ; Bandai Tama 5
675 CART_HuC3 EQU $fe ; HuC3
676 CART_HuC1_RAM_BAT EQU $ff ; HuC1+RAM+BATTERY
677
678 CART_ROM_256K EQU 0
679 CART_ROM_512K EQU 1
680 CART_ROM_1M EQU 2
681 CART_ROM_2M EQU 3
682 CART_ROM_4M EQU 4
683 CART_ROM_8M EQU 5
684 CART_ROM_16M EQU 6
685
686 CART_RAM_NONE EQU 0
687 CART_RAM_16K EQU 1
688 CART_RAM_64K EQU 2
689 CART_RAM_256K EQU 3
690
691 CART_RAM_ENABLE EQU $0a
692 CART_RAM_DISABLE EQU $00
693
694 ;***************************************************************************
695 ;*
696 ;* Keypad related
697 ;*
698 ;***************************************************************************
699
700 PADF_DOWN EQU $80
701 PADF_UP EQU $40
702 PADF_LEFT EQU $20
703 PADF_RIGHT EQU $10
704 PADF_START EQU $08
705 PADF_SELECT EQU $04
706 PADF_B EQU $02
707 PADF_A EQU $01
708
709 PADB_DOWN EQU $7
710 PADB_UP EQU $6
711 PADB_LEFT EQU $5
712 PADB_RIGHT EQU $4
713 PADB_START EQU $3
714 PADB_SELECT EQU $2
715 PADB_B EQU $1
716 PADB_A EQU $0
717
718 ;***************************************************************************
719 ;*
720 ;* Screen related
721 ;*
722 ;***************************************************************************
723
724 SCRN_X EQU 160 ; Width of screen in pixels
725 SCRN_Y EQU 144 ; Height of screen in pixels
726 SCRN_X_B EQU 20 ; Width of screen in bytes
727 SCRN_Y_B EQU 18 ; Height of screen in bytes
728
729 SCRN_VX EQU 256 ; Virtual width of screen in pixels
730 SCRN_VY EQU 256 ; Virtual height of screen in pixels
731 SCRN_VX_B EQU 32 ; Virtual width of screen in bytes
732 SCRN_VY_B EQU 32 ; Virtual height of screen in bytes
733
734 NINTENDO_LOGO: MACRO
735 ;*
736 ;* Nintendo scrolling logo
737 ;* (Code won't work on a real GameBoy)
738 ;* (if next six lines are altered.)
739 DB $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83,$00,$0C,$00,$0D
740 DB $00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6,$DD,$DD,$D9,$99
741 DB $BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F,$BB,$B9,$33,$3E
742 ENDM
743
744 ENDC ;HARDWARE_INC
Deletedbuild.bat +0−11
@@ -1,11 +0,0 @@
1 @echo off
2 rgbasm -odriver.obj driver.z80
3 if %errorlevel% neq 0 call :exit 1
4 rgblink -mdriver.map -ndriver.sym -odriver.gb driver.obj
5 if %errorlevel% neq 0 call :exit 1
6 rgbfix -p0 -v driver.gb
7 if %errorlevel% neq 0 call :exit 1
8 call :exit 0
9
10 :exit
11 exit
Deletedconstants.inc +0−77
@@ -1,77 +0,0 @@
1 ;; hUGETracker constants
2 ;; Written by SuperDisk 2019
3
4 C_3 EQU 0
5 C#3 EQU 1
6 D_3 EQU 2
7 D#3 EQU 3
8 E_3 EQU 4
9 F_3 EQU 5
10 F#3 EQU 6
11 G_3 EQU 7
12 G#3 EQU 8
13 A_3 EQU 9
14 A#3 EQU 10
15 B_3 EQU 11
16 C_4 EQU 12
17 C#4 EQU 13
18 D_4 EQU 14
19 D#4 EQU 15
20 E_4 EQU 16
21 F_4 EQU 17
22 F#4 EQU 18
23 G_4 EQU 19
24 G#4 EQU 20
25 A_4 EQU 21
26 A#4 EQU 22
27 B_4 EQU 23
28 C_5 EQU 24
29 C#5 EQU 25
30 D_5 EQU 26
31 D#5 EQU 27
32 E_5 EQU 28
33 F_5 EQU 29
34 F#5 EQU 30
35 G_5 EQU 31
36 G#5 EQU 32
37 A_5 EQU 33
38 A#5 EQU 34
39 B_5 EQU 35
40 C_6 EQU 36
41 C#6 EQU 37
42 D_6 EQU 38
43 D#6 EQU 39
44 E_6 EQU 40
45 F_6 EQU 41
46 F#6 EQU 42
47 G_6 EQU 43
48 G#6 EQU 44
49 A_6 EQU 45
50 A#6 EQU 46
51 B_6 EQU 47
52 C_7 EQU 48
53 C#7 EQU 49
54 D_7 EQU 50
55 D#7 EQU 51
56 E_7 EQU 52
57 F_7 EQU 53
58 F#7 EQU 54
59 G_7 EQU 55
60 G#7 EQU 56
61 A_7 EQU 57
62 A#7 EQU 58
63 B_7 EQU 59
64 C_8 EQU 60
65 C#8 EQU 61
66 D_8 EQU 62
67 D#8 EQU 63
68 E_8 EQU 64
69 F_8 EQU 65
70 F#8 EQU 66
71 G_8 EQU 67
72 G#8 EQU 68
73 A_8 EQU 69
74 A#8 EQU 70
75 B_8 EQU 71
76 LAST_NOTE EQU 72
77 ___ EQU 90 ; the default "no note" value
Deletedcrap.py +0−26
@@ -1,26 +0,0 @@
1 '''def saw(t):
2 return t & 255
3
4 def saw2(t):
5 return t & 31
6
7 for i in range(0,64,1):
8 print(saw2(i))
9 '''
10
11 def percentage(n):
12 x = 0
13 for i in range(0, 5):
14 if (i & n) == 0:
15 x += 1
16 #print(n, x/100, sep='\t')
17 return x/5
18
19 d = {}
20 for i in range(16):
21 p = percentage(i)
22 if p not in d:
23 d[p] = bin(i) + ", " + hex(i)
24
25 for item in d.items():
26 print(item)
Deleteddebug_macros.inc +0−6
@@ -1,6 +0,0 @@
1 ;; hUGETracker playback macros
2 ;; Written by SuperDisk 2019
3
4 print_a: MACRO
5 db $fd
6 ENDM
Deleteddriver-format.txt +0−31
@@ -1,31 +0,0 @@
1 Note instr effect
2 0000.0000-0000-0000.0000.0000
3
4 Stuff to do:
5 - Implement routines
6 - Reloading the wave buffer when Channel 3's instrument changes
7 - Some form of RLE compression
8
9 If note value is greater than 71 then it's considered to be an empty note cell.
10 Will probably add some sort of RLE encoding later with special notes greater than 71.
11
12 00 is an empty instrument cell.
13
14 000 is an empty effect cell.
15
16 0 - Arpeggio
17 1 - Slide up
18 2 - Slide down
19 3 - Toneporta
20 4 - Vibrato
21 5 - Set master volume
22 6 - Call routine
23 7 - Note delay
24 8 - Set panning
25 9 - Set duty cycle
26 A - Volslide
27 B - Position jump
28 C - Set volume
29 D - Pattern break
30 E - Note cut
31 F - Set speed
Deleteddriver.z80 +0−1651
@@ -1,1651 +0,0 @@
1 ;; hUGETracker playback routine
2 ;; Written by SuperDisk 2019
3
4 include "hardware.inc"
5 include "constants.inc"
6 include "debug_macros.inc"
7
8 add_a_to_r16: MACRO
9 add a, \2
10 ld \2, a
11 adc a, \1
12 sub \2
13 ld \1, a
14 ENDM
15
16 ;; TODO: See if there's a way to shave off a byte.
17 sub_from_r16: MACRO ;; (high, low, value)
18 ld a, \2
19 sub \3
20 ld \2, a
21 ld a, \1
22 sbc a, 0
23 ld \1, a
24 ENDM
25
26 add_a_to_hl: MACRO
27 add_a_to_r16 h, l
28 ENDM
29
30 add_a_to_de: MACRO
31 add_a_to_r16 d, e
32 ENDM
33
34 ret_dont_call_playnote: MACRO
35 pop hl
36 pop af
37 ld a, 6 ; How many bytes until the next channel's code
38 add_a_to_hl
39 jp hl
40 ENDM
41
42 ; Constants
43 STACK_SIZE EQU $7A
44 ;; Stack starts at $FFFE
45
46 PATTERN_LENGTH EQU 64
47 ; TICKS EQU 4
48
49 ; $0000 - $003F: RST handlers.
50
51 SECTION "restarts", ROM0[$0000]
52 ret
53 REPT 7
54 nop
55 ENDR
56 ; $0008
57 ret
58 REPT 7
59 nop
60 ENDR
61 ; $0010
62 ret
63 REPT 7
64 nop
65 ENDR
66 ; $0018
67 ret
68 REPT 7
69 nop
70 ENDR
71 ; $0020
72 ret
73 REPT 7
74 nop
75 ENDR
76 ; $0028
77 ret
78 REPT 7
79 nop
80 ENDR
81 ; $0030
82 ret
83 REPT 7
84 nop
85 ENDR
86 ; $0038
87 ret
88 REPT 7
89 nop
90 ENDR
91
92 ; Interrupt addresses
93 SECTION "Vblank interrupt", ROM0[$0040]
94 reti
95
96 SECTION "LCD controller status interrupt", ROM0[$0048]
97 call _dosound
98 reti
99
100 SECTION "Timer overflow interrupt", ROM0[$0050]
101 reti
102
103 SECTION "Serial transfer completion interrupt", ROM0[$0058]
104 reti
105
106 SECTION "P10-P13 signal low edge interrupt", ROM0[$0060]
107 reti
108
109 ; Reserved stack space
110 SECTION "Stack", HRAM[$FFFE - STACK_SIZE]
111 ds STACK_SIZE
112
113
114 ; Control starts here, but there's more ROM header several bytes later, so the
115 ; only thing we can really do is immediately jump to after the header
116 SECTION "init", ROM0[$0100]
117 nop
118 jp $0150
119
120 SECTION "romname", ROM0[$0134]
121 ; $0134 - $013E: The title, in upper-case letters, followed by zeroes.
122 DB "HUGE"
123 DS 7 ; padding
124 ; $013F - $0142: The manufacturer code. Empty for now
125 DS 4
126 DS 1
127 ; $0144 - $0145: "New" Licensee Code, a two character name.
128 DB "NF"
129
130 dn: MACRO ;; (note, instr, effect)
131 db \1
132 db ((\2 << 4) | (\3 >> 8))
133 db LOW(\3)
134 ENDM
135
136 SECTION "Song Data", ROM0
137 ;; order_cnt is the number of orders times 2
138 order_cnt: db 4
139 order1: dw tfau_arps, unreal
140 order2: dw silence, unreal_arps
141 order3: dw tfau_bass, silence3
142 order4: dw empty, empty
143
144 lunawaves:
145 include "lunawaves.inc"
146 unreal:
147 include "unreal.inc"
148 unreal_arps:
149 include "unreal_arps.inc"
150 tfau_arps:
151 include "tfau_arps.inc"
152 tfau_bass:
153 include "tfau_bass.inc"
154 empty:
155 rept 64
156 dn ___, 0, 0
157 endr
158 silence:
159 dn C_4, 1, $C00
160 rept 63
161 dn ___, 0, $000
162 endr
163 silence3:
164 dn C_4, 2, $C00
165 rept 63
166 dn ___, 0, $000
167 endr
168 testpatt:
169 rept 16
170 dn C_4, 1, $000
171 dn ___, 0, $000
172 dn ___, 0, $000
173 dn ___, 0, $000
174 dn ___, 0, $000
175 dn ___, 0, $000
176 dn ___, 0, $000
177 dn ___, 0, $000
178 endr
179 testpatt2:
180 dn C_4, 1, $000
181 rept 16
182 dn D_4, 0, $000
183 dn ___, 0, $000
184 dn ___, 0, $000
185 dn ___, 0, $000
186 dn ___, 0, $000
187 dn ___, 0, $000
188 dn ___, 0, $000
189 dn ___, 0, $000
190 endr
191 drums:
192 rept 16
193 dn C_4, 2, 0
194 dn ___, 0, 0
195 dn ___, 0, 0
196 dn ___, 0, 0
197 dn ___, 0, 0
198 dn ___, 0, 0
199 dn ___, 0, 0
200 dn ___, 0, 0
201 endr
202 walkup:
203 _ASDF = C_3
204 rept 64
205 dn _ASDF, 0, 0
206 _ASDF = _ASDF + 1
207 endr
208 slideup:
209 dn C_3, 00, $000
210 rept 63
211 dn ___, 00, $101
212 endr
213 arps:
214 rept 64
215 dn C_5, 00, $047
216 endr
217 vib:
218 dn C_5, 00, $000
219 rept 63
220 dn ___, 00, $443
221 endr
222 updown:
223 dn C_4, 00, $105
224 rept 31
225 dn ___, 00, $105
226 endr
227 rept 32
228 dn ___, 00, $205
229 endr
230 volset:
231 dn C_5, 00, $000
232 rept 32
233 dn ___, 00, $C90
234 dn ___, 00, $CF0
235 endr
236 notecut:
237 rept 32
238 dn C_5, 00, $E04
239 dn ___, 00, $000
240 endr
241 notedelay:
242 rept 32
243 dn C_5, 00, 00
244 dn D#5, 00, $704
245 endr
246 volslide:
247 dn C_5, 00, 00
248 rept 63
249 dn ___, 00, $A01
250 endr
251 setduty:
252 dn C_5, 00, $F04
253 rept 21
254 dn ___, 00, $900
255 dn ___, 00, $940
256 dn ___, 00, $980
257 dn ___, 00, $9C0
258 endr
259 setpan:
260 dn C_5, 00, $811
261 rept 15
262 dn ___, 00, 00
263 endr
264 dn C_5, 00, $801
265 rept 15
266 dn ___, 00, 00
267 endr
268 dn C_5, 00, $810
269 rept 15
270 dn ___, 00, 00
271 endr
272 dn C_5, 00, $800
273 rept 15
274 dn ___, 00, 00
275 endr
276
277 ;;;;;;;;;;;;;;;;
278 ;; Instruments
279 ;;;;;;;;;;;;;;;;
280
281 ;; Instruments come in blocks.
282
283 instruments:
284
285 ;; Format for channels 1 and 2:
286
287 square_instrument:
288 .sweep: db ; unused for channel 2
289 .length_and_duty: db %10000001
290 .envelope: db %11110000
291 .highmask: db %11000000
292
293 ;; Format for channel 3:
294
295 voice_instrument:
296 .length: db 0
297 .volume: db %00100000
298 .wave: db 0
299 .highmask: db %10000000
300
301 ;; Format for channel 4:
302
303 noise_instrument:
304 .length: db 0
305 .envelope: db %10100001
306 .step_and_ratio: db 0
307 .highmask: db %10000000
308
309 routines:
310
311 ;; nothing yet
312
313 SECTION "Playback variables", WRAM0
314 pattern1: dw
315 pattern2: dw
316 pattern3: dw
317 pattern4: dw
318
319 ticks_per_row: db
320 current_order: dw
321 next_order: dw
322 row_break: db
323
324 ;; TODO: Find some way to get rid of this thing.
325 temp_note_value: dw
326
327 ;; Size of a channel in bytes
328 CHANNEL_SIZE EQU 8
329 ;; Amount to be shifted in order to skip a channel.
330 CHANNEL_SIZE_EXPONENT EQU 3
331
332 channels:
333
334 ;;;;;;;;;;;
335 ;;Channel 1
336 ;;;;;;;;;;;
337 channel1:
338 channel_period1: dw
339 toneporta_target1: dw
340 channel_note1: db
341 vibrato_tremolo_phase1: db
342 envelope1: db
343 highmask1: db
344
345 ;;;;;;;;;;;
346 ;;Channel 2
347 ;;;;;;;;;;;
348 channel2:
349 channel_period2: dw
350 toneporta_target2: dw
351 channel_note2: db
352 vibrato_tremolo_phase2: db
353 envelope2: db
354 highmask2: db
355
356 ;;;;;;;;;;;
357 ;;Channel 3
358 ;;;;;;;;;;;
359 channel3:
360 channel_period3: dw
361 toneporta_target3: dw
362 channel_note3: db
363 vibrato_tremolo_phase3: db
364 envelope3: db
365 highmask3: db
366
367 ;;;;;;;;;;;
368 ;;Channel 4
369 ;;;;;;;;;;;
370 channel4:
371 channel_period4: dw
372 toneporta_target4: dw
373 channel_note4: db
374 vibrato_tremolo_phase4: db
375 envelope4: db
376 highmask4: db
377
378 row: ds 1
379 tick: ds 1
380
381 ; Initialization
382 SECTION "main", ROM0[$0150]
383 jp _init
384
385 _paint_tile:
386 ld a, b
387 ld [hl+], a
388 ld a, c
389 ld [hl+], a
390 ret
391
392 _init:
393 ; Set LCD palette for grayscale mode; yes, it has a palette
394 ld a, %11100100
395 ld [$FF00+$47], a
396
397 ;; Fill with pattern
398 ld hl, $8000
399 ld bc, `10000000
400 call _paint_tile
401 ld bc, `01000000
402 call _paint_tile
403 ld bc, `00100000
404 call _paint_tile
405 ld bc, `00010000
406 call _paint_tile
407 ld bc, `00001000
408 call _paint_tile
409 ld bc, `00000100
410 call _paint_tile
411 ld bc, `00000010
412 call _paint_tile
413 ld bc, `00000001
414 call _paint_tile
415
416 ;; Load some wave data (or code) into _AUD3WAVERAM
417 ld hl, $000 ;; note_table
418 _addr = _AUD3WAVERAM
419 REPT 16
420 ld a, [hl+]
421 ld [_addr], a
422 _addr = _addr + 1
423 ENDR
424
425 ;; Enable chanel 3
426 ld a, %10000000
427 ld [rAUD3ENA], a
428 ld a, $ff ;; full length (although this does nothing)
429 ld [rAUD3LEN], a
430 ld a, %0000000 ; 0%
431 ld [rAUD3LEVEL], a
432
433 ld a, %11110000
434 ld [envelope1], a
435 ld a, %11110000
436 ld [envelope2], a
437
438 ;; Load starting speed (7 ticks per row)
439 ld a, 7
440 ld [ticks_per_row], a
441
442 ; Enable sound globally
443 ld a, $80
444 ld [rAUDENA], a
445 ; Enable all channels in stereo
446 ld a, $FF
447 ld [rAUDTERM], a
448 ; Set volume
449 ld a, $77
450 ld [rAUDVOL], a
451
452 ld c, 0 ;; Current order index
453 call _refresh_patterns
454
455 ;; Enable the timer
456 ; ld a, TACF_START | TACF_4KHZ
457 ; ld [rTAC], a
458
459 ;; Enable the HBlank interrupt on scanline 0
460 ld a, [rSTAT]
461 or a, STATF_LYC
462 ld [rSTAT], a
463 xor a ; ld a, 0
464 ld [rLYC], a
465
466 ld a, IEF_LCDC ; IEF_VBLANK; | IEF_LCDC ; IEF_HILO | IEF_TIMER
467 ld [rIE], a
468 ei
469
470 jp _halt
471
472 _refresh_patterns:
473 ;; Loads pattern registers with pointers to correct pattern based on
474 ;; an order index
475
476 ;; Call with c set to what order to load
477 load_pattern: MACRO
478 ld hl, 0
479 ld l, c
480 ld de, \1
481 add hl, de
482
483 ld a, [hl+]
484 ld [\2], a
485 ld a, [hl+]
486 ld [\2+1], a
487 ENDM
488 load_pattern order1, pattern1
489 load_pattern order2, pattern2
490 load_pattern order3, pattern3
491 load_pattern order4, pattern4
492 ret
493
494 _load_note_data:
495 ;; Call with:
496 ;; Pattern pointer in BC
497
498 ;; Stores instrument/effect code in B
499 ;; Stores effect params in C
500 ;; Stores note number in A
501 ld a, [row]
502 ld h, a
503 ;; Multiply by 3 for the note value
504 add h
505 add h
506
507 add 2
508 ld h, 0
509 ld l, a
510 add hl, bc ; HL now points at the 3rd byte of the note
511 ld a, [hl-]
512 ld c, a
513 ld a, [hl-]
514 ld b, a
515
516 ld a, [hl]
517
518 ret
519
520 _lookup_note:
521 ;; Call with:
522 ;; Pattern pointer in BC
523 ;; channel_noteX pointer in DE
524
525 ;; Stores note period value in HL
526 ;; Stores instrument/effect code in B
527 ;; Stores effect params in C
528 ;; Stores note number in the memory pointed to by DE
529 call _load_note_data
530 ld hl, 0
531
532 ;; If the note we found is greater than LAST_NOTE, then it's not a valid note
533 ;; and nothing needs to be updated.
534 cp LAST_NOTE
535 ret nc
536
537 ;; Store the loaded note value in channel_noteX
538 ld h, d
539 ld l, e
540 ld [hl], a
541
542 _convert_note:
543 ;; Call with:
544 ;; Note number in A
545 ;; Stores note period value in HL
546
547 add a ;; double it to get index into hi/lo table
548
549 ld hl, note_table
550 add_a_to_hl
551 ld a, [hl+]
552 ld h, [hl]
553 ld l, a
554
555 ;; Need to clear the carry flag-- this complements it, but since the last
556 ;; thing that modified the flag always sets it, this will clear it.
557 ccf
558 ret
559
560 _update_channel:
561 ;; Call with:
562 ;; Channel in B
563 ;; Note tone in DE
564
565 ;; TODO: Turn this into a jump table? Or find some other way to optimize
566 ld a, b
567
568 cp 3
569 jp z, _update_channel4
570 cp 2
571 jp z, _update_channel3
572 cp 1
573 jp z, _update_channel2
574
575 _update_channel1:
576 ld hl, highmask1
577 ld a, e
578 ld [rAUD1LOW], a
579 ld a, d
580 ; or [hl]
581 ; and %01111111
582 ld [rAUD1HIGH], a
583 ret
584 _update_channel2:
585 ld hl, highmask2
586 ld a, e
587 ld [rAUD2LOW], a
588 ld a, d
589 ; or [hl]
590 ; and %01111111
591 ld [rAUD2HIGH], a
592 ret
593 _update_channel3:
594 ld hl, highmask3
595 ld a, e
596 ld [rAUD3LOW], a
597 ld a, d
598 ; or [hl]
599 ; and %01111111
600 ld [rAUD3HIGH], a
601 ret
602 _update_channel4:
603 ld hl, highmask4
604 call _quantize_channel4_note
605 ld [rAUD4POLY], a
606 ; ld a, [hl]
607 ; and %01111111
608 ld a, 0
609 ld [rAUD4GO], a
610 ret
611
612 ;;;;;;;
613 ;; Note playing routines. Need to either consolidate these or find some
614 ;; better way of doing effects that happen on the first tick.
615 ;;;;;;;
616
617 _playnote1:
618 ;; Call with:
619
620 ;; Play a note on channel 1 (square wave)
621 ld a, [temp_note_value+1]
622 ld [channel_period1], a
623 ld [rAUD1LOW], a
624
625 ld a, [temp_note_value]
626 ld [channel_period1+1], a
627
628 ;; Get the highmask and apply it.
629 ld hl, highmask1
630 or [hl]
631 ld [rAUD1HIGH], a
632
633 ret
634
635 _playnote2:
636 ;; Play a note on channel 2 (square wave)
637 ld a, [temp_note_value+1]
638 ld [channel_period2], a
639 ld [rAUD2LOW], a
640
641 ld a, [temp_note_value]
642 ld [channel_period2+1], a
643
644 ;; Get the highmask and apply it.
645 ld hl, highmask2
646 or [hl]
647 ld [rAUD2HIGH], a
648
649 ret
650
651 _playnote3:
652 ;; Play a note on channel 3 (waveform)
653 ld a, [temp_note_value+1]
654 ld [channel_period3], a
655 ld [rAUD3LOW], a
656
657 ld a, [temp_note_value]
658 ld [channel_period3+1], a
659
660 ;; Get the highmask and apply it.
661 ld hl, highmask3
662 or [hl]
663 ld [rAUD3HIGH], a
664
665 ret
666
667 _playnote4:
668 ;; Play a "note" on channel 4 (noise)
669
670 ld a, [temp_note_value+1]
671 ld [channel_period4], a
672 ld e, a
673
674 ld a, [temp_note_value]
675 ld [channel_period4+1], a
676 ld d, a
677
678 call _quantize_channel4_note
679 ld b, a
680
681 ld a, [rAUD4POLY]
682 or b
683 ld [rAUD4POLY], a
684
685 ;; Get the highmask and apply it.
686 ld hl, highmask4
687 or [hl]
688 ld [rAUD4GO], a
689
690 ret
691
692 _quantize_channel4_note:
693 ;; Shift the "note value" right by 7 to get a spread from 0 to 15.
694 ;; Keep just the upmost bit of the lower byte
695 ld a, e
696 and %10000000
697 rla
698 ld c, a
699
700 ;; Keep the entire upper byte (but it's never the full 8 bits)
701 ld a, d
702 rla
703 or c
704 swap a
705 ret
706
707 _doeffect:
708 ;; Call with:
709 ;; B: instrument nibble + effect type nibble
710 ;; C: effect parameters
711 ;; E: channel
712
713 ;; free: A, D, H, L
714
715 ;; Strip the instrument bits off leaving only effect code
716 ld a, b
717 and %00001111
718 ld b, a
719
720 ;; Multiply by 3 to get offset into table
721 ld a, b
722 add a, b
723 add a, b
724
725 ld hl, .jump
726 add_a_to_hl
727
728 ld b, e
729 ld a, [tick]
730 cp 0
731 ; or a ; We can return right off the bat if it's tick zero
732 jp hl
733
734 .jump:
735 ;; Jump table for effect
736 jp fx_arpeggio ;0xy
737 jp fx_porta_up ;1xy
738 jp fx_porta_down ;2xy
739 jp fx_toneporta ;3xy
740 jp fx_vibrato ;4xy
741 jp fx_set_master_volume ;5xy
742 jp fx_call_routine ;6xy
743 jp fx_note_delay ;7xy
744 jp fx_set_pan ;8xy
745 jp fx_set_duty ;9xy
746 jp fx_vol_slide ;Axy
747 jp fx_pos_jump ;Bxy
748 jp fx_set_volume ;Cxy
749 jp fx_pattern_break ;Dxy
750 jp fx_note_cut ;Exy
751 jp fx_set_speed ;Fxy
752
753 setup_channel_pointer:
754 ;; Call with:
755 ;; Channel value in B
756 ;; Offset in D
757 ;; Returns value in HL
758
759 ld a, b
760 REPT CHANNEL_SIZE_EXPONENT
761 sla a
762 ENDR
763 add d
764 ld hl, channels
765 add_a_to_hl
766 ret
767
768 fx_set_master_volume:
769 ret nz
770 ;; B: channel
771 ;; C: effect parameters
772
773 ;; free registers: A, D, E, H, L
774
775 ;; Upper 4 bits contain volume for left, lower 4 bits for right
776 ;; Format is ?LLL ?RRR where ? is just a random bit, since we don't use
777 ;; the Vin
778
779 ;; This can be used as a more fine grained control over channel 3's output,
780 ;; if you pan it completely.
781
782 ld a, c
783 ld [rAUDVOL], a
784 ret
785
786 fx_call_routine:
787 ;; B: channel
788 ;; C: effect parameters
789
790 ;; free registers: A, D, E, H, L
791
792 ;; Routines are 16 bytes. Shift left to multiply by 16, then
793 ;; jump to that location.
794
795 ld hl, routines
796 ld a, c
797 swap a
798 ; and %11110000 is this necessary?
799 ; sla c
800 ; sla c
801 ; sla c
802 ; sla c
803 ; ld a, c
804 add_a_to_hl
805 jp hl
806
807 fx_set_pan:
808 ret nz
809
810 ;; B: channel
811 ;; C: effect parameters
812
813 ;; free registers: A, D, E, H, L
814
815 ;; Pretty simple. The editor can create the correct value here without a bunch
816 ;; of bit shifting manually.
817
818 ld a, c
819 ld [rAUDTERM], a
820 ret
821
822 fx_set_duty:
823 ret nz
824
825 ;; B: channel
826 ;; C: effect parameters
827
828 ;; free registers: A, D, E, H, L
829
830 ;; $900 = 12.5%
831 ;; $940 = 25%
832 ;; $980 = 50%
833 ;; $9C0 = 75%
834
835 ld a, b
836 or a ; cp 0
837 jp z, .chan1
838 .chan2:
839 ld a, c
840 ld [rAUD2LEN], a
841 ret
842 .chan1:
843 ld a, c
844 ld [rAUD1LEN], a
845 ret
846
847 fx_vol_slide:
848 ret nz
849
850 ;; This is really more of a "retrigger note with lower volume" effect and thus
851 ;; isn't really that useful. Instrument envelopes should be used instead.
852 ;; Might replace this effect with something different if a new effect is
853 ;; ever needed.
854
855 ;; B: channel
856 ;; C: effect parameters
857
858 ;; free registers: A, D, E, H, L
859
860 ld d, 0
861 call setup_channel_pointer
862 ld a, [hl+]
863 ld e, [hl]
864 ld d, a
865
866 ld a, b
867 add a
868 ld hl, .envelope_registers
869 add_a_to_hl
870 ld a, [hl+]
871 ld h, [hl]
872 ld l, a
873
874 ;; setup the up and down params
875 ld a, c
876 and %00001111
877 ld d, a
878
879 ld a, c
880 and %11110000
881 ld e, a
882
883 ld a, [hl]
884 and %11110000
885 swap a
886 sub d
887 jp nc, .cont1
888 ld a, 0
889 .cont1:
890 add e
891 jp nc, .cont2
892 ld a, $F
893 .cont2:
894 swap a
895 ld [hl+], a
896
897 ld [hl], d
898 inc hl
899 ld a, e
900 or %10000000
901 ld [hl], a
902
903 ret
904
905 .envelope_registers:
906 dw rAUD1ENV
907 dw rAUD2ENV
908 dw rAUD4ENV
909 dw rAUD4ENV
910
911 fx_note_delay:
912 ;; B: channel
913 ;; C: effect parameters
914
915 ;; free registers: A, D, E, H, L
916
917 jp nz, .play_note
918
919 ;; Just store the note into the channel period, and don't play a note.
920 ld d, 0
921 call setup_channel_pointer
922
923 ld a, [temp_note_value]
924 ld [hl+], a
925 ld a, [temp_note_value+1]
926 ld [hl], a
927
928 ;; Don't call _playnote. This is done by grabbing the return
929 ;; address and manually skipping the next call instruction.
930 ret_dont_call_playnote
931
932 .play_note:
933 ld a, [tick]
934 cp c
935 ret nz ; wait until the correct tick to play the note
936
937 ld d, 0
938 call setup_channel_pointer
939
940 ;; TODO: Change this to accept HL instead?
941 ld a, [hl+]
942 ld [temp_note_value], a
943 ld a, [hl]
944 ld [temp_note_value+1], a
945
946 ;; Generalize this somehow?
947
948 ld hl, .play_note_routines
949 ld a, b
950 add b
951 add b
952 add_a_to_hl
953 jp hl
954
955 .play_note_routines:
956 jp _playnote1
957 jp _playnote2
958 jp _playnote3
959 jp _playnote4
960
961 fx_set_speed:
962 ret nz
963
964 ;; B: channel
965 ;; C: effect parameters
966
967 ;; free registers: A, D, E, H, L
968 ld a, c
969 ld [ticks_per_row], a
970 ret
971
972 fx_pos_jump:
973 ;; B: channel
974 ;; C: effect parameters
975
976 ;; free registers: A, D, E, H, L
977
978 ld a, 1
979 ld [row_break], a
980 ld a, c
981 ld [next_order], a
982
983 ret
984
985 fx_pattern_break:
986 ;; B: channel
987 ;; C: effect parameters
988
989 ;; free registers: A, D, E, H, L
990
991 ld a, c
992 ld [row_break], a
993
994 ret
995
996 ;; TODO: Fix this
997 fx_note_cut:
998 ;; B: channel
999 ;; C: effect parameters
1000
1001 ;; free registers: A, D, E, H, L
1002 ;; ld a, [tick]
1003 cp c
1004 ret nz
1005
1006 ld d, 0
1007 jp set_channel_volume
1008
1009 fx_set_volume:
1010 ret nz ;; Return if we're not on tick zero.
1011
1012 ;; B: channel
1013 ;; C: effect parameters
1014
1015 ;; free registers: A, D, E, H, L
1016
1017 ;; Arguments to this effect will be massaged to correct form for the channel
1018 ;; in the editor so we don't have to AND and SWAP and stuff.
1019
1020 set_channel_volume:
1021 ;; Call with:
1022 ;; Correct volume value in D
1023 ;; Channel number in B
1024
1025 ld a, b
1026 cp 1 ; check if it's channel 2
1027 jr c, set_chn_1_vol
1028 jr z, set_chn_2_vol
1029 set_chn_3_vol:
1030 ;; "Quantize" the more finely grained volume control down to one of 4 values.
1031 ld a, c
1032 swap a
1033 cp 0
1034 jr z, .zero
1035 cp 5
1036 jr nc, .one
1037 cp 10
1038 jr nc, .two
1039 .three:
1040 ld a, %01100000
1041 jr .done
1042 .two:
1043 ld a, %01000000
1044 jr .done
1045 .one:
1046 ld a, %00100000
1047 jr .done
1048 .zero:
1049 ld a, 0
1050 .done:
1051 ld [rAUD3LEVEL], a
1052 ret
1053 set_chn_2_vol:
1054 ; ld a, d
1055 ; and %00001111
1056 ; or c
1057 ld a, c
1058 ld [rAUD2ENV], a
1059
1060 ret
1061 set_chn_1_vol:
1062 ; ld a, d
1063 ; and %00001111
1064 ; or c
1065 ld a, c
1066 ld [rAUD1ENV], a
1067
1068 ret
1069
1070 fx_vibrato:
1071 ret z
1072 ;; B: channel
1073 ;; C: effect parameters
1074
1075 ;; free registers: A, D, E, H, L
1076
1077 ;; Extremely poor man's vibrato.
1078 ;; Speed values:
1079 ;; (0x0 = 1.0)
1080 ;; (0x1 = 0.5)
1081 ;; (0x3 = 0.25)
1082 ;; (0x7 = 0.125)
1083 ;; (0xf = 0.0625)
1084 ld d, 4
1085 call setup_channel_pointer
1086
1087 ld a, c
1088 and %11110000
1089 swap a
1090 ld d, a
1091
1092 ld a, [tick] ; Probably should change to some constantly ticking thing
1093 and d
1094 ld a, [hl-]
1095 jr z, .go_up
1096 .restore:
1097 dec hl
1098 dec hl
1099 ld a, [hl-]
1100 ld l, [hl]
1101 ld h, a
1102 jr .finish_vibrato
1103 .go_up:
1104 call _convert_note ; TODO: Find a way to grab it directly rather than recompute
1105 ld a, c
1106 and %00001111
1107 add_a_to_hl
1108 .finish_vibrato:
1109 ld d, h
1110 ld e, l
1111 jp _update_channel
1112
1113 fx_arpeggio:
1114 ret z
1115 ;; B: channel
1116 ;; C: effect parameters
1117
1118 ;; free registers: A, D, E, H, L
1119
1120 ld d, 4
1121 call setup_channel_pointer
1122
1123 ld a, [tick]
1124 dec a
1125
1126 ;; Multiply by 2 to get offset into table
1127 add a
1128
1129 ld d, [hl]
1130
1131 ld hl, .arp_options
1132 add_a_to_hl
1133 jp hl
1134
1135 ;; TODO: Make this work when TICKS != 6
1136 .arp_options:
1137 jr .set_arp1
1138 jr .set_arp2
1139 jr .reset_arp
1140 jr .set_arp1
1141 jr .set_arp2
1142 .reset_arp:
1143 ld a, d
1144 jr .finish_skip_add
1145 .set_arp2:
1146 ld a, c
1147 swap a
1148 jr .finish_arp
1149 .set_arp1:
1150 ld a, c
1151 .finish_arp:
1152 and %00001111
1153 add d
1154 .finish_skip_add:
1155 call _convert_note
1156 ld d, h
1157 ld e, l
1158 jp _update_channel
1159
1160 fx_porta_up:
1161 ret z
1162 ;; B: channel
1163 ;; C: effect parameters
1164
1165 ;; free registers: A, D, E, H, L
1166
1167 ld d, 0
1168 call setup_channel_pointer
1169
1170 ld a, [hl+]
1171 ld e, a
1172 ld d, [hl]
1173
1174 ld a, c
1175 add_a_to_de
1176
1177 ld a, d
1178 ld [hl-], a
1179 ld [hl], e
1180
1181 jp _update_channel
1182
1183 ;; TODO: Maybe merge with fx_porta_up, since they're so similar? Would need
1184 ;; to find a way to compare against effect code.
1185 fx_porta_down:
1186 ret z
1187 ;; B: channel
1188 ;; C: effect parameters
1189
1190 ;; free registers: A, D, E, H, L
1191
1192 ld d, 0
1193 call setup_channel_pointer
1194
1195 ld a, [hl+]
1196 ld e, a
1197 ld d, [hl]
1198
1199 ld a, c
1200 sub_from_r16 d, e, c
1201
1202 ld a, d
1203 ld [hl-], a
1204 ld [hl], e
1205
1206 jp _update_channel
1207
1208 fx_toneporta:
1209 jr nz, .do_toneporta
1210
1211 ;; We're on tick zero, so just move the temp note value into the toneporta target.
1212 ld d, 2
1213 call setup_channel_pointer
1214
1215 ;; If the note is nonexistent, then just return
1216 ld a, [temp_note_value+1]
1217 or a
1218 jr z, .return_skip
1219
1220 ld [hl+], a
1221 ld a, [temp_note_value]
1222 ld [hl], a
1223
1224 ;; Don't call _playnote. This is done by grabbing the return
1225 ;; address and manually skipping the next call instruction.
1226 .return_skip:
1227 ret_dont_call_playnote
1228
1229 .do_toneporta:
1230 ;; B: channel
1231 ;; C: effect parameters
1232
1233 ;; free registers: A, D, E, H, L
1234
1235 ;; TODO: Optimize. This usage of the stack isn't great but IMO it's
1236 ;; better than using the stack hack which forces all effects to screw with
1237 ;; pushing and popping. Most effects won't need to do this.
1238 ld d, 0
1239 call setup_channel_pointer
1240 push hl
1241
1242 ld a, [hl+]
1243 ld e, a
1244 ld a, [hl+]
1245 ld d, a
1246
1247 ld a, [hl+]
1248 ld h, [hl]
1249 ld l, a
1250
1251 ;; Comparing which direction to move the current value
1252 ;; TODO: Optimize this!!!!
1253
1254 ;; Compare high byte
1255 ld a, h
1256
1257 cp d
1258 jr c, .subtract ; target is less than the current period
1259 jr z, .high_byte_same
1260 jr .add
1261 .high_byte_same:
1262 ld a, l
1263 cp e
1264 jr c, .subtract ; the target is less than the current period
1265 jr z, .done ; both nibbles are the same so no portamento
1266 .add:
1267 ld a, c
1268 add a, e
1269 ld e, a
1270 adc a, d
1271 sub e
1272 ld d, a
1273
1274 ld a, h
1275 cp d
1276 jr c, .set_exact
1277 ld a, l
1278 cp e
1279 jr c, .set_exact
1280
1281 jr .done
1282
1283 .subtract:
1284 ld a, e
1285 sub c
1286 ld e, a
1287
1288 ld a, d
1289 sbc a, 0
1290 ld d, a
1291
1292 ld a, h
1293 cp d
1294 jr nc, .set_exact
1295 ld a, l
1296 cp e
1297 jr nc, .set_exact
1298
1299 jr .done
1300
1301 .set_exact:
1302 ld d, h
1303 ld e, l
1304 .done:
1305 pop hl
1306 ld a, e
1307 ld [hl+], a
1308 ld [hl], d
1309
1310 jp _update_channel
1311
1312 loadShort: MACRO
1313 ld a, [\1]
1314 ld \3, a
1315 ld a, [\1 + 1]
1316 ld \2, a
1317 ENDM
1318
1319 _setup_instrument_pointer:
1320 ld a, b
1321 and %11110000
1322 swap a
1323 ret z ; If there's no instrument, then return early.
1324
1325 dec a ; Instrument 0 is "no instrument"
1326
1327 ;; Shift left twice to multiply by 4
1328 sla a
1329 sla a
1330
1331 ld de, instruments
1332 add_a_to_de
1333 rla ; reset the Z flag
1334 ret
1335
1336 _dosound:
1337 ld a, [tick]
1338 or a
1339 jp nz, .process_effects
1340
1341 ;; Note playback
1342
1343 loadShort pattern1, b, c
1344 ld de, channel_note1
1345 call _lookup_note
1346 push af
1347 jr nc, .do_setvol1
1348
1349 call _setup_instrument_pointer
1350 ld a, [highmask1]
1351 res 7, a ; Turn off the "initial" flag
1352 jr z, .write_mask1
1353
1354 ld a, [de]
1355 inc de
1356 ld [rAUD1SWEEP], a
1357 ld a, [de]
1358 inc de
1359 ld [rAUD1LEN], a
1360 ld a, [de]
1361 ld [rAUD1ENV], a
1362 inc de
1363 ld a, [de]
1364
1365 .write_mask1:
1366 ld [highmask1], a
1367
1368 .do_setvol1:
1369 ld a, h
1370 ld [temp_note_value], a
1371 ld a, l
1372 ld [temp_note_value+1], a
1373
1374 ld e, 0
1375 call _doeffect
1376
1377 pop af
1378
1379 jr nc, .after_note1
1380
1381 call _playnote1 ; 3 bytes
1382
1383 .after_note1:
1384 loadShort pattern2, b, c
1385 ld de, channel_note2
1386 call _lookup_note
1387 push af
1388 jr nc, .do_setvol2
1389
1390 call _setup_instrument_pointer
1391 ld a, [highmask2]
1392 res 7, a ; Turn off the "initial" flag
1393 jr z, .write_mask2
1394
1395 inc de
1396 ld a, [de]
1397 inc de
1398 ld [rAUD2LEN], a
1399 ld a, [de]
1400 ld [rAUD2ENV], a
1401 inc de
1402 ld a, [de]
1403
1404 .write_mask2:
1405 ld [highmask2], a
1406
1407 .do_setvol2:
1408 ld a, h
1409 ld [temp_note_value], a
1410 ld a, l
1411 ld [temp_note_value+1], a
1412
1413 ld e, 1
1414 call _doeffect
1415
1416 pop af
1417
1418 jr nc, .after_note2
1419
1420 call _playnote2 ; 3 bytes
1421
1422 .after_note2:
1423 loadShort pattern3, b, c
1424 ld de, channel_note3
1425 call _lookup_note
1426 push af
1427
1428 jr nc, .do_setvol3
1429
1430 call _setup_instrument_pointer
1431 ld a, [highmask3]
1432 res 7, a ; Turn off the "initial" flag
1433 jr z, .write_mask3
1434
1435 ld a, [de]
1436 inc de
1437 ld [rAUD3LEN], a
1438 ld a, [de]
1439 inc de
1440 ld [rAUD3LEVEL], a
1441 ;; TODO: Write to _AUD3WAVERAM
1442 ; ld a, [de]
1443 ; ld [rAUD3ENV], a
1444 inc de
1445 ld a, [de]
1446
1447 .write_mask3:
1448 ld [highmask3], a
1449
1450 .do_setvol3:
1451 ld a, h
1452 ld [temp_note_value], a
1453 ld a, l
1454 ld [temp_note_value+1], a
1455
1456
1457 ld e, 2
1458 call _doeffect
1459
1460 pop af
1461
1462 jr nc, .after_note3
1463
1464 call _playnote3 ; 3 bytes
1465
1466 .after_note3:
1467 loadShort pattern4, b, c
1468 ld de, channel_note4
1469 call _lookup_note
1470 push af
1471
1472 jr nc, .do_setvol4
1473
1474 call _setup_instrument_pointer
1475 ld a, [highmask4]
1476 res 7, a ; Turn off the "initial" flag
1477 jr z, .write_mask4
1478
1479 ld a, [de]
1480 inc de
1481 ld [rAUD4LEN], a
1482 ld a, [de]
1483 inc de
1484 ld [rAUD4ENV], a
1485 ld a, [de]
1486 ld [rAUD4POLY], a
1487 inc de
1488 ld a, [de]
1489
1490 .write_mask4:
1491 ld [highmask4], a
1492
1493 .do_setvol4:
1494 ld a, h
1495 ld [temp_note_value], a
1496 ld a, l
1497 ld [temp_note_value+1], a
1498
1499 ld e, 3
1500 call _doeffect
1501
1502 pop af
1503
1504 jr nc, .after_note4
1505
1506 call _playnote4 ; 3 bytes
1507
1508 .after_note4:
1509 ;; finally just update the tick/order/row values
1510 jp process_tick
1511
1512 .process_effects:
1513 ;; Only do effects if not on tick zero
1514
1515 loadShort pattern1, b, c
1516 ld de, channel_note1
1517 call _load_note_data
1518
1519 ld a, c
1520 cp 0
1521 jr z, .after_effect1
1522
1523 ld e, 0
1524 call _doeffect
1525
1526 .after_effect1:
1527 loadShort pattern2, b, c
1528 ld de, channel_note2
1529 call _load_note_data
1530
1531 ld a, c
1532 cp 0
1533 jr z, .after_effect2
1534
1535 ld e, 1
1536 call _doeffect
1537
1538 .after_effect2:
1539 loadShort pattern3, b, c
1540 ld de, channel_note3
1541 call _load_note_data
1542
1543 ld a, c
1544 cp 0
1545 jr z, .after_effect3
1546
1547 ld e, 2
1548 call _doeffect
1549
1550 .after_effect3:
1551 loadShort pattern4, b, c
1552 ld de, channel_note4
1553 call _load_note_data
1554
1555 ld a, c
1556 cp 0
1557 jr z, .after_effect4
1558
1559 ld e, 3
1560 call _doeffect
1561
1562 .after_effect4:
1563
1564 process_tick:
1565 ld a, [ticks_per_row]
1566 ld b, a
1567
1568 ld a, [tick]
1569 inc a
1570
1571 cp b
1572 jp z, _newrow
1573
1574 ld [tick], a
1575 ret
1576
1577 _newrow:
1578 ;; Reset tick to 0
1579 xor a ; ld a, 0
1580 ld [tick], a
1581
1582 ;; Check if we need to perform a row break or pattern break
1583 ld a, [row_break]
1584 cp 0
1585 jr z, .no_break
1586
1587 ;; These are offset by one so we can check to see if they've
1588 ;; been modified
1589 dec a
1590 ld b, a
1591
1592 ld a, [next_order]
1593 cp 0
1594
1595 ;; Maybe use HL instead?
1596 push af
1597 ld a, 0
1598 ld [next_order], a
1599 ld [row_break], a
1600 pop af
1601
1602 jr z, _neworder
1603
1604 dec a
1605 sla a ;; Multiply the order by 2 (they are words)
1606
1607 jr _update_current_order
1608
1609 .no_break:
1610 ;; Increment row.
1611 ld a, [row]
1612 inc a
1613 ld b, a
1614 cp PATTERN_LENGTH
1615 jr nz, _noreset
1616
1617 ld b, 0
1618 _neworder:
1619 ;; Increment order and change loaded patterns
1620 ld a, [order_cnt]
1621 ld c, a
1622 ld a, [current_order]
1623 add a, 2
1624 cp c
1625 jr nz, _update_current_order
1626 ld a, 0
1627 _update_current_order:
1628 ;; Call with:
1629 ;; A: The order to load
1630 ;; B: The row for the order to start on
1631 ld [current_order], a
1632 ld c, a
1633 call _refresh_patterns
1634
1635 _noreset:
1636 ld a, b
1637 ld [row], a
1638 ret
1639
1640 _halt:
1641 ; Do nothing, forever
1642 halt
1643 _nop:
1644 nop
1645 jr _halt
1646
1647 SECTION "Wave stuff", ROM0
1648
1649 SECTION "Note Table", ROM0
1650 note_table:
1651 include "music.inc"
Deletedeevee_resamp.py +0−48
@@ -1,48 +0,0 @@
1 import wave
2 import sys
3
4 sys.argv.append('808nokickbreak.wav')
5
6 TARGET_RATE = int(8192)
7
8 with wave.open(sys.argv[1]) as w:
9 nchannels, sample_width, framerate, nframes, _, _ = w.getparams()
10 outdata = bytearray()
11 gbdata = bytearray()
12
13 frames_per_note = framerate // TARGET_RATE
14 nybble = None
15 while True:
16 data = w.readframes(frames_per_note)
17 if not data:
18 break
19
20 n = 0
21 total = 0
22 # Left and right channels are interleaved; this will pick up data from only channel 0
23 for i in range(0, len(data), nchannels * sample_width):
24 frame = int.from_bytes(data[i : i + sample_width], 'little', signed=True)
25 n += 1
26 total += frame
27
28 # Crush the new sample to a nybble
29 crushed_frame = int(total / n) >> (sample_width * 8 - 4)
30 # Expand it back to the full sample size, to make a WAV simulating how it should sound
31 encoded_crushed_frame = (crushed_frame << (sample_width * 8 - 4)).to_bytes(2, 'little', signed=True)
32 outdata.extend(encoded_crushed_frame * (nchannels * frames_per_note))
33
34 # Combine every two nybbles together. The manual shows that the high nybble plays first.
35 # WAV data is signed, but Game Boy nybbles are not, so add the rough midpoint of 7
36 if nybble is None:
37 nybble = crushed_frame + 7
38 else:
39 byte = (nybble << 4) | (crushed_frame + 7)
40 #gbdata.append(byte)
41 nybble = None
42
43 with wave.open(f'{sys.argv[1]}crush.wav', 'wb') as wout:
44 wout.setparams(w.getparams())
45 wout.writeframes(outdata)
46
47 with open(f'{sys.argv[1]}crush.dat', 'wb') as f:
48 f.write(gbdata)
ModifiedhUGEDriver +1−1
@@ -1 +1 @@
1 Subproject commit b8f46b7b2506005704e913565b3345701d2f77b2 1 Subproject commit a8785f40d17eb690d9e6984447ce5dd1d5dceb74
Deletedlunawaves.inc +0−64
@@ -1,64 +0,0 @@
1 dn A#5, 00, 00
2 dn A#4, 00, 00
3 dn F_5 , 00, 00
4 dn A#5, 00, 00
5 dn G#5, 00, 00
6 dn A#4, 00, 00
7 dn F_5 , 00, 00
8 dn G#5, 00, 00
9 dn G_5 , 00, 00
10 dn A#4, 00, 00
11 dn D#5, 00, 00
12 dn G_5 , 00, 00
13 dn G#5, 00, 00
14 dn A#4, 00, 00
15 dn F_5 , 00, 00
16 dn G#5, 00, 00
17 dn A#5, 00, 00
18 dn A#4, 00, 00
19 dn F_5 , 00, 00
20 dn A#5, 00, 00
21 dn G#5, 00, 00
22 dn A#4, 00, 00
23 dn F_5 , 00, 00
24 dn G#5, 00, 00
25 dn G_5 , 00, 00
26 dn A#4, 00, 00
27 dn D#5, 00, 00
28 dn G_5 , 00, 00
29 dn G#5, 00, 00
30 dn A#4, 00, 00
31 dn F_5 , 00, 00
32 dn G#5, 00, 00
33 dn A#5, 00, 00
34 dn A#4, 00, 00
35 dn F_5 , 00, 00
36 dn A#5, 00, 00
37 dn G#5, 00, 00
38 dn A#4, 00, 00
39 dn F_5 , 00, 00
40 dn G#5, 00, 00
41 dn G_5 , 00, 00
42 dn A#4, 00, 00
43 dn D#5, 00, 00
44 dn G_5 , 00, 00
45 dn G#5, 00, 00
46 dn A#4, 00, 00
47 dn F_5 , 00, 00
48 dn G#5, 00, 00
49 dn A#5, 00, 00
50 dn A#4, 00, 00
51 dn F_5 , 00, 00
52 dn A#5, 00, 00
53 dn G#5, 00, 00
54 dn A#4, 00, 00
55 dn F_5 , 00, 00
56 dn G#5, 00, 00
57 dn G_5 , 00, 00
58 dn A#4, 00, 00
59 dn D#5, 00, 00
60 dn G_5 , 00, 00
61 dn G#5, 00, 00
62 dn A#4, 00, 00
63 dn F_5 , 00, 00
64 dn G#5, 00, 00
Deletedmusic.inc +0−81
@@ -1,81 +0,0 @@
1 ;; hUGETracker note table.
2 ;; Written by SuperDisk 2019
3
4 ;; Gameboy sound frequences are represented as 11 byte periods.
5 ;; this note table was generated from http://www.devrs.com/gb/files/sndtab.html
6
7 ;; Since they're 11 bytes, and to avoid doing a bunch of anding and shuffling stuff
8 ;; through HL at playtime, we store them here for a total of 142 bytes of rom.
9
10 db 44, 0 ;; C_3 = 44
11 db 156, 0 ;; C#_3 = 156
12 db 6, 1 ;; D_3 = 7
13 db 107, 1 ;; D#_3 = 107
14 db 201, 1 ;; E_3 = 201
15 db 35, 2 ;; F_3 = 35
16 db 119, 2 ;; F#_3 = 119
17 db 198, 2 ;; G_3 = 198
18 db 18, 3 ;; G#_3 = 19
19 db 86, 3 ;; A_3 = 87
20 db 155, 3 ;; A#_3 = 155
21 db 218, 3 ;; B_3 = 219
22 db 22, 4 ;; C_4 = 22
23 db 78, 4 ;; C#_4 = 78
24 db 131, 4 ;; D_4 = 135
25 db 181, 4 ;; D#_4 = 181
26 db 229, 4 ;; E_4 = 229
27 db 17, 5 ;; F_4 = 21
28 db 59, 5 ;; F#_4 = 63
29 db 99, 5 ;; G_4 = 103
30 db 137, 5 ;; G#_4 = 141
31 db 172, 5 ;; A_4 = 173
32 db 206, 5 ;; A#_4 = 207
33 db 237, 5 ;; B_4 = 237
34 db 10, 6 ;; C_5 = 14
35 db 39, 6 ;; C#_5 = 39
36 db 66, 6 ;; D_5 = 70
37 db 91, 6 ;; D#_5 = 95
38 db 114, 6 ;; E_5 = 118
39 db 137, 6 ;; F_5 = 143
40 db 158, 6 ;; F#_5 = 158
41 db 178, 6 ;; G_5 = 182
42 db 196, 6 ;; G#_5 = 198
43 db 214, 6 ;; A_5 = 214
44 db 231, 6 ;; A#_5 = 231
45 db 247, 6 ;; B_5 = 247
46 db 6, 7 ;; C_6 = 7
47 db 20, 7 ;; C#_6 = 23
48 db 33, 7 ;; D_6 = 39
49 db 45, 7 ;; D#_6 = 47
50 db 57, 7 ;; E_6 = 63
51 db 68, 7 ;; F_6 = 71
52 db 79, 7 ;; F#_6 = 79
53 db 89, 7 ;; G_6 = 95
54 db 98, 7 ;; G#_6 = 103
55 db 107, 7 ;; A_6 = 111
56 db 115, 7 ;; A#_6 = 119
57 db 123, 7 ;; B_6 = 127
58 db 131, 7 ;; C_7 = 135
59 db 138, 7 ;; C#_7 = 143
60 db 144, 7 ;; D_7 = 151
61 db 151, 7 ;; D#_7 = 151
62 db 157, 7 ;; E_7 = 159
63 db 162, 7 ;; F_7 = 167
64 db 167, 7 ;; F#_7 = 167
65 db 172, 7 ;; G_7 = 175
66 db 177, 7 ;; G#_7 = 183
67 db 182, 7 ;; A_7 = 183
68 db 186, 7 ;; A#_7 = 191
69 db 190, 7 ;; B_7 = 191
70 db 193, 7 ;; C_8 = 199
71 db 196, 7 ;; C#_8 = 199
72 db 200, 7 ;; D_8 = 207
73 db 203, 7 ;; D#_8 = 207
74 db 206, 7 ;; E_8 = 207
75 db 209, 7 ;; F_8 = 215
76 db 212, 7 ;; F#_8 = 215
77 db 214, 7 ;; G_8 = 215
78 db 217, 7 ;; G#_8 = 223
79 db 219, 7 ;; A_8 = 223
80 db 221, 7 ;; A#_8 = 223
81 db 223, 7 ;; B_8 = 223
Deletedtfau_arps.inc +0−64
@@ -1,64 +0,0 @@
1 dn E_5, 1, $C70
2 dn G_5, 1, $C70
3 dn B_5, 1, $C60
4 dn E_6, 1, $C60
5 dn E_5, 1, $C50
6 dn G_5, 1, $C50
7 dn B_5, 1, $C40
8 dn E_6, 1, $C40
9 dn E_5, 1, $C30
10 dn G_5, 1, $C30
11 dn B_5, 1, $C30
12 dn E_6, 1, $C20
13 dn F#5, 1, $C70
14 dn A_5, 1, $C70
15 dn B_5, 1, $C70
16 dn E_6, 1, $C60
17 dn F#5, 1, $C60
18 dn A_5, 1, $C60
19 dn B_5, 1, $C60
20 dn E_6, 1, $C50
21 dn F#5, 1, $C50
22 dn A_5, 1, $C50
23 dn B_5, 1, $C40
24 dn E_6, 1, $C40
25 dn F#5, 1, $C40
26 dn A_5, 1, $C40
27 dn B_5, 1, $C30
28 dn E_6, 1, $C30
29 dn F#5, 1, $C30
30 dn A_5, 1, $C30
31 dn B_5, 1, $C20
32 dn E_6, 1, $C20
33 dn G_5, 1, $C70
34 dn B_5, 1, $C70
35 dn E_6, 1, $C70
36 dn G_6, 1, $C70
37 dn G_5, 1, $C70
38 dn B_5, 1, $C60
39 dn E_6, 1, $C60
40 dn G_6, 1, $C60
41 dn G_5, 1, $C60
42 dn B_5, 1, $C60
43 dn E_6, 1, $C60
44 dn G_6, 1, $C50
45 dn G_5, 1, $C50
46 dn B_5, 1, $C50
47 dn E_6, 1, $C50
48 dn G_6, 1, $C50
49 dn G_5, 1, $C40
50 dn B_5, 1, $C40
51 dn E_6, 1, $C40
52 dn G_6, 1, $C40
53 dn G_5, 1, $C40
54 dn B_5, 1, $C40
55 dn E_6, 1, $C30
56 dn G_6, 1, $C30
57 dn G_5, 1, $C30
58 dn B_5, 1, $C30
59 dn E_6, 1, $C30
60 dn G_6, 1, $C30
61 dn G_5, 1, $C30
62 dn B_5, 1, $C20
63 dn E_6, 1, $C20
64 dn G_6, 1, $C20
Deletedtfau_bass.inc +0−64
@@ -1,64 +0,0 @@
1 dn E_3, 2, $F03
2 dn ___, 0, 0
3 dn ___, 0, 0
4 dn ___, 0, 0
5 dn ___, 0, 0
6 dn E_3, 2, $C20
7 dn E_4, 2, 0
8 dn E_4, 2, $C20
9 dn ___, 0, 0
10 dn ___, 0, 0
11 dn ___, 0, 0
12 dn ___, 0, 0
13 dn A_3, 2, 0
14 dn A_3, 2, $C20
15 dn ___, 0, 0
16 dn ___, 0, 0
17 dn A#3, 2, 0
18 dn B_3, 2, $30A
19 dn ___, 0, $30A
20 dn ___, 0, 0
21 dn ___, 0, 0
22 dn B_3, 2, $C20
23 dn D_4, 2, 0
24 dn D_4, 2, $C20
25 dn ___, 0, 0
26 dn ___, 0, 0
27 dn D_4, 2, 0
28 dn D_4, 2, $C20
29 dn F#3, 2, $C80
30 dn ___, 0, 0
31 dn ___, 0, 0
32 dn ___, 0, 0
33 dn G_3, 2, 0
34 dn ___, 0, 0
35 dn ___, 0, 0
36 dn ___, 0, 0
37 dn ___, 0, 0
38 dn F#3, 2, $C20
39 dn G_4, 2, 0
40 dn G_4, 2, $C20
41 dn ___, 0, 0
42 dn ___, 0, 0
43 dn ___, 0, 0
44 dn ___, 0, 0
45 dn A_3, 2, 0
46 dn A_3, 2, $C20
47 dn A#3, 2, $C80
48 dn A#3, 2, $C20
49 dn A#3, 2, $101
50 dn B_3, 2, $30A
51 dn ___, 0, $30A
52 dn ___, 0, 0
53 dn D_4, 2, 0
54 dn D_4, 2, $C20
55 dn ___, 0, 0
56 dn ___, 0, 0
57 dn ___, 0, 0
58 dn ___, 0, 0
59 dn A_3, 2, 0
60 dn A_3, 2, $C20
61 dn B_3, 2, 0
62 dn ___, 0, 0
63 dn ___, 0, 0
64 dn ___, 0, $D01
Deletedunreal.inc +0−64
@@ -1,64 +0,0 @@
1 dn F_5, 1, $F07
2 dn G#5, 1, $316
3 dn C_6, 1, $316
4 dn F_6, 1, $316
5 dn G#6, 1, $316
6 dn F_6, 1, $316
7 dn C_6, 1, $316
8 dn G#5, 1, $316
9 dn F_5, 1, $316
10 dn G#5, 1, $316
11 dn C_6, 1, $316
12 dn F_6, 1, $316
13 dn G#6, 1, $316
14 dn F_6, 1, $316
15 dn C_6, 1, $316
16 dn G#5, 1, $316
17 dn F_5, 1, $316
18 dn C_6, 1, $316
19 dn D#6, 1, $316
20 dn G#6, 1, $316
21 dn C_7, 1, $316
22 dn G#6, 1, $316
23 dn D#6, 1, $316
24 dn C_6, 1, $316
25 dn G#5, 1, $316
26 dn C_6, 1, $316
27 dn D#6, 1, $316
28 dn G#6, 1, $316
29 dn C_7, 1, $316
30 dn G#6, 1, $316
31 dn D#6, 1, $316
32 dn C_6, 1, $316
33 dn A#5, 1, $316
34 dn D_6, 1, $316
35 dn F_6, 1, $316
36 dn A#6, 1, $316
37 dn D_7, 1, $316
38 dn A#6, 1, $316
39 dn F_6, 1, $316
40 dn D_6, 1, $316
41 dn A#5, 1, $316
42 dn D_6, 1, $316
43 dn F_6, 1, $316
44 dn A#6, 1, $316
45 dn D_7, 1, $316
46 dn A#6, 1, $316
47 dn F_6, 1, $316
48 dn D_6, 1, $316
49 dn F_5, 1, $316
50 dn C_6, 1, $316
51 dn F_6, 1, $316
52 dn C_7, 1, $316
53 dn F_7, 1, $316
54 dn C_7, 1, $316
55 dn F_6, 1, $316
56 dn C_6, 1, $316
57 dn F_5, 1, $316
58 dn C_6, 1, $316
59 dn F_6, 1, $316
60 dn C_7, 1, $316
61 dn F_7, 1, $316
62 dn C_7, 1, $316
63 dn F_6, 1, $316
64 dn C_6, 1, $316
Deletedunreal_arps.inc +0−64
@@ -1,64 +0,0 @@
1 dn F_5, 1, $037
2 dn F_5, 1, $037
3 dn F_5, 1, $037
4 dn F_5, 1, $037
5 dn F_5, 1, $037
6 dn F_5, 1, $037
7 dn F_5, 1, $037
8 dn F_5, 1, $037
9 dn F_5, 1, $037
10 dn F_5, 1, $037
11 dn F_5, 1, $037
12 dn F_5, 1, $037
13 dn F_5, 1, $037
14 dn F_5, 1, $037
15 dn F_5, 1, $037
16 dn F_5, 1, $037
17 dn G#5, 1, $047
18 dn G#5, 1, $047
19 dn G#5, 1, $047
20 dn G#5, 1, $047
21 dn G#5, 1, $047
22 dn G#5, 1, $047
23 dn G#5, 1, $047
24 dn G#5, 1, $047
25 dn G#5, 1, $047
26 dn G#5, 1, $047
27 dn G#5, 1, $047
28 dn G#5, 1, $047
29 dn G#5, 1, $047
30 dn G#5, 1, $047
31 dn G#5, 1, $047
32 dn G#5, 1, $047
33 dn A#5, 1, $047
34 dn A#5, 1, $047
35 dn A#5, 1, $047
36 dn A#5, 1, $047
37 dn A#5, 1, $047
38 dn A#5, 1, $047
39 dn A#5, 1, $047
40 dn A#5, 1, $047
41 dn A#5, 1, $047
42 dn A#5, 1, $047
43 dn A#5, 1, $047
44 dn A#5, 1, $047
45 dn A#5, 1, $047
46 dn A#5, 1, $047
47 dn A#5, 1, $047
48 dn A#5, 1, $047
49 dn C_6, 1, $047
50 dn C_6, 1, $047
51 dn C_6, 1, $047
52 dn C_6, 1, $047
53 dn C_6, 1, $047
54 dn C_6, 1, $047
55 dn C_6, 1, $047
56 dn C_6, 1, $047
57 dn C_6, 1, $047
58 dn C_6, 1, $047
59 dn C_6, 1, $047
60 dn C_6, 1, $047
61 dn C_6, 1, $047
62 dn C_6, 1, $047
63 dn C_6, 1, $047
64 dn C_6, 1, $047