aboutsummaryrefslogtreecommitdiff
path: root/draw_lorcha.s
blob: 0f1a376de7b720b4988eec7a17a99fc5a9b0e71f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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