Merge pull request #1810 from mrdudz/coniopeek

conio peek for Atari, Atmos, NES, OSIC1P
This commit is contained in:
Bob Andrews
2025-05-25 03:26:30 +02:00
committed by GitHub
21 changed files with 445 additions and 65 deletions

View File

@@ -169,6 +169,17 @@ void atmos_tock (void);
void atmos_zap (void);
/* Raygun sound effect */
/* The following #defines will cause the matching function prototypes
** in conio.h to be overlaid by macroes with the same names,
** thereby saving the function call overhead.
*/
#define _textcolor(color) COLOR_WHITE
#define _bgcolor(color) COLOR_BLACK
#define _bordercolor(color) COLOR_BLACK
#define _cpeekcolor(color) COLOR_WHITE
void waitvsync (void);
/* Wait for start of next frame */

35
libsrc/atari/cpeekc.s Normal file
View File

@@ -0,0 +1,35 @@
;
; 2016-02-28, Groepaz
; 2017-06-21, Greg King
;
; char cpeekc (void);
;
.export _cpeekc
.include "atari.inc"
_cpeekc:
lda OLDCHR ; get char under cursor
and #<~$80 ; remove reverse bit
;; convert internal screen code to AtSCII
tay
and #%01100000
asl a
asl a
rol a
rol a
tax
tya
eor intats,x
ldx #>$0000
rts
.rodata
intats: .byte %00100000 ; -> %001xxxxx
.byte %01100000 ; -> %010xxxxx
.byte %01000000 ; -> %000xxxxx
.byte %00000000 ; -> %011xxxxx

View File

@@ -0,0 +1,8 @@
;
; 2017-06-03, Greg King
;
; unsigned char cpeekcolor (void);
;
.import return1
.export _cpeekcolor := return1 ; always COLOR_WHITE

View File

@@ -0,0 +1,18 @@
;
; 2017-06-21, Greg King
;
; unsigned char cpeekrevers (void);
;
.export _cpeekrevers
.include "atari.inc"
_cpeekrevers:
lda OLDCHR ; get char under cursor
and #$80 ; get reverse bit
asl a
tax ; ldx #>$0000
rol a ; return boolean value
rts

21
libsrc/atmos/cpeekc.s Normal file
View File

@@ -0,0 +1,21 @@
;
; 2016-02-28, Groepaz
; 2017-06-19, Greg King
;
; char cpeekc (void);
;
; Atmos version
;
.export _cpeekc
.import setscrptr
.importzp ptr2
_cpeekc:
jsr setscrptr ; Set ptr2 and .Y to the cursor's address
lda (ptr2),y ; Get char
and #<~$80 ; Remove revers() bit
ldx #>$0000
rts

10
libsrc/atmos/cpeekcolor.s Normal file
View File

@@ -0,0 +1,10 @@
;
; 2017-06-03, Greg King
;
; unsigned char cpeekcolor (void);
;
; Atmos version
;
.import return1
.export _cpeekcolor := return1 ; always COLOR_WHITE

View File

@@ -0,0 +1,22 @@
;
; 2017-06-08, Greg King
;
; unsigned char cpeekrevers (void);
;
; Atmos version
;
.export _cpeekrevers
.import setscrptr
.importzp ptr2
_cpeekrevers:
jsr setscrptr ; Set ptr2 and .Y to the cursor's address
lda (ptr2),y ; Get char
and #$80 ; get reverse bit
asl a
tax ; ldx #>$0000
rol a ; return boolean value
rts

54
libsrc/atmos/cpeeks.s Normal file
View File

