Skip to content

Commit

Permalink
Moved main demo loop into beebtracker module
Browse files Browse the repository at this point in the history
  • Loading branch information
simondotm committed Jun 26, 2016
1 parent 1c9710b commit 0239f0d
Show file tree
Hide file tree
Showing 2 changed files with 283 additions and 262 deletions.
282 changes: 282 additions & 0 deletions beebtracker.s.6502
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,288 @@




.tracker_main
{
\\ Debounce
LDA #&FF
STA menu_key_held

\\ Load first file in our list
LDA #0
STA file_no


\\ Intro screen goes here \\


\\ ***** Loading state ***** \\

.loading_state
{
\\ Clear screen
LDA #12: JSR oswrch
JSR teletexel_init

\\ Init scrolltext with loading message
LDA #LO(load_message):LDX #HI(load_message)
LDY #11:JSR init_scr

\\ Start our event driven fx
ldx #LO(load_eventv)
ldy #HI(load_eventv)
JSR start_eventv

\\ Blocking file load
JSR load_file_from_table
PHA ; store return value

\\ Kill our event driven fx
JSR stop_eventv

\\ Returned error?
PLA
BEQ no_error

\\ Handle error (exit)
JMP return

.no_error
}

\\ ***** Demo (Tracker) state ***** \\

\\ Initialise demo state
JSR init_demo

.enter_demo_state

\\ Technically should populate the tracker display with genuine music data here!
\\ But at 20ms per line it fills up with data in a 140ms so is hardly noticable...

\\ Demo loop
.demo_loop
{
\\ Check for pressed keys
LDA #121
LDX #&10
JSR osbyte

\\ Still holding same key
CPX menu_key_held
BEQ no_key_pressed

\\ Remember current key
STX menu_key_held

\\ Any key pressed?
CPX #&FF
BEQ no_key_pressed

\\ Check escape
CPX #MENU_key_toggle
BEQ enter_menu_state

.no_key_pressed

\\ Poll the music player
LDA player_ended
BNE song_ended

\\ Wait for vsync - NO LONGER WAITING FOR VSYNC
;LDA #19
;JSR osbyte

\\ Actually sync to audio instead
LDA player_counter
.wait_for_audio_sync
CMP player_counter
BEQ wait_for_audio_sync

\\ At this point we know audio data has just been sent to SN
\\ So all of our vars from the player are fresh
\\ Use these to render our demo FX (before next vsync!)
\\ May still want to do something clever to avoid flicker

\\ Poll tracker
JSR poll_tracker

\\ Poll our VU effects
LDA #&FF ; we do want beat bars
JSR poll_fx

\\ Update scrolltext
JSR poll_scr

\\ Loop
JMP demo_loop

.song_ended

\\ Deinitialise demo state
JSR deinit_demo

\\ Increment file in table
LDX file_no
INX
CPX #NUM_vgm_files
BCC next_file
LDX #0
.next_file
STX file_no

\\ Automatically load next file
JMP loading_state
}

\\ ***** Menu state ***** \\

.enter_menu_state

\\ Initialise menu state

JSR init_menu
JSR menu_populate

\\ Menu loop
.menu_loop
{
\\ Check for pressed keys
LDA #121
LDX #&10
JSR osbyte

\\ Still holding same key
CPX menu_key_held
BEQ no_key_pressed

\\ Remember current key
STX menu_key_held

\\ Any key pressed?
CPX #&FF
BEQ no_key_pressed

\\ Check escape
CPX #MENU_key_toggle
BNE not_escape

\\ Handle toggle key
\\ Revert file no
LDA menu_old_file
STA file_no

\\ Cancel menu
.cancel_menu
JSR deinit_menu
JMP enter_demo_state

.not_escape
CPX #MENU_key_up
BNE not_up

\\ Handle up key
\\ Decrement file_no no lower than 0
LDA file_no
BEQ not_up
DEC file_no

\\ Update our menu on screen
JSR menu_populate
JMP no_key_pressed

.not_up
CPX #MENU_key_down
BNE not_down

\\ Handle down
\\ Increment file_no up to MAX
LDA file_no
IF COMPILE_OPTION_EXIT
CMP #NUM_vgm_files
ELSE
CMP #NUM_vgm_files - 1
ENDIF
BEQ not_down
INC file_no

\\ Update our menu on screen
JSR menu_populate
JMP no_key_pressed

.not_down
CPX #MENU_key_select
BNE not_select

\\ Handle select key
\\ Check if we're on the same track
LDA file_no
CMP menu_old_file
BEQ cancel_menu

\\ Deinit the menu
JSR deinit_menu

\\ Deinit the demo
JSR deinit_demo

\\ Either file load or exit
LDA file_no
CMP #NUM_vgm_files
BEQ exit_app

\\ Load new file
JMP loading_state

.not_select
.no_key_pressed

\\ If track has ended just keep menu around until user action
LDA player_ended
BEQ sync_to_audio

\\ If no audio then sync to vsync instead!
LDA #19
JSR osbyte
BNE skip_audio_sync

\\ Sync to audio
.sync_to_audio
LDA player_counter
.wait_for_audio_sync
CMP player_counter
BEQ wait_for_audio_sync

.skip_audio_sync

\\ Poll our VU effects
LDA #0 ; we don't want beat bars
JSR poll_fx

\\ Update scrolltext
JSR poll_scr

\\ Loop
JMP menu_loop

.exit_app
}


.return
RTS


}









\ ******************************************************************
\ * Menu state routines
\ ******************************************************************
Expand Down
Loading

0 comments on commit 0239f0d

Please sign in to comment.