Fixed .gitignore, removed old files

This commit is contained in:
codinget 2018-06-29 11:08:29 +02:00
parent a8cd111908
commit 04628c9415
21 changed files with 15 additions and 1428 deletions

15
.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
# object files
*.o
*/*.o
*/*/*.o
CASIO_fxlib/asm.bin
CASIO_fxlib/asm.elf
# executable files
interpreter/casio_asm_interpreter
assembler/casio_asm_assembler
CASIO_fxlib/asm.g1a
# copied sources
CASIO_fxlib/*.h
CASIO_fxlib/*.c

Binary file not shown.

Binary file not shown.

269
old/asm.c
View File

@ -1,269 +0,0 @@
#include "asm.h"
//BEGIN Internal functions prototypes
void decodeOpcode(asm_t *state, opcode_t *opcode, opcode_data_t *data);
void execute(asm_t *state, opcode_data_t *instruction, opcode_t *raw);
//END Internal functions prototypes
int run(asm_t *state, int cycles) {
int i=0;
state->status|=ASM_RUNNING;
for(; i<cycles; i++) {
if(state->status&ASM_RUNNING) tick(state);
else break;
}
return i;
}
int tick(asm_t *state) {
opcode_t opcode;
opcode_data_t data;
//read opcode and increment pc
state->registers[0].i+=readOpcode(state->rom, state->registers[0].i, state->romSize, &opcode);
//decode opcode
decodeOpcode(state, &opcode, &data);
//execute instruction
execute(state, &data, &opcode);
}
void initAsm(asm_t *state) {
state->stack.top=0;
for(int i=0; i<256; i++) {
state->stack.elements[i].i=0;
state->registers[i].i=0;
}
state->status=0;
}
//BEGIN Internal functions
//BEGIN opcode reading functions
void readOpcodeData(asm_t *state, opcode_t *opcode, opcode_data_t *data, int args, int type) {
if(!args) return;
if(opcode->nArgs==0) {
//no arguments in opcode, pop everything from stack
popDouble(&state->stack, &(data->arg0.d));
if(args==2) popDouble(&state->stack, &(data->arg1.d));
} else if(opcode->nArgs==1) {
//one argument in opcode, get it from registers
data->arg0=state->registers[opcode->arg0_1];
if(args==2) popDouble(&state->stack, &(data->arg1.d));
} else if(opcode->nArgs==2) {
//two arguments in opcode, get them from registers
data->arg0=state->registers[opcode->arg0_2];
if(args==2) data->arg1=state->registers[opcode->arg1_2];
} else { //opcode->nArgs==3
//immediate argument in opcode
if(!type) {
//we requested an int, it is directly readable
data->arg0.i=opcode->immediate;
} else {
//we requested a double, it must be decoded
data->arg0.d=(double) ((opcode->immediate>>4)&0x7ff);
data->arg0.d*=(2>>((opcode->immediate&0xf)-7));
if((opcode->immediate)>>15) data->arg0.d*=-1;
// smmmmmmm mmmmeeee
// immediate=(-1)^(s+1)*m*2^(e-7)
}
if(args==2) popDouble(&state->stack, &(data->arg1.d));
}
}
void decodeOpcode(asm_t *state, opcode_t *opcode, opcode_data_t *data) {
data->op=opcode->op;
data->nArgs=opcode->nArgs;
//read arguments for opcode
//TODO use a switch instead to handle this
if((data->op>=OP_add_i && data->op<OP_neg_i)
|| (data->op>=OP_pow_i && data->op<OP_not)
|| (data->op>=OP_or_l && data->op<OP_not_l)
|| (data->op>=OP_jnz_i && data->op<=OP_jind)) {
//op takes two int arguments
readOpcodeData(state, opcode, data, 2, 0);
} else if((data->op>=OP_add_d && data->op<OP_neg_d)
|| (data->op==OP_pow_d || data->op==OP_rt_d)
|| (data->op==OP_atan2)) {
//op takes two double arguments
readOpcodeData(state, opcode, data, 2, 1);
} else if((data->op==OP_neg_i)
|| (data->op==OP_not)
|| (data->op==OP_not_l)
|| (data->op==OP_high)
|| (data->op==OP_push)
|| (data->op==OP_const)
|| (data->op==OP_jmp)
|| (data->op==OP_call)
|| (data->op==OP_ext)
|| (data->op==OP_int)) {
//op takes one int argument
readOpcodeData(state, opcode, data, 1, 0);
} else if((data->op==OP_neg_d)
|| (data->op>=OP_sin && data->op<OP_atan2)
|| (data->op==OP_dup)) {
//op takes one double argument
readOpcodeData(state, opcode, data, 1, 1);
} else if((data->op>=OP_store && data->op<OP_rea_i)) {
//store and write instructions
readOpcodeData(state, opcode, data, 2, 0);
} else if((data->op==OP_rea_i || data->op==OP_rea_d)) {
//read instructions
readOpcodeData(state, opcode, data, 1, 0);
} else if((data->op==OP_i2d)) {
//i2d
readOpcodeData(state, opcode, data, 1, 0);
} else if((data->op==OP_d2i)) {
//d2i
readOpcodeData(state, opcode, data, 1, 1);
}
}
//END opcode reading functions
//BEGIN memory access functions
void readMemoryInt(asm_t *state, int address, int *value) {
int val;
if(address<0) return;
if(address<=0xffff) {
if(address+4<state->romSize) {
val=state->rom[address]<<24;
val|=state->rom[address+1]<<16;
val|=state->rom[address+2]<<8;
val|=state->rom[address+3];
*value=val;
}
} else {
address-=0x10000;
if(address+4<state->ramSize) {
val=state->ram[address]<<24;
val|=state->ram[address+1]<<16;
val|=state->ram[address+2]<<8;
val|=state->ram[address+3];
*value=val;
}
}
}
void writeMemoryInt(asm_t *state, int address, int value) {
if(address<=0xffff) return;
address-=0x10000;
if(address+4<state->ramSize) {
state->ram[address]=(char) value>>24;
state->ram[address+1]=(char) value>>16;
state->ram[address+2]=(char) value>>8;
state->ram[address+3]=(char) value;
}
}
//END memory access functions
//BEGIN execution functions
void execute(asm_t *state, opcode_data_t *instruction, opcode_t *raw) {
stack_element_t temp0, temp1;
debug("Opcode: 0x%x, nArgs: %d, PC: 0x%x, stack: %d\n", instruction->op, instruction->nArgs, state->registers[0].i, state->stack.top);
switch(instruction->op) {
case OP_nop:
break;
case OP_halt:
state->status=0;
break;
//BEGIN arithmetic operations
case OP_add_i:
pushInt(&state->stack, instruction->arg0.i+instruction->arg1.i);
break;
case OP_sub_i:
pushInt(&state->stack, instruction->arg0.i-instruction->arg1.i);
break;
case OP_mod_i:
pushInt(&state->stack, instruction->arg0.i%instruction->arg1.i);
break;
case OP_mul_i:
pushInt(&state->stack, instruction->arg0.i*instruction->arg1.i);
break;
case OP_div_i:
pushInt(&state->stack, instruction->arg0.i/instruction->arg1.i);
break;
case OP_neg_i:
pushInt(&state->stack, -instruction->arg0.i);
break;
/*case OP_pow_i:
pushInt(&state->stack, (int) pow((double) instruction->arg0.i, (double) instruction->arg1.i));
break;*/
case OP_add_d:
pushDouble(&state->stack, instruction->arg0.d+instruction->arg1.d);
break;
case OP_sub_d:
pushDouble(&state->stack, instruction->arg0.d-instruction->arg1.d);
break;
case OP_mul_d:
pushDouble(&state->stack, instruction->arg0.d*instruction->arg1.d);
break;
case OP_div_d:
pushDouble(&state->stack, instruction->arg0.d/instruction->arg1.d);
break;
case OP_neg_d:
pushDouble(&state->stack, -instruction->arg0.d);
break;
//END arithmetic operations
//BEGIN bitwise operations
case OP_shlt:
pushInt(&state->stack, instruction->arg0.i<<instruction->arg1.i);
break;
case OP_shrt:
pushInt(&state->stack, instruction->arg0.i>>instruction->arg1.i);
break;
//END bitwise operations
//BEGIN data manipulation operations
case OP_store:
state->registers[raw->arg0_1]=instruction->arg1;
break;
case OP_push:
if(instruction->nArgs==3) {
pushInt(&state->stack, raw->immediate);
} else {
readOpcodeData(state, raw, instruction, 1, 1);
pushDouble(&state->stack, instruction->arg0.d);
}
break;
case OP_high:
pushInt(&state->stack, instruction->arg0.i<<16);
break;
case OP_swap:
popDouble(&state->stack, &temp0.d);
popDouble(&state->stack, &temp1.d);
pushDouble(&state->stack, temp0.d);
pushDouble(&state->stack, temp1.d);
break;
case OP_dup:
pushDouble(&state->stack, instruction->arg0.d);
pushDouble(&state->stack, instruction->arg0.d);
break;
case OP_i2d:
pushDouble(&state->stack, (double) instruction->arg0.i);
break;
case OP_d2i:
pushInt(&state->stack, (int) instruction->arg0.d);
break;
//END data manipulation operations
//BEGIN flow control operations
case OP_jmp:
state->registers[0].i=instruction->arg0.i%65536;
break;
case OP_jle_i:
popInt(&state->stack, &temp0.i);
if(instruction->arg1.i<=temp0.i) state->registers[0].i=instruction->arg0.i%65536;
break;
case OP_jlt_i:
popInt(&state->stack, &temp0.i);
if(instruction->arg1.i<temp0.i) state->registers[0].i=instruction->arg0.i%65536;
break;
//END flow control operations
}
}
//END execution functions
//END Internal functions

