-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflbus.asm
767 lines (527 loc) · 15.3 KB
/
flbus.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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
DEVICE ZXSPECTRUM48
; This demo scrolls (Cobra Style) at 50 FPS using the Floating Bus trick
; on ll moels
GFX0 equ gfx
GFX1 equ gfx
; Store source graphics in lower memory
org $6000
gfxsource:
defb %11111111,%11111111,%11111111,%11111111,%11111111,%10000000,%00000000,%00000000
defb %11000000,%00000000,%00000000,%00000000,%00000001,%10000000,%00000000,%00000000
defb %11001111,%11111111,%11111111,%11111111,%11111001,%10000000,%00000000,%00000000
defb %11001111,%11111111,%11111111,%11111111,%11111001,%10000000,%00000000,%00000000
defb %11001111,%11111111,%11111111,%11111111,%11111001,%10000000,%00000000,%00000000
defb %11001111,%11111111,%11111111,%11111111,%11111001,%10000000,%00000000,%00000000
defb %11000000,%00000000,%00000000,%00000000,%00000001,%10000000,%00000000,%00000000
defb %11111111,%11111111,%11111111,%11111111,%11111111,%10000000,%00000000,%00000000
; Start in upper memory
org $8000
; Start
AppEntry:
; check ROM variable for +2A/+3
; Note, the code in this listing is set up for +2A/+3
; If test shows we are not, we meed to change the code
ld a,($0b53) ; (2899) +2A/+3 ROMs return 126
cp $7e ; If 126 ($7e) then +2A or +3
jr z,AppEntry_go ; so do a different FL_BUS Check
; http://sky.relative-path.com/zx/floating_bus.html
; https://spectrumcomputing.co.uk/forums/viewtopic.php?f=6&t=646&start=40
; We need to modify the 3 bytes LD A,($5800) to NOP,NOP,DEC HL
ld a,$00
ld (v_sync),a ; Add a NOP, purely so easier to disassemble
ld hl,v_sync+2
ld (hl),$2b ;opcode for the DEC HL instruction [6]
; Now when looping ensure we jump to v_sync+2 (Not NOP,NOP but byte 3, DEC HL)
ld (v_sync_sw+1),hl ;redirect the JP NZ,** to DEC HL
ld a,$40 ;change top half of port addr (must be in the $40–$7f range)
ld (port1+1),a
ld a,$ff ;change bottom half of port addr
ld (port2+1),a
ld a,6
ld (fl_bus+1),a ; change border colour, yellow if 48/128/2 blue if 2A,2B,3
; For example the code for 2A/+3 Should look like this:
;port1:
; ld de,$470f ; ATTR color ($01000111=$47) into D, top half of port to read into E
; For 48k, $4740 and 2A $470F
; v_sync:
; ld a,($5800) ;[13]point to contended memory and fetch a "blanking" attr
;or DEC HL [6] for the 48K/128K/+2
; ld a,e ;[4]top half of port into A
;port2:
; in a,($fd) ;[11]read port formed by A (MSB) and FDh (LSB) into A ($FF for 48k)
; cp d ;[4]test for ATTR color
;v_sync_sw:
; jp nz,v_sync ;[10]
; For 48k and 128k, and +2
;port1:
; ld de,$47FF ; ATTR color ($01000111=$47) into D, top half of port to read into E
; For 48k, $4740 and 2A $470F
; v_sync:
; NOP,NOP ; Note this code is redundant as it is only $2b (dec hl) we jump to,
; purely to delay ($00,$00,$2b)
; v_sync_extra:
; dec hl
; ld a,e ;[4]top half of port into A
;port2:
; in a,($ff) ;[11]read port formed by A (MSB) and FDh (LSB) into A ($FF for 48k)
; cp d ;[4]test for ATTR color
;v_sync_sw:
; jp nz,v_sync_extra ;[10]
AppEntry_go:
di ; Disable interrupts (We rely on Floating bus)
; Copy from lower ram to upper ram
ld hl,gfxsource
ld de,gfx
ld bc,255
ldir
; 1 Copy unexpanded to all 8 slots
ld hl,gfx
ld de,gfx+256
ld b,7
cpy1:
push bc
ld b,255
cpy2:
ld a,(hl)
ld (de),a
inc l
inc e
djnz cpy2
inc h
inc d
pop bc
djnz cpy1
; 2 Rotate
; HL = gfx to rotate
; A = number of rotations
; shbit = byte to store offset
ld hl,gfx
ld a,7
call ROTATE_BYTES
ld hl,gfx+256
ld a,6
call ROTATE_BYTES
ld hl,gfx+512
ld a,5
call ROTATE_BYTES
ld hl,gfx+768
ld a,4
call ROTATE_BYTES
ld hl,gfx+1024
ld a,3
call ROTATE_BYTES
ld hl,gfx+1024+256
ld a,2
call ROTATE_BYTES
ld hl,gfx+1024+512
ld a,1
call ROTATE_BYTES
;ld hl,gfx+1024+768
;ld a,1
;call ROTATE_BYTES
xor a
ld (screenoffset),a
ld bc,767 ;
ld hl,$5800 ;
ld (hl),%01001101
ld de,$5801 ;
ldir
; FL_BUS = 01000111
ld a,%01000111 ; Screen Black, bright white
ld ($5860),a ;
ld bc,18*32 ;
ld hl,$5860 ;
ld de,$5861 ;
ldir ;
ld de,31-2
ld hl,$5800
ld b,24
ae1:
ld (hl),0
inc hl
ld (hl),0
add hl,de
ld (hl),0
inc hl
ld (hl),0
inc hl
djnz ae1
; Lets check the Floating Bus for the start of bright white
fl_bus:
; Change the border to zero to show where we are
ld a,1
out ($fe),a ; border change
port1:
ld de,$470f ;ATTR color ($01000111=$47) into D, top half of port to read into E
; For 48k, $4740 and 2A $470F
v_sync:
ld a,($5800) ;[13]point to contended memory and fetch a "blanking" attr
;or DEC HL [6] for the 48K/128K/+2
ld a,e ;[4]top half of port into A
port2:
in a,($fd) ;[11]read port formed by A (MSB) and FDh (LSB) into A ($FF for 48k)
cp d ;[4]test for ATTR color
v_sync_sw:
jp nz,v_sync ;[10]
; ----------------------------------------------------------------------------------
; Draw each row from top to bottom using modifying code
; Draw top Row (Part)
row0: xor a: out ($fe),a : ld hl,row0data : ld de,row1 : jp buff;
row1: ld hl,row1data : ld de,row2 : jp buff;
row2: ld hl,row2data : ld de,row3 : jp buff;
row3: ld hl,row3data : ld de,row4 : jp buff;
row4: ld hl,row4data : ld de,row5 : jp buff;
row5: ld hl,row5data : ld de,row6 : jp buff;
row6: ld hl,row6data : ld de,row7 : jp buff;
row7: ld hl,row7data : ld de,row8 : jp buff;
row8: ld hl,row8data : ld de,row9 : jp buff;
row9: ld hl,row9data : ld de,rowA : jp buff;
rowA: ld hl,rowAdata : ld de,rowB : jp buff;
rowB: ld hl,rowBdata : ld de,rowC : jp buff;
rowC: ld hl,rowCdata : ld de,rowD : jp buff;
rowD: ld hl,rowDdata : ld de,rowE : jp buff;
rowE: ld hl,rowEdata : ld de,rowF : jp buff;
; Draw bottom (Part)
rowF: ld hl,rowFdata : ld de,row10: jp buff;
row10: ld hl,row10data : ld de,row11: jp buff;
row11: ld hl,row11data : ld de,player: jp buff;
player:
ld hl,scroll
ld (Draw_Player_return+1),hl
ld hl,$40A4
ld (Draw_Player+1),hl
jp Draw_Player
;call pause
scroll:
; call pause
; Move by 1 pixels (GFX+256)
ld a,(scrollposition)
inc a
and 7
ld (scrollposition),a
jp nz,fl_bus
; Shift the screen
ld a,(screenoffset)
xor 1
ld (screenoffset),a
and 1
jp nz,fl_bus
ld a,(mapposition)
dec a
jp z,fl_bus
ld (mapposition),a
jp fl_bus
buff:
ld (buff1+1),hl ; Poke the locaion of the row data
ld (jumper+1),de ; Poke where to jump to at the end of drawing a row
buff1:
ld sp,$0000 ; Row Data
pop hl ; Get GFX location for tiles
ld a,(scrollposition)
add a,h
ld h,a
ld (spstore1+1),hl ; Store GFX
pop hl ; Get Screen Location for Row
ld a,(screenoffset) ; Check to see if we need to shift by 1 char to the left
and 255
jr z,buff2
dec l ; Move the column back one
buff2:
ld (spstore2+1),hl ;
pop hl ; Get location of level data (Push for each row, will be 256 long)
ld a,(mapposition)
add l
ld l,a
ld de,buffer ; Copy from level data to buffer
; TODO: Offset on 256 row poke above
ldi ; Copy 15 bytes (30 chars)
ldi ;
ldi ;
ldi ;
ldi ;
ldi ;
ldi ;
ldi ;
ldi ;
ldi ;
ldi ;
ldi ;
ldi ;
ldi ;
ldi ;
ld a,8 ;
blp1:
ex af,af' ;;;
spstore1:
ld sp,$0000 ;
pop af ;
pop bc ;
pop de ;
pop hl ; Image or Blank Space
ld (spstore1+1),sp ; Store SP for GFX position
spstore2:
ld sp,$0000 ; Load screen address to push to
; Self modified push to screen
blanks:
;ld hl,$0000
buffer:
nop ; Buffer to write pushes to
nop ;
nop ;
nop ;
nop
nop ;
nop ;
nop ;
nop
nop ;
nop ;
nop ;
nop
nop ;
nop ;
ld (spstore2+1),sp ; Next Line
ld hl,$0000 ; Copy SP to HL
add hl,sp ;
add30:
ld a,30
add a,l
ld l,a
inc h
ld (spstore2+1),hl ;
ex af,af' ; Loop 8 times
dec a ;
jr nz,blp1 ;
jumper:
jp $0000 ; Repeat
pause:
ld bc,60000
bb1:
dec bc
ld a,c
or b
jr nz,bb1
ret
Draw_Player:
ld hl,$507D ; Screen Position
ld sp,willy ; row 8 would need 64 adding, 7,56 etc (Like Bipboi)
; Then add 256 for each rotated frame (Add d,frame number 0-7)
xor a
ld (collision),a
ld a,8
Draw_Player_loop
ex af,af'
pop de : pop bc
ld a,(hl)
and e
jr nz,col
ld a,(hl)
or e
ld (hl),a
inc l
ld a,(hl)
and d
jr nz,col
ld a,(hl)
or d
ld (hl),a
dec l
inc h
ld a,(hl)
and c
jr nz,col
ld a,(hl)
or c
ld (hl),a
inc l
ld a,(hl)
and b
jr nz,col
ld a,(hl)
or b
ld (hl),a
dec l
inc h
ld a,h
and 7
jr nz,Draw_Player_next
ld a,l
add a,32
ld l,a
jr c,Draw_Player_next
ld a,h
sub 8
ld h,a
Draw_Player_next
ex af,af'
dec a
jr nz,Draw_Player_loop
xor a
ld ($5800),a
Draw_Player_return
jp $0000
col:
; Change the border to zero to show where we are
ld a,%01101010
ld ($5800),A
jp Draw_Player_return
scrollposition DEFB 0
screenoffset DEFB 0
shbit DEFB 0
mapposition: DEFB 240
collision: DEFB 0
; HL = gfx to rotate
; A = number of rotations
; shbit = byte to store offset
ROTATE_BYTES:
EX AF,AF'
XOR A
LD (shbit),A
EX AF,AF'
LD B,A
SH5:
PUSH HL
PUSH BC
LD B,8*8 ; 4 Columns in row4
SH2:
LD A,(shbit) ; Will be either %10000000 or %00000000
LD C,A
; C holds the BIT if after shifting it exits
LD A,(HL) ; Get graphic byte (e.g %00111101)
AND 1 ; Leave the lowest bit (e.g. %00000001)
RRC A ; Rotate Right and Carry (e.g. a = %10000000)
LD (shbit),A ; SHBIT stores a 128 or a 0 (e.g. %10000000)
LD A,(HL) ; Get the Byte to shift
RR A ; Rotate Right
AND %01111111 ; Remove the left hand bit
OR C ; Add on the Shifted Bit
SH2C
LD (HL),A ; Put back into the graphic
INC L
;ADD HL,DE ; Next line byte (48 bytes after this one, 1 column)
DJNZ SH2 ; Repeat for all the columns
POP BC
POP HL
XOR A
LD (shbit),A
DJNZ SH5 ; Repeat for the number of times it needs rotating
RET
; So we need to have the graphics unshifted
; then copy unshifed to all 8 slots
; then starting with the last to the first, rotate right 7,6,5,4,3,2,1
; e.g. unshifted is a gfx
; copy to gfx+256,gfx+512...gfx+(7*256)
; then starting at 8*256, call rotes with a=7 and hl=7*256
; then a=6 and hl = 6*256
; finally last one by 8
; GFX are 0,left,middle1,middle2,end,0
align 256
gfx:
; So byte 0,1 are left,2,3 middle,4,5 are end, but middle needs to wrap internally
;defb %00000001,%11111111,%11111111,%11111111,%11111111,%00000000
;defb 1,0,1,0,1,0
;defb 1,0,1,0,1,0
;defb 1,0,1,0,1,0
;defb 1,0,1,0,1,0
;defb 1,0,1,0,1,0
;defb 1,0,1,0,1,0
;defb %00000001,%11111111,%11111111,%11111111,%11111111,%00000000
; for example
; 00000001 11111111 = first 2, we need to scroll 7 times but
; The middle 2 need to wrap around when scrolled
; 00000001
defs 2048
align 256
willy:
defb %00111100,%00000000
defb %01111110,%00000000
defb %11011111,%00000000
defb %11111111,%00000000
defb %11111111,%00000000
defb %11111111,%00000000
defb %01111110,%00000000
defb %00111100,%00000000
; Right to left, Column 28 to 2
align 256 ;
; The stack will be one less than the value specified here
; so if SP=$407F, Pushing a value will polace it at $407E and $407D
row0data: defw GFX0 : defw $407F : defw row0leveldata+256
row1data: defw GFX0 : defw $409F : defw row1leveldata+256
row2data: defw GFX0 : defw $40BF : defw row2leveldata+256
row3data: defw GFX0 : defw $40DF : defw row3leveldata+256
row4data: defw GFX0 : defw $40FF : defw row4leveldata+256
; Next 3rd
row5data: defw GFX0 : defw $481F : defw row5leveldata+256
row6data: defw GFX0 : defw $483F : defw row6leveldata+256
row7data: defw GFX0 : defw $485F : defw row7leveldata+256
row8data: defw GFX0 : defw $487F : defw row8leveldata+256
row9data: defw GFX0 : defw $489F : defw row9leveldata+256
rowAdata: defw GFX0 : defw $48BF : defw rowAleveldata+256
rowBdata: defw GFX0 : defw $48DF : defw rowBleveldata+256
rowCdata: defw GFX0 : defw $48FF : defw rowCleveldata+256
; Next 3rd
rowDdata: defw GFX0 : defw $501F : defw rowDleveldata+256
rowEdata: defw GFX0 : defw $503F : defw rowEleveldata+256
rowFdata: defw GFX0 : defw $505F : defw rowFleveldata+256
row10data: defw GFX0 : defw $507F : defw row10leveldata+256
row11data: defw GFX0 : defw $509F : defw row11leveldata+256
align 256
row0leveldata:
include "mapbit.asm"
align 256
row1leveldata:
include "mapbit.asm"
align 256
row2leveldata:
include "mapbit.asm"
align 256
row3leveldata:
include "mapbit.asm"
align 256
row4leveldata:
include "mapbit.asm"
align 256
row5leveldata:
include "mapbit.asm"
align 256
row6leveldata:
include "mapbit.asm"
align 256
row7leveldata:
include "mapbit.asm"
align 256
row8leveldata:
include "mapbit.asm"
align 256
row9leveldata:
include "mapbit.asm"
align 256
rowAleveldata:
include "mapbit.asm"
align 256
rowBleveldata:
include "mapbit.asm"
align 256
rowCleveldata:
include "mapbit.asm"
align 256
rowDleveldata:
include "mapbit.asm"
align 256
rowEleveldata:
include "mapbit.asm"
align 256
rowFleveldata:
include "mapbit.asm"
align 256
row10leveldata:
include "mapbit.asm"
align 256
row11leveldata:
include "mapbit.asm"
align 256
row12leveldata:
include "mapbit.asm"
; These generate some output files
savetap "./flscroll.tap",AppEntry
;savesna "src/tests/willyscroll/flscroll.sna",AppEntry