Minor cleanup
This commit is contained in:
parent
0d86ff78d7
commit
f740ec3feb
2
build.sh
2
build.sh
|
@ -28,7 +28,7 @@ else
|
|||
fi
|
||||
|
||||
echo "Assembling.."
|
||||
./bin/assembler projects/software/noodle.usm bin/boot.rom
|
||||
./bin/assembler projects/software/nasu.usm bin/boot.rom
|
||||
|
||||
echo "Running.."
|
||||
if [ "${2}" = '--cli' ];
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
( blank )
|
||||
|
||||
;label2d { x 2 y 2 color 1 addr 2 }
|
||||
;picture2d { x 2 y 2 width 2 height 2 color 1 addr 2 }
|
||||
;rect2d { x1 2 y1 2 x2 2 y2 2 }
|
||||
;point2d { x 2 y 2 }
|
||||
|
||||
|0100 @RESET BRK
|
||||
|c000 @FRAME BRK
|
||||
|d000 @ERROR BRK
|
||||
|
||||
|FF00 ;Console { pad 8 char 1 byte 1 short 2 }
|
||||
|FF10 ;Screen { width 2 height 2 pad 4 x 2 y 2 color 1 }
|
||||
|FF20 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 }
|
||||
|FF30 ;Controller { buttons 1 }
|
||||
|FF40 ;Keys { key 1 }
|
||||
|FF50 ;Mouse { x 2 y 2 state 1 chord 1 }
|
||||
|FF60 ;File { pad 8 name 2 length 2 load 2 save 2 }
|
||||
|
||||
|FFF0 .RESET .FRAME .ERROR ( vectors )
|
||||
|FFF8 [ 13fd 1ef3 1bf2 ] ( palette )
|
|
@ -60,14 +60,14 @@
|
|||
|0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|
||||
|0160 ;File { pad 8 name 2 length 2 load 2 save 2 }
|
||||
|01F0 .RESET .FRAME .ERROR ( vectors )
|
||||
|01F8 [ c0ef c07f c05f ] ( palette )
|
||||
|01F8 [ e0fd 30fd 30fd ] ( palette )
|
||||
|
||||
( program )
|
||||
|
||||
|0200 @RESET
|
||||
|
||||
( default canvas )
|
||||
#0020 =canvas.w #0010 =canvas.h
|
||||
#002a =canvas.w #001a =canvas.h
|
||||
|
||||
( default brush )
|
||||
#04 =brush.size
|
||||
|
@ -784,7 +784,7 @@ RTN
|
|||
@save_icn [ fe82 8282 848a f400 ]
|
||||
|
||||
@blank_icn [ 0000 0000 0000 0000 ]
|
||||
@filepath [ projects/pictures/akane2010.bit 00 ]
|
||||
@filepath [ projects/pictures/tima2a1a.bit 00 ]
|
||||
|
||||
@font_hex ( 0-F )
|
||||
[
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
( hello world )
|
||||
|
||||
%RTN { JMP2r }
|
||||
|
||||
( devices )
|
||||
|
||||
|0100 ;Console { pad 8 char 1 byte 1 short 2 }
|
||||
|01F0 .RESET .FRAME .ERROR ( vectors )
|
||||
|01F8 [ 13fd 1ef3 1bf2 ] ( palette )
|
||||
|
||||
( program )
|
||||
|
||||
|0400 @RESET
|
||||
|
||||
( for loop )
|
||||
#00 #0d
|
||||
$loop
|
||||
( body )
|
||||
SWP #01 ADD SWP
|
||||
DUP2 LTH ^$loop JNZ
|
||||
POP2
|
||||
|
||||
( while )
|
||||
#00 #0d
|
||||
$while
|
||||
( body )
|
||||
DUP2 EQU ^$end JNZ
|
||||
SWP #01 ADD SWP
|
||||
^$while JMP $end
|
||||
POP2
|
||||
|
||||
( switch )
|
||||
#02
|
||||
DUP #01 NEQ ^$b JNZ
|
||||
( a )
|
||||
$b DUP #02 NEQ ^$c JNZ
|
||||
( b )
|
||||
$c DUP #03 NEQ ^$default JNZ
|
||||
( c )
|
||||
$default
|
||||
POP
|
||||
|
||||
BRK
|
||||
|
||||
@FRAME BRK
|
||||
@ERROR BRK
|
|
@ -1,68 +0,0 @@
|
|||
( Loop )
|
||||
|
||||
;a { byte 1 } ;b { byte 1 } ;c { byte 1 }
|
||||
|
||||
|0100 @RESET
|
||||
|
||||
,slow-muljmp JSR2
|
||||
,slow-jmppop JSR2
|
||||
,slow-jmppop-rel JSR2
|
||||
,fast-byte JSR2
|
||||
,fast-short JSR2
|
||||
|
||||
BRK
|
||||
|
||||
|0200 @slow-muljmp ( type: padded muljmp )
|
||||
|
||||
$loop NOP
|
||||
~a #01 ADD =a
|
||||
~a #d0 LTH ^$loop MUL JMP
|
||||
~a =Console.byte
|
||||
|
||||
RTN
|
||||
|
||||
|0300 @slow-jmppop ( type: jmppop )
|
||||
|
||||
$loop
|
||||
~b #01 ADD =b
|
||||
,$loop ~b #d0 LTH JNZ2
|
||||
~b =Console.byte
|
||||
|
||||
RTN
|
||||
|
||||
|0400 @slow-jmppop-rel ( type: padded jmppop )
|
||||
|
||||
$loop NOP
|
||||
~c #01 ADD =c
|
||||
~c #d0 LTH ^$loop SWP JMP?
|
||||
~c =Console.byte
|
||||
|
||||
RTN
|
||||
|
||||
|0500 @fast-byte ( fast byte )
|
||||
|
||||
#00 #d0
|
||||
$loop NOP
|
||||
( incr ) SWP #01 ADD SWP
|
||||
DUP2 LTH ^$loop SWP JMP?
|
||||
POP =Console.byte
|
||||
|
||||
RTN
|
||||
|
||||
|0600 @fast-short ( fast short )
|
||||
|
||||
#0000 #0d00
|
||||
$loop NOP
|
||||
( incr ) SWP2 #0001 ADD2 SWP2
|
||||
OVR2 OVR2 LTH2 ^$loop SWP JMP?
|
||||
POP2 =Console.short
|
||||
|
||||
RTN
|
||||
|
||||
|c000 @FRAME
|
||||
|d000 @ERROR
|
||||
|
||||
|FF00 ;Console { pad 8 char 1 byte 1 short 2 }
|
||||
|
||||
|FFF0 .RESET .FRAME .ERROR ( vectors )
|
||||
|FFF8 [ 13fd 1ef3 1bf2 ] ( palette )
|
|
@ -154,9 +154,12 @@ findopcode(char *s)
|
|||
if(o[0] != s[0] || o[1] != s[1] || o[2] != s[2])
|
||||
continue;
|
||||
while(s[3 + m]) {
|
||||
if(s[3 + m] == '2') i |= (1 << 5); /* mode: short */
|
||||
else if(s[3 + m] == 'r') i |= (1 << 6); /* mode: return */
|
||||
else return 0; /* failed to match */
|
||||
if(s[3 + m] == '2')
|
||||
i |= (1 << 5); /* mode: short */
|
||||
else if(s[3 + m] == 'r')
|
||||
i |= (1 << 6); /* mode: return */
|
||||
else
|
||||
return 0; /* failed to match */
|
||||
m++;
|
||||
}
|
||||
return i;
|
||||
|
|
|
@ -424,16 +424,16 @@ datetime_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
|
|||
Uint8 *m = u->ram.dat;
|
||||
time_t seconds = time(NULL);
|
||||
struct tm *t = localtime(&seconds);
|
||||
m[ptr + 0] = (t->tm_year & 0xff00) >> 8;
|
||||
m[ptr + 1] = t->tm_year & 0xff;
|
||||
m[ptr + 2] = t->tm_mon;
|
||||
m[ptr + 3] = t->tm_mday;
|
||||
m[ptr + 4] = t->tm_hour;
|
||||
m[ptr + 5] = t->tm_min;
|
||||
m[ptr + 6] = t->tm_sec;
|
||||
m[ptr + 7] = t->tm_wday;
|
||||
m[ptr + 8] = (t->tm_yday & 0x100) >> 8;
|
||||
m[ptr + 9] = t->tm_yday && 0xff;
|
||||
m[ptr + 0] = (t->tm_year & 0xff00) >> 8;
|
||||
m[ptr + 1] = t->tm_year & 0xff;
|
||||
m[ptr + 2] = t->tm_mon;
|
||||
m[ptr + 3] = t->tm_mday;
|
||||
m[ptr + 4] = t->tm_hour;
|
||||
m[ptr + 5] = t->tm_min;
|
||||
m[ptr + 6] = t->tm_sec;
|
||||
m[ptr + 7] = t->tm_wday;
|
||||
m[ptr + 8] = (t->tm_yday & 0x100) >> 8;
|
||||
m[ptr + 9] = t->tm_yday && 0xff;
|
||||
m[ptr + 10] = t->tm_isdst;
|
||||
return b1;
|
||||
}
|
||||
|
|
16
src/uxn.c
16
src/uxn.c
|
@ -19,20 +19,22 @@ WITH REGARD TO THIS SOFTWARE.
|
|||
void setflag(Uint8 *a, char flag, int b) { if(b) *a |= flag; else *a &= (~flag); }
|
||||
int getflag(Uint8 *a, char flag) { return *a & flag; }
|
||||
Uint8 devpoke8(Uxn *u, Uint8 id, Uint8 b0, Uint8 b1){ return id < u->devices ? u->dev[id].poke(u, PAGE_DEVICE + id * 0x10, b0, b1) : b1; }
|
||||
void mempoke8(Uxn *u, Uint16 a, Uint8 b) { u->ram.dat[a] = (a & 0xff00) == PAGE_DEVICE ? devpoke8(u, (a & 0xff) >> 4, a & 0xf, b) : b; }
|
||||
Uint8 mempeek8(Uxn *u, Uint16 a) { return u->ram.dat[a]; }
|
||||
void mempoke16(Uxn *u, Uint16 a, Uint16 b) { mempoke8(u, a, b >> 8); mempoke8(u, a + 1, b); }
|
||||
Uint16 mempeek16(Uxn *u, Uint16 a) { return (mempeek8(u, a) << 8) + mempeek8(u, a + 1); }
|
||||
|
||||
void push8(Stack *s, Uint8 a) { if (s->ptr == 0xff) { s->error = 2; return; } s->dat[s->ptr++] = a; }
|
||||
Uint8 pop8(Stack *s) { if (s->ptr == 0) { s->error = 1; return 0; } return s->dat[--s->ptr]; }
|
||||
Uint8 peek8(Stack *s, Uint8 a) { if (s->ptr < a + 1) s->error = 1; return s->dat[s->ptr - a - 1]; }
|
||||
void mempoke8(Uxn *u, Uint16 a, Uint8 b) { u->ram.dat[a] = (a & 0xff00) == PAGE_DEVICE ? devpoke8(u, (a & 0xff) >> 4, a & 0xf, b) : b; }
|
||||
Uint8 mempeek8(Uxn *u, Uint16 a) { return u->ram.dat[a]; }
|
||||
|
||||
void push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); }
|
||||
Uint16 pop16(Stack *s) { return pop8(s) + (pop8(s) << 8); }
|
||||
Uint16 peek16(Stack *s, Uint8 a) { return peek8(s, a * 2) + (peek8(s, a * 2 + 1) << 8); }
|
||||
void mempoke16(Uxn *u, Uint16 a, Uint16 b) { mempoke8(u, a, b >> 8); mempoke8(u, a + 1, b); }
|
||||
Uint16 mempeek16(Uxn *u, Uint16 a) { return (mempeek8(u, a) << 8) + mempeek8(u, a + 1); }
|
||||
/* Stack */
|
||||
void op_brk(Uxn *u) { setflag(&u->status, FLAG_HALT, 1); }
|
||||
void op_lit(Uxn *u) { u->literal += 1; }
|
||||
void op_nop(Uxn *u) { (void)u; }
|
||||
void op_lit(Uxn *u) { u->literal += 1; }
|
||||
void op_pop(Uxn *u) { pop8(u->src); }
|
||||
void op_dup(Uxn *u) { push8(u->src, peek8(u->src, 0)); }
|
||||
void op_swp(Uxn *u) { Uint8 b = pop8(u->src), a = pop8(u->src); push8(u->src, b); push8(u->src, a); }
|
||||
|
@ -62,7 +64,7 @@ void op_div(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b
|
|||
void op_and(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b & a); }
|
||||
void op_ora(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b | a); }
|
||||
void op_eor(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b ^ a); }
|
||||
void op_sft(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); Uint8 left = (a & 0xf0) >> 4; Uint8 right = (a & 0x0f); push8(u->src, b >> (right % 8) << (left % 8)); }
|
||||
void op_sft(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b >> ((a & 0x0f) % 8) << (((a & 0xf0) >> 4) % 8)); }
|
||||
/* Stack */
|
||||
void op_lit16(Uxn *u) { u->literal += 2; }
|
||||
void op_nop16(Uxn *u) { printf("%04x\n", pop16(u->src)); }
|
||||
|
@ -95,7 +97,7 @@ void op_div16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->s
|
|||
void op_and16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b & a); }
|
||||
void op_ora16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b | a); }
|
||||
void op_eor16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b ^ a); }
|
||||
void op_sft16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); Uint8 left = (a & 0x00f0) >> 4; Uint8 right = (a & 0x000f); push16(u->src, b >> (right % 16) << (left % 16)); }
|
||||
void op_sft16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b >> ((a & 0x000f) % 16) << (((a & 0x00f0) >> 4) % 16)); }
|
||||
|
||||
void (*ops[])(Uxn *u) = {
|
||||
op_brk, op_nop, op_lit, op_pop, op_dup, op_swp, op_ovr, op_rot,
|
||||
|
|
Loading…
Reference in New Issue