View File

@ -1,49 +0,0 @@
#ifndef asm_defined
#define asm_defined
//#include <math.h>
#include "opcode.h"
#include "stack.h"
#include "debug.h"
typedef struct asm_t {
//the stack for this processor
stack_t stack;
//the registers for this processor
stack_element_t registers[256];
//this processor's rom, can't be written
char* rom;
int romSize;
//this processor's ram, can be written but not executed
char* ram;
int ramSize;
//this status
int status;
} asm_t;
typedef struct opcode_data_t {
unsigned nArgs:2;
unsigned op:6;
stack_element_t arg0;
stack_element_t arg1;
} opcode_data_t;
int tick(asm_t *state);
int run(asm_t *state, int cycles);
void initAsm(asm_t *state);
//BEGIN status defines
#define ASM_RUNNING 0x01
//END status defines
#endif

View File

@ -1,12 +0,0 @@
//#define DO_DEBUG
#ifdef DO_DEBUG
#include <stdio.h>
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) do {} while(0)
#endif

View File

@ -1,153 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include "stack.h"
#include "asm.h"
#include "debug.h"
void printState(asm_t *state);
void pushOperation(char* rom, int *pos, opcode_t *opcode);
void writeProgram(asm_t *state);
int main(int argc, char** argv) {
asm_t state;
char ram[65536];
char rom[65536];
state.ramSize=65536;
state.romSize=65536;
state.ram=ram;
state.rom=rom;
initAsm(&state);
writeProgram(&state);
run(&state, 1000);
printState(&state);
}
void printState(asm_t *state) {
printf("--asm state--\n");
printf("PC: 0x%x; romSize: %d\n", state->registers[0].i, state->romSize);
printf("IntHandler: 0x%x\n", state->registers[1].i);
printf("Stack size: %d\n", state->stack.top);
for(int i=0; i<state->stack.top; i++) {
printf("\tStack element %d: %d or %lf\n", i, state->stack.elements[i].i, state->stack.elements[i].d);
}
printf("Registers:\n");
for(int i=2; i<256; i++) {
if(state->registers[i].i==0) continue;
printf("\tRegister %d: %d or %lf\n", i, state->registers[i].i, state->registers[i].d);
}
printf("--end of asm state--\n");
}
void pushOperation(char* rom, int *pos, opcode_t *opcode) {
debug("Adding opcode %d with %d arguments at offset 0x%x\n", opcode->op, opcode->nArgs, *pos);
rom[*pos]=opcode->byte0;
(*pos)++;
if(opcode->nArgs>0) {
rom[*pos]=opcode->byte1;
(*pos)++;
if(opcode->nArgs>1) {
rom[*pos]=opcode->byte2;
(*pos)++;
}
}
}
void writeProgram(asm_t *state) {
int pos=0;
opcode_t opcode;
//push 0i
opcode.nArgs=3;
opcode.op=OP_push;
opcode.immediate=0;
pushOperation(state->rom, &pos, &opcode);
//store #2
opcode.nArgs=1;
opcode.op=OP_store;
opcode.arg0_1=2;
pushOperation(state->rom, &pos, &opcode);
//push 1i
opcode.nArgs=3;
opcode.op=OP_push;
opcode.immediate=1;
pushOperation(state->rom, &pos, &opcode);
//store #3
opcode.nArgs=1;
opcode.op=OP_store;
opcode.arg0_1=3;
pushOperation(state->rom, &pos, &opcode);
//.loop:
int loop=pos;
//add_i #2 #3
opcode.nArgs=2;
opcode.op=OP_add_i;
opcode.arg0_2=2;
opcode.arg1_2=3;
pushOperation(state->rom, &pos, &opcode);
//store #2
opcode.nArgs=1;
opcode.op=OP_store;
opcode.arg0_1=2;
pushOperation(state->rom, &pos, &opcode);
//add_i #2 #3
opcode.nArgs=2;
opcode.op=OP_add_i;
opcode.arg0_2=2;
opcode.arg1_2=3;
pushOperation(state->rom, &pos, &opcode);
//store #3
opcode.nArgs=1;
opcode.op=OP_store;
opcode.arg0_1=3;
pushOperation(state->rom, &pos, &opcode);
//high 0x1000i
opcode.nArgs=3;
opcode.op=OP_high;
opcode.immediate=0x1000;
pushOperation(state->rom, &pos, &opcode);
//push #3
opcode.nArgs=1;
opcode.op=OP_push;
opcode.arg0_1=3;
pushOperation(state->rom, &pos, &opcode);
//jle_i loop
opcode.nArgs=3;
opcode.op=OP_jle_i;
opcode.immediate=loop;
pushOperation(state->rom, &pos, &opcode);
//i2d #2
opcode.nArgs=1;
opcode.op=OP_i2d;
opcode.arg0_1=2;
pushOperation(state->rom, &pos, &opcode);
//i2d #3
opcode.nArgs=1;
opcode.op=OP_i2d;
opcode.arg0_1=3;
pushOperation(state->rom, &pos, &opcode);
//div_d
opcode.nArgs=0;
opcode.op=OP_div_d;
pushOperation(state->rom, &pos, &opcode);
//halt
opcode.nArgs=0;
opcode.op=OP_halt;
pushOperation(state->rom, &pos, &opcode);
}

