Jump to content
IGNORED

Binary machine code to Batari Basic?


BadBoy House

Recommended Posts

Correct, there is no program that can turn a binary into bB code.

not as advanced

1011208[/snapback]

Au contraire... The kernel uses modern tricks that were not known in the 80's, so it's actually more advanced.

 

If you replace "advanced" with "specialized" then you would be correct. By using a kernel that's suited for just one game, you can do things that the bB kernel cannot.

Link to comment
Share on other sites

is there any way of converting the binary source code of a game into batari basic?

1010637[/snapback]

 

I'd like to take a stab at this, too!

 

There's another issue in addition to the ones already mentioned. Basically (no pun intended), bB code isn't going to be as optimized as pure 6502 code could be, due to the manner in which the bB code is converted into 6502 code. For example, consider a simple custom display kernel, written entirely in bB code:

 

  COLUBK = $94 : rem * Set the background to blue
loop
  VBLANK = 2 : rem * Turn on the video blanking
  for x = 1 to 30 : rem * Draw 30 blanked scan lines
     WSYNC = 0
  next
  VSYNC = 2 : rem * Turn on the vertical sync pulse
  for x = 1 to 3 : rem * Draw 3 blanked scan lines
     WSYNC = 0
  next
  VSYNC = 0 : rem * Turn off the vertical sync pulse
  for x = 1 to 37 : rem * Draw 37 blanked scan lines
     WSYNC = 0
  next
  VBLANK = 0 : rem * Turn off the video blanking
  for x = 1 to 192 : rem * Draw 192 blue scan lines
     WSYNC = 0
  next
  goto loop

 

When this bB code is compiled, the resulting 6502 code is something like this (I've edited it to look more like "normal" 6502 code):

 

  LDA #$94
  STA COLUBK
.loop
  LDA #2
  STA VBLANK
  LDA #1
  STA x
.L03forx
  LDA #0
  STA WSYNC
.L05
  LDA x
  CMP #30
  INC x
  bcc .L03forx
.L06
  LDA #2
  STA VSYNC
.L07
  LDA #1
  STA x
.L07forx
.L08
  LDA #0
  STA WSYNC
.L09
  LDA x
  CMP #3
  INC x
  bcc .L07forx
.L010
  LDA #0
  STA VSYNC
.L011
  LDA #1
  STA x
.L011forx
.L012
  LDA #0
  STA WSYNC
.L013
  LDA x
  CMP #37
  INC x
  bcc .L011forx
.L014
  LDA #0
  STA VBLANK
.L015
  LDA #1
  STA x
.L015forx
.L016
  LDA #0
  STA WSYNC
.L017
  LDA x
  CMP #192
  INC x
  bcc .L015forx
.L018
  JMP .loop

 

On the other hand, a more optimized version written in 6502 code might be:

 

  LDA #$94
  STA COLUBK
  LDA #2
.loop
  STA VBLANK
  LDX #30
.front_porch
  STA WSYNC
  DEX
  BNE .front_porch
  STA VSYNC
  STA WSYNC
  STA WSYNC
  STA WSYNC
  STX VSYNC
  LDX #37
.back_porch
  STA WSYNC
  DEX
  BNE .back_porch
  STX VBLANK
  LDX #192
.raster
  STA WSYNC
  DEX
  BNE .raster
  JMP .loop

 

Note how much more condensed the pure optimized 6502 code is. The bB code is probably easier for many people to understand, but it ends up producing lengthier 6502 code when it's compiled. And if you want to use bB's default kernel, the bB code is even easier to understand:

 

  COLUBK = $94
loop
  drawscreen
  goto loop

 

However, bB's default kernel does a lot more than what the custom bB kernel did in the first example, because bB's default kernel includes code to automatically draw the playfield pixels, players, missiles, and ball on each scan line, which the custom kernel in the first example didn't bother to do.

 

When programmers write Atari 2600 games, they usually go to great pains to squeeze the instructions into the smallest number of bytes and fastest execution time. Simply put, even if you could create a conversion utility that's smart enough to be able to examine 6502 code, figure out exactly what it's doing, and generate bB code that does essentially the same things, the equivalent bB code will compile into much lengthier 6502 code, which will take up more bytes and execute in more machine cycles.

 

Additionally, bB uses a lot of the Atari's 128 bytes of RAM for bB's own "system variables" (e.g., the array for the playfield pixels, the variables for storing the x and y positions of the players, temporary variables that are used with bB's default kernel, etc.). So if we tried to convert a typical Atari game into an equivalent bB game, we probably won't have enough free RAM to use for all of the game's own variables.

 

So even if somebody could create such a conversion utility (and it would certainly be very cool if someone could), there wouldn't really be much point in using it. But that doesn't mean we can't create bB games which are very similar to existing Atari games.

 

Michael Rideout

Link to comment
Share on other sites

is there any way of converting the binary source code of a game into batari basic?

1010637[/snapback]

 

On second thought, maybe I should clarify something.

 

Yes, there is a way to convert the binary source of a game into batari BASIC-- but not automatically, and the resulting bB program will not compile into 6502 code that's the same as the original code.

 

In other words, you could disassemble the binary source, analyze the disassembly manually, and do your best to replace sections of 6502 code with bB code that accomplishes essentially the same thing, or as nearly the same thing as you can manage. But this might require totally redesigning or replacing bB's include files, along with using inline assembly code for things that can't be adequately replaced with bB code.

 

In short, the process would be very labor-intensive, and the results might not be good enough (fast enough or condensed enough) to justify the effort.

 

On the other hand, such an exercise could be extremely educational, if it helped you figure out ways to accomplish similar results using batari BASIC (e.g., the original game is drawing a particular player shape and moving it around, so how can we draw the same player shape and move it around using bB statements).

 

So no, there's no way to do a conversion automatically, but you can do your best to manually convert a non-bB game into a bB game that recreates the "look and feel" of the original game as much as bB is capable of. And there's no way to get the equivalent bB code to compile into an exact replica of the original game.

 

Michael Rideout

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...