F1DE
F1DE is 0x10c DCPU 1.7 Compliant -   [Editor]   [Dcpu]   [0x10c]   [About]
Project vty97n : New 3D Demo

; Example project - 3D Hi-resolution drawing. ; ; To run, Click Assemble, then Run ; ; Link to this : http://fasm.elasticbeanstalk.com/?proj=vty97n ; ; This uses the high resolution library, via a cross-project include. ; See the High Resolution Library project for more details here: ; ; http://fasm.elasticbeanstalk.com/?proj=l47t4r ; org 0x000 set pc, start include "l47t4r:hires.dasm" include "maths.dasm" :start jsr setup_hw jsr setup_hires :cloop jsr draw_cobra add [rot_angles_x], 4 and [rot_angles_x], 0x0ff add [rot_angles_z], 3 and [rot_angles_z], 0x0ff jsr swap_screens jmp_ cloop
include "ships.dasm" :draw_cobra set i, cobra_mk3 jsr transform_points ; The points are now transformed into x,y pairs in tr_result ; ; Iterate over each facet and decide if we should draw it.. ; We use the convention that a facet facing us has it's points in ; a counter-clockwise orientation ; Sum over the edges, (x2-x1)(y2+y1). If the result is positive ; curve is clockwise, if it's negative the curve is counter-clockwise. ; (The result is twice the enclosed area, with a +/- convention.) ; ;point[0] = (5,0) edge[0]: (6-5)(4+0) = 4 ;point[1] = (6,4) edge[1]: (4-6)(5+4) = -18 ;point[2] = (4,5) edge[2]: (1-4)(5+5) = -30 ;point[3] = (1,5) edge[3]: (1-1)(0+5) = 0 ;point[4] = (1,0) edge[4]: (5-1)(0+0) = 0 ; --- ; -44 counter-clockwise set [dc_facet_flags], 0 set z, cobra_facets ; Z is index into facet data set c, -1 ; C is facet count :dc_facet_loop add c, 1 set i, [z] ; First point in facet is -1 at end... ife i, -1 ret_ set y, 0 ; Y is our total set x, z ; X is first point for later use.. ; Sum over the edges :dc_check_loop add z, 1 ife [z], -1 jmp_ dc_checked_facet add z, 1 shl i, 1 add i, tr_result-1 ; i points at x1, y1 set j, [z] ; Z is next point shl j, 1 add j, tr_result ; j points at x2, y2 sti a, [j] sub a, [i] ; x2 - x1 sti b, [j] add b, [i] ; y2 + y1 mli a, b ; OVERFLOW??? add y, a ; total = (x2-x1) *(y2+y1) set i, [z] jmp_ dc_check_loop :dc_checked_facet add z, 1 ; z points to next facet ifa y, -1 jmp_ dc_facet_loop ; If total < 0, draw facet, otherwise loop ; ; Should draw this facet. ; X points to first point in facet.. ; c is facet count.. set i, x ; Now i = first point in facet sti a, [i] ; A = p1 index :dc_line_loop sti b, [i] ife b, -1 ; B is index of shared facet jmp_ dc_facet_done set x, 1 shl x, b ; X has bit flag for previous facet set b, a sti a, [i] ifb [dc_facet_flags], x ; If it's set, the line has already been drawn jmp_ dc_line_loop ; as part of the previous shared facet ; Now a - p2 index ; b - p1 index ; i -> next bit flag ; c - facet count ; We must preserve i, a, c shl b, 1 ; Retrieve the points from the transformed x, y pairs add b, tr_result set x, [b] set y, [b+1] set push, a shl a, 1 add a, tr_result set b, [a+1] set a, [a] set push, c set push, i jsr draw_line set i, pop set c, pop set a, pop jmp_ dc_line_loop :dc_facet_done set z, i ; Z points to next facet ; Remember to mark that we've drawn this facet set a, 1 shl a, c bor [dc_facet_flags], a jmp_ dc_facet_loop :dc_facet_flags dat 0 ; ; Transform a list of 3d co-ordinates by rotating around the origin and ; then flattening to 2D space. ; ; i = start of 3d co-ordinate triples ; ; [point_count] = number of points ; [rot_angles_x/y/z] = angle of rotation ; ; Transformed points end up in tr_result.... ; :transform_points sti a, [i] set [tr_count], a set [tr_dest], tr_result :transform_loop sti x, [i] sti y, [i] sti z, [i] shl x, 8 shl y, 8 shl z, 8 ; Rotation around X axis ; ry = cos(angle_x) * by - sin(angle_x) * bz ; rz = sin(angle_x) * by + cos(angle_x) * bz set a, [rot_angles_x] add a, cos_table set j, [a] mli j, y ; 8.6 bits in ex set j, ex sub a, 64 ; Convert cos to sin set b, [a] mli b, z sub j, ex ; j = ry set b, [a] mli b, y set b, ex ; sin(x) * by add a, 64 set c, [a] mli c, z add b, ex ; + cos(x) * bz set y, j ; y -> ry NOTE 8.8 bits -> 8.6 set z, b ; z -> rz shl y, 2 shl z, 2 ; Rotation around the Y-axis: ; rx = cos(angle_y) * bx + sin(angle_y) * rz ; rrz = -sin(angle_y) * bx + cos(angle_y) * rz set a, [rot_angles_y] add a, cos_table set j, [a] mli j, x set j, ex ; cos(y) * bx sub a, 64 ; Cos to sin set b, [a] mli b, z add j, ex ; j = rx set b, [a] mli b, x set b, ex ; sin(y) * bx add a, 64 ; Sin to cos set c, [a] mli c, z set z, ex ; cos(y) * rz sub z, b ; z = rrz set x, j ; x = rx shl x, 2 ; Rotation around the Z-axis: ; rrx = cos(angle_z) * rx - sin(angle_z) * ry ; rry = sin(angle_z) * rx + cos(angle_z) * ry set a, [rot_angles_z] add a, cos_table set j, [a] mli j, x set j, ex ; cos(z) * rx sub a, 64 ; Cos to sin set b, [a] mli b, y sub j, ex ; j = rrx set b, [a] mli b, x set b, ex ; sin(z) * rx add a, 64 set c, [a] mli c, y set y, ex add y, b ; y = rry set x, j ; x = rrx ; ; Now we have x, y, z rotated.. ; Precision is now 8.6 bits ; ; Perspective calc ; SX = DIST * X / (DIST + Z) - X is actually multiplied by 64, but we'll treat DIST as 256 ; asr z, 6 add z, 200 shl x, 2 shl y, 2 dvi x, z dvi y, z asr x, 2 asr y, 2 add x, 64 ; Shift origin to middle of screen add y, 48 set a, [tr_dest] set [a], x add a, 1 set [a], y add [tr_dest], 2 sub [tr_count], 1 ifn [tr_count], 0 jmp_ transform_loop ret_ :rot_angles_x dat 0 ; X :rot_angles_y dat 0 ; Y :rot_angles_z dat 0 ; Z :tr_count dat 0 :tr_dest dat 0 :tr_result reserve 64 ; 32 points max :sin_table dat 0x0000, 0x0192, 0x0323, 0x04b5, 0x0645, 0x07d5, 0x0964, 0x0af1 dat 0x0c7c, 0x0e05, 0x0f8c, 0x1111, 0x1294, 0x1413, 0x158f, 0x1708 dat 0x187d, 0x19ef, 0x1b5d, 0x1cc6, 0x1e2b, 0x1f8b, 0x20e7, 0x223d dat 0x238e, 0x24da, 0x261f, 0x275f, 0x2899, 0x29cd, 0x2afa, 0x2c21 dat 0x2d41, 0x2e5a, 0x2f6b, 0x3076, 0x3179, 0x3274, 0x3367, 0x3453 dat 0x3536, 0x3612, 0x36e5, 0x37af, 0x3871, 0x392a, 0x39da, 0x3a82 dat 0x3b20, 0x3bb6, 0x3c42, 0x3cc5, 0x3d3e, 0x3dae, 0x3e14, 0x3e71 dat 0x3ec5, 0x3f0e, 0x3f4e, 0x3f84, 0x3fb1, 0x3fd3, 0x3fec, 0x3ffb :cos_table dat 0x4000, 0x3ffb, 0x3fec, 0x3fd3, 0x3fb1, 0x3f84, 0x3f4e, 0x3f0e dat 0x3ec5, 0x3e71, 0x3e14, 0x3dae, 0x3d3e, 0x3cc5, 0x3c42, 0x3bb6 dat 0x3b20, 0x3a82, 0x39da, 0x392a, 0x3871, 0x37af, 0x36e5, 0x3612 dat 0x3536, 0x3453, 0x3367, 0x3274, 0x3179, 0x3076, 0x2f6b, 0x2e5a dat 0x2d41, 0x2c21, 0x2afa, 0x29cd, 0x2899, 0x275f, 0x261f, 0x24da dat 0x238e, 0x223d, 0x20e7, 0x1f8b, 0x1e2b, 0x1cc6, 0x1b5d, 0x19ef dat 0x187d, 0x1708, 0x158f, 0x1413, 0x1294, 0x1111, 0x0f8c, 0x0e05 dat 0x0c7c, 0x0af1, 0x0964, 0x07d5, 0x0645, 0x04b5, 0x0323, 0x0192 dat 0x0000, 0xfe6e, 0xfcdd, 0xfb4b, 0xf9bb, 0xf82b, 0xf69c, 0xf50f dat 0xf384, 0xf1fb, 0xf074, 0xeeef, 0xed6c, 0xebed, 0xea71, 0xe8f8 dat 0xe783, 0xe611, 0xe4a3, 0xe33a, 0xe1d5, 0xe075, 0xdf19, 0xddc3 dat 0xdc72, 0xdb26, 0xd9e1, 0xd8a1, 0xd767, 0xd633, 0xd506, 0xd3df dat 0xd2bf, 0xd1a6, 0xd095, 0xcf8a, 0xce87, 0xcd8c, 0xcc99, 0xcbad dat 0xcaca, 0xc9ee, 0xc91b, 0xc851, 0xc78f, 0xc6d6, 0xc626, 0xc57e dat 0xc4e0, 0xc44a, 0xc3be, 0xc33b, 0xc2c2, 0xc252, 0xc1ec, 0xc18f dat 0xc13b, 0xc0f2, 0xc0b2, 0xc07c, 0xc04f, 0xc02d, 0xc014, 0xc005 dat 0xc000, 0xc005, 0xc014, 0xc02d, 0xc04f, 0xc07c, 0xc0b2, 0xc0f2 dat 0xc13b, 0xc18f, 0xc1ec, 0xc252, 0xc2c2, 0xc33b, 0xc3be, 0xc44a dat 0xc4e0, 0xc57e, 0xc626, 0xc6d6, 0xc78f, 0xc851, 0xc91b, 0xc9ee dat 0xcaca, 0xcbad, 0xcc99, 0xcd8c, 0xce87, 0xcf8a, 0xd095, 0xd1a6 dat 0xd2bf, 0xd3df, 0xd506, 0xd633, 0xd767, 0xd8a1, 0xd9e1, 0xdb26 dat 0xdc72, 0xddc3, 0xdf19, 0xe075, 0xe1d5, 0xe33a, 0xe4a3, 0xe611 dat 0xe783, 0xe8f8, 0xea71, 0xebed, 0xed6c, 0xeeef, 0xf074, 0xf1fb dat 0xf384, 0xf50f, 0xf69c, 0xf82b, 0xf9bb, 0xfb4b, 0xfcdd, 0xfe6e dat 0x0000, 0x0192, 0x0323, 0x04b5, 0x0645, 0x07d5, 0x0964, 0x0af1 dat 0x0c7c, 0x0e05, 0x0f8c, 0x1111, 0x1294, 0x1413, 0x158f, 0x1708 dat 0x187d, 0x19ef, 0x1b5d, 0x1cc6, 0x1e2b, 0x1f8b, 0x20e7, 0x223d dat 0x238e, 0x24da, 0x261f, 0x275f, 0x2899, 0x29cd, 0x2afa, 0x2c21 dat 0x2d41, 0x2e5a, 0x2f6b, 0x3076, 0x3179, 0x3274, 0x3367, 0x3453 dat 0x3536, 0x3612, 0x36e5, 0x37af, 0x3871, 0x392a, 0x39da, 0x3a82 dat 0x3b20, 0x3bb6, 0x3c42, 0x3cc5, 0x3d3e, 0x3dae, 0x3e14, 0x3e71 dat 0x3ec5, 0x3f0e, 0x3f4e, 0x3f84, 0x3fb1, 0x3fd3, 0x3fec, 0x3ffb
; List of co-ordinate triplets ; :cobra_mk3 dat 26 ; Number of points dat 0,15,10 dat 80,5,-45 dat 25,-5,45 dat -25,-5,45 dat -80,5,-45 dat 0,15,-45 dat 95,-5,-25 dat -95,-5,-25 dat 95,-5,-45 dat -95,-5,-45 dat -25,-15,-45 dat 25,-15,-45 dat -60,-5,-45 dat -60,5,-45 dat -75,0,-45 dat 60,5,-45 dat 75,0,-45 dat 60,-5,-45 dat -5,5,-45 dat -5,-10,-45 dat -30,0,-45 dat -30,-5,-45 dat 5,5,-45 dat 5,-10,-45 dat 30,0,-45 dat 30,-5,-45 ; ; Facet consists of a series of points that are joined by a continuous line. ; Points are counter-clockwise when the facet is towards us. ; To complete the facet, the last point should be the same as the first, or ; the polyon will be open. ; ; For each edge (pair of points), we list the earliest facet (including this ; one) that shares the edge. This allows us to work out if an edge has already ; been drawn. ; ; Data is [point no., previous shared facet no.]... [first point., -1] ; Where point no. == index of point in point table ; previous facet no. == facet that shares the line from this point to following point ; -1 marks end of facet ; ; Note that the code currently requires shared facet indices to be 0-15 ; If the facet starts with -1, no more facets exist for the model. ; :cobra_facets dat 0, 0, 1, 0, 2, 0, 0, -1 dat 0, 1, 3, 1, 4, 1, 0, -1 dat 0, 2, 5, 2, 1, 0, 0, -1 dat 0, 1, 4, 3, 5, 2, 0, -1 dat 2, 0, 1, 4, 6, 4, 2, -1 dat 3, 5, 7, 5, 4, 1, 3, -1 dat 1, 6, 8, 6, 6, 4, 1, -1 dat 4, 5, 7, 7, 9, 7, 4, -1 dat 2, 8, 3, 1, 0, 0, 2, -1 dat 2, 9, 11, 9, 10, 9, 3, 8, 2, -1 dat 8, 10, 11, 9, 2, 10, 8, -1 dat 2, 4, 6, 6, 8, 10, 2, -1 dat 3, 12, 9, 7, 7, 5, 3, -1 dat 3, 9, 10, 13, 9, 12, 3, -1 dat 1, 2, 5, 3, 4, 7, 9, 13, 10, 9, 11, 10, 8, 6, 1, -1 dat 12, 15, 13, 15, 14, 15, 12, -1 dat 17, 16, 16, 16, 15, 16, 17, -1 dat 20, 17, 21, 17, 19, 17, 18, 17, 20, -1 dat 22, 18, 23, 18, 25, 18, 24, 18, 22, -1 dat -1
 
