tfv: title menu sorta working

This commit is contained in:
Vince Weaver 2020-12-30 01:00:25 -05:00
parent 8001a35f5c
commit 65135b451a
14 changed files with 422 additions and 24 deletions

View File

@ -7,8 +7,8 @@ SDL_INCLUDE= `sdl-config --cflags`
GR_SIM = ../gr-sim.a
PNG2RLE = ../../gr-utils/png2rle
ARTDIR = ../../tfv/art
ARTDIR = ../../tfv/graphics_map
TITLEDIR = ../../tfv/graphics_title
all: tfv
@ -25,7 +25,7 @@ $(PNG2RLE):
####
tfv_backgrounds.c: $(PNG2RLE) \
$(ARTDIR)/title.png \
$(TITLEDIR)/title.png \
$(ARTDIR)/map.png \
$(ARTDIR)/landing.png \
$(ARTDIR)/harfco.png \
@ -48,7 +48,7 @@ tfv_backgrounds.c: $(PNG2RLE) \
$(ARTDIR)/patriot_room.png \
$(ARTDIR)/jc_office.png \
$(ARTDIR)/puzzle.png
$(PNG2RLE) c $(ARTDIR)/title.png title_rle > tfv_backgrounds.c
$(PNG2RLE) c $(TITLEDIR)/title.png title_rle > tfv_backgrounds.c
$(PNG2RLE) c $(ARTDIR)/map.png map_rle >> tfv_backgrounds.c
$(PNG2RLE) c $(ARTDIR)/landing.png landing_rle >> tfv_backgrounds.c
$(PNG2RLE) c $(ARTDIR)/harfco.png harfco_rle >> tfv_backgrounds.c

View File

