summaryrefslogtreecommitdiffstats
path: root/hacks/images/m6502/lines.asm
blob: 152d5fb7715dc020117801f8bb7004b4bebf5a17 (plain) (blame)
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
; -*- mode: c; tab-width: 4; fill-column: 128 -*-
; vi: set ts=4 tw=128:

; Lines, Copyright (c) 2018 Dave Odell <dmo2118@gmail.com>
;
; Permission to use, copy, modify, distribute, and sell this software and its
; documentation for any purpose is hereby granted without fee, provided that
; the above copyright notice appear in all copies and that both that
; copyright notice and this permission notice appear in supporting
; documentation.  No representations are made about the suitability of this
; software for any purpose.  It is provided "as is" without express or 
; implied warranty.

; Another port of 20 year old QBasic code.



main_loop:
	lda #$00
	sta $0

y_loop:
	ldx $0

	lda #1
	bit $1
	beq left_right

	; Up-down. Skip all blank columns.
	lda x_px0,x
	and #1
	bne fill
	jmp next_y ; next_y is too far to conditional-branch from here.

clear:
	ldx #1
	lda $0
	clc
	adc #$20
	tay

	sec
clear_loop:
	lda #0 ; $fe
	sta $0200,y
	sta $0240,y
	sta $0280,y
	sta $02c0,y
	sta $0300,y
	sta $0340,y
	sta $0380,y
	sta $03c0,y
	sta $0400,y
	sta $0440,y
	sta $0480,y
	sta $04c0,y
	sta $0500,y
	sta $0540,y
	sta $0580,y
	sta $05c0,y
	tya
	sbc #$20
	tay
	dex
	bpl clear_loop
	jmp next_y

left_right:
	; Repaint columns that were previously on.
	lda x_px0,x
	bit const_two
	beq next_y
	lda x_px0,x
	and #1
	beq clear
	;jmp fill

fill:
	ldx #1
	lda $0
	clc
	adc #$20
	tay

	sec
fill_loop:
	; 3 * 2 * 16 = 96 bytes
	lda y_px0,x
	sta $0200,y
	lda y_px1,x
	sta $0240,y
	lda y_px2,x
	sta $0280,y
	lda y_px3,x
	sta $02c0,y
	lda y_px4,x
	sta $0300,y
	lda y_px5,x
	sta $0340,y
	lda y_px6,x
	sta $0380,y
	lda y_px7,x
	sta $03c0,y
	lda y_px8,x
	sta $0400,y
	lda y_px9,x
	sta $0440,y
	lda y_pxa,x
	sta $0480,y
	lda y_pxb,x
	sta $04c0,y
	lda y_pxc,x
	sta $0500,y
	lda y_pxd,x
	sta $0540,y
	lda y_pxe,x
	sta $0580,y
	lda y_pxf,x
	sta $05c0,y
	tya
	sbc #$20
	tay
	dex
	bpl fill_loop
	;jmp next_y

next_y:
	inc $0
	lda #32
	cmp $0
	beq shift
	jmp y_loop

shift:
	lda $fe
	and #$3
	sta $1 ; Left, down, right, up.
	beq shift_x1

	cmp #2
	bmi shift_y1
	beq shift_x0

shift_y0:
	ldx #0
shift_y0_loop:
	lda y_px0,x
	eor y_px00,x
	sta y_px0,x
	inx
	cpx #31
	bne shift_y0_loop
	jmp main_loop

shift_y1:
	ldx #30
shift_y1_loop:
	lda y_px00,x
	eor y_px0,x
	sta y_px00,x
	dex
	bpl shift_y1_loop
	jmp main_loop

shift_x0:
	ldx #0
shift_x0_loop:
	; px[0] = ((px[0] ^ px[1]) & 1) | (px[1] << 1)
	lda x_px0,x
	eor x_px00,x
	lsr ; Save EOR bit in carry flag.
	lda x_px00,x
	rol ; Restore EOR bit.
	sta x_px0,x
	inx
	cpx #31
	bne shift_x0_loop
	jmp main_loop

shift_x1:
	ldx #30
shift_x1_loop:
	lda x_px00,x
	eor x_px0,x
	lsr
	lda x_px0,x
	rol
	sta x_px00,x
	dex
	bpl shift_x1_loop
	jmp main_loop

y_px0:
	dcb 0
y_px00:
	dcb 0
y_px1:
	dcb 0, 0
y_px2:
	dcb 0, 0
y_px3:
	dcb 0, 0
y_px4:
	dcb 0, 0
y_px5:
	dcb 0, 0
y_px6:
	dcb 0, 0
y_px7:
	dcb 0, 0
y_px8:
	dcb 1, 0
y_px9:
	dcb 0, 0
y_pxa:
	dcb 0, 0
y_pxb:
	dcb 0, 0
y_pxc:
	dcb 0, 0
y_pxd:
	dcb 0, 0
y_pxe:
	dcb 0, 0
y_pxf:
	dcb 0, 0

	; Bit 0: black row, bit 1: changed row
x_px0:
	dcb 0
x_px00:
	dcb    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	dcb 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

const_two: ; lolz
	dcb 2

;#include "screenhack.h"
;
;struct _lines
;{
;	unsigned width, height;
;	unsigned long delay;
;	GC gc;
;};
;
;static void *lines_init(Display *display, Window window)
;{
;	struct _lines *self = malloc(sizeof(*self));
;	XGCValues gcv;
;	XWindowAttributes xgwa;
;
;	if(!self)
;		abort();
;
;	XGetWindowAttributes(display, window, &xgwa);
;	self->width = xgwa.width;
;	self->height = xgwa.height;
;
;	self->delay = get_integer_resource(display, "delay", "Integer");
;
;	gcv.function = GXxor;
;	gcv.foreground = get_pixel_resource(display, xgwa.colormap, "foreground", "Foreground");
;	self->gc = XCreateGC(display, window, GCFunction | GCForeground, &gcv);
;
;	XDrawPoint(display, window, self->gc, xgwa.width >> 1, xgwa.height >> 1);
;
;	return self;
;}
;
;static unsigned long lines_draw(Display *display, Window window, void *self_raw)
;{
;	struct _lines *self = self_raw;
;	static const XPoint xy[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
;	const XPoint *p = xy + NRAND(4);
;
;	XCopyArea(display, window, window, self->gc, 0, 0, self->width, self->height, p->x, p->y);
;	return self->delay;
;}
;
;static void lines_reshape(Display *display, Window window, void *self_raw, unsigned width, unsigned height)
;{
;	struct _lines *self = self_raw;
;	self->width = width;
;	self->height = height;
;}
;
;static Bool lines_event(Display *display, Window window, void *self_raw, XEvent *event)
;{
;	return False;
;}
;
;static void lines_free(Display *display, Window window, void *self_raw)
;{
;	struct _lines *self = self_raw;
;	XFreeGC(display, self->gc);
;	free(self);
;}
;
;static const char *lines_defaults[] =
;{
;	"*fpsSolid:         true",
;	"*delay:            30000",
;	0
;};
;
;static XrmOptionDescRec lines_options [] =
;{
;	{"-delay", ".delay",   XrmoptionSepArg, 0},
;	{0, 0, 0, 0}
;};
;
;XSCREENSAVER_MODULE ("Lines", lines)