update readme, use only Mw/Milsko.h

This commit is contained in:
IoI_xD 2026-03-10 20:52:35 -07:00
commit 7b0bb0ad5c
3 changed files with 30 additions and 43 deletions

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# milskoboy
Basic Gameboy emulator written using PeanutGB and [Milsko](https://gitea.nishi.boats/pyrite-dev/milsko). Not meant to be used seriously, instead meant to be portable enough to be usable as a test across any platforms Milsko supports.

60
main.c
View file

@ -2,22 +2,14 @@
#include "peanut_gb.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <Mw/Milsko.h>
struct priv_t {
uint8_t *rom;
uint8_t *cart_ram;
uint8_t fb[LCD_WIDTH * LCD_HEIGHT * 4];
MwU8 *rom;
MwU8 *cart_ram;
MwU8 fb[LCD_WIDTH * LCD_HEIGHT * 4];
size_t save_size;
MwU64 save_size;
char *save_file_name;
MwWidget *win;
@ -151,7 +143,7 @@ static void key_released(MwWidget handle, void *user, void *client) {
/**
* Returns a byte from the ROM file at the given address.
*/
uint8_t gb_rom_read(struct gb_s *gb, const uint_fast32_t addr) {
MwU8 gb_rom_read(struct gb_s *gb, const uint_fast32_t addr) {
const struct priv_t *const p = gb->direct.priv;
return p->rom[addr];
}
@ -159,13 +151,13 @@ uint8_t gb_rom_read(struct gb_s *gb, const uint_fast32_t addr) {
/**
* Returns a byte from the cartridge RAM at the given address.
*/
uint8_t gb_cart_ram_read(struct gb_s *gb, const uint_fast32_t addr) {
MwU8 gb_cart_ram_read(struct gb_s *gb, const uint_fast32_t addr) {
const struct priv_t *const p = gb->direct.priv;
return p->cart_ram[addr];
}
void read_cart_ram_file(const char *save_file_name, uint8_t **dest,
const size_t len) {
void read_cart_ram_file(const char *save_file_name, MwU8 **dest,
const MwU64 len) {
FILE *f;
/* If save file not required. */
@ -177,31 +169,32 @@ void read_cart_ram_file(const char *save_file_name, uint8_t **dest,
/* Allocate enough memory to hold save file. */
*dest = malloc(len);
printf("%s\n", save_file_name);
if ((f = fopen(save_file_name, "rb")) == NULL) {
printf("Unable to open save file for reading: %s\n", strerror(errno));
printf("Unable to open save file (%s) for reading: %s\n", save_file_name,
strerror(errno));
return;
}
/* Read save file to allocated memory. */
fread(*dest, sizeof(uint8_t), len, f);
fread(*dest, sizeof(MwU8), len, f);
fclose(f);
}
void write_cart_ram_file(const char *save_file_name, uint8_t **dest,
const size_t len) {
void write_cart_ram_file(const char *save_file_name, MwU8 **dest,
const MwU64 len) {
FILE *f;
if (len == 0 || *dest == NULL)
return;
if ((f = fopen(save_file_name, "wb")) == NULL) {
printf("Unable to open save file for writing: %s\n", strerror(errno));
printf("Unable to open save file (%s) for writing: %s\n", save_file_name,
strerror(errno));
return;
}
/* Record save file. */
fwrite(*dest, sizeof(uint8_t), len, f);
fwrite(*dest, sizeof(MwU8), len, f);
fclose(f);
return;
@ -211,7 +204,7 @@ void write_cart_ram_file(const char *save_file_name, uint8_t **dest,
* Writes a given byte to the cartridge RAM at the given address.
*/
void gb_cart_ram_write(struct gb_s *gb, const uint_fast32_t addr,
const uint8_t val) {
const MwU8 val) {
const struct priv_t *const p = gb->direct.priv;
p->cart_ram[addr] = val;
@ -221,10 +214,10 @@ void gb_cart_ram_write(struct gb_s *gb, const uint_fast32_t addr,
/**
* Returns a pointer to the allocated space containing the ROM. Must be freed.
*/
uint8_t *read_rom_to_ram(const char *file_name) {
MwU8 *read_rom_to_ram(const char *file_name) {
FILE *rom_file = fopen(file_name, "rb");
size_t rom_size;
uint8_t *rom = NULL;
MwU64 rom_size;
MwU8 *rom = NULL;
if (rom_file == NULL)
return NULL;
@ -234,7 +227,7 @@ uint8_t *read_rom_to_ram(const char *file_name) {
rewind(rom_file);
rom = malloc(rom_size);
if (fread(rom, sizeof(uint8_t), rom_size, rom_file) != rom_size) {
if (fread(rom, sizeof(MwU8), rom_size, rom_file) != rom_size) {
free(rom);
fclose(rom_file);
return NULL;
@ -266,7 +259,7 @@ void gb_error(struct gb_s *gb, const enum gb_error_e gb_err,
/**
* Draws scanline into framebuffer.
*/
void lcd_draw_line(struct gb_s *gb, const uint8_t pixels[160],
void lcd_draw_line(struct gb_s *gb, const MwU8 pixels[160],
const uint_fast8_t line) {
struct priv_t *priv = gb->direct.priv;
const uint16_t palette[3][4] = {{0xFF, 0xA5, 0x52, 0x00},
@ -318,8 +311,6 @@ int main(int argc, char **argv) {
/* Load Save File. */
gb_get_save_size_s(&gb, &priv.save_size);
printf("%ld\n", priv.save_size);
priv.cart_ram = malloc(priv.save_size);
/* rom save name */
@ -347,9 +338,7 @@ int main(int argc, char **argv) {
struct timeval timecheck;
int state;
gettimeofday(&timecheck, NULL);
start = (long)timecheck.tv_sec * 1000000 + (long)timecheck.tv_usec;
start = MwTimeGetTick();
/* Execute CPU cycles until the screen has to be redrawn. */
gb_run_frame(&gb);
@ -359,8 +348,7 @@ int main(int argc, char **argv) {
if (state < 0)
break;
gettimeofday(&timecheck, NULL);
end = (long)timecheck.tv_sec * 1000000 + (long)timecheck.tv_usec;
end = MwTimeGetTick();
delay = target_speed_us - (end - start);

View file

@ -41,11 +41,7 @@
#define __has_include(x) 0
#endif
#include <stdbool.h> /* Required for bool types */
#include <stdint.h> /* Required for int types */
#include <stdlib.h> /* Required for abort */
#include <string.h> /* Required for memset */
#include <time.h> /* Required for tm struct */
#include <Mw/Milsko.h>
/**
* If PEANUT_GB_IS_LITTLE_ENDIAN is positive, then Peanut-GB will be configured
@ -3364,7 +3360,7 @@ void gb_run_frame(struct gb_s *gb) {
__gb_step_cpu(gb);
}
int gb_get_save_size_s(struct gb_s *gb, size_t *ram_size) {
int gb_get_save_size_s(struct gb_s *gb, MwU64 *ram_size) {
const uint_fast16_t ram_size_location = 0x0149;
const uint_fast32_t ram_sizes[] = {
/* 0, 2KiB, 8KiB, 32KiB, 128KiB, 64KiB */
@ -3769,7 +3765,7 @@ void gb_init_serial(struct gb_s *gb,
* set.
* \returns 0 on success, or -1 if the RAM size is invalid or unknown.
*/
int gb_get_save_size_s(struct gb_s *gb, size_t *ram_size);
int gb_get_save_size_s(struct gb_s *gb, MwU64 *ram_size);
/**
* Deprecated. Use gb_get_save_size_s() instead.