h1. A Database Backend For Rails I18N

Store your translations in the database, rather than yaml files.  As you tag items with i18n.t() throughout your code base, all untranslated items are marked and added to the database.  An admin panel is provided so translators can quickly translate untranslated text.  All keys are cached, and an alternate cache store can be provided.

h2. Installation

    script/generate i18n_database_backend # add migration
    rake db:migrate                       # migrate
    rake i18n:populate:all                # populate locales (list from Java's LocaleServiceProvider)

In config/initialisers/i18n.rb

    I18n.backend = I18n::Backend::Database.new # registers the backend
    I18n.backend.cache_store = :memory_store   # optional: specify an alternate cache store

h2. TODO

* I18n.ta ?
* pluralization to be added/rules imported
* interpolation
* namespacing
* bulk lookup
* view translation cache loader for production

Fix typo in generator instructions

h1. A Database Backend For Rails I18N

Store your translations in the database, rather than yaml files.  As you tag items with i18n.t() throughout your code base, all untranslated items are marked and added to the database.  An admin panel is provided so translators can quickly translate untranslated text.  All keys are cached, and an alternate cache store can be provided.

h2. Installation

    script/generate i18n_backend_database # add migration
    rake db:migrate                       # migrate
    rake i18n:populate:all                # populate locales (list from Java's LocaleServiceProvider)

In config/initialisers/i18n.rb

    I18n.backend = I18n::Backend::Database.new # registers the backend
    I18n.backend.cache_store = :memory_store   # optional: specify an alternate cache store

h2. TODO

* I18n.ta ?
* pluralization to be added/rules imported
* interpolation
* namespacing
* bulk lookup
* view translation cache loader for production


A modular, testable debugger for Ruby 1.9

Some cryptic examples.

Running if rbdbgr is installed:

bc. rbdbgr ruby-program [program]

If your program needs options of its own:

bc. rbdbgr -- ruby-program [program args...]

Running from inside irb:

bc. require 'rbdbgr'
 Debugger.debug { your code }

You can do the same thing inside your Ruby program, but probably you don't want to give a block. Instead, you may want to have debugging start on the next statement in the code:

bc. require 'rbdbgr'
 Debugger.debug # Don't stop here...
 work # but stop here.

or if you haven't mucked around with $0 and ARGV, you might try:

bc. Debugger.debug(:set_restart=>true)

which informs the debugger on how to restart the program (via the restart command) using the values of ARGV and $0 at the time Debugger.debug was called.

The above is really shorthand for something like:

bc. mydbg = Debugger.new(:set_restart=>true)
 mydbg.debugger

Debugger.debug returns a debugger object (mydbg above) which can then be used over again. The debugger object holds debugger settings.

If for some reason you want a synchronous stop in your program call to the debugger at the point of the call, set opts[:immediate] to true. Example:

bc. # ... work, work, work
 mydbg.debugger(:immediate=>true) # enter debugger here
 # ... work, work, work

Add a lead space in 1st line in example code.


!https://github.com/tinkerpop/rexster-kibbles/raw/master/doc/images/rexster-kibbles-logo.png!

Rexster Kibbles is a collection of extensions for the "Rexster":http://rexster.tinkerpop.com graph server.

Fix broken image for kibbles.

!https://github.com/tinkerpop/rexster/blob/master/doc/images/rexster-kibbles-logo.png!

Rexster Kibbles is a collection of extensions for the "Rexster":http://rexster.tinkerpop.com graph server.


h1. InvisionBridge

A Rails plugin to allow Authlogic to use an Invision Power Board database's user credentials.

h2. Credits

* Chris Herring - "connection_ninja":http://github.com/cherring/connection_ninja

Copyright (c) 2009 Robert Speicher, released under the MIT license

Remove a credit, since we went another way.

h1. InvisionBridge

A Rails plugin to allow Authlogic to use an Invision Power Board database's user credentials.

h2. Credits

Copyright (c) 2009 Robert Speicher, released under the MIT license


h1. test-unit-activesupport

!https://travis-ci.org/test-unit/test-unit-activesupport.svg?branch=master!:https://travis-ci.org/test-unit/test-unit-activesupport

"Web site":https://test-unit.github.io/#test-unit-activesupport

h2. Description

test-unit-activesupport is an ActiveSupport adapter for test-unit 3. You can use full test-unit 3 features with @ActiveSupport::TestCase@.

h2. Install

Require @test/unit/active_support@:

require "test/unit/active_support"
require "active_support"

Now you can use full test-unit 3.x features with ActiveSupport.

require 'test/unit/active_support'
require "active_support"

class YourTest < ActiveSupport::TestCase
  # ...
end

h2. License

LGPLv2.1 or later.

(Kouhei Sutou has a right to change the license including contributed patches.)

h2. Authors

* Kouhei Sutou
* Haruka Yoshihara

h2. Thanks

* Michael Grosser