...
   
  • A
    0x0000

    []
    0x0000
  • B
    0x0000

    []
    0x0000
  • C
    0x0000

    []
    0x0000
  • X
    0x0000

    []
    0x0000
  • Y
    0x0000

    []
    0x0000
  • Z
    0x0000

    []
    0x0000
  • I
    0x0000

    []
    0x0000
  • J
    0x0000

    []
    0x0000
  • SP
    0x0000

    []
    0x0000
  • PC
    0x0000

    []
    0x0000
  • EX
    0x0000

    []
    0x0000
  • IA
    0x0000

    []
    0x0000


copy current project files
NOTE: You do not need to save to assemble a project. Just click assemble.

This is a public project. If you wish to save your changes, you must fork it. This will create a new project from your changes, that you alone will be able to edit.

Loading...
About F1DE
X

F1DE - The DCPU Development Tool for 0x10c

Latest Update 23th May 2012 - Version 0.9.20

F1DE is securely hosted on Amazon Web Services for emulation and file storage.
Database is backed up daily.

Example project is here:
http://fasm.elasticbeanstalk.com/?proj=21rnsl

Comments? Suggestions? Ideas? Join us on http://www.0x10cforum.com

DCPU Instructions:
X
Instruction Effect
SETb, asets b to a
ADDb, asets b to b+a, sets EX to 0x0001 if there's an overflow, 0x0 otherwise
SUBb, asets b to b-a, sets EX to 0xffff if there's an underflow, 0x0 otherwise
MULb, asets b to b*a, sets EX to ((b*a)>>16)&0xffff (treats b, a as unsigned)
MLIb, alike MUL, but treat b, a as signed
DIVb, asets b to b/a, sets EX to ((b<<16)/a)&0xffff. if a==0, sets b and EX to 0 instead. (treats b, a as unsigned)
DVIb, alike DIV, but treat b, a as signed. Rounds towards 0
MODb, asets b to b%a. if a==0, sets b to 0 instead.
MDIb, alike MOD, but treat b, a as signed. (MDI -7, 16 == -7)
ANDb, asets b to b&a
BORb, asets b to b|a
XORb, asets b to b^a
SHRb, asets b to b>>>a, sets EX to ((b<<16)>>a)&0xffff (logical shift)
ASRb, asets b to b>>a, sets EX to ((b<<16)>>>a)&0xffff (arithmetic shift) (treats b as signed)
SHLb, asets b to b<<a, sets EX to ((b<<a)>>16)&0xffff
IFBb, aperforms next instruction only if (b&a)!=0
IFCb, aperforms next instruction only if (b&a)==0
IFEb, aperforms next instruction only if b==a
IFNb, aperforms next instruction only if b!=a
IFGb, aperforms next instruction only if b>a
IFAb, aperforms next instruction only if b>a (signed)
IFLb, aperforms next instruction only if b<a
IFUb, aperforms next instruction only if b<a (signed)
ADXb, asets b to b+a+EX, sets EX to 0x0001 if there is an over-flow, 0x0 otherwise
SBXb, asets b to b-a+EX, sets EX to 0xFFFF if there is an under-flow, 0x0 otherwise
STIb, asets b to a, then increases I and J by 1
STDb, asets b to a, then decreases I and J by 1
JSRapushes the address of the next instruction to the stack, then sets PC to a
HCFa---
INTatriggers a software interrupt with message a
IASasets IA to a
IAGasets a to IA
RFIadisables interrupt queueing, pops A from the stack, then pops PC from the stack
IAQaif a is nonzero, interrupts will be added to the queue instead of triggered. if a is zero, interrupts will be triggered as normal again
HWNasets a to number of connected hardware devices
HWQasets A, B, C, X, Y registers to information about hardware a
A+(B<<16) is a 32 bit word identifying the hardware id
C is the hardware version
X+(Y<<16) is a 32 bit word identifying the manufacturer
HWIasends an interrupt to hardware a
Editor Key Shortcuts:
X
PC (Windows/Linux) Mac action
Ctrl-U Ctrl-U change to upper case
Ctrl-Shift-U Ctrl-Shift-U change to lower case
Ctrl-Alt-Down Command-Option-Down copy lines down
Ctrl-Alt-Up Command-Option-Up copy lines up
Ctrl-F Command-F find
Ctrl-K Command-G find next
Ctrl-Shift-K Command-Shift-G find previous
Ctrl-End,Ctrl-Down Command-End,Command-Down go to end
Ctrl-L Command-L go to line
Alt-Right,End Command-Right,End,Ctrl-E go to line end
Alt-Left,Home Command-Left,Home,Ctrl-A go to line start
Ctrl-Home,Ctrl-Up Command-Home,Command-Up go to start
Ctrl-Left Option-Left go to word left
Ctrl-Right Option-Right go to word right
Tab Tab indent
Alt-Down Option-Down move lines down
Alt-Up Option-Up move lines up
Shift-Tab Shift-Tab outdent
Insert Insert overwrite
Ctrl-Shift-Z,Ctrl-Y Command-Shift-Z,Command-Y redo
Ctrl-D Command-D remove line
Ctrl-K remove to line end
Option-Backspace remove to linestart
Alt-Backspace,Ctrl-Alt-Backspace remove word left
Alt-Delete remove word right
Ctrl-R Command-Option-F replace
Ctrl-Shift-R Command-Shift-Option-F replace all
Ctrl-A Command-A select all
Shift-Down Shift-Down select down
Shift-Left Shift-Left select left
Shift-End Shift-End select line end
Shift-Home Shift-Home select line start
Shift-PageDown Shift-PageDown select page down
Shift-PageUp Shift-PageUp select page up
Shift-Right Shift-Right select right
Ctrl-Shift-End,Alt-Shift-Down Command-Shift-Down select to end
Alt-Shift-Right Command-Shift-Right select to line end
Alt-Shift-Left Command-Shift-Left select to line start
Ctrl-Shift-Home,Alt-Shift-Up Command-Shift-Up select to start
Shift-Up Shift-Up select up
Ctrl-Shift-Left Option-Shift-Left select word left
Ctrl-Shift-Right Option-Shift-Right select word right
Ctrl-O split line
Ctrl-T Ctrl-T transpose letters
Ctrl-Z Command-Z undo