summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--audio/engine.asm95
-rw-r--r--engine/pokedex/pokedex.asm2
-rw-r--r--engine/rtc/timeset.asm3
-rw-r--r--home/audio.asm2
-rw-r--r--tools/stadium.c63
5 files changed, 84 insertions, 81 deletions
diff --git a/audio/engine.asm b/audio/engine.asm
index d394067c3..e24ba259c 100644
--- a/audio/engine.asm
+++ b/audio/engine.asm
@@ -101,7 +101,7 @@ _UpdateSound::
ld hl, CHANNEL_NOTE_DURATION
add hl, bc
ld a, [hl]
- cp $2 ; 1 or 0?
+ cp 2 ; 1 or 0?
jr c, .noteover
dec [hl]
jr .continue_sound_update
@@ -212,7 +212,7 @@ _UpdateSound::
UpdateChannels:
ld hl, .ChannelFnPtrs
ld a, [wCurChannel]
- and $7
+ maskbits NUM_CHANNELS
add a
ld e, a
ld d, 0
@@ -1141,7 +1141,6 @@ ParseMusic:
jr z, .sound_ret
cp FIRST_MUSIC_CMD
jr c, .readnote
- ; then it's a command
.readcommand
call ParseMusicCommand
jr ParseMusic ; start over
@@ -1366,39 +1365,39 @@ ParseMusicCommand:
MusicCommands:
; entries correspond to audio constants (see macros/scripts/audio.asm)
- dw Music_Octave8 ; octave 8
- dw Music_Octave7 ; octave 7
- dw Music_Octave6 ; octave 6
- dw Music_Octave5 ; octave 5
- dw Music_Octave4 ; octave 4
- dw Music_Octave3 ; octave 3
- dw Music_Octave2 ; octave 2
- dw Music_Octave1 ; octave 1
+ dw Music_Octave8
+ dw Music_Octave7
+ dw Music_Octave6
+ dw Music_Octave5
+ dw Music_Octave4
+ dw Music_Octave3
+ dw Music_Octave2
+ dw Music_Octave1
dw Music_NoteType ; note length + volume envelope
- dw Music_Transpose ; transpose
- dw Music_Tempo ; tempo
- dw Music_DutyCycle ; duty cycle
- dw Music_VolumeEnvelope ; volume envelope
- dw Music_PitchSweep ; update pitch sweep
- dw Music_DutyCyclePattern ; duty cycle pattern
- dw Music_ToggleSFX ; sound on/off
- dw Music_PitchSlide ; pitch slide
- dw Music_Vibrato ; vibrato
+ dw Music_Transpose
+ dw Music_Tempo
+ dw Music_DutyCycle
+ dw Music_VolumeEnvelope
+ dw Music_PitchSweep
+ dw Music_DutyCyclePattern
+ dw Music_ToggleSFX
+ dw Music_PitchSlide
+ dw Music_Vibrato
dw MusicE2 ; unused
- dw Music_ToggleNoise ; music noise sampling
- dw Music_ForceStereoPanning ; force stereo panning
- dw Music_Volume ; volume
- dw Music_PitchOffset ; pitch offset
+ dw Music_ToggleNoise
+ dw Music_ForceStereoPanning
+ dw Music_Volume
+ dw Music_PitchOffset
dw MusicE7 ; unused
dw MusicE8 ; unused
- dw Music_TempoRelative ; tempo adjust
- dw Music_RestartChannel ; restart current channel from header
- dw Music_NewSong ; new song
- dw Music_SFXPriorityOn ; sfx priority on
- dw Music_SFXPriorityOff ; sfx priority off
+ dw Music_TempoRelative
+ dw Music_RestartChannel
+ dw Music_NewSong
+ dw Music_SFXPriorityOn
+ dw Music_SFXPriorityOff
dw MusicEE ; unused
- dw Music_StereoPanning ; stereo panning
- dw Music_SFXToggleNoise ; sfx noise sampling
+ dw Music_StereoPanning
+ dw Music_SFXToggleNoise
dw MusicF1 ; nothing
dw MusicF2 ; nothing
dw MusicF3 ; nothing
@@ -1408,12 +1407,12 @@ MusicCommands:
dw MusicF7 ; nothing
dw MusicF8 ; nothing
dw MusicF9 ; unused
- dw Music_SetCondition ; set condition
- dw Music_JumpIf ; jumpif
- dw Music_Jump ; jump
- dw Music_Loop ; loop
- dw Music_Call ; call
- dw Music_Ret ; return
+ dw Music_SetCondition
+ dw Music_JumpIf
+ dw Music_Jump
+ dw Music_Loop
+ dw Music_Call
+ dw Music_Ret
MusicF1:
MusicF2:
@@ -2107,29 +2106,23 @@ GetMusicByte:
; input: bc = start of current channel
push hl
push de
- ; load address into de
ld hl, CHANNEL_MUSIC_ADDRESS
add hl, bc
ld a, [hli]
ld e, a
ld d, [hl]
- ; load bank into a
ld hl, CHANNEL_MUSIC_BANK
add hl, bc
ld a, [hl]
- ; get byte
- call _LoadMusicByte ; load data into wCurMusicByte
+ call _LoadMusicByte ; load data into [wCurMusicByte]
inc de ; advance to next byte for next time this is called
- ; update channeldata address
ld hl, CHANNEL_MUSIC_ADDRESS
add hl, bc
ld a, e
ld [hli], a
ld [hl], d
- ; cleanup
pop de
pop hl
- ; store channeldata in a
ld a, [wCurMusicByte]
ret
@@ -2191,7 +2184,6 @@ SetNoteDuration:
inc a
ld e, a
ld d, 0
- ; store NoteLength in a
ld hl, CHANNEL_NOTE_LENGTH
add hl, bc
ld a, [hl]
@@ -2306,7 +2298,6 @@ SetLRTracks:
maskbits NUM_MUSIC_CHANS
ld e, a
ld d, 0
- ; get this channel's lr tracks
call GetLRTracks
add hl, de ; de = channel 0-3
ld a, [hl]
@@ -2396,7 +2387,7 @@ _PlayCry::
inc a
.loop
push af
- call LoadChannel
+ call LoadChannel ; bc = current channel
ld hl, CHANNEL_FLAGS1
add hl, bc
@@ -2439,7 +2430,7 @@ _PlayCry::
bit STEREO, a
jr z, .next
-; [Tracks] &= [wCryTracks]
+; [CHANNEL_TRACKS] &= [wCryTracks]
ld hl, CHANNEL_TRACKS
add hl, bc
ld a, [hl]
@@ -2671,13 +2662,11 @@ PlayStereoSFX::
ret
LoadChannel:
-; prep channel for use
-; input:
-; de:
- ; get pointer to current channel
+; input: de = audio pointer
+; sets bc to current channel pointer
call LoadMusicByte
inc de
- and $7 ; bit 0-2 (current channel)
+ maskbits NUM_CHANNELS
ld [wCurChannel], a
ld c, a
ld b, 0
diff --git a/engine/pokedex/pokedex.asm b/engine/pokedex/pokedex.asm
index 37c3f0a3c..fbdd8a178 100644
--- a/engine/pokedex/pokedex.asm
+++ b/engine/pokedex/pokedex.asm
@@ -374,7 +374,7 @@ Pokedex_UpdateDexEntryScreen:
ld a, [wLastVolume]
and a
jr z, .max_volume
- ld a, $77
+ ld a, MAX_VOLUME
ld [wLastVolume], a
.max_volume
diff --git a/engine/rtc/timeset.asm b/engine/rtc/timeset.asm
index 9dad2355a..635f97ddf 100644
--- a/engine/rtc/timeset.asm
+++ b/engine/rtc/timeset.asm
@@ -653,7 +653,8 @@ MrChrono: ; unreferenced
ret
.NowOnDebug:
- text "<PARA>Now on DEBUG…"
+ text_start
+ para "Now on DEBUG…"
prompt
.PrintTime:
diff --git a/home/audio.asm b/home/audio.asm
index 7c7b84371..405f1ec3f 100644
--- a/home/audio.asm
+++ b/home/audio.asm
@@ -49,7 +49,7 @@ UpdateSound::
ret
_LoadMusicByte::
-; wCurMusicByte = [a:de]
+; [wCurMusicByte] = [a:de]
ldh [hROMBank], a
ld [MBC3RomBank], a
diff --git a/tools/stadium.c b/tools/stadium.c
index 796b7fc22..65753112d 100644
--- a/tools/stadium.c
+++ b/tools/stadium.c
@@ -1,9 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
-#include <stdbool.h>
-#include <getopt.h>
#include <string.h>
#include <stdint.h>
+#include <stdbool.h>
+#include <getopt.h>
#include "common.h"
@@ -17,24 +17,28 @@
#define HEADERSIZE (N64PS3SIZE + 2)
// Checksum every half-bank
#define CHECKSIZE 0x2000
-// The CRC initial value (also used for checksums)
-#define CRC_INIT 0xFEFE
// The CRC polynomial value
#define CRC_POLY 0xC387
+// The CRC initial value (also used for checksums)
+#define CRC_INIT 0xFEFE
+// The CRC initial value for Crystal base data
+#define CRC_INIT_BASE 0xACDE
typedef enum Base { BASE_NONE, BASE_US, BASE_EU, BASE_DEBUG } Base;
-uint8_t us_base[BASESIZE] = {'b', 'a', 's', 'e',
- 0x01, 0x00, 0xBF, 0x6B, 0x40, 0x11, 0x00, 0x22, 0x00, 0x3A,
- 0xF3, 0x38, 0x18, 0xFF, 0xFF, 0x0F, 0x07, 0x10, 0x68, 0x07};
+// Base data format: "base", 1, version, CRC (big-endian), 16 unknown bytes
+
+uint8_t us_base[BASESIZE] = {'b', 'a', 's', 'e', 1, 0, 0, 0,
+ 0x40, 0x11, 0x00, 0x22, 0x00, 0x3A, 0xF3, 0x38,
+ 0x18, 0xFF, 0xFF, 0x0F, 0x07, 0x10, 0x68, 0x07};
-uint8_t eu_base[BASESIZE] = {'b', 'a', 's', 'e',
- 0x01, 0x01, 0x1E, 0xCF, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0C,
- 0xA3, 0x38, 0x00, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x14};
+uint8_t eu_base[BASESIZE] = {'b', 'a', 's', 'e', 1, 1, 0, 0,
+ 0x00, 0x10, 0x00, 0x00, 0x00, 0x0C, 0xA3, 0x38,
+ 0x00, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x14};
-uint8_t dbg_base[BASESIZE] = {'b', 'a', 's', 'e',
- 0x01, 0x00, 0x07, 0x82, 0x40, 0x10, 0x00, 0x22, 0x00, 0x3A,
- 0xE3, 0x38, 0x00, 0xFF, 0xFF, 0x07, 0x07, 0x10, 0x68, 0x06};
+uint8_t dbg_base[BASESIZE] = {'b', 'a', 's', 'e', 1, 0, 0, 0,
+ 0x40, 0x10, 0x00, 0x22, 0x00, 0x3A, 0xE3, 0x38,
+ 0x00, 0xFF, 0xFF, 0x07, 0x07, 0x10, 0x68, 0x06};
uint8_t n64ps3[N64PS3SIZE] = {'N', '6', '4', 'P', 'S', '3'};
@@ -81,6 +85,18 @@ void calculate_checksums(uint8_t *file, int filesize, Base base) {
int DATASIZE = HEADERSIZE + NUMCHECKS * 2; // 2 bytes per checksum
int ORIGIN = filesize - DATASIZE; // Stadium data goes at the end of the file
+ // Initialize the CRC table
+ uint16_t crc_table[256];
+ for (int i = 0; i < 256; i++) {
+ uint16_t c = i;
+ uint16_t rem = 0;
+ for (int y = 0; y < 8; y++) {
+ rem = (rem >> 1) ^ ((rem ^ c) & 1 ? CRC_POLY : 0);
+ c >>= 1;
+ }
+ crc_table[i] = rem;
+ }
+
// Clear the global checksum
SET_U16BE(file, GLOBALOFF, 0);
@@ -94,6 +110,15 @@ void calculate_checksums(uint8_t *file, int filesize, Base base) {
memcpy(file + BASEOFF, dbg_base, BASESIZE);
}
+ // Calculate the CRC of the base data, or none
+ if (base) {
+ uint16_t crc = CRC_INIT_BASE;
+ for (int i = BASEOFF; i < BASEOFF + BASESIZE; i++) {
+ crc = (crc >> 8) ^ crc_table[(crc & 0xFF) ^ file[i]];
+ }
+ SET_U16BE(file, BASEOFF + 6, crc);
+ }
+
// Initialize the Stadium data (this should be free space anyway)
memset(file + ORIGIN, 0, DATASIZE);
memcpy(file + ORIGIN, n64ps3, N64PS3SIZE);
@@ -107,18 +132,6 @@ void calculate_checksums(uint8_t *file, int filesize, Base base) {
SET_U16BE(file, ORIGIN + HEADERSIZE + i * 2, checksum);
}
- // Initialize the CRC table
- uint16_t crc_table[256];
- for (int i = 0; i < 256; i++) {
- uint16_t c = i;
- uint16_t rem = 0;
- for (int y = 0; y < 8; y++) {
- rem = (rem >> 1) ^ ((rem ^ c) & 1 ? CRC_POLY : 0);
- c >>= 1;
- }
- crc_table[i] = rem;
- }
-
// Calculate the CRC of the half-bank checksums
uint16_t crc = CRC_INIT;
for (int i = ORIGIN + HEADERSIZE; i < ORIGIN + DATASIZE; i++) {