kully / vlahb Goto Github PK
View Code? Open in Web Editor NEWA Virtual Machine written in C and an Assembler written in Python.
A Virtual Machine written in C and an Assembler written in Python.
Would be great to automate the GIF -> file.asm
or JPEG -> file.asm
process
We could give a function a link to a raw file online, rather than downloading it.
for both ASM and LANG:
Ideas:
Consider this script
LD R[0] 45
LD R[1] 41
CALL FOO
MAIN:
LD R[0] 7
LD R[1] 4
CALL MATH_SUB
// what should be in R[0],R[1] right now?
RETURN
MATH_SUB:
SUB R[0] R[1]
LD R[4100] R[0]
RETURN
The current way VLAHB is written, 7 and 4 will be the values of R[0] and R[1] after the RETURN
in MATH_SUB
. This is an issue as I want to be able to remember and retrieve easily the very first init values I load in RAM without having them lost somewhere in RAM (specifically between indices 0-4095).
ie
CLEAR
appears slower than manually updating all VRAM slots
LD R[4096] 4100
LD R[4097] 23300
LD R[U:V] 0X000000FF
@glouw thoughts?
See util.py
for all of the custom codes. Maybe we want to change the behaviour so that no error messages appear and instead lines of "incorrect" code just don't run and are skipped.
relevant to #65
Reserve some 1024 slots after RAM to be designated for a heap.
If we call
malloc(8)
in LANG, it should give 8 free consecutive slots from the heap
increase the stack frame from 16 to 128 (make a PR)
write fibo.asm
add opcodes and asm commands for <=, <, >, >=
Assembler should exit if assembly goes past stack size
make some test.asm
files to test that opcodes work as expected
improve the debug printing in terminal - multiple options for output style for fun
make code in asm more DRY - ๐ (don't repeat yourself)
add ASCII codes for VLAHB
make all ASM hexadecimal compatible
eg LD R[4] 0XFF0000FFFF
and ADD R[0X0F] 42
should work fine
Brainstorming
Just label and data:
MARIO:
00043232
08373919
...
LD VRAM[0] MARIO
a way of giving width, x and y
LD VRAM X Y MARIO WIDTH
(just use VRAM_INDEX_FROM_X_Y
or build X,Y straight into program)
optimize, optimize, optimize
notes:
-screen size affects fps
-printing debug messages affects fps
Would be amazing to have opcodes for moving bits into SRAM (Sound Ram?). Could emulate video game music. Perhaps better for a separate project but putting this idea here to remember.
Opt to raise errors rather than bypass incorrect ASM code.
This is causing problems with #38 as the Program Counter is pointing to the wrong place when trying to load sprites into VRAM.
Since the max index of RAM I can reference in an opcode is 0XFFFF
, which is 65,535 in base10, the RAM
and ROM
arrays should not have more slots than this.
See these lines in vm.c
I don't think it's best to have floats stay floats if they can be represented as ints.
black pixel -> white pixel
white pixel -> black pixel
LD R[0]
SUB R[0] 1
ADD R[0] 1
EXIT
should exit with R[0] = 0
but this is not the case.
I noticed one of the debug print statements show a -1 in RAM, which should never happen.
LD R[4099] 1
MUL R[4099] 0XFFFFFFFF
this code should result in R[4099] being equal to 0XFFFFFFFF, but it wraps back to 0. Probably has to do with the new stack overflow underflow function.
Probably out of the scope of this project, but putting down if anybody feels inspired to contribute to this project and add.
Biggest Potential: be able to code games! ๐ธ
Eg. In regexes, use (...)
to extract out the pattern rather than doing something like:
if R[0], set to arg[2:-1]
lets go:
lang.py
asm.py
bin.py <---- currently here
vm.py
Create a grid of nXn pixels such that each color at [x, y] represents the value at a particular slot in RAM. Could be a useful tool for debugging. (Pygame?)
Would be useful for a debugger to have an easy way to control the speed of the CPU
eg. x0.5 speed
, x0.25 speed
Video RAM
VRAM
is a list (array)
len of VRAM
: 800 X 600
Each slot in VRAM
is 4 bytes: the 4 bytes together are ARGB (alpha, red, green, blue)
Index VRAM like this: VRAM[x + y * 800]
Syntax:
# i == integer
V[i] i,i,i,i # direct load to VRAM
V[i] R[i],R[i],R[i],R[i] # load RAM slots into VRAM slot
V[i] V[i] # load VRAM slot into VRAM
probably makes sense to rename the extensions of VLAHB assembly files (eg. .vasm)
The standard sublime 3 .asm syntax works great so far. What's needed is...
0XFFFF
values are same color as int
sLABELS:
LD
, ADD
, SUB
, GOTO
, CALL
, etc;
as the symbol for comments -> eventually replace //
with ;
for the comment symbolOther suggestions?
Surprisingly this doesn't exist. Add it.
For example, we currently have
PC: 2
ROM lines:
0001000c
0000003b
CMP RAM[1] to 59
...True
RAM[0]: 0
RAM[1]: 59
RAM[2]: 0
RAM[3]: 0
RAM[4]: 0
is printed. We want CMP RAM[1] to 59
to be
CMP RAM[1] 59
as this is the actual assembly code.
Does something similar to python3 vm.py -O
work? This didn't work for me.
leave this till the end ๐ค
We should not be seeing a -ve number in the print statements of ROM[k]
but I am seeing them
opcode_lookup_dict
in util.py
so they easily convey meaning of opcode**EXIT
**Can we make LD REGISTERS TO VRAM W VRAM INDEX
make more sense to a new user? ๐
If GOTO 0
is in your file, your PC is gonna shoot to the top of the huge mega giant hex
file that contains all of the hex files code.
Should we even care about this? Should everything be wrapped in labels anyways?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.