-
Notifications
You must be signed in to change notification settings - Fork 1
/
drv_s64.asm
520 lines (432 loc) · 8.02 KB
/
drv_s64.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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
;basic s64 driver
;uses fonts with letters in RIGHT 5 bits (ie. 3 left are 0)
;creates gr.8 dlist with LMS every 8th line to speed up scrolling
;font 1 blatantly stolen from SDX CON64.SYS driver
;letter is 5x8 bits
;if offset is <= 3
;masks would be
;0 - 00000111
;1 - 10000011
;2 - 11000001
;3 - 11100000
;and then oring the left-shifted char
;else
;4 - 11110000 01111111
;5 - 11111000 00111111
;6 - 11111100 00011111
;7 - 11111110 00001111
;and then oring the right-shifted char. This would need to be 2 byte operation
;64 chars = 8x5 byte blocks = 40 bytes
;block:
;char 0 -pixels 00-04 - byte 0, shift -3
;char 1 -pixels 05-09 - byte 0-1, shift +2
;char 2 -pixels 10-14 - byte 1, shift -1
;char 3 -pixels 15-19 - byte 1-2, shift +4
;char 4 -pixels 20-24 -byte 2-3, shift +1
;char 5 -pixels 25-29 - byte 3, shift -2
;char 6 -pixels 30-34 - byte 3-4, shift +3
;char 7 -pixels 35-39 - byte 4, shift 0
;0 1 2 3 4
;0123456701234567012345670123456701234567
;XXXXX XXXXX XXXXX XXXXX
; XXXXX XXXXX XXXXX XXXXX
;rest is completely same as in s80 driver
SCREEN_WIDTH_BYTES = SCREEN_WIDTH_CHARS * 5 / 8
LAST_DLIST_LMS = DLIST + 3 + 23*10 + 1
DLIST = $BF00
GMEM = $A100
SCREEN_LINES_TOTAL = 24
SCREEN_WIDTH_CHARS = 64
SCREEN_WIDTH_CHARS_PRINTED = SCREEN_WIDTH_CHARS-1
graphics_start_page = >GMEM
font1:
ins "drv_s64_fnt1.fnt"
font3:
ins "drv_s64_fnt3.fnt"
line_table: :screen_lines_total .BYTE 0
; ---------------------------------------------------------------------------
s64_last_line: .BYTE 0
graphics_cls:
LDX #0
LDY #SCREEN_LINES_TOTAL
graphics_cls_partial:
STY s64_last_line
s6cp_2:
TXA
PHA
LDA line_table,X
TAY
LDA DLIST, Y
STA s6cp_1+1
LDA DLIST+1, Y
STA s6cp_1+2
LDX #$01
LDY #$40
LDA #$00
s6cp_1: STA.a $0000
INC s6cp_1+1
BNE s6cp_4
INC s6cp_1+2
s6cp_4:
DEY
BNE s6cp_1
DEX
BPL s6cp_1
PLA
TAX
INX
CPX s64_last_line
BNE s6cp_2
s6cp_3: RTS
; ---------------------------------------------------------------------------
graphics_init:
;dlist creation
LDY #0
LDX #3
LDA #$70
dl1: STA DLIST, Y
INY
DEX
BNE dl1
LDX #0
dl3: TXA
PHA
LDA #$40+$F
STA DLIST, Y
INY
TYA
STA line_table,X
gmp1: LDA #<GMEM
STA DLIST, Y
INY
gmp2: LDA #>GMEM
STA DLIST, Y
INY
LDA gmp1+1
CLC
ADC #$40
STA gmp1+1
LDA gmp2+1
ADC #$01
STA gmp2+1
LDX #7
LDA #$F
dl2: STA DLIST, Y
INY
DEX
BNE dl2
PLA
TAX
INX
CPX #SCREEN_LINES_TOTAL
BNE dl3
LDA #$41
STA DLIST, Y
LDA #<DLIST
STA DLIST+1,Y
LDA #>DLIST
STA DLIST+2,Y
JSR graphics_cls
LDA #$0C
STA COLOR3
LDA #$00
STA COLOR2
LDA #<DLIST
STA SDLSTL
LDA #>DLIST
STA SDLSTH
RTS
; ---------------------------------------------------------------------------
;A - font number
graphics_set_font:
CMP #3
BEQ gsf1
LDA #<font1
STA gpc_ptch1+1
LDA #>font1
STA gpc_ptch2+1
RTS
gsf1:
LDA #<font3
STA gpc_ptch1+1
LDA #>font3
STA gpc_ptch2+1
RTS
; ---------------------------------------------------------------------------
s64col2byte .macro col
.BYTE [:col*5/8]
.endm
s64_cols: :64 s64col2byte(:1)
s64_shift_m .macro shift
.if :shift <= 0
.BYTE -:shift
.else
.BYTE $80 | [:shift-1]
.endif
.endm
s64_shifts:
s64_shift_m( -3 ) ;char 0 -pix 00-04 - byte 0, shift -3
s64_shift_m( +2 ) ;char 1 -pix 05-09 - byte 0-1, shift +2
s64_shift_m( -1 ) ;char 2 -pix 10-14 - byte 1, shift -1
s64_shift_m( +4 ) ;char 3 -pix 15-19 - byte 1-2, shift +4
s64_shift_m( +1 ) ;char 4 -pix 20-24 -byte 2-3, shift +1
s64_shift_m( -2 ) ;char 5 -pix 25-29 - byte 3, shift -2
s64_shift_m( +3 ) ;char 6 -pix 30-34 - byte 3-4, shift +3
s64_shift_m( -0 ) ;char 7 -pix 35-39 - byte 4, shift 0
s64_mask_l:
.BYTE %11100000 ;-0
.BYTE %11000001 ;-1
.BYTE %10000011 ;-2
.BYTE %00000111 ;-3
s64_mask_r1:
.BYTE %11110000 ;+1
.BYTE %11111000 ;+2
.BYTE %11111100 ;+3
.BYTE %11111110 ;+4
s64_mask_r2:
.BYTE %01111111 ;+1
.BYTE %00111111 ;+2
.BYTE %00011111 ;+3
.BYTE %00001111 ;+4
s64_c1: .BYTE 0
s64_c2: .BYTE 0
graphics_put_char:
TAX
BMI s6pc4
LDY #0
BEQ s6pc3
s6pc4: LDY #%00011111
s6pc3: STY s6_ptch_inv+1
AND #$7F
LDY #$07
STY s6_ptch2+1
LDY #00
STY temp_gr2_lo
ASL
ROL temp_gr2_lo
ASL
ROL temp_gr2_lo
ASL
ROL temp_gr2_lo
CLC
gpc_ptch1: ADC #<font1
STA s6_ptch1+1
LDA temp_gr2_lo
gpc_ptch2: ADC #>font1
STA s6_ptch1+2
;s6_ptch1 is now pointing to first byte of character data in respective font
LDX ROWCRS ;cursor line
LDA line_table,X
TAX
LDY COLCRS
LDA DLIST, X
CLC
ADC s64_cols,Y
STA temp_gr1_lo
LDA DLIST+1, X
ADC #0
STA temp_gr1_hi
;in temp_gr1 we now have the exact byte address of first graphics memory byte
LDA COLCRS
AND #$07
TAY
LDA s64_shifts, Y
STA s6_ptch3+1
;this is main char printing loop
s6_ptch1: LDA.a $0000
s6_ptch_inv: EOR #$00
STA s64_c1
;so right now, we have the character data in s61_c1, with correct inverse
s6_ptch3: LDA #$00
BMI s6_pn0
;positive, so we're doing one-byte operation, shifting left
TAY
TAX
CPY #0
BEQ s6_pl2
s6_pl1: ASL s64_c1
DEY
BNE s6_pl1
s6_pl2: LDA (temp_gr1_lo),Y
AND s64_mask_l, X
ORA s64_c1
STA (temp_gr1_lo),Y
JMP s6_nxt_line
s6_pn0:
;negative, so we're doing two-byte operation, shifting right
AND #$7F
TAY
TAX
INY
LDA #$00
STA s64_c2
s6_nl1: LSR s64_c1
ROR s64_c2
DEY
BNE s6_nl1
s6_nl2: LDA (temp_gr1_lo),Y
AND s64_mask_r1,X
ORA s64_c1
STA (temp_gr1_lo),Y
INY
LDA (temp_gr1_lo),Y
AND s64_mask_r2,X
ORA s64_c2
STA (temp_gr1_lo),Y
s6_nxt_line:
s6_ptch2: LDA #$00
BNE s6_nxt_line2
RTS
s6_nxt_line2: DEC s6_ptch2+1
INC s6_ptch1+1
BNE s6_nl2a
INC s6_ptch1+2
s6_nl2a:
LDA temp_gr1_lo
CLC
ADC #SCREEN_WIDTH_BYTES
STA temp_gr1_lo
BCC s6_ptch1
INC temp_gr1_hi
JMP s6_ptch1
; ---------------------------------------------------------------------------
graphics_scroll:
LDX #0
;in X is from
graphics_scroll_partially:
TXA
PHA
;this should clear top line
TAY
INY
JSR graphics_CLS_PARTIAL
PLA
PHA
TAX
LDA line_table,X
TAX
LDA DLIST,X
STA s6sp_ptch1+1
LDA DLIST+1,X
STA s6sp_ptch2+1
PLA
TAX
loop_over_screen:
CPX #[SCREEN_LINES_TOTAL-1]
BEQ s6sp_7
TXA
PHA
LDA line_table,X
TAY
LDA line_table+1,X
TAX
LDA DLIST,X
STA DLIST,Y
LDA DLIST+1,X
STA DLIST+1,Y
PLA
TAX
INX
JMP loop_over_screen
s6sp_7:
s6sp_ptch1: LDA #$00
STA LAST_DLIST_LMS
s6sp_ptch2: LDA #$00
STA LAST_DLIST_LMS+1
RTS
; ---------------------------------------------------------------------------
inverted_MORE_string:
DTA '[MORE]'*
more_length = * - inverted_MORE_string
graphics_display_more:
LDA ROWCRS
PHA
LDA COLCRS
PHA
LDA #SCREEN_LINES_TOTAL-1
STA ROWCRS
LDA #0
STA COLCRS
LDY #0
op0nl_1: TYA
PHA
LDA inverted_MORE_string,Y
JSR graphics_put_char
INC COLCRS
PLA
TAY
INY
CPY #more_length
BNE op0nl_1
PLA
STA COLCRS
PLA
STA ROWCRS
RTS
graphics_erase_more:
LDA ROWCRS
PHA
LDA COLCRS
PHA
LDA #SCREEN_LINES_TOTAL-1
STA ROWCRS
LDA #0
STA COLCRS
LDY #0
LDY #0
op0nl_2: TYA
PHA
LDA #' '
JSR graphics_put_char
INC COLCRS
PLA
TAY
INY
CPY #more_length
BNE op0nl_2
PLA
STA COLCRS
PLA
STA ROWCRS
RTS
; ---------------------------------------------------------------------------
graphics_pmg_cursor_on .macro
LDA COLCRS ; moves cursor
ASL
ASL
CLC
ADC COLCRS
LSR
CLC
ADC #$30
STA HPOSM0 ;moves cursor based on COLCRS
LDA ROWCRS
ASL
ASL
ASL
CLC
ADC #39
TAY ;converts ROWCRS to byte to display pmg cursor
LDA #3
STA pmg_cursor_curr_shape_f8
STA pmg_missiles_mem,Y
.endm
graphics_pmg_cursor_xor .macro
LDA pmg_cursor_curr_shape_f8
EOR #3
STA pmg_cursor_curr_shape_f8
STA pmg_missiles_mem,Y
.endm
graphics_pmg_cursor_off .macro
LDA ROWCRS
ASL
ASL
ASL
CLC
ADC #39
TAY ;converts ROWCRS to byte to display pmg cursor
LDA #0
STA pmg_missiles_mem,Y
.endm
graphics_pmg_color = $0C
graphics_pmg_size = 0