-
Notifications
You must be signed in to change notification settings - Fork 2
/
superimpose.asm
154 lines (140 loc) · 3.39 KB
/
superimpose.asm
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
.ifndef SUPERIMPOSE_INC
SUPERIMPOSE_INC = 1
.include "x16.inc"
.include "tilelib.asm"
ASCII_SPACE = $20
.macro SUPERIMPOSE str_arg, x_arg, y_arg
.scope
jmp end_string
string_begin: .asciiz str_arg
end_string:
lda #<string_begin
sta ZP_PTR_1
lda #>string_begin
sta ZP_PTR_1+1
lda #<__superimpose_string
sta ZP_PTR_2
lda #>__superimpose_string
sta ZP_PTR_2+1
ldx #(end_string-string_begin-1)
ldy #0
loop:
lda (ZP_PTR_1),y
sta (ZP_PTR_2),y
iny
dex
bne loop
lda #1
ldx #x_arg
ldy #y_arg
jsr xy2vaddr
sta __superimpose_bank
lda #$10
ora __superimpose_bank
sta __superimpose_bank
lda #(end_string-string_begin-1)
jsr __superimpose
.endscope
.endmacro
.macro SUPERIMPOSE_RESTORE vaddr, length
.if (.paramcount > 0)
lda #(^vaddr | $10)
sta __superimpose_bank
ldx #<vaddr
ldy #>vaddr
.else
ldx __superimpose_address
ldy __superimpose_address+1
.endif
.if (.paramcount > 1)
lda #length
.else
lda __superimpose_length
.endif
jsr __superimpose_restore
.endmacro
.macro __superimpose_args2veraloop
stz VERA_ctrl
lda __superimpose_bank
sta VERA_addr_bank
stx VERA_addr_low
sty VERA_addr_high
ldy #0 ; Y = tilemap address offset
lda __superimpose_length
clc
adc __superimpose_length
tax ; X = 2 x string length
lda #<__superimpose_clipboard
sta ZP_PTR_1 ; ZP_PTR_1 = clipboard
lda #>__superimpose_clipboard
sta ZP_PTR_1+1
.endmacro
__superimpose_clipboard:
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
__superimpose_string:
.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
__superimpose_length:
.byte 0
__superimpose_bank:
.byte 0
__superimpose_address:
.word 0
__superimpose: ; A: string length (max = 20)
; X/Y: tilemap address
; __superimpose_bank: tilemap bank
; __superimpose_string: string to superimpose
sta __superimpose_length
stx __superimpose_address
sty __superimpose_address+1
__superimpose_args2veraloop
@readloop: ; store tiles to clipboard
txa
beq @write
lda VERA_data0
sta (ZP_PTR_1),y
iny
dex
jmp @readloop
@write:
lda __superimpose_address+1
sta VERA_addr_high
lda __superimpose_address
sta VERA_addr_low
lda #<__superimpose_string
sta ZP_PTR_1 ; ZP_PTR_1 = string
lda #>__superimpose_string
sta ZP_PTR_1+1
ldx __superimpose_length ; X = string length
ldy #0 ; Y = string index
@writeloop: ; write character tiles to tilemap
txa
beq @end
lda (ZP_PTR_1),y
cmp #ASCII_SPACE
bne @store_char
lda #0 ; replace spaces with blank tiles
@store_char:
sta VERA_data0 ; store character tile
lda #0
sta VERA_data0 ; store tile control (PO 0, no flip)
iny
dex
jmp @writeloop
@end:
rts
__superimpose_restore: ; A: string length (max = 20)
; X/Y: tilemap address (bank 0 assumed)
; __superimpose_bank: tilemap bank
sta __superimpose_length
__superimpose_args2veraloop
@loop:
txa
beq @end
lda (ZP_PTR_1),y
sta VERA_data0
iny
dex
jmp @loop
@end:
rts
.endif