]> git.sur5r.net Git - cc65/blob - libsrc/nes/ppubuf.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / nes / ppubuf.s
1 ;
2 ; Written by Groepaz/Hitmen <groepaz@gmx.net>
3 ; Cleanup by Ullrich von Bassewitz <uz@cc65.org>
4 ;
5
6
7         .export         ppubuf_waitempty
8         .export         ppubuf_wait
9         .export         ppubuf_put
10         .export         ppubuf_flush
11         .include        "nes.inc"
12
13 .code
14
15 ; ------------------------------------------------------------------------
16 ; ppubuf_waitempty
17 ; Wait until buffer is empty
18
19 .proc   ppubuf_waitempty
20
21
22 @wait:  lda     ringcount
23         bne     @wait
24         rts
25
26 .endproc
27
28
29 ; ------------------------------------------------------------------------
30 ; ppubuf_wait
31 ; Wait until buffer is full
32
33 .proc   ppubuf_wait
34
35         lda     #$ff            ; (($0100/3)*1)
36 @wait:  cmp     ringcount
37         beq     @wait
38         rts
39
40 .endproc
41
42 ; ------------------------------------------------------------------------
43 ; Put a PPU-Memory write to buffer
44 ; called from main program (not necessary when in vblank irq)
45
46 .proc   ppubuf_put
47
48         sta     ppuval
49         sty     ppuhi
50         stx     ppulo
51
52         jsr     ppubuf_wait             ; wait if buffer is full
53
54         ldy     ringwrite
55         lda     ppuhi
56         sta     ringbuff,y
57         lda     ppulo
58         sta     ringbuff+$0100,y
59         lda     ppuval
60         sta     ringbuff+$0200,y
61
62         iny
63         sty     ringwrite
64         inc     ringcount
65         rts
66
67 .endproc
68
69 ; ------------------------------------------------------------------------
70 ; Flush PPU-Memory write buffer
71 ; called from vblank interupt
72
73 .proc   ppubuf_flush
74
75         ldy     ringcount
76         bne     @doloop
77         rts
78
79 @doloop:
80         ldx     ringread
81         lda     #$0e
82         sta     temp
83
84 @loop:
85 .repeat 5
86         lda     ringbuff,x
87         sta     $2006
88         lda     ringbuff+$0100,x
89         sta     $2006
90         lda     ringbuff+$0200,x
91         sta     $2007
92         inx
93
94         dey
95         beq     @end
96 .endrepeat
97
98         dec     temp
99         bne     @loop
100
101 @end:   stx     ringread
102         sty     ringcount
103
104         rts     
105
106 .endproc
107
108 ; ------------------------------------------------------------------------
109 ; Data
110
111 .bss
112
113 temp:   .res    1
114
115