Skip to content

Commit 117a7c5

Browse files
committed
P8SCII support, initial commit. #4, #12
1 parent 97e9139 commit 117a7c5

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

cmake/project_config.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(project_sources
88
${CMAKE_CURRENT_SOURCE_DIR}/src/core.c
99
${CMAKE_CURRENT_SOURCE_DIR}/src/image_loader.c
1010
${CMAKE_CURRENT_SOURCE_DIR}/src/memory.c
11+
${CMAKE_CURRENT_SOURCE_DIR}/src/p8scii.c
1112
${CMAKE_CURRENT_SOURCE_DIR}/src/lexaloffle/p8_compress.c
1213
${CMAKE_CURRENT_SOURCE_DIR}/src/lexaloffle/pxa_compress_snippets.c)
1314

media/ascii_reference.png

1.14 KB
Loading

src/p8scii.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/** @file p8scii.c
2+
*
3+
* A portable PICO-8 emulator written in C.
4+
*
5+
* Copyright (c) 2025, Michael Fitzmayer. All rights reserved.
6+
* SPDX-License-Identifier: MIT
7+
*
8+
**/
9+
10+
#include <stdint.h>
11+
#include "memory.h"
12+
#include "p8scii.h"
13+
14+
#define FONT_WIDTH 3
15+
#define FONT_HEIGHT 5
16+
17+
const uint8_t font[256][FONT_HEIGHT] =
18+
{
19+
{ 0b111, 0b101, 0b101, 0b101, 0b111 }
20+
};
21+
22+
void blit_char_to_screen(uint8_t char_index, int x, int y, uint8_t color)
23+
{
24+
const uint8_t* char_bitmap = font[char_index];
25+
26+
for (int row = 0; row < FONT_HEIGHT; row++)
27+
{
28+
uint8_t row_data = char_bitmap[row];
29+
for (int col = 0; col < FONT_WIDTH; col++)
30+
{
31+
if (row_data & (1 << (FONT_WIDTH - 1 - col)))
32+
{
33+
int screen_x = x + col;
34+
int screen_y = y + row;
35+
uint16_t addr = 0x6000 + (screen_y << 6) + (screen_x >> 1);
36+
uint8_t mask = (screen_x & 1) ? 0x0F : 0xF0;
37+
uint8_t shift = (screen_x & 1) ? 4 : 0;
38+
pico8_ram[addr] = (pico8_ram[addr] & mask) | (color << shift);
39+
}
40+
}
41+
}
42+
}

src/p8scii.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** @file p8scii.h
2+
*
3+
* A portable PICO-8 emulator written in C.
4+
*
5+
* Copyright (c) 2025, Michael Fitzmayer. All rights reserved.
6+
* SPDX-License-Identifier: MIT
7+
*
8+
**/
9+
10+
#ifndef P8SCII_H
11+
#define P8SCII_H
12+
13+
#include <stdint.h>
14+
15+
void blit_char_to_screen(uint8_t char_index, int x, int y, uint8_t color);
16+
17+
#endif // P8SCII_H

0 commit comments

Comments
 (0)