-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathca65-ex01.asm
More file actions
147 lines (128 loc) · 1.8 KB
/
ca65-ex01.asm
File metadata and controls
147 lines (128 loc) · 1.8 KB
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
.segment "STARTUP"
.segment "INIT"
.segment "ONCE"
.segment "CODE"
.include "vtuilib-ca65.inc"
main:
stz xcord
stz ycord
stz newx
stz newy
clc ; BANK 0
jsr vtui_set_bank
stz $9F20 ; ADDR $0100
lda #1
sta $9F21
ldx #7*7 ; Size = 7*7
lda #' '
ldy #$61
: sta $9F23
sty $9F23
dex
bne :-
sec ; BANK 1
jsr vtui_set_bank
lda xcord
ldy ycord
jsr vtui_gotoxy
lda #7
sta r1l ; Width
sta r2l ; Height
stz r0l ; ADDR $0000
stz r0h
lda #$80 ; Save to VRAM
clc ; Bank 0
jsr vtui_save_rect
lda #32 ; X
ldy #30 ; Y
jsr vtui_gotoxy
lda #<my_str ; Ptr to string in r0
sta r0l
lda #>my_str
sta r0h
ldx #$61 ; Color
lda #0
ldy #xcord-my_str
jsr vtui_print_str
: jsr $FFE4 ; GETIN
beq :-
cmp #$9D ; Left arrow
bne @isup
lda newx
beq :-
dec newx
jsr move_logo
bra :-
@isup: cmp #$91 ; Up arrow
bne @isright
lda newy
beq :-
dec newy
jsr move_logo
bra :-
@isright:
cmp #$1D ; Right arrow
bne @isdown
lda newx
cmp #73
beq :-
inc newx
jsr move_logo
bra :-
@isdown:
cmp #$11 ; Down arrow
bne @end
lda newy
cmp #53
beq :-
inc newy
jsr move_logo
bra :-
@end:
rts
move_logo:
lda xcord
ldy ycord
jsr vtui_gotoxy
lda #7
sta r1l ; Width
sta r2l ; Height
stz r0l ; ADDR $0100
lda #1
sta r0h
lda #$80 ; Restore from VRAM
clc ; Bank 0
jsr vtui_rest_rect
lda newx
ldy newy
jsr vtui_gotoxy
lda #7
sta r1l ; Width
sta r2l ; Height
stz r0l ; ADDR $0100
lda #1
sta r0h
lda #$80 ; Save to VRAM
clc ; Bank 0
jsr vtui_save_rect
lda newx
ldy newy
jsr vtui_gotoxy
lda #7
sta r1l ; Width
sta r2l ; Height
lda #$80 ; Restore from VRAM
clc ; Bank 0
stz r0l ; ADDR $0000
stz r0h
jsr vtui_rest_rect
lda newx
sta xcord
lda newy
sta ycord
rts
my_str: .byte "use arrow keys!"
xcord: .byte 0
ycord: .byte 0
newx: .byte 0
newy: .byte 0