Skip to content
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
16 changes: 8 additions & 8 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@

uint16_t rscreenWidth, rscreenHeight; // Real screen size
uint16_t displayXOffset; // Margin of the display area
uint32_t pix_buffer[SCREEN_REAL_WIDTH];
uint32_t pix_buffer[GE0_SCREEN_WIDTH];

void setScreenResolution(uint16_t nw, uint16_t nh) {
if (nw < SCREEN_REAL_WIDTH)
if (nw < GE0_SCREEN_WIDTH)
rscreenWidth = nw;
else
rscreenWidth = SCREEN_REAL_WIDTH - 1;
rscreenWidth = GE0_SCREEN_WIDTH - 1;

if (nh < SCREEN_REAL_HEIGHT)
if (nh < GE0_SCREEN_HEIGHT)
rscreenHeight = nh;
else
rscreenHeight = SCREEN_REAL_HEIGHT - 1;
rscreenHeight = GE0_SCREEN_HEIGHT - 1;

if (rscreenWidth < 95)
rscreenWidth = 95;
if (rscreenHeight < 95)
rscreenHeight = 95;

displayXOffset = (SCREEN_REAL_WIDTH - rscreenWidth) / 2;
displayXOffset = (GE0_SCREEN_WIDTH - rscreenWidth) / 2;
for (int i = 0; i < 4; i++)
line_is_draw[i] = 0xffffffff;
ge0_port_display_fillScreen(0x0000);
Expand All @@ -35,8 +35,8 @@ void redrawScreen() { // todo: change the name to display. "screen" is for
// canvas only
// left shift so we can use fix-point number
// use (_ * _ratio) >> 16 for mapping
int x_ratio = (int)((SCREEN_WIDTH << 16) / rscreenWidth);
int y_ratio = (int)((SCREEN_HEIGHT << 16) / rscreenHeight);
int x_ratio = (int)((GE0_SCREEN_HEIGHT << 16) / rscreenWidth);
int y_ratio = (int)((GE0_SCREEN_HEIGHT << 16) / rscreenHeight);
int x_canvas, hx2, y_canvas, startx;
// Since each line in canvas might be mapped to mutiple
// lines in display. This could reduce the compution need for redraw
Expand Down
10 changes: 5 additions & 5 deletions include/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

#include <stdint.h>

// todo: change this two
// this two in orig project keep the real hw size of the screen
// while the render size is configurable
#define SCREEN_REAL_WIDTH 128
#define SCREEN_REAL_HEIGHT 128
// // todo: change this two
// // this two in orig project keep the real hw size of the screen
// // while the render size is configurable
// #define GE0_SCREEN_WIDTH 128
// #define GE0_SCREEN_HEIGHT 128

void setScreenResolution(uint16_t nw, uint16_t nh);
void redrawScreen(void);
Expand Down
15 changes: 8 additions & 7 deletions include/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

#include <engine.h>
#include <stdint.h>
#include "utils.h"
// #define SCREEN_HEIGHT 128
// #define SCREEN_WIDTH 128

#define SCREEN_HEIGHT 128
#define SCREEN_WIDTH 128
#define SCREEN_WIDTH_BYTES 64
#define SCREEN_WIDTH_BYTES (GE0_SCREEN_WIDTH * 4 / 8) // Each pixel usse 4 bit
#define SCREEN_WIDTH_BYTES_LOG BITS_TO_REPRESENT(SCREEN_WIDTH_BYTES)
#define SCREEN_SIZE (SCREEN_WIDTH_BYTES * GE0_SCREEN_HEIGHT)
#define SCREEN_ARRAY_DEF SCREEN_SIZE

#define SCREEN_SIZE (SCREEN_HEIGHT * SCREEN_WIDTH_BYTES)
#define SCREEN_ARRAY_DEF SCREEN_SIZE

#define SCREEN_ADDR(x, y) (((y) << 6) + (x))
#define SCREEN_ADDR(x, y) (((y) << SCREEN_WIDTH_BYTES_LOG) + (x))

struct sprite {
uint16_t address;
Expand Down
45 changes: 45 additions & 0 deletions include/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef UTILS_H_
#define UTILS_H_

#define IS_REPRESENTIBLE_IN_D_BITS(D, N) \
(((unsigned long) N >= (1UL << (D - 1)) && (unsigned long) N < (1UL << D)) ? D : -1)
// see https://stackoverflow.com/questions/27581671/how-to-compute-log-with-the-preprocessor
#define BITS_TO_REPRESENT(N) \
(N == 0 ? 1 : (31 \
+ IS_REPRESENTIBLE_IN_D_BITS( 1, N) \
+ IS_REPRESENTIBLE_IN_D_BITS( 2, N) \
+ IS_REPRESENTIBLE_IN_D_BITS( 3, N) \
+ IS_REPRESENTIBLE_IN_D_BITS( 4, N) \
+ IS_REPRESENTIBLE_IN_D_BITS( 5, N) \
+ IS_REPRESENTIBLE_IN_D_BITS( 6, N) \
+ IS_REPRESENTIBLE_IN_D_BITS( 7, N) \
+ IS_REPRESENTIBLE_IN_D_BITS( 8, N) \
+ IS_REPRESENTIBLE_IN_D_BITS( 9, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(10, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(11, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(12, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(13, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(14, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(15, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(16, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(17, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(18, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(19, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(20, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(21, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(22, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(23, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(24, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(25, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(26, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(27, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(28, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(29, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(30, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(31, N) \
+ IS_REPRESENTIBLE_IN_D_BITS(32, N) \
) \
)


#endif // UTILS_H_
46 changes: 24 additions & 22 deletions mem.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
// // 在我搞清楚mem到底放了什么东西之前,我先不实现这几个函数了
// int16_t readInt(uint16_t adr) {
// printf("readInt is called\n");
// (void)adr;
// return 0;
// /* int16_t n; */
// /* int8_t *nPtr; */
// /* if(adr < RAM_SIZE - 1){ */
// /* nPtr = (int8_t*)&n; */
// /* *nPtr = lge_mem[adr++]; */
// /* nPtr++; */
// /* *nPtr = lge_mem[adr]; */
// /* return n; */
// /* } */
// /* return 0; */
// }
#include <stdio.h>

// uint8_t readMem(uint16_t adr) {
// printf("readMem is called\n");
// (void)adr;
// return 0;
// /* return (adr < RAM_SIZE) ? lge_mem[adr] : 0; */
// }
// 在我搞清楚mem到底放了什么东西之前,我先不实现这几个函数了
int16_t readInt(uint16_t adr) {
printf("readInt is called\n");
(void)adr;
return 0;
/* int16_t n; */
/* int8_t *nPtr; */
/* if(adr < RAM_SIZE - 1){ */
/* nPtr = (int8_t*)&n; */
/* *nPtr = lge_mem[adr++]; */
/* nPtr++; */
/* *nPtr = lge_mem[adr]; */
/* return n; */
/* } */
/* return 0; */
}

uint8_t readMem(uint16_t adr) {
printf("readMem is called\n");
(void)adr;
return 0;
/* return (adr < RAM_SIZE) ? lge_mem[adr] : 0; */
}
9 changes: 6 additions & 3 deletions ports/bare_metal_lcd_port.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include "ge0_port_interface.h"
#include "lcd.h"

void ge0_port_display_fillScreen(uint16_t color){

lcd_fill(0, 0, LCD_W, LCD_H, color);
}

void ge0_port_display_drawLine(uint32_t line, uint32_t start, uint32_t width, uint32_t *colors){

for(uint32_t i=0;i<width;++i){
lcd_draw_point(start+i, line, ((uint16_t*)colors)[i]);
}
}

void ge0_port_display_sync(void){

return;
}
10 changes: 5 additions & 5 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void setPix(uint16_t x, uint16_t y, uint8_t p) {
if (0) {
// todo :1484
} else {
if (x < SCREEN_WIDTH && y < SCREEN_HEIGHT) {
if (x < GE0_SCREEN_WIDTH && y < GE0_SCREEN_HEIGHT) {
x_index = x >> 1;
orig = screen[SCREEN_ADDR(x_index, y)];
if (x & 1)
Expand All @@ -73,8 +73,8 @@ void setPix(uint16_t x, uint16_t y, uint8_t p) {
}

void clearScr(uint8_t p) {
for (uint16_t y = 0; y < SCREEN_HEIGHT; y++) {
for (uint16_t x = 0; x < SCREEN_WIDTH; x++) {
for (uint16_t y = 0; y < GE0_SCREEN_HEIGHT; y++) {
for (uint16_t x = 0; x < GE0_SCREEN_WIDTH; x++) {
setPix(x, y, p);
}
}
Expand All @@ -85,8 +85,8 @@ void clearScr(uint8_t p) {
void changePalette(uint8_t n, uint16_t c) {
if (n < 16) {
palette[n] = c;
for (uint8_t y = 0; y < 128; y++) {
for (uint8_t x = 0; x < 64; x++) { // todo: Why x here is 64?
for (uint8_t y = 0; y < GE0_SCREEN_HEIGHT; y++) {
for (uint8_t x = 0; x < SCREEN_WIDTH_BYTES; x++) {
if (((screen[SCREEN_ADDR(x, y)] & 0xf0) >> 4) == n ||
(screen[SCREEN_ADDR(x, y)] & 0x0f) == n)
SET_LINE_IS_DRAW(y);
Expand Down