-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlibperspective.asm
More file actions
1633 lines (1502 loc) · 49.5 KB
/
libperspective.asm
File metadata and controls
1633 lines (1502 loc) · 49.5 KB
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
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;******************************************************************************
; Perspective - A VMU Graphics Library
;******************************************************************************
; Version: 0.1
; ------------
; Perspective is a drawing library for the VMU which uses WRAM to allow for
; fast, artifact-free drawing to VMU XRAM.
;
; (C) Kresna Susila - 2018
;******************************************************************************
; Resource Usage:
; ---------------
; RAM1: $F2-$FF (Adjustable, be cautious of sizes)
; WRAM1: $00-$BF (Adjustable with User Constants)
;
;------------------------------------------------------------------------------
; User Macros:
; ------------
;
; Background Drawing Macros:
; --------------------------
;
; P_Draw_Background
; -----------------
; Args: 1
; Accepts: Background Image Address (2 bytes)
; Destroys: ACC, C, TRL, TRH, VRMAD1, VRMAD2, VSEL, PSW
; Copies a bitmap 48x32 pixels in size. Uses standard Perspective
; image format, but ignores size bits. Accepts only an address from RAM.
;
; P_Draw_Background_Constant
; -----------------
; Args: 1
; Accepts: Background Image Address (16bit Constant)
; Destroys: ACC, C, TRL, TRH, VRMAD1, VRMAD2, VSEL, PSW
; Copies a bitmap 48x32 pixels in size. Uses standard Perspective
; image format, but ignores size bits. Accepts only constants.
;
;
; Sprite Drawing Macros:
; ----------------------
;
; P_Draw_Sprite
; ----------------------
; Args: 3
; Accepts: Sprite Address (1 bytes)
; Sprite X Coordinate (1 byte)
; Sprite Y Coordinate (1 byte)
; Destroys: ACC, B, C, TRL, TRH, VRMAD1, VRMAD2, VSEL, PSW,
; @R0 Pointer
; Draws a sprite directly onto the screen without a sprite mask. Sprites
; use the standard format. Accepts only RAM addresses for all arguments.
;
; P_Draw_Sprite_Constant
; ----------------------
; Args: 3
; Accepts: Sprite Address (16bit Constant)
; Sprite X Coordinate (8bit Constant)
; Sprite Y Coordinate (8bit Constant)
; Destroys: ACC, B, C, TRL, TRH, VRMAD1, VRMAD2, VSEL, PSW,
; @R0 Pointer
; Draws a sprite directly onto the screen without a sprite mask. Sprites
; use the standard format. Accepts only constants for all arguments.
;
; P_Draw_Sprite_Mask
; ---------------------------
; Args: 3
; Accepts: Sprite Address (2 bytes)
; Sprite X Coordinate (1 byte)
; Sprite Y Coordinate (1 byte)
; Destroys: ACC, B, C, TRL, TRH, VRMAD1, VRMAD2, VSEL, PSW,
; @R0 Pointer
; Draws a sprite onto the screen with a sprite mask. Sprites use the
; masked sprite format. Accepts only RAM addresses for all arguments.
;
; P_Draw_Sprite_Mask_Constant
; ---------------------------
; Args: 3
; Accepts: Sprite Address (16bit Constant)
; Sprite X Coordinate (8bit Constant)
; Sprite Y Coordinate (8bit Constant)
; Destroys: ACC, B, C, TRL, TRH, VRMAD1, VRMAD2, VSEL, PSW,
; @R0 Pointer
; Draws a sprite onto the screen with a sprite mask. Sprites use the
; masked sprite format. Accepts only constants for all arguments.
;
;
; Screen Macros:
; --------------
;
; P_Blit_Screen
; -------------
; Args: 0
; Accepts: None
; Destroys: ACC, C, VRMAD1, VRMAD2, VSEL, PSW, @R2 Pointer
; Alias for calling the P_Blit_Screen function. Blits the WRAM
; buffer to XRAM. Call this once per frame to update the XRAM
; framebuffer.
;
; P_Fill_Screen
; -------------
; Args: 1
; Accepts: Fill Value (8bit Constant)
; Destroys: ACC, C, VRMAD1, VRMAD2, VSEL
; Fills the screen with the given value. Any value is valid.
; Built-in constants are P_WHITE and P_BLACK.
;
; P_Mask_Fill_Screen
; -------------
; Args: 1
; Accepts: Mask Value (1 byte)
; Destroys: ACC, B, C, VRMAD1, VRMAD2, VSEL
; Masks the screen with a value from RAM.
;
; P_Mask_Fill_Screen_Constant
; -------------
; Args: 1
; Accepts: Mask Value (8bit Constant)
; Destroys: ACC, B, C, VRMAD1, VRMAD2, VSEL
; Masks the screen with the given constant value.
;
; P_Clear_Screen
; -------------
; Args: 0
; Accepts: None
; Destroys: ACC, C, VRMAD1, VRMAD2, VSEL
; Alias for 'P_Fill_Screen P_WHITE'. Clears the WRAM framebuffer.
;
; P_Invert_Screen
; ---------------
; Args: 0
; Accepts: None
; Destroys: ACC, C, VRMAD1, VRMAD2, VSEL
; Alias for calling the P_Invert_Screen function. Inverts all
; bits of the WRAM framebuffer.
;
; User Functions:
; ---------------
; P_Blit_Screen
; -----------
; Accepts: None
; Destroys: ACC, C, VRMAD1, VRMAD2, VSEL, PSW, @R2 Pointer
; Blits the WRAM buffer to XRAM. Call this once per frame to
; update the XRAM framebuffer.
;
; P_Invert_Screen
; ---------------
; Accepts: None
; Destroys: ACC, C, VRMAD1, VRMAD2, VSEL
; Inverts all bits of the WRAM framebuffer.
;
;------------------------------------------------------------------------------
; Internal Functions:
; -------------------
; _P_Draw_Background
; _P_Fill_Screen
; _P_Mask_Fill_Screen
; _P_Draw_Sprite_No_Mask
; _P_Draw_Sprite_Mask
; _P_Sprite_Buffer_Common
; _P_Blit_Pass_Unrolled
;
; Internal Macros:
; ----------------
; None
;
;------------------------------------------------------------------------------
; Example Sprite Format (No Mask):
; --------------------------------
; Sprites that have no mask are drawn approximately twice as fast as those
; which use a mask. Backgrounds follow the same format as a non-masked sprite,
; but have a fixed size of 48x32 pixels. Even though the size is fixed, the
; pixel dimensions must still be declared as if it was a large sprite.
;
; Sprite:
; .byte 4, 4 ; Sprite X and Y size in pixels.
; .byte %11110000 ; Sprite bitmap, a sprite larger than 8 pixels
; .byte %10010000 ; will span across multiple bytes. Sprites must
; .byte %10010000 ; be byte aligned.
; .byte %11110000
;
; Example Sprite Format (With Mask):
; ----------------------------------
; Masked_Sprite:
; .byte 4, 4 ; Sprite X and Y size in pixels.
; .byte %00001111 ; Sprite mask
; .byte %00001111
; .byte %00001111
; .byte %00001111
; .byte %11110000 ; Sprite bitmap
; .byte %10010000
; .byte %10010000
; .byte %11110000
;
;******************************************************************************
;------------------------------------------------------------------------------
; Library Variables
;------------------------------------------------------------------------------
p_spr_x = $ff ; 1 byte
p_spr_y = $fe ; 1 byte
p_spr_flag = $fd ; 1 byte
p_spr_size_x = $fc ; 1 byte
p_spr_size_y = $fb ; 1 byte
p_spr_size_x_remainder = $fa ; 1 byte
p_spr_counter = $f9 ; 1 byte
p_spr_offset_x = $f8 ; 1 byte
p_byte_buffer = $f2 ; 6 bytes
;------------------------------------------------------------------------------
; Library Constants
;------------------------------------------------------------------------------
;User Constants:
P_WRAM_BANK EQU 1 ; WRAM Bank to use for buffer
P_WRAM_ADDR EQU 0 ; WRAM buffer start address
P_PSW_IRBKX EQU %00000010 ; PSW IRBK setting
P_INDR_SFR EQU 2 ; Address for @R2
P_INDR_MEM EQU 0 ; Address for @R0
P_BYTE_BUFFER_LOC EQU $f2 ; Location of byte buffer
; Library Constants:
P_WHITE EQU $00
P_BLACK EQU $FF
;------------------------------------------------------------------------------
%macro P_Draw_Sprite_Mask %spr_addr, %spr_x, %spr_y
;----------------------------------------------------------------------
; Draw a sprite to the background with a mask using stored RAM values
;----------------------------------------------------------------------
; Draws a sprite onto the screen with a sprite mask.
; Sprites use the standard format. Accepts only RAM addresses for all
; arguments
;
; Accepts: Sprite Address (2 bytes)
; Sprite X Coordinate (1 byte)
; Sprite Y Coordinate (1 byte)
; Destroys: ACC, B, C, TRL, TRH, VRMAD1, VRMAD2, VSEL, PSW
;----------------------------------------------------------------------
; Preload RAM
ld %spr_x
st p_spr_x
ld %spr_y
st p_spr_y
ld %spr_addr
st trl
ld %spr_addr+1
st trh
call _P_Draw_Sprite_Mask
%end
%macro P_Draw_Sprite_Mask_Constant %spr_addr, %spr_x, %spr_y
;----------------------------------------------------------------------
; Draw a sprite to the background with a mask using constant values
;----------------------------------------------------------------------
; Draws a sprite onto the screen with a sprite mask.
; Sprites use the standard format. Accepts only constant values for
; all arguments.
;
; Accepts: Sprite Address (16bit Constant)
; Sprite X Coordinate (8bit Constant)
; Sprite Y Coordinate (8bit Constant)
; Destroys: ACC, B, C, TRL, TRH, VRMAD1, VRMAD2, VSEL, PSW
;----------------------------------------------------------------------
; Preload RAM
mov #%spr_x, p_spr_x
mov #%spr_y, p_spr_y
mov #<%spr_addr, trl
mov #>%spr_addr, trh
call _P_Draw_Sprite_Mask
%end
%macro P_Draw_Sprite %spr_addr, %spr_x, %spr_y
;----------------------------------------------------------------------
; Draw a sprite to the background with no mask using stored RAM values
;----------------------------------------------------------------------
; Draws a sprite directly onto the screen without a sprite mask.
; Sprites use the standard format. Accepts only constant values for
; all arguments.
;
; Accepts: Sprite Address (16bit Constant)
; Sprite X Coordinate (8bit Constant)
; Sprite Y Coordinate (8bit Constant)
; Destroys: ACC, B, C, TRL, TRH, VRMAD1, VRMAD2, VSEL, PSW
;----------------------------------------------------------------------
; Preload RAM
ld %spr_x
st p_spr_x
ld %spr_y
st p_spr_y
ld %spr_addr
st trl
ld %spr_addr+1
st trh
call _P_Draw_Sprite_No_Mask
%end
%macro P_Draw_Sprite_Constant %spr_addr, %spr_x, %spr_y
;----------------------------------------------------------------------
; Draw a sprite to the background with no mask using constant values
;----------------------------------------------------------------------
; Draws a sprite directly onto the screen without a sprite mask.
; Sprites use the standard format. Accepts only constant values for
; all arguments.
;
; Accepts: Sprite Address (16bit Constant)
; Sprite X Coordinate (8bit Constant)
; Sprite Y Coordinate (8bit Constant)
; Destroys: ACC, B, C, TRL, TRH, VRMAD1, VRMAD2, VSEL, PSW
;----------------------------------------------------------------------
; Preload RAM
mov #%spr_x, p_spr_x
mov #%spr_y, p_spr_y
ld %spr_addr
st trl
ld %spr_addr+1
st trh
; mov #<%spr_addr, trl
; mov #>%spr_addr, trh
call _P_Draw_Sprite_No_Mask
%end
%macro P_Blit_Screen
;----------------------------------------------------------------------
; Blit WRAM to XRAM
;----------------------------------------------------------------------
; Accepts: None
; Destroys: ACC, C, VRMAD1, VRMAD2, VSEL, PSW
;
; Alias for calling the P_Blit_Screen function.
;----------------------------------------------------------------------
call P_Blit_Screen
%end
%macro P_Draw_Background %bgaddr
;----------------------------------------------------------------------
; Draw a background image to WRAM
;----------------------------------------------------------------------
; Accepts: Background Image address (16bit Constant)
; Destroys: ACC, C, TRL, TRH, VRMAD1, VRMAD2, VSEL
;
; Copies a bitmap 48x32 pixels in size. Uses standard Perspective image
; format, but ignores size bits. Controls _P_Draw_Background.
;----------------------------------------------------------------------
ld %bgaddr+1
st trh
ld %bgaddr
add #2
st trl
bn psw, 7, .no_overflow%
inc trh
.no_overflow%
call _P_Draw_Background
%end
%macro P_Draw_Background_Constant %bgaddr
;----------------------------------------------------------------------
; Draw a background image to WRAM
;----------------------------------------------------------------------
; Accepts: Background Image address (16bit Constant)
; Destroys: ACC, C, TRL, TRH, VRMAD1, VRMAD2, VSEL
;
; Copies a bitmap 48x32 pixels in size. Uses standard Perspective image
; format, but ignores size bits. Controls _P_Draw_Background.
;----------------------------------------------------------------------
mov #<(%bgaddr+2), trl
mov #>(%bgaddr+2), trh
call _P_Draw_Background
%end
%macro P_Fill_Screen %value
;----------------------------------------------------------------------
; Fill the screen with a value
;----------------------------------------------------------------------
; Accepts: Fill Value (8bit Constant)
; Destroys: ACC, C, VRMAD1, VRMAD2, VSEL
;
; Fills the screen with the value of ACC.
;----------------------------------------------------------------------
mov #%value, acc
call _P_Fill_Screen
%end
%macro P_Mask_Fill_Screen %value
;----------------------------------------------------------------------
; Mask the screen with a value from RAM
;----------------------------------------------------------------------
; Accepts: Fill Value (1 byte)
; Destroys: ACC, B, C, VRMAD1, VRMAD2, VSEL
;
; Mask the screen with a RAM value.
;----------------------------------------------------------------------
ld %value
call _P_Mask_Fill_Screen
%end
%macro P_Mask_Fill_Screen_Constant %value
;----------------------------------------------------------------------
; Mask the screen with a constant value
;----------------------------------------------------------------------
; Accepts: Fill Value (8bit Constant)
; Destroys: ACC, B, C, VRMAD1, VRMAD2, VSEL
;
; Mask the screen with an 8bit constant.
;----------------------------------------------------------------------
mov #%value, acc
call _P_Mask_Fill_Screen
%end
%macro P_Clear_Screen
;----------------------------------------------------------------------
; Clears the screen
;----------------------------------------------------------------------
; Accepts: None
; Destroys: ACC, C, VRMAD1, VRMAD2, VSEL
;
; Alias for 'P_Fill_Screen P_WHITE'.
;----------------------------------------------------------------------
mov #P_WHITE, acc
call _P_Fill_Screen
%end
%macro P_Invert_Screen
;----------------------------------------------------------------------
; Invert the screen colours
;----------------------------------------------------------------------
; Accepts: None
; Destroys: ACC, C, VRMAD1, VRMAD2, VSEL
;
; Alias for calling the P_Invert_Screen function.
;----------------------------------------------------------------------
call P_Invert_Screen
%end
%macro P_Set_Pixel_Black %pixel_x, %pixel_y
;----------------------------------------------------------------------
; Set one pixel to black
;----------------------------------------------------------------------
; Accepts: X and Y coords
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Sets the pixel at X and Y to black in the in the frame buffer
;----------------------------------------------------------------------
mov #%pixel_x, p_spr_x
mov #%pixel_y, p_spr_y
call P_Get_Px_Coord
call P_Set_Bit_Framebuffer
%end
%macro P_Set_Pixel_White %pixel_x, %pixel_y
;----------------------------------------------------------------------
; Set one pixel to white
;----------------------------------------------------------------------
; Accepts: X and Y coords
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Sets the pixel at X and Y to white in the in the frame buffer
;----------------------------------------------------------------------
mov #%pixel_x, p_spr_x
mov #%pixel_y, p_spr_y
call P_Get_Px_Coord
call P_Clear_Bit_Framebuffer
%end
%macro P_Flip_Pixel %pixel_x, %pixel_y
;----------------------------------------------------------------------
; Flip the state of one pixel
;----------------------------------------------------------------------
; Accepts: X and Y coords
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Flips the pixel at X and Y in the frame buffer
;----------------------------------------------------------------------
mov #%pixel_x, p_spr_x
mov #%pixel_y, p_spr_y
call P_Get_Px_Coord
call P_Flip_Bit_Framebuffer
%end
%macro P_Get_Pixel %pixel_x, %pixel_y
;----------------------------------------------------------------------
; Get the state of one pixel
;----------------------------------------------------------------------
; Accepts: X and Y coords
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Reads the pixel at X and Y in the frame buffer and places it on ACC
;----------------------------------------------------------------------
mov #%pixel_x, p_spr_x
mov #%pixel_y, p_spr_y
call P_Get_Px_Coord
call P_Read_Bit_Framebuffer
%end
%macro P_Write_Pixel %pixel_x, %pixel_y
;----------------------------------------------------------------------
; Set one pixel to the contents of the ACC register's bit 0
;----------------------------------------------------------------------
; Accepts: ACC bit 0, X and Y coords
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Copies ACC's bit 0 into the pixel pointed by X and Y position vars
; Alias to call the bit write function
;----------------------------------------------------------------------
mov #%pixel_x, p_spr_x
mov #%pixel_y, p_spr_y
call P_Write_Pixel_Fn
%end
%macro P_Plot_Pixel_Black
;----------------------------------------------------------------------
; Set one pixel to black without setting X and Y coords
;----------------------------------------------------------------------
; Accepts: None
; Destroys: ACC, B, C, VRMAD1, VRMAD2, VSEL
;
; Reads the pixel at X and Y in the frame buffer and places it on ACC
;----------------------------------------------------------------------
call P_Get_Px_Coord
call P_Read_Bit_Framebuffer
%end
%macro P_Plot_Pixel_White
;----------------------------------------------------------------------
; Set one pixel to white without setting X and Y coords
;----------------------------------------------------------------------
; Accepts: None
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Sets the pixel at X and Y to white in the in the frame buffer
;----------------------------------------------------------------------
call P_Get_Px_Coord
call P_Clear_Bit_Framebuffer
%end
%macro P_Plot_Flip_Pixel
;----------------------------------------------------------------------
; Flip the state of one pixel without setting X and Y coords
;----------------------------------------------------------------------
; Accepts: None
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Flips the pixel at X and Y in the frame buffer
;----------------------------------------------------------------------
call P_Get_Px_Coord
call P_Flip_Bit_Framebuffer
%end
%macro P_Plot_Get_Pixel
;----------------------------------------------------------------------
; Get the state of one pixel without setting X and Y coords
;----------------------------------------------------------------------
; Accepts: None
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Reads the pixel at X and Y in the frame buffer and places it on ACC
;----------------------------------------------------------------------
call P_Get_Px_Coord
call P_Read_Bit_Framebuffer
%end
%macro P_Plot_Write_Pixel
;----------------------------------------------------------------------
; Set one pixel to the contents of the ACC register's bit 0
; without setting X and Y coords
;----------------------------------------------------------------------
; Accepts: ACC bit 0
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Alias to call the bit write function
;----------------------------------------------------------------------
call P_Write_Pixel_Fn
%end
P_Write_Pixel_Fn:
;----------------------------------------------------------------------
; Get the state of one pixel without setting X and Y coords
;----------------------------------------------------------------------
; Accepts: ACC bit 0
; Destroys: ACC, B, VRMAD1, VRMAD2
;
; Copies ACC's bit 0 into the pixel pointed by X and Y position vars
;----------------------------------------------------------------------
bn ACC, 0, .white_px
call P_Get_Px_Coord
call P_Set_Bit_Framebuffer
ret
.white_px:
call P_Get_Px_Coord
call P_Clear_Bit_Framebuffer
ret
P_Get_Px_Coord:
;----------------------------------------------------------------------
; Get the byte position inside the WRAM frame buffer
;----------------------------------------------------------------------
; Accepts: X and Y position
; Destroys: ACC, B
;
; Converts X and Y vars into a WRAM index
;----------------------------------------------------------------------
ld p_spr_y ; get Y offset
rol ; *2
st B
rol ; *4
add B ; *4 + *2
st B
ld p_spr_x ; get X offset
ror
ror
ror
and #%00011111
add B
ret
P_Set_Bit_Framebuffer:
;----------------------------------------------------------------------
; Set one pixel to black in WRAM
;----------------------------------------------------------------------
; Accepts: X and Y position
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Used in a macro function
;----------------------------------------------------------------------
mov #P_WRAM_BANK, VRMAD2
st VRMAD1
mov #0, VSEL
bn p_spr_x, 2, .4topbits
bn p_spr_x, 1, .2top_lownib_bits
bn p_spr_x, 0, .bit1
set1 VTRBF, 0
ret
.bit1:
set1 VTRBF, 1
ret
.2top_lownib_bits:
bn p_spr_x, 0, .bit3
set1 VTRBF, 2
ret
.bit3:
set1 VTRBF, 3
ret
.4topbits:
bn p_spr_x, 1, .2top_hinib_bits
bn p_spr_x, 0, .bit5
set1 VTRBF, 4
ret
.bit5:
set1 VTRBF, 5
ret
.2top_hinib_bits:
bn p_spr_x, 0, .bit7
set1 VTRBF, 6
ret
.bit7:
set1 VTRBF, 7
ret
P_Clear_Bit_Framebuffer:
;----------------------------------------------------------------------
; Set one pixel to white in WRAM
;----------------------------------------------------------------------
; Accepts: X and Y position
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Used in a macro function
;----------------------------------------------------------------------
mov #0, VSEL
mov #P_WRAM_BANK, VRMAD2
st VRMAD1
bn p_spr_x, 2, .4topbits
bn p_spr_x, 1, .2top_lownib_bits
bn p_spr_x, 0, .bit1
clr1 VTRBF, 0
ret
.bit1:
clr1 VTRBF, 1
ret
.2top_lownib_bits:
bn p_spr_x, 0, .bit3
clr1 VTRBF, 2
ret
.bit3:
clr1 VTRBF, 3
ret
.4topbits:
bn p_spr_x, 1, .2top_hinib_bits
bn p_spr_x, 0, .bit5
clr1 VTRBF, 4
ret
.bit5:
clr1 VTRBF, 5
ret
.2top_hinib_bits:
bn p_spr_x, 0, .bit7
clr1 VTRBF, 6
ret
.bit7:
clr1 VTRBF, 7
ret
P_Flip_Bit_Framebuffer:
;----------------------------------------------------------------------
; Flips the state of one pixel inside WRAM
;----------------------------------------------------------------------
; Accepts: X and Y position
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Used in a macro function
;----------------------------------------------------------------------
mov #P_WRAM_BANK, VRMAD2
st VRMAD1
mov #0, VSEL
bn p_spr_x, 2, .4topbits
bn p_spr_x, 1, .2top_lownib_bits
bn p_spr_x, 0, .bit1
not1 VTRBF, 0
ret
.bit1:
not1 VTRBF, 1
ret
.2top_lownib_bits:
bn p_spr_x, 0, .bit3
not1 VTRBF, 2
ret
.bit3:
not1 VTRBF, 3
ret
.4topbits:
bn p_spr_x, 1, .2top_hinib_bits
bn p_spr_x, 0, .bit5
not1 VTRBF, 4
ret
.bit5:
not1 VTRBF, 5
ret
.2top_hinib_bits:
bn p_spr_x, 0, .bit7
not1 VTRBF, 6
ret
.bit7:
not1 VTRBF, 7
ret
P_Read_Bit_Framebuffer:
;----------------------------------------------------------------------
; Get one pixel from WRAM into ACC bit 0
;----------------------------------------------------------------------
; Accepts: X and Y position
; Destroys: ACC, B, VRMAD1, VRMAD2, VSEL
;
; Used in a macro function
;----------------------------------------------------------------------
mov #P_WRAM_BANK, VRMAD2
st VRMAD1
mov #0, VSEL
ld VTRBF
bn p_spr_x, 2, .4topbits
bn p_spr_x, 1, .2top_lownib_bits
bn p_spr_x, 0, .bit1
and #%00000001
br .bitdone
.bit1:
and #%00000010
br .bitdone
.2top_lownib_bits:
bn p_spr_x, 0, .bit3
and #%00000100
br .bitdone
.bit3:
and #%00001000
br .bitdone
.4topbits:
bn p_spr_x, 1, .2top_hinib_bits
bn p_spr_x, 0, .bit5
and #%00010000
br .bitdone
.bit5:
and #%00100000
br .bitdone
.2top_hinib_bits:
bn p_spr_x, 0, .bit7
and #%01000000
br .bitdone
.bit7:
and #%10000000
br .bitdone
.bitdone:
bz .exit
mov #1, ACC
.exit:
ret
P_Invert_Screen:
;----------------------------------------------------------------------
; Invert the screen colours
;----------------------------------------------------------------------
; Accepts: None
; Destroys: ACC, C, VRMAD1, VRMAD2, VSEL
;
; Inverts the screen colours
;----------------------------------------------------------------------
clr1 ocr, 5
; Prepare the frame buffer address
mov #P_WRAM_BANK, vrmad2
mov #P_WRAM_ADDR, vrmad1
mov #%00000000, vsel
mov #48, c
.loop
ld vtrbf
xor #%11111111
st vtrbf
inc vrmad1
ld vtrbf
xor #%11111111
st vtrbf
inc vrmad1
ld vtrbf
xor #%11111111
st vtrbf
inc vrmad1
ld vtrbf
xor #%11111111
st vtrbf
inc vrmad1
dbnz c, .loop
set1 ocr, 5
ret
P_Blit_Screen:
;----------------------------------------------------------------------
; Blit WRAM to XRAM
;----------------------------------------------------------------------
; Accepts: None
; Destroys: ACC, C, VRMAD1, VRMAD2, VSEL, PSW
;
; Blits the WRAM buffer to XRAM. Call this once per frame to update the
; XRAM framebuffer.
;----------------------------------------------------------------------
clr1 ocr, 5
; Prepare the frame buffer address
mov #P_WRAM_BANK, vrmad2
mov #P_WRAM_ADDR, vrmad1
mov #%00010000, vsel
; Copy the frame buffer to XRAM quickly
; Configure indirect addressing mode
mov #0, xbnk
mov #P_PSW_IRBKX, psw
; Fast XRAM Copy
; ---------------------------------------------------------------------
; Pass 1, Bank 0
mov #$80, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 2, Bank 0
mov #$90, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 3, Bank 0
mov #$A0, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 4, Bank 0
mov #$B0, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 5, Bank 0
mov #$C0, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 6, Bank 0
mov #$D0, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 7, Bank 0
mov #$E0, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 8, Bank 0
mov #$F0, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Next Bank
mov #1, xbnk
; Pass 9, Bank 1
mov #$80, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 10, Bank 1
mov #$90, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 11, Bank 1
mov #$A0, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 12, Bank 1
mov #$B0, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 13, Bank 1
mov #$C0, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 14, Bank 1
mov #$D0, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 15, Bank 1
mov #$E0, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Pass 16, Bank 1
mov #$F0, P_INDR_SFR
call _P_Blit_Pass_Unrolled
; Done
set1 ocr, 5
ret
;------------------------------------------------------------------------------
; Internal Library Functions
;------------------------------------------------------------------------------
_P_Draw_Background:
;----------------------------------------------------------------------
; Draw a background image to WRAM
;----------------------------------------------------------------------
; Accepts: TRL, TRH - Background image address
; Destroys: ACC, C, TRL, TRH, VRMAD1, VRMAD2, VSEL, PSW
;
; Copies a bitmap 48x32 pixels in size. Uses standard Perspective image
; format, but relies on macro to skip size bits. Controlled by
; P_Draw_Background Macro.
;----------------------------------------------------------------------
clr1 ocr, 5
; Prepare the frame buffer address
mov #P_WRAM_BANK, vrmad2
mov #P_WRAM_ADDR, vrmad1
mov #%00010000, vsel
mov #0, c
.loop
ld c
ldc
st vtrbf
inc c
ld c
ldc
st vtrbf
inc c
ld c
ldc
st vtrbf
inc c
ld c
ldc
st vtrbf
inc c
ld c
ldc
st vtrbf
inc c
ld c
ldc
st vtrbf
inc c
ld c
sub #192
bnz .loop
set1 ocr, 5
ret
_P_Mask_Fill_Screen:
;----------------------------------------------------------------------
; Mask the screen with a value
;----------------------------------------------------------------------
; Accepts: ACC - Fill value
; Destroys: ACC, B, C, VRMAD1, VRMAD2, VSEL
;
; Masks the screen with the value of ACC. Controlled by the macro