Skip to content

Commit

Permalink
[Decompilation] [th01] Ellipse arc blitting
Browse files Browse the repository at this point in the history
Most frequently used for complete circles, though… but who cares, as
of this commit, ReC98, as a whole, is ⅓ done!

Part of P0120, funded by Yanga.
  • Loading branch information
nmlgc committed Sep 28, 2020
1 parent a80343a commit 23f5645
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 502 deletions.
69 changes: 69 additions & 0 deletions th01/main/shape.cpp
@@ -0,0 +1,69 @@
#include "th01/sprites/shape8x8.h"
#include "th01/main/shape.hpp"

#define shape8x8_put(shape, left, top, col) \
dots8x8_t sprite = sSHAPE8X8[shape]; \
vram_offset_t vram_offset_topleft = vram_offset_divmul(left, top); \
int first_bit = (left % BYTE_DOTS); \
if((left < 0) || (left >= RES_X) || (top < 0) || (top >= RES_Y)) { \
return; \
} \
grcg_put_8x8_mono(vram_offset_topleft, first_bit, sprite.rows, col);

void shape8x8_diamond_put(screen_x_t left, vram_y_t top, int col)
{
shape8x8_put(SHAPE8X8_DIAMOND, left, top, col);
}

void shape8x8_star_put(screen_x_t left, vram_y_t top, int col)
{
shape8x8_put(SHAPE8X8_STAR, left, top, col);
}

void shape8x8_flake_put(screen_x_t left, vram_y_t top, int col)
{
shape8x8_put(SHAPE8X8_FLAKE, left, top, col);
}

void shape_ellipse_arc_put(
screen_x_t center_x,
vram_y_t center_y,
pixel_t radius_x,
pixel_t radius_y,
int col,
unsigned char angle_step,
unsigned char angle_start,
unsigned char angle_end
)
{
int angle; // 16 bits to correctly work for an [angle_end] of 0xFF
dots8_t cache_dots = 0;
vram_offset_t cache_vram_offset = -1;

grcg_setcolor_rmw(col);

if(angle_start > angle_end) {
return;
}

for(angle = angle_start; angle <= angle_end; angle += angle_step) {
vram_offset_t vram_offset;
screen_x_t cur_x = polar_x(center_x, radius_x, angle);
vram_y_t cur_y = polar_y(center_y, radius_y, angle);

vram_offset = vram_offset_shift(cur_x, cur_y);
if(cache_vram_offset != vram_offset) {
if(
(cur_x >= 0) && (cur_x < RES_X) &&
(cache_vram_offset >= 0) && (cache_vram_offset < PLANE_SIZE)
) {
VRAM_PUT(B, cache_vram_offset, cache_dots, 8);
}
cache_dots = ((0x80) >> (cur_x & (BYTE_DOTS - 1)));
cache_vram_offset = vram_offset;
} else {
cache_dots |= ((0x80) >> (cur_x & (BYTE_DOTS - 1)));
}
}
grcg_off();
}
11 changes: 11 additions & 0 deletions th01/main/shape8x8.hpp → th01/main/shape.hpp
Expand Up @@ -3,3 +3,14 @@
void shape8x8_diamond_put(screen_x_t left, vram_y_t top, int col);
void shape8x8_star_put(screen_x_t left, vram_y_t top, int col);
void shape8x8_flake_put(screen_x_t left, vram_y_t top, int col);

void shape_ellipse_arc_put(
screen_x_t center_x,
vram_y_t center_y,
pixel_t radius_x,
pixel_t radius_y,
int col,
unsigned char angle_step,
unsigned char angle_start,
unsigned char angle_end
);
26 changes: 0 additions & 26 deletions th01/main/shape8x8.cpp

This file was deleted.

4 changes: 3 additions & 1 deletion th01/main_23.cpp
Expand Up @@ -6,8 +6,10 @@
#pragma option -3 -Z

extern "C" {
#include "libs/master.lib/master.h"
#include "th01/formats/grc.cpp"
#include "th01/hardware/grcg8x8m.cpp"
#include "th01/math/vector.hpp"
}

#include "th01/main/shape8x8.cpp"
#include "th01/main/shape.cpp"

0 comments on commit 23f5645

Please sign in to comment.