Use calloc for memory array
This commit is contained in:
parent
22c6e07fca
commit
cca1253376
|
@ -1,7 +1,9 @@
|
||||||
( dev/console )
|
( dev/console )
|
||||||
|
|
||||||
|00 @System $e &debug
|
%HALT { #010f DEO }
|
||||||
|10 @Console $8 &write
|
%EMIT { #18 DEO }
|
||||||
|
%DEBUG { ;print-hex/byte JSR2 #0a EMIT }
|
||||||
|
%DEBUG2 { ;print-hex JSR2 #0a EMIT }
|
||||||
|
|
||||||
( init )
|
( init )
|
||||||
|
|
||||||
|
@ -9,11 +11,28 @@
|
||||||
|
|
||||||
;hello-word
|
;hello-word
|
||||||
&while
|
&while
|
||||||
( send ) LDAk .Console/write DEO
|
( send ) LDAk EMIT
|
||||||
|
#20 EMIT
|
||||||
|
DUP2 ;print-hex JSR2
|
||||||
|
#20 EMIT
|
||||||
|
LDAk ;print-hex/byte JSR2
|
||||||
|
#0a EMIT
|
||||||
INC2 LDAk ,&while JCN
|
INC2 LDAk ,&while JCN
|
||||||
POP2
|
POP2
|
||||||
( show debugger ) #01 .System/debug DEO
|
( stop ) HALT
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
|
@print-hex ( value* -- )
|
||||||
|
|
||||||
|
SWP ,&byte JSR
|
||||||
|
&byte ( byte -- )
|
||||||
|
STHk #04 SFT ,&parse JSR #18 DEO
|
||||||
|
STHr #0f AND ,&parse JSR #18 DEO
|
||||||
|
JMP2r
|
||||||
|
&parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r
|
||||||
|
&above #57 ADD JMP2r
|
||||||
|
|
||||||
|
JMP2r
|
||||||
|
|
||||||
@hello-word "Hello 20 "Uxn!
|
@hello-word "Hello 20 "Uxn!
|
|
@ -4018,12 +4018,13 @@ error:
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
uxn_boot(Uxn *u)
|
uxn_boot(Uxn *u, Uint8 *memory)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
char *cptr = (char *)u;
|
char *cptr = (char *)u;
|
||||||
for(i = 0; i < sizeof(*u); ++i)
|
for(i = 0; i < sizeof(*u); ++i)
|
||||||
cptr[i] = 0x00;
|
cptr[i] = 0x00;
|
||||||
|
u->ram.dat = memory;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,12 +136,13 @@ uxn_eval(Uxn *u, Uint16 vec)
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
int
|
int
|
||||||
uxn_boot(Uxn *u)
|
uxn_boot(Uxn *u, Uint8 *memory)
|
||||||
{
|
{
|
||||||
Uint32 i;
|
Uint32 i;
|
||||||
char *cptr = (char *)u;
|
char *cptr = (char *)u;
|
||||||
for(i = 0; i < sizeof(*u); ++i)
|
for(i = 0; i < sizeof(*u); ++i)
|
||||||
cptr[i] = 0x00;
|
cptr[i] = 0x00;
|
||||||
|
u->ram.dat = memory;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Uint16 ptr;
|
Uint16 ptr;
|
||||||
Uint8 dat[65536];
|
Uint8 *dat;
|
||||||
} Memory;
|
} Memory;
|
||||||
|
|
||||||
typedef struct Device {
|
typedef struct Device {
|
||||||
|
@ -44,7 +44,7 @@ typedef struct Uxn {
|
||||||
void poke16(Uint8 *m, Uint16 a, Uint16 b);
|
void poke16(Uint8 *m, Uint16 a, Uint16 b);
|
||||||
Uint16 peek16(Uint8 *m, Uint16 a);
|
Uint16 peek16(Uint8 *m, Uint16 a);
|
||||||
|
|
||||||
int uxn_boot(Uxn *c);
|
int uxn_boot(Uxn *c, Uint8 *memory);
|
||||||
int uxn_eval(Uxn *u, Uint16 vec);
|
int uxn_eval(Uxn *u, Uint16 vec);
|
||||||
int uxn_halt(Uxn *u, Uint8 error, char *name, int id);
|
int uxn_halt(Uxn *u, Uint8 error, char *name, int id);
|
||||||
Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8));
|
Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8));
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "uxn.h"
|
#include "uxn.h"
|
||||||
|
@ -147,7 +148,7 @@ load(Uxn *u, char *filepath)
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int r;
|
int r;
|
||||||
if(!(f = fopen(filepath, "rb"))) return 0;
|
if(!(f = fopen(filepath, "rb"))) return 0;
|
||||||
r = fread(u->ram.dat + PAGE_PROGRAM, 1, sizeof(u->ram.dat) - PAGE_PROGRAM, f);
|
r = fread(u->ram.dat + PAGE_PROGRAM, 1, 0xffff - PAGE_PROGRAM, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if(r < 1) return 0;
|
if(r < 1) return 0;
|
||||||
fprintf(stderr, "Loaded %s\n", filepath);
|
fprintf(stderr, "Loaded %s\n", filepath);
|
||||||
|
@ -160,7 +161,7 @@ main(int argc, char **argv)
|
||||||
Uxn u;
|
Uxn u;
|
||||||
int i, loaded = 0;
|
int i, loaded = 0;
|
||||||
|
|
||||||
if(!uxn_boot(&u))
|
if(!uxn_boot(&u, (Uint8 *)calloc(0xffff, sizeof(Uint8))))
|
||||||
return error("Boot", "Failed");
|
return error("Boot", "Failed");
|
||||||
|
|
||||||
/* system */ devsystem = uxn_port(&u, 0x0, system_dei, system_deo);
|
/* system */ devsystem = uxn_port(&u, 0x0, system_dei, system_deo);
|
||||||
|
|
|
@ -273,7 +273,7 @@ load(Uxn *u, char *rom)
|
||||||
SDL_RWops *f;
|
SDL_RWops *f;
|
||||||
int r;
|
int r;
|
||||||
if(!(f = SDL_RWFromFile(rom, "rb"))) return 0;
|
if(!(f = SDL_RWFromFile(rom, "rb"))) return 0;
|
||||||
r = f->read(f, u->ram.dat + PAGE_PROGRAM, 1, sizeof(u->ram.dat) - PAGE_PROGRAM);
|
r = f->read(f, u->ram.dat + PAGE_PROGRAM, 1, 0xffff - PAGE_PROGRAM);
|
||||||
f->close(f);
|
f->close(f);
|
||||||
if(r < 1) return 0;
|
if(r < 1) return 0;
|
||||||
fprintf(stderr, "Loaded %s\n", rom);
|
fprintf(stderr, "Loaded %s\n", rom);
|
||||||
|
@ -284,7 +284,8 @@ load(Uxn *u, char *rom)
|
||||||
static int
|
static int
|
||||||
start(Uxn *u, char *rom)
|
start(Uxn *u, char *rom)
|
||||||
{
|
{
|
||||||
if(!uxn_boot(u))
|
Uint8 *memory = (Uint8 *)calloc(0xffff, sizeof(Uint8));
|
||||||
|
if(!uxn_boot(u, memory))
|
||||||
return error("Boot", "Failed to start uxn.");
|
return error("Boot", "Failed to start uxn.");
|
||||||
if(!load(u, rom))
|
if(!load(u, rom))
|
||||||
return error("Boot", "Failed to load rom.");
|
return error("Boot", "Failed to load rom.");
|
||||||
|
|
Loading…
Reference in New Issue