This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LeDark Lua's profile picture

Chiper - A Virtual Machine/Emulator

Started by LeDark Lua, 29 March 2017 - 12:32 PM
LeDark Lua #1
Posted 29 March 2017 - 02:32 PM
Chiper

What is Chiper?
  • Chiper is a emulator/virtual machine made by me.
  • It's like Chip-8
What does the Chiper do?
  • It runs bytecode and executes instructions like a CPU ( Central Processing Unit )
Why should I use it?
  • If you are not interested, fine, but its a great tool to learn Assembly and fight the limitations that it comes with! Also its fun :P/>
Does it come with an Assembler?
  • Yes
Can I create a Programming Language for Chiper?
  • Yes, its easier to target an Assembly language than Lua, C++, Java, Etc
Can I create Games?
  • You can create whatever you can with it :D/>
I'm interested, where can I get it?
Versions
  • Version 1 here: pastebin get cR1ZuRX0 chiper
  • Original release
  • Version 2 here: pastebin get rQC0drnX chiper
  • Assembler errors more readable
  • Version 3 here: pastebin get aP1SN7gh chiper
  • Bug fixes for Assembly Compiler
  • Version 4 here: pastebin get 5zS3FUk8 chiper
  • Added INTerupts! Check Assembly Tutorial Section!
  • Version 5 here: pastebin get BYKVszJj chiper
  • Added DB arguments! Check Assembly Tutorial Section!
  • Version 6 here: pastebin get 54aZVDpG chiper
  • Now you can store data! Check Assembly Tutorial Section!
  • Added few helpful thingies!
  • Version 7 here: pastebing get gE6AmbRG chiper
  • Added bitwise operators! Check Assembly Tutorial Section!
  • Added INC and DEC operator! Check Assembly Tutorial Section!
I can't test it, it has no programs :angry:/>
  • Yes you can! Don't be angry :P/> : pastebin get QaLQDVgd print.asm
How do I use Chiper?
  • chiper <ROM> -This will run the ROM
  • chiper <ASM file> <OUT file> -This will run the compiler for the ASM file and OUTputs a ROM
