Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segfault #8

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion cmd/go6502/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func run() {

deviceMap, err := bus.New(
bus.NewRam(0x0, 0x1000),
bus.NewRom(0x8000, "./code/blinkc"),
bus.NewRom(0x8000, "./code/graphics"),
graphics.CreatePPU(0x1000),
imu,
)
Expand Down
6 changes: 6 additions & 0 deletions code/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

GFX_FILES = gfx/gfx.c
GFX = $(patsubst %.c,%.o,$(GFX_FILES))

%.o: %.s
ca65 -o $@ $^ -t none

Expand All @@ -9,5 +12,8 @@
cl65 -o $@ $^ -t none -c


graphics: graphics.o $(GFX) reset.o
ld65 -o $@ $^ none.lib -C link.ld

blinkc: blinkc.o reset.o
ld65 -o $@ $^ -C link.ld
27 changes: 27 additions & 0 deletions code/gfx/gfx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "gfx.h"
#include <stdint.h>

char * video_buffer;
uint8_t width;
uint8_t height;

void gfx_init(uintptr_t video_buffer_address, uint8_t w, uint8_t h) {
video_buffer = (char *)video_buffer_address;
width = w;
height = h;
}

void clear(color_t color) {
uint8_t i;
uint8_t j;

for (i = 0; i < width; ++i) {
for (j = 0; j < height; ++j) {
video_buffer[j * width + i] = color;
}
}
}

color_t get_color(Palette p, uint8_t index) {
return (uint8_t) p << 5 | index && 0b11111;
}
27 changes: 27 additions & 0 deletions code/gfx/gfx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#ifndef GFX_H
#define GFX_H

#include <stdint.h>

extern char * video_buffer;
extern uint8_t width;
extern uint8_t height;

typedef uint8_t color_t;

void gfx_init(uintptr_t video_buffer_address, uint8_t w, uint8_t h);
void clear(color_t color);

typedef enum {
Palette0 = 0,
Endesga = 1,
Clear = 2,

GrayPalette = 7,
} Palette;


color_t get_color(Palette p, uint8_t index);

#endif
Binary file modified code/graphics
Binary file not shown.
10 changes: 10 additions & 0 deletions code/graphics.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "gfx/gfx.h"

void reset() {
color_t red;

gfx_init(0x1000, 64, 64);

red = get_color(Endesga, 3);
clear(red);
}
4 changes: 4 additions & 0 deletions code/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ SEGMENTS {
load = RAM1
type=bss
define=yes;
ZEROPAGE:
load = RAM1
type = zp
define = yes;
RESET:
load = ROM1
start = $fffa
Expand Down