Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read colours #154

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions video/agon.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#define VDP_RTC 0x87 // RTC
#define VDP_KEYSTATE 0x88 // Keyboard repeat rate and LED status
#define VDP_MOUSE 0x89 // Mouse data
#define VDP_READ_COLOUR 0x94 // Read colour
#define VDP_BUFFERED 0xA0 // Buffered commands
#define VDP_UPDATER 0xA1 // Update VDP
#define VDP_LOGICALCOORDS 0xC0 // Switch BBC Micro style logical coords on and off
Expand Down
1 change: 1 addition & 0 deletions video/vdu_stream_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class VDUStreamProcessor {
void sendCursorPosition();
void sendScreenChar(uint16_t x, uint16_t y);
void sendScreenPixel(uint16_t x, uint16_t y);
void sendColour(uint8_t colour);
void sendTime();
void vdu_sys_video_time();
void sendKeyboardState();
Expand Down
44 changes: 44 additions & 0 deletions video/vdu_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ void VDUStreamProcessor::vdu_sys_video() {
case VDP_MOUSE: { // VDU 23, 0, &89, command, <args>
vdu_sys_mouse();
} break;
case VDP_READ_COLOUR: { // VDU 23, 0, &94, index
auto index = readByte_t(); // Read colour from palette
if (index >= 0) {
sendColour(index);
}
} break;
case VDP_BUFFERED: { // VDU 23, 0, &A0, bufferId; command, <args>
vdu_sys_buffered();
} break;
Expand Down Expand Up @@ -238,6 +244,44 @@ void VDUStreamProcessor::sendScreenPixel(uint16_t x, uint16_t y) {
send_packet(PACKET_SCRPIXEL, sizeof packet, packet);
}

// VDU 23, 0, &94, index: Send a colour back to MOS
//
void VDUStreamProcessor::sendColour(uint8_t colour) {
RGB888 pixel;
if (colour < 64) {
// Colour is a palette lookup
uint8_t c = palette[colour % getVGAColourDepth()];
pixel = colourLookup[c];
} else {
// Colour may be an active colour lookup
switch (colour) {
case 128: // text foreground
pixel = tfg;
break;
case 129: // text background
pixel = tbg;
break;
case 130: // graphics foreground
pixel = gfg;
break;
case 131: // graphics background
pixel = gbg;
break;
default:
// Unrecognised colour - no response
return;
}
}

uint8_t packet[] = {
pixel.R, // Send the colour components
pixel.G,
pixel.B,
colour,
};
send_packet(PACKET_SCRPIXEL, sizeof packet, packet);
}

// VDU 23, 0, &87, 0: Send TIME information (from ESP32 RTC)
//
void VDUStreamProcessor::sendTime() {
Expand Down