Skip to content

Commit

Permalink
screen now 2048x600, blit checks for alpha, thanks douglas!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhitman committed May 5, 2023
1 parent b938669 commit 8252daa
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Tulip CC rev 4 supports:
- An [AMY](https://github.com/bwhitman/amy) stereo 64-voice synthesizer engine running locally or as a wireless controller for an [Alles](https://github.com/bwhitman/alles) mesh. Tulip's synth supports additive oscillators, an excellent FM synthesis engine, samplers, karplus-strong, filters, and much more.
- Text frame buffer layer, 128 x 50, with ANSI support for 256 colors, inverse, bold, underline, background color
- Up to 32 sprites on screen, drawn per scanline, from a total of 32KB of bitmap memory (1 byte per pixel)
- A 1280x750 background frame buffer to draw arbitrary bitmaps to, or use as RAM, and which can scroll horizontally / vertically
- A 2048x600 background frame buffer to draw arbitrary bitmaps to, or use as RAM, and which can scroll horizontally / vertically
- WiFi, access http via Python requests or TCP / UDP sockets
- Adjustable display clock and resolution, defaults to 30 FPS at 1024x600.
- 256 colors
Expand Down
7 changes: 5 additions & 2 deletions docs/tulip_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ tulip.midi_out(bytes) # Can send bytes or list
## Graphics system

The Tulip GPU consists of 3 subsystems, in drawing order:
* A bitmap graphics plane (BG) (default size: 1280x750), with scrolling x- and y- speed registers. Drawing shape primitives draw to the BG.
* A bitmap graphics plane (BG) (default size: 2048x600), with scrolling x- and y- speed registers. Drawing shape primitives draw to the BG.
* A text frame buffer (TFB) that draws 8x12 fixed width text on top of the BG, with 256 colors
* A sprite layer on top of the TFB (which is on top of the BG)

Expand Down Expand Up @@ -307,7 +307,7 @@ tulip.brightness(5)

## Graphics background plane

The default background plane (BG) is 1280 x 750, with the visible portion 1024x600. (You can change this with `tulip.timing()`.) Use the extra for hardware scrolling or for storing bitmap data "offscreen" for later blitting (you can treat it as fixed bitmap RAM.) The BG is drawn first, with the TFB and sprite layers drawn on top.
The default background plane (BG) is 2048 x 600, with the visible portion 1024x600. (You can change this with `tulip.timing()`.) Use the extra for double buffering, hardware scrolling or for storing bitmap data "offscreen" for later blitting (you can treat it as fixed bitmap RAM.) The BG is drawn first, with the TFB and sprite layers drawn on top.

Tulip uses RGB332, with 256 colors. Here's the palette:

Expand Down Expand Up @@ -336,6 +336,9 @@ tulip.bg_png(png_filename, x, y)
# Copy bitmap area from x,y of width,height to x1, y1
tulip.blit(x,y,w,h,x1, y1)

# If you give blit an extra parameter it will not copy over alpha color (0x55), good for blending BG images
tulip.blit(x,y,w,h,x1, y1, 1)

# Sets or gets a rect of the BG with bitmap data (RGB332 pal_idxes)
tulip.bg_bitmap(x, y, w, h, bitmap)
bitmap = tulip.bg_bitmap(x, y, w, h)
Expand Down
15 changes: 15 additions & 0 deletions extmod/tulip/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,21 @@ void display_bg_bitmap_blit(uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint16_t
}
}

void display_bg_bitmap_blit_alpha(uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint16_t x1,uint16_t y1) {
for (uint16_t j = y1; j < y1+h; j++) {
for (uint16_t i = x1; i < x1+w; i++) {
uint16_t src_y = y+(j-y1);
uint16_t src_x = x+(i-x1);
if(j<V_RES+OFFSCREEN_Y_PX && i < H_RES+OFFSCREEN_X_PX) {
uint8_t c = (bg)[(((src_y*(H_RES+OFFSCREEN_X_PX) + src_x)*BYTES_PER_PIXEL) + 0)];
if(c != ALPHA) {
(bg)[(((j*(H_RES+OFFSCREEN_X_PX) + i)*BYTES_PER_PIXEL) + 0)] = (bg)[(((src_y*(H_RES+OFFSCREEN_X_PX) + src_x)*BYTES_PER_PIXEL) + 0)];
}
}
}
}
}



//mem_len = sprite_load(bitmap, mem_pos, [x,y,w,h]) # returns mem_len (w*h*2)
Expand Down
5 changes: 3 additions & 2 deletions extmod/tulip/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void display_get_bg_bitmap_raw(uint16_t x, uint16_t y, uint16_t w, uint16_t h, u
void display_set_bg_bitmap_rgba(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t* data);
void display_set_bg_bitmap_raw(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t* data);
void display_bg_bitmap_blit(uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint16_t x1,uint16_t y1);
void display_bg_bitmap_blit_alpha(uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint16_t x1,uint16_t y1);

void display_load_sprite_rgba(uint32_t mem_pos, uint32_t len, uint8_t* data);
void display_load_sprite_raw(uint32_t mem_pos, uint32_t len, uint8_t* data);
Expand Down Expand Up @@ -89,8 +90,8 @@ extern const unsigned char font_8x12_r[256][12];

#define DEFAULT_H_RES 1024
#define DEFAULT_V_RES 600
#define DEFAULT_OFFSCREEN_X_PX 256
#define DEFAULT_OFFSCREEN_Y_PX 150
#define DEFAULT_OFFSCREEN_X_PX 1024
#define DEFAULT_OFFSCREEN_Y_PX 0
#define DEFAULT_PIXEL_CLOCK_MHZ 22


Expand Down
9 changes: 7 additions & 2 deletions extmod/tulip/modtulip.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ STATIC mp_obj_t tulip_bg_bitmap(size_t n_args, const mp_obj_t *args) {

STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tulip_bg_bitmap_obj, 4, 5, tulip_bg_bitmap);


// tulip.bg_blit(x, y, w, h, x1, y1) --> copies bitmap ram
STATIC mp_obj_t tulip_bg_blit(size_t n_args, const mp_obj_t *args) {
uint16_t x = mp_obj_get_int(args[0]);
Expand All @@ -143,11 +144,15 @@ STATIC mp_obj_t tulip_bg_blit(size_t n_args, const mp_obj_t *args) {
uint16_t h = mp_obj_get_int(args[3]);
uint16_t x1 = mp_obj_get_int(args[4]);
uint16_t y1 = mp_obj_get_int(args[5]);
display_bg_bitmap_blit(x,y,w,h,x1,y1);
if(n_args > 6) {
display_bg_bitmap_blit_alpha(x,y,w,h,x1,y1);
} else {
display_bg_bitmap_blit(x,y,w,h,x1,y1);
}
return mp_const_none;
}

STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tulip_bg_blit_obj, 6, 6, tulip_bg_blit);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tulip_bg_blit_obj, 6, 7, tulip_bg_blit);



Expand Down

0 comments on commit 8252daa

Please sign in to comment.