View File

@ -1,18 +0,0 @@
#include "opcode.h"
//reads an opcode
int readOpcode(char* data, int pos, int max, opcode_t *opcode) {
if(pos>=max||pos<0) return -1;
opcode->byte0=data[pos];
if(opcode->nArgs) { //if we have arguments, read them
if(pos+1>=max) return -1;
opcode->byte1=data[pos+1];
if(opcode->nArgs-1) { //we either have 2 args or an immediate value
if(pos+2>=max) return -1;
opcode->byte2=data[pos+2];
return 3;
}
return 2;
}
return 1;
}

View File

@ -1,129 +0,0 @@
#ifndef opcode_defined
#define opcode_defined
typedef union opcode_t {
//raw 24bit data
unsigned data:24;
//common data
struct {
unsigned nArgs:2;
unsigned op:6;
};
//single-arg, 16bit argument
struct {
unsigned:8;
unsigned arg0_1:8;
};
//bi-arg, 8bit arguments
struct {
unsigned:8;
unsigned arg0_2:8;
unsigned arg1_2:8;
};
//immediate value
struct {
unsigned:8;
signed int immediate:16;
};
//byte by byte data
struct {
char byte0:8;
char byte1:8;
char byte2:8;
};
} opcode_t;
int readOpcode(char* data, int pos, int max, opcode_t *opcode);
//BEGIN opcode constants
#define OP_nop 0b000000
//BEGIN int arithmetic
#define OP_add_i 0b000001
#define OP_sub_i 0b000010
#define OP_mod_i 0b000011
#define OP_mul_i 0b000100
#define OP_div_i 0b000101
#define OP_neg_i 0b000110
#define OP_pow_i 0b000111
//END int arithmetic
//BEGIN bit manipulation
#define OP_shlt 0b001000
#define OP_shrt 0b001001
#define OP_or 0b001010
#define OP_and 0b001011
#define OP_xor 0b001100
#define OP_not 0b001101
//END bit manipulation
//BEGIN logic manipulation
#define OP_or_l 0b001110
#define OP_and_l 0b001111
#define OP_xor_l 0b010000
#define OP_not_l 0b010001
//END logic manipulation
//BEGIN double arithmetic
#define OP_add_d 0b010010
#define OP_sub_d 0b010011
#define OP_mul_d 0b010100
#define OP_div_d 0b010101
#define OP_neg_d 0b010110
#define OP_pow_d 0b010111
#define OP_rt_d 0b011000
//END double arithmetic
//BEGIN trig functions
#define OP_sin 0b011001
#define OP_cos 0b011010
#define OP_atan 0b011011
#define OP_atan2 0b011100
//END trig functions
//BEGIN stack manipulation
#define OP_dup 0b011101
#define OP_swap 0b011110
#define OP_pop 0b011111
#define OP_high 0b100000
#define OP_push 0b100001
#define OP_const 0b100010
//END stack manipulation
//BEGIN flow control
#define OP_jmp 0b100011
#define OP_call 0b100100
#define OP_jnz_i 0b100101
#define OP_jnz_d 0b100110
#define OP_jz_i 0b100111
#define OP_jz_d 0b101000
#define OP_jlt_i 0b101001
#define OP_jlt_d 0b101010
#define OP_jle_i 0b101011
#define OP_jle_d 0b101100
#define OP_jind 0b101101
//END flow control
//BEGIN data manipulation
#define OP_store 0b101110
#define OP_wri_i 0b101111
#define OP_wri_d 0b110000
#define OP_rea_i 0b110001
#define OP_rea_d 0b110010
#define OP_i2d 0b110011
#define OP_d2i 0b110100
//END data manipulation
#define OP_halt 0b110101
#define OP_int 0b110110
#define OP_ext 0b110111
//END opcode constants
#endif

