Original author: Pierre Sarrazin. Preserve upstream GPLv3-or-later and file-specific notices. Source: http://sarrazip.com/dev/coco-letters-0.1.0.tar.gz Archive SHA-256: ad7c7771845e1a35014644fb562634a558abee632e1d7738683db6e9e9e46b94
155 lines
4.0 KiB
C
155 lines
4.0 KiB
C
/* graphics.h
|
|
Copyright (C) 2026 Pierre Sarrazin <http://sarrazip.com/>
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef _H_graphics
|
|
#define _H_graphics
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
// Define names for the palette slots, e.g., PAL_SCREEN_BG for
|
|
// the screen background color.
|
|
//
|
|
enum
|
|
{
|
|
#define PALETTE_ELEMENT(name, rgbCode, cmpCode) CONCAT(PAL_, name),
|
|
#include "palette.h"
|
|
#undef PALETTE_ELEMENT
|
|
};
|
|
|
|
|
|
// Displays the 40x24 no-color text screen.
|
|
// Redirects printf() et al. to it.
|
|
// Scrolling is not supported. The cursor must not go beyond the last row.
|
|
// Call showGraphicsMode() to go to the graphics screen.
|
|
//
|
|
void showHardwareTextScreen(void);
|
|
|
|
|
|
// Also homes the cursor.
|
|
//
|
|
void clearHardwareTextScreen(void);
|
|
|
|
|
|
void hcls(byte color);
|
|
|
|
|
|
// Sets MMU pages to point to the graphics blocks.
|
|
// Clears the graphics screen.
|
|
// Homes the cursor used by printf() et al., which get redirected
|
|
// to a part of the graphics screen.
|
|
//
|
|
void setupGraphicsMode();
|
|
|
|
|
|
// Initializes the 16 palette slots according to monitorIsRGB.
|
|
// If it is false, a composite monitor is assumed.
|
|
// If this function is never called, the default palette is RGB.
|
|
//
|
|
void setPalette(BOOL monitorIsRGB);
|
|
|
|
|
|
// Switches between the RGB and CMP palettes.
|
|
//
|
|
void alternatePalettes(void);
|
|
|
|
|
|
// Shows the graphics mode that was set up by setupGraphicsMode(),
|
|
// which must have been called before this function can be called.
|
|
// Redirects printf() et al. to a part of the graphics screen.
|
|
// Does not move the cursor.
|
|
//
|
|
void showGraphicsMode(void);
|
|
|
|
|
|
// Returns the address of the byte that contains the pixel at (x, y).
|
|
// x, y: Positions in pixels.
|
|
//
|
|
__gcccall byte *getPixelAddr(byte x, byte y);
|
|
|
|
|
|
void setPixel(byte x, byte y, byte color);
|
|
|
|
|
|
byte getPixel(byte x, byte y);
|
|
|
|
|
|
void hline(byte left, byte right, byte row, byte colorIndex);
|
|
|
|
|
|
void vline(byte top, byte bottom, byte column, byte colorIndex);
|
|
|
|
|
|
void draw6ByteWideRectangle(byte leftPosInBytes,
|
|
byte upperRowInPixels,
|
|
byte heightInPixels,
|
|
byte colorIndex);
|
|
|
|
// Draws a full rectangle.
|
|
//
|
|
void drawRect(byte leftPosInPixels,
|
|
byte upperRowInPixels,
|
|
byte widthInPixels,
|
|
byte heightInPixels,
|
|
byte colorIndex);
|
|
|
|
|
|
// Draws an empty box.
|
|
// N.B.: rightX and bottomY are positions, not dimensions.
|
|
//
|
|
void drawBox(byte leftX, byte topY, byte rightX, byte bottomY, byte colorIndex);
|
|
|
|
|
|
// Writes a character in a 4x8 font at a pixel-precise position.
|
|
// x: 0..251.
|
|
// y: 0..184.
|
|
// asciiCode: 0..127.
|
|
//
|
|
void writeCharAtPixelPos(byte x, byte y, char asciiCode);
|
|
|
|
|
|
// Writes a character in a 4x8 font at a text grid position.
|
|
// textCol: 0..50.
|
|
// textRow: 0..23.
|
|
// asciiCode: 0..127.
|
|
//
|
|
#define writeCharAt(textCol, textRow, asciiCode) (writeCharAtPixelPos((textCol) * CHAR_WIDTH, (textRow) * CHAR_HEIGHT, (asciiCode)))
|
|
|
|
|
|
// The text must not go beyond the row it starts on.
|
|
// '\n' goes to the next line. The text must not go below
|
|
// the bottom of the text window.
|
|
//
|
|
void writeStringAt(byte textCol, byte textRow, const char *str);
|
|
|
|
|
|
void writeDecimalAt(byte textCol, byte textRow, unsigned value);
|
|
|
|
|
|
// Returns a position in a 51x24 grid.
|
|
//
|
|
void getCurrentTextWindowPos(byte *textCol, byte *textRow);
|
|
|
|
|
|
// Writes a capital letter in a tile-specific font.
|
|
// tileType: 1..26.
|
|
//
|
|
void writeTileCharAtPixelPosWithColors(byte x, byte y, byte tileType, byte foreColorIndex, byte backColorIndex);
|
|
|
|
|
|
#endif /* _H_graphics */
|