Assembly TutorialNumbers can be: Hexadecimal ( $FF ) or Numeric ( #255 )
Label can be: Strings ( .text db "Test" ), Pointers ( .loop jmp loop ), Numbers: ( .number db $FF )
Strings And Numbers in labels return a pointer in memory!
To create data in memory do:
.name db "String"
or
.name db $FF
You can have arguments in DB's:
.player db $0, $F, $2,

hlt ; halts the program
ret ; returns from subroutine
call I ; jumps to a memory location at I and waits for RET
call <number/label> ; jumps to a memory location and waits for RET
jmp <number/label> ;jumps to a memory location
ld A, <number> ;loads a number to register A
ld B, <number> ;loads a number to register B
ld (I), A ;stores whatever is in register A
ld A, (I) ; loads from memory location I to register A
ld (I), B ;stores whatever is in register B
ld B, (I) ; loads from memory location I to register B
ld I, <number/label> ;sets register I to number or labeled memory location ( pointer )
ld X, <number/label> ;sets register X to number or labeled memory location ( pointer )
ld X, I ; sets register I to X
ld I, X ; sets register X to I
ld (I), <number> ; stores a value to memory location I

inc A ; increase register A value by one
inc B ; increase register B value by one
inc I ; increase register I value by one
inc X ; increase register X value by one
dec A ; decrease register A value by one
dec B ; decrease register B value by one
dec I ; decrease register I value by one
dec X ; decrease register X value by one

add A, <number> ; adds register A with a number
add A, B ; adds register A with register B
add B, <number> ; adds register B with a number
add B, A ; adds register B with register A
add I, <number> ; adds register I with a number
add I, A ; adds register I with register A
add I, B ; adds register I with register B
add X, <number> ; adds register X with a number
add X, A ; adds register X with register A
add X, B ; adds register X with register B
; there is sub ( subtract ), mul ( multiply ) but you cant subtract or multiply register I
eql A, <number> ; checks if A is equal to a number value, if false skip next instruction
eql B, <number> ; checks if B is equal to a number value, if false skip next instruction
eql A, B ; checks if A is equal to B and if false skip next instruction
meq A, <number> ; checks if A is more or equal to a number value, if false skip next instruction
meq B, <number> ; checks if B is more or equal to a number value, if false skip next instruction
meq A, B ; checks if A is more or equal to B and if false skip next instruction
leq A, <number> ; checks if A is less or equal to a number value, if false skip next instruction
leq B, <number> ; checks if B is less or equal to a number value, if false skip next instruction
leq A, B ; checks if A is less or equal to B and if false skip next instruction
mor A, <number> ; checks if A is more than a number value, if false skip next instruction
mor B, <number> ; checks if B is more than a number value, if false skip next instruction
mor A, B ; checks if A is more than B and if false skip next instruction
les A, <number> ; checks if A is less than a number value, if false skip next instruction
les B, <number> ; checks if B is less than a number value, if false skip next instruction
les A, B ; checks if A is less than B and if false skip next instruction

; bitwise operators <to be included!>
shl A ; shifts register A value by one to the left
shl B ; shifts register B value by one to the left
shr A ; shifts register A value by one to the right
shr B ; shifts register B value by one to the right

or A, <number> ; does bitwise or operation on register A
or B, <number> ; does bitwise or operation on register B
or A, B ; does bitwise or operation on register A with register B
or B, A ; does bitwise or operation on register B with register A
xor A, <number> ; does bitwise xor operation on register A
xor B, <number> ; does bitwise xor operation on register B
xor A, B ; does bitwise xor operation on register A with register B
xor B, A ; does bitwise xor operation on register B with register A
and A, <number> ; does bitwise and operation on register A
and B, <number> ; does bitwise and operation on register B
and A, B ; does bitwise and operation on register A with register B
and B, A ; does bitwise and operation on register B with register A

int A, <number/label> ; INT takes register A as timer, if A value will hit 0, PC will be set to <number/label>
int B, <number/label> ; INT takes register B as timer, if B value will hit 0, PC will be set to <number/label>
int A, I ; INT takes register A as timer, if A value will hit 0, PC will be set to Register I
int B, I ; INT takes register A as timer, if B value will hit 0, PC will be set to Register I

EXAMPLE:

call refreshScreen ; refreshScreen

.loop

; do stuff

jmp loop

.refreshScreen
ld I, $FFF
ld (I), #1  ; refresh it
ld A, $3A	; load immediate value of HEX 3A into register A
int A, refreshScreen   ; set interupt to call refreshScreen every 58 ( or hex value of 3A ) CPU cycles
ret  ; return from int/call

there are locations in memory that are being updated by the "hardware" or can be updated by the user:
  1. Key location: $FF9
  2. Text Color Location: $FFD ( write from $0 to $F )
  3. Background Color Location: $FFC ( write from $0 to $F )
  4. Char Location: $FFE ( write from $0 to $FF )
  5. Update Location: $FFF
  6. Screen X Pos: $FFA
  7. Screen Y Pos: $FFB
  8. Data Transfer Location: $FF8
Key Values:
  • No Key: $0
  • Up Arrow: $1
  • Down Arrow: $2
  • Left Arrow: $3
  • Right Arrow: $4
  • Key Z: $5
  • Key X: $6
  • Numpad8: $7
  • Numpad5: $8
  • Numpad4: $9
  • Numpad6: $A
  • Key ',' comma: $B
  • Key '.' dot: $C
How to use: $FFF
  • 1 - Updates the Screen
  • 2 - Reads current Pixel to its locations: Background Color( $FFC ), Text Color( $FFD ), Char( $FFE )
  • 3 - Writes Data Register to Disk
  • 4 - Read From Disk to Data Register Location( $FF8 )
NOTE: Disk will only save after program termination or halt!

Storing Values EXAMPLE

; set X register to Location in the Disk
ld X, $FFF

; write a value to Disk Register
ld I, $FF8
ld (I), $FF

;store it
ld I, $FFF
ld (I), $3

hlt

If you made a cool program, post it here, share with everybody so that we can try it :P/>
I hope you guys will make some awesome stuff, of course, if you're interested ;)/>

~LeDark Lua
Edited on 13 April 2017 - 01:07 PM
supernicejohn #2
Posted 30 March 2017 - 10:43 AM
!dlrow ,olleH
Nice work! I'll see if I can't make something fun, been wanting to try some assembly type stuff for a while.
The drawing part will be a challenge…
LeDark Lua #3
Posted 30 March 2017 - 01:05 PM
New version available!

The drawing part will be a challenge…
THANKS! And yeah, but where's the fun without any challenges, right? :P/>

And I have another program for you guys! Moving pixel: pastebin get XKfu5hRe movpix.asm
To move the pixel: Left Arrow, Right Arrow, Up Arrow, Down Arrow
Edited on 30 March 2017 - 11:10 AM
LeDark Lua #4
Posted 31 March 2017 - 11:30 AM
New version available! Fixed some bugs!
LeDark Lua #5
Posted 31 March 2017 - 11:40 PM
New version available! Added Interupts! Check Assembly Tutorial Section!
LeDark Lua #6
Posted 04 April 2017 - 01:12 PM
New version available! Added DB arguments! Check Assembly Tutorial Section!
This may be my last update… Now I'll work on some programs for Chiper and then something awesome ;)/>

And come on guys, give me some reviews!

Thanks in advance,

~LeDark Lua
Edited on 04 April 2017 - 11:16 AM
LeDark Lua #7
Posted 08 April 2017 - 02:15 PM
New Program! Screen Saver Thingy? Try it! pastebin get MDju6xmw scrsvr.asm
LeDark Lua #8
Posted 09 April 2017 - 10:07 PM
New Version is HERE! Added:
  • Savable/Readable disk!
  • Read current pixel status!
Check Assembly Tutorial Section!
LeDark Lua #9
Posted 13 April 2017 - 01:48 PM
New version available! Added bitwise operators and INC/DEC operators! Check Assembly Tutorial Section!
Midnightas #10
Posted 15 May 2017 - 11:45 PM
I really want to create a programming language that compiles to this, but I need an *ahem* less vague explanation?
Not trying to be rude, not sure if there's a better way to phrase it.
I need to ask a couple of Qs, are you aight with that?
LeDark Lua #11
Posted 20 May 2017 - 03:25 PM
Sorry for a late reply. Write 'em to me ( PM ) I will answer all your questions.