View File

View File

@ -1,42 +0,0 @@
//the platform we're on
#define WINDOWS
#define LINUX
#define CASIO
//figure out whether or not we're on PC
#ifdef WINDOWS
#define PC
#endif
#ifdef LINUX
#define PC
#endif
//set 4byte types according to platform
#ifdef PC
typedef float decimal;
typedef signed int integral;
#else
typedef float decimal;
typedef signed int integral;
#endif
//functions to manage files
int openFile(char* filename, int mode);
int readFile(int handle, char* buffer, int length, int pos);
int writeFile(int handle, char* buffer, int length, int pos);
int lengthFile(int handle);
#ifdef CASIO
//a way to remember open files on casio
typedef struct file_info_t {
int handle;
int mode;
char name[256];
} file_info_t;
#endif
//file open flags
#define FILE_read
#define FILE_write
#define FILE_create
#define FILE_truncate

View File

@ -1,27 +0,0 @@
#include "stack.h"
//pushes an int onto the stack
int pushInt(stack_t *stack, int value) {
if(!ensure(stack)) return -1;
stack->elements[stack->top].i=value;
return (stack->top)++;
}
//pushes a double onto the stack
int pushDouble(stack_t *stack, double value) {
if(!ensure(stack)) return -1;
stack->elements[stack->top].d=value;
return (stack->top)++;
}
//pops an int from the stack
int popInt(stack_t *stack, int *value) {
if(empty(stack)) return -1;
*value=stack->elements[stack->top-1].i;
return --stack->top;
}
//pops a double from the stack
int popDouble(stack_t *stack, double *value) {
if(empty(stack)) return -1;
*value=stack->elements[stack->top-1].d;
return --stack->top;
}