@@ -0,0 +1,54 @@
;
; 2017-06-20, Greg King
;
; void cpeeks (char* s, unsigned length);
;
.export _cpeeks
.import setscrptr, popax
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
.macpack generic
_cpeeks:
eor #<$FFFF ; counting a word upward is faster
sta ptr3 ; so, we use -(length + 1)
txa
eor #>$FFFF
sta ptr3+1
jsr setscrptr ; Set ptr2 and .Y to the cursor's address
sty tmp2
jsr popax
sta tmp1 ; (will be a .Y index)
stx ptr1+1
ldx #<$0000
stx ptr1
bze L3 ; branch always
L4: ldy tmp2
lda (ptr2),y ; Get char
iny
bnz L2
inc ptr2+1
L2: sty tmp2
and #<~$80 ; Remove reverse bit
ldy tmp1
sta (ptr1),y
iny
bnz L1
inc ptr1+1
L1: sty tmp1
L3: inc ptr3 ; count length
bnz L4
inc ptr3+1
bnz L4
txa ; terminate the string
ldy tmp1
sta (ptr1),y
rts

View File

@@ -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

37
libsrc/nes/cpeekc.s Normal file
View File

@@ -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

8
libsrc/nes/cpeekcolor.s Normal file
View File

@@ -0,0 +1,8 @@
;
; 2017-06-03, Greg King
;
; unsigned char cpeekcolor (void);
;
.import return1
.export _cpeekcolor := return1 ; always COLOR_WHITE

37
libsrc/nes/cpeekrevers.s Normal file
View File

@@ -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

17
libsrc/osic1p/cpeekc.s Normal file
View File

@@ -0,0 +1,17 @@
;
; 2017-06-21, Greg King
;
; char cpeekc (void);
;
; Get a character from OSI C1P screen RAM.
;
.export _cpeekc
.include "extzp.inc"
_cpeekc:
ldy CURS_X
lda (SCREEN_PTR),y
ldx #>$0000
rts

View File

@@ -0,0 +1,8 @@
;
; 2017-06-03, Greg King
;
; unsigned char cpeekcolor (void);
;
.import return1
.export _cpeekcolor := return1 ; always COLOR_WHITE

View File

@@ -0,0 +1,9 @@
;
; 2017-06-15, Greg King
;
; unsigned char cpeekrevers (void);
;
; Get a reverse attribute from screen RAM
;
.import return0
.export _cpeekrevers := return0 ; No attribute

View File

@@ -14,11 +14,11 @@ _cpeekc:
st0 #VDC_MARR ; Memory-Address Read
ldy SCREEN_PTR
ldx SCREEN_PTR+1
sty VDC_DATA_LO
stx VDC_DATA_HI
sty a:VDC_DATA_LO
stx a:VDC_DATA_HI
st0 #VDC_VRR ; VRAM Read Register
lda VDC_DATA_LO ; character
lda a:VDC_DATA_LO ; character
and #<~$80 ; remove reverse bit
ldx #0
rts

View File

@@ -14,11 +14,11 @@ _cpeekcolor:
st0 #VDC_MARR ; Memory-Address Read
ldy SCREEN_PTR
ldx SCREEN_PTR+1
sty VDC_DATA_LO
stx VDC_DATA_HI
sty a:VDC_DATA_LO
stx a:VDC_DATA_HI
st0 #VDC_VRR ; VRAM Read Register
lda VDC_DATA_HI
lda a:VDC_DATA_HI
and #<~$02
lsr a
lsr a

View File

@@ -14,13 +14,14 @@ _cpeekrevers:
st0 #VDC_MARR ; Memory-Address Read
ldy SCREEN_PTR
ldx SCREEN_PTR+1
sty VDC_DATA_LO
stx VDC_DATA_HI
sty a:VDC_DATA_LO
stx a:VDC_DATA_HI
st0 #VDC_VRR ; VRAM Read Register
lda VDC_DATA_LO ; character (bit 7 is revers bit)
rol a
rol a
and #1
ldx #0
lda a:VDC_DATA_LO ; character (bit 7 is revers bit)
and #$80 ; get reverse bit
asl a ; reverse bit to carry, A=0
tax ; ldx #>$0000
rol a ; reverse bit from carry
rts

