2009-01-25 14:27:24 +00:00
|
|
|
|
2009-03-26 03:17:47 +00:00
|
|
|
;REQUIRES KEYCODES TO BE DEFINED
|
|
|
|
|
2009-01-31 13:56:41 +00:00
|
|
|
OPTIONS_PER_PAGE = $10
|
2009-01-25 14:27:24 +00:00
|
|
|
.bss
|
|
|
|
|
2009-01-31 13:56:41 +00:00
|
|
|
number_of_options: .res 2
|
|
|
|
current_option: .res 2
|
|
|
|
temp_option_counter: .res 2
|
2009-01-25 14:27:24 +00:00
|
|
|
|
2009-01-31 13:56:41 +00:00
|
|
|
first_option_this_page: .res 2
|
2009-01-25 14:27:24 +00:00
|
|
|
options_shown_this_page: .res 1
|
2009-01-31 13:56:41 +00:00
|
|
|
options_table_pointer: .res 2
|
|
|
|
jump_to_prefix: .res 1
|
2009-02-01 10:11:21 +00:00
|
|
|
last_page_flag: .res 1
|
2009-03-08 10:18:59 +00:00
|
|
|
|
|
|
|
get_current_byte: .res 4
|
2009-10-20 10:36:09 +00:00
|
|
|
|
|
|
|
convert_to_native: .res 1
|
|
|
|
|
2009-03-08 10:18:59 +00:00
|
|
|
|
2009-01-25 14:27:24 +00:00
|
|
|
.code
|
|
|
|
|
|
|
|
|
2009-01-26 01:54:59 +00:00
|
|
|
;on entry, AX should point to the list of null terminated option strings to be selected from
|
2009-10-20 10:36:09 +00:00
|
|
|
;Y should be 1 if menu items are in ASCII, 0 if they are in native char format
|
2009-01-26 01:54:59 +00:00
|
|
|
;on exit, AX points to the selected string
|
2009-04-13 10:30:49 +00:00
|
|
|
;carry is set of QUIT was selected, clear otherwise
|
2009-01-25 14:27:24 +00:00
|
|
|
select_option_from_menu:
|
2009-10-20 10:36:09 +00:00
|
|
|
sty convert_to_native
|
2009-01-31 13:56:41 +00:00
|
|
|
stax options_table_pointer
|
2009-03-08 10:18:59 +00:00
|
|
|
stax get_current_byte+1
|
|
|
|
;set the 'LDA' and RTS' opcodes for the 'get current byte' subroutine, which is self-modified-code, hence must be located in RAM not ROM
|
|
|
|
lda #$ad ;opcode for LDA absolute
|
|
|
|
sta get_current_byte
|
|
|
|
lda #$60 ;opcode for RTS
|
|
|
|
sta get_current_byte+3
|
|
|
|
|
2009-01-31 13:56:41 +00:00
|
|
|
lda #0
|
|
|
|
sta current_option
|
|
|
|
sta current_option+1
|
|
|
|
sta number_of_options
|
|
|
|
sta number_of_options+1
|
|
|
|
|
|
|
|
|
|
|
|
;count the number of options. this is done by scanning till we find a double zero, incrementing the count on each single zero
|
|
|
|
@count_strings:
|
|
|
|
jsr @skip_past_next_null_byte
|
2009-01-26 01:54:59 +00:00
|
|
|
inc number_of_options
|
2009-01-31 13:56:41 +00:00
|
|
|
bne :+
|
|
|
|
inc number_of_options+1
|
|
|
|
:
|
2009-03-08 10:18:59 +00:00
|
|
|
jsr get_current_byte
|
2009-01-31 13:56:41 +00:00
|
|
|
bne @count_strings
|
|
|
|
|
|
|
|
jmp @display_first_page_of_options
|
|
|
|
|
|
|
|
@skip_past_next_null_byte:
|
2009-01-26 01:54:59 +00:00
|
|
|
jsr @move_to_next_byte
|
2009-03-08 10:18:59 +00:00
|
|
|
jsr get_current_byte
|
2009-01-31 13:56:41 +00:00
|
|
|
bne @skip_past_next_null_byte
|
2009-01-26 01:54:59 +00:00
|
|
|
jsr @move_to_next_byte
|
2009-01-31 13:56:41 +00:00
|
|
|
rts
|
2009-01-26 01:54:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
@move_to_next_byte:
|
2009-03-08 10:18:59 +00:00
|
|
|
inc get_current_byte+1
|
2009-01-26 01:54:59 +00:00
|
|
|
bne :+
|
2009-03-08 10:18:59 +00:00
|
|
|
inc get_current_byte+2
|
2009-01-26 01:54:59 +00:00
|
|
|
:
|
|
|
|
rts
|
|
|
|
|
2009-01-31 13:56:41 +00:00
|
|
|
;move the ptr along till it's pointing at the whatever is the value of current_option
|
|
|
|
@move_to_current_option:
|
|
|
|
ldax options_table_pointer
|
2009-03-08 10:18:59 +00:00
|
|
|
stax get_current_byte+1
|
2009-01-31 13:56:41 +00:00
|
|
|
lda #0
|
|
|
|
sta temp_option_counter
|
|
|
|
sta temp_option_counter+1
|
|
|
|
|
|
|
|
@skip_over_strings:
|
|
|
|
lda temp_option_counter
|
|
|
|
cmp current_option
|
|
|
|
bne @not_at_current_option
|
|
|
|
lda temp_option_counter+1
|
|
|
|
cmp current_option+1
|
|
|
|
bne @not_at_current_option
|
|
|
|
rts
|
|
|
|
@not_at_current_option:
|
|
|
|
jsr @skip_past_next_null_byte
|
|
|
|
|
|
|
|
inc temp_option_counter
|
|
|
|
bne :+
|
|
|
|
inc temp_option_counter+1
|
|
|
|
:
|
|
|
|
jmp @skip_over_strings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-01-25 14:27:24 +00:00
|
|
|
@display_first_page_of_options:
|
|
|
|
lda #0
|
|
|
|
sta first_option_this_page
|
2009-01-31 13:56:41 +00:00
|
|
|
sta first_option_this_page+1
|
|
|
|
|
2009-01-25 14:27:24 +00:00
|
|
|
|
|
|
|
@print_current_page:
|
2009-01-31 13:56:41 +00:00
|
|
|
lda first_option_this_page
|
|
|
|
sta current_option
|
|
|
|
lda first_option_this_page+1
|
|
|
|
sta current_option+1
|
2009-02-01 10:11:21 +00:00
|
|
|
lda #0
|
|
|
|
sta last_page_flag
|
2009-01-31 13:56:41 +00:00
|
|
|
|
|
|
|
jsr @move_to_current_option
|
|
|
|
|
|
|
|
|
2009-01-25 14:27:24 +00:00
|
|
|
jsr cls
|
2009-01-31 13:56:41 +00:00
|
|
|
|
2009-01-25 14:27:24 +00:00
|
|
|
ldax #select_from_following_options
|
|
|
|
jsr print
|
2009-01-26 03:22:49 +00:00
|
|
|
|
2009-02-01 03:29:44 +00:00
|
|
|
|
2009-01-26 01:54:59 +00:00
|
|
|
jsr print_cr
|
2009-01-25 14:27:24 +00:00
|
|
|
lda #0
|
|
|
|
sta options_shown_this_page
|
|
|
|
|
|
|
|
@print_loop:
|
|
|
|
|
|
|
|
lda options_shown_this_page
|
|
|
|
clc
|
|
|
|
adc #'A'
|
|
|
|
jsr print_a
|
|
|
|
|
2009-01-26 01:54:59 +00:00
|
|
|
lda #')'
|
2009-01-25 14:27:24 +00:00
|
|
|
jsr print_a
|
2009-01-26 01:54:59 +00:00
|
|
|
|
|
|
|
lda #' '
|
|
|
|
jsr print_a
|
2009-01-31 13:56:41 +00:00
|
|
|
|
2009-03-08 10:18:59 +00:00
|
|
|
lda get_current_byte+1
|
|
|
|
ldx get_current_byte+2
|
2009-10-20 10:36:09 +00:00
|
|
|
ldy convert_to_native
|
|
|
|
beq :+
|
2009-09-22 09:49:37 +00:00
|
|
|
jsr print_ascii_as_native
|
2009-10-20 10:36:09 +00:00
|
|
|
jmp @printed
|
|
|
|
:
|
|
|
|
jsr print
|
|
|
|
@printed:
|
|
|
|
|
2009-01-25 14:27:24 +00:00
|
|
|
jsr print_cr
|
2009-01-31 13:56:41 +00:00
|
|
|
jsr @skip_past_next_null_byte
|
2009-01-25 14:27:24 +00:00
|
|
|
inc current_option
|
2009-01-31 13:56:41 +00:00
|
|
|
bne :+
|
|
|
|
inc current_option+1
|
|
|
|
:
|
2009-01-25 14:27:24 +00:00
|
|
|
lda current_option
|
|
|
|
cmp number_of_options
|
2009-01-31 13:56:41 +00:00
|
|
|
bne :+
|
|
|
|
lda current_option+1
|
|
|
|
cmp number_of_options+1
|
|
|
|
bne :+
|
2009-02-01 10:11:21 +00:00
|
|
|
inc last_page_flag
|
2009-02-01 03:29:44 +00:00
|
|
|
jmp @print_instructions_and_get_keypress
|
2009-01-31 13:56:41 +00:00
|
|
|
:
|
2009-01-25 14:27:24 +00:00
|
|
|
inc options_shown_this_page
|
|
|
|
lda options_shown_this_page
|
|
|
|
cmp #OPTIONS_PER_PAGE
|
2009-02-01 03:29:44 +00:00
|
|
|
beq @print_instructions_and_get_keypress
|
2009-01-25 14:27:24 +00:00
|
|
|
jmp @print_loop
|
2009-01-31 13:56:41 +00:00
|
|
|
|
|
|
|
@jump_to:
|
|
|
|
jsr print_cr
|
|
|
|
ldax #jump_to_prompt
|
|
|
|
jsr print
|
|
|
|
lda #'?'
|
2009-03-08 10:18:59 +00:00
|
|
|
|
2009-01-31 13:56:41 +00:00
|
|
|
jsr get_key
|
2009-02-01 03:29:44 +00:00
|
|
|
ora #$80 ;set the high bit
|
2009-01-31 13:56:41 +00:00
|
|
|
|
2009-03-08 10:18:59 +00:00
|
|
|
|
2009-01-31 13:56:41 +00:00
|
|
|
sta jump_to_prefix
|
|
|
|
ldax options_table_pointer
|
2009-03-08 10:18:59 +00:00
|
|
|
stax get_current_byte+1
|
2009-01-31 13:56:41 +00:00
|
|
|
lda #0
|
2009-02-01 03:29:44 +00:00
|
|
|
sta current_option
|
|
|
|
sta current_option+1
|
2009-01-25 14:27:24 +00:00
|
|
|
|
2009-01-31 13:56:41 +00:00
|
|
|
@check_if_at_jump_to_prefix:
|
2009-03-08 10:18:59 +00:00
|
|
|
jsr get_current_byte
|
2009-02-01 03:29:44 +00:00
|
|
|
ora #$80 ;set high bit
|
2009-01-31 13:56:41 +00:00
|
|
|
cmp jump_to_prefix
|
|
|
|
beq @at_prefix
|
|
|
|
jsr @skip_past_next_null_byte
|
2009-02-01 03:29:44 +00:00
|
|
|
inc current_option
|
2009-01-31 13:56:41 +00:00
|
|
|
bne :+
|
2009-02-01 03:29:44 +00:00
|
|
|
inc current_option+1
|
|
|
|
:
|
2009-03-08 10:18:59 +00:00
|
|
|
jsr get_current_byte
|
2009-02-01 03:29:44 +00:00
|
|
|
bne @check_if_at_jump_to_prefix
|
|
|
|
jsr beep ;if we got to the end of the options table without finding the char we want, then sound a beep
|
|
|
|
jmp @jump_to_finished
|
2009-01-31 13:56:41 +00:00
|
|
|
@at_prefix:
|
2009-02-01 03:29:44 +00:00
|
|
|
lda current_option
|
|
|
|
sta first_option_this_page
|
|
|
|
lda current_option+1
|
|
|
|
sta first_option_this_page+1
|
|
|
|
@jump_to_finished:
|
2009-03-08 10:18:59 +00:00
|
|
|
jmp @print_current_page
|
2009-01-31 13:56:41 +00:00
|
|
|
|
2009-02-01 03:29:44 +00:00
|
|
|
|
|
|
|
@print_instructions_and_get_keypress:
|
|
|
|
lda number_of_options+1
|
|
|
|
bne @navigation_instructions
|
|
|
|
lda number_of_options
|
|
|
|
cmp #OPTIONS_PER_PAGE
|
|
|
|
bcc :+
|
|
|
|
@navigation_instructions:
|
|
|
|
ldax #navigation_instructions
|
|
|
|
jsr print
|
|
|
|
:
|
2009-01-25 14:27:24 +00:00
|
|
|
@get_keypress:
|
2009-01-26 01:54:59 +00:00
|
|
|
lda #'?'
|
2009-03-08 10:18:59 +00:00
|
|
|
|
2009-01-25 14:27:24 +00:00
|
|
|
jsr get_key
|
2009-03-08 10:18:59 +00:00
|
|
|
|
2009-04-15 13:28:20 +00:00
|
|
|
; jsr print_hex
|
2009-03-08 10:18:59 +00:00
|
|
|
; @fixme:
|
|
|
|
; jmp @fixme
|
|
|
|
|
2009-04-15 13:28:20 +00:00
|
|
|
cmp #KEYCODE_ABORT
|
|
|
|
beq @quit
|
2009-03-26 03:17:47 +00:00
|
|
|
cmp #KEYCODE_SLASH
|
2009-01-31 13:56:41 +00:00
|
|
|
beq @jump_to
|
2009-03-26 03:17:47 +00:00
|
|
|
cmp #KEYCODE_RIGHT
|
2009-01-25 14:27:24 +00:00
|
|
|
beq @forward_one_page
|
2009-03-26 03:17:47 +00:00
|
|
|
cmp #KEYCODE_DOWN
|
2009-01-25 14:27:24 +00:00
|
|
|
beq @forward_one_page
|
2009-03-26 03:17:47 +00:00
|
|
|
cmp #KEYCODE_UP
|
2009-01-25 14:27:24 +00:00
|
|
|
beq @back_one_page
|
2009-03-26 03:17:47 +00:00
|
|
|
cmp #KEYCODE_LEFT
|
2009-01-25 14:27:24 +00:00
|
|
|
beq @back_one_page
|
|
|
|
|
|
|
|
ora #$e0 ;make it a lower case letter with high bit set
|
|
|
|
sec
|
|
|
|
sbc #$e1
|
|
|
|
bcc @get_keypress ;if we have underflowed, it wasn't a valid option
|
2009-04-15 13:28:20 +00:00
|
|
|
|
|
|
|
|
2009-01-25 14:27:24 +00:00
|
|
|
cmp #OPTIONS_PER_PAGE-1
|
|
|
|
beq @got_valid_option
|
2009-01-26 01:54:59 +00:00
|
|
|
bpl @get_keypress ;if we have underflowed, it wasn't a valid option
|
2009-01-25 14:27:24 +00:00
|
|
|
|
2009-01-31 13:56:41 +00:00
|
|
|
|
|
|
|
@got_valid_option:
|
2009-01-25 14:27:24 +00:00
|
|
|
clc
|
|
|
|
adc first_option_this_page
|
2009-01-31 13:56:41 +00:00
|
|
|
sta current_option
|
|
|
|
lda #0
|
|
|
|
adc first_option_this_page+1
|
|
|
|
|
|
|
|
sta current_option+1
|
2009-02-01 03:29:44 +00:00
|
|
|
|
2009-01-31 13:56:41 +00:00
|
|
|
jsr @move_to_current_option
|
2009-03-08 10:18:59 +00:00
|
|
|
ldax get_current_byte+1
|
2009-04-13 10:30:49 +00:00
|
|
|
clc
|
2009-01-25 14:27:24 +00:00
|
|
|
rts
|
2009-01-26 01:54:59 +00:00
|
|
|
|
2009-04-13 10:30:49 +00:00
|
|
|
@quit:
|
|
|
|
sec
|
|
|
|
rts
|
|
|
|
|
2009-01-25 14:27:24 +00:00
|
|
|
@forward_one_page:
|
|
|
|
clc
|
2009-02-01 10:11:21 +00:00
|
|
|
lda last_page_flag
|
|
|
|
beq :+
|
|
|
|
@back_to_first_page:
|
|
|
|
jmp @display_first_page_of_options
|
|
|
|
:
|
2009-01-25 14:27:24 +00:00
|
|
|
lda first_option_this_page
|
|
|
|
adc #OPTIONS_PER_PAGE
|
|
|
|
sta first_option_this_page
|
2009-01-31 13:56:41 +00:00
|
|
|
bcc :+
|
|
|
|
inc first_option_this_page+1
|
|
|
|
:
|
|
|
|
|
2009-01-25 14:27:24 +00:00
|
|
|
jmp @print_current_page
|
|
|
|
|
|
|
|
@back_one_page:
|
|
|
|
sec
|
|
|
|
lda first_option_this_page
|
|
|
|
sbc #OPTIONS_PER_PAGE
|
|
|
|
sta first_option_this_page
|
2009-01-31 13:56:41 +00:00
|
|
|
lda first_option_this_page+1
|
|
|
|
sbc #0
|
|
|
|
sta first_option_this_page+1
|
|
|
|
bmi @show_last_page_of_options
|
|
|
|
|
2009-01-25 14:27:24 +00:00
|
|
|
jmp @print_current_page
|
|
|
|
@show_last_page_of_options:
|
|
|
|
sec
|
2009-01-31 13:56:41 +00:00
|
|
|
lda number_of_options
|
2009-01-25 14:27:24 +00:00
|
|
|
sbc #OPTIONS_PER_PAGE
|
|
|
|
sta first_option_this_page
|
2009-01-31 13:56:41 +00:00
|
|
|
lda number_of_options+1
|
|
|
|
sbc #0
|
|
|
|
sta first_option_this_page+1
|
|
|
|
bmi @back_to_first_page
|
2009-01-25 14:27:24 +00:00
|
|
|
jmp @print_current_page
|
|
|
|
|
|
|
|
.rodata
|
2009-04-15 13:28:20 +00:00
|
|
|
|
2009-01-26 03:22:49 +00:00
|
|
|
select_from_following_options: .byte "SELECT ONE OF THE FOLLOWING OPTIONS:",13,0
|
2009-02-01 03:29:44 +00:00
|
|
|
navigation_instructions: .byte 13,"ARROW KEYS NAVIGATE BETWEEN MENU PAGES",13
|
2009-04-15 13:28:20 +00:00
|
|
|
.byte "/ TO JUMP OR "
|
|
|
|
.byte KEYNAME_ABORT
|
|
|
|
.byte " TO QUIT",13,0
|
|
|
|
|
2009-01-31 13:56:41 +00:00
|
|
|
jump_to_prompt: .byte "JUMP TO:",0
|