Glitch City Laboratories Forums

Lab δ: Tech => Programming/Scripting/Development/Web Design => Topic started by: Ganix on December 10, 2016, 09:57:42 pm

Title: [Utility] 8F Helper - gbz80aid
Post by: Ganix on December 10, 2016, 09:57:42 pm
Heya guys,

After a good bit of going back-and-forth to the Wiki (and later back-and-forth to a text file) in order to look up values for the 8F glitch, I decided to write a program in C using lookup tables that could directly parse gbz80 assembly and machine code, then output the results to the console pretty quickly (~12 milliseconds) in a variety of outputs.

You can check it out over at its Github page, 8F Helper (https://github.com/KernelEquinox/8F-Helper).

As an example of its output, I took the assembly instructions for the perpetually resetting save file (http://forums.glitchcity.info/index.php?topic=6638.msg192694.html#msg192694) by Wacko and converted them to 8F items with the utility.

test.asm:
Code: [Select]
ld l,$6E
ld (hl),$36
ld a,$D3
ld ($D36F),a
inc b
ld c,$1c
ld h,$78
ld l,$48 ; 1c:7848: SaveSAVtoSRAM
ld b,c
call $35d6 ; BankSwitch
jp nc,$1f49 ; SoftReset

Command and output:
Code: [Select]
root@gbdev:~# gbz80aid -o gen1 -f test_code.asm

Item            Quantity
========================
X Accuracy      x110
Max Revive      x54
Lemonade        x211
TM34            x111
TM11            x4
Awakening       x28
Carbos          x120
X Accuracy      x72
X Attack        x205
TM14            x53
TM10            x73
Old Amber       xAny

Hope it can be of use! ;D
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: ISSOtm on December 11, 2016, 05:28:02 am
Sure it'll be useful ! (And kudos for running this on Linux :D)

That reminds me of my old JavaScript "compiler" (http://prama-initiative.com/8F/beta/), and I'd like to suggest some features that came to my mind as I was developing it.

- A -w option that would enable warnings (such as invalid items, using key items with a non-one quantity, two stacks of the same item...).
- Turn the gen2 option into gen2i to make room for the next option.
- Add a gen2b that outputs box names for more recent Gen II ACE exploits.
- More label support.
- Different syntax ? There are multiple syntax used out there.

Which compiler do you use ?

I have some knowledge about C and GBz80, so I forked your repository and did some edits.
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: Wack0 on December 11, 2016, 08:42:47 am
Nice work :)
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: Ganix on December 11, 2016, 10:10:59 pm
- A -w option that would enable warnings (such as invalid items, using key items with a non-one quantity, two stacks of the same item...).
- Turn the gen2 option into gen2i to make room for the next option.
- Add a gen2b that outputs box names for more recent Gen II ACE exploits.
- More label support.
- Different syntax ? There are multiple syntax used out there.

Thanks for the feedback! I'll start experimenting with the label support and warnings, and I'll start doing research into Gen II ACE exploits.

And yeah, the pointer operations are pretty hacky; I'll work on standardizing the code and sticking with one style. :D

Which compiler do you use ?

I have some knowledge about C and GBz80, so I forked your repository and did some edits.

Oh awesome! As for my go-to compiler, I use gcc almost exclusively, but I use Visual Studio's cl.exe compiler on very rare occasions.
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: ISSOtm on December 12, 2016, 09:37:42 am
The edits are sitting on my PC as I'm writing stuff in gedit. I dunno which command you use to compile, so here's mine :
Code: [Select]
gcc gbz80aid.c -o gbz80aid -std=c99

Progression thus far :
Added bounds checking on options using arguments (-f and -o).
Added comments when I needed them.
Added a -v (version) argument, prints light version info.
Added support for brackets instead of parentheses.
Replaced some "malloc"s by some local strings.
Adding a -ofs option of asm format.
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: ISSOtm on December 14, 2016, 08:39:37 am
I've sent a pull request, but I'm working on implementing some more features and cleaning stuff up.
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: Ganix on December 14, 2016, 11:54:00 am
I've sent a pull request, but I'm working on implementing some more features and cleaning stuff up.

Oh awesome! I've merged the pull request with the changes in the master repo, which contains support for multiple labels, some error handling, and more efficient/standardized code than my initial master commit. ;D

As for my compilation command, I usually just use:
Code: [Select]
gcc -o gbz80aid gbz80aid.c
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: ISSOtm on December 15, 2016, 11:39:17 am
You never get any warnings when compiling ?
I got a ton when I ran this command, mostly about "for(int i = 0; ...", which went away when I switched to C99 standard (-std=c99)

I added "-Wall -Wextra" and commited changes to remove almost all warnings.
I'm also getting ready to write a box name format for Gen II.
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: Ganix on December 16, 2016, 05:57:49 pm
Nah, no warnings from the compiler; I'm using GCC 6.2.1 on Kali 2016.2 Rolling. Same with GCC using MinGW on Windows.

It only complains about warnings whenever I enable all warnings during compilation, but it's otherwise quiet.
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: Yeniaul on December 16, 2016, 08:22:35 pm
...why are you running Kali for everyday use?
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: Wack0 on December 17, 2016, 05:57:17 am
...why are you running Kali for everyday use?

FTFY
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: ISSOtm on December 17, 2016, 03:42:26 pm
I have GCC 4.9, if I'm correct (I'm on my Windows right now, so no checking that 'cause I got stuff to do before I reboot).
That might explain.
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: Ganix on December 17, 2016, 07:17:09 pm
...why are you running Kali for everyday use?
Probably PTSD from taking the OSCP and OSCE.

...why are you running Kali for everyday use?

To spread holiday cheer (https://holidayhackchallenge.com/2016/). ;D

I have GCC 4.9, if I'm correct (I'm on my Windows right now, so no checking that 'cause I got stuff to do before I reboot).
That might explain.
Oh yeah, GCC 5 changed the default from 89 to 11. :P
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: Ganix on December 21, 2016, 03:42:08 pm
I apologize for the double post, but I just pushed a pretty big update to the repo that will, among other things, greatly help with determining the inputs for the recently-posted Full Control (http://forums.glitchcity.info/index.php?topic=7744.0) 8F RAM manipulation method.


Due to an oversight on my end, I had neglected to implement translation for the JP instruction and only supported the JR instruction; it now includes full support for both the JP and JR instructions, even when using custom offsets with the -ofs flag.

The program now supports both the reading and printing of gbz80 ASM in a variety of formats, primarily the BGB format—for example, the instructions ldi (hl),a and ld (hl+),a are treated as the same instruction and can be output in BGB format by specifying the -o bgb flag.

Most notably, however, the program can now convert gbz80 ASM (and gbz80 machine code) into button presses for use with the Full Control 8F method. In this mode, each line of button presses represents a single byte written to memory, and even calculated the total number of button presses required (just for fun). You can specify this mode with the -o joy flag.


As an example of the 8F Full Control button output, here's a snippet of the output when using the ASM code for credits warping on Super Mario Land 2 from TheZZAZZGlitch's recent ACE video (https://www.youtube.com/watch?v=SL_Zuc0tlvo).

SAMPLE OUTPUT:
Code: [Select]
C:\gbdev>gbz80aid.exe -o joy -f sml2_ace.asm

Joypad Values:

A
DOWN UP LEFT RIGHT B A A
RIGHT SELECT B B
START B A A
DOWN A DOWN DOWN
UP DOWN LEFT RIGHT START SELECT B A A
DOWN UP LEFT RIGHT START SELECT B A A
START B A A
UP LEFT RIGHT START A A
DOWN LEFT RIGHT RIGHT

[92 lines omitted]

LEFT B B
DOWN LEFT START SELECT B A A
LEFT B B
LEFT RIGHT START SELECT B B
DOWN UP RIGHT RIGHT
LEFT B B
DOWN UP B A A
DOWN UP LEFT LEFT
DOWN UP RIGHT RIGHT
START + SELECT

Total number of button presses: 506

If you're interested in testing it out, you can grab the Windows executable all zipped up here (https://github.com/KernelEquinox/8F-Helper/releases/download/v1.2/gbz80aid.zip).
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: Evie (retired from head adminship) on December 21, 2016, 04:19:37 pm
Very cool! It's funny these are button combinations like classic game cheats. What would the Konami code or Up-Down-Left-Right-A+Start give, lol?
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: ISSOtm on December 22, 2016, 04:03:41 am
Very cool! It's funny these are button combinations like classic game cheats. What would the Konami code or Up-Down-Left-Right-A+Start give, lol?
I know I'm kind of a cheat nazi, but here goes :
It's Up-Up-Down-Down-Left-Right-Left-Right-B-A-Start.

(And the answer is probably a crash :D)
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: Evie (retired from head adminship) on December 22, 2016, 08:01:32 am
Very cool! It's funny these are button combinations like classic game cheats. What would the Konami code or Up-Down-Left-Right-A+Start give, lol?
I know I'm kind of a cheat nazi, but here goes :
It's Up-Up-Down-Down-Left-Right-Left-Right-B-A-Start.

(And the answer is probably a crash :D)

Mm yes, the Konami code is that code. The Up-Down-Left-Right-A+Start is actually a Sonic the Hedgehog cheat (I think?), in case you thought I was writing the Konami code. On hindsight it's been a long time since I tried messing around with the Sonic games so I don't know if that's the code for sure.

Thanks. :)

Yeah. It would be fun if you didn't get a crash, then you could brag using 8F with a set up and entering the Konami code does something cool (or uncool). Perhaps not many people would have believed you if this was back in 2000 or so lol.
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: ISSOtm on December 22, 2016, 08:28:21 am
Imagine using 8F in 1996/7 :D
Title: Re: [Utility] 8F Helper - gbz80aid
Post by: Ganix on December 22, 2016, 09:07:25 am
Very cool! It's funny these are button combinations like classic game cheats. What would the Konami code or Up-Down-Left-Right-A+Start give, lol?

Hehe, definitely brings me back to being a kid in the 90's!

As far as the instructions go, Up-Down-Left-Right-A-Start would translate to the ld sp,hl instruction.

The Konami code would actually be 3 instructions: ld b,b; add a,b; and ld l,e.

And yeah, both would cause the game to NOP slide to its (probable) demise. :P

Imagine using 8F in 1996/7 :D

Oh man, it's crazy to think what people would have come up with back when the GameBoy was in its prime. With all the GB devs with gbz80 experience, it would've only been a matter of time before a few of 'em made some truly unique and crazy stuff with it. =')