View File

@ -1,23 +0,0 @@
#ifndef stack_defined
#define stack_defined
typedef union stack_element_t {
int i;
double d;
} stack_element_t;
typedef struct stack_t {
int top;
stack_element_t elements[256];
} stack_t;
int pushInt(stack_t *stack, int value);
int pushDouble(stack_t *stack, double value);
int popInt(stack_t *stack, int *value);
int popDouble(stack_t *stack, double *value);
#define ensure(stack) (stack->top<255)
#define empty(stack) (!stack->top)
#endif

View File

@ -1,352 +0,0 @@
' this program counts how many times
' the user pressed EXE key and moves
' the display with the arrow keys
' first, clean the variables we will use
' y coordinate
push,30
store,#17
' x coordinate
push,60
store,#16
' number
push,0
store,#15
' second, setup the interrupt handler and
' subscribe to the keyboard events
inth,.inth
sub,b1
' fall through
' now, wait, everything is in the event handler
.wait
halt
jmp,.wait
' function to draw what we want
.draw
' set the values
push,#17
push,#16
push,#15
store,#5
store,#6
store,#7
' clear screen
ext,x0c
' draw counter
call,.decdraw
' print vram
ext,x01
' return
jmp
' interrupt handler
.inth
' protect the interrupt handler
unsub,b1
' check event type
store,#10
' check if hardware
high,x4000
and,#10
jnt,.abort
' check if it's a keydown
high,x4000
xor,#10
eq_i,x1
jif,.keydown
' if it's not, then pop the data and exit
pop
jmp,.inthl
' keydown event handler
.keydown
store,#11
' check if it's EXE
push,31
eq_i,#11
jnt,.keydown2
' yes, increment, exit the inth and print
push,1
add_i,#15
store,#15
jmp,.inthl
' no, check for the arrow keys
.keydown2
' increment #16 if right
push,27
eq_i,#11
add_i,#16
store,#16
' decrement #16 if left
push,38
eq_i,#11
sub_i,#16
store,#16
' increment #17 if down
push,37
eq_i,#11
add_i,#17
store,#17
' decrement #17 if up
push,28
eq_i,#11
sub_i,#17
store,#17
' exit the handler
' fall through
' leaves the interrupt handler and redraws
.inthl
push,.draw
push,b0
sub,b1
stat_s,x2
' if that doesn't work, abort
' fall through
' kills the program
.abort
' set the abort flag
push,b1
stat_s,x3
' remove interrupt handler and halt
' the program won't probably go here
inth,-1
halt
' subroutine to draw dec number on screen
' #5 input number
' #6 x coordinate
' #7 y coordinate
' #8 temp
.decdraw
push,#5
store,#8
.decdraw2
' divide temp by 8
push,10
div_i,#8
dup
store,#8
' if it is null, stop
jnt,.decdraw3
' else, add 4 to the x coordinate
push,4
add_i,#6
store,#6
' continue the loop
jmp,.decdraw2
.decdraw3
' get digit
push,10
mod_i,#5
'draw digit to screen
store,#8
call,.decdigit
' add 4 to the y coordinate
push,4
sub_i,#6
store,#6
' get next digit
push,10
div_i,#5
' draw next digit
dup
store,#5
jif,.decdraw3
'return
jmp
' subroutine to draw a dec digit on screen
' #8 input digit
' #6 x coordinate
' #7 y coordinate
.decdigit
' draw C if the number isn't 2
push,2
neq_i,#8
cif,.dispC
' draw A if the number isn't 1 or 4
push,1
neq_i,#8
push,4
neq_i,#8
and_l
cif,.dispA
' draw B if the number isn't 5 or 6
push,5
neq_i,#8
push,6
neq_i,#8
and_l
cif,.dispB
' draw D if the number isn't 1, 4 or 7
push,1
neq_i,#8
push,4
neq_i,#8
push,7
neq_i,#8
and_l
and_l
cif,.dispD
' draw G if the number isn't 0, 1 or 7
push,0
neq_i,#8
push,1
neq_i,#8
push,7
neq_i,#8
and_l
and_l
cif,.dispG
' draw F if the number isn't 1, 2, 3 or 7
push,1
neq_i,#8
push,2
neq_i,#8
push,3
neq_i,#8
push,7
neq_i,#8
and_l
and_l
and_l
cif,.dispF
' draw E if the number is 0, 2, 6 or 8
push,0
eq_i,#8
push,2
eq_i,#8
push,6
eq_i,#8
push,8
eq_i,#8
or_l
or_l
or_l
cif,.dispE
'return
jmp
' subroutine to draw the A part of a segment
.dispA
' color COLOR_BLACK
push,1
' x2=x+2
push,2
add_i,#6
' x1=x
push,#6
' y=y
push,#7
' lineH
ext,x07
' return
jmp
' subroutine to draw the B part of a segment
.dispB
' color COLOR_BLACK
push,1
' y2=y+2
push,2
add_i,#7
' y1=y
push,#7
' x=x+2
push,2
add_i,#6
' lineV
ext,x08
' return
jmp
' subroutine to draw the C part of a segment
.dispC
' color COLOR_BLACK
push,1
' y2=y+4
push,4
add_i,#7
' y1=y+2
push,2
add_i,#7
' x=x+2
push,2
add_i,#6
' lineV
ext,x08
' return
jmp
' subroutine to draw the D part of a segment
.dispD
' color COLOR_BLACK
push,1
' x2=x+2
push,2
add_i,#6
' x1=x
push,#6
' y=y+4
push,4
add_i,#7
' lineH
ext,x07
' return
jmp
' subroutine to draw the E part of a segment
.dispE
' color COLOR_BLACK
push,1
' y2=y+4
push,4
add_i,#7
' y1=y+2
push,2
add_i,#7
' x=x
push,#6
' lineV
ext,x08
' return
jmp
' subroutine to draw the F part of a segment
.dispF
' color COLOR_BLACK
push,1
' y2=y+2
push,2
add_i,#7
' y1=y
push,#7
' x=x
push,#6
' lineV
ext,x08
' return
jmp
' subroutine to draw the G part of a segment
.dispG
' color COLOR_BLACK
push,1
' x2=x+2
push,2
add_i,#6
' x1=x
push,#6
' y=y+2
push,2
add_i,#7
' lineH
ext,x07
' return
jmp

