Les membres ayant 30 points peuvent parler sur les canaux annonces, projets et hs du chat.
La shoutbox n'est pas chargée par défaut pour des raisons de performances. Cliquez pour charger.

Forum Casio - Projets de programmation


Index du Forum » Projets de programmation » Barnsley fern (516 bytes)
Tbit Hors ligne Membre Points: 14 Défis: 0 Message

Barnsley fern (516 bytes)

Posté le 29/07/2020 21:16

Hi,

this is a proof of concept graphics effect abusing the fact that the program header is loaded alongside the Add-in. I don't know if this has been done yet, but I'm sure there are many more possibilities for interesting effects, especially when using 100% assembly. Sources are included for anyone who wants to have a try

The effect itself is very simple:


Tested on an fx-9750GII, doesn't seem to work on the official emulator though, maybe one of you knows why?

Fichier joint


Lephenixnoir Hors ligne Administrateur Points: 24229 Défis: 170 Message

Citer : Posté le 29/07/2020 21:20 | #


I see so you store data and code within the G1A header to save space? Nice compacity trick!

# TODO: why does 'bra _main' not work?

The assembler is unable to construct a PC-relative address for _main since it is in a different compilation unit.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Tbit Hors ligne Membre Points: 14 Défis: 0 Message

Citer : Posté le 29/07/2020 21:21 | #


Ah, so how could you get around that problem? I honestly don't know much about assembly or linking.
Lephenixnoir Hors ligne Administrateur Points: 24229 Défis: 170 Message

Citer : Posté le 29/07/2020 21:23 | #


The way to go is exactly as you did - create a reference to the symbol that the linker can resolve and substitute, then load it and call it. This is a very common structure in all SuperH assembly code to call external functions.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Tbit Hors ligne Membre Points: 14 Défis: 0 Message

Citer : Posté le 29/07/2020 21:27 | #


Yeah, but it would be nice to only do
bra _main
nop

since that would save some bytes at the end
For example, the main code is always located at offset 0x22, so is it possible to hard-code the value instead?
Lephenixnoir Hors ligne Administrateur Points: 24229 Défis: 170 Message

Citer : Posté le 29/07/2020 21:31 | #


You can do mov #22, r0; jmp @r0; nop, or since you also know the offset of the entry point (0x200), you can also do bra @(offset,pc) where offset is 0x200 - 0x22 - 4. (The -4 is because PC points 4 bytes after the current instruction.)
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Tbit Hors ligne Membre Points: 14 Défis: 0 Message

Citer : Posté le 29/07/2020 21:42 | #


For the first one I would need the full address as a long, which is basically what I'm doing already. For the second one, I get a bad expression error If I try to manually write the displacement value, like so:
bra -2

I get this very cryptic error message:
(.entry+0x0): relocation truncated to fit: R_SH_IND12W against `*ABS*'+fffffffffffffffa
Lephenixnoir Hors ligne Administrateur Points: 24229 Défis: 170 Message

Citer : Posté le 29/07/2020 22:11 | #


The first one saves you the .long which is a 4-byte gain. Not optimal, but still something.

As for the second one, the error messages means that the linker, while attempting to adjust the target of bra after selecting the location of the _entry and _main functions, found itself confronted to the problem that the argument of bra only has 12 bits (this particular case of adjusting addresses is named R_SH_IND12W) and the value to be put here did not fit.

This reason it did not fit is because it is absolute (ie. it starts counting at the 0 of the address space) instead of being relative to either the file header, or a program section, or a symbol. You should provide a relative address suitable for relocation by using a different format.

start:
  bra start - 0x200 + 0x22
  nop

The @(offset,pc) I mentioned earlier does not work here, sorry for the confusion.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Tbit Hors ligne Membre Points: 14 Défis: 0 Message

Citer : Posté le 29/07/2020 22:22 | #


Perfect, thanks
bra (start - 0x200 + 0x22)/2+4

worked for me! This brought the size down to 516 bytes.
Lephenixnoir Hors ligne Administrateur Points: 24229 Défis: 170 Message

Citer : Posté le 29/07/2020 22:24 | #


Good catch, now this can't be made any more compact since all 1-instruction jumps (bt/bf) are conditional.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)

LienAjouter une imageAjouter une vidéoAjouter un lien vers un profilAjouter du codeCiterAjouter un spoiler(texte affichable/masquable par un clic)Ajouter une barre de progressionItaliqueGrasSoulignéAfficher du texte barréCentréJustifiéPlus petitPlus grandPlus de smileys !
Cliquez pour épingler Cliquez pour détacher Cliquez pour fermer
Alignement de l'image: Redimensionnement de l'image (en pixel):
Afficher la liste des membres
:bow: :cool: :good: :love: ^^
:omg: :fusil: :aie: :argh: :mdr:
:boulet2: :thx: :champ: :whistle: :bounce:
valider
 :)  ;)  :D  :p
 :lol:  8)  :(  :@
 0_0  :oops:  :grr:  :E
 :O  :sry:  :mmm:  :waza:
 :'(  :here:  ^^  >:)

Σ π θ ± α β γ δ Δ σ λ
Veuillez donner la réponse en chiffre
Vous devez activer le Javascript dans votre navigateur pour pouvoir valider ce formulaire.

Si vous n'avez pas volontairement désactivé cette fonctionnalité de votre navigateur, il s'agit probablement d'un bug : contactez l'équipe de Planète Casio.

Planète Casio v4.3 © créé par Neuronix et Muelsaco 2004 - 2024 | Il y a 90 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements

Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd