From ae7a38f3de4a0855a35a71190f558faa8c9c2c3d Mon Sep 17 00:00:00 2001 From: Greg King Date: Wed, 15 Jul 2020 14:01:58 -0400 Subject: [PATCH] Added peek functions to the conio library. The functions return the character, or its attributes, that is at the current screen location of conio's cursor. The values can be used directly by the output functions to reproduce that screen character. --- include/atmos.h | 9 +++++++ include/conio.h | 24 ++++++++--------- include/osic1p.h | 1 + libsrc/atari/cpeekc.s | 35 ++++++++++++++++++++++++ libsrc/atari/cpeekcolor.s | 8 ++++++ libsrc/atari/cpeekrevers.s | 18 +++++++++++++ libsrc/atmos/cpeekc.s | 21 +++++++++++++++ libsrc/atmos/cpeekcolor.s | 10 +++++++ libsrc/atmos/cpeekrevers.s | 22 +++++++++++++++ libsrc/atmos/cpeeks.s | 54 +++++++++++++++++++++++++++++++++++++ libsrc/c128/cpeeks.s | 5 +--- libsrc/nes/cpeekc.s | 37 +++++++++++++++++++++++++ libsrc/osic1p/cpeekc.s | 17 ++++++++++++ libsrc/osic1p/cpeekcolor.s | 8 ++++++ libsrc/osic1p/cpeekrevers.s | 9 +++++++ libsrc/pce/cpeekc.s | 6 ++--- libsrc/pce/cpeekcolor.s | 6 ++--- libsrc/pce/cpeekrevers.s | 14 +++++----- libsrc/pce/cpeeks.s | 28 ++++++++----------- 19 files changed, 286 insertions(+), 46 deletions(-) create mode 100644 libsrc/atari/cpeekc.s create mode 100644 libsrc/atari/cpeekcolor.s create mode 100644 libsrc/atari/cpeekrevers.s create mode 100644 libsrc/atmos/cpeekc.s create mode 100644 libsrc/atmos/cpeekcolor.s create mode 100644 libsrc/atmos/cpeekrevers.s create mode 100644 libsrc/atmos/cpeeks.s create mode 100644 libsrc/nes/cpeekc.s create mode 100644 libsrc/osic1p/cpeekc.s create mode 100644 libsrc/osic1p/cpeekcolor.s create mode 100644 libsrc/osic1p/cpeekrevers.s diff --git a/include/atmos.h b/include/atmos.h index 227c387aa..35d4e0582 100644 --- a/include/atmos.h +++ b/include/atmos.h @@ -169,6 +169,15 @@ 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 + /* End of atmos.h */ diff --git a/include/conio.h b/include/conio.h index bac20e3c5..71fe7315e 100644 --- a/include/conio.h +++ b/include/conio.h @@ -35,16 +35,16 @@ /* ** This is the direct console interface for cc65. I do not like the function -** names very much, but the first version started as a rewrite of Borland's -** conio, and, even if the interface has changed, the names did not. +** names very much; but, the first version started as a rewrite of Borland's +** conio; and, even if the interface has changed, the names did not. ** -** The interface does direct screen I/O, so it is fast enough for most -** programs. I did not implement text windows, since many applications do -** not need them and should not pay for the additional overhead. It should -** be easy to add text windows on a higher level if needed, +** The interface does direct screen I/O; so, it is fast enough for most +** programs. I did not implement text windows because many applications do +** not need them, and should not pay for the additional overhead. It should +** be easy to add text windows on a higher level if needed. ** -** Most routines do not check the parameters. This may be unfortunate but is -** also related to speed. The coordinates are always 0/0 based. +** Most routines do not check the parameters. That might be unfortunate; +** but also is related to speed. The coordinates are always (0,0)-based. */ @@ -191,10 +191,10 @@ void __fastcall__ cputhex16 (unsigned val); /* On some platforms, functions are not available or are dummys. To suppress -** the call to these functions completely, the platform header files may -** define macros for these functions that start with an underline. If such a -** macro exists, a new macro is defined here, that expands to the one with the -** underline. The reason for this two stepped approach is that it is sometimes +** the call to those functions completely, the platform header files may +** define macros for those functions that start with an underscore. If such a +** macro exists, a new macro is defined here that expands to the one with the +** underscore. The reason for this two-stepped approach is that it is sometimes ** necessary to take the address of the function, which is not possible when ** using a macro. Since the function prototype is still present, #undefining ** the macro will give access to the actual function. diff --git a/include/osic1p.h b/include/osic1p.h index d6ab5fee1..004c38010 100644 --- a/include/osic1p.h +++ b/include/osic1p.h @@ -43,5 +43,6 @@ #define _textcolor(color) COLOR_WHITE #define _bgcolor(color) COLOR_BLACK #define _bordercolor(color) COLOR_BLACK +#define _cpeekcolor(color) COLOR_WHITE #endif 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/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/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/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/libsrc/c128/cpeeks.s b/libsrc/c128/cpeeks.s index 12c3349e4..e4b5ad3a7 100644 --- a/libsrc/c128/cpeeks.s +++ b/libsrc/c128/cpeeks.s @@ -11,9 +11,6 @@ .importzp ptr1, ptr2, ptr3, tmp1, tmp2 .macpack generic - -; FIXME c128 needs special version that handles the 80-column VDC. - .include "c128.inc" _cpeeks: @@ -97,7 +94,7 @@ c80: stx ptr1+1 ldx #<$0000 stx ptr1 - bze L3a ; branch always + bze L3a ; branch always L4a: lda ptr2 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/osic1p/cpeekc.s b/libsrc/osic1p/cpeekc.s new file mode 100644 index 000000000..55a170501 --- /dev/null +++ b/libsrc/osic1p/cpeekc.s @@ -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 diff --git a/libsrc/osic1p/cpeekcolor.s b/libsrc/osic1p/cpeekcolor.s new file mode 100644 index 000000000..ed275ec95 --- /dev/null +++ b/libsrc/osic1p/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/osic1p/cpeekrevers.s b/libsrc/osic1p/cpeekrevers.s new file mode 100644 index 000000000..ab7c68b35 --- /dev/null +++ b/libsrc/osic1p/cpeekrevers.s @@ -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 diff --git a/libsrc/pce/cpeekc.s b/libsrc/pce/cpeekc.s index e144f94ac..326fe5203 100644 --- a/libsrc/pce/cpeekc.s +++ b/libsrc/pce/cpeekc.s @@ -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 diff --git a/libsrc/pce/cpeekcolor.s b/libsrc/pce/cpeekcolor.s index 8b96d29d4..ecee91ed5 100644 --- a/libsrc/pce/cpeekcolor.s +++ b/libsrc/pce/cpeekcolor.s @@ -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 diff --git a/libsrc/pce/cpeekrevers.s b/libsrc/pce/cpeekrevers.s index 3f208fd10..fa982de88 100644 --- a/libsrc/pce/cpeekrevers.s +++ b/libsrc/pce/cpeekrevers.s @@ -14,13 +14,13 @@ _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 + and #$80 ; get reverse bit + asl a + tax ; ldx #>$0000 + rol a ; return boolean value rts diff --git a/libsrc/pce/cpeeks.s b/libsrc/pce/cpeeks.s index fe5e28687..322b9ba30 100644 --- a/libsrc/pce/cpeeks.s +++ b/libsrc/pce/cpeeks.s @@ -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