[TI ASM]Title Animation
Moderator: MaxCoderz Staff
- thegamefreak0134
- Extreme Poster
- Posts: 455
- Joined: Mon 23 Jan, 2006 10:09 pm
- Location: In front of a Computer, coding
- Contact:
[TI ASM]Title Animation
OK, this might get a bit confusing.
I am using Jim e's greyscale package, and I have an effect I want to achieve. I have a title screen whose colors I want to swap out quickly. I want white to stay white, black to become dark grey, dark grey to become light grey, and light grey to become black. Keeping his package in mind, can someone tell me the math I need to apply to the buffers byte by byte to get this to work? I know it's probably something simple, my mind's just not working it out.
thanks!
-gamefreak
I am using Jim e's greyscale package, and I have an effect I want to achieve. I have a title screen whose colors I want to swap out quickly. I want white to stay white, black to become dark grey, dark grey to become light grey, and light grey to become black. Keeping his package in mind, can someone tell me the math I need to apply to the buffers byte by byte to get this to work? I know it's probably something simple, my mind's just not working it out.
thanks!
-gamefreak
XOR the two planes together (light and dark) This is the new light plane.
The old light plane becomes the new dark plane.
edit: example:
dark: %11110000
light: %11001100
xor: %00111100
colors: black, darkgray, lightgray, white
new:
dark|%11001100
light|%00111100
colors: dark gray, light gray, black, white
The old light plane becomes the new dark plane.
edit: example:
dark: %11110000
light: %11001100
xor: %00111100
colors: black, darkgray, lightgray, white
new:
dark|%11001100
light|%00111100
colors: dark gray, light gray, black, white
- benryves
- Maxcoderz Staff
- Posts: 3087
- Joined: Thu 16 Dec, 2004 10:06 pm
- Location: Croydon, England
- Contact:
EDIT: Oh, Liazon beat me by... a few hours :\
When trying to work out this sort of thing, you could try using truth tables and binary logic:
So, to get the required effect you need to xor each byte in the two buffers to get the new buffer 1 and to also copy the first bitplane to the second.
At a rough guess, the code for that would be something like this:
(Assuming the two bitplanes are stored as 2 individual 768-byte bitmaps).
When trying to work out this sort of thing, you could try using truth tables and binary logic:
Code: Select all
A = bitplane 1 in
B = bitplane 2 in
Q = bitplane 1 out
R = bitplane 2 out
(Assuming BA=01 = light grey, BA=10 = dark grey)
BA|RQ
--+--
00|00
01|11
10|01
11|10
From this, we can see:
_ _
Q = A.B + A.B = A(x)B
R = A
At a rough guess, the code for that would be something like this:
Code: Select all
ld de,buffer_1
ld hl,buffer_2
ld bc,768
_loop
ld a,(de)
push af
xor (hl)
ld (de),a
pop af
ld (hl),a
inc hl
inc de
dec bc
ld a,b
or c
jr nz,_loop
- Jim e
- Calc King
- Posts: 2457
- Joined: Sun 26 Dec, 2004 5:27 am
- Location: SXIOPO = Infinite lives for both players
- Contact:
You can optimise that a bit.
Code: Select all
ld hl,buffer_2 ;light
ld de,buffer_1 ;dark
ld bc,768
_loop:
ld a,(de)
xor (hl)
ldi
dec hl
ld (hl),a
inc hl
jp pe,_loop
- benryves
- Maxcoderz Staff
- Posts: 3087
- Joined: Thu 16 Dec, 2004 10:06 pm
- Location: Croydon, England
- Contact:
Parity refers to whether there is an even or odd number of bits in the byte. This is where you get parity bits from in communications - for example, if you have a 'parity even' system, you will send an extra bit which is either set or reset with each 8 bits to make sure that there is an even number of set bits (a form of error detection).
However, the po/pe flags* (parity odd/even) also correspond to overflow. In this instance, Jim e is testing for overflow from the ldi instruction (for when bc has reached zero) as to whether to loop again or not.
EDIT: When I say 'flags' there's only one bit (one flag), but two states (set/reset) of course.
However, the po/pe flags* (parity odd/even) also correspond to overflow. In this instance, Jim e is testing for overflow from the ldi instruction (for when bc has reached zero) as to whether to loop again or not.
EDIT: When I say 'flags' there's only one bit (one flag), but two states (set/reset) of course.
Last edited by benryves on Tue 20 Jun, 2006 12:09 pm, edited 1 time in total.
- thegamefreak0134
- Extreme Poster
- Posts: 455
- Joined: Mon 23 Jan, 2006 10:09 pm
- Location: In front of a Computer, coding
- Contact:
Y'all are making this much more difficult than it needs to be. As usually happens, I posted for help and then promptly went home and figured it out on my own. It's fairly straightforward.
OK, I want to make B become D, D become L, and L become B right? And I want to completely ignore W? So,
1 -> 1
1 -> 0
1 -> 0
0 -> 1
0 -> 1
1 -> 1
So, here's the solution:
Bit 2 = Bit1 xor Bit2
Bit 1 = Bit1 xor Bit2
In other words, load bit 2 into mem, make bit 2 equal bit1 xor bit2, and make bit1 equal the bit you loaded to mem.
I applied this process to every byte in the buffers, and the effect goes so fast that the greyscale effect is lost entirely. You actually see more of a blur than anything. When I slowed it down, it worked alright. Thanks for the advice though!
-gamefreak
OK, I want to make B become D, D become L, and L become B right? And I want to completely ignore W? So,
1 -> 1
1 -> 0
1 -> 0
0 -> 1
0 -> 1
1 -> 1
So, here's the solution:
Bit 2 = Bit1 xor Bit2
Bit 1 = Bit1 xor Bit2
In other words, load bit 2 into mem, make bit 2 equal bit1 xor bit2, and make bit1 equal the bit you loaded to mem.
I applied this process to every byte in the buffers, and the effect goes so fast that the greyscale effect is lost entirely. You actually see more of a blur than anything. When I slowed it down, it worked alright. Thanks for the advice though!
-gamefreak
- thegamefreak0134
- Extreme Poster
- Posts: 455
- Joined: Mon 23 Jan, 2006 10:09 pm
- Location: In front of a Computer, coding
- Contact: