aboutsummaryrefslogtreecommitdiff
path: root/examples/0x42c.dasm16
blob: 693843089a38bfda2f94a3991fa02095675838c7 (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
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
SET PC, initialstate

; string definitions (currently using C-style strings)
:version dat "0x42c v.0.1 128K MEM READY", 0
:input dat "> ", 0

; commands
:reddit dat "reddit", 0
:date dat "date", 0
:clean dat "clean", 0
:vers dat "version", 0
:echo dat "echo", 0

; outputs
:redditoutput dat "Reddit, the frontpage of the internet.", 0
:dateoutput dat "00:00:00 UTC on 1 January 1970", 0
:unrecognized dat "Unrecognized command '", 0
:unrecognizedEnd dat "'.", 0


:initialstate
	set [0x1335], 0x8000   ; vidmem
	set [0x1337], 0x1338 ; input buffer


:main
	set a, version
	jsr printnl      ; printnl(version)

:inputready
	set a, input
	jsr print        ; printnl(input)

	set pc, kbloop

:kbloop
	ife [0x9000], 0   ; if there's no input...
	set pc, kbloop
	ife [0x9000], 0xA ; enter
	jsr enteredcommand
	ife [0x9000], 0x8 ; backspace
	jsr backspace

	set a, [0x9000]
	jsr printchar     ; printchar([0x9000])

	set a, [0x1337]   ; 0x1337 is the pointer to my buffer string
	set b, [0x9000]
	jsr strcat        ; strcat([0x1337], [0x9000])
	add [0x1337], 1

	set [0x9000], 0

	set pc, kbloop

:backspace
	sub [0x1335], 1    ; video pointer

        sub [0x1337], 1    ; delete last char

        set a, [0x1337]
	set [a], 0

        set a, 0
	jsr printchar      ; printchar(0)
	sub [0x1335], 1
	set [0x9000], 0
	set pc, kbloop

:reset
	set [0x1337], 0x1338 ; reset pointer
	set [0x1338], 0        ; reset string
	set [0x9000], 0      ; reset keyboard
	set [0x1336], 0      ; reset command recognized
	set pc, pop

:enteredcommand
	set a, echo
	set b, 0x1338
	jsr startswith        ; startswith(echo, 0x1338)
	ife y, 1
	set pc, echof

	set a, reddit
	set b, 0x1338
	jsr strcmp             ; strcmp(reddit, 0x1338)
	ife y, 1
	set pc, redditf

	set a, date
	set b, 0x1338
	jsr strcmp            ; strcmp(date, 0x1338)
	ife y, 1
	set pc, datef

	set a, clean
	set b, 0x1338
	jsr strcmp            ; strcmp(date, 0x1338)
	ife y, 1
	set pc, cleanf

	set a, vers
	set b, 0x1338
	jsr strcmp            ; strcmp(vers, 0x1338)
	ife y, 1
	set pc, versionf

	ifn a, 1
	set pc, unrecognizedf

	:enterdone
		jsr reset

		set pc, inputready


:echof
	jsr newline
	set a, echo
	jsr strlen
	add a, 1			; +1 to strlen, for the space

	set b, 0x1338
	add b, a 			; start at `strlen'
	set a, b		; string pointer
	jsr printnl

	set a, 1
	set pc, enterdone

:cleanf
	jsr clearScreen
	set [0x1335], 0x8000
	set a, 1
	set pc, enterdone

:clearScreen
    set i, sp
    set sp, 0x8200
	:clearScreen_loop
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		set push, 0
		ifg 0x8000, sp
			set pc, clearScreen_done
		set pc, clearScreen_loop
	:clearScreen_done
		set sp, i
		set pc, pop

:versionf
	jsr newline
	jsr reset
	set a, 1              ; return 1
	set pc, main

:unrecognizedf
	jsr newline
	set a, unrecognized
	jsr print
    set a, 0x1338
    jsr print
    set a, unrecognizedEnd
    jsr printnl

	set a, 1               ; return 1
	set pc, enterdone

:redditf
        set x, 1337
	jsr printnl
	set a, redditoutput
	jsr printnl
	set a, 1               ; return 1
	set pc, enterdone

:datef
	jsr printnl
	set a, dateoutput
	jsr printnl
	set a, 1               ; return 1
	set pc, enterdone


;; STANDARD FUNCTIONS OVER HER

:startswith
	set y, 0

	ife [a], 0
	set pc, startswith_end_success

	ife [a], [b]
	jsr checkzero

        ifn [a], [b]
        set pc, pop

	ife y, 1
	set pc, pop

	add a, 1
	add b, 1
	set pc, startswith

	:startswith_end_success
		set y, 1
		set pc, pop

:strlen
	set y, 0

	:strlen_begin
		ife [a], 0
		set pc, strlen_end

		add y, 1
		add a, 1
		set pc, strlen_begin

	:strlen_end
		set a, y
		set pc, pop


:strcmp
	set y, 0

	ife [a], [b]
	jsr checkzero

	ife y, 1
	set pc, pop

	ifn [a], [b]
	set pc, pop

	add a, 1
	add b, 1
	set pc, strcmp

:checkzero
	ife [a], 0
	set y, 1
	set pc, pop

:strcat
	set [a], b
	add a, 1
        add b, 1
	set [a], 0
	set pc, pop


:printnl   ; shortcut
	jsr print
	jsr newline
	set pc, pop

:print
	set i, a
	:doprint
		ifg [0x1335], 0x81ff ; end of vidmem
		set [0x1335], 0x8000
		ife [i], 0
		set pc, pop
		set a, [i]
		jsr printchar
		add i, 1
		set pc, doprint

:printchar
	set b, [0x1335]
	bor a, 0xf100 ; color :D
	set [b], a
	add [0x1335], 1
	set pc, pop

:newline

	set i, [0x1335]
	mod i, 32 ; width
	set z, 32
	sub z, i
	add [0x1335], z
	set pc, pop

:end set pc, end