tfv: more work on the split

This commit is contained in:
Vince Weaver 2020-12-30 01:41:14 -05:00
parent 65135b451a
commit c272bd33fe
13 changed files with 516 additions and 288 deletions

View File

@ -11,11 +11,12 @@ all: tfv.dsk
$(DOS33):
cd ../dos33fs-utils && make
tfv.dsk: $(DOS33) HELLO LOADER TFV_TITLE TFV
tfv.dsk: $(DOS33) HELLO LOADER TFV_TITLE TFV_FLYING TFV_WORLD
$(DOS33) -y tfv.dsk SAVE A HELLO
$(DOS33) -y tfv.dsk BSAVE -a 0x1000 LOADER
$(DOS33) -y tfv.dsk BSAVE -a 0x2000 TFV_TITLE
$(DOS33) -y tfv.dsk BSAVE -a 0x2000 TFV
$(DOS33) -y tfv.dsk BSAVE -a 0x2000 TFV_FLYING
$(DOS33) -y tfv.dsk BSAVE -a 0x2000 TFV_WORLD
###
@ -43,25 +44,26 @@ tfv_title.o: tfv_title.s \
###
TFV: tfv.o
ld65 -o TFV tfv.o -C ../linker_scripts/apple2_2000.inc
###
tfv.o: tfv.s \
tfv_flying.s tfv_info.s \
tfv_textentry.s tfv_worldmap.s \
graphics_map/tfv_backgrounds.inc tfv_sprites.inc zp.inc \
../asm_routines/multiply_fast.s \
gr_fast_clear.s \
../asm_routines/pageflip.s \
../asm_routines/gr_setpage.s \
../asm_routines/keypress.s \
../asm_routines/gr_putsprite.s \
../asm_routines/text_print.s \
../asm_routines/memset.s \
../asm_routines/gr_vlin.s \
../asm_routines/gr_copy.s \
../asm_routines/gr_unrle.s
ca65 -o tfv.o tfv.s -l tfv.lst
TFV_FLYING: tfv_flying.o
ld65 -o TFV_FLYING tfv_flying.o -C ../linker_scripts/apple2_2000.inc
tfv_flying.o: tfv_flying.s \
gr_hlin.s gr_putsprite.s \
tfv_help.s \
tfv_sprites.inc
ca65 -o tfv_flying.o tfv_flying.s -l tfv_flying.lst
###
TFV_WORLD: tfv_world.o
ld65 -o TFV_WORLD tfv_world.o -C ../linker_scripts/apple2_2000.inc
tfv_world.o: tfv_world.s \
tfv_overworld.s tfv_drawmap.s \
graphics_map/tfv_backgrounds.inc tfv_sprites.inc zp.inc
ca65 -o tfv_world.o tfv_world.s -l tfv_world.lst
graphics_map/tfv_backgrounds.inc:
cd graphics_map && make
@ -71,5 +73,5 @@ graphics_map/tfv_backgrounds.inc:
###
clean:
rm -f *~ TITLE.GR *.o *.lst TFV TFV_TITLE HELLO LOADER
rm -f *~ TITLE.GR *.o *.lst TFV TFV_TITLE TFV_FLYING TFV_WORLD HELLO LOADER

124
tfv/gr_hlin.s Normal file
View File

