Project: Added the tool to convert from stl to source code data although it's almost emberassingly badly written.Made the size of the model for the 3d renderer variable and added the Utah teapot stl file and made rendering it the default program

This commit is contained in:
(Tim) Efthimis Kritikos 2024-03-02 23:26:35 +00:00
parent 2d28146e3f
commit 031f0d75bf
8 changed files with 66311 additions and 168 deletions

4
.gitignore vendored
View File

@ -3,3 +3,7 @@ first
*.rom
make.deps
callgrind.out
programs/cube.asm
programs/utah_teapot.asm
auxiliary_progs/stl_to_source_code

View File

@ -5,8 +5,10 @@ USE_AALIB=1
all:first
OBJECT_FILES=gui.o gui_display.o main.o simdata.o assembly.o cpu.o
MAIN_ROM=programs/3d_renderer.rom
ROMS=test.rom ${MAIN_ROM}
MAIN_ROM=programs/utah_teapot.rom
ROMS=test.rom ${MAIN_ROM} programs/cube.rom
UTAH_TEAPOT_ASCII_STL=assets/Utah_teapot_ascii.stl
AXIL_PROGS=auxiliary_progs/stl_to_source_code
make.deps: $(subst .o,.c,${OBJECT_FILES}) $(wildcard *.h)
@$(CC) -MM $(subst .o,.c,${OBJECT_FILES}) > make.deps
@ -20,6 +22,8 @@ ifeq "${QUIET}" "1"
QUIET_FAS = @echo ' FAS '$@;
QUIET_CLEAN = @echo ' CLEAN .';
QUIET_VALGRIND = @echo ' VALGRIND '$@;
QUIET_STL_CONV = @echo ' STL_TO_SOURCE_CODE '$@;
Q = @
else
Q =
@ -50,6 +54,20 @@ gprof:
$(QUIET_FAS)
${Q}./first -i $< -a $@
auxiliary_progs/%:auxiliary_progs/%.c
${QUIET_CC}
${Q}gcc $< -DUSE_AALIB=${USE_AALIB} -Wall -Wextra -Werror -O2 -o $@
programs/utah_teapot.asm: auxiliary_progs/stl_to_source_code ${UTAH_TEAPOT_ASCII_STL} programs/3d_renderer.asm
${QUIET_STL_CONV}
${Q}cat programs/3d_renderer.asm >> "$@_"
${Q}auxiliary_progs/stl_to_source_code < "${UTAH_TEAPOT_ASCII_STL}" >> "$@_"
${Q}mv "$@_" "$@"
programs/cube.asm: programs/cube_data.asm programs/3d_renderer.asm
${Q}cat programs/3d_renderer.asm programs/cube_data.asm > "$@"
%.o:%.c
${QUIET_CC}
${Q}gcc -c $< -DUSE_AALIB=${USE_AALIB} -Wall -Wextra -Werror ${CFLAGS}
@ -61,7 +79,7 @@ callgrind.out:first ${MAIN_ROM}
rm -f "$@";\
echo ERROR: Binary build with libasan, please rebuild without address sanitiser;\
else\
valgrind --tool=callgrind --dump-instr=yes --simulate-cache=yes --collect-jumps=yes --callgrind-out-file=callgrind.out ./first -i programs/3d_renderer.rom;\
valgrind --tool=callgrind --dump-instr=yes --simulate-cache=yes --collect-jumps=yes --callgrind-out-file=callgrind.out ./first -i programs/utah_teapot.rom;\
fi
@ -71,4 +89,4 @@ profile: callgrind.out
.PHONY: clean
clean:
${QUIET_CLEAN}
${Q} rm -f ${OBJECT_FILES} first ${ROMS} callgrind.out
${Q} rm -f ${OBJECT_FILES} first ${ROMS} callgrind.out programs/cube.asm programs/utah_teapot.asm ${AXIL_PROGS}

View File

@ -1,2 +1,4 @@
First - A simple computer architecture simulator for COMS30046
Note, assets/Utah\_teapot\_ascii.stl is a model created by zzubnik and converted to ascii stl by vancha's binarty to ascii stl tool https://github.com/vancha/Binary-stl-to-ascii-stl

View File

