-
-
Save emoon/77963aabc16edd82f14f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Pure Lisp based assembler | |
(def my-fun (input1 :in d1 | |
input2 :in d2 | |
output :out d0) | |
(move.l input1 output) | |
(add.l input2 output)) | |
---------------------------------------------------------------------------------------- | |
; We can also have loop constructions by doing a macro (no need for it to be 'built-in') | |
(def my-fun (input1 :in d1 | |
input2 :in d2 | |
output :out d0) | |
(loop for input1 to input2 do ; macro can in compile time look at body and figure out how to do the loop in the best way | |
(add.l input output))) | |
------------------------------------------------------------------------------------------------------------------------- | |
; This works quite well for simple instructions (would fit great far 6502) but 68k has more complex addressing modes which | |
; makes this a bit annoying | |
; | |
; Example: move.l d0,(a0)+ ; move register d0, to where a0 is pointing and bump the pointer according to the move size (here 4) | |
(move.l d0 a0+) ; maybe (move.l d0 (a0+)) would work but it becomes a bit ackward. | |
--------------------------------------------------------------------------------------------------------- | |
; maybe a mixed approach is better (notice that syntax may not be 100% valid, just really playing around) | |
(def my-fun (input1 :in d1 | |
input2 :in d2 | |
array :in a0 | |
output :out d0) | |
add.l input1,input2 | |
move.l input2,output | |
(loop for input1 to input2 do | |
move.l input,(array)+)) | |
--------------------------------------------------------------------------------------------------------------------------- | |
; thoughs: | |
; Julia has some nice metaprogramming stuff which comes from lisp but isn't s-exp http://docs.julialang.org/en/latest/manual/metaprogramming/ maybe ideas can be used from here) | |
; KickAssembler can be used as insperation as well http://www.theweb.dk/KickAssembler/webhelp/content/cpt_FunctionsAndMacros.html | |
--------------------------------------------------------------------------------------------------------------------------- | |
; Structs | |
; using structs in lisp is a bit tire some because the way you write the access. GOAL uses -> which is fine I guess. Here is some GOAL code (a bit formated in more Lisp style) | |
(defun sparticle-red-2-converge ((sp-system sparticle-system) (particle sparticle-cpuinfo) (spvec sprite-vec-data-2d)) | |
"Red gun 2 charge glow effect" | |
(let ((control (the sparticle-launch-control (-> particle key)))) | |
;; figure out the offset from the player's position | |
(let ((origin-vec (stack-vector)) | |
(offset-vec (stack-vector))) | |
;; retrieve offset vec off of userdata, omega. We only had 8 bytesfor data storage, | |
;; but needed to store a full vec3, so we packed it into fixed point. | |
(let ((combined-vec (new 'stack 'vector4w))) | |
(set! (-> combined-vec x) (-> particle user-uint32)) | |
(set! (-> combined-vec y) (-> particle data 0)) | |
(rlet ((offset :reg vf1) | |
(preconverted :reg vf2) | |
(iconv0) | |
(src)) | |
(l.q src combined-vec) ;; GOAL->EE | |
(mer.vh lo iconv0 src r0) ;; EE | |
(sr.vw iconv0 iconv0 16) ;; EE | |
(m preconverted iconv0) ;; EE->VU0 | |
;; (format *stderr* "Value is ~d~%" iconv0) ;; GOAL | |
;; VU ftoi15 | |
(cvt.s.w offset preconverted :fixed 12) ;; VU0 | |
(s.q offset offset-vec))) ;; VU0->GOAL | |
;; figure out distance | |
(let ((time-remaining (-> particle timer)) | |
(distance 0.0) | |
(tt 0.0)) | |
(set! tt (/ (the float (-> particle timer)) (the float (frame-time90)))) | |
(*! tt tt ) | |
(set! tt (- 1.0 tt)) | |
(vector-normalize! offset-vec (lerp PARTICLE_RED_2_CHARGE_SIZE (meters 0) tt)) | |
(vector-copy! origin-vec (-> *target* gun fire-point)) | |
(set! (-> spvec trans x) (+ (-> offset-vec x) (-> origin-vec x))) | |
(set! (-> spvec trans y) (+ (-> offset-vec y) (-> origin-vec y))) | |
(set! (-> spvec trans z) (+ (-> offset-vec z) (-> origin-vec z))))))) | |
-------------------------------------------------------------------------------- | |
I would actually prefer some other way here to do structs and access data in a nice fasihon, something along the line: | |
struct Foo | |
{ | |
.long meh | |
.long foo | |
} | |
register a0 is of type Foo; | |
move.l (a0).foo,d0 ; would translate to move.l 4(a0),d0 | |
; also very basic syntax transforms like this can be used if wanted then | |
(a0).foo = d0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment