commit d3a54e24eef8b1cb6f8427cc1d8968504d403b48 Author: Brian Holman Date: Mon Nov 9 23:35:21 2026 -0700 Import Cardgame 0.1.15 upstream source snapshot Original author: Pierre Sarrazin. Public-domain library and demo. Source: http://sarrazip.com/dev/cardgame-0.1.15.tar.gz Archive SHA-256: ca706dddd96fec63b829f8958c2e47485b0e1166129d45fda0b6369404c1bb54 diff --git a/8-bit-wide-font.c b/8-bit-wide-font.c new file mode 100644 index 0000000..6eba614 --- /dev/null +++ b/8-bit-wide-font.c @@ -0,0 +1,81 @@ +/* 8-bit-wide-font.c - 8x8 font for the Color Computer + + By Pierre Sarrazin . + This file is in the public domain. + + Does not include glyphs from 94 to 127 (i.e., no lower case letters). + Size in memory: 434 bytes. + In the 8x8 grid, the two left-most columns are always empty, i.e., + the two highest bits in each byte are 0. +*/ + +#include "8-bit-wide-font.h" + + +const unsigned char eightBitWideFont[65][7] = { +{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, // ( 32, 0x20) +{ 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x00, 0x0C, }, // ! ( 33, 0x21) +{ 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, }, // " ( 34, 0x22) +{ 0x1E, 0x1E, 0x1E, 0x3F, 0x1E, 0x1E, 0x1E, }, // # ( 35, 0x23) +{ 0x0C, 0x1E, 0x30, 0x3F, 0x03, 0x1E, 0x0C, }, // $ ( 36, 0x24) +{ 0x33, 0x33, 0x06, 0x0C, 0x18, 0x33, 0x33, }, // % ( 37, 0x25) +{ 0x1C, 0x36, 0x30, 0x18, 0x3C, 0x36, 0x1B, }, // & ( 38, 0x26) +{ 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, }, // ' ( 39, 0x27) +{ 0x03, 0x06, 0x0C, 0x0C, 0x0C, 0x06, 0x03, }, // ( ( 40, 0x28) +{ 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x18, 0x30, }, // ) ( 41, 0x29) +{ 0x00, 0x0C, 0x1E, 0x3F, 0x1E, 0x0C, 0x00, }, // * ( 42, 0x2A) +{ 0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, }, // + ( 43, 0x2B) +{ 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x18, }, // , ( 44, 0x2C) +{ 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, }, // - ( 45, 0x2D) +{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, }, // . ( 46, 0x2E) +{ 0x03, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x30, }, // / ( 47, 0x2F) +{ 0x1E, 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, }, // 0 ( 48, 0x30) +{ 0x1C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, }, // 1 ( 49, 0x31) +{ 0x1E, 0x33, 0x03, 0x06, 0x0C, 0x18, 0x3F, }, // 2 ( 50, 0x32) +{ 0x1E, 0x33, 0x03, 0x0E, 0x03, 0x33, 0x1E, }, // 3 ( 51, 0x33) +{ 0x33, 0x33, 0x33, 0x3F, 0x03, 0x03, 0x03, }, // 4 ( 52, 0x34) +{ 0x3F, 0x30, 0x30, 0x3E, 0x03, 0x03, 0x3E, }, // 5 ( 53, 0x35) +{ 0x1E, 0x33, 0x30, 0x3E, 0x33, 0x33, 0x1E, }, // 6 ( 54, 0x36) +{ 0x3F, 0x03, 0x03, 0x06, 0x0C, 0x0C, 0x0C, }, // 7 ( 55, 0x37) +{ 0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, }, // 8 ( 56, 0x38) +{ 0x1E, 0x33, 0x33, 0x1F, 0x03, 0x33, 0x1E, }, // 9 ( 57, 0x39) +{ 0x00, 0x0C, 0x0C, 0x00, 0x0C, 0x0C, 0x00, }, // : ( 58, 0x3A) +{ 0x00, 0x0C, 0x0C, 0x00, 0x0C, 0x0C, 0x18, }, // ; ( 59, 0x3B) +{ 0x03, 0x06, 0x0C, 0x18, 0x0C, 0x06, 0x03, }, // < ( 60, 0x3C) +{ 0x00, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x00, }, // = ( 61, 0x3D) +{ 0x30, 0x18, 0x0C, 0x06, 0x0C, 0x18, 0x30, }, // > ( 62, 0x3E) +{ 0x1E, 0x33, 0x03, 0x06, 0x0C, 0x00, 0x0C, }, // ? ( 63, 0x3F) +{ 0x1E, 0x33, 0x03, 0x1F, 0x33, 0x33, 0x1E, }, // @ ( 64, 0x40) +{ 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, }, // A ( 65, 0x41) +{ 0x3E, 0x33, 0x33, 0x3E, 0x33, 0x33, 0x3E, }, // B ( 66, 0x42) +{ 0x1E, 0x33, 0x30, 0x30, 0x30, 0x33, 0x1E, }, // C ( 67, 0x43) +{ 0x3E, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3E, }, // D ( 68, 0x44) +{ 0x3F, 0x30, 0x30, 0x3C, 0x30, 0x30, 0x3F, }, // E ( 69, 0x45) +{ 0x3F, 0x30, 0x30, 0x3C, 0x30, 0x30, 0x30, }, // F ( 70, 0x46) +{ 0x1F, 0x30, 0x30, 0x33, 0x33, 0x33, 0x1F, }, // G ( 71, 0x47) +{ 0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, }, // H ( 72, 0x48) +{ 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, }, // I ( 73, 0x49) +{ 0x03, 0x03, 0x03, 0x03, 0x03, 0x33, 0x1E, }, // J ( 74, 0x4A) +{ 0x33, 0x33, 0x36, 0x3C, 0x36, 0x33, 0x33, }, // K ( 75, 0x4B) +{ 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3F, }, // L ( 76, 0x4C) +{ 0x33, 0x3F, 0x3F, 0x3F, 0x33, 0x33, 0x33, }, // M ( 77, 0x4D) +{ 0x33, 0x33, 0x3B, 0x3F, 0x37, 0x33, 0x33, }, // N ( 78, 0x4E) +{ 0x1E, 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, }, // O ( 79, 0x4F) +{ 0x3E, 0x33, 0x33, 0x3E, 0x30, 0x30, 0x30, }, // P ( 80, 0x50) +{ 0x1E, 0x33, 0x33, 0x33, 0x33, 0x36, 0x1F, }, // Q ( 81, 0x51) +{ 0x3E, 0x33, 0x33, 0x3E, 0x3C, 0x36, 0x33, }, // R ( 82, 0x52) +{ 0x1E, 0x33, 0x30, 0x0C, 0x03, 0x33, 0x1E, }, // S ( 83, 0x53) +{ 0x3F, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, }, // T ( 84, 0x54) +{ 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, }, // U ( 85, 0x55) +{ 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, }, // V ( 86, 0x56) +{ 0x33, 0x33, 0x33, 0x3F, 0x3F, 0x3F, 0x33, }, // W ( 87, 0x57) +{ 0x33, 0x33, 0x1E, 0x0C, 0x1E, 0x33, 0x33, }, // X ( 88, 0x58) +{ 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, }, // Y ( 89, 0x59) +{ 0x3F, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x3F, }, // Z ( 90, 0x5A) +{ 0x0F, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0F, }, // [ ( 91, 0x5B) +{ 0x30, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x03, }, // \ ( 92, 0x5C) +{ 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, }, // ] ( 93, 0x5D) +{ 0x0C, 0x1E, 0x3F, 0x0C, 0x0C, 0x0C, 0x0C, }, // ^ ( 94, 0x5E) +{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, }, // _ ( 95, 0x5F) +{ 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, }, // ` ( 96, 0x60) +}; diff --git a/8-bit-wide-font.h b/8-bit-wide-font.h new file mode 100644 index 0000000..b945fb3 --- /dev/null +++ b/8-bit-wide-font.h @@ -0,0 +1,12 @@ +/* 8-bit-wide-font.h - 8x8 font for the Color Computer + + By Pierre Sarrazin . + This file is in the public domain. +*/ + +#ifndef _8_bit_wide_font_h +#define _8_bit_wide_font_h + +extern const unsigned char eightBitWideFont[65][7]; + +#endif /* _8_bit_wide_font_h */ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6545073 --- /dev/null +++ b/Makefile @@ -0,0 +1,130 @@ +# By Pierre Sarrazin +# This file is in the public domain. + +PACKAGE = cardgame +VERSION = 0.1.15 +TARGET = coco + +ifneq "$(TARGET)" "os9" +EXEEXT = .bin +endif + +LIBSRC = \ + $(PACKAGE).c \ + pmode4game.c \ + 8-bit-wide-font.c \ + compiled-cards.c \ + initSound.c \ + beep.c \ + whiteNoise.c \ + OS9Timer.c \ + invertCharAtCursor.c \ + waitForKeyWithAnimatedCursor.c \ + moveCursorLeft.c \ + drawCharWithoutMovingCursor.c \ + readLineFromKeyboard.c \ + concat.c \ + enableInvertedColorText.c \ + setColorInversionMask.c \ + printCentered.c \ + setScreenBuffer.c \ + setScreenBuffer2.c \ + moveCursor.c \ + getCursor.c \ + hiResTextConsoleOutHook.c \ + drawChar.c \ + setTextAreaScrollCallback.c \ + getCurrentCharPos.c \ + pmode4game_vars.c \ + setInvertedColorsParameters.c \ + makeSpacesTransparent.c + +LIBHEADERS = \ + $(PACKAGE).h \ + pmode4game.h \ + pmode4game_private.h \ + 8-bit-wide-font.h \ + compiled-cards.h \ + OS9Timer.h + +STATICLIB = lib$(PACKAGE).a + +CARDGAMEDEMOSRC = $(PACKAGE)-demo.c +CARDGAMEDEMOBIN = $(PACKAGE)$(EXEEXT) + +BEEPDEMOSRC = beep-demo.c +ifneq "$(TARGET)" "os9" +BEEPDEMOBIN = beep$(EXEEXT) +endif + +OS9TIMERDEMOSRC = os9timer-demo.c +ifeq "$(TARGET)" "os9" +OS9TIMERDEMOBIN = os9timer +endif + +DISTFILES = README.md Makefile $(LIBHEADERS) $(LIBSRC) $(CARDGAMEDEMOSRC) $(BEEPDEMOSRC) $(OS9TIMERDEMOSRC) + +ORG = #--org=2800 +INTERMEDIATE = #--intermediate +NDEBUG = -DNDEBUG +WARNINGS = -Wfor-condition-sizes +WERROR = -Werror +CFLAGS = --$(TARGET) $(WARNINGS) $(WERROR) $(NDEBUG) $(INTERMEDIATE) +LDFLAGS = --$(TARGET) $(ORG) $(INTERMEDIATE) + +CARDGAMEDEMOOBJ = $(CARDGAMEDEMOSRC:.c=.o) +BEEPDEMOOBJ = $(BEEPDEMOSRC:.c=.o) +OS9TIMERDEMOOBJ = $(OS9TIMERDEMOSRC:.c=.o) +LIBOBJ = $(LIBSRC:.c=.o) + +CMOC = cmoc +LWAR = lwar +TAR = tar + +all: $(CARDGAMEDEMOBIN) $(BEEPDEMOBIN) $(OS9TIMERDEMOBIN) + +$(CARDGAMEDEMOBIN): $(CARDGAMEDEMOOBJ) $(STATICLIB) + $(CMOC) -o $(CARDGAMEDEMOBIN) $(LDFLAGS) $(CARDGAMEDEMOOBJ) -L. -l$(PACKAGE) + +ifneq "$(TARGET)" "os9" +$(BEEPDEMOBIN): $(BEEPDEMOOBJ) $(STATICLIB) + $(CMOC) -o $(BEEPDEMOBIN) $(LDFLAGS) $(BEEPDEMOOBJ) -L. -l$(PACKAGE) +endif + +ifeq "$(TARGET)" "os9" +$(OS9TIMERDEMOBIN): $(OS9TIMERDEMOOBJ) $(STATICLIB) + $(CMOC) -o $(OS9TIMERDEMOBIN) $(LDFLAGS) $(OS9TIMERDEMOOBJ) -L. -l$(PACKAGE) +endif + +$(STATICLIB): $(LIBOBJ) + $(LWAR) --create $(STATICLIB) $(LIBOBJ) + +%.o: %.c + $(CMOC) -c $(CFLAGS) -o $@ $< + +clean: + rm -f $(CARDGAMEDEMOBIN) $(CARDGAMEDEMOOBJ) $(BEEPDEMOBIN) $(BEEPDEMOOBJ) $(OS9TIMERDEMOBIN) $(OS9TIMERDEMOOBJ) $(STATICLIB) $(LIBOBJ) + +.PHONY: dist +dist: + $(TAR) -czf $(PACKAGE)-$(VERSION).tar.gz --transform 's,^,$(PACKAGE)-$(VERSION)/,' $(DISTFILES) + +distcheck: dist + mkdir ,distcheck + $(TAR) -C ,distcheck -xzf $(PACKAGE)-$(VERSION).tar.gz + $(MAKE) -C ,distcheck/$(PACKAGE)-$(VERSION) all + rm -fr ,distcheck + @echo "SUCCESS: $(PACKAGE)-$(VERSION).tar.gz ready for distribution" + +# Automatic prerequisite generation. +%.d: %.c + $(CMOC) --deps-only $(CFLAGS) $< + +.PHONY: cleandeps +cleandeps: + rm -f $(CARDGAMEDEMOSRC:.c=.d) $(BEEPDEMOSRC:.c=.d) $(OS9TIMERDEMOSRC:.c=.d) $(LIBSRC:.c=.d) + +include $(CARDGAMEDEMOSRC:.c=.d) +include $(BEEPDEMOSRC:.c=.d) +include $(OS9TIMERDEMOSRC:.c=.d) +include $(LIBSRC:.c=.d) diff --git a/OS9Timer.c b/OS9Timer.c new file mode 100644 index 0000000..4f325e6 --- /dev/null +++ b/OS9Timer.c @@ -0,0 +1,118 @@ +#include "OS9Timer.h" + +#ifdef OS9 + + +static const char *OS9Timer_deviceName = "/Nil"; // driver presumed installed in OS-9 +static byte OS9Timer_nilPathNumber; +static word OS9Timer_counter; + + +static asm interrupt void +OS9Timer_signalHandler(void) +{ + asm + { + tfr u,y // make Y point to data segment, to access globals + ldd :OS9Timer_counter + addd #1 + std :OS9Timer_counter + } +} + + +byte +OS9Timer_init(unsigned ticksPerIncrement) +{ + byte errorCode; + asm + { + clr :errorCode + ; + // Tell OS-9 which function must be called when this process receives a signal. + leax OS9Timer_signalHandler + exg u,y // pass data segment address in U + os9 $09 // F$Icpt + exg u,y // restore both registers + + lda #1 // read mode + ldx :OS9Timer_deviceName + os9 $84 // I$Open + bcs @ErrExit + sta :OS9Timer_nilPathNumber + bra @nilOpen +@ErrExit + stb :errorCode + bra @done +@nilOpen + pshs y // preserve data segment register + ldy :ticksPerIncrement // number of 60 Hz ticks + ldb #$C7 // set FS2+ VIRQ entry + tfr y,x + os9 $8E // I$SetStt + puls y + bcs @ErrExit +@done + } + return errorCode; +} + + +byte +OS9Timer_shutdown(void) +{ + byte errorCode; + asm + { + clr :errorCode + pshs y // preserve data segment register + lda :OS9Timer_nilPathNumber + ldb #$81 // call code + ldy #0 // clears entry + os9 $8E // I$SetStt + puls y + bcc @entryCleared // if success + stb :errorCode + bra @done +@entryCleared + ; Close the path to /Nil. + lda :OS9Timer_nilPathNumber + os9 $8F // I$Close + bcc @done // if success + stb :errorCode +@done + } + return errorCode; +} + + +word +OS9Timer_getTimer(void) +{ + return OS9Timer_counter; +} + + +void +OS9Timer_setTimer(word newValue) +{ + OS9Timer_counter = newValue; +} + + +void +OS9Timer_delay(word ticksToWait) +{ + asm + { + LDD :ticksToWait // ticksToWait + BEQ @done + ADDD :OS9Timer_counter // value that TIMER must reach +@loop CMPD :OS9Timer_counter + BNE @loop +@done + } +} + + +#endif /* OS9 */ diff --git a/OS9Timer.h b/OS9Timer.h new file mode 100644 index 0000000..be01e30 --- /dev/null +++ b/OS9Timer.h @@ -0,0 +1,49 @@ +#ifndef _H_OS9Timer +#define _H_OS9Timer + +#include + + +#ifdef OS9 + + +// Initializes a timer system that maintains a 16-bit unsigned counter. +// This counters wraps to 0 when it passes 65535. +// +// ticksPerIncrement: How many sixtieths of a second before the timer is incremented by 1. +// Pass 1 to have a counter similar to Color Basic's TIMER. +// +// Call OS9Timer_shutdown() when finished with the use of the timer. +// +// CAUTION: OS-9 F$Sleep call gets stopped by the interrupts caused by this timer system. +// This means that CMOC's delay() function is affected too. +// Delays may be achieved with OS9Timer_delay() instead. +// +byte OS9Timer_init(unsigned ticksPerIncrement); + + +// Releases the resources used by this timer system. +// +byte OS9Timer_shutdown(void); + + +// Returns the current value of the periodically incremented counter. +// +word OS9Timer_getTimer(void); + + +// Changes the current value of the periodically incremented counter. +// +void OS9Timer_setTimer(word newValue); + + +// Wait for the specified number of increments to have been made to the counter. +// Can be used as a replacement for the F$Sleep system call and for the delay() function. +// +void OS9Timer_delay(word ticksToWait); + + +#endif /* OS9 */ + + +#endif /* _H_OS9Timer */ diff --git a/README.md b/README.md new file mode 100644 index 0000000..279a27b --- /dev/null +++ b/README.md @@ -0,0 +1,115 @@ +CardGame +======== + +By Pierre Sarrazin (). + +This library is in the public domain. + +It is a C library that offers a PMODE 4 game library that can display +playing cards. It targets the Tandy Color Computer but should also work +on the Dragon. Most of the features should also work on CoCo-based +versions of OS-9. + + +# OS-9 Support + +OS-9 was suspended with version 0.1.11 but has been restored with version 0.1.12. + +Note that the sound features of this version of the library are not supported under OS-9. + +To compile with OS-9, pass TARGET=os9 to make. + +The "cardgame" demo program MUST be run from a 32x16 VDG terminal. +Use the Clear key to find one. +If none exists, create one with the "shell i=/v1" command, then use Clear to find it. + +The "os9timer" demo program can be run from any terminal. + +There is no "beep" demo program for OS-9. + + +# Adapting to version 0.1.11 + +openPMode4GameScreenMode() and closePMode4GameScreenMode() have been renamed to +openPMode4Game() and closePMode4Game() because the latter does not restore +the screen mode anymore. It cannot know in which mode the screen was initially. + +openPMode4Game() does not call resetPalette() anymore, which assumed that Basic +was present. That call was made only when TRUE was passed for emulatePMode4OnCoCo3. +Now, in this case, only palette slots 0..3 are initialized. + +openCardGameScreenMode() and closeCardGameScreenMode() have been renamed to +openCardGame() and closeCardGame() for similar reasons. + +restoreOriginalTextMode() has been removed from the interface, since it relied +on Basic. The program must restore the text mode itself, if needed. + +Under OS-9, this can be done this way: + + putstr("\x12\x0E", 2); + +Under the native environment: + + screen(0, 0); + +Function waitForKeyWithAnimatedCursor() and readLineFromKeyboard() must now +be passed a callback to a function that returns a timer value that increments +60 times per second. See pmode4game.h for details. + + +# Text font + +The text font supports ASCII characters 32 to 96 inclusively. It does not +support lower-case letters. + +The font is 8 bits wide, which makes it relatively efficient to write. + +See 8-bit-wide-font.h and 8-bit-wide-font.c. + + +# Version history + + 0.1.0 - 2015-08-12 - First public release. + 0.1.1 - 2016-03-12 - New #defines. New function drawFaceDownCard(). + 0.1.2 - 2016-03-25 - setConsoleOutHook() and resetConsoleOutHook() now taken + from . + 0.1.3 - 2017-12-01 - openCardGameScreenMode() now optionally emulates PMODE 4 + in a CoCo 3 mode to approximate the artifact colors. + Assumes RGB mode. Adapted to compile in linker mode. + 0.1.4 - 2018-04-03 - Adaptation to CMOC 0.1.51 (const). + 0.1.5 - 2018-08-04 - Added square brackets and backslash to 8-bit-wide-font.c. + Added sound routines. + 0.1.6 - 2018-09-20 - Adapted to CMOC 0.1.53. + Sound functions now declared by cardgame.h. beep.h now obsolete. + 0.1.7 - 2018-10-04 - Fixed openPMode4GameScreenMode() re: CoCo 3 mode. + 0.1.8 - 2018-11-25 - Now compilable for the Dragon (make TARGET=dragon). + 0.1.9 - 2019-06-03 - OS-9 supported, except for sound. + 0.1.10 - 2020-06-28 - Functions added: drawCharWithoutMovingCursor(), moveCursorLeft(), + invertCharAtCursor(), waitForKeyWithAnimatedCursor(), readLineFromKeyboard(). + Removed PMODE4_PAGE0 and PMODE4_PAGE1: use + (byte *) (((word) * (byte *) 0x00BC) << 8) + to get the ECB PMODE buffer address instead. + 0.1.11 - 2023-06-27 - The library does not assume the presence of Basic anymore. + See section "Adapting to version 0.1.11" for details. + OS-9 support is suspended [restored with 0.1.12]. + 0.1.12 - 2024-06-08 - Added setScreenBuffer2(), which allows to omit showing the screen. + Put several functions in individual C files to help reduce the size + of programs that do not use all functions of this library. + Added os9timer-demo.c to the archive generated by 'make dist'. + 0.1.13 - 2025-11-16 Added drawCompiledCard2(), which supports drawing the suit a little + higher or lower than the default, and supports only drawing the top + of a card, by specifying the number of pixel rows to draw. + Fixed drawCompiledPixMap() so that its inline assembly does not + refer to any global C variable in the code section that uses + the Y register. (That register is used under OS-9 to point to + the current process's global variables segment.) The old code + was not defective but its structure was error prone. + Added getCursor(), which returns the current position of the cursor. + Removed runPMode4GameDoubleBufferLoop(), which is obsolete. + 0.1.14 - 2026-02-05 Added setInvertedColorsParameters(), which determines how caracters + are rendered in inverted colors mode, from parameters drawRowOverGlyph + and drawColumnAtRightOfGlyph. + Added makeSpacesTransparent(), which determines if space characters + are drawn (the pixels take the background color) or not (the pixels + remain unmodified). + 0.1.15 - 2026-09-06 Added ^, _ and ` to the 8-bit-wide font. diff --git a/beep-demo.c b/beep-demo.c new file mode 100644 index 0000000..8aa8a1f --- /dev/null +++ b/beep-demo.c @@ -0,0 +1,82 @@ +// By Pierre Sarrazin +// This file is in the public domain. +// +// This program must run under DECB. + +#include "cardgame.h" + + +int main() +{ + initCoCoSupport(); + resetPalette(TRUE); + initSound(); + + byte duration = 50; + word freq = 220; + byte volume = BEEP_MAX_VOL; + word spacing = 16; + byte showPrompt = TRUE; + for (;;) + { + if (showPrompt) + { + printf("bEEP\n" + "wHITE NOISE\n" + "dURATION: %u\n" + "sPACING: %u\n" + "fREQ: %u HZ\n" + "qUIT\n", + duration, spacing, freq); + printf("COMMAND? "); + } + byte key = (byte) toupper(waitkey(TRUE)); + if (key == 'Q') + { + printf("\n"); + break; + } + showPrompt = FALSE; + switch (key) + { + case 'B': + beep(duration, getTicksForFrequency(freq), volume); + break; + case 'W': + whiteNoise(duration, spacing, volume); + break; + case 'D': + { + printf("\n""NEW DURATION (1-255)? "); + word w = readword(); + if (w == 0 || w > 255) + printf("INVALID.\n"); + else + duration = (byte) w; + showPrompt = TRUE; + break; + } + case 'F': // frequency: only for beep + { + printf("\n""NEW FREQUENCY (HZ)? "); + word w = readword(); + if (w < 20 || w > 20000) + printf("INVALID.\n"); + else + freq = w; + showPrompt = TRUE; + break; + } + case 'S': // spacing: only for white noise + { + printf("\n""NEW SPACING (0-65535)? "); + spacing = readword(); + showPrompt = TRUE; + break; + } + } + } + + printf("END.\n"); + return 0; +} diff --git a/beep.c b/beep.c new file mode 100644 index 0000000..ba4c626 --- /dev/null +++ b/beep.c @@ -0,0 +1,58 @@ +// By Pierre Sarrazin +// This file is in the public domain. + +#include "cardgame.h" + + +extern dword beep_cpuFreqDiv16; + + +word +getTicksForFrequency(word hertz) +{ + return (word) (beep_cpuFreqDiv16 / hertz) - 2; +} + + +void +beep(byte duration, word ticks, byte volume) +{ + byte shiftedVolume = volume << 2; + asm + { +; Nops are inserted so that an equal number of cycles is spent in each +; of the two phases of the square wave. +; The @halfSquareWave routine takes a number of cycles equal to +; 2 + 5 + 6 + ticks * (5 + 3) + 5, i.e., +; 18 + 8 * ticks. +; If we want a square wave of frequency F (e.g., 200 Hz), +; then we want a half period of 1 / F / 2 (e.g., 0.0025 s), +; If the CPU frequency is C (e.g., 894886 Hz), +; then the number of cycles for one half period is C / F / 2 (e.g., 2237.22 cycles). +; Hence, 18 + 8 * ticks == C / F / 2, +; i.e., ticks = C / F / 16 - 2.25 (e.g., 277.402 ticks). +; +@loop + lda :shiftedVolume ; 5 cycles in low phase + bsr @halfSquareWave ; 7+N cycles in high phase + lda #0 ; 2 cycles in high phase + lbrn @loop ; 5 cycles in high phase + lbrn @loop ; 5 cycles in high phase + brn @loop ; 3 cycles in high phase + bsr @halfSquareWave ; 7+N cycles in low phase + dec :duration ; 7 cycles in low phase + bne @loop ; 3 cycles in low phase + bra @done +@halfSquareWave + anda #$FC ; keep 6 high bits ; 2 cycles + sta $FF20 ; send ; 5 cycles + ldx :ticks ; 6 cycles +@sleep + leax -1,x ; 5 cycles + bne @sleep ; 3 cycles + rts ; 5 cycles +@done + } +} + + diff --git a/cardgame-demo.c b/cardgame-demo.c new file mode 100644 index 0000000..9ea9c3b --- /dev/null +++ b/cardgame-demo.c @@ -0,0 +1,80 @@ +/* cardgame.c + Skeleton CoCo program that draws playing cards. + + By Pierre Sarrazin . + This file is in the public domain. +*/ + +#include "cardgame.h" + + +int +main() +{ + // Initialize the PMODE 4 screen. + // Under OS-9, no screen buffer address is passed because the system chooses it. + // This initializes the (global) scrnBuffer pointer. + // Use showGraphicsAddress() to point to another PMODE 4 buffer later + // (not supported under OS-9). + // CoCo 3 emulation of artifact colors is not supported under OS-9. + #ifdef OS9 + openCardGame(NULL, FALSE); + #else + openCardGame((void *) (((word) * (byte *) 0x00BC) << 8), TRUE); + #endif + + // Precompute the number of pixel rows per card, for the coming loops. + byte cardHeight = getNumPixelRowsPerCard(); + + // Draw the 52 ordinary cards in a grid, which each card overlapping + // its predecessor in the current row. + byte pixelRow = 0; + byte horizSkip = 4; + for (byte suit = SUIT_HEARTS; suit <= SUIT_CLUBS; ++suit, pixelRow += cardHeight + horizSkip) + { + for (byte value = 1; value <= 13; ++value) // ace to king + { + byte byteCol = (value - 1) << 1; // 2 bytes of visible width per card (other 2 bytes gets overlapped) + drawCompiledCard(value, suit, byteCol, pixelRow); + } + } + + // Draw the two jokers at top right. + for (byte joker = 1; joker <= 2; ++joker) + drawCompiledCard(joker, SUIT_JOKER, 28, (joker - 1) * (cardHeight + 4)); + + // Draw a face-down card at bottom right. + drawFaceDownCard(PIXEL_ROWS_PER_SCREEN - getNumPixelRowsPerCard(), 28); + + // Show a prompt at the bottom and wait for the user to quit. + moveCursor(0, 23); + #ifdef OS9 // Only a delay, because no waitkey() + word delayInSeconds = 5; + printf("QUITTING AFTER %u SECONDS.", delayInSeconds); + delay(delayInSeconds * 60); + #else + printf("PRESS BREAK TO QUIT."); + while (waitkey(FALSE) != 3) + ; + #endif + + // Erase the jokers over a short delay, as an example of erasing cards. + eraseCard(28, cardHeight + 4); + delay(30); + eraseCard(28, 0); + delay(30); + + // Go back to the text screen. + closeCardGame(); + #ifdef OS9 + putstr("\x12\x0E", 2); + #else + width(32); + screen(0, 0); + cls(255); + #endif + + // printf() now prints to the hardware CoCo text screen. + printf("THANKS FOR PLAYING.\n"); + return 0; +} diff --git a/cardgame.c b/cardgame.c new file mode 100644 index 0000000..80e325e --- /dev/null +++ b/cardgame.c @@ -0,0 +1,281 @@ +/* cardgame.c - PMODE 4 playing cards library for the CoCo. + + By Pierre Sarrazin . + This file is in the public domain. +*/ + +#include "cardgame.h" + + +byte * +drawCompiledPixMap2(byte byteOffset, byte pixelRow, const word *wordArray, byte numRows, + byte rowRepetitions, const byte *drawingAreaEnd) +{ + assertf(byteOffset < BYTES_PER_SCREEN_ROW, "%u", byteOffset); + assertf(pixelRow < PIXEL_ROWS_PER_SCREEN, "%u", pixelRow); + assertf(numRows <= PIXEL_ROWS_PER_SCREEN, "%u", numRows); + assertf(pixelRow + numRows <= PIXEL_ROWS_PER_SCREEN, "%u, %u", pixelRow, numRows); + assertf(rowRepetitions > 0, "%u", rowRepetitions); + + /* Logic implemented in assembly language that follows: + word *dest = (word *) (scrnBuffer + (word) pixelRow * BYTES_PER_SCREEN_ROW + byteOffset); + for (byte i = 0; i < numRows; ++i) + { + word w = wordArray[i]; + for (byte r = 0; r < rowRepetitions; ++r) + { + if (dest >= drawingAreaEnd) + return; + *dest = w; + dest += WORDS_PER_SCREEN_ROW; + } + } + */ + + byte *topLeft; + byte r; // temp row counter + + asm + { + ldx :scrnBuffer // load global variable value, point X to screen start + + pshs y // save global data segment on OS-9 + + lda pixelRow + ldb #BYTES_PER_SCREEN_ROW + mul + addb byteOffset + adca #0 + leax d,x // make X point to first screen byte to write to + stx topLeft + + ldy :wordArray // cannot refer to global vars now on OS-9 + +drawCompiledPixMap_foreach_word: + ldb rowRepetitions // reinit rep counter + stb r + ldd ,y++ + +drawCompiledPixMap_foreach_rep: + cmpx :drawingAreaEnd // if past the writing limit + bhs drawCompiledPixMap_earlyEnd + + std ,x + leax BYTES_PER_SCREEN_ROW,x // move to next row down + + dec r + bne drawCompiledPixMap_foreach_rep + + dec numRows + bne drawCompiledPixMap_foreach_word + +drawCompiledPixMap_earlyEnd: + puls y + } + + return topLeft; +} + + +byte * +drawCompiledPixMap(byte byteOffset, byte pixelRow, const word *wordArray, byte numRows, byte rowRepetitions) +{ + return drawCompiledPixMap2(byteOffset, pixelRow, wordArray, numRows, + rowRepetitions, scrnBuffer + 6144); // assumes PMODE 4 +} + + +void +drawCompiledCard2(byte cardValue, byte cardSuit, byte byteColumn, byte pixelRow, + char suitRowOffset, byte maxNumRowsToDraw) +{ + --cardValue; // bring to 0..12 index + + const byte *drawingAreaEnd = scrnBuffer + (((word) pixelRow + maxNumRowsToDraw) << 5); // 32 bytes per row + + // Draw top of card. + drawCompiledPixMap2(byteColumn, pixelRow, cardTopLeft, ROWS_PER_CARD_TOP, 1, drawingAreaEnd); + drawCompiledPixMap2(byteColumn + 2, pixelRow, cardTopRight, ROWS_PER_CARD_TOP, 1, drawingAreaEnd); + + // Draw the blank part at the right of the card value. + drawCompiledPixMap2(byteColumn + 2, pixelRow + ROWS_PER_CARD_TOP, cardRight, 1, ROWS_PER_CARD_TOP * 2, drawingAreaEnd); + + // Draw card value (A, 2..10, J, Q, K, joker). + const word *pixmap; + if (cardSuit == SUIT_JOKER) + pixmap = (cardValue == 1 ? redJokerValue : blackJokerValue); + else + pixmap = (word *) ((cardSuit & 1) ? blackCards[cardValue] : redCards[cardValue]); + + drawCompiledPixMap2(byteColumn, pixelRow + ROWS_PER_CARD_TOP, pixmap, ROWS_PER_CARD_VALUE, 1, drawingAreaEnd); + + // Draw blank middle (the suit will be drawn over it). + byte middleRow = pixelRow + ROWS_PER_CARD_TOP + ROWS_PER_CARD_VALUE; + byte middleHeight = ROWS_ABOVE_SUIT + ROWS_PER_SUIT * 2 + ROWS_BELOW_SUIT; // times 2 b/c suit drawn w/ rowRepetitions == 2 + drawCompiledPixMap2(byteColumn, middleRow, cardLeft, 1, middleHeight, drawingAreaEnd); + drawCompiledPixMap2(byteColumn + 2, middleRow, cardRight, 1, middleHeight, drawingAreaEnd); + + // Draw bottom of card. + drawCompiledPixMap2(byteColumn, middleRow + middleHeight, cardBottomLeft, ROWS_PER_CARD_BOTTOM, 1, drawingAreaEnd); + drawCompiledPixMap2(byteColumn + 2, middleRow + middleHeight, cardBottomRight, ROWS_PER_CARD_BOTTOM, 1, drawingAreaEnd); + + // Draw suit. Use a 'rowRepetitions' of 2 to stretch the suit pixmap over 14 rows instead of 7 (ROWS_PER_SUIT). + byte suitByteOffset = byteColumn + 1; + byte suitRow = pixelRow + ROWS_PER_CARD_TOP + ROWS_ABOVE_SUIT + ROWS_PER_CARD_VALUE + suitRowOffset; + if (cardSuit == SUIT_JOKER) + drawCompiledPixMap2(suitByteOffset, suitRow, cardValue == 1 ? redJokerSuit : blackJokerSuit, ROWS_PER_SUIT, 2, drawingAreaEnd); + else + drawCompiledPixMap2(suitByteOffset, suitRow, suits[cardSuit], ROWS_PER_SUIT, 2, drawingAreaEnd); +} + + +void +drawCompiledCard(byte cardValue, byte cardSuit, byte byteColumn, byte pixelRow) +{ + drawCompiledCard2(cardValue, cardSuit, byteColumn, pixelRow, 0, 255); +} + + +byte +getNumPixelRowsPerCard() +{ + return ROWS_PER_CARD_TOP + ROWS_PER_CARD_VALUE + ROWS_ABOVE_SUIT + + ROWS_PER_SUIT * 2 + ROWS_BELOW_SUIT + ROWS_PER_CARD_BOTTOM; +} + + +void +eraseCard(byte byteColumn, byte pixelRow) +{ + word *p = (word *) (scrnBuffer + (((word) pixelRow) << 5) + byteColumn); + byte h = getNumPixelRowsPerCard(); + for (byte i = 0; i < h; ++i, p += WORDS_PER_SCREEN_ROW) + { + p[0] = 0; + p[1] = 0; + } +} + + +void +drawFaceDownCard(byte rowInPixels, byte colInBytes) +{ + word *writer = (word *) (scrnBuffer + (word) rowInPixels * BYTES_PER_SCREEN_ROW + colInBytes); + byte rowsPerCard = getNumPixelRowsPerCard(); + word wordToWrite = 0x5555; + for (byte row = 0; row < rowsPerCard; ++row, writer += WORDS_PER_SCREEN_ROW) + { + *writer = writer[1] = wordToWrite; // blue + if (row == rowsPerCard - 2) + wordToWrite = 0x5555; + else if (row & 1) + wordToWrite = 0x0505; + else + wordToWrite = 0x5050; + } +} + + +byte +getCardType(byte card) +{ + if (card <= 13) + return SUIT_HEARTS; + if (card <= 26) + return SUIT_SPADES; + if (card <= 39) + return SUIT_DIAMONDS; + if (card <= 52) + return SUIT_CLUBS; + if (card <= 54) + return SUIT_JOKER; + return BAD_CARD_SUIT; +} + + +byte +getCardValue(byte card) +{ + if (card == 0) + return BAD_CARD_VALUE; + if (card <= 52) + return (card - 1) % 13 + 1; + if (card <= 54) + return card - 52; + return BAD_CARD_VALUE; +} + + +const char * +getSuitName(byte suit) +{ + switch (suit) + { + case SUIT_HEARTS: return "hearts"; + case SUIT_SPADES: return "spades"; + case SUIT_DIAMONDS: return "diamonds"; + case SUIT_CLUBS: return "clubs"; + default: return "ERROR"; + } +} + + +void +shuffleDeck(byte deck[], byte numCards) +{ + for (byte i = 1; i < numCards; ++i) + { + byte other = (byte) (rand() % (numCards - i) + i); + assertf(i - 1 < NUMCARDS, "%u", i); + assertf(other < NUMCARDS, "%u", other); + byte temp = deck[i - 1]; + deck[i - 1] = deck[other]; + deck[other] = temp; + } +} + + +byte +pickCardFromDeck(byte deck[], byte *pNumCards) +{ + if (*pNumCards == 0) + return BAD_CARD_VALUE; + byte card = deck[--*pNumCards]; + assertf(card >= 1 && card <= NUMCARDS, "%u", card); + return card; +} + + +void +drawSuit(byte col, byte row, byte suit) +{ + // Draw the suit by repeating each pixmap row twice: + // + byte *topLeft = drawCompiledPixMap(col, row, suits[suit], ROWS_PER_SUIT, 2); + + // Draw a white horizontal line above and below the suit pixmap just drawn at topLeft: + // + byte *aboveRow = topLeft - BYTES_PER_SCREEN_ROW; + *((word *) aboveRow) = 0xFFFF; + *((word *) (topLeft + ROWS_PER_SUIT * BYTES_PER_SCREEN_ROW * 2)) = 0xFFFF; + + // Draw a white vertical line at the left of that pixmap: + // + byte *leftSide = aboveRow - 1; + for (byte numRows = (ROWS_PER_SUIT << 1) + 2; numRows; --numRows, leftSide += BYTES_PER_SCREEN_ROW) + *leftSide |= 0x01; +} + + +void +openCardGame(void *_scrnBuffer, byte _emulatePMode4OnCoCo3) +{ + openPMode4Game(_scrnBuffer, _emulatePMode4OnCoCo3); +} + + +void +closeCardGame(void) +{ + closePMode4Game(); +} diff --git a/cardgame.h b/cardgame.h new file mode 100644 index 0000000..a20ecb3 --- /dev/null +++ b/cardgame.h @@ -0,0 +1,182 @@ +/* cardgame.h - PMODE 4 playing cards library for Disk Basic. + + By Pierre Sarrazin . + This file is in the public domain. +*/ + +#ifndef _H_cardgame +#define _H_cardgame + +#include "pmode4game.h" +#include "compiled-cards.h" /* card bitmaps */ + +#ifdef OS9 +#include "OS9Timer.h" +#endif + + +#define NUMCARDS 54 +#define BAD_CARD_SUIT 0xFF +#define BAD_CARD_VALUE 0 +#define BAD_INDEX 0xFF + +#define ROWS_ABOVE_SUIT 2 +#define ROWS_BELOW_SUIT 6 +#define ROWS_PER_CARD_TOP 5 +#define ROWS_PER_CARD_BOTTOM ROWS_PER_CARD_TOP +#define BYTES_PER_CARD_WIDTH 4 +#define ROWS_PER_CARD_VALUE 10 +#define ROWS_PER_SUIT 7 + +#define SUIT_HEARTS 0 +#define SUIT_SPADES 1 +#define SUIT_DIAMONDS 2 +#define SUIT_CLUBS 3 +#define SUIT_JOKER 4 +#define SUIT_NONE 255 + + +/////////////////////////////////////////////////////////////////////////////// + + +// Draws a 16-bit-wide pixmap on the screen that starts at scrnBuffer. +// byteOffset: Offset in bytes from the left of the screen (must be < BYTES_PER_SCREEN_ROW). +// pixelRow: Vertical position (in pixels) of the row at which to start drawing (downwards). +// Must be < PIXEL_ROWS_PER_SCREEN. +// wordArray: Words that define the pixmap. +// numRows: Number of words in wordArray[]. Must be > 0. +// rowRepetitions: Number of times that each row must be repeated. Must be > 0. +// Example: If wordArray contains values { A, B, C }, and rowRepetitions is 2, +// then values A, A, B, B, C, C will be written in successive screen rows. +// Returns the address of the top left byte of the region that was modified. +// Uses global variable scrnBuffer as the start of the PMODE 4 screen buffer. +// +byte *drawCompiledPixMap(byte byteOffset, byte pixelRow, const word *wordArray, byte numRows, byte rowRepetitions); + + +// cardValue: 1..13 (1 = ace). +// cardSuit: SUIT_* (0..3). +// Except for jokers: cardValue must be 1 (red) or 2 (black) and cardSuit must be SUIT_JOKER. +// byteColumn: 0..28 (maps to pixel columns 0, 8, 16, ..., 224). +// pixelRow: 0..150. +// +// The number of pixels rows occupied by the card is given by getNumPixelRowsPerCard(). +// A card is 4 bytes wide, i.e., 32 pixels. +// +void drawCompiledCard(byte cardValue, byte cardSuit, byte byteColumn, byte pixelRow); + + +// Like drawCompiledCard(), but with these additiona parameters: +// suitRowOffset: Has the suit drawn a little higher or lower than the default. +// To draw the suit 2 pixel rows higher than the default, pass -2. +// maxNumRowsToDraw: Maximum of rows to draw, from the top of the card. +// Allows drawing only the top portion of a card. +// A card normally has a number of pixel rows that is given by +// getNumPixelRowsPerCard(). +// +void drawCompiledCard2(byte cardValue, byte cardSuit, byte byteColumn, byte pixelRow, + char suitRowOffset, byte maxNumRowsToDraw); + + +// Height of a card drawn by drawCompiledCard(). +// A card is 4 bytes wide, i.e., 32 pixels. +// +byte getNumPixelRowsPerCard(); + + +void eraseCard(byte byteColumn, byte pixelRow); + + +// rowInPixels: Offset in pixels down the top of the screen. +// colInBytes: Horizontal position of the card, in bytes (0..28). +// +void drawFaceDownCard(byte rowInPixels, byte colInBytes); + + +// Returns SUIT_HEARTS, SUIT_SPADES, SUIT_DIAMONDS, SUIT_CLUBS +// or SUIT_JOKER if 'card' is valid, BAD_CARD_SUIT otherwise. +// +byte getCardType(byte card); + + +// Returns 1..13 if 'card' is an ordinary ace-to-king card. +// Returns 1..2 if 'card' is a joker, i.e., getCardType() +// returns SUIT_JOKER for this card value. +// Returns BAD_CARD_VALUE otherwise. +// +byte getCardValue(byte card); + + +const char *getSuitName(byte suit); + + +void shuffleDeck(byte deck[], byte numCards); + + +// Removes a card from the end of the designated deck, which +// initially contains a number of cards given by *pNumCards, +// decrements this number, then returns the removed card. +// (The "top" of a deck is at the highest valid index, +// while the "bottom" is at index 0.) +// +byte pickCardFromDeck(byte deck[], byte *pNumCards); + + +// col: Byte offset in targeted row. +// row: Pixel row where to draw top of suit. +// suit: Index into suits[]. +// +void drawSuit(byte col, byte row, byte suit); + + +// Calls openPMode4Game(). +// +void openCardGame(void *_scrnBuffer, byte _emulatePMode4OnCoCo3); + + +// Calls closePMode4Game(). +// +void closeCardGame(void); + + +enum +{ + BEEP_MIN_VOL = 0, + BEEP_MAX_VOL = 63, +}; + + +// Must be called before using the functions that follow. +// CAUTION: These sound functions address the hardware directly +// and thus are not suitable for OS-9. +// +void initSound(); + + +// Returns the number of ticks to pass to beep() to have it play a +// square wave of the given frequency (in hertz). +// +word getTicksForFrequency(word hertz); + + +// initSound() MUST have been called before calling this function. +// duration: Must be positive (max 255). +// Should be >= 5 for usable sound. +// ticks: Length of the half period of the square wave. +// See getTicksForFrequency(). +// Larger number means lower sound. +// Should be <= 4000 for usable sound. Should not be 0. +// volume: 0..BEEP_MAX_VOL. +// +void beep(byte duration, word ticks, byte volume); + + +// duration: Must be positive (max 255). +// Should be >= 5 for usable sound. +// spacing: 0..65535: length of each random sample send to the speaker. +// volume: 0..BEEP_MAX_VOL. +// +void whiteNoise(word duration, word spacing, byte volume); + + +#endif /* _H_cardgame */ diff --git a/compiled-cards.c b/compiled-cards.c new file mode 100644 index 0000000..768f42c --- /dev/null +++ b/compiled-cards.c @@ -0,0 +1,471 @@ +/* compiled-cards.c - Playing card bitmaps for the Color Computer. + + By Pierre Sarrazin . + This file is in the public domain. + + Version 0.1.1 - 2016-03-12 - First release in the public domain. + Version 0.1.2 - 201?-??-?? - Adapted to compile in linker mode. +*/ + +#include "compiled-cards.h" + + +const unsigned short redCard_1[10] = { + 0x3EFF, /* # r 0011111011111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ +}; +const unsigned short redCard_2[10] = { + 0x3EFF, /* # r 0011111011111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3BFF, /* # r 0011101111111111 */ + 0x3BFF, /* # r 0011101111111111 */ + 0x3BFF, /* # r 0011101111111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ +}; +const unsigned short redCard_3[10] = { + 0x3EFF, /* # r 0011111011111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3EBF, /* # rr 0011111010111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3EFF, /* # r 0011111011111111 */ +}; +const unsigned short redCard_4[10] = { + 0x3FBF, /* # r 0011111110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ +}; +const unsigned short redCard_5[10] = { + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3BFF, /* # r 0011101111111111 */ + 0x3BFF, /* # r 0011101111111111 */ + 0x3AFF, /* # rr 0011101011111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3EFF, /* # r 0011111011111111 */ +}; +const unsigned short redCard_6[10] = { + 0x3EFF, /* # r 0011111011111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BFF, /* # r 0011101111111111 */ + 0x3AFF, /* # rr 0011101011111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3EFF, /* # r 0011111011111111 */ +}; +const unsigned short redCard_7[10] = { + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3F7F, /* # b 0011111101111111 */ + 0x3EFF, /* # r 0011111011111111 */ + 0x3EFF, /* # r 0011111011111111 */ + 0x3EFF, /* # r 0011111011111111 */ + 0x3EFF, /* # r 0011111011111111 */ +}; +const unsigned short redCard_8[10] = { + 0x3EFF, /* # r 0011111011111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3EFF, /* # r 0011111011111111 */ +}; +const unsigned short redCard_9[10] = { + 0x3EFF, /* # r 0011111011111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3EFF, /* # r 0011111011111111 */ +}; +const unsigned short redCard_10[10] = { + 0x3BAB, /* # r rrr 0011101110101011 */ + 0x3BBB, /* # r r r 0011101110111011 */ + 0x3BBB, /* # r r r 0011101110111011 */ + 0x3BBB, /* # r r r 0011101110111011 */ + 0x3BBB, /* # r r r 0011101110111011 */ + 0x3BBB, /* # r r r 0011101110111011 */ + 0x3BBB, /* # r r r 0011101110111011 */ + 0x3BBB, /* # r r r 0011101110111011 */ + 0x3BBB, /* # r r r 0011101110111011 */ + 0x3BAB, /* # r rrr 0011101110101011 */ +}; +const unsigned short redCard_11[10] = { + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3EFF, /* # r 0011111011111111 */ +}; +const unsigned short redCard_12[10] = { + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3FBF, /* # r 0011111110111111 */ +}; +const unsigned short redCard_13[10] = { + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3B7F, /* # r b 0011101101111111 */ + 0x3AFF, /* # rr 0011101011111111 */ + 0x3AFF, /* # rr 0011101011111111 */ + 0x3ABF, /* # rrr 0011101010111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ + 0x3BBF, /* # r r 0011101110111111 */ +}; +const unsigned short blackCard_1[10] = { + 0x387F, /* # r#b 0011100001111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ +}; +const unsigned short blackCard_2[10] = { + 0x387F, /* # r#b 0011100001111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x383F, /* # r## 0011100000111111 */ + 0x307F, /* # ##b 0011000001111111 */ + 0x33FF, /* # # 0011001111111111 */ + 0x33FF, /* # # 0011001111111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x303F, /* # ### 0011000000111111 */ +}; +const unsigned short blackCard_3[10] = { + 0x387F, /* # r#b 0011100001111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x387F, /* # r#b 0011100001111111 */ + 0x387F, /* # r#b 0011100001111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x387F, /* # r#b 0011100001111111 */ +}; +const unsigned short blackCard_4[10] = { + 0x3F3F, /* # # 0011111100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ +}; +const unsigned short blackCard_5[10] = { + 0x303F, /* # ### 0011000000111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x33FF, /* # # 0011001111111111 */ + 0x33FF, /* # # 0011001111111111 */ + 0x307F, /* # ##b 0011000001111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x307F, /* # ##b 0011000001111111 */ +}; +const unsigned short blackCard_6[10] = { + 0x387F, /* # r#b 0011100001111111 */ + 0x307F, /* # ##b 0011000001111111 */ + 0x33FF, /* # # 0011001111111111 */ + 0x33FF, /* # # 0011001111111111 */ + 0x307F, /* # ##b 0011000001111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x387F, /* # r#b 0011100001111111 */ +}; +const unsigned short blackCard_7[10] = { + 0x303F, /* # ### 0011000000111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3E7F, /* # rb 0011111001111111 */ + 0x3E7F, /* # rb 0011111001111111 */ + 0x3CFF, /* # # 0011110011111111 */ + 0x3CFF, /* # # 0011110011111111 */ + 0x3CFF, /* # # 0011110011111111 */ + 0x3CFF, /* # # 0011110011111111 */ +}; +const unsigned short blackCard_8[10] = { + 0x387F, /* # r#b 0011100001111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x387F, /* # r#b 0011100001111111 */ + 0x387F, /* # r#b 0011100001111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x387F, /* # r#b 0011100001111111 */ +}; +const unsigned short blackCard_9[10] = { + 0x387F, /* # r#b 0011100001111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x383F, /* # r## 0011100000111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x383F, /* # r## 0011100000111111 */ + 0x387F, /* # r#b 0011100001111111 */ +}; +const unsigned short blackCard_10[10] = { + 0x3387, /* # # r#b 0011001110000111 */ + 0x3303, /* # # ### 0011001100000011 */ + 0x3333, /* # # # # 0011001100110011 */ + 0x3333, /* # # # # 0011001100110011 */ + 0x3333, /* # # # # 0011001100110011 */ + 0x3333, /* # # # # 0011001100110011 */ + 0x3333, /* # # # # 0011001100110011 */ + 0x3333, /* # # # # 0011001100110011 */ + 0x3303, /* # # ### 0011001100000011 */ + 0x3387, /* # # r#b 0011001110000111 */ +}; +const unsigned short blackCard_11[10] = { + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x387F, /* # r#b 0011100001111111 */ +}; +const unsigned short blackCard_12[10] = { + 0x387F, /* # r#b 0011100001111111 */ + 0x303F, /* # ### 0011000000111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x323F, /* # #r# 0011001000111111 */ + 0x301F, /* # ###b 0011000000011111 */ + 0x381F, /* # r##b 0011100000011111 */ +}; +const unsigned short blackCard_13[10] = { + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x30FF, /* # ## 0011000011111111 */ + 0x30FF, /* # ## 0011000011111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ + 0x333F, /* # # # 0011001100111111 */ +}; + +const unsigned short * const redCards[13] = { +redCard_1, +redCard_2, +redCard_3, +redCard_4, +redCard_5, +redCard_6, +redCard_7, +redCard_8, +redCard_9, +redCard_10, +redCard_11, +redCard_12, +redCard_13, +}; +const unsigned short * const blackCards[13] = { +blackCard_1, +blackCard_2, +blackCard_3, +blackCard_4, +blackCard_5, +blackCard_6, +blackCard_7, +blackCard_8, +blackCard_9, +blackCard_10, +blackCard_11, +blackCard_12, +blackCard_13, +}; + +const unsigned short suit_hearts[7] = { + 0xEBAF, /* rr rr 1110101110101111 */ + 0xAAAB, /* rrrrrrr 1010101010101011 */ + 0xAAAB, /* rrrrrrr 1010101010101011 */ + 0xAAAB, /* rrrrrrr 1010101010101011 */ + 0xEAAF, /* rrrrr 1110101010101111 */ + 0xFABF, /* rrr 1111101010111111 */ + 0xFEFF, /* r 1111111011111111 */ +}; +const unsigned short suit_spades[7] = { + 0xFCFF, /* # 1111110011111111 */ + 0xF03F, /* ### 1111000000111111 */ + 0xC00F, /* ##### 1100000000001111 */ + 0x0003, /* ####### 0000000000000011 */ + 0xC00F, /* ##### 1100000000001111 */ + 0xFCFF, /* # 1111110011111111 */ + 0xFCFF, /* # 1111110011111111 */ +}; +const unsigned short suit_diamonds[7] = { + 0xFEFF, /* r 1111111011111111 */ + 0xFABF, /* rrr 1111101010111111 */ + 0xEAAF, /* rrrrr 1110101010101111 */ + 0xAAAB, /* rrrrrrr 1010101010101011 */ + 0xEAAF, /* rrrrr 1110101010101111 */ + 0xFABF, /* rrr 1111101010111111 */ + 0xFEFF, /* r 1111111011111111 */ +}; +const unsigned short suit_clubs[7] = { + 0xF03F, /* ### 1111000000111111 */ + 0xF03F, /* ### 1111000000111111 */ + 0xF03F, /* ### 1111000000111111 */ + 0x0003, /* ####### 0000000000000011 */ + 0x0003, /* ####### 0000000000000011 */ + 0x0CC3, /* ## # ## 0000110011000011 */ + 0xFCFF, /* # 1111110011111111 */ +}; + +const unsigned short * const suits[4] = { suit_hearts, suit_spades, suit_diamonds, suit_clubs }; + +const unsigned short cardTopLeft[5] = { + 0x0000, /* ######## 0000000000000000 */ + 0x07FF, /* ##b 0000011111111111 */ + 0x1FFF, /* #b 0001111111111111 */ + 0x1FFF, /* #b 0001111111111111 */ + 0x1FFF, /* #b 0001111111111111 */ +}; +const unsigned short cardBottomLeft[5] = { + 0x1FFF, /* #b 0001111111111111 */ + 0x1FFF, /* #b 0001111111111111 */ + 0x1FFF, /* #b 0001111111111111 */ + 0x07FF, /* ##b 0000011111111111 */ + 0x0000, /* ######## 0000000000000000 */ +}; +const unsigned short cardTopRight[5] = { + 0x0000, /* ######## 0000000000000000 */ + 0xFFC0, /* ### 1111111111000000 */ + 0xFFF0, /* ## 1111111111110000 */ + 0xFFF0, /* ## 1111111111110000 */ + 0xFFF0, /* ## 1111111111110000 */ +}; +const unsigned short cardBottomRight[5] = { + 0xFFF0, /* ## 1111111111110000 */ + 0xFFF0, /* ## 1111111111110000 */ + 0xFFF0, /* ## 1111111111110000 */ + 0xFFC0, /* ### 1111111111000000 */ + 0x0000, /* ######## 0000000000000000 */ +}; +const unsigned short cardLeft[1] = { + 0x3FFF, /* # 0011111111111111 */ +}; +const unsigned short cardRight[1] = { + 0xFFF8, /* r# 1111111111111000 */ +}; +const unsigned short redJokerValue[10] = { + 0x3EFF, /* # r 0011111011111111 */ + 0x3EBF, /* # rr 0011111010111111 */ + 0x3BFF, /* # r 0011101111111111 */ + 0x3BFF, /* # r 0011101111111111 */ + 0x3EFF, /* # r 0011111011111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3FBF, /* # r 0011111110111111 */ + 0x3AFF, /* # rr 0011101011111111 */ + 0x3EFF, /* # r 0011111011111111 */ +}; +const unsigned short blackJokerValue[10] = { + 0x3CFF, /* # # 0011110011111111 */ + 0x3C3F, /* # ## 0011110000111111 */ + 0x33FF, /* # # 0011001111111111 */ + 0x33FF, /* # # 0011001111111111 */ + 0x3CFF, /* # # 0011110011111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x3F3F, /* # # 0011111100111111 */ + 0x30FF, /* # ## 0011000011111111 */ + 0x3CFF, /* # # 0011110011111111 */ +}; +const unsigned short redJokerSuit[7] = { + 0xAAAB, /* rrrrrrr 1010101010101011 */ + 0xAABB, /* rrrrr r 1010101010111011 */ + 0xAABB, /* rrrrr r 1010101010111011 */ + 0xAABB, /* rrrrr r 1010101010111011 */ + 0xBABB, /* r rrr r 1011101010111011 */ + 0xAFEB, /* rr rr 1010111111101011 */ + 0xAAAB, /* rrrrrrr 1010101010101011 */ +}; +const unsigned short blackJokerSuit[7] = { + 0x0003, /* ####### 0000000000000011 */ + 0x0033, /* ##### # 0000000000110011 */ + 0x0033, /* ##### # 0000000000110011 */ + 0x0033, /* ##### # 0000000000110011 */ + 0x3033, /* # ### # 0011000000110011 */ + 0x0FC3, /* ## ## 0000111111000011 */ + 0x0003, /* ####### 0000000000000011 */ +}; diff --git a/compiled-cards.h b/compiled-cards.h new file mode 100644 index 0000000..9a1d3e2 --- /dev/null +++ b/compiled-cards.h @@ -0,0 +1,59 @@ +/* compiled-cards.h - Playing card bitmaps for the Color Computer. + + By Pierre Sarrazin . + This file is in the public domain. + + Version 0.1.1 - 2016-03-12 - First release in the public domain. + Version 0.1.2 - 201?-??-?? - Adapted to compile in linker mode. +*/ + +#ifndef _compiled_cards_h +#define _compiled_cards_h + + +extern const unsigned short redCard_1[10]; +extern const unsigned short redCard_2[10]; +extern const unsigned short redCard_3[10]; +extern const unsigned short redCard_4[10]; +extern const unsigned short redCard_5[10]; +extern const unsigned short redCard_6[10]; +extern const unsigned short redCard_7[10]; +extern const unsigned short redCard_8[10]; +extern const unsigned short redCard_9[10]; +extern const unsigned short redCard_10[10]; +extern const unsigned short redCard_11[10]; +extern const unsigned short redCard_12[10]; +extern const unsigned short redCard_13[10]; +extern const unsigned short blackCard_1[10]; +extern const unsigned short blackCard_2[10]; +extern const unsigned short blackCard_3[10]; +extern const unsigned short blackCard_4[10]; +extern const unsigned short blackCard_5[10]; +extern const unsigned short blackCard_6[10]; +extern const unsigned short blackCard_7[10]; +extern const unsigned short blackCard_8[10]; +extern const unsigned short blackCard_9[10]; +extern const unsigned short blackCard_10[10]; +extern const unsigned short blackCard_11[10]; +extern const unsigned short blackCard_12[10]; +extern const unsigned short blackCard_13[10]; +extern const unsigned short * const redCards[13]; +extern const unsigned short * const blackCards[13]; +extern const unsigned short suit_hearts[7]; +extern const unsigned short suit_spades[7]; +extern const unsigned short suit_diamonds[7]; +extern const unsigned short suit_clubs[7]; +extern const unsigned short * const suits[4]; +extern const unsigned short cardTopLeft[5]; +extern const unsigned short cardBottomLeft[5]; +extern const unsigned short cardTopRight[5]; +extern const unsigned short cardBottomRight[5]; +extern const unsigned short cardLeft[1]; +extern const unsigned short cardRight[1]; +extern const unsigned short redJokerValue[10]; +extern const unsigned short blackJokerValue[10]; +extern const unsigned short redJokerSuit[7]; +extern const unsigned short blackJokerSuit[7]; + + +#endif /* _compiled_cards_h */ diff --git a/concat.c b/concat.c new file mode 100644 index 0000000..13a06b3 --- /dev/null +++ b/concat.c @@ -0,0 +1,22 @@ +#include "cardgame.h" + + +void +concat(char *out, unsigned max, ...) +{ + va_list ap; + va_start(ap, max); + for (char *src; src = va_arg(ap, char *); ) // for each string passed as an argument + { + word len = strlen(src); + if (len > max - 1) + len = max - 1; + max -= len; + while (len--) // while that string is not finished + *out++ = *src++; + if (max <= 1) + break; + } + va_end(ap); + *out = '\0'; +} diff --git a/drawChar.c b/drawChar.c new file mode 100644 index 0000000..510afc8 --- /dev/null +++ b/drawChar.c @@ -0,0 +1,32 @@ +#include "pmode4game_private.h" + + +void +drawChar(unsigned char c) +{ + if (c == '\n') + textPosX = BYTES_PER_SCREEN_ROW - 1; // go to end of current line + else + drawCharWithoutMovingCursor(c); + + // Advance cursor. + if (textPosX == BYTES_PER_SCREEN_ROW - 1) // if column finished, go to next row + { + textPosX = 0; + if (textPosY == TEXT_ROWS_PER_SCREEN - 1) // if at last row, wrap around + { + if (textAreaScrollCallback) + { + // This may call moveCursor(), which may change textPosX and textPosY. + (*textAreaScrollCallback)(textAreaScrollCallbackUserData); + } + else + textPosY = 0; // wrap around + } + else + ++textPosY; + } + else + ++textPosX; +} + diff --git a/drawCharWithoutMovingCursor.c b/drawCharWithoutMovingCursor.c new file mode 100644 index 0000000..1ece353 --- /dev/null +++ b/drawCharWithoutMovingCursor.c @@ -0,0 +1,48 @@ +#include "cardgame.h" + +#include "pmode4game_private.h" + + +void +drawCharAtAddressWithoutMovingCursor(unsigned char c, byte *dest, BOOL drawBottomRow) +{ + if (c == ' ' && transparentSpaceChar) + return; // nothing to do + if (c < ' ' || c > '`') // mask undefined glyphs + c = '?'; + + BOOL drawRight = (colorInversionMask == 0xFF + && drawColumnAtRightOfGlyphWhenColorsInverted + && ((byte) (word) dest & 0x1F) < 0x1F); + + if (colorInversionMask == 0xFF + && drawRowOverGlyphWhenColorsInverted + && dest >= scrnBuffer + BYTES_PER_SCREEN_ROW) + { + dest[-BYTES_PER_SCREEN_ROW] = colorInversionMask; + if (drawRight) + dest[1 - BYTES_PER_SCREEN_ROW] |= 0xC0; + } + + const byte *src = eightBitWideFont[c - ' ']; + for (byte i = 0; i < PIXEL_ROWS_PER_GLYPH; ++i) + { + *dest = *src++ ^ colorInversionMask; + if (drawRight) + dest[1] |= 0xC0; + dest += BYTES_PER_SCREEN_ROW; + } + if (drawBottomRow) + { + *dest = colorInversionMask; // additional row below glyph -- total of 8 rows + if (drawRight) + dest[1] |= 0xC0; + } +} + + +void +drawCharWithoutMovingCursor(unsigned char c) +{ + drawCharAtAddressWithoutMovingCursor(c, getCurrentCharPos(), TRUE); +} diff --git a/enableInvertedColorText.c b/enableInvertedColorText.c new file mode 100644 index 0000000..a7674e4 --- /dev/null +++ b/enableInvertedColorText.c @@ -0,0 +1,9 @@ +#include "cardgame.h" + +#include "pmode4game_private.h" + + +void enableInvertedColorText(BOOL enabled) +{ + colorInversionMask = (enabled ? 0xFF : 0x00); +} diff --git a/getCurrentCharPos.c b/getCurrentCharPos.c new file mode 100644 index 0000000..c07c5fb --- /dev/null +++ b/getCurrentCharPos.c @@ -0,0 +1,8 @@ +#include "pmode4game.h" + + +byte * +getCurrentCharPos(void) +{ + return scrnBuffer + (((word) textPosY) << 8) + textPosX; +} diff --git a/getCursor.c b/getCursor.c new file mode 100644 index 0000000..6d3ac65 --- /dev/null +++ b/getCursor.c @@ -0,0 +1,9 @@ +#include "pmode4game.h" + + +void +getCursor(byte *x, byte *y) +{ + *x = textPosX; + *y = textPosY; +} diff --git a/hiResTextConsoleOutHook.c b/hiResTextConsoleOutHook.c new file mode 100644 index 0000000..4bab77b --- /dev/null +++ b/hiResTextConsoleOutHook.c @@ -0,0 +1,25 @@ +#include "pmode4game.h" + + +void +hiResTextConsoleOutHook() +{ + byte ch; + asm + { + pshs x,b // avoids crashing... + sta ch + } + + if (ch == '\r') + ch = '\n'; + else + ch = (byte) toupper(ch); + + drawChar(ch); + + asm + { + puls b,x + } +} diff --git a/initSound.c b/initSound.c new file mode 100644 index 0000000..06b1ab6 --- /dev/null +++ b/initSound.c @@ -0,0 +1,27 @@ +// By Pierre Sarrazin +// This file is in the public domain. + +#include "cardgame.h" + + +dword beep_cpuFreqDiv16; + + +void +initSound() +{ + beep_cpuFreqDiv16 = 894886UL >> 4; // re: 0.894886 MHz CPU clock + + asm + { + lda $FF01 // select sound out + anda #$F7 // reset mux bit + sta $FF01 // store + lda $FF03 // select sound out + anda #$F7 // reset mux bit + sta $FF03 // store + lda $FF23 // get PIA + ora #8 // set 6-bit sound enable + sta $FF23 // store + } +} diff --git a/invertCharAtCursor.c b/invertCharAtCursor.c new file mode 100644 index 0000000..669afac --- /dev/null +++ b/invertCharAtCursor.c @@ -0,0 +1,28 @@ +#include "cardgame.h" + + +static byte * +work(void) +{ + byte *dest = getCurrentCharPos(); + for (byte i = 0; i < PIXEL_ROWS_PER_GLYPH; ++i) + { + *dest ^= 0xFF; + dest += BYTES_PER_SCREEN_ROW; + } + return dest; +} + + +void +invertCharAtCursorExceptRowBelowGlyph(void) +{ + work(); +} + + +void +invertCharAtCursor(void) +{ + *work() ^= 0xFF; // row below glyph +} diff --git a/makeSpacesTransparent.c b/makeSpacesTransparent.c new file mode 100644 index 0000000..d03554d --- /dev/null +++ b/makeSpacesTransparent.c @@ -0,0 +1,8 @@ +#include "pmode4game_private.h" + + +void +makeSpacesTransparent(BOOL transparent) +{ + transparentSpaceChar = transparent; +} diff --git a/moveCursor.c b/moveCursor.c new file mode 100644 index 0000000..fc09377 --- /dev/null +++ b/moveCursor.c @@ -0,0 +1,14 @@ +#include "pmode4game.h" + + +void +moveCursor(byte x, byte y) +{ + if (x >= BYTES_PER_SCREEN_ROW) + return; + if (y >= TEXT_ROWS_PER_SCREEN) + return; + + textPosX = x; + textPosY = y; +} diff --git a/moveCursorLeft.c b/moveCursorLeft.c new file mode 100644 index 0000000..d62d0f2 --- /dev/null +++ b/moveCursorLeft.c @@ -0,0 +1,11 @@ +#include "cardgame.h" + + +void +moveCursorLeft(byte numColumns) +{ + if (textPosX < numColumns) + textPosX = 0; + else + textPosX -= numColumns; +} diff --git a/os9timer-demo.c b/os9timer-demo.c new file mode 100644 index 0000000..c0f0020 --- /dev/null +++ b/os9timer-demo.c @@ -0,0 +1,29 @@ +#include "cardgame.h" + + +int main() +{ + byte err = OS9Timer_init(1); // increment a counter at every 60 Hz tick + if (err != 0) + { + printf("Failed to init OS-9 timer: error #%u\n", err); + return 1; + } + + word seconds; + do + { + word t = OS9Timer_getTimer(); + seconds = t / 60; + printf("%5u ticks, %4u s\n", t, seconds); + } while (seconds < 5); + + err = OS9Timer_shutdown(); + if (err != 0) + { + printf("Failed to close OS-9 timer: error #%u\n", err); + return 1; + } + + return 0; +} diff --git a/pmode4game.c b/pmode4game.c new file mode 100644 index 0000000..4d9301a --- /dev/null +++ b/pmode4game.c @@ -0,0 +1,72 @@ +/* pmode4game.c - PMODE 4 game library for the CoCo. + Assumes Disk Basic, i.e., the PMODE 4 screen starts at $0E00. + + By Pierre Sarrazin . + This file is in the public domain. +*/ + +#include "cardgame.h" + +#include "pmode4game_private.h" + + +/////////////////////////////////////////////////////////////////////////////// + + +void +openPMode4Game(void *_scrnBuffer, byte _emulatePMode4OnCoCo3) +{ + initCoCoSupport(); + + emulatingPMode4OnCoCo3 = _emulatePMode4OnCoCo3; + +#ifdef OS9 + // Source: OS-9 Operating System User's Guide: + // For Use with OS-9 Level Oneand OS-9 Level Two + // + // The terminal from which this is run must already be in a VDG screen mode. + // + putstr("\x0F\x00\x05\x13", 4); // 256x192x2, white on black; Clear Screen + asm + { + pshs y ; protect global variable segment pointer + lda #1 + ldb #$12 ; SS.DSTAT (Get Display Status) + os9 $8D ; I$GSTT + puls y + stx :scrnBuffer + } +#else + scrnBuffer = (byte *) _scrnBuffer; + + pmode(4, scrnBuffer); + pcls(0); + if (isCoCo3 && emulatingPMode4OnCoCo3) + { + * (byte *) 0xFF90 = 0x7E; // not CoCo compatible mode + * (byte *) 0xFF98 = 0x80; // graphics mode + * (byte *) 0xFF99 = 0x09; // 192 pixel rows, 32 bytes per row, 4 pixels per byte (i.e., 128x192, 4 colors) + * (byte *) 0xFF9A = 0xFF; // white border + * (void **) 0xFF9D = 0xE000 | (scrnBuffer >> 3); // typically, $70E00 / 8. + memcpy((byte *) 0xFFB0, "\x00\x0B\x34\xFF", 4); // palette slots 0..3: black, blue, orange, white + } + else + screen(1, 1); // white/black +#endif + + // Hi-res text screen: + moveCursor(0, 0); + + // Set screen dimensions for functions in coco.h. + textScreenWidth = TEXT_COLS_PER_ROW; + textScreenHeight = TEXT_ROWS_PER_SCREEN; + + // Redirect printf(). + oldCHROUT = setConsoleOutHook(hiResTextConsoleOutHook); +} + + +void closePMode4Game(void) +{ + setConsoleOutHook(oldCHROUT); +} diff --git a/pmode4game.h b/pmode4game.h new file mode 100644 index 0000000..6ce3e76 --- /dev/null +++ b/pmode4game.h @@ -0,0 +1,295 @@ +/* pmode4game.h - PMODE 4 playing cards library for the Disk Basic. + + By Pierre Sarrazin . + This file is in the public domain. +*/ + +#ifndef _H_pmode4game +#define _H_pmode4game + +#if !defined(_COCO_BASIC_) && !defined(DRAGON) && !defined(OS9) +#error This program must be compiled for a CoCo Disk Basic or Dragon or OS-9 environment. +#endif + +#include +#include +#include "8-bit-wide-font.h" /* text font bitmaps */ + + +#ifndef NDEBUG +#define assertf(cond, ...) do { if (!(cond)) { \ + screen(0, 0); \ + printf("***ASSERT FAILED (%s): %u: %s: ", __TIME__, __LINE__, #cond); \ + printf(__VA_ARGS__); putchar('\n'); \ + for (;;); } } while (0) +#else +#define assertf(cond, ...) ((void) 0) +#endif + +#define WORDS_PER_SCREEN_ROW 16 +#define BYTES_PER_SCREEN_ROW 32 +#define TEXT_COLS_PER_ROW 32 +#define TEXT_ROWS_PER_SCREEN 24 +#define PIXEL_ROWS_PER_SCREEN 192 +#define BYTES_PER_SCREEN 0x1800 // 256 * 192 / 8 == 6144 == 6 kB +#define PIXEL_ROWS_PER_GLYPH 7 // see 8-bit-wide-font.h +#define PIXEL_ROWS_PER_TEXT_ROW 8 // PIXEL_ROWS_PER_GLYPH plus one separator row +#define BYTES_PER_TEXT_ROW 256 // 32 bytes per row of pixels, 8 rows of pixels per text row + +#ifdef OS9 +#define optDelay(ticks) (OS9Timer_delay(ticks)) /* because delay() uses F$Sleep */ +#else +#define optDelay(ticks) (delay(ticks)) +#endif + +extern byte *scrnBuffer; // PMODE 4 buffer +extern byte textPosX; // 0..BYTES_PER_SCREEN_ROW-1 +extern byte textPosY; // 0..TEXT_ROWS_PER_SCREEN-1 +extern byte emulatingPMode4OnCoCo3; +extern ConsoleOutHook oldCHROUT; + + +/////////////////////////////////////////////////////////////////////////////// + + +// Concatenates one or more strings into an output buffer. +// out: Output buffer. +// max: Maximum number of characters to write to the output buffer, +// including the terminating '\0'. +// +// CAUTION: The last argument MUST be a null pointer. +// +// If the input strings together contain too many characters, +// the concatenation stops at 'max'. +// The returned string always finishes with a terminating '\0'. +// +void concat(char *out, unsigned max, ...); + + +/////////////////////////////////////////////////////////////////////////////// + + +// Returns the screen address at which drawChar() would put the glyph. +// This address points to the top of the 8x8 pixel grid that would be +// occupied by the glyph. See PIXEL_ROWS_PER_TEXT_ROW and BYTES_PER_SCREEN_ROW. +// +byte *getCurrentCharPos(void); + + +// Used by drawChar(). +// +typedef void (*TextAreaScrollCallback)(void *userdata); + + +// Sets the callback to be invoked by drawChar() when the cursor reaches +// the bottom right of the text area. +// userdata: Passed to (*callback)() when it is invoked. +// The callback is allowed to call moveCursor(). +// +void setTextAreaScrollCallback(TextAreaScrollCallback callback, void *userdata); + + +// Displays the given character at the current cursor position and advances +// the cursor. +// Assumes that scrnBuffer points to the current screen buffer. +// When this function has just written to the last screen position, +// it invokes the callback set by setTextAreaScrollCallback() if that function +// has last been called with a non-null callback pointer, otherwise, the screen +// is not scrolled and the cursor goes home instead. +// Pass '\n' to go to the beginning of the next text row. +// No other cursor-moving control character is supported. +// +void drawChar(unsigned char c); + + +// Displays the given character at the given byte and at the 6 or 7 bytes below on the screen. +// Assumes that scrnBuffer points to the current screen buffer. +// Cursor-moving control characters are not supported. +// dest: Address of the top byte of the area to be changed. +// drawBottomRow: If TRUE, draws an 8th row below the 7 rows defined by the font. +// +void drawCharAtAddressWithoutMovingCursor(unsigned char c, byte *dest, BOOL drawBottomRow); + + +// Cursor-moving control characters are not supported. +// Assumes that scrnBuffer points to the current screen buffer. +// +void drawCharWithoutMovingCursor(unsigned char c); + + +// enabled: If TRUE, each byte from the font will be inverted before it is written to the screen. +// +void enableInvertedColorText(BOOL enabled); + + +// Sets a byte to be XORed with each byte from the font before writing the result to the screen. +// +void setColorInversionMask(byte newColorInversionMask); + + +// Determines how caracters are rendered in inverted colors mode. +// drawRowOverGlyph: When TRUE, the row of pixels above the 8x8 character bitmap will be drawn. +// drawColumnAtRightOfGlyph: When TRUE, the column of pixels above the 8x8 character bitmap +// will be drawn. +// By passing TRUE for both, each character in inverted colors will be surrounded by set pixels, +// which is likely to look better. +// +void setInvertedColorsParameters(BOOL drawRowOverGlyph, BOOL drawColumnAtRightOfGlyph); + + +// When TRUE is passed, spaces are not drawn at all, so the existing pixels +// stay unmodified. This is useful when passing TRUE to setInvertedColorsParameters() +// for its drawColumnAtRightOfGlyph parameter, to ensure a good look at the right of +// a character in inverted colors. +// +void makeSpacesTransparent(BOOL transparent); + + +// x: 0..TEXT_COLS_PER_ROW-1. +// y: 0..TEXT_ROWS_PER_SCREEN-1. +// Does nothing if either is out of range. +// +void moveCursor(byte x, byte y); + + +// Moves the cursor left by the specified number of columns, without leaving +// the current row. If numColumns exceeds the current horizontal position, +// the cursor will be left at the leftmost position of the current row. +// +void moveCursorLeft(byte numColumns); + + +// Returns the position of the cursor. See moveCursor(). +// +void getCursor(byte *x, byte *y); + + +// Reverses the colors of the pixels in the rectangle occupied by the current +// text cursor position. +// Does not advance the cursor. +// Assumes that scrnBuffer points to the current screen buffer. +// +void invertCharAtCursor(void); + + +// Same as invertCharAtCursor(), but does not invert the row below the rows +// defined by the glyph. +// Assumes that scrnBuffer points to the current screen buffer. +// +void invertCharAtCursorExceptRowBelowGlyph(void); + + +// See waitForKeyWithAnimatedCursor() and readLineFromKeyboard(). +// +typedef byte (*KeyboardPollFunction)(void *userdata); + + +// See waitForKeyWithAnimatedCursor() and readLineFromKeyboard(). +// +typedef word (*GetTimerFunction)(void *userdata); + + +// Animates a cursor at the current cursor position while calling (*poll)(userdata) +// until this call returns a non-zero value. This value is returned. +// For example, 'poll' can be a pointer to a function like the following, when using +// the BControl library: +// byte pollKeyboard(void *) { return Keyboard_poll(&keyboard); } +// Assumes that scrnBuffer points to the current screen buffer. +// ticksPerCursorPeriod: Duration of the cursor animation period, in ticks. +// Pass 0 to show no cursor at all. +// getTimerValue: Must return a value that is incremented 60 times per second. +// Receives userdata when called. +// Ignored if ticksPerCursorPeriod is 0. +// +byte waitForKeyWithAnimatedCursor(KeyboardPollFunction poll, + void *userdata, + word ticksPerCursorPeriod, + GetTimerFunction getTimerValue); + + +// Animates a cursor at the current cursor position and lets the user type a line +// ended with pressing Enter. The backspace key is supported. +// Assumes that scrnBuffer points to the current screen buffer. +// poll, userdata, ticksPerCursorPeriod, getTimerValue: See waitForKeyWithAnimatedCursor(). +// lineBuffer: Array of characters that will receive the NUL-terminated string typed by the user. +// bufferSize: Size of the lineBuffer array in bytes. Must include space a the NUL terminator. +// Returns TRUE if the user pressed Enter, or FALSE if the user pressed Break. +// If TRUE is returned, lineBuffer contains a NUL-terminated string. +// +BOOL readLineFromKeyboard(KeyboardPollFunction poll, + void *userdata, + word ticksPerCursorPeriod, + GetTimerFunction getTimerValue, + char *lineBuffer, size_t bufferSize); + + +// Called by PUTCHR, which is called by printf() et al. +// The character to print is in A. +// It is sent to drawChar() (the 32x24 screen) instead of +// the regular CoCo screen. +// +void hiResTextConsoleOutHook(); + + +// Prints a one-line string at the given text row, with leading and trailing +// spaces so that the string is centered in that row. +// row: Text line where to print (2nd argument to moveCursor()). +// str: Single line of text to print. Must not be more than 'textScreenWidth' characters. +// Returns the text column where 'str' gets printed. +// Assumes that scrnBuffer points to the current screen buffer. +// +byte printCentered(byte row, const char *str); + + +// Makes the PMODE 4 screen at the given address visible. +// If that mode is being emulated on a CoCo 3, the address +// must be an offset from physical address $70000. +// +// This function remembers the given address as the start of the screen, +// which affects other functions in this file when they determine a character's +// address in the screen buffer. +// +// Not supported under OS-9. +// +void setScreenBuffer(void *screen); + + +// Sets this library's internal graphics screen pointer to 'screen'. +// Does NOT change the graphics mode. +// Usable under OS-9. +// +void setScreenBuffer2(void *screen); + + +// Initializes CoCo support functions. +// Does the equivalent of PMODE 4:SCREEN 1,1. +// Does not assume the presence of ECB. +// +// _scrnBuffer: Address of the 6k graphics buffer. Must be divisible by 512. +// Ignored under OS-9. +// _emulatePMode4OnCoCo3: Uses a CoCo 3 graphics mode to emulate PMODE 4 +// and its artifact colors. +// +// Global variable scrnBuffer is initialized with _scrnBuffer, except under OS-9, +// where it is initialized with the screen buffer address given by the system. +// This affects other functions in this file when they determine a character's +// address in the screen buffer. +// +// Initializes the 32x24 software text screen's cursor at the home position. +// Remembers the initial text mode (32, 40, 80), on a CoCo 3. +// Initializes coco.h globals textScreenWidth and textScreenHeight. +// Redirects printf() so that it prints to the software text screen. +// +void openPMode4Game(void *_scrnBuffer, byte _emulatePMode4OnCoCo3); + + +// Releases resources allocated by openPMode4Game(). +// Does not leave graphics mode. +// Under OS-9, the program should do this to leave graphics mode: +// putstr("\x12\x0E", 2); // End Graphics, Display Alpha (text mode) +// Under the native CoCo environment, the program should call screen(0, 0). +// +void closePMode4Game(void); + + +#endif /* _H_pmode4game */ diff --git a/pmode4game_private.h b/pmode4game_private.h new file mode 100644 index 0000000..7d24364 --- /dev/null +++ b/pmode4game_private.h @@ -0,0 +1,22 @@ +/* pmode4game_private.h - PMODE 4 playing cards library for the Disk Basic. + + By Pierre Sarrazin . + This file is in the public domain. +*/ + +#ifndef _H_pmode4game_private +#define _H_pmode4game_private + + +#include "pmode4game.h" + + +extern TextAreaScrollCallback textAreaScrollCallback; +extern void *textAreaScrollCallbackUserData; +extern byte colorInversionMask; +extern BOOL drawRowOverGlyphWhenColorsInverted; +extern BOOL drawColumnAtRightOfGlyphWhenColorsInverted; +extern BOOL transparentSpaceChar; + + +#endif /* _H_pmode4game_private */ diff --git a/pmode4game_vars.c b/pmode4game_vars.c new file mode 100644 index 0000000..9090d08 --- /dev/null +++ b/pmode4game_vars.c @@ -0,0 +1,14 @@ +#include "pmode4game_private.h" + + +byte *scrnBuffer; // 1st PMODE 4 buffer +byte textPosX; // 0..BYTES_PER_SCREEN_ROW-1 +byte textPosY; // 0..TEXT_ROWS_PER_SCREEN-1 +byte emulatingPMode4OnCoCo3; +ConsoleOutHook oldCHROUT; +TextAreaScrollCallback textAreaScrollCallback; +void *textAreaScrollCallbackUserData; +byte colorInversionMask = 0x00; // 0xFF to write in black on white +BOOL drawRowOverGlyphWhenColorsInverted = FALSE; +BOOL drawColumnAtRightOfGlyphWhenColorsInverted = FALSE; +BOOL transparentSpaceChar = FALSE; diff --git a/printCentered.c b/printCentered.c new file mode 100644 index 0000000..c531ffc --- /dev/null +++ b/printCentered.c @@ -0,0 +1,18 @@ +#include "cardgame.h" + + +byte +printCentered(byte row, const char *str) +{ + word len = strlen(str); + if (len > textScreenWidth) + len = textScreenWidth; + byte col = (byte) (textScreenWidth - len) >> 1; + moveCursor(0, row); + for (byte x = 0; x < col; ++x) + putchar(' '); + putstr(str, len); + for (byte x = col; x < BYTES_PER_SCREEN_ROW; ++x) + putchar(' '); + return col; +} diff --git a/readLineFromKeyboard.c b/readLineFromKeyboard.c new file mode 100644 index 0000000..c6be191 --- /dev/null +++ b/readLineFromKeyboard.c @@ -0,0 +1,41 @@ +#include "cardgame.h" + + +BOOL +readLineFromKeyboard(KeyboardPollFunction poll, + void *userdata, + word ticksPerCursorPeriod, + GetTimerFunction getTimerValue, + char *lineBuffer, size_t bufferSize) +{ + size_t bufIndex = 0; + for (;;) + { + byte key = waitForKeyWithAnimatedCursor(poll, userdata, ticksPerCursorPeriod, getTimerValue); + switch (key) + { + case '\r': + lineBuffer[bufIndex] = '\0'; + return TRUE; + case 3: // break + return FALSE; + case '\b': // backspace + if (bufIndex > 0) + { + --bufIndex; + moveCursorLeft(1); + drawCharWithoutMovingCursor(' '); + } + break; + default: + if (key >= ' ' && key <= ']') + { + if (bufIndex < bufferSize - 1) // minus one, to leave space for final '\0' + { + lineBuffer[bufIndex++] = (char) key; + drawChar(key); + } + } + } + } +} diff --git a/setColorInversionMask.c b/setColorInversionMask.c new file mode 100644 index 0000000..e759557 --- /dev/null +++ b/setColorInversionMask.c @@ -0,0 +1,9 @@ +#include "cardgame.h" + +#include "pmode4game_private.h" + + +void setColorInversionMask(byte newColorInversionMask) +{ + colorInversionMask = newColorInversionMask; +} diff --git a/setInvertedColorsParameters.c b/setInvertedColorsParameters.c new file mode 100644 index 0000000..943d846 --- /dev/null +++ b/setInvertedColorsParameters.c @@ -0,0 +1,9 @@ +#include "pmode4game_private.h" + + +void +setInvertedColorsParameters(BOOL drawRowOverGlyph, BOOL drawColumnAtRightOfGlyph) +{ + drawRowOverGlyphWhenColorsInverted = drawRowOverGlyph; + drawColumnAtRightOfGlyphWhenColorsInverted = drawColumnAtRightOfGlyph; +} diff --git a/setScreenBuffer.c b/setScreenBuffer.c new file mode 100644 index 0000000..7fd6e9f --- /dev/null +++ b/setScreenBuffer.c @@ -0,0 +1,20 @@ +/* setScreenBuffer.c + + By Pierre Sarrazin . + This file is in the public domain. +*/ + +#include "pmode4game.h" + + +void +setScreenBuffer(void *screen) +{ + scrnBuffer = (byte *) screen; +#ifndef OS9 + if (isCoCo3 && emulatingPMode4OnCoCo3) + * (void **) 0xFF9D = 0xE000 | (screen >> 3); + else + showGraphicsAddress(6, (byte) (screen >> 9)); +#endif +} diff --git a/setScreenBuffer2.c b/setScreenBuffer2.c new file mode 100644 index 0000000..68c9964 --- /dev/null +++ b/setScreenBuffer2.c @@ -0,0 +1,14 @@ +/* setScreenBuffer2.c + + By Pierre Sarrazin . + This file is in the public domain. +*/ + +#include "pmode4game.h" + + +void +setScreenBuffer2(void *screen) +{ + scrnBuffer = (byte *) screen; +} diff --git a/setTextAreaScrollCallback.c b/setTextAreaScrollCallback.c new file mode 100644 index 0000000..ed04184 --- /dev/null +++ b/setTextAreaScrollCallback.c @@ -0,0 +1,9 @@ +#include "pmode4game_private.h" + + +void +setTextAreaScrollCallback(TextAreaScrollCallback callback, void *userdata) +{ + textAreaScrollCallback = callback; + textAreaScrollCallbackUserData = userdata; +} diff --git a/waitForKeyWithAnimatedCursor.c b/waitForKeyWithAnimatedCursor.c new file mode 100644 index 0000000..e80d113 --- /dev/null +++ b/waitForKeyWithAnimatedCursor.c @@ -0,0 +1,42 @@ +#include "cardgame.h" + +#ifdef OS9 +#define getTimer() (OS9Timer_getTimer()) +#endif + + +byte +waitForKeyWithAnimatedCursor(KeyboardPollFunction poll, + void *userdata, + word ticksPerCursorPeriod, + GetTimerFunction getTimerValue) +{ + byte prevCursorState; + word nearEndOfPeriod; + if (ticksPerCursorPeriod > 0) // if cursor wanted + { + invertCharAtCursor(); + prevCursorState = 1; + nearEndOfPeriod = ticksPerCursorPeriod * 3 / 4; + } + else + prevCursorState = 0; + + byte key; + while ((key = (*poll)(userdata)) == 0) + { + if (ticksPerCursorPeriod > 0) + { + word now = (*getTimerValue)(userdata); + byte currentCursorState = (now % ticksPerCursorPeriod < nearEndOfPeriod); + if (currentCursorState != prevCursorState) + { + invertCharAtCursor(); + prevCursorState = currentCursorState; + } + } + } + if (prevCursorState) + invertCharAtCursor(); + return key; +} diff --git a/whiteNoise.c b/whiteNoise.c new file mode 100644 index 0000000..87760a5 --- /dev/null +++ b/whiteNoise.c @@ -0,0 +1,50 @@ +// By Pierre Sarrazin +// This file is in the public domain. + +#include "cardgame.h" + + +#define NUM_BYTES 32 + +static const byte uniformlyRandomBytes[NUM_BYTES] = +{ + 0x08, 0xf0, 0xfc, 0x9c, 0x94, 0xc8, 0xd4, 0x74, 0xd4, 0x20, 0x04, 0xac, 0xb4, 0x68, 0xe0, 0x08, + 0x74, 0x20, 0x28, 0x64, 0x24, 0xa4, 0xcc, 0xb8, 0x58, 0xa0, 0x54, 0x7c, 0x04, 0x44, 0x84, 0xb0, +}; + + +void +whiteNoise(word duration, word spacing, byte volume) +{ + asm + { + leax :uniformlyRandomBytes + pshs y + ldy :duration +; Cannot refer to globals anymore under OS-9, as per CMOC register convention. +@durationLoop + ldb #NUM_BYTES ; size of uniformlyRandomBytes[] +@writeLoop + lda ,x+ + sta $FF20 + bsr @sleep + decb + bne @writeLoop + leax -NUM_BYTES,x + leay -1,y ; decrement duration + bne @durationLoop +; + puls y + bra @done +@sleep + pshs x + ldx :spacing + beq @sleepDone +@sleepLoop + leax -1,x + bne @sleepLoop +@sleepDone + puls x,pc +@done + } +}