Author Topic: [TUTO] How to make "beautiful greyscale" in Axe using interrupts  (Read 9887 times)

0 Members and 1 Guest are viewing this topic.

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Re: [TUTO] How to make "beautiful greyscale" in Axe using interrupts
« Reply #15 on: March 21, 2013, 05:02:37 pm »
How would you go about allowing moving objects on the screen with the interrupt running?  Would you have to somehow sync the refresh rate with the amount of frames? (Sorry if I worded that incorrectly)
You don't necessarily have to sync with the interrupts, but it would be good practice to use it to keep a constant framerate.  
The Stop command halts the CPU until an interrupt occurs.  Remember that a frame is not drawn every interrupt in this case.  You could call a piece of code each time the screen is drawn, but you have to keep your code short to avoid interrupting on itself.  Instead, you can set a variable each time the screen is drawn, then have a piece of main code that waits for the variable to be reset.  



I wrote the following code to have more precision in screen drawing.  The 8.16 fixed point number allows the screen display rate to alternate between whole numbers.  While you will be able to make the screen better, it will still not be as clean as the faster crystal timer interrupts.

Code: [Select]
:.AXEGRAY
:
:ClrDrawrr
:Rect(48,0,48,64)
:Rect(24,0,24,64)r
:Rect(72,0,24,64)r
:
:1→G
:0→H
:9→S
:0→T
:FnInt(DG,0)
:Fix 0
:Fix 5
:
:While 1
:If getKey(4)
:If T>(T+256→T)
:S+1→S
:End
:End
:If getKey(3)
:T+1→T
:If T=0
:S+1→S
:End
:End
:If getKey(1)
:If T<(T-256→T)
:S-1→S
:End
:End
:If getKey(2)
:T-1→T
:If T=EFFFF
:S-1→S
:End
:End
:Text(0,0,S►Hex)
:Text(16,0,T►Hex)
:Pause 100
:EndIf getKey(15)
:LnReg
:Fix 4
:Return
:
:Lbl DG
:G-1→G
:If G=0
:DispGraphrr
:If H<(H+T→H)
:G+1→G
:End
:G+S→G
:End
:Return

EDIT: Wait... This code crashes in Wabbit.  It works fine on my calculator, though.
« Last Edit: March 21, 2013, 05:19:02 pm by ralphdspam »
ld a, 0
ld a, a

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: [TUTO] How to make "beautiful greyscale" in Axe using interrupts
« Reply #16 on: March 22, 2013, 02:19:44 am »
How would you go about allowing moving objects on the screen with the interrupt running?
There is ralphdspam's solution, but you can just also be sure that the drawing commands are always close enough to the erasing commands so that the interrupt "never" occurs between them.

For example, lets say that your program is 7 balls moving on the screen.
Don't do this:
Erase all screen
For(7)
 Calculate coordinates of ball
 Draw ball
End

In this case, the interrupt can occur before all the balls are drawn.
This would be better:
For(7)
 Erase ball
 Calculate new coordinates
 Draw ball
End


Now, at worst, there will be one ball missing on the screen, but that is only at one frame, it will be back at the next frame.
The best would be this:
For(7)
 Calculate new coordinates
 Erase ball
 Draw ball
End

There is almost absolutely no chance that the interrupt occurs between erase and draw ;)
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Re: [TUTO] How to make "beautiful greyscale" in Axe using interrupts
« Reply #17 on: March 22, 2013, 02:21:57 pm »
There is almost absolutely no chance that the interrupt occurs between erase and draw ;)

You could also temporarily disable interrupts before the erase and enable them after the draw.  That way, you will never display a half-drawn screen.

EDIT: fixed quote formatting
« Last Edit: March 22, 2013, 02:23:46 pm by ralphdspam »
ld a, 0
ld a, a

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: [TUTO] How to make "beautiful greyscale" in Axe using interrupts
« Reply #18 on: March 22, 2013, 02:26:07 pm »
You could call a piece of code each time the screen is drawn, but you have to keep your code short to avoid interrupting on itself.
Actually you can encapsulate your interrupt with FnOff and FnOn to avoid that. Then put what you want in. The main reason why an interrupt should be short is speed. The longer it is, the more lag you create in your main prog.

Also I've compared 3 vs 4 levels and 3 looks clean when scrolling while 4 looks really blurry. Maybe it's because I can't calibrate it correctly. ???
« Last Edit: March 22, 2013, 02:34:31 pm by Streetwalker »

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Re: [TUTO] How to make "beautiful greyscale" in Axe using interrupts
« Reply #19 on: March 22, 2013, 02:52:43 pm »
Also I've compared 3 vs 4 levels and 3 looks clean when scrolling while 4 looks really blurry. Maybe it's because I can't calibrate it correctly. ???
What you are seing is most likely an artifact of the grayscale mask.  How fast are you scrolling in relationship to the interrupts?  Have you tried scrolling at faster or slower rates?
« Last Edit: March 22, 2013, 02:53:21 pm by ralphdspam »
ld a, 0
ld a, a

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: [TUTO] How to make "beautiful greyscale" in Axe using interrupts
« Reply #20 on: March 22, 2013, 03:44:59 pm »
I'm scrolling a bit faster than the interrupt. Syncing it doesn't fix it so I think it's the calibration because 3 level looks perfect at the same speed.