@ -0,0 +1,124 @@
;=====================================================================
;= ROUTINES
;=====================================================================
;================================
; hlin_setup
;================================
; put address in GBASL/GBASH
; Ycoord in A, Xcoord in Y
hlin_setup:
sty TEMPY ; 3
tay ; y=A ; 2
lda gr_offsets,Y ; lookup low-res memory address ; 4
clc ; 2
adc TEMPY ; 3
sta GBASL ; 3
iny ; 2
lda gr_offsets,Y ; 4
adc DRAW_PAGE ; add in draw page offset ; 3
sta GBASH ; 3
rts ; 6
;===========
; 35
;================================
; hlin_double:
;================================
; HLIN Y, V2 AT A
; Y, X, A trashed
; start at Y, draw up to and including X
hlin_double:
;int hlin_double(int page, int x1, int x2, int at) {
jsr hlin_setup ; 41
sec ; 2
lda V2 ; 3
sbc TEMPY ; 3
tax ; 2
inx ; 2
;===========
; 53
; fallthrough
;=================================
; hlin_double_continue: width
;=================================
; GBASL has correct offset for row/col
; width in X
hlin_double_continue:
ldy #0 ; 2
lda COLOR ; 3
hlin_double_loop:
sta (GBASL),Y ; 6
inc GBASL ; 5
dex ; 2
bne hlin_double_loop ; 2nt/3
rts ; 6
;=============
; 53+5+X*16+5
;================================
; hlin_single:
;================================
; HLIN Y, V2 AT A
; Y, X, A trashed
hlin_single:
jsr hlin_setup
sec
lda V2
sbc TEMPY
tax
; fallthrough
;=================================
; hlin_single_continue: width
;=================================
; width in X
hlin_single_continue:
hlin_single_top:
lda COLOR
and #$f0
sta COLOR
hlin_single_top_loop:
ldy #0
lda (GBASL),Y
and #$0f
ora COLOR
sta (GBASL),Y
inc GBASL
dex
bne hlin_single_top_loop
rts
hlin_single_bottom:
lda COLOR
and #$0f
sta COLOR
hlin_single_bottom_loop:
ldy #0
lda (GBASL),Y
and #$f0
sta (GBASL),Y
inc GBASL
dex
bne hlin_single_bottom_loop
rts

101
tfv/gr_putsprite.s Normal file
View File

@ -0,0 +1,101 @@
;=============================================
; put_sprite
;=============================================
; Sprite to display in INH,INL
; Location is XPOS,YPOS
; Note, only works if YPOS is multiple of two?
put_sprite:
ldy #0 ; byte 0 is xsize ; 2
lda (INL),Y ; 5
sta CH ; xsize is in CH ; 3
iny ; 2
lda (INL),Y ; byte 1 is ysize ; 5
sta CV ; ysize is in CV ; 3
iny ; 2
lda YPOS ; make a copy of ypos ; 3
sta TEMPY ; as we modify it ; 3
;===========
; 28
put_sprite_loop:
sty TEMP ; save sprite pointer ; 3
ldy TEMPY ; 3
lda gr_offsets,Y ; lookup low-res memory address ; 5
clc ; 2
adc XPOS ; add in xpos ; 3
sta OUTL ; store out low byte of addy ; 3
lda gr_offsets+1,Y ; look up high byte ; 5
adc DRAW_PAGE ; ; 3
sta OUTH ; and store it out ; 3
ldy TEMP ; restore sprite pointer ; 3
; OUTH:OUTL now points at right place
ldx CH ; load xsize into x ; 3
;===========
; 36
put_sprite_pixel:
lda (INL),Y ; get sprite colors ; 5
iny ; increment sprite pointer ; 2
sty TEMP ; save sprite pointer ; 3
ldy #$0 ; 2
; check if completely transparent
; if so, skip
cmp #$0 ; if all zero, transparent ; 2
beq put_sprite_done_draw ; don't draw it ; 2nt/3
; FIXME: use BIT? ;==============
; 17
sta COLOR ; save color for later ; 3
; check if top pixel transparent
and #$f0 ; check if top nibble zero ; 2
bne put_sprite_bottom ; if not skip ahead ; 2nt/3
lda #$f0 ; setup mask ; 2
sta MASK ; 3
bmi put_sprite_mask ; 2nt/3
put_sprite_bottom:
lda COLOR ; re-load color ; 3
and #$0f ; check if bottom nibble zero ; 2
bne put_sprite_all ; if not, skip ahead ; 2nt/3
lda #$0f ; 2
sta MASK ; setup mask ; 3
put_sprite_mask:
lda (OUTL),Y ; get color at output ; 5
and MASK ; mask off unneeded part ; 3
ora COLOR ; or the color in ; 3
sta (OUTL),Y ; store it back ; 5
jmp put_sprite_done_draw ; we are done ; 3
put_sprite_all:
lda COLOR ; load color ; 3
sta (OUTL),Y ; and write it out ; 5
put_sprite_done_draw:
ldy TEMP ; restore sprite pointer ; 3
inc OUTL ; increment output pointer ; 5
dex ; decrement x counter ; 2
bne put_sprite_pixel ; if not done, keep looping ; 2nt/3
inc TEMPY ; each line has two y vars ; 5
inc TEMPY ; 5
dec CV ; decemenet total y count ; 5
bne put_sprite_loop ; loop if not done ; 2nt/3
rts ; return ; 6

View File

@ -151,15 +151,15 @@ copy_filename_done:
filenames:
.word intro_filename
.word flying_filename
.word duke2_filename
.word world_filename
.word credits_filename
intro_filename:
.byte "TFV_TITLE",0
flying_filename:
.byte "TFV_FLYING",0
duke2_filename:
.byte "DUKE_LEVEL2",0
world_filename:
.byte "TFV_WORLD",0
credits_filename:
.byte "TFV_CREDITS",0

View File

@ -120,7 +120,7 @@ move_and_print_list:
rts
.if 0
;================================
; move and print a list of lines
;================================
@ -188,4 +188,4 @@ print_both_pages:
rts
.endif

View File

@ -1,91 +0,0 @@
.include "zp.inc"
.include "hardware.inc"
;================================
; Clear screen and setup graphics
;================================
jsr HOME
jsr set_gr_page0
lda #0
sta DISP_PAGE ; Forgot to set initially
; real hardware and AppleWin default
; to different values
;=====================
; Flying
;=====================
jsr flying_start
;=====================
; World Map
;=====================
jsr world_map
;=====================
; Game Over
;=====================
jsr game_over
;=====================
; All finished
;=====================
exit:
lda #$4
sta BASH
lda #$0
sta BASL ; restore to 0x400 (page 0)
; copy to 0x400 (page 0)
; call home
jsr HOME
; Return to BASIC?
rts
;===============================================
; External modules
;===============================================
;.include "tfv_opener.s"
;.include "tfv_title.s"
.include "tfv_textentry.s"
.include "tfv_flying.s"
.include "tfv_worldmap.s"
.include "tfv_info.s"
.include "gr_fast_clear.s"
.include "../asm_routines/gr_hlin.s"
.include "../asm_routines/pageflip.s"
.include "../asm_routines/gr_setpage.s"
.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/gr_vlin.s"
.include "../asm_routines/gr_copy.s"
;.include "../asm_routines/gr_unrle.s"
.include "decompress_fast_v2.s"
.include "../asm_routines/gr_offsets.s"
;===============================================
; Variables
;===============================================
enter_name_string:
.asciiz "PLEASE ENTER A NAME:"
name:
.byte $0,$0,$0,$0,$0,$0,$0,$0
.include "tfv_sprites.inc"
.include "graphics_map/tfv_backgrounds.inc"

89
tfv/tfv_drawmap.s Normal file
View File

@ -0,0 +1,89 @@
;==========================
; draw world map
;==========================
; including position
show_map:
lda #<(map_lzsa)
sta getsrc_smc+1
lda #>(map_lzsa)
sta getsrc_smc+2
lda DRAW_PAGE
clc
adc #$4 ; page to load at?
; FIXME: really need to load at 0xc and
; copy
jsr decompress_lzsa2_fast
; basic_plot(8+((map_x&0x3)*6)+(tfv_x/6),
; 8+(((map_x&0xc)>>2)*6)+(tfv_y/6))
; horizontal
lda MAP_X
and #3
asl
sta TEMP
asl
clc
adc TEMP ; ( MAP_X & 3 ) * 6
sta TEMP
lda TFV_X
lsr
lsr
lsr ; TFV/8
adc TEMP
adc #8
sta CH
; vertical
lda MAP_X
and #$c
lsr
sta TEMP
asl
clc
adc TEMP ; ( MAP_X & C ) * 6
sta TEMP
lda TFV_Y
lsr
lsr
lsr ; TFV/8
adc TEMP
adc #8
lsr ; divide by 2 as htab_vtab multiplies
sta CV
; jsr htab_vtab
lda CV
asl
tay
lda gr_offsets,Y
clc
adc CH
sta BASL
lda gr_offsets+1,Y
sta BASH
lda #$19 ; red/orange
ldy #0
sta (BASL),Y
jsr page_flip
jsr wait_until_keypressed
rts

View File

@ -1,3 +1,10 @@
; Mode-7 Flying code
.include "zp.inc"
.include "hardware.inc"
.include "common_defines.inc"
;===========
; CONSTANTS
;===========
@ -15,14 +22,18 @@ CONST_SCALE_F = $00
CONST_LOWRES_HALF_I = $ec ; -(LOWRES_W/2)
CONST_LOWRES_HALF_F = $00
flying_start:
flying:
;===================
; Clear screen/pages
;===================
jsr clear_screens
jsr set_gr_page0
bit PAGE0
lda #0
sta DISP_PAGE
lda #4
sta DRAW_PAGE
; Initialize the 2kB of multiply lookup tables
jsr init_multiply_tables
@ -66,7 +77,7 @@ flying_loop:
flying_keyboard:
jsr get_key ; get keypress ; 6
jsr get_keypress ; get keypress ; 6
lda LASTKEY ; 3
@ -77,7 +88,7 @@ flying_keyboard:
;skipskip:
cmp #('W') ; 2
bne check_down ; 3/2nt
bne flying_check_down ; 3/2nt
;===========
; UP PRESSED
@ -85,7 +96,7 @@ flying_keyboard:
lda SHIPY
cmp #17
bcc check_down ; bgt, if shipy>16
bcc flying_check_down ; bgt, if shipy>16
dec SHIPY
dec SHIPY ; move ship up
inc SPACEZ_I ; incement height
@ -93,9 +104,9 @@ flying_keyboard:
lda #0
sta SPLASH_COUNT
check_down:
flying_check_down:
cmp #('S')
bne check_left
bne flying_check_left
;=============
; DOWN PRESSED
@ -108,15 +119,15 @@ check_down:
inc SHIPY ; move ship down
dec SPACEZ_I ; decrement height
jsr update_z_factor
bcc check_left
bcc flying_check_left
splashy:
lda #10
sta SPLASH_COUNT
check_left:
flying_check_left:
cmp #('A')
bne check_right
bne flying_check_right
;=============
; LEFT PRESSED
@ -129,7 +140,7 @@ check_left:
lda #$0
sta TURNING
clv
bvc check_right
bvc flying_check_right
turn_left:
lda #253 ; -3
@ -137,7 +148,7 @@ turn_left:
dec ANGLE
check_right:
flying_check_right:
cmp #('D')
bne check_speedup
@ -1243,3 +1254,25 @@ horizontal_lookup:
grass_string:
.asciiz "NEED TO LAND ON GRASS!"
;===============================================
; External modules
;===============================================
.include "gr_offsets.s"
.include "gr_hlin.s"
.include "gr_pageflip.s"
.include "gr_putsprite.s"
.include "gr_fast_clear.s"
.include "keyboard.s"
.include "joystick.s"
.include "wait_keypressed.s"
.include "text_print.s"
.include "tfv_help.s"
.include "tfv_sprites.inc"

28
tfv/tfv_game_over.s Normal file
View File

@ -0,0 +1,28 @@
game_over:
lda #$a0
jsr clear_top_a
bit SET_TEXT
lda #10
sta CV
lda #15
sta CH
lda #>(game_over_man)
sta OUTH
lda #<(game_over_man)
sta OUTL
jsr move_and_print
jsr page_flip
jsr wait_until_keypressed
rts
game_over_man:
.asciiz "GAME OVER"

36
tfv/tfv_help.s Normal file
View File

@ -0,0 +1,36 @@
;====================
; print help message
;====================
print_help:
lda #$a0
jsr clear_top_a
bit SET_TEXT
lda #>(help_message)
sta OUTH
lda #<(help_message)
sta OUTL
jsr move_and_print_list
jsr page_flip
jsr wait_until_keypressed
bit SET_GR ; set graphics
rts
help_message:
.byte 1,18,"HELP"
.byte 3,4,"ARROWS - MOVE"
.byte 3,5,"W/A/S/D - MOVE"
.byte 3,6,"Z/X - SPEED UP / SLOW DOWN"
.byte 3,7,"SPACE - STOP"
.byte 3,8,"RETURN - LAND / ENTER / ACTION"
.byte 3,9,"I - INVENTORY"
.byte 3,10,"M - MAP"
.byte 3,11,"ESC - QUIT"
.byte $ff

View File

@ -1,157 +0,0 @@
game_over:
lda #$a0
jsr clear_top_a
bit SET_TEXT
lda #10
sta CV
lda #15
sta CH
lda #>(game_over_man)
sta OUTH
lda #<(game_over_man)
sta OUTL
jsr move_and_print
jsr page_flip
hang_forever:
jmp hang_forever
rts
game_over_man:
.asciiz "GAME OVER"
show_map:
lda DRAW_PAGE
clc
adc #$4 ; page to load at?
; FIXME: really need to load at 0xc and
; copy
pha
lda #<(map_lzsa)
sta getsrc_smc+1
lda #>(map_lzsa)
sta getsrc_smc+2
pla
jsr decompress_lzsa2_fast
; basic_plot(8+((map_x&0x3)*6)+(tfv_x/6),
; 8+(((map_x&0xc)>>2)*6)+(tfv_y/6))
; horizontal
lda MAP_X
and #3
asl
sta TEMP
asl
clc
adc TEMP ; ( MAP_X & 3 ) * 6
sta TEMP
lda TFV_X
lsr
lsr
lsr ; TFV/8
adc TEMP
adc #8
sta CH
; vertical
lda MAP_X
and #$c
lsr
sta TEMP
asl
clc
adc TEMP ; ( MAP_X & C ) * 6
sta TEMP
lda TFV_Y
lsr
lsr
lsr ; TFV/8
adc TEMP
adc #8
lsr ; divide by 2 as htab_vtab multiplies
sta CV
jsr htab_vtab
lda #$19 ; red/orange
ldy #0
sta (BASL),Y
jsr page_flip
jsr wait_until_keypressed
rts
print_help:
lda #$a0
jsr clear_top_a
bit SET_TEXT
lda #1
sta CV
lda #18
sta CH
lda #>(help1)
sta OUTH
lda #<(help1)
sta OUTL
jsr move_and_print
jsr point_to_end_string
lda #3
sta CV
lda #4
sta CH
help_loop:
jsr move_and_print
jsr point_to_end_string
inc CV
lda #11
cmp CV
bne help_loop
jsr page_flip
jsr wait_until_keypressed
bit SET_GR ; set graphics
rts
help1: .asciiz "HELP"
help2: .asciiz "ARROWS - MOVE"
help3: .asciiz "W/A/S/D - MOVE"
help4: .asciiz "Z/X - SPEED UP / SLOW DOWN"
help5: .asciiz "SPACE - STOP"
help6: .asciiz "RETURN - LAND / ENTER / ACTION"
help7: .asciiz "I - INVENTORY"
help8: .asciiz "M - MAP"
help9: .asciiz "ESC - QUIT"

View File

@ -20,7 +20,11 @@ world_map:
;===================
jsr clear_screens
jsr set_gr_page0
bit PAGE0
lda #0
sta DISP_PAGE
lda #4
sta DRAW_PAGE
;===============
; Init Variables
@ -58,7 +62,7 @@ worldmap_loop:
worldmap_keyboard:
jsr get_key ; get keypress
jsr get_keypress ; get keypress
lda LASTKEY

59
tfv/tfv_world.s Normal file
View File

@ -0,0 +1,59 @@
; TFV world
; the main part of the game
.include "zp.inc"
.include "hardware.inc"
.include "common_defines.inc"
;================================
; Clear screen and setup graphics
;================================
;=====================
; World Map
;=====================
jsr world_map
;=====================
; Game Over
;=====================
; return to title screen?
jsr game_over
lda #LOAD_TITLE
sta WHICH_LOAD
rts
;===============================================
; External modules
;===============================================
.include "tfv_drawmap.s"
.include "tfv_overworld.s"
.include "tfv_game_over.s"
.include "tfv_help.s"
.include "gr_fast_clear.s"
.include "gr_hlin.s"
.include "gr_pageflip.s"
.include "keyboard.s"
.include "joystick.s"
.include "gr_putsprite.s"
.include "text_print.s"
.include "gr_copy.s"
.include "decompress_fast_v2.s"
.include "gr_offsets.s"
.include "wait_keypressed.s"
;===============================================
; Variables
;===============================================
.include "tfv_sprites.inc"
.include "graphics_map/tfv_backgrounds.inc"