From 228316ff58cd9ac7fd70727713f8a486f09b3a4c Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sat, 24 May 2025 19:19:49 +0200 Subject: [PATCH] NES complete now (tested and conio test updated), replaces what is in #532 --- libsrc/nes/color.s | 4 ++-- libsrc/nes/cpeekc.s | 37 +++++++++++++++++++++++++++++++++++++ libsrc/nes/cpeekchar.s | 34 ---------------------------------- libsrc/nes/cpeekcolor.s | 8 ++++++++ libsrc/nes/cpeekrevers.s | 37 +++++++++++++++++++++++++++++++++++++ targettest/conio.c | 1 + 6 files changed, 85 insertions(+), 36 deletions(-) create mode 100644 libsrc/nes/cpeekc.s delete mode 100644 libsrc/nes/cpeekchar.s create mode 100644 libsrc/nes/cpeekcolor.s create mode 100644 libsrc/nes/cpeekrevers.s diff --git a/libsrc/nes/color.s b/libsrc/nes/color.s index e3aef9a28..cd1a950ea 100644 --- a/libsrc/nes/color.s +++ b/libsrc/nes/color.s @@ -9,11 +9,11 @@ .export _textcolor, _bgcolor, _bordercolor - .import return0, ppubuf_put + .import return0, return1, ppubuf_put .include "nes.inc" -_textcolor = return0 +_textcolor = return1 _bordercolor = return0 .proc _bgcolor diff --git a/libsrc/nes/cpeekc.s b/libsrc/nes/cpeekc.s new file mode 100644 index 000000000..315a2df5c --- /dev/null +++ b/libsrc/nes/cpeekc.s @@ -0,0 +1,37 @@ +; +; 2016-02-28, Groepaz +; 2017-08-17, Greg King +; +; char cpeekc (void); +; + + .export _cpeekc + + .import ppubuf_waitempty + .forceimport initconio + + .include "nes.inc" + + +_cpeekc: + ; wait until all console data has been written + jsr ppubuf_waitempty + + ldy SCREEN_PTR+1 + lda SCREEN_PTR + +; waiting for vblank is incredibly slow :// +vwait: +; ldx PPU_STATUS +; bpl vwait + + ldx #>$0000 + sty PPU_VRAM_ADDR2 + sta PPU_VRAM_ADDR2 + lda PPU_VRAM_IO ; first read is invalid + lda PPU_VRAM_IO ; get data + stx PPU_VRAM_ADDR2 + stx PPU_VRAM_ADDR2 + + and #<~$80 ; remove reverse bit + rts diff --git a/libsrc/nes/cpeekchar.s b/libsrc/nes/cpeekchar.s deleted file mode 100644 index 55230edbc..000000000 --- a/libsrc/nes/cpeekchar.s +++ /dev/null @@ -1,34 +0,0 @@ - - .export _cpeekc - - .import ppubuf_waitempty - - .include "nes.inc" - - .segment "CODE" - -_cpeekc: - - ; wait until all console data has been written - jsr ppubuf_waitempty - - ldy SCREEN_PTR+1 - ldx SCREEN_PTR - -; waiting for vblank is incredibly slow :// -vwait: -; lda $2002 ;wait -; bpl vwait - - lda #0 - sty $2006 - stx $2006 - ldy $2007 ; first read is invalid - ldy $2007 ; get data - sta $2006 - sta $2006 - - tya - and #$7f ; ?!?! - rts - diff --git a/libsrc/nes/cpeekcolor.s b/libsrc/nes/cpeekcolor.s new file mode 100644 index 000000000..ed275ec95 --- /dev/null +++ b/libsrc/nes/cpeekcolor.s @@ -0,0 +1,8 @@ +; +; 2017-06-03, Greg King +; +; unsigned char cpeekcolor (void); +; + + .import return1 + .export _cpeekcolor := return1 ; always COLOR_WHITE diff --git a/libsrc/nes/cpeekrevers.s b/libsrc/nes/cpeekrevers.s new file mode 100644 index 000000000..8b1542bc0 --- /dev/null +++ b/libsrc/nes/cpeekrevers.s @@ -0,0 +1,37 @@ +; +; 2016-02-28, Groepaz +; 2017-08-17, Greg King +; +; char cpeekrevers (void); +; + + .export _cpeekrevers + + .import ppubuf_waitempty + .forceimport initconio + + .include "nes.inc" + + +_cpeekrevers: + ; wait until all console data has been written + jsr ppubuf_waitempty + + ldy SCREEN_PTR+1 + lda SCREEN_PTR + +; waiting for vblank is incredibly slow :// +vwait: +; ldx PPU_STATUS +; bpl vwait + + ldx #>$0000 + sty PPU_VRAM_ADDR2 + sta PPU_VRAM_ADDR2 + lda PPU_VRAM_IO ; first read is invalid + lda PPU_VRAM_IO ; get data + stx PPU_VRAM_ADDR2 + stx PPU_VRAM_ADDR2 + + and #<$80 ; get reverse bit + rts diff --git a/targettest/conio.c b/targettest/conio.c index f65f886c5..e054319e5 100644 --- a/targettest/conio.c +++ b/targettest/conio.c @@ -59,6 +59,7 @@ void peektest(void) (void)textcolor(j); revers((j >> 1)&1); cputc('a' + j); + rbuf[j] = (j >> 1)&1; } for (j = 0; j < NUMCOLS; ++j) { gotoxy(j, LINE_PEEKTEST);