From: cuz Date: Fri, 2 May 2003 13:40:01 +0000 (+0000) Subject: Moved more files with cleanup X-Git-Tag: V2.12.0~1596 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d53211198b099aa59dcb1853f147c8640bd18ffa;p=cc65 Moved more files with cleanup git-svn-id: svn://svn.cc65.org/cc65/trunk@2118 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/libsrc/nes/Makefile b/libsrc/nes/Makefile index c0f623207..58d9531fd 100644 --- a/libsrc/nes/Makefile +++ b/libsrc/nes/Makefile @@ -20,7 +20,12 @@ C_OBJS = S_OBJS = _scrsize.o \ - crt0.o + clock.o \ + color.o \ + crt0.o \ + ppu.o \ + ppubuf.o \ + waitvblank.o #-------------------------------------------------------------------------- # Targets diff --git a/libsrc/nes/clock.s b/libsrc/nes/clock.s new file mode 100644 index 000000000..b36735e85 --- /dev/null +++ b/libsrc/nes/clock.s @@ -0,0 +1,24 @@ +; +; Written by Groepaz/Hitmen +; Cleanup by Ullrich von Bassewitz +; +; clock_t clock (void); +; + + .include "nes.inc" + + .export _clock + .importzp sreg + + +.proc _clock + + ldy #0 ; High word is always zero + sty sreg+1 + sty sreg + ldx tickcount+1 ; ## Problem: Cannot disable ints here + lda tickcount + rts + +.endproc + diff --git a/libsrc/nes/color.s b/libsrc/nes/color.s new file mode 100644 index 000000000..3ac4dd620 --- /dev/null +++ b/libsrc/nes/color.s @@ -0,0 +1,69 @@ +; +; Written by Groepaz/Hitmen +; Cleanup by Ullrich von Bassewitz +; +; unsigned char __fastcall__ textcolor (unsigned char color); +; unsigned char __fastcall__ bgcolor (unsigned char color); +; unsigned char __fastcall__ bordercolor (unsigned char color); +; + + + .export _textcolor, _bgcolor, _bordercolor + .import return0, ppubuf_put + + .include "nes.inc" + +_textcolor = return0 +_bordercolor = return0 + +.proc _bgcolor + + tax + lda BGCOLOR ; get old value + stx BGCOLOR ; set new value + pha + + lda colors,x + pha + ldy #$3F + ldx #0 + jsr ppubuf_put + pla + pha + ldy #$3F + ldx #4 + jsr ppubuf_put + pla + pha + ldy #$3F + ldx #8 + jsr ppubuf_put + pla + ldy #$3F + ldx #12 + jsr ppubuf_put + + pla + rts + +.endproc + +.rodata + +colors: .byte $0f ; 0 black + .byte $3d ; 1 white + .byte $04 ; 2 red + .byte $3b ; 3 cyan + .byte $14 ; 4 violett + .byte $1a ; 5 green + .byte $01 ; 6 blue + .byte $38 ; 7 yellow + .byte $18 ; 8 orange + .byte $08 ; 9 brown + .byte $35 ; a light red + .byte $2d ; b dark grey + .byte $10 ; c middle grey + .byte $2b ; d light green + .byte $22 ; e light blue + .byte $3d ; f light gray + diff --git a/libsrc/nes/crt0.s b/libsrc/nes/crt0.s index a4676c7e2..cda428522 100644 --- a/libsrc/nes/crt0.s +++ b/libsrc/nes/crt0.s @@ -20,7 +20,7 @@ .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__ .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__ .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ - + .include "zeropage.inc" .include "nes.inc" @@ -165,7 +165,7 @@ _exit: jsr donelib ; Run module destructors ; ------------------------------------------------------------------------ ; System V-Blank Interupt ; updates PPU Memory (buffered) -; updates VBLANK_FLAG and _tickcount +; updates VBLANK_FLAG and tickcount ; ------------------------------------------------------------------------ nmi: pha @@ -177,9 +177,9 @@ nmi: pha lda #1 sta VBLANK_FLAG - inc _tickcount + inc tickcount bne @s - inc _tickcount+1 + inc tickcount+1 @s: jsr ppubuf_flush diff --git a/libsrc/nes/nes.inc b/libsrc/nes/nes.inc index 24ce62d67..aaba4fca7 100644 --- a/libsrc/nes/nes.inc +++ b/libsrc/nes/nes.inc @@ -13,7 +13,7 @@ RVS = $68 CURS_X = $69 CURS_Y = $6a -_tickcount = $6b ;2 +tickcount = $6b ;2 VBLANK_FLAG = $70 diff --git a/libsrc/nes/ppu.s b/libsrc/nes/ppu.s new file mode 100644 index 000000000..861685280 --- /dev/null +++ b/libsrc/nes/ppu.s @@ -0,0 +1,158 @@ +; +; Written by Groepaz/Hitmen +; Cleanup by Ullrich von Bassewitz +; + + .export ppuinit + .export paletteinit + + .include "nes.inc" + +;+---------+----------------------------------------------------------+ +;| $2000 | PPU Control Register #1 (W) | +;| | | +;| | D7: Execute NMI on VBlank | +;| | 0 = Disabled | +;| | 1 = Enabled | +;| | D6: PPU Master/Slave Selection --+ | +;| | 0 = Master +-- UNUSED | +;| | 1 = Slave --+ | +;| | D5: Sprite Size | +;| | 0 = 8x8 | +;| | 1 = 8x16 | +;| | D4: Background Pattern Table Address | +;| | 0 = $0000 (VRAM) | +;| | 1 = $1000 (VRAM) | +;| | D3: Sprite Pattern Table Address | +;| | 0 = $0000 (VRAM) | +;| | 1 = $1000 (VRAM) | +;| | D2: PPU Address Increment | +;| | 0 = Increment by 1 | +;| | 1 = Increment by 32 | +;| | D1-D0: Name Table Address | +;| | 00 = $2000 (VRAM) | +;| | 01 = $2400 (VRAM) | +;| | 10 = $2800 (VRAM) | +;| | 11 = $2C00 (VRAM) | +;+---------+----------------------------------------------------------+ +;+---------+----------------------------------------------------------+ +;| $2001 | PPU Control Register #2 (W) | +;| | | +;| | D7-D5: Full Background Colour (when D0 == 1) | +;| | 000 = None +------------+ | +;| | 001 = Green | NOTE: Do not use more | +;| | 010 = Blue | than one type | +;| | 100 = Red +------------+ | +;| | D7-D5: Colour Intensity (when D0 == 0) | +;| | 000 = None +--+ | +;| | 001 = Intensify green | NOTE: Do not use more | +;| | 010 = Intensify blue | than one type | +;| | 100 = Intensify red +--+ | +;| | D4: Sprite Visibility | +;| | 0 = Sprites not displayed | +;| | 1 = Sprites visible | +;| | D3: Background Visibility | +;| | 0 = Background not displayed | +;| | 1 = Background visible | +;| | D2: Sprite Clipping | +;| | 0 = Sprites invisible in left 8-pixel column | +;| | 1 = No clipping | +;| | D1: Background Clipping | +;| | 0 = BG invisible in left 8-pixel column | +;| | 1 = No clipping | +;| | D0: Display Type | +;| | 0 = Colour display | +;| | 1 = Monochrome display | +;+---------+----------------------------------------------------------+ + + +;----------------------------------------------------------------------------- + +.proc ppuinit + + lda #%10101000 + sta PPU_CTRL1 + + lda #%00011110 + sta PPU_CTRL2 + +; Wait for vblank + +@wait: lda PPU_STATUS + bpl @wait + +; reset scrolling + + lda #0 + sta PPU_VRAM_ADDR1 + sta PPU_VRAM_ADDR1 + +; Make all sprites invisible + + lda #$00 + ldy #$f0 + sta PPU_SPR_ADDR + ldx #$40 +@loop: sty PPU_SPR_IO + sta PPU_SPR_IO + sta PPU_SPR_IO + sty PPU_SPR_IO + dex + bne @loop + + rts + +.endproc + + +;----------------------------------------------------------------------------- + +.proc paletteinit + +; Wait for v-blank +@wait: lda PPU_STATUS + bpl @wait + + lda #$3F + sta PPU_VRAM_ADDR2 + lda #$00 + sta PPU_VRAM_ADDR2 + + ldx #0 +@loop: lda paldata,x + sta PPU_VRAM_IO + inx + cpx #(16*2) + bne @loop + + rts + +.endproc + +;----------------------------------------------------------------------------- + +.rodata + +paldata: + .repeat 2 + .byte $0f ; 0 black + .byte $14 ; 4 violett + .byte $3b ; 3 cyan + .byte $3d ; 1 white + + .byte $38 ; 7 yellow + .byte $2d ; b dark grey + .byte $22 ; e light blue + .byte $04 ; 2 red + + .byte $18 ; 8 orange + .byte $08 ; 9 brown + .byte $35 ; a light red + .byte $01 ; 6 blue + + .byte $10 ; c middle grey + .byte $2b ; d light green + .byte $3d ; f light gray + .byte $1a ; 5 green + .endrepeat + diff --git a/libsrc/nes/ppubuf.s b/libsrc/nes/ppubuf.s new file mode 100644 index 000000000..68f194e78 --- /dev/null +++ b/libsrc/nes/ppubuf.s @@ -0,0 +1,115 @@ +; +; Written by Groepaz/Hitmen +; Cleanup by Ullrich von Bassewitz +; + + + .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 + + diff --git a/libsrc/nes/waitvblank.s b/libsrc/nes/waitvblank.s new file mode 100644 index 000000000..a54607092 --- /dev/null +++ b/libsrc/nes/waitvblank.s @@ -0,0 +1,20 @@ +; +; Written by Groepaz/Hitmen +; Cleanup by Ullrich von Bassewitz +; +; void __fastcall__ waitvblank(void); +; + + .export _waitvblank + + .include "nes.inc" + +.proc _waitvblank + +wait: lda PPU_STATUS + bpl wait + rts + +.endproc + +