aboutsummaryrefslogtreecommitdiff
path: root/draw_lorcha.s
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2015-12-29 23:10:50 -0500
committerB. Watson <yalhcru@gmail.com>2015-12-29 23:10:50 -0500
commit2300d2813a524cbfeabac794335e7abe99263df6 (patch)
treed729ca4f99634788cbb3a2101a5b5854a4bc2d06 /draw_lorcha.s
downloadtaipan-2300d2813a524cbfeabac794335e7abe99263df6.tar.gz
initial commit
Diffstat (limited to 'draw_lorcha.s')
-rw-r--r--draw_lorcha.s100
1 files changed, 100 insertions, 0 deletions
diff --git a/draw_lorcha.s b/draw_lorcha.s
new file mode 100644
index 0000000..0f1a376
--- /dev/null
+++ b/draw_lorcha.s
@@ -0,0 +1,100 @@
+
+ .export _draw_lorcha
+ .import popax
+
+; TODO: maybe replace position tables with mul40? see
+; libsrc/atari/mul40.s, which is getting linked anyway
+; because conio uses it.
+
+; offset from start of screen for each ship position (0-9)
+lorcha_pos_lo:
+ .byte <320, <328, <336, <344, <352
+ .byte <640, <648, <656, <664, <672
+lorcha_pos_hi:
+ .byte >320, >328, >336, >344, >352
+ .byte >640, >648, >656, >664, >672
+
+; Atari OS's pointer to start of screen RAM
+ SAVMSC = $58
+
+; ZP working variables start at $d4, aka FR0 (floating point reg 0).
+ mask = $d4
+ displacement = $d5
+ destptr = $d6
+
+; 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!)
+lorcha_data:
+ .incbin "LORCHA.DAT"
+
+; void __fastcall__ draw_lorcha(int which, int displacement, int mask);
+_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?
+ tax
+
+; setup pointer to screen offset of upper left of ship
+ lda lorcha_pos_lo,x
+ clc
+ adc SAVMSC
+ sta destptr
+ lda lorcha_pos_hi,x
+ clc
+ adc SAVMSC+1
+ 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
+ dey
+ bpl blankcolloop
+ jsr bump_pointer ; add 40 (1 line) to dest pointer.
+ dex
+ bne blanklineloop
+
+ ; 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
+ clc
+ bcc shiplineloop
+
+done:
+ rts
+
+bump_pointer:
+ lda destptr
+ clc
+ adc #40
+ sta destptr
+ lda destptr+1
+ adc #0
+ sta 215
+ rts