View File

@@ -1,5 +1,6 @@
;
; 2020-07-14, Groepaz
; 2020-07-15, Greg King
;
; void cpeeks (char* s, unsigned length);
;
@@ -8,9 +9,7 @@
.export _cpeeks
.import popax
.importzp ptr1, ptr2, tmp1, tmp2
.macpack generic
.importzp ptr1, ptr2
.include "pce.inc"
.include "extzp.inc"
@@ -22,35 +21,31 @@ _cpeeks:
eor #>$FFFF
sta ptr2+1
st0 #VDC_CR ; Control Register
st2 #>$0088 ; make VRAM address increment by one
st0 #VDC_MARR ; Memory-Address Read
ldy SCREEN_PTR
ldx SCREEN_PTR+1
sty VDC_DATA_LO
stx VDC_DATA_HI
sty a:VDC_DATA_LO
stx a:VDC_DATA_HI
st0 #VDC_VRR ; VRAM Read Register
jsr popax
sta tmp1 ; (will be a .Y index)
tay ; low byte of address will be used as index
stx ptr1+1
ldx #<$0000
stx ptr1
beq L2 ; branch always
L3: ldy tmp2
lda VDC_DATA_LO ; get character
bit VDC_DATA_HI ; we need to "read" the highbyte to advance the address
iny
sty tmp2
L3: lda a:VDC_DATA_LO ; get character
bit a:VDC_DATA_HI ; need to read high byte to advance VDC address
and #<~$80 ; remove reverse bit
ldy tmp1
sta (ptr1),y
iny
bne L1
bne L2
inc ptr1+1
L1: sty tmp1
L2: inc ptr2 ; count length
bne L3
@@ -58,6 +53,5 @@ L2: inc ptr2 ; count length
bne L3
txa ; terminate the string
ldy tmp1
sta (ptr1),y
rts

View File

@@ -540,12 +540,13 @@ EXELIST_sym1 = \
strnlen \
strqtok-test
# omitted: clock-test cpeek-test conio deb dir-test em-test exec-test1 exec-test2
# omitted: clock-test cpeek-test deb dir-test em-test exec-test1 exec-test2
# fileio-test ft mouse-test posixio-test rename-test seek ser-test
EXELIST_atmos = \
minimal \
arg-test \
clock \
conio \
cprintf \
cursor \
div-test \
@@ -623,6 +624,7 @@ EXELIST_pce = \
# stroserror-test strqtok-test uname-test
EXELIST_osic1p = \
minimal \
conio \
cursor \
mul-test

View File