Binary file not shown.

View File

@ -1,322 +0,0 @@
' store 1 in registers 2 and 3
dup,1
store,#2
store,#3
' store the max value in register 4
high,x100
store,#4
.loop
' add registers 2 and 3 twice
add_i,#2,#3
store,#2
add_i,#2,#3
store,#3
' print #2 and #3 to screen
call,.print
' loop if we're not at the max
lt_i,#3,#4
jif,.loop
' wait until we EXIT
inth,.inth
sub,x1
.wait
halt
jmp,.wait
' interrupt handler
.inth
' disable all interrupts temporarily
unsub,x1
' get interrupt number
store,#10
' check if it is hardware
high,x4000
and,#10
' if it isn't, abort (it is an error)
jnt,.abort
' check if the interrupt is a keydown
push,x1
and,#10
jif,.keydown
' pop the key code and continue execution
pop
jmp,.cont
.keydown
' check the key code
eq_i,47
' if it is 47 (EXIT), abort the program
jif,.abort
' if it isn't, continue execution
.cont
' remove interrupt flag and subscribe to interrupt again
push,b0
sub,x1
stat_s,x2
' if it didn't work, abort
jmp,.abort
' kills the program
.abort
' set the abort flag
push,b1
stat_s,x3
' remove interrupt handler and halt
inth,-1
halt
' prints #2 and #3 to screen
.print
' clear VRAM
ext,x0c
' draw #2 at 0,0
dup,0
store,#6
store,#7
push,#2
store,#5
call,.decdraw
' draw #3 at 0,6
push,0
store,#6
push,6
store,#7
push,#3
store,#5
call,.decdraw
' print the VRAM
ext,x01
' return
jmp
' subroutine to draw dec number on screen
' #5 input number
' #6 x coordinate
' #7 y coordinate
' #8 temp
.decdraw
push,#5
store,#8
.decdraw2
' divide temp by 8
push,10
div_i,#8
dup
store,#8
' if it is null, stop
jnt,.decdraw3
' else, add 4 to the x coordinate
push,4
add_i,#6
store,#6
' continue the loop
jmp,.decdraw2
.decdraw3
' get digit
push,10
mod_i,#5
'draw digit to screen
store,#8
call,.decdigit
' add 4 to the y coordinate
push,4
sub_i,#6
store,#6
' get next digit
push,10
div_i,#5
' draw next digit
dup
store,#5
jif,.decdraw3
'return
jmp
' subroutine to draw a dec digit on screen
' #8 input digit
' #6 x coordinate
' #7 y coordinate
.decdigit
' draw C if the number isn't 2
push,2
neq_i,#8
cif,.dispC
' draw A if the number isn't 1 or 4
push,1
neq_i,#8
push,4
neq_i,#8
and_l
cif,.dispA
' draw B if the number isn't 5 or 6
push,5
neq_i,#8
push,6
neq_i,#8
and_l
cif,.dispB
' draw D if the number isn't 1, 4 or 7
push,1
neq_i,#8
push,4
neq_i,#8
push,7
neq_i,#8
and_l
and_l
cif,.dispD
' draw G if the number isn't 0, 1 or 7
push,0
neq_i,#8
push,1
neq_i,#8
push,7
neq_i,#8
and_l
and_l
cif,.dispG
' draw F if the number isn't 1, 2, 3 or 7
push,1
neq_i,#8
push,2
neq_i,#8
push,3
neq_i,#8
push,7
neq_i,#8
and_l
and_l
and_l
cif,.dispF
' draw E if the number is 0, 2, 6 or 8
push,0
eq_i,#8
push,2
eq_i,#8
push,6
eq_i,#8
push,8
eq_i,#8
or_l
or_l
or_l
cif,.dispE
'return
jmp
' subroutine to draw the A part of a segment
.dispA
' color COLOR_BLACK
push,1
' x2=x+2
push,2
add_i,#6
' x1=x
push,#6
' y=y
push,#7
' lineH
ext,x07
' return
jmp
' subroutine to draw the B part of a segment
.dispB
' color COLOR_BLACK
push,1
' y2=y+2
push,2
add_i,#7
' y1=y
push,#7
' x=x+2
push,2
add_i,#6
' lineV
ext,x08
' return
jmp
' subroutine to draw the C part of a segment
.dispC
' color COLOR_BLACK
push,1
' y2=y+4
push,4
add_i,#7
' y1=y+2
push,2
add_i,#7
' x=x+2
push,2
add_i,#6
' lineV
ext,x08
' return
jmp
' subroutine to draw the D part of a segment
.dispD
' color COLOR_BLACK
push,1
' x2=x+2
push,2
add_i,#6
' x1=x
push,#6
' y=y+4
push,4
add_i,#7
' lineH
ext,x07
' return
jmp
' subroutine to draw the E part of a segment
.dispE
' color COLOR_BLACK
push,1
' y2=y+4
push,4
add_i,#7
' y1=y+2
push,2
add_i,#7
' x=x
push,#6
' lineV
ext,x08
' return
jmp
' subroutine to draw the F part of a segment
.dispF
' color COLOR_BLACK
push,1
' y2=y+2
push,2
add_i,#7
' y1=y
push,#7
' x=x
push,#6
' lineV
ext,x08
' return
jmp
' subroutine to draw the G part of a segment
.dispG
' color COLOR_BLACK
push,1
' x2=x+2
push,2
add_i,#6
' x1=x
push,#6
' y=y+2
push,2
add_i,#7
' lineH
ext,x07
' return
jmp

Binary file not shown.

View File

@ -1,29 +0,0 @@
#include <stdlib.h>
#include <SDL2/SDL.h>
#define WINDOW_WIDTH 600
int main(void) {
SDL_Event event;
SDL_Renderer *renderer;
SDL_Window *window;
int i;
SDL_Init(SDL_INIT_VIDEO);
SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_WIDTH, 0, &window, &renderer);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
for (i = 0; i < WINDOW_WIDTH; ++i)
SDL_RenderDrawPoint(renderer, i, i);
SDL_RenderPresent(renderer);
while (1) {
if (SDL_PollEvent(&event) && event.type == SDL_QUIT)
break;
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return EXIT_SUCCESS;
}

Binary file not shown.

View File

@ -1,3 +0,0 @@
#!/bin/bash
gcc -o 'sdl.out' 'sdl.c' -lSDL2
./sdl.out

Binary file not shown.