Author Topic: Butts Fredkin's Buffer Tutorial in Axe 1.0.2  (Read 5584 times)

0 Members and 1 Guest are viewing this topic.

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Butts Fredkin's Buffer Tutorial in Axe 1.0.2
« on: August 20, 2011, 05:44:37 pm »
NOTE:For this tutorial, I'm using Axe 1.0.2. Check the Commands.htm of your current version of Axe to make sure the commands are supported

So. There's this thing that you can use in Axe. It's called a Buffer, and it's basically a chunk of memory, and appvar, or some other form of an Array. By definition, it is 768 bytes in size. By using the appropriate commands in Axe Parser, buffers can be displayed on the screen of your calculator to output graphics in monochrome, 3, or 4 level grayscale.


Using the Default Buffers

In Axe, there is a location in saferam or freeram or whatever you want to call it, called L6. Check the commands list - L6 is 768 bytes in size! Perfect for a buffer. L6 (and also L3, for grayscale) are known as the Default Buffers.

Whenever you use a command such as Pt-On(X,Y,Pic1) or Pxl-On(44,36) or Drawinv or something like that, you are drawing to the Default Buffer.

Line(0,0,10,10) doesn't 'draw a Line' per se, it sets and edits data in L6, the default buffer (for more on how computers draw lines, you might want to read this). Then, when you call DispGraph, it looks at the data in L6, and displays it.

Check this out:

Code: [Select]

Repeat getkey(15)

.This command fills L6 with a bunch of zeros, 768 to be exact
ClrDraw

.Now let's edit the very first byte in L6

255->{L6}

.We set the first byte to 255, or FF in hexadecimal
.255 / 0xFF translates out to the following binary:
.11111111 (eight ones)
.So when we call DispGraph, it will display eight black pixels in the first byte of the buffer
.In other words, the top left corner

DispGraph

End


Try it! If you understand how sprites work, you can see that Pt-On just copies your sprite hex data into a buffer! Experiment with this -- you could even write your own Pt-On subroutine, completely in Axe! (not that it would be extremely useful, just fun to make)

Grayscale

So how does grayscale work in Axe? This is where the Back-Buffer comes in. L3 is referred to as the Back Buffer, or Secondary Buffer.

When you call commands such as Pt-On(X,Y,Pic1)r, it does the exact same thing as without the little r, but it draws to the Back-Buffer instead of the Default Buffer. And when you call DispGraphr, it displays all the data in L3 as gray, and all the data in L6 as black. For more on how grayscale works, I recommend reading this

And for four-level grayscale, L3 is displayed as light gray, L6 is used for dark gray, where they overlap is displayed as black, and where they are both blank is white. So to display four blocks right next to each other, progressively getting lighter, do this:

Code: [Select]

prgmEXAMPLE

.EXPROG
.Example program is an example.

[FFFFFFFFFFFFFFFF]->Pic1
.^this is just a solid block

Repeat getkey(15)

ClrDraw
ClrDraw[sup]r[/sup]

Pt-On(0,0,Pic1)
Pt-On(8,0,Pic1)
Pt-On(0,0,Pic1)[sup]r[/sup]
Pt-On(16,0,Pic1)[sup]r[/sup]

DispGraph[sup]rr[/sup]

End



Using Alternate Buffers

If you understand that Line(0,0,10,10) isn't technically drawing a line on the screen it's really just editing and setting data in a Buffer, then using Alternate Buffers should not be hard to understand. All that's different is a slight syntax change.

To initialize a buffer (let's call it GDB1, just for fun), we do the following:

Zeros(768)->GDB1

This creates an array in memory that is 768 bytes large and fills it with zeros. To clear the buffer, do the following:

ClrDraw(GDB1)

and other than that, it's really easy.

I'll just show you some code examples, instead of explaining in words.

Monochrome Buffers:

Code: [Select]
prgmMOVE
.MVMT A simple movement demo (with buffers)

0->X
0->Y

Zeros(768)->GDB1

[FFFFFFFFFFFFFFFF]->Pic1

Repeat getkey(15)

.(this input system does not react to walls)
getkey(3)+X-(getkey(2))->X
getkey(1)+Y-(getkey(4))->Y

ClrDraw(GDB1)

Pt-On(X,Y,Pic1,GDB1)

Dispgraph(GDB1)

End


The same code, with 3 level gray:


Code: [Select]
prgmMOVE
.MVMT A simple movement demo (with buffers)

0->X
0->Y

Zeros(768)->GDB1
Zeros(768)->GDB2

[FF000000000000FF]->Pic1
[00FFFFFFFFFFFF00]->Pic2

Repeat getkey(15)

.(this input system does not react to walls)
getkey(3)+X-(getkey(2))->X
getkey(1)+Y-(getkey(4))->Y

ClrDraw(GDB1)
ClrDraw(GDB2)

Pt-On(X,Y,Pic1,GDB1)
Pt-On(X,Y,Pic2,GDB2)

Dispgraph(GDB1,GDB2)

End


I'm not 100% sure on the syntax here (I use 0.5.3  ;D) but you get the idea.


Voila! You have successfully set up and used an alternate buffer system! Let me know if I was unclear on anything.
« Last Edit: August 20, 2011, 07:41:09 pm by buttsfredkin »
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline yunhua98

  • You won't this read sentence right.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2718
  • Rating: +214/-12
  • Go take a dive in the River Lethe.
    • View Profile
Re: Butts Fredkin's Buffer Tutorial in Axe 1.0.2
« Reply #1 on: August 20, 2011, 06:08:41 pm »
I skimmed through.  This seems very useful for arcade games.  Thanks for sharing, although I probably won't use it until I'm sure Axe is stable.  ;)

