-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.asm
332 lines (276 loc) · 6.11 KB
/
main.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
;dragon 32 brainfuck interpreter
;an unfinished old project picked up and
;finished on 27-28/03/2023
org 0
;varzzzzzz
scrnpointer rmb 2
jmpaddr rmb 2
outputpointer rmb 2
tmpvar rmb 1
org $1000
;coedzzzzz
start
jsr blankscrn
ldy #titlestring
jsr printtitle
ldx #$480
stx scrnpointer
stx outputpointer
jmp main
startback
jsr blankscrn
ldy #titlestring
jsr printtitle
jsr copyback
ldx scrnpointer
lda #32
sta $5FF
main
lda #35 ;#
sta ,x
leax 1,x
lda #32 ;space after to stop 0 char showing on copyback
sta ,x
leax -1,x
jsr $8006 ;get char
beq skipnone
cmpa #32 ;space
bne skipspace
adda #64
skipspace
cmpa #12 ;clear
bne skipclear
jmp helpscreen
skipclear
cmpa #8 ;backspace
bne skipback
cmpx #$480
beq skipnone ;if on the first char then don't back up any more
lda #32
sta ,x
leax -2,x
jmp skipendinc
skipback
cmpa #40 ;[
bne skipleft
;suba #13
lda #27
skipleft
cmpa #41 ;]
bne skipright
;suba #12
lda #29
skipright
cmpa #13 ;enter
bne skipenter
leax 1,x
lda #0
sta ,x
leax -1,x
jsr output
jmp start
skipenter
sta ,x
skipendinc
leax 1,x
skipnone
jmp main
helpscreen
stx scrnpointer
jsr copyprog
jsr blankscrn
ldy #helptitle
jsr printtitle
ldx #helpstring
ldy #$480
helptextlp
lda ,x+
beq checkclear
suba #64
sta ,y+
jmp helptextlp
checkclear
jsr $8006
cmpa #12
bne checkclear
jmp startback
output
stx scrnpointer
jsr copyprog
jsr blankscrn
ldy #outputscrnstring
jsr printtitle
jsr interpret
checkenter
jsr $8006
cmpa #13
bne checkenter
jmp startback
rts
cleararray
ldx #bfarray
ldd #$0000
clearlp
std ,x++
cmpx #bfarrayend
bne clearlp
rts
interpret
jsr cleararray
ldu outputpointer
ldx #progarray
ldy #bfarray
interpretlp
lda ,x
cmpa #60 ;<
bne skiplt
leay -1,y
jmp outputend
skiplt
cmpa #62 ;>
bne skipgt
leay 1,y
jmp outputend
skipgt
cmpa #43 ;+
bne skipinc
inc ,y
jmp outputend
skipinc
cmpa #45 ;-
bne skipdec
dec ,y
jmp outputend
skipdec
cmpa #46 ;.
bne skipoutput
lda ,y
sta ,u+
jmp outputend
skipoutput
cmpa #44 ;,
bne skipinput
inputlp
jsr $8006
beq inputlp
sta ,y
jmp outputend
skipinput
cmpa #27 ;[
bne skiplb
stx jmpaddr
jmp outputend
skiplb
cmpa #29 ;]
bne skiprb
lda ,y
beq skiprb
ldx jmpaddr
jmp outputend
skiprb
cmpa #32 ;space
bne outputend
jmp outputend
outputend
leax 1,x
outputend2
cmpx #progarrayend
bne interpretlp
interpretend
rts
;el cheapo copy by copying whatever is on the screen
;to an array to then be interpreted
;not ideal but who the fuck is going to write more
;than a whole screens worth its a novelty ;)
copyprog
ldx #$480
ldy #progarray
copyproglp
lda ,x+
cmpx #$600
beq copydone
sta ,y+
bne copyproglp
copydone
rts
copyback
ldx #progarray
ldy #$480
copyprogbacklp
lda ,x+
cmpy #$600
beq copydone
sta ,y+
bne copyproglp
copybackdone
rts
clrscrn
ldx #$400
ldd #$2020
clrscrnlp
std ,x++
cmpx #$800
bne clrscrnlp
rts
printtitle
ldx #$400
printtitlelp
lda ,y+
beq skipprint
sta ,x+
bra printtitlelp
skipprint
rts
println
ldx #$460
lda #128
linelp
sta ,x+
cmpx #$480
bne linelp
rts
blankscrn
jsr clrscrn
jsr println
rts
titlestring
fcv " DRAGON BRAINFUCK INTERPRETER BY TOBACH/SLP+TUHB enter TO RUN clear FOR HELP ",0
outputscrnstring
fcv " OUTPUT: ",0
helptitle
fcv " HELP SCREEN: WHAT IS BRAINFUCK AND WHY SHOULD I CARE? ",0
helpstring
fcv "BRAINFUCK IS AN ESOTERIC PROGRAMMING LANGUAGE CREATED IN 1993 BY URBAN MULLER. "
fcv "THE ONLY CHARACTERS ARE:"
fcb 190,188,171,173,174,172,155,157
;fcv " "
fcb 188
fcv " AND "
fcb 190
fcv " ARE USED TO INC AND DEC THE POINTER, "
fcb 171
fcv " AND "
fcb 173
fcv " TO ADD OR SUBRACT ONE FROM THE CURRENT "
fcv "POINTER LOCATION, "
fcb 174
fcv " TO OUTPUT A BYTE AND "
fcb 172
fcv " TO TAKE INPUT. "
fcb 155
fcv " AND "
fcb 157
fcv " ARE FOR LOOPING, WHICH IF THE CURRENT VALUE !=0 BY THE END "
fcb 157
fcv ", THEN JUMPS BACK TO THE START "
fcb 155
fcv ".",0
org $2000
bfarray
rzb 512
bfarrayend
org $3000
progarray
rzb 512
progarrayend
end start