aboutsummaryrefslogtreecommitdiff
path: root/draw_lorcha.s
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2015-12-30 04:49:43 -0500
committerB. Watson <yalhcru@gmail.com>2015-12-30 04:49:43 -0500
commitd5c761515bd26f1f2a6b0f91e2b6f6762431566c (patch)
tree2358efc0ce7bfa5c11956193ad67bdcc7468c623 /draw_lorcha.s
parent2300d2813a524cbfeabac794335e7abe99263df6 (diff)
downloadtaipan-d5c761515bd26f1f2a6b0f91e2b6f6762431566c.tar.gz
Visible damage
Diffstat (limited to 'draw_lorcha.s')
-rw-r--r--draw_lorcha.s233
1 files changed, 178 insertions, 55 deletions
diff --git a/draw_lorcha.s b/draw_lorcha.s
index 0f1a376..2abd196 100644
--- a/draw_lorcha.s
+++ b/draw_lorcha.s
@@ -1,6 +1,9 @@
+; Atari Taipan routines for rendering enemy lorchas.
- .export _draw_lorcha
- .import popax
+; Lorcha (boat), a type of sailing vessel having a Chinese
+; junk rig on a Portuguese or European style hull.
+
+ .export _draw_lorcha, _sink_lorcha, _damage_lorcha, _clear_lorcha, _flash_lorcha
; TODO: maybe replace position tables with mul40? see
; libsrc/atari/mul40.s, which is getting linked anyway
@@ -18,83 +21,203 @@ lorcha_pos_hi:
SAVMSC = $58
; ZP working variables start at $d4, aka FR0 (floating point reg 0).
- mask = $d4
- displacement = $d5
+ temp = $d4
+ andmask = temp
+ flashing = temp+1
destptr = $d6
+ lcount = $d8
+ which = $d9
-; Lorcha (boat), a type of sailing vessel having a Chinese
-; junk rig on a Portuguese or European style hull.
; Our lorcha is a 7x7 block of ATASCII characters. We're storing
; directly to screen RAM, so we use 'internal' codes.
-; To edit the graphics, load up LORCHA.LST in atari800, with the H:
-; device enabled, writable, set to current directory. Then edit the
-; quoted strings in lines 10-70, and RUN the program. It will
-; generate a new LORCHA.DAT, which must be 49 bytes long (so don't
-; change the lengths of the strings in the BASIC code!)
+; To edit the graphics, see shipshape[] in convfont.c.
lorcha_data:
.incbin "LORCHA.DAT"
-; void __fastcall__ draw_lorcha(int which, int displacement, int mask);
+; fully-damaged version of the lorcha, damaged_shipshape[] in convfont.c
+damaged_data:
+ .incbin "DAMAGED.DAT"
+
+; void __fastcall__ flash_lorcha(int which);
+_flash_lorcha:
+ ldx #$80
+ stx flashing
+ bne drawit
+
+; void __fastcall__ clear_lorcha(int which);
+_clear_lorcha:
+ ldx #0
+ stx andmask
+ stx flashing
+ beq drawit
+
+; void __fastcall__ draw_lorcha(int which);
_draw_lorcha:
- sta mask ; stash mask (0 = normal, $80 = inverse)
- jsr popax ; get displacement (0 = whole ship, 1..6 = sinking, 7 = blank)
- sta displacement
- jsr popax ; which ship position?
+ ldx #$ff
+ stx andmask
+ ldx #0
+ stx flashing
+
+; the above 3 entry points set up flashing and/or andmask,
+; then branch to the common routine here.
+; flashing = 1: invert all the character codes (ignore andmask). turns
+; ship inverse, or back to normal, using the data that's
+; already in screen RAM (meaning, damage is preserved).
+; flashing = 0: copy lorcha_data to destptr, ANDing with andmask:
+; andmask = 0: clear lorcha
+; andmask = $ff: draw lorcha
+
+drawit:
tax
+ jsr setup_destptr
+ ldx #0
+line:
+ ldy #0
+char:
+ bit flashing
+ bpl noflash
+ lda (destptr),y
+ eor #$80
+ clc
+ bcc storeit
+noflash:
+ lda lorcha_data,x
+ and andmask
+storeit:
+ sta (destptr),y
+ inx
+ iny
+ cpy #7
+ bne char
+ jsr bump_destptr
+ cpx #49
+ bne line
+ rts
-; setup pointer to screen offset of upper left of ship
- lda lorcha_pos_lo,x
+; sinking the lorcha means copying each line of screen RAM
+; from the one above it. has to be done in reverse order.
+_sink_lorcha:
+ sta which
+ lda #6
+ sta lcount
+
+sinkloop:
+ ldx which
+ jsr setup_destptr
clc
- adc SAVMSC
+ lda destptr
+ adc #200 ; 40 bytes/line * 5 lines
sta destptr
- lda lorcha_pos_hi,x
- clc
- adc SAVMSC+1
+ lda destptr+1
+ adc #0
sta destptr+1
- ; first, draw any blank lines
- ldx displacement ; are there any?
- beq shiplineloop ; no, draw ship
-blanklineloop:
- lda #0 ; screen code for space
- ;ora mask ; apply mask ; don't need this here
- ldy #6 ; ship is 7 columns wide (we count 6 to -1)
-blankcolloop:
- sta (destptr),y
+ ldx #6 ; line loop counter
+ ; delay for several jiffies
+ sei
+ lda #0
+ sta 541
+ lda #7
+ sta 540
+ cli
+sdelay:
+ lda 541
+ ora 540
+ bne sdelay
+
+
+ ; at start of loop, destptr points to last line, and temp
+ ; is unitialized.
+slineloop:
+
+ ; temp=destptr; destptr-=40;
+ lda destptr
+ sta temp
+ sec
+ sbc #40
+ sta destptr
+ lda destptr+1
+ sta temp+1
+ sbc #0
+ sta destptr+1
+
+ ; now loop over 7 bytes
+ ldy #6
+sbyteloop:
+ lda (destptr),y
+ sta (temp),y
dey
- bpl blankcolloop
- jsr bump_pointer ; add 40 (1 line) to dest pointer.
+ bpl sbyteloop
dex
- bne blanklineloop
+ bpl slineloop
+ dec lcount
+ bpl sinkloop
- ; X is now 0, however we got here.
-shiplineloop:
- lda displacement
- cmp #7
- beq done
- ldy #0
-shipcolloop:
- lda lorcha_data,x
- eor mask
- sta (destptr),y
- iny
- inx
- cpy #7
- bne shipcolloop
- jsr bump_pointer
- inc displacement
+ rts ; end of _sink_lorcha
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+_damage_lorcha:
+ tax
+ jsr setup_destptr
+
+xrand:
+ ; get random number 0-48 in X:
+ lda 53770 ; RANDOM
+ lsr
+ lsr
+ cmp #49
+ bcs xrand
+ tax
+
+getpiece:
+ lda damaged_data,x
+ cmp lorcha_data,x
+ beq xrand ; if it's a piece that can't show damage,
+ ; ditch it and start over
+ sta temp ; stash the piece
+
+ ; which row/col? call bump_destptr (x/7)-1 times.
+ txa
+calcrow:
+ sec
+ sta temp+1 ; this holds the modulus (x%7)
+ sbc #7
+ bcc rowdone
+ pha
+ jsr bump_destptr
+ pla
clc
- bcc shiplineloop
+ bcc calcrow
-done:
- rts
+rowdone:
+ lda temp ; the piece
+ ldy temp+1
+ sta (destptr),y
+
+ rts ; end of _damage_lorcha
+
+; a couple of utility functions for dealing with destptr:
-bump_pointer:
+; add 40 to destptr. trashes A, preserves X/Y.
+bump_destptr:
lda destptr
clc
adc #40
sta destptr
lda destptr+1
adc #0
- sta 215
+ sta destptr+1
+ rts
+
+; sets up destptr to point to correct position for the given
+; ship number (0-9) in X reg. trashes A, preserves X/Y.
+setup_destptr:
+ lda lorcha_pos_lo,x
+ clc
+ adc SAVMSC
+ sta destptr
+ lda lorcha_pos_hi,x
+ clc
+ adc SAVMSC+1
+ sta destptr+1
rts