Skip to content

Commit

Permalink
Frame Buffer: overide OS_ReadPoint when framebuffer active
Browse files Browse the repository at this point in the history
Change-Id: I7152005ecba1e751bcf97438ac3e93e0ee22dd8d
  • Loading branch information
hoglet67 committed Sep 2, 2021
1 parent 9d8f1e4 commit d623e6a
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 26 deletions.
8 changes: 8 additions & 0 deletions src/framebuffer/primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,14 @@ void prim_set_pixel(screen_mode_t *screen, int x, int y, pixel_t colour) {
set_pixel(screen, x, y, colour);
}

pixel_t prim_get_pixel(screen_mode_t *screen, int x, int y) {
return get_pixel(screen, x, y);
}

int prim_on_screen(screen_mode_t *screen, int x, int y) {
return x >= g_x_min && x <= g_x_max && y >= g_y_min && y <= g_y_max;
}

// Rodders: Line mode support
// Implementation of Bresenham's line drawing algorithm from here:
// http://tech-algorithm.com/articles/drawing-line-using-bresenham-algorithm/
Expand Down
53 changes: 27 additions & 26 deletions src/framebuffer/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,32 @@ typedef enum {
PM_INVERT = 4
} plotmode_t;

void prim_set_fg_plotmode (plotmode_t plotmode);
plotmode_t prim_get_fg_plotmode();
void prim_set_bg_plotmode (plotmode_t plotmode);
plotmode_t prim_get_bg_plotmode();
void prim_set_graphics_area (screen_mode_t *screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
void prim_clear_graphics_area (screen_mode_t *screen, pixel_t colour);
void prim_set_pixel (screen_mode_t *screen, int x, int y, pixel_t colour);
void prim_draw_line (screen_mode_t *screen, int x1, int y1, int x2, int y2, pixel_t colour, uint8_t linemode);
void prim_flood_fill (screen_mode_t *screen, int x, int y, pixel_t fill_col, pixel_t ref_col, int c);
void prim_fill_area (screen_mode_t *screen, int x, int y, pixel_t colour, fill_t mode);
void prim_draw_circle (screen_mode_t *screen, int xc, int yc, int xr, int yr, pixel_t colour);
void prim_fill_circle (screen_mode_t *screen, int xc, int yc, int xr, int yr, pixel_t colour);
void prim_draw_ellipse (screen_mode_t *screen, int xc, int yc, int width, int height, int shear, pixel_t colour);
void prim_fill_ellipse (screen_mode_t *screen, int xc, int yc, int width, int height, int shear, pixel_t colour);
void prim_fill_triangle (screen_mode_t *screen, int x1, int y1, int x2, int y2, int x3, int y3, pixel_t colour);
void prim_draw_arc (screen_mode_t *screen, int xc, int yc, int x1, int y1, int x2, int y2, pixel_t colour);
void prim_fill_chord (screen_mode_t *screen, int xc, int yc, int x1, int y1, int x2, int y2, pixel_t colour);
void prim_fill_sector (screen_mode_t *screen, int xc, int yc, int x1, int y1, int x2, int y2, pixel_t colour);
void prim_move_copy_rectangle (screen_mode_t *screen, int x1, int y1, int x2, int y2, int x3, int y3, int move);
void prim_fill_rectangle (screen_mode_t *screen, int x1, int y1, int x2, int y2, pixel_t colour);
void prim_fill_parallelogram (screen_mode_t *screen, int x1, int y1, int x2, int y2, int x3, int y3, pixel_t colour);
void prim_draw_character (screen_mode_t *screen, int c, int x_pos, int y_pos, pixel_t colour);

void prim_reset_sprites (screen_mode_t *screen);
void prim_define_sprite (screen_mode_t *screen, int n, int x1, int y1, int x2, int y2);
void prim_draw_sprite (screen_mode_t *screen, int n, int x, int y);
void prim_set_fg_plotmode (plotmode_t plotmode);
plotmode_t prim_get_fg_plotmode ();
void prim_set_bg_plotmode (plotmode_t plotmode);
plotmode_t prim_get_bg_plotmode ();
void prim_set_graphics_area (screen_mode_t *screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
void prim_clear_graphics_area (screen_mode_t *screen, pixel_t colour);
void prim_set_pixel (screen_mode_t *screen, int x, int y, pixel_t colour);
pixel_t prim_get_pixel (screen_mode_t *screen, int x, int y);
int prim_on_screen (screen_mode_t *screen, int x, int y);
void prim_draw_line (screen_mode_t *screen, int x1, int y1, int x2, int y2, pixel_t colour, uint8_t linemode);
void prim_flood_fill (screen_mode_t *screen, int x, int y, pixel_t fill_col, pixel_t ref_col, int c);
void prim_fill_area (screen_mode_t *screen, int x, int y, pixel_t colour, fill_t mode);
void prim_draw_circle (screen_mode_t *screen, int xc, int yc, int xr, int yr, pixel_t colour);
void prim_fill_circle (screen_mode_t *screen, int xc, int yc, int xr, int yr, pixel_t colour);
void prim_draw_ellipse (screen_mode_t *screen, int xc, int yc, int width, int height, int shear, pixel_t colour);
void prim_fill_ellipse (screen_mode_t *screen, int xc, int yc, int width, int height, int shear, pixel_t colour);
void prim_fill_triangle (screen_mode_t *screen, int x1, int y1, int x2, int y2, int x3, int y3, pixel_t colour);
void prim_draw_arc (screen_mode_t *screen, int xc, int yc, int x1, int y1, int x2, int y2, pixel_t colour);
void prim_fill_chord (screen_mode_t *screen, int xc, int yc, int x1, int y1, int x2, int y2, pixel_t colour);
void prim_fill_sector (screen_mode_t *screen, int xc, int yc, int x1, int y1, int x2, int y2, pixel_t colour);
void prim_move_copy_rectangle (screen_mode_t *screen, int x1, int y1, int x2, int y2, int x3, int y3, int move);
void prim_fill_rectangle (screen_mode_t *screen, int x1, int y1, int x2, int y2, pixel_t colour);
void prim_fill_parallelogram (screen_mode_t *screen, int x1, int y1, int x2, int y2, int x3, int y3, pixel_t colour);
void prim_draw_character (screen_mode_t *screen, int c, int x_pos, int y_pos, pixel_t colour);
void prim_reset_sprites (screen_mode_t *screen);
void prim_define_sprite (screen_mode_t *screen, int n, int x1, int y1, int x2, int y2);
void prim_draw_sprite (screen_mode_t *screen, int n, int x, int y);

#endif
43 changes: 43 additions & 0 deletions src/framebuffer/swi_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../tube-lib.h"
#include "../tube-swi.h"

#include "primitives.h"
#include "framebuffer.h"
#include "screen_modes.h"

Expand Down Expand Up @@ -354,6 +355,47 @@ static void OS_ReadVduVariables_impl(unsigned int *reg) {
}
}

// ==========================================================================
// Implementation of OS_ReadPoint SWI
// ==========================================================================

// Entry
// R0 X co-ordinate
// R1 Y co-ordinate
// Exit
// R0 Preserved
// R1 Preserved
// R2 Colour
// R3 Tint
// R4 -1 if point was off screen, else 0
// Notes
// If in a 16 or 32 bpp mode, this will return the 15 or 24 bit
// colour number in R2 and tint will be 0.

static void OS_ReadPoint_impl(unsigned int *reg) {
int32_t x = (int32_t)reg[0];
int32_t y = (int32_t)reg[1];

screen_mode_t *screen = get_screen_mode(fb_get_current_screen_mode());

pixel_t colour = prim_get_pixel(screen, x, y);

if (prim_on_screen(screen, x, y)) {
if (screen->log2bpp == 3) {
reg[2] = colour & 0x3F;
reg[3] = colour & 0xC0;
} else {
reg[2] = colour;
reg[3] = 0;
}
reg[4] = 0;
} else {
reg[2] = -1;
reg[3] = 0;
reg[4] = -1;
}
}

// ==========================================================================
// Public methods
// ==========================================================================
Expand Down Expand Up @@ -384,6 +426,7 @@ void fb_add_swi_handlers() {
SWI_Table[SWI_OS_Byte].handler = OS_Byte_impl;
SWI_Table[SWI_OS_ReadLine].handler = OS_ReadLine_impl;
SWI_Table[SWI_OS_ScreenMode].handler = OS_ScreenMode_impl;
SWI_Table[SWI_OS_ReadPoint].handler = OS_ReadPoint_impl;
SWI_Table[SWI_OS_ReadModeVariable].handler = OS_ReadModeVariable_impl;
SWI_Table[SWI_OS_ReadVduVariables].handler = OS_ReadVduVariables_impl;

Expand Down

0 comments on commit d623e6a

Please sign in to comment.