ootw: actually draw sprite

This commit is contained in:
Vince Weaver 2019-01-13 23:37:49 -05:00
parent ac18cfd838
commit 943fc5fac7
8 changed files with 249 additions and 23 deletions

View File

@ -92,14 +92,18 @@ no_change:
color_progression:
.byte $03
.byte $bf
.byte $b3
; .byte $04 ; black / d.green
; .byte $cf ; l.green / white
; .byte $c4 ; l.green / d.green
.byte $03 ; black / purple
.byte $bf ; pink / white
.byte $b3 ; pink / purple
.byte $00
.byte $00
.byte $02
.byte $6f
.byte $62
.byte $02 ; black/ dblue
.byte $6f ; med blue / white
.byte $62 ; med blue / dblue

View File

@ -16,8 +16,8 @@ OOTW: ootw.o
ld65 -o OOTW ootw.o -C ../linker_scripts/apple2_1000.inc
ootw.o: ootw.s wait_keypress.s \
gr_copy.s gr_fast_clear.s gr_pageflip.s gr_unrle.s \
ootw_backgrounds.inc
gr_copy.s gr_fast_clear.s gr_pageflip.s gr_unrle.s gr_putsprite.s \
ootw_backgrounds.inc ootw_sprites.inc
ca65 -o ootw.o ootw.s -l ootw.lst
####

BIN
ootw/another_sprites.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

4
ootw/gr_offsets.s Normal file
View File

@ -0,0 +1,4 @@
gr_offsets:
.word $400,$480,$500,$580,$600,$680,$700,$780
.word $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8
.word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0

150
ootw/gr_putsprite.s Normal file
View File

@ -0,0 +1,150 @@
;=============================================
; put_sprite
;=============================================
; Sprite to display in INH,INL
; Location is XPOS,YPOS
; Note, only works if YPOS is multiple of two
; transparent color is $A (grey #2)
; this means we can have black ($0) in a sprite
; also note all the cycle count is out of date
; time= 28 setup
; Y*outerloop
; outerloop = 34 setup
; X*innerloop
; innerloop = 30 if $00 17+13(done)
; 64 if $0X 16+7+8+20(put_sprite_mask)+13(done)
; 69 if $X0 16+8+7+5+20(put_sprite_mask)+13(done)
; 54 if if $XX 16+8+8+9(put_all)+13(done)
; -1 for last iteration
; 18 (-1 for last)
; 6 return
; so cost = 28 + Y*(34+18)+ (INNER-Y) -1 + 6
; = 33 + Y*(52)+(INNER-Y)
; = 33 + Y*(52)+ [30A + 64B + 69C + 54D]-Y
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 ; 4
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 ; 4
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
;===========
; 34
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 #$aa ; if all zero, transparent ; 2
beq put_sprite_done_draw ; don't draw it ; 2nt/3
;==============
; 16/17
sta COLOR ; save color for later ; 3
; check if top pixel transparent
and #$f0 ; check if top nibble zero ; 2
cmp #$a0
bne put_sprite_bottom ; if not skip ahead ; 2nt/3
;==============
; 7/8
lda COLOR
and #$0f
sta COLOR
lda #$f0 ; setup mask ; 2
sta MASK ; 3
bmi put_sprite_mask ; always? ; 3
;=============
; 8
put_sprite_bottom:
lda COLOR ; re-load color ; 3
and #$0f ; check if bottom nibble zero ; 2
cmp #$0a
bne put_sprite_all ; if not, skip ahead ; 2nt/3
;=============
; 7/8
lda COLOR
and #$f0
sta COLOR
lda #$0f ; 2
sta MASK ; setup mask ; 3
;===========
; 5
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 ; 6
jmp put_sprite_done_draw ; we are done ; 3
;===========
; 20
put_sprite_all:
lda COLOR ; load color ; 3
sta (OUTL),Y ; and write it out ; 6
;============
; 9
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
;==============
; 12/13
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
;==============
; 17/18
rts ; return ; 6

View File

@ -33,12 +33,12 @@ title_screen:
;=============================
; Load title_rle
; Load background to $c00
lda #$0c
sta BASH
lda #$00
sta BASL ; load image off-screen 0xc00
sta BASL ; load image off-screen $c00
lda #>(planet_rle)
sta GBASH
@ -47,32 +47,89 @@ title_screen:
jsr load_rle_gr
;=================================
; copy to both pages
; copy to both pages $400/$800
jsr gr_copy_to_current
jsr page_flip
jsr gr_copy_to_current
lda #20
sta YPOS
lda #20
sta XPOS
;=================================
; wait for keypress
; setup vars
lda #22
sta ADV_Y
lda #20
sta ADV_X
forever:
jsr wait_until_keypress
game_loop:
; jsr TEXT
; check keyboard
jsr handle_keypress
; copy background to current page
; draw adventurer
lda #>stand_right
sta INH
lda #<stand_right
sta INL
done_walking:
lda ADV_X
sta XPOS
lda ADV_Y
sta YPOS
jsr put_sprite
; draw bad guys
; draw foreground
; page flip
jsr page_flip
jmp forever
; pause?
.include "wait_keypress.s"
; loop forever
jmp game_loop
;======================================
; handle keypress
;======================================
handle_keypress:
lda KEYPRESS ; 4
bpl no_keypress ; 3
; -1
bit KEYRESET ; clear the keyboard strobe ; 4
no_keypress:
rts ; 6
;.include "wait_keypress.s"
.include "gr_pageflip.s"
.include "gr_unrle.s"
.include "gr_fast_clear.s"
.include "gr_copy.s"
.include "gr_putsprite.s"
.include "gr_offsets.s"
.include "ootw_backgrounds.inc"
.include "ootw_sprites.inc"

11
ootw/ootw_sprites.inc Normal file
View File

@ -0,0 +1,11 @@
stand_right:
.byte $4,$8
.byte $aa,$9a,$9a,$aa
.byte $aa,$99,$bb,$aa
.byte $aa,$0b,$aa,$aa
.byte $aa,$bb,$aa,$aa
.byte $aa,$bb,$aa,$aa
.byte $aa,$44,$aa,$aa
.byte $aa,$44,$aa,$aa
.byte $aa,$f4,$fa,$aa

View File

@ -149,8 +149,8 @@ OFFSET = $EF
;FIRST = $F0
LASTKEY = $F1
PADDLE_STATUS = $F2
ADV_X = $F1
ADV_Y = $F2
SPRITETEMP = $F2
XPOS = $F3