@@ -15,15 +15,25 @@
#include <stdlib.h>
#include <joystick.h>
#if defined(__GAMATE__)
#if defined(__GAMATE__) || defined(__OSIC1P__)
/* there is not enough screen space to show all 256 characters at the bottom */
#define NUMCHARS 128
#define NUMCOLS 4
#else
#define NUMCHARS 256
#endif
#if defined(__GAMATE__)
#define NUMCOLS 4
#else
#define NUMCOLS 16
#endif
#if defined(__ATMOS__)
// FIXME: those should be defined elsewhere?
#define CH_HLINE '-'
#define CH_VLINE '!'
#endif
static char grid[5][5] = {
{CH_ULCORNER, CH_HLINE, CH_TTEE, CH_HLINE, CH_URCORNER},
{CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE },
@@ -32,6 +42,107 @@ static char grid[5][5] = {
{CH_LLCORNER, CH_HLINE, CH_BTEE, CH_HLINE, CH_LRCORNER}
};
#define LINE_COLORTEST 3
#define LINE_PEEKTEST 11
void colortest(void)
{
unsigned int i, j;
cputsxy(0, 2, "Colors:" );
for (i = 0; i < 3; ++i) {
gotoxy(i, LINE_COLORTEST + i);
for (j = 0; j < NUMCOLS; ++j) {
(void)textcolor(j);
cputc('X');
}
}
}
void peektest(void)
{
int j;
char buf[NUMCOLS];
char cbuf[NUMCOLS];
char rbuf[NUMCOLS];
gotoxy(0, LINE_PEEKTEST);
for (j = 0; j < NUMCOLS; ++j) {
(void)textcolor(j);
revers((j >> 1)&1);
cputc('a' + j);
buf[j] ='#';
cbuf[j] = 1;
rbuf[j] = 0;
}
for (j = 0; j < NUMCOLS; ++j) {
gotoxy(j, LINE_PEEKTEST);
// TODO: cpeekc() implementation missing for those:
#if !defined(__TELESTRAT__)
buf[j] = cpeekc();
#endif
// TODO: cpeekcolor() implementation missing for those:
#if !defined(__TELESTRAT__)
cbuf[j] = cpeekcolor();
#endif
// TODO: cpeekrevers() implementation missing for those:
#if !defined(__TELESTRAT__)
rbuf[j] = cpeekrevers();
#endif
}
gotoxy(0, (LINE_PEEKTEST+1));
for (j = 0; j < NUMCOLS; ++j) {
(void)textcolor(cbuf[j]);
revers(rbuf[j]);
cputc(buf[j]);
}
// TODO: cpeeks() implementation missing for those:
#if !defined(__APPLE2__) && \
!defined(__APPLE2ENH__) && \
!defined(__ATARI__) && \
!defined(__CX16__) && \
!defined(__NES__) && \
!defined(__TELESTRAT__) && \
!defined(__OSIC1P__)
gotoxy(0, LINE_PEEKTEST);
cpeeks(buf, NUMCOLS);
(void)textcolor(1);
revers(0);
gotoxy(20, LINE_PEEKTEST);
for (j = 0; j < NUMCOLS; ++j) {
cputc(buf[j]);
}
#endif
}
void allchars(int xsize, int ysize)
{
int i;
gotoxy(0, ysize - 2 - ((NUMCHARS + (xsize-1)) / xsize));
// one line with 0123..pattern
revers(1);
for (i = 0; i < xsize; ++i) {
cputc('0' + i % 10);
}
revers(0);
for (i = 0; i < NUMCHARS; ++i) {
if ((i != '\n') && (i != '\r')) {
cputc(i);
} else {
cputc(' ');
}
}
// fill last line of the block with '#'
while(wherex() > 0) {
cputc('#');
}
// one more line with 0123..pattern
revers(1);
for (i = 0; i < xsize; ++i) {
cputc('0' + i % 10);
}
revers(0);
}
void main(void)
{
unsigned int i, j, n;
@@ -52,16 +163,13 @@ void main(void)
(void)bordercolor(bcol);
(void)bgcolor(bgcol);
cputsxy(0, 2, "Colors:" );
for (i = 0; i < 3; ++i) {
gotoxy(i, 3 + i);
for (j = 0; j < NUMCOLS; ++j) {
(void)textcolor(j);
cputc('X');
}
}
(void)textcolor(tcol);
colortest();
peektest();
(void)textcolor(tcol);
revers(0);
gotoxy(4,5);
cprintf("\n\n\r Screensize: %ux%u", xsize, ysize);
chlinexy(0, 6, xsize);
@@ -80,27 +188,7 @@ void main(void)
}
}
gotoxy(0, ysize - 2 - ((NUMCHARS + xsize) / xsize));
revers(1);
for (i = 0; i < xsize; ++i) {
cputc('0' + i % 10);
}
revers(0);
for (i = 0; i < NUMCHARS; ++i) {
if ((i != '\n') && (i != '\r')) {
cputc(i);
} else {
cputc(' ');
}
}
while(wherex() > 0) {
cputc('#');
}
revers(1);
for (i = 0; i < xsize; ++i) {
cputc('0' + i % 10);
}
revers(0);
allchars(xsize, ysize);
cursor(1);
for (;;) {