hacer varias cosas configurables desde config.h
This commit is contained in:
parent
dd8d9d950d
commit
db7add34d1
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#define MEM_W 400
|
||||
#define MEM_H 300
|
||||
#define MEM_ZOOM 2
|
||||
|
||||
#define STACK_SIZE 256
|
||||
|
||||
#define RETSTACK_DEPTH 256
|
||||
#define CALL_SIZE 255
|
||||
|
||||
#define CPU_STACK_SIZE 256
|
||||
|
||||
#define TARGET_FPS 30
|
|
@ -1,3 +1,5 @@
|
|||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
@ -6,14 +8,9 @@
|
|||
typedef unsigned int u32;
|
||||
typedef unsigned char u8; //NASTY GIRL FANTASTIC
|
||||
|
||||
#define MEM_SIZE_W 400
|
||||
#define MEM_SIZE_H 300
|
||||
#define MEM_SIZE 300 * 400
|
||||
/*
|
||||
extern const u32 MEM_SIZE_W = 400;
|
||||
extern const u32 MEM_SIZE_H = 300;
|
||||
extern const u32 MEM_SIZE = MEM_SIZE_W * MEM_SIZE_H;
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#define MEM_SIZE (MEM_W * MEM_H)
|
||||
|
||||
enum op_c {
|
||||
// 0
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include "config.h"
|
||||
|
||||
/* Una pequeña VM para una presentacion
|
||||
* opcodes:
|
||||
* nop
|
||||
|
@ -21,7 +23,7 @@
|
|||
* pop
|
||||
*
|
||||
* stack_p nos señala donde viven nuestras variables locales.
|
||||
* actualmente cada call reserva 255 espacios de memoria...
|
||||
* actualmente cada call reserva CALL_SIZE espacios de memoria...
|
||||
* esto es ridiculo y deberia en realidad reservar menos memoria.
|
||||
* Tal vez hasta podria ser configurable. Podriamos guardarnos un
|
||||
* poco de memoria al final de todo para configurar opciones.
|
||||
|
@ -47,9 +49,9 @@
|
|||
#define VM_ERR_OUT_OF_INDEX -2
|
||||
|
||||
struct toyboxica {
|
||||
u8 mem[400 * 300];
|
||||
u8 mem[MEM_W * MEM_H];
|
||||
u8 c_pointer;
|
||||
u32 cpu_stack[256];
|
||||
u32 cpu_stack[CPU_STACK_SIZE];
|
||||
u32 stack_p;
|
||||
u32 *ret_stack;
|
||||
u32 pc;
|
||||
|
|
|
@ -2,30 +2,35 @@
|
|||
|
||||
void
|
||||
draw_mem(struct toyboxica *t) {
|
||||
for (int x = 0; x < MEM_SIZE_W; x++)
|
||||
for (int y = 0; y < MEM_SIZE_H; y++) {
|
||||
u8 p = t->mem[x + y * MEM_SIZE_W];
|
||||
const int w = MEM_W;
|
||||
const int h = MEM_H;
|
||||
const int z = MEM_ZOOM;
|
||||
|
||||
for (int x = 0; x < w; x++)
|
||||
for (int y = 0; y < h; y++) {
|
||||
u8 p = t->mem[x + y * w];
|
||||
if (p != 0) {
|
||||
DrawRectangle(x * 2, y * 2, 2, 2,
|
||||
DrawRectangle(x * z, y * z, z, z,
|
||||
(Color){
|
||||
(p * 8) % 130,
|
||||
(p * 7) % 44,
|
||||
(p * 3) % 73,
|
||||
255});
|
||||
}
|
||||
if (x == 0 || x == MEM_SIZE_W -1) DrawPixel(x * 2, y * 2, LIME);
|
||||
if (y == 0 || y == MEM_SIZE_H -1) DrawPixel(x * 2, y * 2, LIME);
|
||||
if (x == 0 || x == w-1) DrawPixel(x * z, y * z, LIME);
|
||||
if (y == 0 || y == h-1) DrawPixel(x * z, y * z, LIME);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main() {
|
||||
InitWindow(800, 600, "presentacion");
|
||||
InitWindow(MEM_W * MEM_ZOOM, MEM_H * MEM_ZOOM, "toyboxica");
|
||||
|
||||
struct toyboxica t;
|
||||
read_mem(&(t.mem));
|
||||
toy_init(&t);
|
||||
|
||||
SetTargetFPS(30);
|
||||
SetTargetFPS(TARGET_FPS);
|
||||
|
||||
while(!WindowShouldClose()) {
|
||||
for(int i = 0; i < 10; i++)
|
||||
|
|
|
@ -101,7 +101,7 @@ call_i(struct toyboxica *t) {
|
|||
*t->ret_stack = t->pc + 4;
|
||||
*(t->ret_stack + 1) = t->stack_p;
|
||||
t->ret_stack += 2;
|
||||
t->stack_p -= 255;
|
||||
t->stack_p -= CALL_SIZE;
|
||||
t->pc = pop_i(t);
|
||||
return;
|
||||
}
|
||||
|
@ -190,9 +190,10 @@ step(struct toyboxica *t) {
|
|||
|
||||
void
|
||||
toy_init(struct toyboxica *t) {
|
||||
for (int i = 0; i < 255; i++) t->cpu_stack[i] = 0;
|
||||
t->stack_p = MEM_SIZE - 256; // 65535
|
||||
t->ret_stack = &(t->mem[MEM_SIZE - 256 * 256]);
|
||||
for (int i = 0; i < CPU_STACK_SIZE; i++) t->cpu_stack[i] = 0;
|
||||
|
||||
t->stack_p = MEM_SIZE - STACK_SIZE;
|
||||
t->ret_stack = &(t->mem[MEM_SIZE - STACK_SIZE - RETSTACK_DEPTH * CALL_SIZE]);
|
||||
t->pc = 0;
|
||||
t->c_pointer = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue