Commit c86fc07

Nick Faro committed on
WIP table-enabled preview
commit c86fc07cef34c17c44a9c3cbb5f530e0d04acb61 parent d6fa4bf
1 changed files +85−127
Modifiedhalt.asm +85−127
@@ -1,8 +1,5 @@
1 include "hardware.inc" 1 include "hardware.inc"
2 2 include "hUGE.inc"
3 ;; This is a short program which just contains the noise macro logic found
4 ;; in hUGEDriver. Values are poked by the tracker into RAM, and they are played back
5 ;; by this routine, which is constantly running when the tracker is not playing a song.
6 3
7 add_a_to_r16: MACRO 4 add_a_to_r16: MACRO
8 add \2 5 add \2
@@ -20,23 +17,6 @@ add_a_to_de: MACRO
20 add_a_to_r16 d, e 17 add_a_to_r16 d, e
21 ENDM 18 ENDM
22 19
23 SECTION "Vars", WRAM0
24
25 instr: ds 8
26 note: db
27
28 macro_index: db
29
30 SECTION "LCD controller status interrupt", ROM0[$0048]
31 ;; HACK!!!!!!!!!!!!!
32 ;; there's some sort of bug in the emulator which needs to be fixed,
33 ;; which screws up the program counter immediately after it exits a halt.
34 ;; this nop protects against that for now.
35 nop
36 nop
37 nop
38 jp _domacro
39
40 SECTION "init", ROM0[$0100] 20 SECTION "init", ROM0[$0100]
41 jp init 21 jp init
42 22
@@ -50,115 +30,71 @@ DS 1
50 ; $0144 - $0145: "New" Licensee Code, a two character name. 30 ; $0144 - $0145: "New" Licensee Code, a two character name.
51 DB "NF" 31 DB "NF"
52 32
33 SECTION "Vars", WRAM0
34
35 note1: ds 3
36 note2: ds 3
37 note3: ds 3
38 note4: ds 4
39
40 instrument1: ds 6
41 instrument2: ds 6
42 instrument3: ds 6
43 instrument4: ds 6
44
45 subpattern1: ds (3*64)
46 subpattern2: ds (3*64)
47 subpattern3: ds (3*64)
48 subpattern4: ds (3*64)
49
50 start_zero:
51
52 start_ch1: db
53 start_ch2: db
54 start_ch3: db
55 start_ch4: db
56
57 running_ch1: db
58 running_ch2: db
59 running_ch3: db
60 running_ch4: db
61
62 end_zero:
63
53 SECTION "code", ROM0[$400] 64 SECTION "code", ROM0[$400]
54 65
55 _domacro: 66 init_note1:
56 ld a, [macro_index] 67 ld bc, note1
57 cp 1 68 call get_current_row
58 jp z, _macro_begin 69 call get_note_period
59 jp nc, _macro_update 70 ld a, l
60 reti 71 ld [channel_period1], a
61 72 ld a, h
62 _macro_begin: 73 ld [channel_period1+1], a
63 ld a, [instr] 74
64 ld [rAUD4ENV], a 75 ld a, [hl+]
65 76 ldh [rAUD1SWEEP], a
66 ld a, [note] 77 ld a, [hl+]
67 call _convert_ch4_note 78 ldh [rAUD1LEN], a
68 ld d, a 79 ld a, [hl+]
69 ld a, [instr+1] 80 ldh [rAUD1ENV], a
70 and %10000000 81
71 swap a 82 xor a
72 or d 83 ld [table_row1], a
73 ld [rAUD4POLY], a 84 ld [start_ch1], a
74 85 inc a
75 ld a, [instr+1] 86 ld [highmask1], a
76 and %00111111 87 ld [running_ch1], a
77 ld [rAUD4LEN], a 88
78 89 jp play_ch1_note
79 ld a, [instr+1] 90
80 and %01000000 ; get only length enabled 91 run_table1:
81 or %10000000 ; restart sound 92 ld bc, subpattern1
82 ld [rAUD4GO], a 93 ld hl, table_row1
83 94 ld e, 0
84 ld hl, macro_index 95 jp do_table
85 inc [hl]
86 reti
87
88 _macro_update:
89 ld a, [macro_index]
90
91 ld de, instr
92 add_a_to_de
93 ld a, [de]
94 ld b, a
95
96 ld a, [note]
97 add b
98
99 call _convert_ch4_note
100 ld d, a
101 ld a, [instr+1]
102 and %10000000
103 swap a
104 or d
105 ld [rAUD4POLY], a
106
107 ld a, [instr+1]
108 and %01000000 ; get only length enabled
109 ld [rAUD4GO], a
110
111 ld a, [macro_index]
112 inc a
113 cp 8
114 jp nz, .done
115 xor a
116 .done:
117 ld [macro_index], a
118 reti
119
120 _convert_ch4_note:
121 ;; Call with:
122 ;; Note number in A
123 ;; Stores polynomial counter in A
124 ;; Free: HL
125
126 ;; Invert the order of the numbers
127 add 192 ; (255 - 63)
128 cpl
129
130 ;; Thanks to RichardULZ for this formula
131 ;; https://docs.google.com/spreadsheets/d/1O9OTAHgLk1SUt972w88uVHp44w7HKEbS/edit#gid=75028951
132 ; if A > 7 then begin
133 ; B := (A-4) div 4;
134 ; C := (A mod 4)+4;
135 ; A := (C or (B shl 4))
136 ; end;
137
138 ; if A < 7 then return
139 cp 7
140 ret c
141
142 ld h, a
143
144 ; B := (A-4) div 4;
145 sub 4
146 srl a
147 srl a
148 ld l, a
149
150 ; C := (A mod 4)+4;
151 ld a, h
152 and 3
153 add 4
154
155 ; A := (C or (B shl 4))
156 swap l
157 or l
158 ret
159 96
160 init: 97 init:
161 ; jp _halt
162 _addr = _AUD3WAVERAM 98 _addr = _AUD3WAVERAM
163 REPT 16 99 REPT 16
164 ld a, $FF 100 ld a, $FF
@@ -182,14 +118,36 @@ _addr = _addr + 1
182 ld a, [rSTAT] 118 ld a, [rSTAT]
183 or a, STATF_LYC 119 or a, STATF_LYC
184 ld [rSTAT], a 120 ld [rSTAT], a
185 xor a ; ld a, 0 121 xor a
186 ld [rLYC], a 122 ld [rLYC], a
187 123
188 ld a, IEF_LCDC 124 ld a, IEF_LCDC
189 ld [rIE], a 125 ld [rIE], a
190 ei 126 ei
191 127
128 ;; Initialize hUGEDriver-related vars
129 xor a
130 ld [row], a
131
132 ;; Zero some ram
133 ld c, end_zero - start_zero
134 ld hl, start_zero
135 xor a
136 .fill_loop:
137 ld [hl+], a
138 dec c
139 jr nz, .fill_loop
140
192 _halt: 141 _halt:
193 halt 142 halt
194 nop 143 nop
144
145 ld a, [running_ch1]
146 and $FF
147 call nz, run_table1
148
149 ld a, [start_ch1]
150 and $FF
151 call nz, init_note1
152
195 jr _halt 153 jr _halt