diff --git a/carillon.sav b/carillon.sav deleted file mode 100644 index 6ec3dbf..0000000 Binary files a/carillon.sav and /dev/null differ diff --git a/gb_tarot_theme1.inc b/gb_tarot_theme1.inc deleted file mode 100644 index 7426525..0000000 --- a/gb_tarot_theme1.inc +++ /dev/null @@ -1,262 +0,0 @@ -; File created by shoofle's s3m2gbt edit - -gb_tarot_theme1_0: - db $00, $00, -db $11, $00, -db $21, $0F, -db $31, $40, -db $12, $18, -db $22, $0F, -db $32, $40, -db $23, $00, -db $24, $00, - - db $0F, $01, - - db $0F, $02, -db $11, $00, -db $21, $0F, -db $31, $80, -db $12, $1C, -db $22, $0F, -db $32, $40, - - db $0F, $03, - - db $0F, $04, -db $11, $00, -db $21, $0F, -db $31, $C0, -db $12, $1F, -db $22, $0F, -db $32, $40, - - db $0F, $05, - - db $0F, $06, -db $81, $00, -db $12, $18, -db $22, $0F, -db $32, $40, - - db $0F, $07, - - db $0F, $08, -db $12, $1C, -db $22, $0F, -db $32, $40, - - db $0F, $09, - - db $0F, $0A, -db $12, $1F, -db $22, $0F, -db $32, $40, - - db $0F, $0B, - - db $0F, $0C, -db $11, $00, -db $21, $0F, -db $31, $00, -db $12, $18, -db $22, $0F, -db $32, $40, - - db $0F, $0D, - - db $0F, $0E, -db $11, $00, -db $21, $0F, -db $31, $00, -db $12, $1C, -db $22, $0F, -db $32, $40, - - db $0F, $0F, - - db $0F, $10, -db $11, $04, -db $21, $0F, -db $31, $40, -db $12, $1C, -db $22, $0F, -db $32, $40, - - db $0F, $11, - - db $0F, $12, -db $11, $04, -db $21, $0F, -db $31, $80, -db $12, $1F, -db $22, $0F, -db $32, $40, - - db $0F, $13, - - db $0F, $14, -db $11, $04, -db $21, $0F, -db $31, $C0, -db $12, $23, -db $22, $0F, -db $32, $40, - - db $0F, $15, - - db $0F, $16, -db $81, $00, -db $12, $1C, -db $22, $0F, -db $32, $40, - - db $0F, $17, - - db $0F, $18, -db $12, $1F, -db $22, $0F, -db $32, $40, - - db $0F, $19, - - db $0F, $1A, -db $12, $23, -db $22, $0F, -db $32, $40, - - db $0F, $1B, - - db $0F, $1C, -db $11, $04, -db $21, $0F, -db $31, $00, -db $12, $1C, -db $22, $0F, -db $32, $40, - - db $0F, $1D, - - db $0F, $1E, -db $11, $04, -db $21, $0F, -db $31, $00, -db $12, $1F, -db $22, $0F, -db $32, $40, - - db $0F, $1F, - - db $0F, $20, -db $11, $06, -db $21, $0F, -db $31, $40, -db $12, $1F, -db $22, $0F, -db $32, $40, - - db $0F, $21, - - db $0F, $22, -db $11, $06, -db $21, $0F, -db $31, $80, -db $22, $0C, - - db $0F, $23, - - db $0F, $24, -db $11, $06, -db $21, $0F, -db $31, $C0, -db $22, $0C, - - db $0F, $25, - - db $0F, $26, -db $81, $00, -db $22, $0C, - - db $0F, $27, - - db $0F, $28, -db $22, $07, - - db $0F, $29, - - db $0F, $2A, - - db $0F, $2B, - - db $0F, $2C, -db $11, $06, -db $21, $0F, -db $31, $00, -db $22, $07, - - db $0F, $2D, - - db $0F, $2E, -db $11, $06, -db $21, $0F, -db $31, $00, - - db $0F, $2F, - - db $0F, $30, -db $11, $05, -db $21, $0F, -db $31, $40, -db $22, $07, - - db $0F, $31, - - db $0F, $32, -db $11, $05, -db $21, $0F, -db $31, $80, - - db $0F, $33, - - db $0F, $34, -db $11, $05, -db $21, $0F, -db $31, $C0, -db $22, $03, - - db $0F, $35, - - db $0F, $36, -db $81, $00, - - db $0F, $37, - - db $0F, $38, -db $22, $03, - - db $0F, $39, - - db $0F, $3A, - - db $0F, $3B, - - db $0F, $3C, -db $11, $11, -db $21, $0F, -db $31, $00, -db $22, $03, - - db $0F, $3D, - - db $0F, $3E, -db $11, $11, -db $21, $0F, -db $31, $00, - - db $0F, $3F, - -gb_tarot_theme1: - db 3 - dw gb_tarot_theme1_0 - dw gb_tarot_theme1_0 - dw gb_tarot_theme1_0 diff --git a/gb_tarot_theme_2.mod b/gb_tarot_theme_2.mod deleted file mode 100644 index 75d6c2a..0000000 Binary files a/gb_tarot_theme_2.mod and /dev/null differ diff --git a/gb_tarot_theme_2.mod~ b/gb_tarot_theme_2.mod~ deleted file mode 100644 index 89df4d4..0000000 Binary files a/gb_tarot_theme_2.mod~ and /dev/null differ diff --git a/gb_tarot_theme_2.s3m b/gb_tarot_theme_2.s3m deleted file mode 100644 index 4202458..0000000 Binary files a/gb_tarot_theme_2.s3m and /dev/null differ diff --git a/gbt_player.inc b/gbt_player.inc deleted file mode 100644 index ddd96a2..0000000 --- a/gbt_player.inc +++ /dev/null @@ -1,643 +0,0 @@ -;############################################################################### -; -; GBT Player v3.1.0 -; -; SPDX-License-Identifier: MIT -; -; Copyright (c) 2009-2021, Antonio Niño Díaz -; -;############################################################################### - - INCLUDE "hardware.inc" -;############################################################################### -; -; GBT Player v3.1.0 -; -; SPDX-License-Identifier: MIT -; -; Copyright (c) 2009-2020, Antonio Niño Díaz -; -;############################################################################### - - IF !DEF(GBT_PLAYER_INC) - DEF GBT_PLAYER_INC = 1 - -;############################################################################### - - EXPORT gbt_play ; Starts playing a song. - ; de = pointer to song data - ; a = default speed. Careful, 0 = 256! - ; bc = data bank (b ignored if ROM with < 256 banks) - ; THIS WILL CHANGE ROM BANK!!! - - EXPORT gbt_pause ; Pauses or unpauses the song. - ; a = 0 to pause, anything else to unpause. - - EXPORT gbt_loop ; Enables/disables looping at the end of the song. - ; a = 0 to stop at the end, anything else to loop - - EXPORT gbt_stop ; Stops the song. - - EXPORT gbt_enable_channels ; Enables given channels. - ; a = channel flags ORed: - ; channel 1 = 1 - ; channel 2 = 2 - ; channel 3 = 4 - ; channel 4 = 8 - - EXPORT gbt_update ; Updates the player, must be called each VBL. - ; Note: This will change the active ROM bank! - -; - If the following value is uncomented, the total of banks allowed is 512 -; (or more), but it's a bit slower. MBC5 ONLY, DOESN'T WORK WITH OTHERS!!! -; YOU MUST USE THE -512-banks OPTION WHEN CONVERTING A SONG WITH mod2gbt!!! -; - If it's commented, only 256 banks are allowed, it's a little bit faster -; and saves a few bytes. MBC1, MBC3 and MBC5 (and others). - -; DEF GBT_USE_MBC5_512BANKS = 1 - -;############################################################################### - - ENDC ; GBT_PLAYER_INC - -;############################################################################### - - -;############################################################################### - - SECTION "GBT_VAR_1",WRAMX[$d800] - -;------------------------------------------------------------------------------- - -gbt_playing: DS 1 - -; pointer to the pattern pointer array -gbt_pattern_array_ptr: DS 2 ; LSB first -IF DEF(GBT_USE_MBC5_512BANKS) -gbt_pattern_array_bank: DS 2 ; LSB first -ELSE -gbt_pattern_array_bank: DS 1 -ENDC - -; playing speed -gbt_speed:: DS 1 - -; Up to 12 bytes per step are copied here to be handled in functions in bank 1 -gbt_temp_play_data:: DS 12 - -gbt_loop_enabled: DS 1 -gbt_ticks_elapsed:: DS 1 -gbt_current_step:: DS 1 -gbt_current_pattern:: DS 1 -gbt_current_step_data_ptr:: DS 2 ; pointer to next step data - LSB first -IF DEF(GBT_USE_MBC5_512BANKS) -gbt_current_step_data_bank:: DS 2 ; bank of current pattern data - LSB first -ELSE -gbt_current_step_data_bank:: DS 1 ; bank of current pattern data -ENDC - -gbt_channels_enabled:: DS 1 - -gbt_pan:: DS 4*1 ; Ch 1-4 -gbt_vol:: DS 4*1 ; Ch 1-4 -gbt_instr:: DS 4*1 ; Ch 1-4 -gbt_freq:: DS 3*2 ; Ch 1-3 - -gbt_channel3_loaded_instrument:: DS 1 ; current loaded instrument ($FF if none) - -; Arpeggio -> Ch 1-3 -gbt_arpeggio_freq_index:: DS 3*3 ; {base index, base index+x, base index+y} * 3 -gbt_arpeggio_enabled:: DS 3*1 ; if 0, disabled -gbt_arpeggio_tick:: DS 3*1 - -; Cut note -gbt_cut_note_tick:: DS 4*1 ; If tick == gbt_cut_note_tick, stop note. - -; Last step of last pattern this is set to 1 -gbt_have_to_stop_next_step:: DS 1 - -gbt_update_pattern_pointers:: DS 1 ; set to 1 by jump effects - -;############################################################################### - - SECTION "GBT_BANK0",ROM0 - -;------------------------------------------------------------------------------- - -gbt_get_pattern_ptr:: ; a = pattern number - - ; loads a pointer to pattern a into gbt_current_step_data_ptr and - ; gbt_current_step_data_bank - - ld e,a - ld d,0 - -IF DEF(GBT_USE_MBC5_512BANKS) - ld a,[gbt_pattern_array_bank+0] - ld [rROMB0],a ; MBC5 - Set bank - ld a,[gbt_pattern_array_bank+1] - ld [rROMB1],a ; MBC5 - Set bank -ELSE - ld a,[gbt_pattern_array_bank] - ld [rROMB0],a ; MBC1, MBC3, MBC5 - Set bank -ENDC - - ld hl,gbt_pattern_array_ptr - ld a,[hl+] - ld h,[hl] - ld l,a - - ; hl = pointer to list of pointers - ; de = pattern number - -IF DEF(GBT_USE_MBC5_512BANKS) - add hl,de -ENDC - add hl,de - add hl,de - add hl,de - - ; hl = pointer to pattern bank - - ld a,[hl+] - ld [gbt_current_step_data_bank+0],a -IF DEF(GBT_USE_MBC5_512BANKS) - ld a,[hl+] - ld [gbt_current_step_data_bank+1],a -ENDC - - ; hl = pointer to pattern data - - ld a,[hl+] - ld h,[hl] - ld l,a - - ld a,l - ld [gbt_current_step_data_ptr],a - ld a,h - ld [gbt_current_step_data_ptr+1],a - - ret - -;------------------------------------------------------------------------------- - -gbt_get_pattern_ptr_banked:: ; a = pattern number - - push de - call gbt_get_pattern_ptr - pop de - - ld hl,gbt_current_step_data_ptr - ld a,[hl+] - ld b,a - ld a,[hl] - or a,b - jr nz,.dont_loop - xor a,a - ld [gbt_current_pattern], a -.dont_loop: - -IF DEF(GBT_USE_MBC5_512BANKS) - xor a,a - ld [rROMB1],a -ENDC - ld a,$01 - ld [rROMB0],a ; MBC1, MBC3, MBC5 - Set bank 1 - - ret - -;------------------------------------------------------------------------------- - -gbt_play:: ; de = data, bc = bank, a = speed - - ld hl,gbt_pattern_array_ptr - ld [hl],e - inc hl - ld [hl],d - - ld [gbt_speed],a - - ld a,c - ld [gbt_pattern_array_bank+0],a -IF DEF(GBT_USE_MBC5_512BANKS) - ld a,b - ld [gbt_pattern_array_bank+1],a -ENDC - - ld a,0 - call gbt_get_pattern_ptr - - xor a,a - ld [gbt_current_step],a - ld [gbt_current_pattern],a - ld [gbt_ticks_elapsed],a - ld [gbt_loop_enabled],a - ld [gbt_have_to_stop_next_step],a - ld [gbt_update_pattern_pointers],a - - ld a,$FF - ld [gbt_channel3_loaded_instrument],a - - ld a,$0F - ld [gbt_channels_enabled],a - - ld hl,gbt_pan - ld a,$11 ; L and R - ld [hl+],a - add a,a - ld [hl+],a - add a,a - ld [hl+],a - add a,a - ld [hl],a - - ld hl,gbt_vol - ld a,$F0 ; 100% - ld [hl+],a - ld [hl+],a - ld a,$20 ; 100% - ld [hl+],a - ld a,$F0 ; 100% - ld [hl+],a - - ld a,0 - - ld hl,gbt_instr - ld [hl+],a - ld [hl+],a - ld [hl+],a - ld [hl+],a - - ld hl,gbt_freq - ld [hl+],a - ld [hl+],a - ld [hl+],a - ld [hl+],a - ld [hl+],a - ld [hl+],a - - ld [gbt_arpeggio_enabled+0],a - ld [gbt_arpeggio_enabled+1],a - ld [gbt_arpeggio_enabled+2],a - - ld a,$FF - ld [gbt_cut_note_tick+0],a - ld [gbt_cut_note_tick+1],a - ld [gbt_cut_note_tick+2],a - ld [gbt_cut_note_tick+3],a - - ld a,$80 - ld [rNR52],a - ld a,$00 - ld [rNR51],a - ld a,$00 ; 0% - ld [rNR50],a - - xor a,a - ld [rNR10],a - ld [rNR11],a - ld [rNR12],a - ld [rNR13],a - ld [rNR14],a - ld [rNR21],a - ld [rNR22],a - ld [rNR23],a - ld [rNR24],a - ld [rNR30],a - ld [rNR31],a - ld [rNR32],a - ld [rNR33],a - ld [rNR34],a - ld [rNR41],a - ld [rNR42],a - ld [rNR43],a - ld [rNR44],a - - ld a,$77 ; 100% - ld [rNR50],a - - ld a,$01 - ld [gbt_playing],a - - ret - -;------------------------------------------------------------------------------- - -gbt_pause:: ; a = pause/unpause - ld [gbt_playing],a - or a,a - jr nz,.gbt_pause_unmute - - ; Silence all channels - xor a,a - ld [rNR51],a - - ret - -.gbt_pause_unmute: ; Unmute sound if playback is resumed - - ; Restore panning status - ld hl,gbt_pan - ld a,[hl+] - or a,[hl] - inc hl - or a,[hl] - inc hl - or a,[hl] - ld [rNR51],a - - ret - -;------------------------------------------------------------------------------- - -gbt_loop:: ; a = loop/don't loop - ld [gbt_loop_enabled],a - ret - -;------------------------------------------------------------------------------- - -gbt_stop:: - xor a,a - ld [gbt_playing],a - ld [rNR50],a - ld [rNR51],a - ld [rNR52],a - ret - -;------------------------------------------------------------------------------- - -gbt_enable_channels:: ; a = channel flags (channel flag = (1<<(channel_num-1))) - ld [gbt_channels_enabled],a - ret - -;------------------------------------------------------------------------------- - - EXPORT gbt_update_bank1 - -gbt_update:: - - ld a,[gbt_playing] - or a,a - ret z ; If not playing, return - - ; Handle tick counter - - ld hl,gbt_ticks_elapsed - ld a,[gbt_speed] ; a = total ticks - ld b,[hl] ; b = ticks elapsed - inc b - ld [hl],b - cp a,b - jr z,.dontexit - - ; Tick != Speed, update effects and exit -IF DEF(GBT_USE_MBC5_512BANKS) - xor a,a - ld [rROMB1],a -ENDC - ld a,$01 - ld [rROMB0],a ; MBC1, MBC3, MBC5 - Set bank 1 - ; Call update function in bank 1 (in gbt_player_bank1.s) - call gbt_update_effects_bank1 - - ret - -.dontexit: - ld [hl],$00 ; reset tick counter - - ; Clear tick-based effects - ; ------------------------ - - xor a,a - ld hl,gbt_arpeggio_enabled ; Disable arpeggio - ld [hl+],a - ld [hl+],a - ld [hl],a - dec a ; a = $FF - ld hl,gbt_cut_note_tick ; Disable cut note - ld [hl+],a - ld [hl+],a - ld [hl+],a - ld [hl],a - - ; Update effects - ; -------------- - -IF DEF(GBT_USE_MBC5_512BANKS) - xor a,a - ld [rROMB1],a -ENDC - ld a,$01 - ld [rROMB0],a ; MBC1, MBC3, MBC5 - Set bank 1 - ; Call update function in bank 1 (in gbt_player_bank1.s) - call gbt_update_effects_bank1 - - ; Check if last step - ; ------------------ - - ld a,[gbt_have_to_stop_next_step] - or a,a - jr z,.dont_stop - - call gbt_stop - ld a,0 - ld [gbt_have_to_stop_next_step],a - ret - -.dont_stop: - - ; Get this step data - ; ------------------ - - ; Change to bank with song data - -IF DEF(GBT_USE_MBC5_512BANKS) - ld a,[gbt_current_step_data_bank+0] - ld [rROMB0],a ; MBC5 - Set bank - ld a,[gbt_current_step_data_bank+1] - ld [rROMB1],a ; MBC5 - Set bank -ELSE - ld a,[gbt_current_step_data_bank] - ld [rROMB0],a ; MBC1, MBC3, MBC5 - Set bank -ENDC - - ; Get step data - - ld a,[gbt_current_step_data_ptr] - ld l,a - ld a,[gbt_current_step_data_ptr+1] - ld h,a ; hl = pointer to data - - ld de,gbt_temp_play_data - - ld b,4 -.copy_loop: ; copy as bytes as needed for this step - - ld a,[hl+] - ld [de],a - inc de - bit 7,a - jr nz,.more_bytes - bit 6,a - jr z,.no_more_bytes_this_channel - - jr .one_more_byte - -.more_bytes: - - ld a,[hl+] - ld [de],a - inc de - bit 7,a - jr z,.no_more_bytes_this_channel - -.one_more_byte: - - ld a,[hl+] - ld [de],a - inc de - -.no_more_bytes_this_channel: - dec b - jr nz,.copy_loop - - ld a,l - ld [gbt_current_step_data_ptr],a - ld a,h - ld [gbt_current_step_data_ptr+1],a ; save pointer to data - - ; Increment step/pattern - ; ---------------------- - - ; Increment step - - ld a,[gbt_current_step] - inc a - ld [gbt_current_step],a - cp a,64 - jr nz,.dont_increment_pattern - - ; Increment pattern - - ld a,0 - ld [gbt_current_step],a ; Step 0 - - ld a,[gbt_current_pattern] - inc a - ld [gbt_current_pattern],a - - call gbt_get_pattern_ptr - - ld a,[gbt_current_step_data_ptr] - ld b,a - ld a,[gbt_current_step_data_ptr+1] - or a,b - jr nz,.not_ended ; if pointer is 0, song has ended - - ld a,[gbt_loop_enabled] - and a,a - - jr z,.loop_disabled - - ; If loop is enabled, jump to pattern 0 - - ld a,0 - ld [gbt_current_pattern],a - - call gbt_get_pattern_ptr - - jr .end_handling_steps_pattern - -.loop_disabled: - - ; If loop is disabled, stop song - ; Stop it next step, if not this step won't be played - - ld a,1 - ld [gbt_have_to_stop_next_step],a - -.not_ended: - -.dont_increment_pattern: - -.end_handling_steps_pattern: - -IF DEF(GBT_USE_MBC5_512BANKS) - xor a,a - ld [rROMB1],a ; MBC5 -ENDC - ld a,$01 - ld [rROMB0],a ; MBC1, MBC3, MBC5 - Set bank 1 - ; Call update function in bank 1 (in gbt_player_bank1.s) - call gbt_update_bank1 - - ; Check if any effect has changed the pattern or step - - ld a,[gbt_update_pattern_pointers] - and a,a - ret z - ; if any effect has changed the pattern or step, update - - xor a,a - ld [gbt_update_pattern_pointers],a ; clear update flag - - ld [gbt_have_to_stop_next_step],a ; clear stop flag - - ld a,[gbt_current_pattern] - call gbt_get_pattern_ptr ; set ptr to start of the pattern - - ; Search the step - - ; Change to bank with song data - -IF DEF(GBT_USE_MBC5_512BANKS) - ld a,[gbt_pattern_array_bank+1] - ld [rROMB1],a ; MBC5 -ENDC - ld a,[gbt_pattern_array_bank+0] - ld [rROMB0],a ; MBC1, MBC3, MBC5 - - ld a,[gbt_current_step_data_ptr] - ld l,a - ld a,[gbt_current_step_data_ptr+1] - ld h,a ; hl = pointer to data - - ld a,[gbt_current_step] - and a,a - ret z ; if changing to step 0, exit - - add a,a - add a,a - ld b,a ; b = iterations = step * 4 (number of channels) -.next_channel: - - ld a,[hl+] - bit 7,a - jr nz,.next_channel_more_bytes - bit 6,a - jr z,.next_channel_no_more_bytes_this_channel - - jr .next_channel_one_more_byte - -.next_channel_more_bytes: - - ld a,[hl+] - bit 7,a - jr z,.next_channel_no_more_bytes_this_channel - -.next_channel_one_more_byte: - - ld a,[hl+] - -.next_channel_no_more_bytes_this_channel: - dec b - jr nz,.next_channel - - ld a,l - ld [gbt_current_step_data_ptr],a - ld a,h - ld [gbt_current_step_data_ptr+1],a ; save pointer to data - - ret - -;############################################################################### diff --git a/gbt_player_bank1.inc b/gbt_player_bank1.inc deleted file mode 100644 index 14093ba..0000000 --- a/gbt_player_bank1.inc +++ /dev/null @@ -1,1389 +0,0 @@ -;############################################################################### -; -; GBT Player v3.1.0 -; -; SPDX-License-Identifier: MIT -; -; Copyright (c) 2009-2020 Antonio Niño Díaz -; -;############################################################################### - - INCLUDE "hardware.inc" - INCLUDE "gbt_player.inc" - -;############################################################################### - - SECTION "GBT_BANK1",ROMX,BANK[1] - -;------------------------------------------------------------------------------- - -gbt_wave: ; 8 sounds -DB $A5,$D7,$C9,$E1,$BC,$9A,$76,$31,$0C,$BA,$DE,$60,$1B,$CA,$03,$93 ; random -DB $F0,$E1,$D2,$C3,$B4,$A5,$96,$87,$78,$69,$5A,$4B,$3C,$2D,$1E,$0F -DB $FD,$EC,$DB,$CA,$B9,$A8,$97,$86,$79,$68,$57,$46,$35,$24,$13,$02 ; up-downs -DB $DE,$FE,$DC,$BA,$9A,$A9,$87,$77,$88,$87,$65,$56,$54,$32,$10,$12 -DB $AB,$CD,$EF,$ED,$CB,$A0,$12,$3E,$DC,$BA,$BC,$DE,$FE,$DC,$32,$10 ; tri. broken -DB $FF,$EE,$DD,$CC,$BB,$AA,$99,$88,$77,$66,$55,$44,$33,$22,$11,$00 ; triangular -DB $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$00,$00,$00,$00,$00,$00,$00,$00 ; square -DB $79,$BC,$DE,$EF,$FF,$EE,$DC,$B9,$75,$43,$21,$10,$00,$11,$23,$45 ; sine - -gbt_noise: ; 16 sounds - ; 7 bit - DB $5F,$5B,$4B,$2F,$3B,$58,$1F,$0F - ; 15 bit - DB $90,$80,$70,$50,$00 - DB $67,$63,$53 - -gbt_frequencies: - DW 44, 156, 262, 363, 457, 547, 631, 710, 786, 854, 923, 986 - DW 1046, 1102, 1155, 1205, 1253, 1297, 1339, 1379, 1417, 1452, 1486, 1517 - DW 1546, 1575, 1602, 1627, 1650, 1673, 1694, 1714, 1732, 1750, 1767, 1783 - DW 1798, 1812, 1825, 1837, 1849, 1860, 1871, 1881, 1890, 1899, 1907, 1915 - DW 1923, 1930, 1936, 1943, 1949, 1954, 1959, 1964, 1969, 1974, 1978, 1982 - DW 1985, 1988, 1992, 1995, 1998, 2001, 2004, 2006, 2009, 2011, 2013, 2015 - -;------------------------------------------------------------------------------- - -_gbt_get_freq_from_index: ; a = index, bc = returned freq - ld hl,gbt_frequencies - ld c,a - ld b,$00 - add hl,bc - add hl,bc - ld c,[hl] - inc hl - ld b,[hl] - ret - -;------------------------------------------------------------------------------- -; ---------------------------------- Channel 1 --------------------------------- -;------------------------------------------------------------------------------- - -gbt_channel_1_handle:: ; de = info - - ld a,[gbt_channels_enabled] - and a,$01 - jr nz,.channel1_enabled - - ; Channel is disabled. Increment pointer as needed - - ld a,[de] - inc de - bit 7,a - jr nz,.more_bytes - bit 6,a - jr z,.no_more_bytes_this_channel - - jr .one_more_byte - -.more_bytes: - - ld a,[de] - inc de - bit 7,a - jr z,.no_more_bytes_this_channel - -.one_more_byte: - - inc de - -.no_more_bytes_this_channel: - - ret - -.channel1_enabled: - - ; Channel 1 is enabled - - ld a,[de] - inc de - - bit 7,a - jr nz,.has_frequency - - ; Not frequency - - bit 6,a - jr nz,.instr_effects - - ; Set volume or NOP - - bit 5,a - jr nz,.just_set_volume - - ; NOP - - ret - -.just_set_volume: - - ; Set volume - - and a,$0F - swap a - ld [gbt_vol+0],a - - jr .refresh_channel1_regs - -.instr_effects: - - ; Set instrument and effect - - ld b,a ; save byte - - and a,$30 - add a,a - add a,a - ld [gbt_instr+0],a ; Instrument - - ld a,b ; restore byte - - and a,$0F ; a = effect - - call gbt_channel_1_set_effect - - jr .refresh_channel1_regs - -.has_frequency: - - ; Has frequency - - and a,$7F - ld [gbt_arpeggio_freq_index+0*3],a - ; This destroys hl and a. Returns freq in bc - call _gbt_get_freq_from_index - - ld a,c - ld [gbt_freq+0*2+0],a - ld a,b - ld [gbt_freq+0*2+1],a ; Get frequency - - ld a,[de] - inc de - - bit 7,a - jr nz,.freq_instr_and_effect - - ; Freq + Instr + Volume - - ld b,a ; save byte - - and a,$30 - add a,a - add a,a - ld [gbt_instr+0],a ; Instrument - - ld a,b ; restore byte - - and a,$0F ; a = volume - - swap a - ld [gbt_vol+0],a - - jr .refresh_channel1_regs - -.freq_instr_and_effect: - - ; Freq + Instr + Effect - - ld b,a ; save byte - - and a,$30 - add a,a - add a,a - ld [gbt_instr+0],a ; Instrument - - ld a,b ; restore byte - - and a,$0F ; a = effect - - call gbt_channel_1_set_effect - - ;jr .refresh_channel1_regs - -.refresh_channel1_regs: - - ; fall through!!!!! - -; ----------------- - -channel1_refresh_registers: - - xor a,a - ld [rNR10],a - ld a,[gbt_instr+0] - ld [rNR11],a - ld a,[gbt_vol+0] - ld [rNR12],a - ld a,[gbt_freq+0*2+0] - ld [rNR13],a - ld a,[gbt_freq+0*2+1] - or a,$80 ; start - ld [rNR14],a - - ret - -; ------------------ - -channel1_update_effects: ; returns 1 in a if it needed to update sound registers - - ; Cut note - ; -------- - - ld a,[gbt_cut_note_tick+0] - ld hl,gbt_ticks_elapsed - cp a,[hl] - jp nz,.dont_cut - - dec a ; a = $FF - ld [gbt_cut_note_tick+0],a ; disable cut note - - xor a,a ; vol = 0 - ld [rNR12],a - ld a,$80 ; start - ld [rNR14],a - -.dont_cut: - - ; Arpeggio - ; -------- - - ld a,[gbt_arpeggio_enabled+0] - and a,a - ret z ; a is 0, return 0 - - ; If enabled arpeggio, handle it - - ld a,[gbt_arpeggio_tick+0] - and a,a - jr nz,.not_tick_0 - - ; Tick 0 - Set original frequency - - ld a,[gbt_arpeggio_freq_index+0*3+0] - - call _gbt_get_freq_from_index - - ld a,c - ld [gbt_freq+0*2+0],a - ld a,b - ld [gbt_freq+0*2+1],a ; Set frequency - - ld a,1 - ld [gbt_arpeggio_tick+0],a - - ret ; ret 1 - -.not_tick_0: - - cp a,1 - jr nz,.not_tick_1 - - ; Tick 1 - - ld a,[gbt_arpeggio_freq_index+0*3+1] - - call _gbt_get_freq_from_index - - ld a,c - ld [gbt_freq+0*2+0],a - ld a,b - ld [gbt_freq+0*2+1],a ; Set frequency - - ld a,2 - ld [gbt_arpeggio_tick+0],a - - dec a - ret ; ret 1 - -.not_tick_1: - - ; Tick 2 - - ld a,[gbt_arpeggio_freq_index+0*3+2] - - call _gbt_get_freq_from_index - - ld a,c - ld [gbt_freq+0*2+0],a - ld a,b - ld [gbt_freq+0*2+1],a ; Set frequency - - xor a,a - ld [gbt_arpeggio_tick+0],a - - inc a ; ret 1 - ret - -; ----------------- - -; returns a = 1 if needed to update registers, 0 if not -gbt_channel_1_set_effect: ; a = effect, de = pointer to data. - - ld hl,.gbt_ch1_jump_table - ld c,a - ld b,0 - add hl,bc - add hl,bc - - ld a,[hl+] - ld h,[hl] - ld l,a - - ld a,[de] ; load args - inc de - - jp hl - -.gbt_ch1_jump_table: - DW .gbt_ch1_pan - DW .gbt_ch1_arpeggio - DW .gbt_ch1_cut_note - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_jump_pattern - DW gbt_ch1234_jump_position - DW gbt_ch1234_speed - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - -.gbt_ch1_pan: - and a,$11 - ld [gbt_pan+0],a - xor a,a - ret ; ret 0 do not update registers, only NR51 at end. - -.gbt_ch1_arpeggio: - ld b,a ; b = params - - ld hl,gbt_arpeggio_freq_index+0*3 - ld c,[hl] ; c = base index - inc hl - - ld a,b - swap a - and a,$0F - add a,c - - ld [hl+],a ; save first increment - - ld a,b - and a,$0F - add a,c - - ld [hl],a ; save second increment - - ld a,1 - ld [gbt_arpeggio_enabled+0],a - ld [gbt_arpeggio_tick+0],a - - ret ; ret 1 - -.gbt_ch1_cut_note: - ld [gbt_cut_note_tick+0],a - xor a,a ; ret 0 - ret - -;------------------------------------------------------------------------------- -; ---------------------------------- Channel 2 --------------------------------- -;------------------------------------------------------------------------------- - -gbt_channel_2_handle:: ; de = info - - ld a,[gbt_channels_enabled] - and a,$02 - jr nz,.channel2_enabled - - ; Channel is disabled. Increment pointer as needed - - ld a,[de] - inc de - bit 7,a - jr nz,.more_bytes - bit 6,a - jr z,.no_more_bytes_this_channel - - jr .one_more_byte - -.more_bytes: - - ld a,[de] - inc de - bit 7,a - jr z,.no_more_bytes_this_channel - -.one_more_byte: - - inc de - -.no_more_bytes_this_channel: - - ret - -.channel2_enabled: - - ; Channel 2 is enabled - - ld a,[de] - inc de - - bit 7,a - jr nz,.has_frequency - - ; Not frequency - - bit 6,a - jr nz,.instr_effects - - ; Set volume or NOP - - bit 5,a - jr nz,.just_set_volume - - ; NOP - - ret - -.just_set_volume: - - ; Set volume - - and a,$0F - swap a - ld [gbt_vol+1],a - - jr .refresh_channel2_regs - -.instr_effects: - - ; Set instrument and effect - - ld b,a ; save byte - - and a,$30 - add a,a - add a,a - ld [gbt_instr+1],a ; Instrument - - ld a,b ; restore byte - - and a,$0F ; a = effect - - call gbt_channel_2_set_effect - - jr .refresh_channel2_regs - -.has_frequency: - - ; Has frequency - - and a,$7F - ld [gbt_arpeggio_freq_index+1*3],a - ; This destroys hl and a. Returns freq in bc - call _gbt_get_freq_from_index - - ld a,c - ld [gbt_freq+1*2+0],a - ld a,b - ld [gbt_freq+1*2+1],a ; Get frequency - - ld a,[de] - inc de - - bit 7,a - jr nz,.freq_instr_and_effect - - ; Freq + Instr + Volume - - ld b,a ; save byte - - and a,$30 - add a,a - add a,a - ld [gbt_instr+1],a ; Instrument - - ld a,b ; restore byte - - and a,$0F ; a = volume - - swap a - ld [gbt_vol+1],a - - jr .refresh_channel2_regs - -.freq_instr_and_effect: - - ; Freq + Instr + Effect - - ld b,a ; save byte - - and a,$30 - add a,a - add a,a - ld [gbt_instr+1],a ; Instrument - - ld a,b ; restore byte - - and a,$0F ; a = effect - - call gbt_channel_2_set_effect - - ;jr .refresh_channel2_regs - -.refresh_channel2_regs: - - ; fall through!!!!! - -; ----------------- - -channel2_refresh_registers: - - ld a,[gbt_instr+1] - ld [rNR21],a - ld a,[gbt_vol+1] - ld [rNR22],a - ld a,[gbt_freq+1*2+0] - ld [rNR23],a - ld a,[gbt_freq+1*2+1] - or a,$80 ; start - ld [rNR24],a - - ret - -; ------------------ - -channel2_update_effects: ; returns 1 in a if it needed to update sound registers - - ; Cut note - ; -------- - - ld a,[gbt_cut_note_tick+1] - ld hl,gbt_ticks_elapsed - cp a,[hl] - jp nz,.dont_cut - - dec a ; a = $FF - ld [gbt_cut_note_tick+1],a ; disable cut note - - xor a,a ; vol = 0 - ld [rNR22],a - ld a,$80 ; start - ld [rNR24],a - -.dont_cut: - - ; Arpeggio - ; -------- - - ld a,[gbt_arpeggio_enabled+1] - and a,a - ret z ; a is 0, return 0 - - ; If enabled arpeggio, handle it - - ld a,[gbt_arpeggio_tick+1] - and a,a - jr nz,.not_tick_0 - - ; Tick 0 - Set original frequency - - ld a,[gbt_arpeggio_freq_index+1*3+0] - - call _gbt_get_freq_from_index - - ld a,c - ld [gbt_freq+1*2+0],a - ld a,b - ld [gbt_freq+1*2+1],a ; Set frequency - - ld a,1 - ld [gbt_arpeggio_tick+1],a - - ret ; ret 1 - -.not_tick_0: - - cp a,1 - jr nz,.not_tick_1 - - ; Tick 1 - - ld a,[gbt_arpeggio_freq_index+1*3+1] - - call _gbt_get_freq_from_index - - ld a,c - ld [gbt_freq+1*2+0],a - ld a,b - ld [gbt_freq+1*2+1],a ; Set frequency - - ld a,2 - ld [gbt_arpeggio_tick+1],a - - dec a - ret ; ret 1 - -.not_tick_1: - - ; Tick 2 - - ld a,[gbt_arpeggio_freq_index+1*3+2] - - call _gbt_get_freq_from_index - - ld a,c - ld [gbt_freq+1*2+0],a - ld a,b - ld [gbt_freq+1*2+1],a ; Set frequency - - xor a,a - ld [gbt_arpeggio_tick+1],a - - inc a ; ret 1 - ret - -; ----------------- - -; returns a = 1 if needed to update registers, 0 if not -gbt_channel_2_set_effect: ; a = effect, de = pointer to data - - ld hl,.gbt_ch2_jump_table - ld c,a - ld b,0 - add hl,bc - add hl,bc - - ld a,[hl+] - ld h,[hl] - ld l,a - - ld a,[de] ; load args - inc de - - jp hl - -.gbt_ch2_jump_table: - DW .gbt_ch2_pan - DW .gbt_ch2_arpeggio - DW .gbt_ch2_cut_note - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_jump_pattern - DW gbt_ch1234_jump_position - DW gbt_ch1234_speed - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - -.gbt_ch2_pan: - and a,$22 - ld [gbt_pan+1],a - xor a,a - ret ; ret 0 do not update registers, only NR51 at end. - -.gbt_ch2_arpeggio: - ld b,a ; b = params - - ld hl,gbt_arpeggio_freq_index+1*3 - ld c,[hl] ; c = base index - inc hl - - ld a,b - swap a - and a,$0F - add a,c - - ld [hl+],a ; save first increment - - ld a,b - and a,$0F - add a,c - - ld [hl],a ; save second increment - - ld a,1 - ld [gbt_arpeggio_enabled+1],a - ld [gbt_arpeggio_tick+1],a - - ret ; ret 1 - -.gbt_ch2_cut_note: - ld [gbt_cut_note_tick+1],a - xor a,a ; ret 0 - ret - -;------------------------------------------------------------------------------- -; ---------------------------------- Channel 3 --------------------------------- -;------------------------------------------------------------------------------- - -gbt_channel_3_handle:: ; de = info - - ld a,[gbt_channels_enabled] - and a,$04 - jr nz,.channel3_enabled - - ; Channel is disabled. Increment pointer as needed - - ld a,[de] - inc de - bit 7,a - jr nz,.more_bytes - bit 6,a - jr z,.no_more_bytes_this_channel - - jr .one_more_byte - -.more_bytes: - - ld a,[de] - inc de - bit 7,a - jr z,.no_more_bytes_this_channel - -.one_more_byte: - - inc de - -.no_more_bytes_this_channel: - - ret - -.channel3_enabled: - - ; Channel 3 is enabled - - ld a,[de] - inc de - - bit 7,a - jr nz,.has_frequency - - ; Not frequency - - bit 6,a - jr nz,.effects - - ; Set volume or NOP - - bit 5,a - jr nz,.just_set_volume - - ; NOP - - ret - -.just_set_volume: - - ; Set volume - - and a,$0F - swap a - ld [gbt_vol+2],a - - jr .refresh_channel3_regs - -.effects: - - ; Set effect - - and a,$0F ; a = effect - - call gbt_channel_3_set_effect - and a,a - ret z ; if 0, don't refresh registers - - jr .refresh_channel3_regs - -.has_frequency: - - ; Has frequency - - and a,$7F - ld [gbt_arpeggio_freq_index+2*3],a - ; This destroys hl and a. Returns freq in bc - call _gbt_get_freq_from_index - - ld a,c - ld [gbt_freq+2*2+0],a - ld a,b - ld [gbt_freq+2*2+1],a ; Get frequency - - ld a,[de] - inc de - - bit 7,a - jr nz,.freq_instr_and_effect - - ; Freq + Instr + Volume - - ld b,a ; save byte - - and a,$0F - ld [gbt_instr+2],a ; Instrument - - ld a,b ; restore byte - - and a,$30 ; a = volume - add a,a - ld [gbt_vol+2],a - - jr .refresh_channel3_regs - -.freq_instr_and_effect: - - ; Freq + Instr + Effect - - ld b,a ; save byte - - and a,$0F - ld [gbt_instr+2],a ; Instrument - - ld a,b ; restore byte - - and a,$70 - swap a ; a = effect (only 0-7 allowed here) - - call gbt_channel_3_set_effect - - ;jr .refresh_channel3_regs - -.refresh_channel3_regs: - - ; fall through!!!!! - -; ----------------- - -channel3_refresh_registers: - - xor a,a - ld [rNR30],a ; disable - - ld a,[gbt_channel3_loaded_instrument] - ld b,a - ld a,[gbt_instr+2] - cp a,b - call nz,gbt_channel3_load_instrument ; a = instrument - - ld a,$80 - ld [rNR30],a ; enable - - xor a,a - ld [rNR31],a - ld a,[gbt_vol+2] - ld [rNR32],a - ld a,[gbt_freq+2*2+0] - ld [rNR33],a - ld a,[gbt_freq+2*2+1] - or a,$80 ; start - ld [rNR34],a - - ret - -; ------------------ - -gbt_channel3_load_instrument: - - ld [gbt_channel3_loaded_instrument],a - - swap a ; a = a * 16 - ld c,a - ld b,0 - ld hl,gbt_wave - add hl,bc - - ld c,$30 - ld b,16 -.loop: - ld a,[hl+] - ld [$FF00+c],a - inc c - dec b - jr nz,.loop - - ret - -; ------------------ - -channel3_update_effects: ; returns 1 in a if it needed to update sound registers - - ; Cut note - ; -------- - - ld a,[gbt_cut_note_tick+2] - ld hl,gbt_ticks_elapsed - cp a,[hl] - jp nz,.dont_cut - - dec a ; a = $FF - ld [gbt_cut_note_tick+2],a ; disable cut note - - ld a,$80 - ld [rNR30],a ; enable - - xor a,a ; vol = 0 - ld [rNR32],a - ld a,$80 ; start - ld [rNR34],a - -.dont_cut: - - ; Arpeggio - ; -------- - - ld a,[gbt_arpeggio_enabled+2] - and a,a - ret z ; a is 0, return 0 - - ; If enabled arpeggio, handle it - - ld a,[gbt_arpeggio_tick+2] - and a,a - jr nz,.not_tick_0 - - ; Tick 0 - Set original frequency - - ld a,[gbt_arpeggio_freq_index+2*3+0] - - call _gbt_get_freq_from_index - - ld a,c - ld [gbt_freq+2*2+0],a - ld a,b - ld [gbt_freq+2*2+1],a ; Set frequency - - ld a,1 - ld [gbt_arpeggio_tick+2],a - - ret ; ret 1 - -.not_tick_0: - - cp a,1 - jr nz,.not_tick_1 - - ; Tick 1 - - ld a,[gbt_arpeggio_freq_index+2*3+1] - - call _gbt_get_freq_from_index - - ld a,c - ld [gbt_freq+2*2+0],a - ld a,b - ld [gbt_freq+2*2+1],a ; Set frequency - - ld a,2 - ld [gbt_arpeggio_tick+2],a - - dec a - ret ; ret 1 - -.not_tick_1: - - ; Tick 2 - - ld a,[gbt_arpeggio_freq_index+2*3+2] - - call _gbt_get_freq_from_index - - ld a,c - ld [gbt_freq+2*2+0],a - ld a,b - ld [gbt_freq+2*2+1],a ; Set frequency - - xor a,a - ld [gbt_arpeggio_tick+2],a - - inc a - ret ; ret 1 - -; ----------------- - -; returns a = 1 if needed to update registers, 0 if not -gbt_channel_3_set_effect: ; a = effect, de = pointer to data - - ld hl,.gbt_ch3_jump_table - ld c,a - ld b,0 - add hl,bc - add hl,bc - - ld a,[hl+] - ld h,[hl] - ld l,a - - ld a,[de] ; load args - inc de - - jp hl - -.gbt_ch3_jump_table: - DW .gbt_ch3_pan - DW .gbt_ch3_arpeggio - DW .gbt_ch3_cut_note - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_jump_pattern - DW gbt_ch1234_jump_position - DW gbt_ch1234_speed - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - -.gbt_ch3_pan: - and a,$44 - ld [gbt_pan+2],a - xor a,a - ret ; ret 0 do not update registers, only NR51 at end. - -.gbt_ch3_arpeggio: - ld b,a ; b = params - - ld hl,gbt_arpeggio_freq_index+2*3 - ld c,[hl] ; c = base index - inc hl - - ld a,b - swap a - and a,$0F - add a,c - - ld [hl+],a ; save first increment - - ld a,b - and a,$0F - add a,c - - ld [hl],a ; save second increment - - ld a,1 - ld [gbt_arpeggio_enabled+2],a - ld [gbt_arpeggio_tick+2],a - - ret ; ret 1 - -.gbt_ch3_cut_note: - ld [gbt_cut_note_tick+2],a - xor a,a ; ret 0 - ret - -;------------------------------------------------------------------------------- -; ---------------------------------- Channel 4 --------------------------------- -;------------------------------------------------------------------------------- - -gbt_channel_4_handle:: ; de = info - - ld a,[gbt_channels_enabled] - and a,$08 - jr nz,.channel4_enabled - - ; Channel is disabled. Increment pointer as needed - - ld a,[de] - inc de - bit 7,a - jr nz,.more_bytes - bit 6,a - jr z,.no_more_bytes_this_channel - - jr .one_more_byte - -.more_bytes: - - ld a,[de] - inc de - bit 7,a - jr z,.no_more_bytes_this_channel - -.one_more_byte: - - inc de - -.no_more_bytes_this_channel: - - ret - -.channel4_enabled: - - ; Channel 4 is enabled - - ld a,[de] - inc de - - bit 7,a - jr nz,.has_instrument - - ; Not instrument - - bit 6,a - jr nz,.effects - - ; Set volume or NOP - - bit 5,a - jr nz,.just_set_volume - - ; NOP - - ret - -.just_set_volume: - - ; Set volume - - and a,$0F - swap a - ld [gbt_vol+3],a - - jr .refresh_channel4_regs - -.effects: - - ; Set effect - - and a,$0F ; a = effect - - call gbt_channel_4_set_effect - and a,a - ret z ; if 0, don't refresh registers - - jr .refresh_channel4_regs - -.has_instrument: - - ; Has instrument - - and a,$0F - ld hl,gbt_noise - ld c,a - ld b,0 - add hl,bc - ld a,[hl] ; a = instrument data - - ld [gbt_instr+3],a - - ld a,[de] - inc de - - bit 7,a - jr nz,.instr_and_effect - - ; Instr + Volume - - and a,$0F ; a = volume - - swap a - ld [gbt_vol+3],a - - jr .refresh_channel4_regs - -.instr_and_effect: - - ; Instr + Effect - - and a,$0F ; a = effect - - call gbt_channel_4_set_effect - - ;jr .refresh_channel4_regs - -.refresh_channel4_regs: - - ; fall through!!!!! - -; ----------------- - -channel4_refresh_registers: - - xor a,a - ld [rNR41],a - ld a,[gbt_vol+3] - ld [rNR42],a - ld a,[gbt_instr+3] - ld [rNR43],a - ld a,$80 ; start - ld [rNR44],a - - ret - -; ------------------ - -channel4_update_effects: ; returns 1 in a if it needed to update sound registers - - ; Cut note - ; -------- - - ld a,[gbt_cut_note_tick+3] - ld hl,gbt_ticks_elapsed - cp a,[hl] - jp nz,.dont_cut - - dec a ; a = $FF - ld [gbt_cut_note_tick+3],a ; disable cut note - - xor a,a ; vol = 0 - ld [rNR42],a - ld a,$80 ; start - ld [rNR44],a - -.dont_cut: - - xor a,a - ret ; a is 0, return 0 - -; ----------------- - -; returns a = 1 if needed to update registers, 0 if not -gbt_channel_4_set_effect: ; a = effect, de = pointer to data - - ld hl,.gbt_ch4_jump_table - ld c,a - ld b,0 - add hl,bc - add hl,bc - - ld a,[hl+] - ld h,[hl] - ld l,a - - ld a,[de] ; load args - inc de - - jp hl - -.gbt_ch4_jump_table: - DW .gbt_ch4_pan - DW gbt_ch1234_nop ; gbt_ch4_arpeggio - DW .gbt_ch4_cut_note - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_jump_pattern - DW gbt_ch1234_jump_position - DW gbt_ch1234_speed - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - DW gbt_ch1234_nop - -.gbt_ch4_pan: - and a,$88 - ld [gbt_pan+3],a - xor a,a - ret ; ret 0 do not update registers, only NR51 at end. - -.gbt_ch4_cut_note: - ld [gbt_cut_note_tick+3],a - xor a,a ; ret 0 - ret - -;------------------------------------------------------------------------------- -;------------------------------------------------------------------------------- -;------------------------------------------------------------------------------- - -; Common effects go here: - -gbt_ch1234_nop: - xor a,a ;ret 0 - ret - -gbt_ch1234_jump_pattern: - ld [gbt_current_pattern],a - xor a,a - ld [gbt_current_step],a - ld [gbt_have_to_stop_next_step],a ; clear stop flag - ld a,1 - ld [gbt_update_pattern_pointers],a - xor a,a ;ret 0 - ret - -gbt_ch1234_jump_position: - ld [gbt_current_step],a - ld hl,gbt_current_pattern - inc [hl] - - ; Check to see if jump puts us past end of song - ld a,[hl] - call gbt_get_pattern_ptr_banked - ld a,1 - ld [gbt_update_pattern_pointers],a - xor a,a ;ret 0 - ret - -gbt_ch1234_speed: - ld [gbt_speed],a - xor a,a - ld [gbt_ticks_elapsed],a - ret ;ret 0 - -;------------------------------------------------------------------------------- - -gbt_update_bank1:: - - ld de,gbt_temp_play_data - - ; each function will return in de the pointer to next byte - - call gbt_channel_1_handle - - call gbt_channel_2_handle - - call gbt_channel_3_handle - - call gbt_channel_4_handle - - ; end of channel handling - - ld hl,gbt_pan - ld a,[hl+] - or a,[hl] - inc hl - or a,[hl] - inc hl - or a,[hl] - ld [rNR51],a ; handle panning... - - ret - -;------------------------------------------------------------------------------- - -gbt_update_effects_bank1:: - - call channel1_update_effects - and a,a - call nz,channel1_refresh_registers - - call channel2_update_effects - and a,a - call nz,channel2_refresh_registers - - call channel3_update_effects - and a,a - call nz,channel3_refresh_registers - - call channel4_update_effects - and a,a - call nz,channel4_refresh_registers - - ret - -;############################################################################### diff --git a/gbtarottheme.inc b/gbtarottheme.inc deleted file mode 100644 index 5a995e8..0000000 --- a/gbtarottheme.inc +++ /dev/null @@ -1,203 +0,0 @@ -; File created by shoofle's s3m2gbt edit - -gbtarottheme_0: - db $00, $00, -db $11, $0C, -db $21, $0F, -db $31, $40, -db $22, $00, -db $23, $00, -db $24, $00, - - db $0F, $01, - - db $0F, $02, -db $11, $0C, -db $21, $0F, -db $31, $80, - - db $0F, $03, - - db $0F, $04, -db $11, $0C, -db $21, $0F, -db $31, $C0, - - db $0F, $05, - - db $0F, $06, -db $81, $FE, - - db $0F, $07, - - db $0F, $08, - - db $0F, $09, - - db $0F, $0A, - - db $0F, $0B, - - db $0F, $0C, -db $11, $0C, -db $21, $0F, -db $31, $00, - - db $0F, $0D, - - db $0F, $0E, -db $11, $0C, -db $21, $0F, -db $31, $00, - - db $0F, $0F, - - db $0F, $10, -db $11, $10, -db $21, $0F, -db $31, $40, - - db $0F, $11, - - db $0F, $12, -db $11, $10, -db $21, $0F, -db $31, $80, - - db $0F, $13, - - db $0F, $14, -db $11, $10, -db $21, $0F, -db $31, $C0, - - db $0F, $15, - - db $0F, $16, -db $81, $FE, - - db $0F, $17, - - db $0F, $18, - - db $0F, $19, - - db $0F, $1A, - - db $0F, $1B, - - db $0F, $1C, -db $11, $10, -db $21, $0F, -db $31, $00, - - db $0F, $1D, - - db $0F, $1E, -db $11, $10, -db $21, $0F, -db $31, $00, - - db $0F, $1F, - - db $0F, $20, -db $11, $12, -db $21, $0F, -db $31, $40, - - db $0F, $21, - - db $0F, $22, -db $11, $12, -db $21, $0F, -db $31, $80, - - db $0F, $23, - - db $0F, $24, -db $11, $12, -db $21, $0F, -db $31, $C0, - - db $0F, $25, - - db $0F, $26, -db $81, $FE, - - db $0F, $27, - - db $0F, $28, - - db $0F, $29, - - db $0F, $2A, - - db $0F, $2B, - - db $0F, $2C, -db $11, $12, -db $21, $0F, -db $31, $00, - - db $0F, $2D, - - db $0F, $2E, -db $11, $12, -db $21, $0F, -db $31, $00, - - db $0F, $2F, - - db $0F, $30, -db $11, $11, -db $21, $0F, -db $31, $40, - - db $0F, $31, - - db $0F, $32, -db $11, $11, -db $21, $0F, -db $31, $80, - - db $0F, $33, - - db $0F, $34, -db $11, $11, -db $21, $0F, -db $31, $C0, - - db $0F, $35, - - db $0F, $36, -db $81, $FE, - - db $0F, $37, - - db $0F, $38, - - db $0F, $39, - - db $0F, $3A, - - db $0F, $3B, - - db $0F, $3C, -db $11, $11, -db $21, $0F, -db $31, $00, - - db $0F, $3D, - - db $0F, $3E, -db $11, $11, -db $21, $0F, -db $31, $00, - - db $0F, $3F, - -gbtarottheme: - db 4 - dw gbtarottheme_0 - dw gbtarottheme_0 - dw gbtarottheme_0 diff --git a/pythonrangetest.c b/pythonrangetest.c deleted file mode 100644 index 1cad6b3..0000000 --- a/pythonrangetest.c +++ /dev/null @@ -1,217 +0,0 @@ -; s3m2gbt modified by shoofle to output rgbds-compatible asm filespythonrangetest_0: - db 0xBF,0x00,0x30,0x10,0x10,0x10, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x01,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x02,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x03,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x04,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x05,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x06,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x07,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x08,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x09,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x0A,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x0B,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x0C,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x0D,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x0E,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x0F,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x10,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x11,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x12,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x13,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x14,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x15,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x16,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x17,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x18,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x19,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x1A,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x1B,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x1C,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x1D,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x1E,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x1F,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - - -pythonrangetest_1: - db 0xBF,0x20,0x30,0x10,0x10,0x10, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x21,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x22,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x23,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x24,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x25,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x26,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x27,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x28,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x29,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x2A,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x2B,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x2C,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x2D,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x2E,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x2F,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x30,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x31,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x32,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x33,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x34,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x35,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x36,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x37,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x38,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x39,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x3A,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x3B,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x3C,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x3D,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x3E,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x3F,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - - -pythonrangetest_2: - db 0xBF,0x40,0x30,0x10,0x10,0x10, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x41,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x42,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x43,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x44,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x45,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x46,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0xBF,0x47,0x30,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - db 0x00,0x00,0x00,0x00, - - -pythonrangetest_init_state: - db 0x01,0x06,0x02,0x11,0x22,0x44,0x88,0x00, - -pythonrangetest: - db BANK(pythonrangetest_0) - dw pythonrangetest_0 - - db BANK(pythonrangetest_1) - dw pythonrangetest_1 - - db BANK(pythonrangetest_2) - dw pythonrangetest_2 - - db $00 - dw $0000 - diff --git a/pythonrangetest.inc b/pythonrangetest.inc deleted file mode 100644 index 354236b..0000000 --- a/pythonrangetest.inc +++ /dev/null @@ -1,222 +0,0 @@ -; s3m2gbt modified by shoofle to output rgbds-compatible asm files -SECTION "pythonrangetest_0", ROMX -pythonrangetest_0: - db $BF,$00,$30,$10,$10,$10, - db $00,$00,$00,$00, - db $BF,$01,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$02,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$03,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$04,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$05,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$06,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$07,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$08,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$09,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$0A,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$0B,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$0C,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$0D,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$0E,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$0F,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$10,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$11,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$12,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$13,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$14,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$15,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$16,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$17,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$18,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$19,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$1A,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$1B,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$1C,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$1D,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$1E,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$1F,$30,$00,$00,$00, - db $00,$00,$00,$00, - - -SECTION "pythonrangetest_1", ROMX -pythonrangetest_1: - db $BF,$20,$30,$10,$10,$10, - db $00,$00,$00,$00, - db $BF,$21,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$22,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$23,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$24,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$25,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$26,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$27,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$28,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$29,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$2A,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$2B,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$2C,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$2D,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$2E,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$2F,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$30,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$31,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$32,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$33,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$34,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$35,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$36,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$37,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$38,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$39,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$3A,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$3B,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$3C,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$3D,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$3E,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$3F,$30,$00,$00,$00, - db $00,$00,$00,$00, - - -SECTION "pythonrangetest_2", ROMX -pythonrangetest_2: - db $BF,$40,$30,$10,$10,$10, - db $00,$00,$00,$00, - db $BF,$41,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$42,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$43,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$44,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$45,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$46,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $BF,$47,$30,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - db $00,$00,$00,$00, - - -pythonrangetest_init_state: - db 0x01,0x06,0x02,0x11,0x22,0x44,0x88,0x00, - -SECTION "pythonrangetest", ROMX -pythonrangetest: - db BANK(pythonrangetest_0) - dw pythonrangetest_0 - - db BANK(pythonrangetest_1) - dw pythonrangetest_1 - - db BANK(pythonrangetest_2) - dw pythonrangetest_2 - - db $00 - dw $0000 - diff --git a/range_test.s3m b/range_test.s3m deleted file mode 100644 index 8ca03c0..0000000 Binary files a/range_test.s3m and /dev/null differ diff --git a/rangetest.inc b/rangetest.inc deleted file mode 100644 index dafaae6..0000000 --- a/rangetest.inc +++ /dev/null @@ -1,672 +0,0 @@ -; File created by shoofle's s3m2gbt edit - -rangetest_0: - db $00, $00, -db $11, $00, -db $21, $0F, -db $31, $40, -db $22, $00, -db $23, $00, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $01, -db $84, $00, - - db $0F, $02, -db $21, $00, - - db $0F, $03, - - db $0F, $04, -db $11, $02, -db $21, $0E, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $05, -db $84, $00, - - db $0F, $06, -db $21, $00, - - db $0F, $07, - - db $0F, $08, -db $11, $04, -db $21, $0C, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $09, -db $84, $00, - - db $0F, $0A, -db $21, $00, - - db $0F, $0B, - - db $0F, $0C, -db $11, $06, -db $21, $0A, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $0D, -db $84, $00, - - db $0F, $0E, -db $21, $09, - - db $0F, $0F, - - db $0F, $10, -db $11, $08, -db $21, $08, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $11, -db $84, $00, - - db $0F, $12, -db $21, $07, - - db $0F, $13, - - db $0F, $14, -db $11, $0A, -db $21, $06, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $15, -db $84, $00, - - db $0F, $16, -db $11, $0B, -db $21, $05, -db $31, $C0, - - db $0F, $17, - - db $0F, $18, -db $11, $0C, -db $21, $04, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $19, -db $84, $00, - - db $0F, $1A, -db $11, $0D, -db $21, $03, -db $31, $C0, - - db $0F, $1B, - - db $0F, $1C, -db $11, $0E, -db $21, $02, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $1D, -db $84, $00, - - db $0F, $1E, -db $11, $0F, -db $21, $01, -db $31, $C0, - - db $0F, $1F, - - db $0F, $20, -db $11, $10, -db $21, $00, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $21, -db $84, $00, - - db $0F, $22, -db $11, $11, -db $21, $0F, -db $31, $C0, - - db $0F, $23, - - db $0F, $24, -db $11, $12, -db $21, $0F, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $25, -db $84, $00, - - db $0F, $26, -db $11, $13, -db $21, $0F, -db $31, $C0, - - db $0F, $27, - - db $0F, $28, -db $11, $14, -db $21, $0F, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $29, -db $84, $00, - - db $0F, $2A, -db $11, $15, -db $21, $0F, -db $31, $C0, - - db $0F, $2B, - - db $0F, $2C, -db $11, $16, -db $21, $0F, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $2D, -db $84, $00, - - db $0F, $2E, -db $11, $17, -db $21, $0F, -db $31, $C0, - - db $0F, $2F, - - db $0F, $30, -db $11, $18, -db $21, $0F, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $31, -db $84, $00, - - db $0F, $32, -db $11, $19, -db $21, $0F, -db $31, $C0, - - db $0F, $33, - - db $0F, $34, -db $11, $1A, -db $21, $0F, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $35, -db $84, $00, - - db $0F, $36, -db $11, $1B, -db $21, $0F, -db $31, $C0, - - db $0F, $37, - - db $0F, $38, -db $11, $1C, -db $21, $0F, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $39, -db $84, $00, - - db $0F, $3A, -db $11, $1D, -db $21, $0F, -db $31, $C0, - - db $0F, $3B, - - db $0F, $3C, -db $11, $1E, -db $21, $0F, -db $31, $C0, -db $14, $18, -db $24, $0F, -db $34, $00, - - db $0F, $3D, -db $84, $00, - - db $0F, $3E, -db $11, $1F, -db $21, $0F, -db $31, $C0, - - db $0F, $3F, - -rangetest_1: - db $00, $00, -db $11, $20, -db $21, $0F, -db $31, $C0, -db $22, $00, -db $23, $00, -db $24, $00, - - db $0F, $01, - - db $0F, $02, -db $11, $21, -db $21, $0F, -db $31, $C0, - - db $0F, $03, - - db $0F, $04, -db $11, $22, -db $21, $0F, -db $31, $C0, - - db $0F, $05, - - db $0F, $06, -db $11, $23, -db $21, $0F, -db $31, $C0, - - db $0F, $07, - - db $0F, $08, -db $11, $24, -db $21, $0F, -db $31, $C0, - - db $0F, $09, - - db $0F, $0A, -db $11, $25, -db $21, $0F, -db $31, $C0, - - db $0F, $0B, - - db $0F, $0C, -db $11, $26, -db $21, $0F, -db $31, $C0, - - db $0F, $0D, - - db $0F, $0E, -db $11, $27, -db $21, $0F, -db $31, $C0, - - db $0F, $0F, - - db $0F, $10, -db $11, $28, -db $21, $0F, -db $31, $C0, - - db $0F, $11, - - db $0F, $12, -db $11, $29, -db $21, $0F, -db $31, $C0, - - db $0F, $13, - - db $0F, $14, -db $11, $2A, -db $21, $0F, -db $31, $C0, - - db $0F, $15, - - db $0F, $16, -db $11, $2B, -db $21, $0F, -db $31, $C0, - - db $0F, $17, - - db $0F, $18, -db $11, $2C, -db $21, $0F, -db $31, $C0, - - db $0F, $19, - - db $0F, $1A, -db $11, $2D, -db $21, $0F, -db $31, $C0, - - db $0F, $1B, - - db $0F, $1C, -db $11, $2E, -db $21, $0F, -db $31, $C0, - - db $0F, $1D, - - db $0F, $1E, -db $11, $2F, -db $21, $0F, -db $31, $C0, - - db $0F, $1F, - - db $0F, $20, -db $11, $30, -db $21, $0F, -db $31, $C0, - - db $0F, $21, - - db $0F, $22, -db $11, $31, -db $21, $0F, -db $31, $C0, - - db $0F, $23, - - db $0F, $24, -db $11, $32, -db $21, $0F, -db $31, $C0, - - db $0F, $25, - - db $0F, $26, -db $11, $33, -db $21, $0F, -db $31, $C0, - - db $0F, $27, - - db $0F, $28, -db $11, $34, -db $21, $0F, -db $31, $C0, - - db $0F, $29, - - db $0F, $2A, -db $11, $35, -db $21, $0F, -db $31, $C0, - - db $0F, $2B, - - db $0F, $2C, -db $11, $36, -db $21, $0F, -db $31, $C0, - - db $0F, $2D, - - db $0F, $2E, -db $11, $37, -db $21, $0F, -db $31, $C0, - - db $0F, $2F, - - db $0F, $30, -db $11, $38, -db $21, $0F, -db $31, $C0, - - db $0F, $31, - - db $0F, $32, -db $11, $39, -db $21, $0F, -db $31, $C0, - - db $0F, $33, - - db $0F, $34, -db $11, $3A, -db $21, $0F, -db $31, $C0, - - db $0F, $35, - - db $0F, $36, -db $11, $3B, -db $21, $0F, -db $31, $C0, - - db $0F, $37, - - db $0F, $38, -db $11, $3C, -db $21, $0F, -db $31, $C0, - - db $0F, $39, - - db $0F, $3A, -db $11, $3D, -db $21, $0F, -db $31, $C0, - - db $0F, $3B, - - db $0F, $3C, -db $11, $3E, -db $21, $0F, -db $31, $C0, - - db $0F, $3D, - - db $0F, $3E, -db $11, $3F, -db $21, $0F, -db $31, $C0, - - db $0F, $3F, - -rangetest_2: - db $00, $00, -db $11, $40, -db $21, $0B, -db $31, $80, -db $22, $00, -db $23, $00, -db $24, $00, - - db $0F, $01, - - db $0F, $02, -db $11, $41, -db $21, $0B, -db $31, $80, - - db $0F, $03, - - db $0F, $04, -db $11, $42, -db $21, $0B, -db $31, $80, - - db $0F, $05, - - db $0F, $06, -db $11, $43, -db $21, $0B, -db $31, $80, - - db $0F, $07, - - db $0F, $08, -db $11, $44, -db $21, $0B, -db $31, $80, - - db $0F, $09, - - db $0F, $0A, -db $11, $45, -db $21, $0B, -db $31, $80, - - db $0F, $0B, - - db $0F, $0C, -db $11, $46, -db $21, $0B, -db $31, $80, - - db $0F, $0D, - - db $0F, $0E, -db $11, $47, -db $21, $0B, -db $31, $80, - - db $0F, $0F, - - db $0F, $10, - - db $0F, $11, - - db $0F, $12, - - db $0F, $13, - - db $0F, $14, - - db $0F, $15, - - db $0F, $16, - - db $0F, $17, - - db $0F, $18, - - db $0F, $19, - - db $0F, $1A, - - db $0F, $1B, - - db $0F, $1C, - - db $0F, $1D, - - db $0F, $1E, - - db $0F, $1F, - - db $0F, $20, - - db $0F, $21, - - db $0F, $22, - - db $0F, $23, - - db $0F, $24, - - db $0F, $25, - - db $0F, $26, - - db $0F, $27, - - db $0F, $28, - - db $0F, $29, - - db $0F, $2A, - - db $0F, $2B, - - db $0F, $2C, - - db $0F, $2D, - - db $0F, $2E, - - db $0F, $2F, - - db $0F, $30, - - db $0F, $31, - - db $0F, $32, - - db $0F, $33, - - db $0F, $34, - - db $0F, $35, - - db $0F, $36, - - db $0F, $37, - - db $0F, $38, - - db $0F, $39, - - db $0F, $3A, - - db $0F, $3B, - - db $0F, $3C, - - db $0F, $3D, - - db $0F, $3E, - - db $0F, $3F, - -rangetest: - db 4 - dw rangetest_0 - dw rangetest_1 - dw rangetest_2 diff --git a/rangetest.mod b/rangetest.mod deleted file mode 100644 index 680be11..0000000 Binary files a/rangetest.mod and /dev/null differ diff --git a/rangetest.s3m b/rangetest.s3m deleted file mode 100644 index a3d188d..0000000 Binary files a/rangetest.s3m and /dev/null differ diff --git a/s3m2gbt.py b/s3m2gbt.py deleted file mode 100755 index 0ba7e82..0000000 --- a/s3m2gbt.py +++ /dev/null @@ -1,779 +0,0 @@ -#!/usr/bin/env python3 - -# s3m2gbt v4.4.1 (Part of GBT Player) -# -# SPDX-License-Identifier: MIT -# -# Copyright (c) 2022 Antonio Niño Díaz - -class RowConversionError(Exception): - def __init__(self, message, pattern = -1, row = -1, channel = -1): - self.pattern = pattern - self.row = row - self.channel = channel + 1 - self.message = message - - def __str__(self): - return f"Pattern {self.pattern} | Row {self.row} | Channel {self.channel} | {self.message}" - -class S3MFormatError(Exception): - pass - -class S3MFormatReader: - - def read_u8(self): - offset = self.read_ptr - self.read_ptr += 1 - return int(self.data[offset]) - - def read_u16(self): - offset = self.read_ptr - self.read_ptr += 2 - return int((self.data[offset + 1] << 8) | self.data[offset]) - - def read_memseg(self): - offset = self.read_ptr - self.read_ptr += 3 - part1 = self.data[offset + 0] - part2 = self.data[offset + 1] - part3 = self.data[offset + 2] - return int((part1 << 16) | (part3 << 8) | part2) - - def read_string(self, size): - offset = self.read_ptr - self.read_ptr += size - return self.data[offset:offset+size] - -class S3MFileInstrument(S3MFormatReader): - - def __init__(self, data, offset): - self.data = data - self.read_ptr = offset - - instrument_type = self.read_u8() - if instrument_type != 1: - self.exists = False - return - self.exists = True - - self.dos_filename = self.read_string(12).decode("utf-8") - - self.sample_data_offset = self.read_memseg() * 16 - - self.length = self.read_u16() - self.length |= self.read_u16() << 16 - - self.read_ptr += 4 + 4 # Skip loop begin and loop end - - self.default_volume = self.read_u8() - - self.read_ptr = offset + 0x30 - - self.sample_name = self.read_string(28).decode("utf-8") - - if self.read_string(4) != b'SCRS': - raise S3MFormatError("Invalid magic string in instrument") - - start = self.sample_data_offset - end = start + self.length - self.sample_data = self.data[start:end] - -class S3MFilePatternCell(): - - def __init__(self, header, channel, note, instrument, volume, - effect, effect_args): - - if header == 0: - self.empty = True - return - - self.empty = False - - self.channel = channel - - if (note != None) or (instrument != None): - self.has_note_and_instrument = True - self.note = note - self.instrument = instrument - else: - self.has_note_and_instrument = False - - if volume != None: - self.has_volume = True - self.volume = volume - else: - self.has_volume = False - - if (effect != None) or (effect_args != None): - self.has_effect = True - self.effect = effect - self.effect_args = effect_args - else: - self.has_effect = False - -class S3MFilePattern(S3MFormatReader): - - def __init__(self, data, offset): - - # Check if we have asked to generate an empty pattern - if data == None: - cell = S3MFilePatternCell(0, 0, 0, 0, 0, 0, 0) - self.cells = [] - for i in range(0, 64): - self.cells.append(cell) - return - - self.data = data - self.read_ptr = offset - - length = self.read_u16() - 2 - - self.cells = [] - - while length > 0: - header = self.read_u8() - length -= 1 - - channel = header & 31 - - note = None - instrument = None - volume = None - effect = None - effect_args = None - - if (header & (1 << 5)) != 0: # Has note and instrument - note = self.read_u8() - instrument = self.read_u8() - length -= 2 - - if (header & (1 << 6)) != 0: # Has volume - volume = self.read_u8() - length -= 1 - - if (header & (1 << 7)) != 0: # Has effect - effect = self.read_u8() - effect_args = self.read_u8() - length -= 2 - - cell = S3MFilePatternCell(header, channel, note, instrument, volume, - effect, effect_args) - self.cells.append(cell) - -class S3MFile(S3MFormatReader): - - def __init__(self, data): - - # Save data for now - - self.data = data - self.read_ptr = 0 - - self.name = self.read_string(28).decode("utf-8") - print(f"Song Name: '{self.name}'") - - self.read_ptr += 1 + 1 + 2 # Ignore fields - - self.song_length = self.read_u16() - print(f"Song Length: {self.song_length}") - - self.num_instruments = self.read_u16() - self.num_patterns = self.read_u16() - - self.read_ptr += 6 # Ignore fields - - if self.read_string(4) != b'SCRM': - raise S3MFormatError("Invalid magic string in file") - - self.global_volume = self.read_u8() - - self.initial_speed = self.read_u8() - - if self.read_u8() != 150: - raise S3MFormatError("Invalid tempo: It must be 150") - - self.master_volume = self.read_u8() & 0b00111111 # master volume - - self.read_ptr += 1 # Ignore ultraclick removal - - # Save this for later - has_custom_pan = False - if self.read_u8() == 252: - has_custom_pan = True - - self.read_ptr = 0x40 # jump forward to uint8[32] channelSettings - channel_settings = self.read_string(4) - if channel_settings[0] >= 16 or channel_settings[1] >= 16 or \ - channel_settings[2] >= 16 or channel_settings[3] >= 16: - raise S3MFormatError("Invalid channel settings: Channels 0-3 must be enabled") - - # Read orders - - self.read_ptr = 0x60 # jump forward to uint8[orderCount] orderList - - self.song_orders = self.read_string(self.song_length) - if self.song_length % 2 == 1: - self.read_ptr += 1 # Align to 2 - - # Read instrument parapointers - - self.instrument_offsets = [None] * self.num_instruments - for i in range(0, self.num_instruments): - self.instrument_offsets[i] = self.read_u16() * 16 - - # Read pattern parapointers - - self.pattern_offsets = [None] * self.num_patterns - for i in range(0, self.num_patterns): - self.pattern_offsets[i] = self.read_u16() * 16 - - # Read default panning - - if has_custom_pan: - self.channel_pan = [b & 0xF for b in self.read_string(4)] - else: - self.channel_pan = [8, 8, 8, 8] - - # Load instruments - - self.instruments = [None] * self.num_instruments - for i in range(0, len(self.instrument_offsets)): - offset = self.instrument_offsets[i] - if offset != 0: - instr = S3MFileInstrument(self.data, offset) - if instr.exists: - self.instruments[i] = instr - - # Load patterns - - self.patterns = [None] * self.num_patterns - for i in range(0, len(self.pattern_offsets)): - offset = self.pattern_offsets[i] - if offset != 0: - self.patterns[i] = S3MFilePattern(self.data, offset) - else: - # A NULL pointer means that the pattern is empty - self.patterns[i] = S3MFilePattern(None, 0) - - # The file data is no longer needed - - self.data = [] - -# Channels 1, 2, 4 -def s3m_volume_to_gb(s3m_vol): # this is identical to mod files. - if s3m_vol >= 64: - return 15 - else: - return s3m_vol >> 2; - -# Channel 3 -def s3m_volume_to_gb_ch3(s3m_vol): # also identicll to mod files - vol = s3m_volume_to_gb(s3m_vol) - - if vol >= 0 and vol <= 3: - return 0 # 0% - elif vol >= 4 and vol <= 6: - return 3 # 25% - elif vol >= 7 and vol <= 9: - return 2 # 50% - elif vol >= 10 and vol <= 12: - return 4 # 75% - elif vol >= 13 and vol <= 15: - return 1 # 100% - else: - return 0 - -def s3m_note_to_gb(note): - # Note cut with ^^ - if note == 0xFE: - return 0xFE - - # Note off and ^^ note cut should be handled before reaching this point - assert note <= 0x7F - - note -= 32 - if note < 0: - raise RowConversionError("Note too low") - elif note > 32 + 16 * 6: - raise RowConversionError("Note too high") - - note = (note & 0xF) + ((note & 0xF0) >> 4) * 12 - return note - -def s3m_pan_to_gb(pan, channel): - left = False - right = False - - if pan >= 0 and pan <= 3: - left = True - elif pan >= 4 and pan <= 11: - left = True - right = True - elif pan >= 12 and pan <= 15: - right = True - - val = 0 - if left: - val |= 1 << (3 + channel) - if right: - val |= 1 << (channel - 1) - - return val - -EFFECT_PAN = 0 -EFFECT_ARPEGGIO = 1 -EFFECT_NOTE_CUT = 2 -EFFECT_VIBRATO = 3 -EFFECT_VOLUME_SLIDE = 4 -EFFECT_PATTERN_JUMP = 8 -EFFECT_BREAK_SET_STEP = 9 -EFFECT_SPEED = 10 -EFFECT_EVENT = 15 - -# Returns (converted_num, converted_params) if there was a valid effect. If -# there is none, it returns (None, None). Note that it is needed to pass the -# channel to this function because some effects behave differently depending on -# the channel (like panning). -def effect_s3m_to_gb(channel, effectnum, effectparams): - - if effectnum == 'A': # Set Speed. compatible - if effectparams > 0x1F: - raise RowConversionError("Unsupported BPM speed effect") - - if effectparams == 0: - raise RowConversionError("Speed must not be zero") - - return (EFFECT_SPEED, effectparams) - - if effectnum == 'B': # Pattern jump compatible - # TODO: Fail if this jumps out of bounds - return (EFFECT_PATTERN_JUMP, effectparams) - - elif effectnum == 'C': # Break + Set row compatiblle - # Effect value is BCD, convert to integer - val = (((effectparams & 0xF0) >> 4) * 10) + (effectparams & 0x0F) - return (EFFECT_BREAK_SET_STEP, val) - - elif effectnum == 'D': # Volume Slide not present in .mod - if channel == 3: - raise RowConversionError("Volume slide not supported in channel 3") - - if effectparams == 0: - # Ignore volume slide commands that just continue the effect, - # they are only needed for the S3M player. - return (None, None) - - upper = (effectparams >> 4) & 0xF - lower = effectparams & 0xF - - if upper == 0xF or lower == 0xF: - raise RowConversionError("Fine volume slide not supported") - - elif lower == 0: # Volume goes up - params = 1 << 3 # Increase - delay = 7 - upper + 1 - if delay <= 0: - raise RowConversionError("Volume slide too steep") - params |= delay - return (EFFECT_VOLUME_SLIDE, params) - elif upper == 0: # Volume goes down - params = 0 << 3 # Decrease - delay = 7 - lower + 1 - if delay <= 0: - raise RowConversionError("Volume slide too steep") - params = delay - return (EFFECT_VOLUME_SLIDE, params) - else: - raise RowConversionError("Invalid volume slide arguments") - - return (EFFECT_VOLUME_SLIDE, effectparams) - - elif effectnum == 'H': # Vibrato - return (EFFECT_VIBRATO, effectparams) - - elif effectnum == 'J': # Arpeggio - return (EFFECT_ARPEGGIO, effectparams) - - elif effectnum == 'S': # This effect is subdivided into many - - subeffectnum = (effectparams & 0xF0) >> 4 - subeffectparams = effectparams & 0x0F - - if subeffectnum == 0x8: # Pan position compatible - val = s3m_pan_to_gb(subeffectparams, channel) - return (EFFECT_PAN, val) - - elif subeffectnum == 0xC: # Notecut compatible - print(f"fofund a note cut, {effectnum}, {subeffectnum}, {subeffectparams}") - return (EFFECT_NOTE_CUT, subeffectparams) - - elif subeffectnum == 0xF: # Funkrepeat? Set active macro? not present in .mod - # This effect is either unused, or it's the "set active macro" - # command, which doesn't have any effect if you don't use the macro - # afterwards. It can safely be overloaded for event callbacks. - return (EFFECT_EVENT, subeffectparams) - - raise RowConversionError(f"Unsupported effect: {effectnum}{effectparams:02X}") - -HAS_VOLUME = 1 << 5 # changing these to be compatible with old gbt -HAS_DRUM_EFFECT = 1 << 6 -HAS_EFFECT = 1 << 7 -HAS_NOTE = 1 << 7 -HAS_KIT = 1 << 7 - -def convert_channel(channel, note_index, samplenum, volume, effectnum, effectparams): - #print(f"{channel}: {note_index}, using {samplenum} @ volume {volume}") - if channel == 4: - return convert_channel4(note_index, samplenum, volume, effectnum, effectparams) - - command = [ 0, 0, 0 ] # NOP - command_len = 1 - - if channel == 3: - shifted_instrument = (samplenum) << 7 - converted_volume = s3m_volume_to_gb_ch3(volume) - else: - shifted_instrument = (samplenum & 3) << 4 - converted_volume = s3m_volume_to_gb(volume) - - # Check if it's needed to add a note - if note_index != -1: - command[0] = HAS_NOTE | note_index - command[1] = shifted_instrument | converted_volume - command_len = 2 - - if effectnum is not None: - [num, params] = effect_s3m_to_gb(channel, effectnum, effectparams) - command[1] = HAS_EFFECT | shifted_instrument | num - command[2] = params - command_len = 3 - else: - command[0] = HAS_VOLUME | converted_volume - command_len = 1 - - if effectnum is not None: - [num, params] = effect_s3m_to_gb(channel, effectnum, effectparams) - command[1] = HAS_EFFECT | shifted_instrument | num - command[2] = params - command_len = 3 - - return command[:command_len] - - -def convert_channel4(note_index, samplenum, volume, effectnum, effectparams): - command = [ 0, 0, 0 ] # NOP - command_len = 1 - - #print(f"we found a note with index {note_index}") - # Note cut using ^^ as note - if note_index == 169 or note_index == -1: - if samplenum > 0: - # This limitation is only for channel 4. It should never happen in a - # regular song. - raise("Note cut + Sample in same row: Not supported in channel 4") - samplenum = 0xFE - - if note_index != 169 and note_index != -1 and samplenum > 0: - command[0] = HAS_KIT | (samplenum & 0xF) - command[1] = s3m_volume_to_gb(volume) & 0xF - command_len = 2 - else: - if note_index == 169: - command[0] = HAS_DRUM_EFFECT | EFFECT_NOTE_CUT - command[1] = 1 # 0 ticks - command_len = 2 - elif effectnum is not None: - [num, params] = effect_s3m_to_gb(4, effectnum, effectparams) - - if num is not None: - command[0] = HAS_DRUM_EFFECT | (num & 0x0F) - command[1] = (params & 0xFF) | 1 - command_len = 2 - elif volume > -1: - #command[0] = HAS_VOLUME | (s3m_volume_to_gb(volume) & 0xF) - command[0] = 0 - command_len = 1 - - return command[:command_len] - -STARTUP_CMD_DONE = 0 -STARTUP_CMD_SPEED = 1 -STARTUP_CMD_PANING = 2 -STARTUP_CMD_CHANNEL3_INSTRUMENT = 3 - -SAMPLE_64_ENTRIES = 1 << 7 - -def initial_state_array(speed, panning_array, instruments): - array = [] - - # Initial speed - # ------------- - - array.extend([STARTUP_CMD_SPEED, speed]) - - # Initial panning - # --------------- - - array.extend([STARTUP_CMD_PANING]) - array.extend(panning_array) - - # Channel 3 instruments - # --------------------- - - if instruments is not None: - print("Exporting instruments...") - count = 0 - for inst in instruments: - # In the tracker, instruments start at index 1, but they start at - # index 0 in the S3M file. - count += 1 - - # Only handle instruments assigned to channel 3 - if count < 8 or count > 15: - continue - - name = inst.sample_name - - size = inst.length - if size != 32 and size != 64: - raise S3MFormatError(f"Sample '{name}': Invalid sample length: {size}") - else: - flags = count - 8 # The low bits are the instrument index - if size == 64: - flags |= SAMPLE_64_ENTRIES - - array.extend([STARTUP_CMD_CHANNEL3_INSTRUMENT, flags]) - - # Convert from 8 bit to 4 bit - for i in range(0, size, 2): - sample_hi = inst.sample_data[i + 0] >> 4 - sample_lo = inst.sample_data[i + 1] >> 4 - value = (sample_hi << 4) | sample_lo - array.extend([value]) - - # End commands - # ------------ - - array.extend([STARTUP_CMD_DONE]) - - return array - -def convert_file(module_path, song_name, output_path, export_instruments): - - with open(module_path, "rb") as file: - file_byte_array = bytearray(file.read()) - - s3m = S3MFile(file_byte_array) - - if output_path == None: - output_path = song_name + ".inc" - - with open(output_path, "w") as fileout: - - fileout.write("; s3m2gbt modified by shoofle to output rgbds-compatible asm files\n") - - # Export patterns - # --------------- - - print(f"Exporting patterns...") - - pattern = -1 - for p in s3m.patterns: - pattern += 1 - - # Check if pattern is actually used in the order list. If it isn't - # used, don't export it. - if pattern not in s3m.song_orders: - print(f"Pattern {pattern} not exported: Not in the order list") - continue - - fileout.write(f"SECTION \"{song_name}_{pattern}\", ROMX\n") - fileout.write(f"{song_name}_{pattern}:\n") - - row = 0 - - cmd1 = [0] - cmd2 = [0] - cmd3 = [0] - cmd4 = [0] - - for c in p.cells: - - # If an end of row marker is reached, print the previous row. - # Trust that the S3M file is generated in a valid way and it - # doesn't have markers at weird positions, and that there is one - # marker right at the end of each pattern. - if c.empty: - - # Write row - fileout.write(" db ") - - cmd = cmd1 + cmd2 + cmd3 + cmd4 - for b in cmd: - if b == -1: fileout.write(f"$FF, ") - else: fileout.write(f"${b:02X},") - - fileout.write("\n") - - row = row + 1 - - # Clear commands - cmd1 = [0] - cmd2 = [0] - cmd3 = [0] - cmd4 = [0] - - # Next iteration - continue - - volume = -1 - if c.has_volume: - volume = c.volume - - note = -1 - instrument = 0 - if c.has_note_and_instrument: - note = c.note - 0b0010_0001 # note indices should start from 0=C3 - note = note + 1 # s3m note values go 00..0A, 0F, 10..1A, 1F, etc. - note = (note // 16) * 12 + (note % 16) #these expressions compensate for it. - note = note - 1 - instrument = c.instrument - - # Rows with note and instrument but no volume use the - # default volume of the sample. - if instrument > 0 and volume == -1: - this_instr = s3m.instruments[instrument - 1] - volume = this_instr.default_volume - - effectnum = None - effectparams = None - if c.has_effect: - # Convert type to ASCII to match the documentation - effectnum = chr(c.effect + ord('A') - 1) - effectparams = c.effect_args - - channel = c.channel + 1 - - try: - if channel == 1: - cmd1 = convert_channel(channel, note, instrument, volume, effectnum, effectparams) - elif channel == 2: - cmd2 = convert_channel(channel, note, instrument, volume, effectnum, effectparams) - elif channel == 3: - cmd3 = convert_channel(channel, note, instrument, volume, effectnum, effectparams) - elif channel == 4: - cmd4 = convert_channel(channel, note, instrument, volume, effectnum, effectparams) - else: - raise S3MFormatError(f"Too many channels: {channel}") - except RowConversionError as e: - e.row = row - e.pattern = pattern - e.channel = channel - raise e - - fileout.write("\n") - fileout.write("\n") - - # Export initial state - # -------------------- - - print(f"Exporting initial state...") - - fileout.write(f"{song_name}_init_state:\n") - - default_pan = [8, 8, 8, 8] - for i in range(0, 4): - default_pan[i] = s3m.channel_pan[i] - - gb_default_pan = [ - s3m_pan_to_gb(default_pan[0], 1), - s3m_pan_to_gb(default_pan[1], 2), - s3m_pan_to_gb(default_pan[2], 3), - s3m_pan_to_gb(default_pan[3], 4) - ] - - instr = None - if export_instruments: - instr = s3m.instruments - - state_array = initial_state_array(s3m.initial_speed, gb_default_pan, instr) - - # Write rows of 8 bytes until the end of the array - while True: - left = len(state_array) - - write = [] - if left == 0: - break - elif left <= 8: - write = state_array - state_array = [] - else: - write = state_array[0:8] - state_array = state_array[8:] - - fileout.write(" db ") - for s in write: - fileout.write(f"0x{s:02X},") - fileout.write("\n") - - fileout.write("\n") - - # Export orders - # ------------- - - print(f"Exporting orders...") - - fileout.write(f"SECTION \"{song_name}\", ROMX\n") - fileout.write(f"{song_name}:\n") - - #fileout.write(f" {song_name}_init_state,") - #fileout.write("\n") - - for o in s3m.song_orders: - pattern = int(o) - if pattern >= s3m.num_patterns: - # TODO: Warn if the pattern goes over the limit? - continue - fileout.write(f" db BANK({song_name}_{pattern})\n") - fileout.write(f" dw {song_name}_{pattern}\n") - fileout.write("\n") - - fileout.write(" db $00\n") - fileout.write(" dw $0000\n") - fileout.write("\n") - -if __name__ == "__main__": - - import argparse - import sys - - print("s3m2gbt v4.4.1 (part of GBT Player)") - print("Copyright (c) 2022 Antonio Niño Díaz ") - print("All rights reserved") - print("") - - parser = argparse.ArgumentParser(description='Convert S3M files into GBT format.') - parser.add_argument("--input", default=None, required=True, - help="input file") - parser.add_argument("--name", default=None, required=True, - help="output song name") - parser.add_argument("--output", default=None, required=False, - help="output file") - parser.add_argument("--instruments", default=False, required=False, - action='store_true', help="export channel 3 instruments") - - args = parser.parse_args() - - try: - convert_file(args.input, args.name, args.output, args.instruments) - except RowConversionError as e: - print("ERROR: " + str(e)) - sys.exit(1) - except S3MFormatError as e: - print("ERROR: Invalid S3M file: " + str(e)) - sys.exit(1) - - print("Done!") - - sys.exit(0)