-
Notifications
You must be signed in to change notification settings - Fork 2
/
worm.asm
140 lines (129 loc) · 6.3 KB
/
worm.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
*=$1000
Const_KBD_BUFFER = $c5 ; Keyboard matrix
Const_UP = $09 ;
Const_DOWN = $0c ;values
Const_LEFT = $0a ;for up down left right
Const_RIGHT = $0d ;
Const_LEVELUP_KEY = $16 ; "T" pressed = increase length of worm
;*****************************************************
; Initialize worm memory areas
;*****************************************************
ldx #0
lda #0
loop sta worm1,x
sta worm2,x
inx
dex
bne loop
lda #$93 ; Clear the screen
jsr $ffd2
lda #$30
pokeaxy startx,starty
main_loop
lda #$20 ; Erase starting position
pokeaxy startx,starty
lda startdir
cmp #1
beq @down
cmp #2
beq @left
cmp #3
beq @right
@up dec starty
jmp @cont
@down inc starty
jmp @cont
@left dec startx
jmp @cont
@right inc startx
jmp @cont
@cont
lda #$30
pokeaxy startx,starty
jsr get_key
jsr delay
jmp main_loop
rts
get_key lda Const_KBD_BUFFER ; Input a key from Keyboard
sta $400
_ck_pressed
cmp #Const_DOWN ; down - z pressed
beq @down
cmp #Const_Right ; up - w pressed
beq @right
cmp #Const_LEFT ; left - a pressed
beq @left
cmp #Const_Up ; right - s pressed
beq @up
cmp #Const_LEVELUP_KEY ; T - Pressed - advance a level - cheat
beq @make_bigger
rts
@down
lda #1
sta startdir ; Down
rts
@right
inc $401
lda #3
sta startdir ; Right
rts
@up
lda #0
sta startdir ; Up
rts
@left
lda #2
sta startdir ; left
rts
@make_bigger inc length
rts
;***DELAY ***
delay txa
pha
ldx #$ff
@loop1 ldy #0
@loop2 dey
bne @loop2
dex
bne @loop1
pla
rts
startx byte 15,00
starty byte 10,00
startdir byte 00,00
offset byte 00,00
length byte 00,00
map_off_l byte $00,$28,$50,$78,$A0,$C8,$F0,$18,$40,$68,$90,$b8,$E0,$08,$30,$58,$80,$a8,$d0,$f8,$20,$48,$70,$98,$c0
map_off_h byte $04,$04,$04,$04,$04,$04,$04,$05,$05,$05,$05,$05,$05,$06,$06,$06,$06,$06,$06,$06,$07,$07,$07,$07,$07
;*****************************************************
; Grab value of screen position located at x,y
; Store result in accumulator
;*****************************************************
defm peekaxy
ldx /2 ; X value
ldy /1 ; Y Value
lda map_off_l,x ; Load map low byte into $fb
sta $fb
lda map_off_h,x ; Load map hig byte into $fc
sta $fc
lda ($fb),y ; Load result into acc
endm
;*****************************************************
; Store value of accumulator in screen memory at position
; x, y
;*****************************************************
defm pokeaxy
pha
ldx /2 ; X value
ldy /1 ; Y value
lda map_off_l,x ; Load map low byte into $fb
sta $fb
lda map_off_h,x ; Load map high byte into $fc
sta $fc
pla
sta ($fb),y ; Store result in screen memory
endm
*=$2000
worm1
*=$2100
worm2