diff --git a/include/atmos.h b/include/atmos.h index 460a0010f..9b1b021c1 100644 --- a/include/atmos.h +++ b/include/atmos.h @@ -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 */ diff --git a/libsrc/atmos/cpeekc.s b/libsrc/atmos/cpeekc.s new file mode 100644 index 000000000..f0f5f99b1 --- /dev/null +++ b/libsrc/atmos/cpeekc.s @@ -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 diff --git a/libsrc/atmos/cpeekchar.s b/libsrc/atmos/cpeekchar.s deleted file mode 100644 index fba51bf72..000000000 --- a/libsrc/atmos/cpeekchar.s +++ /dev/null @@ -1,30 +0,0 @@ - - .include "atmos.inc" - - .export _cpeekc - -_cpeekc: - - ldy CURS_Y - ldx ScrTabLo,y - stx @l+1 - ldx ScrTabHi,y - stx @l+2 - ldx CURS_X -@l: - lda $bb80,x -;; inc COORDX_TEXT - ldx #0 - rts - - ; FIXME: is that table available elsewhere? -.rodata -ScrTabLo: - .repeat 28, Line - .byte <(SCREEN + Line * 40) - .endrep - -ScrTabHi: - .repeat 28, Line - .byte >(SCREEN + Line * 40) - .endrep diff --git a/libsrc/atmos/cpeekcolor.s b/libsrc/atmos/cpeekcolor.s new file mode 100644 index 000000000..307c04e96 --- /dev/null +++ b/libsrc/atmos/cpeekcolor.s @@ -0,0 +1,10 @@ +; +; 2017-06-03, Greg King +; +; unsigned char cpeekcolor (void); +; +; Atmos version +; + + .import return1 + .export _cpeekcolor := return1 ; always COLOR_WHITE diff --git a/libsrc/atmos/cpeekrevers.s b/libsrc/atmos/cpeekrevers.s new file mode 100644 index 000000000..53f907511 --- /dev/null +++ b/libsrc/atmos/cpeekrevers.s @@ -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 diff --git a/libsrc/atmos/cpeeks.s b/libsrc/atmos/cpeeks.s new file mode 100644 index 000000000..e54563e7d --- /dev/null +++ b/libsrc/atmos/cpeeks.s @@ -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 diff --git a/targettest/Makefile b/targettest/Makefile index 4d989d0df..35b767727 100644 --- a/targettest/Makefile +++ b/targettest/Makefile @@ -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 \ diff --git a/targettest/conio.c b/targettest/conio.c index e054319e5..56fc5dcda 100644 --- a/targettest/conio.c +++ b/targettest/conio.c @@ -24,6 +24,12 @@ #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 }, @@ -73,6 +79,14 @@ void peektest(void) revers(rbuf[j]); cputc(buf[j]); } + 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]); + } } void main(void)