@ -1,5 +1,5 @@
unsigned char title_rle[]={
0x28, /* ysize=40 */
0x28, /* ysize=48 */
0x00,0xA0,0x19,0x20,0xAF,0x00,0x22,0xA3,0x66,0x22,0x62,
0x66,0x62,0x22,0x66,0xA3,0x22,0x66,0x26,
0x62,0x22,0x62,0x26,0x62,0x22,0xA3,0x66,
@ -44,7 +44,7 @@ unsigned char title_rle[]={
0xBB,0x00,0x0D,0xA4,0x00,0xBB,0xBB,0xAC,0x00,0x0C,
0x4C,0x44,0x55,0xAC,0x00,0xBB,0xBB,0xA6,0x00,0x20,
0x22,0x2B,0x0B,0xAE,0x00,0x05,0x05,0xA9,0x00,0x20,
0xA6,0x22,0xA3,0x20,0x22,0x22,0x02,0xA9,0x00,0xA1, };
0xA6,0x22,0xA3,0x20,0x22,0x22,0x02,0xA9,0x00,0xA0,0xA0,0xA0,0xA1, };
unsigned char map_rle[]={
0x28, /* ysize=40 */
0xA0,0x23,0x66,0x46,0x06,0xA5,0x66,0x56,0xAE,0x66,0xE6,

View File

@ -51,3 +51,4 @@ demo_rle: .byte $28 ; ysize=40
.byte $0B, $A6,$00, $90, $A5,$99, $F9, $A7,$FF, $A5,$00
.byte $20, $A6,$22, $A3,$20, $22,$22, $02, $A6,$00
.byte $A1
; cycles=21582

View File

@ -37,6 +37,7 @@ TFV_TITLE: tfv_title.o
tfv_title.o: tfv_title.s \
gr_vlin.s tfv_opener.s \
draw_menu.s keyboard.s joystick.s \
graphics_title/tfv_title.inc
ca65 -o tfv_title.o tfv_title.s -l tfv_title.lst

View File

@ -1,3 +1,17 @@
title:
timeout if no key pressed at splash/title screen
walking around:
separate background image that says when you can walk
different colors to indicate who you can talk to
battle:
spiral intro
animated intro
load game support
split title and flying off from map play
new or load game

View File

@ -1,3 +1,4 @@
LOAD_TITLE = 0
LOAD_TFV = 1
LOAD_FLYING = 2
LOAD_CREDITS = 3

97
tfv/draw_menu.s Normal file
View File

@ -0,0 +1,97 @@
; print menu selection, draw to draw page
; use arrow keys to scroll
; return/space selects
; X = num entries
; Y = start Y?
; OUTL/OUTH points to list to draw
; return number of response in A
; $FF = nothing
; 0..# is number of selection chosen
draw_menu:
; clear bottom
jsr clear_bottom
; make normal?
; draw list
jsr move_and_print_list
; draw arrow
lda menu_y
clc
adc menu_offset
asl
tay
lda gr_offsets+1,Y
clc
adc DRAW_PAGE
sta OUTH
clc
lda gr_offsets,Y
adc menu_x
sta OUTL
ldy #0
lda #'-'
sta (OUTL),Y
iny
sta (OUTL),Y
iny
lda #'>'
sta (OUTL),Y
; check keypress
jsr get_keypress
; keypress is in A
cmp #0
beq menu_nothing
cmp #'A'
beq dec_menu
cmp #'W'
beq dec_menu
cmp #'S'
beq inc_menu
cmp #'D'
beq inc_menu
cmp #' '
beq menu_select
bne menu_nothing
inc_menu:
lda menu_offset
cmp menu_max
bcs menu_nothing ; don't go above max
inc menu_offset
jmp menu_nothing
dec_menu:
lda menu_offset
beq menu_nothing ; can't go below 0
dec menu_offset
jmp menu_nothing
menu_select:
lda menu_offset
jmp done_menu
menu_nothing:
lda #$ff
done_menu:
sta MENU_RESULT
rts
menu_x: .byte 12
menu_y: .byte 21
menu_max: .byte 2
menu_offset: .byte 0

46
tfv/joystick.s Normal file
View File

@ -0,0 +1,46 @@
; Oliver Schmidt
; comp.sys.apple2.programmer
; Call with joystick number (0 or 1) in A.
; Results are stored in value0 and value1.
; UPPER_THRESHOLD is the paddle value you want to consider as "right enough" /
; "down enough".
UPPER_THRESHOLD = 128
;PTRIG = $c070
PADDL1 = $C065
handle_joystick:
lda #0
; Read both paddles simultaneously
asl ; Joystick number -> paddle number
tax
ldy #$00
sty value0
sty value1
lda PTRIG ; Trigger paddles
loop: lda PADDL0,x ; Read paddle (0 or 2)
bmi set0 ; Cycles: 2 3
nop ; Cycles: 2
bpl nop0 ; Cycles: 3
set0: sty value0 ; Cycles: 4
nop0: ; - -
; Cycles: 7 7
lda PADDL1,x ; Read paddle (1 or 3)
bmi set1 ; Cycles: 2 3
nop ; Cycles: 2
bpl nop1 ; Cycles: 3
set1: sty value1 ; Cycles: 4
nop1: ; - -
; Cycles: 7 7
iny
cpy #UPPER_THRESHOLD+1
bne loop
rts
value0: .byte $00
value1: .byte $00

163
tfv/keyboard.s Normal file
View File

@ -0,0 +1,163 @@
;==============================
; Get Keypress
;==============================
; returns 0 if nothing pressed
get_keypress:
; first handle joystick
lda JOYSTICK_ENABLED
beq actually_handle_keypress
; only check joystick every-other frame
lda FRAMEL
and #$1
beq actually_handle_keypress
check_button:
lda PADDLE_BUTTON0
bpl button_clear
lda JS_BUTTON_STATE
bne js_check
lda #1 ; only register on release
sta JS_BUTTON_STATE
lda #' '
jmp done_keypress
button_clear:
lda #0
sta JS_BUTTON_STATE
js_check:
jsr handle_joystick
js_check_left:
lda value0
cmp #$20
bcs js_check_right ; if less than 32, left
lda #'A'
jmp done_keypress
js_check_right:
cmp #$40
bcc js_check_up
lda #'D'
jmp done_keypress
js_check_up:
lda value1
cmp #$20
bcs js_check_down
lda #'W'
jmp done_keypress
js_check_down:
cmp #$40
bcc done_joystick
lda #'S'
jmp done_keypress
done_joystick:
actually_handle_keypress:
lda KEYPRESS
bmi keypress
jmp no_keypress
keypress:
and #$7f ; clear high bit
cmp #' '
beq check_sound ; make sure not to lose space
and #$df ; convert uppercase to lower case
check_sound:
cmp #$14 ; control-T
bne check_joystick
lda SOUND_STATUS
eor #SOUND_DISABLED
sta SOUND_STATUS
jmp no_keypress
; can't be ^J as that's the same as down
check_joystick:
cmp #'J' ; J
bne check_load
lda JOYSTICK_ENABLED
eor #1
sta JOYSTICK_ENABLED
jmp no_keypress
check_load:
; cmp #$C ; control-L
; bne check_save
; jsr load_game
; jmp done_keypress
check_save:
; cmp #$13 ; control-S
; bne check_left
; jsr save_game
; jmp done_keypress
check_left:
cmp #'A'
beq left_pressed
cmp #8 ; left key
bne check_right
left_pressed:
lda #'A'
jmp done_keypress
check_right:
cmp #'D'
beq right_pressed
cmp #$15 ; right key
bne check_up
right_pressed:
lda #'D'
jmp done_keypress
check_up:
cmp #'W'
beq up_pressed
cmp #$0B ; up key
bne check_down
up_pressed:
lda #'W'
jmp done_keypress
check_down:
cmp #'S'
beq down_pressed
cmp #$0A
bne check_return
down_pressed:
lda #'S'
jmp done_keypress
check_return:
cmp #' '
beq return_pressed
cmp #13
bne no_keypress
return_pressed:
lda #' '
jmp done_keypress
no_keypress:
lda #0
done_keypress:
bit KEYRESET
rts

View File

@ -152,6 +152,7 @@ filenames:
.word intro_filename
.word flying_filename
.word duke2_filename
.word credits_filename
intro_filename:
.byte "TFV_TITLE",0
@ -159,6 +160,8 @@ flying_filename:
.byte "TFV_FLYING",0
duke2_filename:
.byte "DUKE_LEVEL2",0
credits_filename:
.byte "TFV_CREDITS",0
;===================================================

View File

@ -69,7 +69,7 @@ exit:
.include "../asm_routines/keypress.s"
.include "../asm_routines/gr_putsprite.s"
.include "../asm_routines/text_print.s"
.include "../asm_routines/memset.s"
;.include "../asm_routines/memset.s"
.include "../asm_routines/gr_vlin.s"
.include "../asm_routines/gr_copy.s"
;.include "../asm_routines/gr_unrle.s"

View File

@ -11,16 +11,13 @@ enter_name:
jsr print_string
; zero out name
lda #<(name)
sta MEMPTRL
sta NAMEL
lda #>(name)
sta MEMPTRH
sta NAMEH
ldx #0
lda #0
ldx #8
jsr memset
zero_name_loop:
sta name,X
inx
cpx #8
bne zero_name_loop
name_loop:

View File

@ -70,26 +70,84 @@ title_screen:
lda #20
sta XPOS
;=================================
; title menu loop
;=================================
; wait for keypress
jsr wait_until_keypressed
lda #0
sta menu_offset
lda #2
sta menu_max
title_menu_loop:
lda #<title_menu
sta OUTL
lda #>title_menu
sta OUTH
jsr draw_menu
jsr page_flip
jsr increment_frame
lda MENU_RESULT
bmi title_menu_loop
; space was pressed!
beq title_new_game
cmp #1
beq title_load_game
bne title_load_credits
;=================================
; new game started!
;=================================
title_new_game:
;=================================
; enter name
; jsr enter_name
jsr enter_name
;=================================
; move on to flying
; TODO: all rest
lda #LOAD_FLYING
sta WHICH_LOAD
rts
;=================================
; load game! for now, debugging
;=================================
title_load_game:
lda #LOAD_FLYING
sta WHICH_LOAD
rts
;=================================
; load credits!
;=================================
title_load_credits:
lda #LOAD_CREDITS
sta WHICH_LOAD
rts
;===============================
; increment frame
;===============================
increment_frame:
inc FRAMEL
bne done_increment_frame
inc FRAMEH
done_increment_frame:
rts
;===============================================
; External modules
@ -105,11 +163,22 @@ title_screen:
.include "decompress_fast_v2.s"
.include "gr_offsets.s"
.include "wait_keypressed.s"
.include "tfv_textentry.s"
.include "keyboard.s"
.include "joystick.s"
.include "draw_menu.s"
;===============================================
; Variables
; Data
;===============================================
title_menu:
.byte 16,21,"NEW GAME",0
.byte 16,22,"LOAD GAME",0
.byte 16,23,"CREDITS",0
.byte 255
enter_name_string:
.asciiz "PLEASE ENTER A NAME:"

View File

@ -86,6 +86,12 @@ JOYSTICK_ENABLED= $A1
FRAMEL = $A2
FRAMEH = $A3
WHICH_LOAD = $A4
MENU_RESULT = $A5
SOUND_STATUS = $A6
SOUND_DISABLED = $80
SOUND_IN_LC = $01 ; $01 sound effects in language card
SOUND_MOCKINGBOARD = $02 ; mockingboard detected
JS_BUTTON_STATE = $A7
COLOR1 = $E0
COLOR2 = $E1
@ -95,8 +101,8 @@ YY = $E4
SHIPY = $E4
YADD = $E5
LOOP = $E6
MEMPTRL = $E7
MEMPTRH = $E8
;MEMPTRL = $E7
;MEMPTRH = $E8
NAMEL = $E9
NAMEH = $EA
NAMEX = $EB