File: ppubuf.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (115 lines) | stat: -rw-r--r-- 2,141 bytes parent folder | download | duplicates (3)
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
;
; Written by Groepaz/Hitmen <groepaz@gmx.net>
; Cleanup by Ullrich von Bassewitz <uz@cc65.org>
;


        .export         ppubuf_waitempty
        .export         ppubuf_wait
        .export         ppubuf_put
        .export         ppubuf_flush
        .include        "nes.inc"

.code

; ------------------------------------------------------------------------
; ppubuf_waitempty
; Wait until buffer is empty

.proc   ppubuf_waitempty


@wait:  lda     ringcount
        bne     @wait
        rts

.endproc


; ------------------------------------------------------------------------
; ppubuf_wait
; Wait until buffer is full

.proc   ppubuf_wait

        lda     #$ff            ; (($0100/3)*1)
@wait:  cmp     ringcount
        beq     @wait
        rts

.endproc

; ------------------------------------------------------------------------
; Put a PPU-Memory write to buffer
; called from main program (not necessary when in vblank irq)

.proc   ppubuf_put

        sta     ppuval
        sty     ppuhi
        stx     ppulo

        jsr     ppubuf_wait             ; wait if buffer is full

        ldy     ringwrite
        lda     ppuhi
        sta     ringbuff,y
        lda     ppulo
        sta     ringbuff+$0100,y
        lda     ppuval
        sta     ringbuff+$0200,y

        iny
        sty     ringwrite
        inc     ringcount
        rts

.endproc

; ------------------------------------------------------------------------
; Flush PPU-Memory write buffer
; called from vblank interupt

.proc   ppubuf_flush

        ldy     ringcount
        bne     @doloop
        rts

@doloop:
        ldx     ringread
        lda     #$0e
        sta     temp

@loop:
.repeat 5
        lda     ringbuff,x
        sta     $2006
        lda     ringbuff+$0100,x
        sta     $2006
        lda     ringbuff+$0200,x
        sta     $2007
        inx

        dey
        beq     @end
.endrepeat

        dec     temp
        bne     @loop

@end:   stx     ringread
        sty     ringcount

        rts     

.endproc

; ------------------------------------------------------------------------
; Data

.bss

temp:   .res    1