Spoiler For =====My Projects=====:
Minor setback due to code messing up.  On hold for Contest.
<hr>
On hold for Contest.


Spoiler For ===Staff Memberships===:






Have you seen any good news-worthy programs/events?  If so, PM me with an article to be included in the next issue of CGPN!
The Game is only a demo, the code that allows one to win hasn't been done.
To paraphrase Oedipus, Hamlet, Lear, and all those guys, "I wish I had known this some time ago."
Signature Last Updated: 12/26/11
<hr>

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Butts Fredkin's Buffer Tutorial in Axe 1.0.2
« Reply #2 on: August 20, 2011, 06:12:10 pm »
That's pretty much why I'm still using Axe 0.5.3 :)
« Last Edit: August 20, 2011, 06:13:35 pm by buttsfredkin »
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline XVicarious

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +45/-28
  • I F**king Love Twisty Puzzles
    • View Profile
    • XVicarious
Re: Butts Fredkin's Buffer Tutorial in Axe 1.0.2
« Reply #3 on: August 20, 2011, 07:17:25 pm »
You should put the code in code tags.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Butts Fredkin's Buffer Tutorial in Axe 1.0.2
« Reply #4 on: August 20, 2011, 07:26:20 pm »
A couple friendly suggestions:

1) Use [code][/code] tags around your code to make it visually separate from the rest of the text.
2) I'd recommend explaining the concepts more in depth. You never really answered the question "So how does grayscale work in Axe?" beyond "Use another buffer." Why does having another buffer allow greyscale? The same goes for the Line() function that you say doesn't actually draw a line. A user who doesn't understand that Bresenham's Line algorithm is actually a numerical approximation to a true line is going to be very confused by that statement.

Overall, good job. Format it a bit more and we can add it to the tutorials section :)
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Butts Fredkin's Buffer Tutorial in Axe 1.0.2
« Reply #5 on: August 20, 2011, 07:29:42 pm »
I actually submitted it as a tutorial and it's in the tutorial section currently ;) and in the tutorial section, it had code tags, just when I copied it over to this thread, they didn't copy. And no problem Qwerty, I'll flesh out some concepts.
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline yunhua98

  • You won't this read sentence right.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2718
  • Rating: +214/-12
  • Go take a dive in the River Lethe.
    • View Profile
Re: Butts Fredkin's Buffer Tutorial in Axe 1.0.2
« Reply #6 on: August 20, 2011, 07:29:44 pm »
It's already been added Qwerty.  ;)  It was added in there before it was posted.

I changed your post to the source in the tutorials.  ;)
« Last Edit: August 20, 2011, 07:31:58 pm by yunhua98 »

Spoiler For =====My Projects=====:
Minor setback due to code messing up.  On hold for Contest.
<hr>
On hold for Contest.


Spoiler For ===Staff Memberships===:






Have you seen any good news-worthy programs/events?  If so, PM me with an article to be included in the next issue of CGPN!
The Game is only a demo, the code that allows one to win hasn't been done.
To paraphrase Oedipus, Hamlet, Lear, and all those guys, "I wish I had known this some time ago."
Signature Last Updated: 12/26/11
<hr>

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Butts Fredkin's Buffer Tutorial in Axe 1.0.2
« Reply #7 on: August 20, 2011, 07:33:01 pm »
I changed your post to the source in the tutorials.  ;)

Thanks. It looks much better now, I think.
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Butts Fredkin's Buffer Tutorial in Axe 1.0.2
« Reply #8 on: October 07, 2011, 06:32:50 pm »
Very nice...
I understand now... XD

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Butts Fredkin's Buffer Tutorial in Axe 1.0.2
« Reply #9 on: October 09, 2011, 02:31:56 pm »
Glad to know I can help! :)
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)