comparison clojure/com/aurellem/gb/assembly.clj @ 183:5e34473ac774

merged assembly
author Dylan Holmes <ocsenave@gmail.com>
date Wed, 21 Mar 2012 23:19:01 -0500
parents 95b2758dd517
children d585b91de06c
comparison
equal deleted inserted replaced
179:d63886d63b2f 183:5e34473ac774
404 "Input freestyle buttons and observe the effects at the repl." 404 "Input freestyle buttons and observe the effects at the repl."
405 [] 405 []
406 (set-state! (input-number)) 406 (set-state! (input-number))
407 (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) 407 (dotimes [_ 90000] (step (view-memory @current-state 0xD352))))
408 408
409
410
411
412
413
409 (defn write-memory-assembly* 414 (defn write-memory-assembly*
410 "A program for altering in-game memory by pressing buttons." 415 "A program for altering in-game memory by pressing buttons."
411 [] 416 []
412 [ 417 [
413 0xF3 ; stop interrupts 418 0xF3 ; stop interrupts
417 422
418 ;; --------- FRAME METRONOME 423 ;; --------- FRAME METRONOME
419 0xF1 ;; pop AF (vblank prev) [D320] 424 0xF1 ;; pop AF (vblank prev) [D320]
420 425
421 0x2F ;; invert A 426 0x2F ;; invert A
422 0x47 ;; A -> B 427 0x4F ;; A -> C
423 428
424 0xF0 ;; copy STAT into A 429 0xF0 ;; copy STAT into A
425 0x41 430 0x41
426 431
427 0xCB ;; swap A nybbles; now A_0 is (VB==1). 432 0x47 ;; A->B
428 0x37 433 0x1F ;; rotate A right
429 434 0x2F ;; complement A
435 0xA0 ;; A & B --> A
436
430 0xF5 ;; push AF (vbprev) 437 0xF5 ;; push AF (vbprev)
431 438
432 0xA0 ;; A & B --> A. Now A_0 contains "increment?" 439 0xA1 ;; A & C --> A. Now A_0 contains "increment?"
433 440
434 0xCB ;; test A_0. this result will be used twice. 441 0xCB ;; test A_0. this result will be used twice.
435 0x47 442 0x47
443
436 0x28 ;; end frame (JUMP) if A_0 = 0. 444 0x28 ;; end frame (JUMP) if A_0 = 0.
437 0x00 ;; TODO: set jump length 445 0xF3 ;; TODO: set jump length
438 446
439 ;; -------- GET BUTTON INPUT 447 ;; -------- GET BUTTON INPUT
440 448
441 ;; btw, Z bit is now 1 449 ;; btw, Z bit is now 1
442 ;; prepare to select bits 450 ;; prepare to select bits
468 0x3E ;; load 0x10 into A, to measure btns 476 0x3E ;; load 0x10 into A, to measure btns
469 0x10 477 0x10
470 478
471 0xBF ;; compare(A,A) sets Z=0 479 0xBF ;; compare(A,A) sets Z=0
472 480
473 0x18 ;; JUMP back to "load A into [FF00]" [20 steps?] 481 0x18 ;; JUMP back to "load A into [FF00]"
474 0xED 482 0xEF
475 483
476 484
477 ;; ------ TAKE ACTION BASED ON USER INPUT 485 ;; ------ TAKE ACTION BASED ON USER INPUT
478 486
479 ;; "input mode" 487 ;; "input mode"
553 561
554 (defn write-mem-dyl [] 562 (defn write-mem-dyl []
555 (-> (tick (mid-game)) 563 (-> (tick (mid-game))
556 (IE! 0) 564 (IE! 0)
557 (inject-item-assembly (write-memory-assembly*)))) 565 (inject-item-assembly (write-memory-assembly*))))
566
567 (defn ntick [s n]
568 (if (zero? n) s
569 (do
570 (set-state! s)
571 (dorun (dotimes [_ n]
572 (com.aurellem.gb.Gb/tick)))
573 (update-state))))
574
575
576 (defn find-frame-shift [state]
577 ;;(restart!)
578 (set-state! state)
579 (loop [n 0]
580 (if (>= (first (registers)) 0xD32D)
581 (do (println n)
582 (update-state))
583 (do
584 (com.aurellem.gb.Gb/tick)
585 (recur (inc n) )))))
586
587 (defn demo-assembly [n]
588 (repeat n 0x00))
589
590
591 (defn find-frame-shift* [state]
592 (set-state! state)
593 (loop []
594 (com.aurellem.gb.Gb/tick)
595 ;;(println (first (registers)))
596 (if (>= (first (registers)) 0xD32D)
597 (update-state)
598 (recur))))
599
600
601 (defn dylan**
602 ([k]
603 (->
604 (tick (mid-game))
605 (inject-item-assembly(write-memory-assembly*))
606 ;;(find-frame-shift)
607 (ntick k)
608 (d-tick)
609 (view-register "A" A)
610 (view-register "B" B)
611 (view-register "D" D)
612 (view-register "E" E)
613 (view-register "F" F)
614 (#(do (println) %))
615 ))
616 ([] (dylan** 0)))
617
618
558 619
559 620
560 (defn dylan* [] 621 (defn dylan* []
561 (-> 622 (->
562 (write-mem-dyl) 623 (write-mem-dyl)