@ -723,7 +723,7 @@ int64_t assemble_line(char *line, struct assembler_context_t *assembler_context)
}else{
temp=imm->value;
free(imm);
return (temp&0xFF000000)>>24|(temp&0x00FF0000)>>8|(temp&0x0000FF00)<<8|(temp&0x000000FF>>24);
return ((temp&0xFF000000)>>24)|((temp&0x00FF0000)>>8)|((temp&0x0000FF00)<<8)|((temp&0x000000FF)<<24);
}
}else
return -2;

66068
assets/Utah_teapot_ascii.stl Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
//TODO:
//Don't hard code the size of the model!!!
//Detect binary stl
//Do automaitic scaling
//FIX THE HORRIBLE PARSING
//do the float to u32 in software
#define LINE_SIZE 500
//#define SCALE 2
//#define YOFFSET 1
#define SCALE 5
#define YOFFSET 1
union U32FLOAT_RETURN{
float f;
uint32_t u;
};
int main(){
union U32FLOAT_RETURN x,y,z, x0,y0,z0;
int point=1;
char *line=malloc(LINE_SIZE);
printf("DDW $0x00006E9A\n");
while(fgets(line,LINE_SIZE,stdin)!= NULL){
if(strncmp(line," vertex",14)==0){
if(sscanf(line+14,"%f %f %f\n",&x.f,&z.f,&y.f)==3){
x.f/=SCALE;
y.f/=SCALE;
z.f/=SCALE;
y.f=-y.f;
y.f+=YOFFSET;
if(point==3){
printf("DDW $0x%08x\nDDW $0x%08x\nDDW $0x%08x\n",x0.u,y0.u,z0.u);
point=1;
}else if(point==1){
x0.f=x.f,y0.f=y.f,z0.f=z.f;
point++;
}else{
point++;
}
printf("DDW $0x%08x\nDDW $0x%08x\nDDW $0x%08x\n",x.u,y.u,z.u);
}else
break;
}
}
}

View File

@ -19,14 +19,17 @@ JMP,NZ $MAIN_LOOP
HALT
:SPIN
MOV $>DATA_START,%R0l
MOV $<DATA_START,%R0h
MOV $0x001A,%R7l
MOV $0x0000,%R7h #The number of points (x2 lines)
MOV $0x0004,%R5l
MOV $0x0000,%R5h #Constant 4
MOV $0x0008,%R2l
MOV $0x0000,%R2h #Constant 8
MOV $0x0004,%R5l
MOV $0x0000,%R5h #Constant 4
MOV $>DATA_START,%R0l
MOV $<DATA_START,%R0h
MOV (%R0),%R7
ADD %R5,%R0 #Load the number of lines
SL %R7 # x2 to get the number of points
MOV $0x3ccc,%R6h
MOV $0xcccd,%R6l #The angle to rotate by
:SPIN_LOOP
@ -72,10 +75,14 @@ MOV $0x00FF,%R4h
MOV $0x0002,%R1l
MOV $0x0000,%R1h #Clear the frame
MOV %R1,(%R4)
MOV $0x3f80,%R6h
MOV $0x0000,%R6l
MOV (%R0),%R7
ADD %R5,%R0
MOV $0xFFFC,%R4l
MOV $0x00FF,%R4h
MOV $0x3f80,%R6h
MOV $0x0000,%R6l
:RENDER_LOOP
MOV $0xFFFF,%R1l
@ -126,158 +133,4 @@ MOV %R1,(%R4)
RET
:DATA_START
#0,0,0
DDW $0xbf800000
DDW $0xbf800000
DDW $0xbf800000
#0,0,1
DDW $0xbf800000
DDW $0xbf800000
DDW $0x3f800000
#0,0,0
DDW $0xbf800000
DDW $0xbf800000
DDW $0xbf800000
#1,0,0
DDW $0x3f800000
DDW $0xbf800000
DDW $0xbf800000
#0,0,0
DDW $0xbf800000
DDW $0xbf800000
DDW $0xbf800000
#0,1,0
DDW $0xbf800000
DDW $0x3f800000
DDW $0xbf800000
#1,1,1
DDW $0x3f800000
DDW $0x3f800000
DDW $0x3f800000
#1,1,0
DDW $0x3f800000
DDW $0x3f800000
DDW $0xbf800000
#1,1,1
DDW $0x3f800000
DDW $0x3f800000
DDW $0x3f800000
#1,0,1
DDW $0x3f800000
DDW $0xbf800000
DDW $0x3f800000
#1,1,1
DDW $0x3f800000
DDW $0x3f800000
DDW $0x3f800000
#0,1,1
DDW $0xbf800000
DDW $0x3f800000
DDW $0x3f800000
#0,1,1
DDW $0xbf800000
DDW $0x3f800000
DDW $0x3f800000
#0,1,0
DDW $0xbf800000
DDW $0x3f800000
DDW $0xbf800000
#0,1,1
DDW $0xbf800000
DDW $0x3f800000
DDW $0x3f800000
#0,0,1
DDW $0xbf800000
DDW $0xbf800000
DDW $0x3f800000
#0,1,0
DDW $0xbf800000
DDW $0x3f800000
DDW $0xbf800000
#1,1,0
DDW $0x3f800000
DDW $0x3f800000
DDW $0xbf800000
#0,1,0
DDW $0xbf800000
DDW $0x3f800000
DDW $0xbf800000
#1,1,0
DDW $0x3f800000
DDW $0x3f800000
DDW $0xbf800000
#0,0,1
DDW $0xbf800000
DDW $0xbf800000
DDW $0x3f800000
#1,0,1
DDW $0x3f800000
DDW $0xbf800000
DDW $0x3f800000
#1,0,0
DDW $0x3f800000
DDW $0xbf800000
DDW $0xbf800000
#1,1,0
DDW $0x3f800000
DDW $0x3f800000
DDW $0xbf800000
#1,0,0
DDW $0x3f800000
DDW $0xbf800000
DDW $0xbf800000
#1,0,1
DDW $0x3f800000
DDW $0xbf800000
DDW $0x3f800000