Use double quote (") for string literal

h1. test-unit-activesupport

!https://travis-ci.org/test-unit/test-unit-activesupport.svg?branch=master!:https://travis-ci.org/test-unit/test-unit-activesupport

"Web site":https://test-unit.github.io/#test-unit-activesupport

h2. Description

test-unit-activesupport is an ActiveSupport adapter for test-unit 3. You can use full test-unit 3 features with @ActiveSupport::TestCase@.

h2. Install

Require @test/unit/active_support@:

require "test/unit/active_support"
require "active_support"

Now you can use full test-unit 3.x features with ActiveSupport.

require "test/unit/active_support"
require "active_support"

class YourTest < ActiveSupport::TestCase
  # ...
end

h2. License

LGPLv2.1 or later.

(Kouhei Sutou has a right to change the license including contributed patches.)

h2. Authors

* Kouhei Sutou
* Haruka Yoshihara

h2. Thanks

* Michael Grosser


h1. About Wef

Wef is a Web Extensions Framework

* License: "MIT License":https://github.com/diesire/wef/blob/master/LICENSE.txt
* Tests: "test/":https://github.com/diesire/wef/tree/master/test

h2. Development

To build wef
<pre>
make build
</pre>

h2. TODO
* [ ] Dependency management

Update testing and add features

h1. About Wef

Wef is a Web Extensions Framework

* License: "MIT License":https://github.com/diesire/wef/blob/master/LICENSE.txt
* Tests: "test/":https://github.com/diesire/wef/tree/master/test

h2. Features
* Educational purposes. Because I`m learning JavaScript and Hello, world! is mainstream.
* Work in progress. You know, forever beta stage.
* Eating your own dog food. Wef is used in my awesome "CSS Template Layout Module":https://github.com/diesire/cssTemplateLayout
* Plain JavaScript, no third party libraries
* Modular, extensible

h2. Development

To build wef
<pre>
make build
</pre>

For testing, wef uses "jsTestDriver":http://code.google.com/p/js-test-driver/


h2. Spree 1.0 Release Notes

endprologue.

h3. Summary

This is the official 1.0 Release of Spree

h3. Preferences

We have refactored Spree Preferences to improve performance and simplify
code for applicaitons and extensions. The previous interfaces have been
maintained so no code changes should be required. The underlying classes
have been completely rewritten.

Please see the "Spree blog":http://spreecommerce.com/blog/2011/12/04/spree-preferences-refactor for
notes on this release

h3. Deprecated functions

h4. Product

+master_price+, +master_price=+, +variants?+, +variant+ are now officially retired. Please use +Product.price+, +Product.price=+, +Product.has_variants?+ and +Product.master+ respectively instead.

h4. Spree::Config[:stylesheets]

+Spree::Config[:stylesheets]+ and +stylesheet_tags+ are removed in favor for the Rails 3.1 Asset Pipeline. See the "Asset Customization":asset_customization.html for more information.

Extensions looking to add stylesheets to the application should do so through the Asset Pipeline by making the extension an engine.

h3. Testing

h4. The demise of Cucumber testing

Cucumber is a great testing tool however it doesn't bring more values for tesing but overhead. It is decide to opt for a light-weight practice of RSpec + Capybara.

Improve documentation in summary of 1.0 release notes

h2. Spree 1.0 Release Notes

endprologue.

h3. Summary

This is the official 1.0 Release of Spree. This is a *major* release for Spree, and so backwards compatibility with extensions and applications is not maintained.

The changes to Spree in the 1.0 Release are outlined in this document.

h3. Preferences

We have refactored Spree Preferences to improve performance and simplify
code for applicaitons and extensions. The previous interfaces have been
maintained so no code changes should be required. The underlying classes
have been completely rewritten.

Please see the "Spree blog":http://spreecommerce.com/blog/2011/12/04/spree-preferences-refactor for
notes on this release

h3. Deprecated functions

h4. Product

+master_price+, +master_price=+, +variants?+, +variant+ are now officially retired. Please use +Product.price+, +Product.price=+, +Product.has_variants?+ and +Product.master+ respectively instead.

h4. Spree::Config[:stylesheets]

+Spree::Config[:stylesheets]+ and +stylesheet_tags+ are removed in favor for the Rails 3.1 Asset Pipeline. See the "Asset Customization":asset_customization.html for more information.

Extensions looking to add stylesheets to the application should do so through the Asset Pipeline by making the extension an engine.

h3. Testing

h4. The demise of Cucumber testing

Cucumber is a great testing tool however it doesn't bring more values for tesing but overhead. It is decide to opt for a light-weight practice of RSpec + Capybara.


h2. Spree 1.2.0 Release Notes

endprologue.

h3. Summary

h3. Major changes (backwards incompatibility)

h3. Minor changes

h4. Spree::Zone#country_list renamed to #zone_member_list

Please be noted that the underlying logics remain intact.

Add note about CreditCard renaming changes in release notes

h2. Spree 1.2.0 Release Notes

endprologue.

h3. Summary

h3. Major changes (backwards incompatibility)

h3. Minor changes

h4. Spree::Zone#country_list renamed to #zone_member_list

Please be noted that the underlying logics remain intact.

h4. Spree::Creditcard renamed to Spree::CreditCard

All occurences of Creditcard word are changed to CreditCard.


h1. profiling

A bookmarklet to turn profiling on and off in SiteVision.

h2. Installation

Installation is easy - "follow the instructions on this page":http://svendahlstrand.github.com/profiling.

h2. Usage

Use the bookmarklet to toggle profiling on and off.

h2. Known limitations

When there is no profiling query string present you have to use the bookmarklet twice to turn profiling off. This will be fixed.

Remove known limititations, the problem is fixed.


h1. Fuubar

Fuubar is an instafailing "RSpec":http://github.com/rspec formatter that uses a progress bar instead of a string of letters and dots as feedback. Here's "a video of Fuubar in action":http://vimeo.com/16845253.

h2. Installation

Installing Fuubar is easy. Just put it in your @Gemfile@ and run your specs like this from now on:

bc. $ rspec --format Fuubar --color spec

If you want to use Fuubar as your default formatter, simply put the options in your @.rspec@ file:

bc. --format Fuubar
--color

h2. Contributing

Found an issue? Have a great idea? Want to help? Great! Create an issue "issue":http://github.com/jeffkreeftmeijer/fuubar/issues for it, "ask":http://github.com/inbox/new/jeffkreeftmeijer, or even better; fork the project and fix the problem yourself. Pull requests are always welcome. :)

Add the Travis build status badge

h1. Fuubar ![Build status](http://travis-ci.org/jeffkreeftmeijer/fuubar.png)

Fuubar is an instafailing "RSpec":http://github.com/rspec formatter that uses a progress bar instead of a string of letters and dots as feedback. Here's "a video of Fuubar in action":http://vimeo.com/16845253.

h2. Installation

Installing Fuubar is easy. Just put it in your @Gemfile@ and run your specs like this from now on:

bc. $ rspec --format Fuubar --color spec

If you want to use Fuubar as your default formatter, simply put the options in your @.rspec@ file:

bc. --format Fuubar
--color

h2. Contributing

Found an issue? Have a great idea? Want to help? Great! Create an issue "issue":http://github.com/jeffkreeftmeijer/fuubar/issues for it, "ask":http://github.com/inbox/new/jeffkreeftmeijer, or even better; fork the project and fix the problem yourself. Pull requests are always welcome. :)


h1. level 1 heading

h2=. level 2 heading

h3>. level 3 heading

h4<{color:red}. level 4 heading

bq. this is blockquoted text

fn1. footnote 1

fn2. footnote 2

This text refernces a footnote[1]

# numbered list item 1
# numbered list item 2

* bulleted list first item
* bulleted list second item

_emphasis_
*strong*
??citation??
-deleted text-
+inserted text+
^superscript^
~subscript~
%span%

p(class). paragraph with a classname

p(#id). paragraph with an ID

p{color:red}. paragrah with a CSS style

p[fr]. paragraphe en français

p<. right aligned paragraph

p>. left aligned paragraph

p=. centered aligned paragraph

p<>. justified text paragraph

|_. head |_. table |_. row |
| a | table | row 1 |
| a | table | row 2 |

"Link to Textile GitHub":https://github.com/textile

!https://avatars2.githubusercontent.com/u/362604?v=3&s=200!

ABBR(Abbreviation)


---
title: Expanding the Scope of the Blog
layout: blog
author: Ken Mix
email: ken.mix@gmail.com
---
p. For the folks following this blog (both of you) it's probably become readily apparent that:

# IPv6 is a pipe dream, _or_
# After all of the initial testing and configuration, it turns out the demand just isn't there yet, _or_
# We're pretty lazy (or busy -- take your pick)

p. In reality, it's a bit of each.  While we know IPv6 isn't _really_ a pipe dream, and that IPv6 traffic increases every day, the portion of our workdays involving IPv6 equals exactly 0.00%.  If we want slightly more involvement, we could always work at Google; according to their "IPv6 statistics":http://www.google.com/ipv6/statistics.html, IPv6-enabled Google users account for 0.68% of their workload at the time of this writing...

p. While we're certain there will eventually be more IPv6 content, we felt it would be handy to have a repository for the rest of the sweet nuggets of info we dig up or develop in the course of our jobs.  Hence, knowledgebombs.net.  Enjoy!


h2. Spree 1.2.0 Release Notes

endprologue.

h3. Summary

h3. Major changes (backwards incompatibility)

h3. Minor changes

h4. Spree::Zone#country_list renamed to #zone_member_list

Please be noted that the underlying logics remain intact.


Add post about the new `git status` features in 2.6

---
layout: post
title: "interactive rebase status"
category: intermediate
---

With "git 2.6": https://github.com/git/git/blob/v2.6.0/Documentation/RelNotes/2.6.0.txt it's now easier than ever to keep track of your work during an interactive rebase.

Previously, if you were rebasing interactively and had hit a conflict or stopped to reword a commit, git status would look like this:

$ git rebase -i HEAD~5
$ git status
rebase in progress; onto 0927cd6
You are currently rebasing branch 'testbranch' on '0927cd6'.
  (fix conflicts and then run "git rebase --continue")

This only tells you what branch you started with and the target of your rebase. If you want to get information about which commit you'vestopped on, you need to turn to
git log
.

With the release of 2.6, git status now produces much more helpful output that *reminds you what you were doing*. It includes which rebase commands have finished already, and what's still left to do.

$ git rebase -i HEAD~5
$ git status
interactive rebase in progress; onto '0927cd6'

Last commands done (2 done):
  pick f47cc4d Style edits
  pick 903d58c Post about techcrunch article
  edit 8cd01c4 Limit width of post content

Next commands to do (1 remaining commands):
  pick 6aa9082 Delete zero-sized files

You are currently editing a commit while rebasing branch 'testbranch' on '0927cd6'.

nothing to commit, working directory clean

This gives you more context when working with your commit history, so you know why the rebase stopped.


h2. Spree 1.1.0 Release Notes

endprologue.

h3. Summary

h3. spree_product_groups now as standalone extension

Product Groups component is extracted to a standalone spree extension. It is
now could be added to your application by appending to Gemfile:

    gem 'spree_product_groups', :git => 'git@github.com:spree/spree_product_groups.git'


h2. GradleFx changelog

h3. v0.2.2

* Fixed a critical issue where the mainClass could never be found
* Changed the convention for the output property from "${project.name}.${project.type}" to project.name
* The output directory for the htmlWrapper task is now created when it doesn't exist yet

h3. v0.2.1

* Fixed an issue where overriding the 'output' property didn't work

h3. v0.2

* Added HTML wrapper generation

h3. v0.1

* Initial version

Update change log with the 0.3.0 release including FlexUnit

h2. GradleFx changelog

h3. v0.3.0

* Added FlexUnit support for executing tests as part of the build. This is optional and any existing builds should continue to work
* Compiler warnings will now be visible on stdout

h3. v0.2.2

* Fixed a critical issue where the mainClass could never be found
* Changed the convention for the output property from "${project.name}.${project.type}" to project.name
* The output directory for the htmlWrapper task is now created when it doesn't exist yet

h3. v0.2.1

* Fixed an issue where overriding the 'output' property didn't work

h3. v0.2

* Added HTML wrapper generation

h3. v0.1

* Initial version


Add a notice file listing all dependencies and their licenses

h2. List of 3rd party dependencies and their licenses

This project depends on the following 3rd party code:

| *Name*      | *What it does*  | *Version* | *Authors*   | *URL*                             | *License*    | *License URL*                            |
| validatable | Validation of   | 1.6.7     | Jay Fields  | http://validatable.rubyforge.org  | Ruby License | http://www.ruby-lang.org/en/LICENSE.txt  |
| -           | inputs          | -         | -           | -                                 | -            | -                                        |
| -           | -               | -         | -           | -                                 | -            | -                                        |


h1. Cucumber goes Tcl

h2. Prerequisites

Install the ruby-tcl bindings:

  [sudo] gem install tcl --source http://gemcutter.org/

h2. Run the example:

  rake cucumber

Fix incorrect gem install command

h1. Cucumber goes Tcl

h2. Prerequisites

Install the ruby-tcl bindings:

  [sudo] gem install --source http://gemcutter.org/ tcl

h2. Run the example:

  rake cucumber


h1. Wilker Dot Files

This repository inclues my dotfiles for unix enviroments

h2. Install

Install instructions

bc. git clone git://github.com:wilkerlucio/dotfiles.git
cd dotfiles
rake install

Change owner name - thanks Wilker!

h1. Eduardo Lundgren

This repository inclues my dotfiles for unix enviroments

h2. Install

Install instructions

bc. git clone git://github.com:eduardolundgren/dotfiles.git
cd dotfiles
rake install


---
title: "GNU Manual Improved"
date: 2015-03-18
categories: experiment gnu
excerpt: "What's not to love about the GNU C Library manual. Its long, it looks like crap and its older than all of us. This is my attempt to improve it!"
---

What's not to love about the GNU C Library manual. Its long, it looks like crap and its older than all of us. For some time now I have been wanting to create a new version of the manual with a refreshed look and a new navigation system. Getting anywhere in that manual is a chore, and I always seem to end up with ten tabs open to different sections. So please, check out "my":1 take on the GNU manual and let me know what you think in the comments.

p{font-size: 2em;}. Go Here: "Yet Another GNU Manual":1

[1]/gnu_manual.html


;------------------------------------------------------------------------------
;
; Copyright (c) 2006, Intel Corporation
; All rights reserved. This program and the accompanying materials
; are licensed and made available under the terms and conditions of the BSD License
; which accompanies this distribution.  The full text of the license may be found at
; http://opensource.org/licenses/bsd-license.php
;
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;
; Module Name:
;
;   FlushCacheLine.Asm
;
; Abstract:
;
;   AsmFlushCacheLine function
;
; Notes:
;
;------------------------------------------------------------------------------

    .code

;------------------------------------------------------------------------------
; VOID
; EFIAPI
; AsmFlushCacheLine (
;   IN      VOID                      *LinearAddress
;   );
;------------------------------------------------------------------------------
AsmFlushCacheLine   PROC
    clflush [rcx]
    mov     rax, rcx
    ret
AsmFlushCacheLine   ENDP

    END

Change VOID into VOID * in function header

;------------------------------------------------------------------------------
;
; Copyright (c) 2006, Intel Corporation
; All rights reserved. This program and the accompanying materials
; are licensed and made available under the terms and conditions of the BSD License
; which accompanies this distribution.  The full text of the license may be found at
; http://opensource.org/licenses/bsd-license.php
;
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;
; Module Name:
;
;   FlushCacheLine.Asm
;
; Abstract:
;
;   AsmFlushCacheLine function
;
; Notes:
;
;------------------------------------------------------------------------------

    .code

;------------------------------------------------------------------------------
; VOID *
; EFIAPI
; AsmFlushCacheLine (
;   IN      VOID                      *LinearAddress
;   );
;------------------------------------------------------------------------------
AsmFlushCacheLine   PROC
    clflush [rcx]
    mov     rax, rcx
    ret
AsmFlushCacheLine   ENDP

    END


TITLE Linear/Sequential search implemented in x86 assembly (MASM)
; Search for a value in an array of bytes by comparing each value with a key
; return the position of the key
; O(n) time complexity
; the address of the first element in the array must be in the edx
; and the arrays length in the ecx register
; the index of the key is returned in the eax register

.386	; minimum CPU required to run the program
.model flat, stdcall ; identifies the memory model for the program,
					; in this case its protected mode. It also tells which
					; calling convention to use for procedures
.stack 4096

.data
data db 42, 40, 70, 90, 62, 70, 40 ; our array of data

.code
; implementation of sequential search
SequentialSearch PROC
	xor eax, eax 			; clear eax register just in case
BEGIN_LOOP:
	cmp BYTE PTR[edx], bl   ; if [edx] == bl
	je FOUND				;    then goto FOUND
	inc eax                 ; else increment eax
	inc edx                 ; increment edx
	loop BEGIN_LOOP			; automatically decrements ecx register
FOUND:
	ret
SequentialSearch ENDP

; entry point
main PROC
	mov bl, 90 ; search for 92 in array
	mov edx, OFFSET data
	mov ecx, LENGTHOF data
	call SequentialSearch
main ENDP

END main


Add patch to display popup when attempting to enter forest portrait

.nds
.relativeinclude on
.erroronwarning on

; This patch adds a text popup if the player tries to enter the Forest of Doom portrait before it's unlocked.
; This is necessary for portrait randomizer when the Forest of Doom portrait isn't in the normal location, since the normal event only works in that sector.

@Overlay119Start equ 0x023C0000
@FreeSpace equ 0x023C0000

.open "ftc/arm9.bin", 02000000h

.org 0x02079350 ; Location of code normally run when the Forest of Doom portrait is locked. (todo test if it affects other locked portraits)
  beq @FreeSpace

.close

.open "ftc/overlay9_119", @Overlay119Start

.org @FreeSpace
  ldr  r2,=20FC48Eh ; Bitfield of buttons pressed this frame.
  ldrh r2,[r2]
  ands r2,r2,40h ; Up.
  beq  20793FCh ; If up was not just pressed, continue on with the normal code without showing the message.

  ldr  r0,=4BEh ; Load text index 4BE. Originally this is just an unused string ("The Lost Village") but this should be changed in the text editor to say:
  ; "You must beat Stella and talk to Wind\nto unlock the Forest of Doom."
  bl   2050544h ; Call ShowTextPopup.
  b    20793FCh ; Then continue on with the rest of the code.
  .pool

.close


.regalias count s1
			.regalias source s2
			.regalias dest s3
			.regalias temp s4

_start		temp = 0xf
			cr30 = temp				; start all strands

			count = mem_l[length]
			source = &dataStart
			dest = source + count

			count = count >> 2		; divide by 4
			temp = cr0				; get strand ID
			temp = temp * count		; compute offset
			source = source + temp	; compute source offset for this strand
			dest = dest + temp		; compute dest offset for this strand

loop		temp = mem_b[source]
			mem_b[dest] = temp
			source = source + 1
			dest = dest + 1
			count = count - 1
			if count goto loop

			cr31 = s0		; halt simulation

length		.word 2048
dataStart	.word 0

Add synchronization at the end of the copy test.

.regalias count s1
			.regalias source s2
			.regalias dest s3
			.regalias temp s4

_start		temp = 0xf
			cr30 = temp				; start all strands

			count = mem_l[length]
			source = &dataStart
			dest = source + count

			count = count >> 2		; divide by 4
			temp = cr0				; get strand ID
			temp = temp * count		; compute offset
			source = source + temp	; compute source offset for this strand
			dest = dest + temp		; compute dest offset for this strand

loop		temp = mem_b[source]
			mem_b[dest] = temp
			source = source + 1
			dest = dest + 1
			count = count - 1
			if count goto loop

			; Update number of finished strands
			s0 = &running_strands
retry		s1 = mem_sync[s0]
			s1 = s1 - 1
			s2 = s1
			mem_sync[s0] = s1
			if !s1 goto retry

wait_done	if s2 goto wait_done	; Will fall through on last ref (s2 = 1)
			cr31 = s0				; halt

running_strands .word 4

length		.word 2048
dataStart	.word 0


Add experiment showing use of string as immediate value in source operand.

; Sandbox asm file template to start experimenting from

SECTION .data
SECTION .text

  global _start

_start:
  nop

  mov eax,'WXYZ'	; You can use a string as an immediate value
			; in a soure operand. Debugger will show 0x5A595857
			; which is the binary ascii equivalent.

  mov eax,1		; Code for Exit Syscall
  mov ebx,0		; Return a code of zero
  int 80H		; Make kernel call

SECTION .bss


;;----------------------------------------------------------------------------;;
;;  Move images in rupe (zoom) menu.
;;  Copyright 2014 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

; Familiar brand image
.thumb
.org 0x0215A810
  MOV r1, #0x52     ; X pos, originally 0x52
  MOV r2, #0x4C     ; Y pos, originally 0x4C

Move familiar type image in zoom menu

;;----------------------------------------------------------------------------;;
;;  Move images in rupe (zoom) menu.
;;  Copyright 2014 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

; Familiar brand image
.thumb
.org 0x0215A810
  MOV r1, #0x40     ; X pos, originally 0x52
  MOV r2, #0x4C     ; Y pos, originally 0x4C

; Familiar type image
.org 0x0215A87C
  MOV r1, #0x5C     ; X pos, originally 0x70
  MOV r2, #0x4B     ; Y pos, originally 0x4B


Add patch to fix infinite quest rewards bug in PoR

.nds
.relativeinclude on
.erroronwarning on

.open "ftc/arm9.bin", 02000000h

; Disables the start button exiting the quests menu.
; The B button can be used to exit the quest menu instead.
; This prevents taking quest rewards over and over by exiting before the quest is marked as complete.

; Changes how the quest menu handles button presses.
; Normally the value at [r13,14h] being 2 means B was pressed, and 3 means start was pressed.
; When B is pressed on the quest list, it changes the value to 3 to simulate the player exiting with start.
; Instead we change it so 4 is the value needed to exit the menu, and make B pressed on the quest list set the value to 4 instead of 3.
; Start still just sets it to 3, which is now ignored.
.org 0x02040848
  cmp r0, 4h ; This is the value it must be to exit the quest menu.
.org 0x0204041C
  moveq r0, 4h ; This is the value set when pressing B on the quest list.
.org 0x0204083C
  movle r0, 4h ; This is the value set when the quest list is empty in some cases.
.org 0x0204052C
  mov r0, 4h ; This is the value set when the quest list is empty in other cases.

.close


Convert a string from uppercase to lowercase.

; Sandbox asm file template to start experimenting from
; converts the Snippet string in memory to lowercase by looping and
; adding 32 to each byte in the string

SECTION .data
	Snippet db "KANGAROO"
SECTION .text

  global _start

_start:
		nop

		mov ebx,Snippet
		mov eax,8
	DoMore: add byte [ebx],32
		inc ebx
		dec eax
		jnz DoMore

		mov eax,1		; Code for Exit Syscall
		mov ebx,0		; Return a code of zero
		int 80H		; Make kernel call

SECTION .bss


; Test program to bit-bang a single character out SOD as serial async data

        org     00000H

BITTIME equ     0113h          ; Time delay for a single bit
OUTBITS equ	00Bh

START:
        mvi     c,'T'           ; Send a test character
COUT:
        di
        mvi     b,OUTBITS       ; Number of output bits
        xra     a               ; Clear carry for start bit
CO1:
        mvi     a,080H          ; Set the SDE flag
        rar                     ; Shift carry into SOD flag
        cmc                     ;   and invert carry.  Why? (serial is inverted?)
        sim                     ; Output data bit
        lxi     h,BITTIME       ; Load the time delay for one bit width
CO2:
        dcr     l               ; Wait for bit time
        jnz     CO2
        dcr     h
        jnz     CO2
        stc                     ; Shift in stop bit(s)
        mov     a,c             ; Get char to send
        rar                     ; LSB into carry
        mov     c,a             ; Store rotated data
        dcr     b
        jnz     CO1             ; Send next bit
        ei

        lxi     h,03fffH        ; Wait a while before sending the character again
CHILL:
        dcr     l
        jnz     CHILL
        dcr     h
        jnz     CHILL

        jmp     START


; Sandbox asm file template to start experimenting from

SECTION .data
SECTION .text

  global _start

_start:
  nop

  mov eax,1		; Code for Exit Syscall
  mov ebx,0		; Return a code of zero
  int 80H		; Make kernel call

SECTION .bss

Add tabs to sandbox template.


Add patch to change number of map tiles in DoS

.nds
.relativeinclude on
.erroronwarning on

; This patch slightly changes the code that calculates what percentage of the map you have explored so that the total number of tiles can be easily changed, allowing the percentage to be correct with modded maps.

.open "ftc/arm9.bin", 02000000h

.org 0x02026B54
  mul r0, r0, r1 ; Multiplies the number of explored map tiles (in r0) by 0d1000 (in r1) (for 100.0%, 4 digits including the decimal point).
  ldr r1, =401h ; The total number of map tiles. (The base game has 0x400 tiles, but we put 401 instead because the assembler would optimize 400 into a shifted immediate and then the randomizer couldn't easily change this later on.)
  bl 02075B28h ; Divide
  add r13, r13, 4h
  pop r15
  .pool

.close


; Copyright 2015 Philipp Oppermann
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;    http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.

global long_mode_start
extern main

section .text
bits 64
long_mode_start:

    ; call rust main
    call main
    ; print `OKAY` to screen
    mov rax, 0x2f592f412f4b2f4f
    mov qword [0xb8000], rax
    hlt

Add an 64-bit error function

; Copyright 2015 Philipp Oppermann
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;    http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.

global long_mode_start
extern main

section .text
bits 64
long_mode_start:

    ; call rust main
    call main
    ; print `OKAY` to screen
    mov rax, 0x2f592f412f4b2f4f
    mov qword [0xb8000], rax
    hlt

; Prints `ERROR: ` and the given error code to screen and hangs.
; parameter: error code (in ascii) in al
error:
    mov rbx, 0x4f4f4f524f524f45
    mov [0xb8000], rbx
    mov rbx, 0x4f204f204f3a4f52
    mov [0xb8008], rbx
    mov byte [0xb800e], al
    hlt


Add patch to make PoR enemy resistances behave like DoS and OoE

.nds
.relativeinclude on
.erroronwarning on

; This patch makes resistances in PoR act like resistances in DoS and OoE.
; In vanilla PoR, if an enemy resists even one element of an attack, it will resist the attack.
; This changes it so the enemy must resist all elements of the attack to resist the attack.

.open "ftc/overlay9_0", 021CDF60h

.org 0x021DA1F8
  mvn r0, r5 ; Negate the bitfield of resistances.
  and r0, r0, r7 ; AND the attack's damage types with the negated resistances to find what elements were not resisted.
  ands r0, r0, 0FFh ; Only consider the first 8 resistances. Others have no effect.
  bne 021DA224h ; If any elements were not resisted, do not resist the attack.
  mov r0, r1, asr 1h ; Resisted, so halve the damage. (This was originally a float multiply by 0.5x, but we used up too much space so simplify it to a shift instead.)
  nop
  nop
  nop

.close


;;----------------------------------------------------------------------------;;
;;  Align the position of the numbers in blackjack minigame of casino.
;;  Copyright 2015 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;
.arm

;; Number of rounds played
.org 0x02095FC0
    ADD r1, r6, #0x00 + 0x1C      ; X position

Fix position of blackjack player plays

;;----------------------------------------------------------------------------;;
;;  Align the position of the numbers in blackjack minigame of casino.
;;  Copyright 2015 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;
.arm

;; Number of rounds played
.org 0x02095FC0
    ADD r1, r6, #0x00 + 0x12      ; X position


.nds
.relativeinclude on
.erroronwarning on

.open "ftc/arm9.bin", 02000000h

.org 0x02051F90 ; Where the original game's code for loading area/sector/room indexes is.
  b 020BFC00h ; Jump to some free space, where we will put our own code for loading the area/sector/room indexes.

.org 0x020BFC00 ; Free space.
  mov r5,0h        ; Load the area index into r5.
  strb r5,[r0,515] ; Store the area index to the ram address where r0 will read it later.
  mov r5,0h        ; Load the sector index into r5.
  mov r4,0h        ; Load the room index into r4.
  b 02051F94h      ; Return to where we came from.

.close

Fix bug when changing PoR starting area

.nds
.relativeinclude on
.erroronwarning on

.open "ftc/arm9.bin", 02000000h

.org 0x02051F90 ; Where the original game's code for loading area/sector/room indexes is.
  b 020BFC00h ; Jump to some free space, where we will put our own code for loading the area/sector/room indexes.

.org 0x020BFC00 ; Free space.
  mov r5,0h        ; Load the area index into r5.
  strb r5,[r0,515h] ; Store the area index to the ram address where r0 will read it later. (0x02111785)
  mov r5,0h        ; Load the sector index into r5.
  mov r4,0h        ; Load the room index into r4.
  b 02051F94h      ; Return to where we came from.

.close


; Volume Label
db 'BOOTDISK' ; File Name
db '   '      ; File Extension
db 0x08       ; Attribute
db 0x00       ; Reserved for NT
db 0x01       ; Creation
dw 0x0000     ; Creation Time
dw 0x0000     ; Creation Date
dw 0x0000     ; Last Access Data
dw 0x0000     ; FAT32 Upper Half
dw 0x8000     ; Last Write Time
dw 0x475F     ; Last Write Date
dw 0x0000     ; Starting Cluster
dd 0x00000000 ; File Size

; Second-Stage File
db 'STAGE2  ' ; File Name
db 'BIN'      ; File Extension
db 0x05       ; Attribute (Read-only: 1; System: 4)
db 0x00       ; Reserved for NT
db 0x01       ; Creation
dw 0x0000     ; Creation Time
dw 0x0000     ; Creation Date
dw 0x0000     ; Last Access Data
dw 0x0000     ; FAT32 Upper Half
dw 0x8000     ; Last Write Time
dw 0x475F     ; Last Write Date
dw 0x0000     ; Starting Cluster
dd 0x00000200 ; File Size

pad: times (14*512)-($-$$) db 0

Fix error with root directory entry for STAGE2.BIN

; Volume Label
db 'BOOTDISK' ; File Name
db '   '      ; File Extension
db 0x08       ; Attribute
db 0x00       ; Reserved for NT
db 0x01       ; Creation
dw 0x0000     ; Creation Time
dw 0x0000     ; Creation Date
dw 0x0000     ; Last Access Data
dw 0x0000     ; FAT32 Upper Half
dw 0x8000     ; Last Write Time
dw 0x475F     ; Last Write Date
dw 0x0000     ; Starting Cluster
dd 0x00000000 ; File Size

; Second-Stage File
db 'STAGE2  ' ; File Name
db 'BIN'      ; File Extension
db 0x05       ; Attribute (Read-only: 1; System: 4)
db 0x00       ; Reserved for NT
db 0x01       ; Creation
dw 0x0000     ; Creation Time
dw 0x0000     ; Creation Date
dw 0x0000     ; Last Access Data
dw 0x0000     ; FAT32 Upper Half
dw 0x8000     ; Last Write Time
dw 0x475F     ; Last Write Date
dw 0x0002     ; Starting Cluster
dd 0x00000200 ; File Size

pad: times (14*512)-($-$$) db 0


Add patch to enable skipping AoS cutscenes on first playthrough

.gba
.relativeinclude on
.erroronwarning on

.open "ftc/rom.gba", 08000000h

; Allow skipping events with start, even if you haven't beaten the game once yet.
.org 0x0805B56C
  mov r0, 3h

.close


// Super Smash Bros. flash on Z cancel demonstration

arch n64.cpu
endian msb
//output "", create

include "LIB\N64.inc"
include "LIB\macros.inc"

origin 0x0
insert "LIB\Super Smash Bros. (U) [!].z64"

origin 0x0CB528
base 0x80150AE8 // Z cancel
jal Flash

origin 0x33204
base 0x80032604
scope Flash: {
  addiu sp, -0x18
  sw ra, 0x14 (sp)
  jal 0x80142D9C // Original instruction
  sw v1, 0x10 (sp) // Save v1
  lw v1, 0x10 (sp) // Restore v1
  lw t0, 0x0160 (v1)
  slti t1, t0, 0x000B
  beqz t1, End // If within frame window
  nop
  Flash:
    lw a0, 0x04 (v1) // Pointer
    //lli a1, 0x08 // Sparkle
    lli a1, 0x2B // Yellow
    jal 0x800E9814 // Flash
    or a2, r0, r0
  End:
    lw ra, 0x14 (sp)
    jr ra
    addiu sp, 0x18
}


Add patch to fix bug where common enemy creature sets boss death flag

.nds
.relativeinclude on
.erroronwarning on

; This patch fixes the bug where the common enemy version of The Creature sets his boss death flag.

.open "ftc/overlay9_60", 022D7900h

.org 0x022D7D14
  ; Check if Var A is 0 (common enemy/boss rush version) and skip setting the boss death flag if so.
  ; This code already existed around here in vanilla, we're just moving it up a few lines to before setting the boss death flag instead of after.
  ldrh r1, [r1, 3Ch]
  cmp r1, 0h
  beq 0x022D7D30

  ; Then set the boss death flag.
  ldr r2, [r0, 76Ch]
  orr r2, r2, 200h
  str r2, [r0, 76Ch]

.close


; =============================================================================
; Copyright (C) 2015 Manolis Fragkiskos Ragkousis -- see LICENSE.TXT
; =============================================================================

;;; Print routine
;;; ebx contains a null terminated string

%ifndef PRINT_STRING_PM
%define PRINT_STRING_PM

[bits 32]
VIDEO_MEMORY equ 0xb8000
WHITE_ON_BLACK equ 0x0f

print_string_pm:
        pusha
        mov edx, VIDEO_MEMORY

print_string_pm_loop:
        mov al, [ebx]
        mov ah, WHITE_ON_BLACK

        cmp al, 0
        je print_string_pm_done

        mov [edx], ax
        add ebx, 1
        add edx, 2

        jmp print_string_pm_loop

print_string_pm_done:
        popa
        ret

%endif


Add patch to make Balore face left if player enters from left

.nds
.relativeinclude on
.erroronwarning on

; This patch makes Balore detect which side of the room the player enters from, and if it's from the left, he moves himself to face left.

.open "ftc/overlay9_23", 022FF9C0h

@Overlay41Start equ 0x02308920
@FreeSpace equ @Overlay41Start + 0x140

.org 0x022FFD44
  b @BaloreFacePlayer

.close

.open "ftc/overlay9_41", @Overlay41Start

.org @FreeSpace
@BaloreFacePlayer:
  mov r0, r5
  bl 021C3278h ; GetPlayerXPos
  cmp r0, 80000h ; X pos 0x80, halfway through the leftmost screen
  bge @BaloreFaceRight
@BaloreFaceLeft:
  mov r0, 0h ; Var A
  mov r1, 0F0000h ; X pos
  str r1, [r5, 2Ch]
  b @BaloreFacePlayerEnd
@BaloreFaceRight:
  mov r0, 1h ; Var A
  ; We don't set X pos here because we assume Balore's X pos was already properly set for facing right.
@BaloreFacePlayerEnd:
  ; Go back to Balore's normal code to set the direction he faces
  ; We make sure r0 has Var A in it - but not Balore's real Var A, just the one to check for the purposes of deciding the direction he faces.
  b 0x022FFD48

.close


;;----------------------------------------------------------------------------;;
;;  Align the position of the textbox in equip menu
;;  Copyright 2014 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

;; Item name
.arm
.org 0x020821B8
  MOV r1, #0x83     ; X pos, originally 0x84

;; Item quantity
.arm
.org 0x02082228
  MOV r1, #0xDB     ; X pos, originally 0xDD

Move level number in equip menu

;;----------------------------------------------------------------------------;;
;;  Align the position of the textbox in equip menu
;;  Copyright 2014 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

;; Item name
.arm
.org 0x020821B8
  MOV r1, #0x83     ; X pos, originally 0x84

;; Item quantity
.arm
.org 0x02082228
  MOV r1, #0xDB     ; X pos, originally 0xDD

;; Level
.arm
.org 0x2080544
  MOV r1, #0x79 + 2 ; X poss


; 0x0000
; RST 0x00
    jp boot
; Magic Number
; 0x0003
.db "KK"

; 0x0008
; RST 0x08
.fill 0x08-$
rkcall:
    jp kcall
.fill 0x10-$
; 0x0010
; RST 0x10
rlcall:
    jp lcall
.fill 0x18-$
; 0x0018
; RST 0x18
    jp reboot
.fill 0x20-$
; 0x0020
; RST 0x20
    jp pcall
.fill 0x28-$
; 0x0028
; RST 0x28
    jp bcall
.fill 0x30-$
; 0x0030
; RST 0x30
    ret
.fill 0x38-$
; 0x0038
; RST 0x38
; SYSTEM INTERRUPT
    jp sysInterrupt
; 0x003B

.fill 0x53-$
; 0x0053
    jp boot
; 0x0056
.db 0xFF, 0xA5, 0xFF
.fill 0x64-$
.exec git describe --dirty ; Version string
.db 0

Modify version string to be more concise

; 0x0000
; RST 0x00
    jp boot
; Magic Number
; 0x0003
.db "KK"

; 0x0008
; RST 0x08
.fill 0x08-$
rkcall:
    jp kcall
.fill 0x10-$
; 0x0010
; RST 0x10
rlcall:
    jp lcall
.fill 0x18-$
; 0x0018
; RST 0x18
    jp reboot
.fill 0x20-$
; 0x0020
; RST 0x20
    jp pcall
.fill 0x28-$
; 0x0028
; RST 0x28
    jp bcall
.fill 0x30-$
; 0x0030
; RST 0x30
    ret
.fill 0x38-$
; 0x0038
; RST 0x38
; SYSTEM INTERRUPT
    jp sysInterrupt
; 0x003B

.fill 0x53-$
; 0x0053
    jp boot
; 0x0056
.db 0xFF, 0xA5, 0xFF
.fill 0x64-$
.exec git describe --dirty=+ ; Version string
.db 0


Add patch to skip emblem drawing screen in PoR

.nds
.relativeinclude on
.erroronwarning on

.open "ftc/overlay9_25", 022D7900h

; Skip the screen where the player has to draw an emblem and press OK when starting a new game.

.org 0x022DAAB0 ; Code in the name entry menu after you finished typing in your name that would normally take you to the emblem drawing screen next.
  mov r11, 19h ; We set the return value to 0x19, which is the state for the scrolling prologue introduction.
  nop
  nop
  nop
  nop
  nop
  nop

.close


Add patch to fix Gravedorcus from left entrance

.nds
.relativeinclude on
.erroronwarning on

; This patch makes Gravedorcus not immediately damage the player if they enter from the left door.

.open "ftc/overlay9_33", 022B73A0h

.org 0x022BA230
  ; Remove branch that would make Gravedorcus's intro cutscene play if you enter the room from the right.
  nop

.org 0x022BA250
.area 0x20 ; Lines 022BA258-022BA26C were for the cutscene we skipped over, so we get 0x18 extra bytes to work with from that.
  ; Set Gravedorcus's state to 5 instead of 1.
  ; This causes Gravedorcus to start at X position 0x100 and shooting projectiles to the left, which is dodgeable, while spawning right on top of the player and moving to the right is not dodgeable.
  mov r0, 5h
  strb r0, [r5, 0Dh]

  ; Replace the two lines we overwrote at the start (return)
  add r13, r13, 10h
  pop r3-r5,r15
.endarea

.close


;;----------------------------------------------------------------------------;;
;;  Align the position of the numbers in military minigame of casino.
;;  Copyright 2015 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

.arm
.org 0x0207E900
  MOV r1, #0xB+19       ; X pos
  MOV R2, #3            ; Y pos

Move up the number of military games

;;----------------------------------------------------------------------------;;
;;  Align the position of the numbers in military minigame of casino.
;;  Copyright 2015 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

.arm
.org 0x0207E900
  MOV r1, #0xB+19       ; X pos
  MOV R2, #2            ; Y pos


Add patch to always enable dowsing hat effect

.nds
.relativeinclude on
.erroronwarning on

; Always have the Dowsing Hat effect of beeping when there's a hidden blue chest, even if you don't have Dowsing Hat equipped.

.open "ftc/overlay9_19", 021FFFC0h

.org 0x0221AE30 ; Where the blue chest loads your currently equipped head armor.
  mov r0, 7h ; Dowsing Hat

.close


Add asm patch to implement magical tickets in DoS

.nds
.relativeinclude on
.erroronwarning on

@Overlay41Start equ 0x023E0100
@FreeSpace equ 0x023E0100

.open "ftc/overlay9_0", 0219E3E0h

.org 0x021EEF00
  b @FreeSpace

.close

.open "ftc/overlay9_41", @Overlay41Start

.org @FreeSpace
  ; TODO: Don't allow using during boss fights.

  mov r0, 0h ; Sector index
  mov r1, 1h ; Room index
  mov r2, 80h ; X pos
  mov r3, 60h ; Y pos
  bl 02026AD0h ; SetDestinationRoomSectorAndRoomIndexes
  ldr r1, =020F6DF4h
  mov r0, 6h
  strb r0, [r1] ; We set the current type of transition mode (020F6DF4) to 6, meaning a warp of some kind.
  mov r0, 0h
  strb r0, [r1,1h]

  ; Enable control of the player, in case they were using the slide puzzle and controls were disabled.
  bl 021F64BCh

  ; Below is copy pasted, it triggers the game to unpause.
  mov     r0,44h
  bl      2029BF0h
  mov     r0,0h
  mvn     r1,0Fh
  mov     r2,8h
  bl      20080DCh
  mov     r2,3h
  ldr     r0,=208AC20h
  strb    r2,[r9,0Dh]
  ldr     r1,[r0]
  ldrb    r0,[r1,8h]
  cmp     r0,17h
  strneb  r2,[r1,0Ah]
  ; Above is copy pasted, it triggers the game to unpause

  mov r4, 42h ; This tells the rest of the consumable code to use one of the consumable, and play the consumable-used SFX.
  b 0x021EF0F8 ; Return to the consumable code.

  ; Alternate code to not use one of the tickets up:
  ; mov r0, 42h ; This is the SFX that will be played.
  ; b 0x021EF264 ; Return to the consumable code.

  .pool

.close


Add patch to fix some PoR bosses not playing music in boss rando

.nds
.relativeinclude on
.erroronwarning on

; Fixes the boss rush versions of certain bosses so they play the boss music when they're created.
; This is for the boss randomizer.

@Overlay119Start equ 0x02308EC0
@FreeSpace equ @Overlay119Start + 0x4C0

.open "ftc/overlay9_119", @Overlay119Start

.org @FreeSpace
@InitializeEnemyAndOverridePlayBossMusic:
  push r14
  push r1 ; Preserve the music ID

  bl 021D9184h ; InitializeEnemyFromDNA (replaces the line we overwrote to call this custom function)

  pop r0 ; Get the music ID out of the stack
  bl 0204D374h ; PlaySongWithVariableUpdatesExceptInBossRush

  ; Set bit to make the song that was set override the BGM.
  ldr r0, =0211174Ch
  ldr r1, [r0]
  orr r1, r1, 00040000h
  str r1, [r0]

  pop r15

@InitializeEnemyAndOverridePlayBossMusicForLegion:
  push r14
  mov r1, 12h ; Music ID for Destroyer
  bl @InitializeEnemyAndOverridePlayBossMusic
  pop r15

.pool

.close

.open "ftc/overlay9_52", 022D7900h

; Legion
.org 0x022D7A24
  bl @InitializeEnemyAndOverridePlayBossMusicForLegion

.close

.open "ftc/overlay9_64", 022D7900h

; Death
.org 0x022D7BD0
  ; This line usually prevented the code for starting the boss music from running in Jonathan mode.
  ; Just remove it.
  nop

.close

.open "ftc/overlay9_63", 022D7900h

; Stella
.org 0x022D7A4C
  ; This line usually prevented the code for starting the boss music from running in Jonathan mode.
  ; Just remove it.
  nop

.close


.386
.model flat
exception_handler proto
.safeseh exception_handler
end

Fix Windows compileation for VS 2010

.386
.model flat
exception_handler proto c
.safeseh exception_handler
end


; This file is a part of the IncludeOS unikernel - www.includeos.org
;
; Copyright 2015 Oslo and Akershus University College of Applied Sciences
; and Alfred Bratterud
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.

global __arch_start:function
extern kernel_start

[BITS 32]

;; @param: eax - multiboot magic
;; @param: ebx - multiboot bootinfo addr
__arch_start:

    ;; Create stack frame for backtrace
    push ebp
    mov ebp, esp

    ;; hack to avoid stack protector
    mov DWORD [0x1014], 0x89abcdef

    ;; Push params on 16-byte aligned stack
    sub esp, 8
    and esp, -16
    mov [esp], eax
    mov [esp+4], ebx

    call kernel_start

    ;; Restore stack frame
    mov esp, ebp
    pop ebp
    ret

sentinel_table:
    dd sentinel_table ;; 0x0
    dd 0 ;; 0x8
    dd 0 ;; 0x10
    dd 0 ;; 0x18
    dd 0 ;; 0x20
    dd 0x123456789ABCDEF

Remove unused sentinel table for i686


\ This software is the Kestrel-3's first milestone: print a bunch of "A"
\ characters to the console.

	$2000 ORG		( RISC-V ISA spec says we boot here. )

	0 x31 auipc		( X31 = address of next insn )
	assume-gp		( This lets us load big constants )

	x31 gl> uart-port x2 ld	( X2 = uart transmit port )
	x0 65 x3 addi		( X3 = ASCII code for "A" )
-> .again
	x3 x2 0 sb		( send "A" to console )
	.again x0 jal		( repeat forever )

-> uart-port	$0F000000.00000000 D,

Test source update to test both gl> and gs>

\ This software is the Kestrel-3's first milestone: print a bunch of "A"
\ characters to the console.

	$2000 ORG		( RISC-V ISA spec says we boot here. )

	0 x31 auipc		( X31 = address of next insn )
	assume-gp		( This lets us load big constants )

	x31 gl> uart-port x2 ld	( X2 = uart transmit port )
	x0 65 x3 addi		( X3 = ASCII code for "A" )
-> .again
	x3 x2 0 sb		( send "A" to console )
	x31 gl> .ctr x4 ld	( count how many "A"s we send )
	x4 1 x4 addi
	x4 x31 gs> .ctr sd
	.again x0 jal		( repeat forever )

-> uart-port	$0F000000.00000000 D,
-> .ctr		0.0 D,


;;----------------------------------------------------------------------------;;
;;  Increase textbox size in request menu
;;  Copyright 2014 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

;; # REQUEST TITLE #
.arm
.org 020C5804h
MOV     r1, #0x49   ; X Position: original 0x50
MOV     r2, #4      ; Y Position: original 0x03

;; # STAMP GIVEN #
.org 020C5950h
MOV     r1, #0xCD + 10  ; X position

Fix the bold effect for stamps in request menu

;;----------------------------------------------------------------------------;;
;;  Increase textbox size in request menu
;;  Copyright 2014 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

;; # REQUEST TITLE #
.arm
.org 020C5804h
MOV     r1, #0x49   ; X Position: original 0x50
MOV     r2, #4      ; Y Position: original 0x03

;; # STAMP GIVEN #
.org 020C5950h
MOV     r1, #0xCD + 10  ; X position

.org 020C5968h
MOV     r1, #0xCE + 10  ; X position (to paint twice - bold effect)


# multiboot config and setup
.set ALIGN,     1<<0                # align modules on page boundaries
.set MEMINFO,   1<<1                # provide memory map
.set FLAGS,     ALIGN | MEMINFO     # flags
.set MAGIC,     0x1BADB002          # header magic
.set CHECKSUM,  -(MAGIC + FLAGS)    # checksum to prove multi
.section .multiboot
    .align 4
    .long MAGIC
    .long FLAGS
    .long CHECKSUM

# configure early stack (to be replaced once gdt loaded)
.section .stack, "aw", @nobits
    stack_bottom:
        .skip 16384
    stack_top:

.section .text
    .extern     entry
    .global     _start
    .type       _start, @function
    _start:
        mov     $stack_top,%esp
        call    entry
    _stop:
        cli
        1: hlt
        jmp 1b

.size _start, . - _start

Add call for load_gdt, but disabled because it triple faults

# multiboot config and setup
.set ALIGN,     1 << 0              # align modules on page boundaries
.set MEMINFO,   1 << 1              # provide memory map
.set FLAGS,     ALIGN | MEMINFO     # flags
.set MAGIC,     0x1BADB002          # header magic
.set CHECKSUM,  -(MAGIC + FLAGS)    # checksum to prove multi

.section .multiboot

.align  4
.long   MAGIC
.long   FLAGS
.long   CHECKSUM

# configure early stack (to be replaced once gdt loaded)
.section .stack, "aw", @nobits

stack_bottom:
    .skip   16384
stack_top:

.section .text

.extern entry
.extern load_gdt
.global _start
.type   _start, @function
_start:
    movl    $stack_top,%esp
    #call    load_gdt
    call    entry
    cli
halt:
    hlt
    jmp     halt

.size _start, . - _start


use32
global  _interrupt_handler_kbd_wrapper
global  int_handler
global test1
global  run_interrupt
align   4

extern _interrupt_handler_kbd

_interrupt_handler_kbd_wrapper:
    pushad
    call    _interrupt_handler_kbd
    popad
    iret

run_interrupt:
   int 33
   ret

int_handler:
   pushad
   mov ax, 0x08
   mov gs, ax
   call  _interrupt_handler_kbd
   popad
   iret

idt:
   resd 50*2

idtr:
   dw (50*8)-1
   dd idt

test1:
   lidt [idtr]

   mov eax,int_handler
   mov [idt+33*8],ax
   mov word [idt+33*8+2],0x08
   mov word [idt+33*8+4],0x8E00
   shr eax,16
   mov [idt+33*8+6],ax

   mov eax,int_handler
   mov [idt+1*8],ax
   mov word [idt+1*8+2],0x08
   mov word [idt+1*8+4],0x8E00
   shr eax,16
   mov [idt+1*8+6],ax

   ret

Remove unnecessary entry from IDT

use32
global  _interrupt_handler_kbd_wrapper
global  int_handler
global test1
global  run_interrupt
align   4

extern _interrupt_handler_kbd

_interrupt_handler_kbd_wrapper:
    pushad
    call    _interrupt_handler_kbd
    popad
    iret

run_interrupt:
   int 33
   ret

int_handler:
   pushad
   mov ax, 0x08
   mov gs, ax
   call  _interrupt_handler_kbd
   popad
   iret

idt:
   resd 50*2

idtr:
   dw (50*8)-1
   dd idt

test1:
   lidt [idtr]

   mov eax,int_handler
   mov [idt+33*8],ax
   mov word [idt+33*8+2],0x08
   mov word [idt+33*8+4],0x8E00
   shr eax,16
   mov [idt+33*8+6],ax

   ret


Add patch to keep DoS drawbridge down once lowered

.nds
.relativeinclude on
.erroronwarning on

; This patch makes the drawbridge in DoS stay down permanently once you've lowered it once.
; The button will stay depressed, so that you don't need to worry about hitting it every time you walk into the room from the right.

.open "ftc/overlay9_0", 0219E3E0h

.org 0x021A27C8 ; When Soma walks/jumps off the button after pressing it, this line would normally re-raise the button.
  nop ; Remove it so the button doesn't instantly come up.
.org 0x021A2260 ; This line runs when the drawbridge is created, if the drawbridge has already been lowered previously.
  ; Originally this line was doing something useless, storing 0 to a value which is just 0 by default anyway. So we can replace it.
  strb r3, [r4, 5h] ; Store 1 to the button's "pressed" state so the player can't press it again.

.close


Add completely untested multitasking code

taskswapHandler :
	pop ecx	; pop eip into ecx
		pusha
		mov ebx, [currentTaskNum]	; get the current task
		imul ebx, TASK_OBJ_SIZE
		add ebx, RunningTaskList
		mov [ebx+Task_eip], ecx
		mov [ebx+Task_stackLoc], esp	; store the relevent things
			; get the next Task object into ebx
			taskswapHandler.goLoop :
			add ebx, TASK_OBJ_SIZE
			cmp ebx, RunningTaskListEnd
				jge taskswapHandler.doneZeroing
			mov ebx, RunningTaskList
			taskswapHandler.doneZeroing :
			cmp dword [ebx+Task_id], 0
				je taskswapHandler.goLoop
			taskswapHandler.noloopback :
		mov esp, [ebx+Task_stackLoc]
		popa
	push dword [ebx+Task_eip]
	iret

currentTaskNum :
	dd 0x0
RunningTaskList :
	times 32*TASK_OBJ_SIZE db 0x0	; 32 tasks max atm
RunningTaskListEnd :

Task_id equ 0x0
Task_stackLoc equ 0x4
Task_eip equ 0x8
TASK_OBJ_SIZE equ 0xC

registerTask :	; eip in ecx
	pusha
		mov ebx, RunningTaskList
		registerTask.loop :
		cmp dword [ebx+Task_id], 0
			je registerTask.foundTask
		add ebx, TASK_OBJ_SIZE
		jmp registerTask.loop
		registerTask.foundTask :
		mov eax, [currentTaskId]
		mov [ebx+Task_id], eax
		mov [ebx+Task_eip], ecx
		add eax, 1
		mov [currentTaskId], eax
		mov edx, ebx
		sub eax, 1
		mov ebx, TASK_STACK_SIZE
		call Guppy.malloc
		add ebx, TASK_STACK_SIZE*0x200
		mov [edx+Task_stackLoc], ebx
	popa
	ret
unregisterTask :	; ID in ecx
	pusha
		mov ebx, RunningTaskList
		unregisterTask.loop :
		cmp dword [ebx+Task_id], ecx
			je unregisterTask.foundTask
		unregisterTask.foundTask :
		xor ecx, ecx
		mov [ebx+Task_id], ecx
	popa
	ret
currentTaskId :
dd 0x0
TASK_STACK_SIZE equ 2


use32

global _GLOBAL_OFFSET_TABLE_
global __morestack
global abort
global memcmp
global memcpy
global malloc
global free
global start

extern main

start:
    ; rust functions compare esp against [gs:0x30] as a sort of stack guard thing
    ; as long as we set [gs:0x30] to dword 0, it should be ok
    mov [gs:0x30], dword 0
    ; clear the screen a slightly different colour
    mov edi, 0xb8000
    mov ecx, 80*25*2
    mov al, 1
    rep stosb
    ; jump into rust
    call main
    jmp $

_GLOBAL_OFFSET_TABLE_:

__morestack:

abort:
    jmp $

memcmp:
    jmp $

memcpy:
    jmp $

malloc:
    jmp $

free:
    jmp $

Set global GOT at 0 and merge infinite loops

use32

global __morestack
global abort
global memcmp
global memcpy
global malloc
global free
global start

global _GLOBAL_OFFSET_TABLE_
_GLOBAL_OFFSET_TABLE_ equ 0

extern main

start:
    ; rust functions compare esp against [gs:0x30] as a sort of stack guard thing
    ; as long as we set [gs:0x30] to dword 0, it should be ok
    mov [gs:0x30], dword 0
    ; clear the screen a slightly different colour
    mov edi, 0xb8000
    mov ecx, 80*25*2
    mov al, 1
    rep stosb
    ; jump into rust
    call main
abort:
__morestack:
memcmp:
memcpy:
malloc:
free:
    jmp $


BasicUpstart2(start)

	* = $0810 "Main"
start:

	rts

Add optimistic disk loading code to get the map into 000

BasicUpstart2(start)

	* = $0810 "Main"
start:
	jsr	loadmap

	rts

loadmap:
        lda #fname_end-fname
        ldx #<fname
        ldy #>fname
        jsr $FFBD     //; call SETNAM
        lda #$01
        ldx $BA
//#; last used dev number
        bne skip
        ldx #$08      //; default to device 8
skip:  ldy #$00      //; $00 means: load to new address
        jsr $FFBA     //; call SETLFS

        ldx #<$1000
        ldy #>$1000
        lda #$00      //; $00 means: load to memory (not verify)
        jsr $FFD5     //; call LOAD
        bcs error    //; if carry set, a load error has happened
        rts
error:

//	; Accumulator contains BASIC error code

//        ; most likely errors:
//        ; A = $05 (DEVICE NOT PRESENT)
//        ; A = $04 (FILE NOT FOUND)
//        ; A = $1D (LOAD ERROR)
//        ; A = $00 (BREAK, RUN/STOP has been pressed during loading)

//        ... error handling ...
	sta $d020
        rts

fname:  .text "MAP1A"
fname_end:

* = $1000 "map data section"
map:
	.fill 1000,0
mapend:


%include "Ab/State.nasm"

extern ab_act

global ab_interpret_func

section .text

ab_interpret_func:
    call ab_act
    ret

Check the state->st_b.condition when returining from the interpreter

%include "Ab/State.nasm"

extern ab_act

global ab_interpret_func

section .text

; Byte* ab_interpret_func(ExecState*, ExecAction)
ab_interpret_func:
    push rbx
    mov rbx, rdi
    call ab_act
    cmp byte [rbx + ExecState.st_b + ExecStateB.condition], ExecCond_HALTED
    je ab_exit
    int 3
ab_exit:
    pop rbx
    ret


global _start

section .data
	align 16

%include "header.inc"

    sub esp, 128
    fldz
    fld1
    fsave [esp]
    frstor [esp]

%include "footer.inc"


Add proof of concept file for using assembler macros instead of instructions.

.cpu "6502"
.format "flat"
* = $F000

BackgroundColor = $80
INT_Byte_SIZE = 1

VSYNC = $00
VBLANK = $01
WSYNC = $02
COLUBK = $09
TIM64T = $296
INTIM = $284

push .macro address, size
	.for i = \address, i <= \address + (\size - 1), i = i + 1
		LDA i
		PHA
	.next
.endmacro

popTo .macro address, size
	.for i = \address + (\size - 1), i >= \address, i = i - 1
		PLA
		STA i
	.next
.endmacro

// Can replace a consecutive ".push(...) .popTo(...)" as an optimization.
// Copies directly between 2 addresses without using PHA/PLA
copyTo .macro fromAddress, toAddress, size
	.for i = 0, i < \size, i = i + 1
		.let source = \fromAddress + i
		.let destination = \toAddress + i
		LDA source
		STA destination
	.next
.endmacro

Start
	SEI
	CLD
	LDX #$FF
	TXS
	LDA #0
ClearMem
	STA 0,X
	DEX
	BNE ClearMem
MainLoop
	LDA #%00000010
	STA VSYNC
	STA WSYNC
	STA WSYNC
	STA WSYNC
	LDA #43
	STA TIM64T
	LDA #0
	STA VSYNC

	INC BackgroundColor
	//.push BackgroundColor, INT_Byte_SIZE
	//.popTo COLUBK, INT_Byte_SIZE
	// Compiler should optimize above to:
	.copyTo BackgroundColor, COLUBK, INT_Byte_SIZE

WaitForVBlankEnd
	LDA INTIM
	BNE WaitForVBlankEnd
	STA WSYNC
	STA VBLANK
	LDY #192

ScanLoop
	STA WSYNC
	DEY
	BNE ScanLoop

	LDA #2
	STA WSYNC
	STA VBLANK
	LDY #30
OverScanWait
	STA WSYNC
	DEY
	BNE OverScanWait
	JMP MainLoop

// Special memory locations. Tells the 6502 where to go.
* = $FFFC
.word Start
.word Start


;;----------------------------------------------------------------------------;;
;;  Increase textbox size in request menu
;;  Copyright 2014 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

;; # REQUEST TITLE #
.arm
.org 020C5804h
MOV     r1, #0x49   ; X Position: original 0x50
MOV     r2, #4      ; Y Position: original 0x03

Move stamp gives in request menu

;;----------------------------------------------------------------------------;;
;;  Increase textbox size in request menu
;;  Copyright 2014 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

;; # REQUEST TITLE #
.arm
.org 020C5804h
MOV     r1, #0x49   ; X Position: original 0x50
MOV     r2, #4      ; Y Position: original 0x03

;; # STAMP GIVEN #
.org 020C5950h
MOV     r1, #0xCD + 10  ; X position


.nds
.relativeinclude on
.erroronwarning on

.open "ftc/arm9.bin", 02000000h

; Skip the screen where the player has to sign their name and press OK when starting a new game.

.org 0x02045E8C ; Code that sets the name signing menu's state to 3 after zeroing out the name pixel data.
  movne r0, 6h ; Instead set the state to 6, meaning the state where the player has pressed OK and the new game is now starting.

.close

Tweak to skip name signing patch

.nds
.relativeinclude on
.erroronwarning on

.open "ftc/arm9.bin", 02000000h

; Skip the screen where the player has to sign their name and press OK when starting a new game.

.org 0x02045E8C ; Code that sets the name signing menu's state to 3 after zeroing out the name pixel data.
  movne r0, 6h ; Instead set the state to 6, meaning the state where the player has pressed OK and the new game is now starting.

.org 0x02045E78 ; Code that displays the name signing menu on the screen.
  nop ; Delete it to prevent the name signing screen from being visible for a split second when starting a new game.

.close


// load sid music

.var music = LoadSid("res/jeff_donald.sid")
//.var music = LoadSid("res/demo.sid")
.pc = music.location
.fill music.size, music.getData(i)

.var picture = LoadBinary("res/dcc.prg")
.pc = $2000 - 2 "Bitmap Data"
.fill picture.getSize(), picture.get(i)

Print additional info about SID file

// load sid music

//.var music = LoadSid("res/jeff_donald.sid")
.var music = LoadSid("res/demo.sid")
.pc = music.location "Music"
.fill music.size, music.getData(i)

.pc = $2000 - 2 "Bitmap Data"
.var picture = LoadBinary("res/dcc.prg")
.fill picture.getSize(), picture.get(i)

//----------------------------------------------------------
// Print the music info while assembling
.print ""
.print "SID Data"
.print "--------"
.print "location=$"+toHexString(music.location)
.print "init=$"+toHexString(music.init)
.print "play=$"+toHexString(music.play)
.print "songs="+music.songs
.print "startSong="+music.startSong
.print "size=$"+toHexString(music.size)
.print "name="+music.name
.print "author="+music.author
.print "copyright="+music.copyright

.print ""
.print "Additional tech data"
.print "--------------------"
.print "header="+music.header
.print "header version="+music.version
.print "flags="+toBinaryString(music.flags)
.print "speed="+toBinaryString(music.speed)
.print "startpage="+music.startpage
.print "pagelength="+music.pagelength


.nds
.relativeinclude on
.erroronwarning on

.open "ftc/overlay9_0", 0219E3E0h

; This makes it so you don't need to draw a Magic Seal to kill a boss.

.org 0x02213C04 ; Location of the boss-killed code for loading the current game mode.
  mov r0, 1 ; Always load 1 (meaning Julius mode).

.close

Fix bug in dos seal drawing skip patch

.nds
.relativeinclude on
.erroronwarning on

.open "ftc/overlay9_0", 0219E3E0h

; This patch makes it so you don't need to draw a Magic Seal to kill a boss.

.org 0x02213C04 ; Location of the seal drawing code for loading the current game mode.
  mov r0, 1 ; Always load 1 (meaning Julius mode).

; The above change causes a bug with the practice seal menu, where attempting to practice a seal will cause the screen to go black and the game to softlock.
.org 0x021F1BF8 ; Location of code in the practice menu to decide which type of seal to do.
  mov r1, 0 ; Instead of setting argument r1 to 2 (meaning a practice seal) we set it to 0 (meaning an automatically drawn example seal). This doesn't softlock the game.

.close


org $0fff

load_address:
    $01 $10 @(low basic_end) @(high basic_end) $01 $00 $9e "4109" 0
basic_end:
    $00 $00

Make SYS call to label main, not the end of the BASIC program.

org $0fff

load_address:
    $01 $10 @(low basic_end) @(high basic_end) $01 $00 $9e @(princ main nil) 0
basic_end:
    $00 $00


;;----------------------------------------------------------------------------;;
;;  Align the position of the textbox in team menu
;;  Copyright 2015 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

.arm

;; Character face icon
.org 0x02130478
  ADD     R2, R2, #0x19 - 1     ; Y position

;; Health state
.org 0x02130A08
  MOV     R2, #0x2A + 1         ; Y position

Move technique name and PM in team menu

;;----------------------------------------------------------------------------;;
;;  Align the position of the textbox in team menu
;;  Copyright 2015 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

.arm

;; Character face icon
.org 0x02130478
  ADD     R2, R2, #0x19 - 1     ; Y position

;; Health state
.org 0x02130A08
  MOV     R2, #0x2A + 1         ; Y position

;; Technique name
.org 0x021311AC
  MOV     R2, #7 - 3            ; Y position

;; Technique magic
.org 0x021311EC
  MOV     R2, #8 - 2            ; Y position


;
; Assembly "Hello, World!" for Linux
;

/* Properly defined in <sys/syscall.h> */
%define SYS_exit	1
%define SYS_write	4

	section .text

	global _start
_start:
	; gdb doesn't like to stop at the entry point address, so
	; we put a nop here for pure convenience
	nop

write_hello:
	mov edx, hello_len
	mov ecx, hello

.loop:
	mov eax, SYS_write
	mov ebx, 1			; stdout
	int 80h

	cmp eax, -4096
	ja error

	add ecx, eax
	sub edx, eax
	jnz .loop

ok:
	mov eax, SYS_exit
	xor ebx, ebx
	int 80h
	hlt

error:
	mov eax, SYS_exit
	mov ebx, 1		; Error
	int 80h
	hlt

	section .rodata
hello:	db "Hello, World!", 10
hello_len equ $-hello


Add patch to make gergoth not be on top of player coming from left

.nds
.relativeinclude on
.erroronwarning on

; This patch makes Gergoth appear on the right half of his room when the player enters from the left so he's not on top of the player.

.open "ftc/overlay9_36", 022FF9C0h

.org 0x022FFAF0 ; Code in Gergoth's initialization that normally floors him in different ways depending on his var A.
  ; First we simplify the flooring code (to make room for new code) by always doing the same thing instead of having 4 different possibilities for 4 different var As.
  mov r0, 0B0000h
  str r0, [r5, 30h] ; Set Gergoth's Y pos to 0xB0.

  ldr r0, =020CA95Ch
  ldr r0, [r0] ; Load player's X pos.
  cmp r0, 80000h ; Check if player came in on the left half of the room.
  movlt r0, 0C0000h
  strlt r0, [r5, 2Ch] ; Move Gergoth's X pos to 0xC0, close to the right wall.
  b 022FFB48h
  .pool

.close


Add patch to start Julius with the Tower Key

.nds
.relativeinclude on
.erroronwarning on

.open "ftc/overlay9_0", 0219E3E0h

; This patch starts the player with the Tower Key in Julius mode.
; This is so the player doesn't get softlocked by the randomizer in Julius mode.

.org 0x021F6280
  ; Give all 5 magic seals (simplified version of the original code that was here)
  mov r4, 1Fh
  ldr r0, =020F7254h
  strb r4, [r0]
  ; Then give Tower Key
  mov r0, 2h
  mov r1, 39h
  bl 021E7870h ; GiveItem
  b 021F62A8h ; Jump to after the constant pool
  .pool

.close


[ORG 0x10800]

PMode:
	mov eax, 0xFEEDFACE
	mov ecx, 0xF00DD00D
	mov edx, 0xBAADBEEF
.jmpy:
	hlt
	jmp .jmpy

Change setup for protected mode

[ORG 0x10800]
[BITS 32]
PMode:
	mov eax, 0x10
	mov ds, ax
	mov es, ax
	mov fs, ax
	mov gs, ax
	mov ss, ax
	mov esp, 0x90000
	mov ebp, esp
.jmpy:
	hlt
	jmp .jmpy


Add asm patch to break balore blocks with any weapon

.nds
.relativeinclude on
.erroronwarning on

.open "ftc/overlay9_0", 0219E3E0h

; This makes it so that all melee weapons can break balore blocks, not just Julius's whip.

.org 0x02212AB0 ; Branch of a switch statement taken for all melee weapons except Julius's whip.
  b 02212D64h ; Instead take the branch taken for Julius's whip.

.close


Add in example that was provided to create a basic "kernel" for the atari game for rendering to the screen.

processor 6502
include "vcs.h"
include "macro.h"

SEG
ORG $F000

Reset

StartOfFrame

; Start of vertical blank processing
lda #0
sta VBLANK

lda #2
sta VSYNC

; 3 scanlines of VSYNCH signal...
sta WSYNC
sta WSYNC
sta WSYNC

lda #0

sta VSYNC

; 37 scanlines of vertical blank...
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC

; 192 scanlines of picture...
ldx #0
REPEAT 192; scanlines
    inx
    stx COLUBK
    sta WSYNC
REPEND

lda #%01000010

sta VBLANK                     ; end of screen - enter blanking

; 30 scanlines of overscan...
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC
sta WSYNC

jmp StartOfFrame

ORG $FFFA

.word Reset          ; NMI
.word Reset          ; RESET
.word Reset          ; IRQ

END


//============================================================
// .efo header
//============================================================

.pc = $0

.text "EFO2"          // fileformat magic
.word prepare         // prepare routine
.word setup           // setup routine
.word interrupt       // irq handler
.word 0               // main routine
.word 0               // fadeout routine
.word 0               // cleanup routine
.word 0               // location of playroutine call

// tags
//.byt "P", $04, $07    // range of pages in use
//.byt "I",$10,$1f      // range of pages inherited
//.byt "Z",$02,$03      // range of zero-page addresses in use
//.byt "S"              // i/o safe
//.byt "X"              // avoid loading
//.byt "M",<play,>play  // install music playroutine
.byte 0                 // end-of-tags

.word load_addr

load_addr:
.import source "init.asm"
.import source "fx.asm"
.import source "main.asm"

Fix load address - still not working :(

//============================================================
// .efo header
//============================================================

.pc = $2000

.text "EFO2"          // fileformat magic
.word prepare         // prepare routine
.word setup           // setup routine
.word interrupt       // irq handler
.word 0               // main routine
.word 0               // fadeout routine
.word 0               // cleanup routine
.word 0               // location of playroutine call

// tags
//.byt "P", $04, $07    // range of pages in use
//.byt "I",$10,$1f      // range of pages inherited
//.byt "Z",$02,$03      // range of zero-page addresses in use
//.byt "S"              // i/o safe
//.byt "X"              // avoid loading
//.byt "M",<play,>play  // install music playroutine
.byte 0                 // end-of-tags

.word load_addr

load_addr:
.import source "init.asm"
.import source "fx.asm"
.import source "main.asm"


Add completely untested multitasking code

taskswapHandler :
	pop ecx	; pop eip into ecx
		pusha
		mov ebx, [currentTaskNum]	; get the current task
		imul ebx, TASK_OBJ_SIZE
		add ebx, RunningTaskList
		mov [ebx+Task_eip], ecx
		mov [ebx+Task_stackLoc], esp	; store the relevent things
			; get the next Task object into ebx
			taskswapHandler.goLoop :
			add ebx, TASK_OBJ_SIZE
			cmp ebx, RunningTaskListEnd
				jge taskswapHandler.doneZeroing
			mov ebx, RunningTaskList
			taskswapHandler.doneZeroing :
			cmp dword [ebx+Task_id], 0
				je taskswapHandler.goLoop
			taskswapHandler.noloopback :
		mov esp, [ebx+Task_stackLoc]
		popa
	push dword [ebx+Task_eip]
	iret

currentTaskNum :
	dd 0x0
RunningTaskList :
	times 32*TASK_OBJ_SIZE db 0x0	; 32 tasks max atm
RunningTaskListEnd :

Task_id equ 0x0
Task_stackLoc equ 0x4
Task_eip equ 0x8
TASK_OBJ_SIZE equ 0xC

registerTask :	; eip in ecx
	pusha
		mov ebx, RunningTaskList
		registerTask.loop :
		cmp dword [ebx+Task_id], 0
			je registerTask.foundTask
		add ebx, TASK_OBJ_SIZE
		jmp registerTask.loop
		registerTask.foundTask :
		mov eax, [currentTaskId]
		mov [ebx+Task_id], eax
		mov [ebx+Task_eip], ecx
		add eax, 1
		mov [currentTaskId], eax
		mov edx, ebx
		sub eax, 1
		mov ebx, TASK_STACK_SIZE
		call Guppy.malloc
		add ebx, TASK_STACK_SIZE*0x200
		mov [edx+Task_stackLoc], ebx
	popa
	ret
unregisterTask :	; ID in ecx
	pusha
		mov ebx, RunningTaskList
		unregisterTask.loop :
		cmp dword [ebx+Task_id], ecx
			je unregisterTask.foundTask
		unregisterTask.foundTask :
		xor ecx, ecx
		mov [ebx+Task_id], ecx
	popa
	ret
currentTaskId :
dd 0x0
TASK_STACK_SIZE equ 2


;;----------------------------------------------------------------------------;;
;;  Align the position of the textbox in the effect of items
;;  Copyright 2014 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

.thumb
;; Item effect
.org 0x02117D4E
  MOV    R1, #0x60 ; X POS -> Original 0x62

;; Slot color
.org 0x021170DE
  MOV    R1, #0x9E - 4 ; X POS

Increase textbox width of item name in menu

;;----------------------------------------------------------------------------;;
;;  Align the position of the textbox in the effect of items
;;  Copyright 2014 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

.thumb
;; Item effect
.org 0x02117D4E
  MOV    R1, #0x60 ; X POS -> Original 0x62

;; Slot color
.org 0x021170DE
  MOV    R1, #0x9E - 4 ; X POS

.thumb
;; Increase the size of the item name textbox
.org 0x02116E90
  MOV     R0, #0x14 + 1     ; Width / 8


Add PoR patch to fix bonus STR not affecting martial art

.nds
.relativeinclude on
.erroronwarning on

; In vanilla PoR Martial Art does not take bonus STR (e.g. from STR Boost) into account when calculating its damage.
; This patch causes it to take bonus STR into account.

.open "ftc/overlay9_0", 021CDF60h

.org 0x022176CC
  ldrsh r1, [r4, 18h] ; Load bonus STR from 02111FEC
  add r0, r0, r1 ; Add base STR (already in r0) to bonus STR
  mov r0, r0, lsl 1h ; Double the strength value to get the damage martial art should do (same as in vanilla, except in vanilla it used float multiplication instead of shifting)
  nop
  nop

.close


; Based on http://codekata.com/kata/kata09-back-to-the-checkout/

			org	8000h

include src/zx-spec.asm

			spec_init

	describe 'price'
		it 'Returns 0 for no items'

			ld	a,$FF
			call	price
			assert_a_equal	0

			spec_end

price			proc
			ret
			endp

			end	8000h

Return 0 for no items

; Based on http://codekata.com/kata/kata09-back-to-the-checkout/

			org	8000h

include src/zx-spec.asm

			spec_init

	describe 'price'
		it 'Returns 0 for no items'

			ld	a,$FF
			call	price
			assert_a_equal	0

			spec_end

price			proc
			ld	a,0
			ret
			endp

			end	8000h


Add patch to make wygol unlocked from the start in OoE

.nds
.relativeinclude on
.erroronwarning on

.open "ftc/overlay9_22", 02223E00h

; Shanoa mode: Makes Ecclesia and Wygol be unlocked from the start.
.org 0x0223B7F4 ; Code that would normally set Ecclesia as the default unlocked area.
  ldr r14, =021003CCh
  ldr r0, [r14]
  mov r1, 0x0000003C ; Sets both bits for Ecclesia and Wygol
  orr r0, r0, r1
  str r0, [r14]
  b 0223B840h
  .pool

.close


LLB R1, 70 #Address
LHB R1, 0xCC
LLB R2, 59
LLB R12, 34
LLB R13, 45
LLB R14, 78

SW R1, R1, 0
SW R12, R1, 1
SW R13, R1, 2
SW R14, R1, 3

LW R3, R1, 0
ADD R4, R2, R2
LW R7, R1, 1
ADD R4, R4, R4
LW R8, R1, 2
ADD R4, R4, R4
LW R9, R1, 3
ADD R4, R4, R4

SW R2, R1, 0
LW R5, R1, 1
LW R6, R1, 3
HLT

Write to 0x70 instead 46

LLB R1, 0x70 #Address
LHB R1, 0xCC
LLB R2, 59
LLB R12, 34
LLB R13, 45
LLB R14, 78

SW R1, R1, 0
SW R12, R1, 1
SW R13, R1, 2
SW R14, R1, 3

LW R3, R1, 0
ADD R4, R2, R2
LW R7, R1, 1
ADD R4, R4, R4
LW R8, R1, 2
ADD R4, R4, R4
LW R9, R1, 3
ADD R4, R4, R4

SW R2, R1, 0
LW R5, R1, 1
LW R6, R1, 3
HLT


bits 64
	VFMADDPD xmm0, xmm1, [0], xmm3
	VFMADDPD xmm0, xmm1, xmm2, [0]
	VFMADDPD ymm0, ymm1, [0], ymm3
	VFMADDPD ymm0, ymm1, ymm2, [0]

Fix file with no final newline


;Testname=unoptimized; Arguments=-O0 -fbin -obr3187743.bin; Files=stdout stderr br3187743.bin
;Testname=optimized;   Arguments=-Ox -fbin -obr3187743.bin; Files=stdout stderr br3187743.bin

	bits 64

	vlddqu	xmm0,[edi]
	vlddqu	ymm0,[edi]


;
; Copyright Mehdi Sotoodeh.  All rights reserved.
; <mehdisotoodeh@gmail.com>
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that source code retains the
; above copyright notice and following disclaimer.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;

include defines.inc

PUBPROC readTSC
    rdtscp
    shl     rdx,32
    xchg    eax,edx
    xchg    rdx,rax
    ret
ENDPROC readTSC
END

Include upper 32-bits of tsc.

;
; Copyright Mehdi Sotoodeh.  All rights reserved.
; <mehdisotoodeh@gmail.com>
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that source code retains the
; above copyright notice and following disclaimer.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;

include defines.inc

PUBPROC readTSC
    rdtscp
    shl     rdx,32
    add     rax,rdx
    ret
ENDPROC readTSC
END


Add patch to prevent overlapping events in first room of DoS

.nds
.relativeinclude on
.erroronwarning on

; This patch fixes issues that could happen in the first room of the castle if the player got one of the bad endings before seeing the cutscene with Hammer in that first room.
; The cutscene with Hammer would play at the same time as the bad ending cutscene, and could allow skipping the cutscene to get out of the room, escaping from the bad ending.

@Overlay41Start equ 0x02308920
@FreeSpace equ @Overlay41Start + 0x1DC

.open "ftc/overlay9_0", 0219E3E0h

.org 0x021C84DC ; In Object5ECreate (cutscene in the first room of the castle with Hammer)
  bne @CheckInBadEnding

.close

.open "ftc/overlay9_41", @Overlay41Start

.org @FreeSpace
@CheckInBadEnding:
  ldr r1, =020F7188h ; Bitfield of event flags
  ldr r1, [r1]
  ands r1, r1, 24000h ; Check the two bad ending flags
  beq 0x021C84F4 ; If neither are set, continue on with this event code
  b 0x021C84E0 ; Otherwise, delete this event
  .pool

.close


Add patch for boss orbs to reload some boss rooms in OoE

.nds
.relativeinclude on
.erroronwarning on

; This patch makes it so getting a boss orb in Mystery Manor or Ecclesia will reload the room.
; This is because the cutscene after beating Albus/Barlowe won't play until the room is reloaded.
; Albus/Barlowe normally reload the room on defeat, but in boss randomizer something else needs to do it.

@Overlay86Start equ 0x022EB1A0
@FreeSpace equ 0x022EB1A0 + 0x48

.open "ftc/arm9.bin", 02000000h

.org 0x02061254 ; At the end of the function for the boss orb being picked up
  b @BossOrbCheckReloadRoom

.close

.open "ftc/overlay9_86", @Overlay86Start ; Free space overlay

.org @FreeSpace
@BossOrbCheckReloadRoom:
  ldr r0, =02100790h
  ldrb r0, [r0] ; Read the current game mode
  cmp r0, 0h ; Shanoa mode
  bne @BossOrbCheckReloadRoomEnd

  ldr r0, =020FFCB9h
  ldrb r0, [r0] ; Read the current area index
  cmp r0, 0Eh ; Mystery Manor
  beq @BossOrbReloadRoomMysteryManor
  cmp r0, 2h ; Ecclesia
  bne @BossOrbCheckReloadRoomEnd

@BossOrbReloadRoomEcclesia:
  mov r0, 2h ; Area, Ecclesia
  mov r1, 0h ; Sector
  mov r2, 6h ; Room
  b @BossOrbReloadRoom

@BossOrbReloadRoomMysteryManor:
  mov r0, 0Eh ; Area, Mystery Manor
  mov r1, 0h ; Sector
  mov r2, 9h ; Room

@BossOrbReloadRoom:
  mov r3, 0C0h ; X pos
  mov r4, 0B0h ; Y pos
  str r3, [r13]
  bl 0203AFD0h ; TeleportPlayer
  bl 0203B014h ; TriggerRoomTransition

@BossOrbCheckReloadRoomEnd:
  ; Return to the normal boss orb code
  add r13, r13, 34h ; Replace line overwritten to jump here
  b 2061258h
  .pool

.close


Test of immediate handling on 64-bit mode

bits 64

	mov rax,1234567890abcdefh
	mov eax,1234567890abcdefh
	mov rax,dword 1234567890abcdefh
	mov rax,qword 1234567890abcdefh
	mov dword [rsi],1234567890abcdefh
	mov qword [rsi],1234567890abcdefh
	mov dword [rsi],dword 1234567890abcdefh
	mov qword [rsi],dword 1234567890abcdefh
;	mov qword [rsi],qword 1234567890abcdefh		; Error
;	mov [rsi],qword 1234567890abcdefh		; Error
	mov [rsi],dword 1234567890abcdefh


.nds
.relativeinclude on
.erroronwarning on

; This patch makes the color at index 2 in Shanoa's palette (the glyph on her back) not glow and switch between colors automatically.

.open "ftc/arm9.bin", 02000000h

.org 0x0208C990
  nop

.close


;;----------------------------------------------------------------------------;;
;;  Reduce the font space
;;  Copyright 2015 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

.arm

.org 020C64E0h
.area 4h
  MOV     R1, #8 - 4
.endarea

Remove any space between chars

;;----------------------------------------------------------------------------;;
;;  Reduce the font space
;;  Copyright 2015 Benito Palacios (aka pleonex)
;;
;;  Licensed under the Apache License, Version 2.0 (the "License");
;;  you may not use this file except in compliance with the License.
;;  You may obtain a copy of the License at
;;
;;      http://www.apache.org/licenses/LICENSE-2.0
;;
;;  Unless required by applicable law or agreed to in writing, software
;;  distributed under the License is distributed on an "AS IS" BASIS,
;;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;  See the License for the specific language governing permissions and
;;  limitations under the License.
;;----------------------------------------------------------------------------;;

.arm

.org 020C64E0h
.area 4h
  MOV     R1, #8 - 8
.endarea