From 6628c4ff4333d82c40fa13db9b6e4356ce405951 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sat, 24 May 2025 18:34:44 +0200 Subject: [PATCH] fix cpeekc/cpeekcolor/cpeekrevers for atari 800 --- libsrc/atari/cpeekc.s | 35 +++++++++++++++++++++++ libsrc/atari/cpeekchar.s | 35 ----------------------- libsrc/atari/cpeekcolor.s | 8 ++++++ libsrc/atari/cpeekrevers.s | 18 ++++++++++++ targettest/conio.c | 57 ++++++++++++++++++++++++++++++++------ 5 files changed, 109 insertions(+), 44 deletions(-) create mode 100644 libsrc/atari/cpeekc.s delete mode 100644 libsrc/atari/cpeekchar.s create mode 100644 libsrc/atari/cpeekcolor.s create mode 100644 libsrc/atari/cpeekrevers.s diff --git a/libsrc/atari/cpeekc.s b/libsrc/atari/cpeekc.s new file mode 100644 index 000000000..a51e477a6 --- /dev/null +++ b/libsrc/atari/cpeekc.s @@ -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 diff --git a/libsrc/atari/cpeekchar.s b/libsrc/atari/cpeekchar.s deleted file mode 100644 index ff502074d..000000000 --- a/libsrc/atari/cpeekchar.s +++ /dev/null @@ -1,35 +0,0 @@ - - .export _cpeekc - - .import mul40 - .importzp ptr4 - - .include "atari.inc" - - .segment "CODE" - -_cpeekc: - - lda ROWCRS - jsr mul40 ; destroys tmp4 - clc - adc SAVMSC ; add start of screen memory - sta ptr4 - txa - adc SAVMSC+1 - sta ptr4+1 - - ldy COLCRS - lda (ptr4),y ; get char - tax - - ;; convert to asc - - ;; FIXME: ugly hack here to make tetris fx work :=P - lda #' ' - cpx #0 - beq @l - lda #0 -@l: - ldx #0 - rts diff --git a/libsrc/atari/cpeekcolor.s b/libsrc/atari/cpeekcolor.s new file mode 100644 index 000000000..ed275ec95 --- /dev/null +++ b/libsrc/atari/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/atari/cpeekrevers.s b/libsrc/atari/cpeekrevers.s new file mode 100644 index 000000000..15b26fcd4 --- /dev/null +++ b/libsrc/atari/cpeekrevers.s @@ -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 diff --git a/targettest/conio.c b/targettest/conio.c index efe82d7c6..f65f886c5 100644 --- a/targettest/conio.c +++ b/targettest/conio.c @@ -32,6 +32,48 @@ static char grid[5][5] = { {CH_LLCORNER, CH_HLINE, CH_BTEE, CH_HLINE, CH_LRCORNER} }; +void colortest(void) +{ + unsigned int i, j; + 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'); + } + } +} + +#define LINE_PEEKTEST 11 + +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); + } + for (j = 0; j < NUMCOLS; ++j) { + gotoxy(j, LINE_PEEKTEST); + buf[j] = cpeekc(); + cbuf[j] = cpeekcolor(); + rbuf[j] = cpeekrevers(); + } + gotoxy(0, (LINE_PEEKTEST+1)); + for (j = 0; j < NUMCOLS; ++j) { + (void)textcolor(cbuf[j]); + revers(rbuf[j]); + cputc(buf[j]); + } +} + void main(void) { unsigned int i, j, n; @@ -52,16 +94,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);