144
programs/cube_data.asm Normal file
View File

@ -0,0 +1,144 @@
# 12 lines
DDW $0x0000000C
#0,0,0
DDW $0xbf800000
DDW $0xbf800000
DDW $0xbf800000
#0,0,1
DDW $0xbf800000
DDW $0xbf800000
DDW $0x3f800000
#0,0,0
DDW $0xbf800000
DDW $0xbf800000
DDW $0xbf800000
#1,0,0
DDW $0x3f800000
DDW $0xbf800000
DDW $0xbf800000
#0,0,0
DDW $0xbf800000
DDW $0xbf800000
DDW $0xbf800000
#0,1,0
DDW $0xbf800000
DDW $0x3f800000
DDW $0xbf800000
#1,1,1
DDW $0x3f800000
DDW $0x3f800000
DDW $0x3f800000
#1,1,0
DDW $0x3f800000
DDW $0x3f800000
DDW $0xbf800000
#1,1,1
DDW $0x3f800000
DDW $0x3f800000
DDW $0x3f800000
#1,0,1
DDW $0x3f800000
DDW $0xbf800000
DDW $0x3f800000
#1,1,1
DDW $0x3f800000
DDW $0x3f800000
DDW $0x3f800000
#0,1,1
DDW $0xbf800000
DDW $0x3f800000
DDW $0x3f800000
#0,1,1
DDW $0xbf800000
DDW $0x3f800000
DDW $0x3f800000
#0,1,0
DDW $0xbf800000
DDW $0x3f800000
DDW $0xbf800000
#0,1,1
DDW $0xbf800000
DDW $0x3f800000
DDW $0x3f800000
#0,0,1
DDW $0xbf800000
DDW $0xbf800000
DDW $0x3f800000
#0,1,0
DDW $0xbf800000
DDW $0x3f800000
DDW $0xbf800000
#1,1,0
DDW $0x3f800000
DDW $0x3f800000
DDW $0xbf800000
#0,0,1
DDW $0xbf800000
DDW $0xbf800000
DDW $0x3f800000
#1,0,1
DDW $0x3f800000
DDW $0xbf800000
DDW $0x3f800000
#1,0,0
DDW $0x3f800000
DDW $0xbf800000
DDW $0xbf800000
#1,1,0
DDW $0x3f800000
DDW $0x3f800000
DDW $0xbf800000
#1,0,0
DDW $0x3f800000
DDW $0xbf800000
DDW $0xbf800000
#1,0,1
DDW $0x3f800000
DDW $0xbf800000
DDW $0x3f800000