So I've been given an assignment where we have to make a symbol using colored pixels using an 6502 assembly emulator. I don't quite understand how this grid works. Could someone please explain how this grid works and maybe give and example?
here is the link to the emulator: https://skilldrick.github.io/easy6502/#first-program
and the grid I'm to work with: https://i.stack.imgur.com/QuqPi.png
I think Michael's command is correct; avoiding use of 'x' and 'y' for potential register ambiguity reasons, address $0200 + (q*32) + p contains the pixel at (p, q) for p and q in the range 0 to 31, and in each byte the low four bits determine the pixel colour.
So e.g. $0200 is the pixel in the top left, $0201 is the pixel one to the right of the top left, and $0220 is the pixel one below the top left.
In 6502 terms one possible straightforward implementation of a generic plot subroutine could use indexed indirect addressing, storing $0200 + (q*32) into a zero-page location and then indexing by p to hit a particular horizontal position within that row. Off the top of my head, and without having checked exactly what syntax that assembler uses and hard-coding the use of zero-page addresses $80 and $81:
;
; Plot; stores the colour in A to the pixel at (y, x).
; So, yes: x and y are backwards.
;
; Clobbers x.
;
Plot:
; Arbitrarily, this adds x to ($200 >> 5) and
; then shifts the whole lot left by 5. That's
; rather than shifting x by 5 and then doing a
; one-byte add to the upper byte, I guess.
pha
txa
clc
adc #$10 ; $10 = $200 >> 5
sta $80
lda #$00
sta $81
; Multiply by 32. You could unroll this if
; that's what your priorities imply.
ldx #5
.rollLoop
asl $80
rol $81
dex
bne rollLoop
pla
sta ($80), y
rts
Related
with JPEG snoop for an image 4:2:2 hor (YYCbCr)
I see this in the SOF0:
Component[1]: ID=0x01, Samp Fac=0x21 (Subsamp 1 x 1), Quant Tbl Sel=0x00 (Lum: Y)
Component[2]: ID=0x02, Samp Fac=0x11 (Subsamp 2 x 1), Quant Tbl Sel=0x01 (Chrom: Cb)
Component[3]: ID=0x03, Samp Fac=0x11 (Subsamp 2 x 1), Quant Tbl Sel=0x01 (Chrom: Cr)
Now where are the values 0x21 and 0x11 coming from?
I know that sampling factors are stored like this: (1byte) (bit 0-3 vertical., 4-7 horizontal.)
but I don't see how 0x11 relates to 2x1 and 0x21 to 1x1.
I expected to see 0x11 for Y component and not 0x21.
(not sure how you get 0x21 as result).
Can somebody explain these values and how you calculate them for example 4:2:2 horizontal (16x8)?
JPEG does it bassackwarks. The values indicate RELATIVE SAMPLING RATES.
The highest sampling rate is for Y (2). The sampling rate for Cb and Cr is 1.
Use the highest sampling rate to normalize to pixels:
2Y = Cb = Cr.
Y = 1/2 Cb = 1/2 Cr.
For every Y pixel value in that direction you use 1/2 a Cb and Cr pixel value.
You could even have something like according to the JPEG standard.
4Y = 3Cb = 1Cr
Y = 3/4Cb = 1/4 Cr
or
3Y=2Cb=1Cr
Y=2/3Cb=1/3Cr
But most decoders could not handle that.
The labels like "4:4:4", "4:2:2", and "4:4:0" are just that: labels that are not in the JPEG standard. Quite frankly, I don't even know where those term even come from and they are not intuitive at all (there is never a zero sampling).
Let me add another way of looking at this problem. But first, you have to keep in mind that the JPEG standard itself is not implementable. Things necessary to encode images are undefined and the standard is sprawling with unnecessary stuff.
If a scan is interleaved (all three components), it is encoded in minimum coded units (MCUs). An MCU consists of 8x8 encoded blocks.
The sampling rate specifies the number of 8x8 blocks in an MCU.
You have 2x1 for Y + 1x1 for Cb and 1x1 for Cr. That means a total of 4 8x8 blocks are in an MCU. While I mentioned other theoretical values above, the maximum number of blocks in an MCU is 10. Thus 4x4 + 3x3 + 2x2 is not possible.
The JPEG standard does not say how those blocks are mapped to pixels in an image. We usually use the largest value and say that wave a 2x1 zone or 16x8 pixels.
But all kinds of weirdness is possible under the standard, such as:
Y = 2x1, Cb = 1x2 and Cr = 1x1
That would probably mean an MCU maps to a 16x16 block of pixels but your decoder would probably not support this. Alternatively, it might mean an MCA maps to a 16x8 block of pixels and the Cb component has more values in the 8 direction.
A final way of viewing this (the practicable way) is to use the Y component as a reference point. Assume that Y is always going to have 1 or 2 (and maybe a 4) as the sampling rate in the X and Y directions and define the rates on Cb and Cr are going to be 1 (and maybe 2).The Y component always defines the pixels in the image.
These would then be realistic possibilities:
Y Cb Cr
1x1, 1x1, 1x1
2x2, 1x1, 1x1
4x4, 1x1, 1x1
2x1, 1x1, 1x1
1x2, 1x1, 1x1
Below is my matlab code snippet for generating first order markov chain. I am having trouble with extending to 2nd order markov chain. Can some one help me in doing so? Any suggestions, hints, links, pseudo-code, algorithm, python or matlab snippets would be helpful.
cdist is the cumulative distribution vector (size-28*1) my 27 symbols. I am writing the output to file called chain.p and q are uniform random numbers. CTRANS is the cumulative matrix corresponding to my first order transition matrix TRANS (which is not shown here, its size is 729*27). CTRANS besides being the cumulative version also has a row vector of zeros appended on top for programming ease. cols is the column size of CTRANS.
%generate sequence according to distribution and transition matrix
fileID = fopen('chain','w');
for k=1:10000
p=rand;
for l=2:numel(cdist)%2 to 28
if ((p >= cdist(l-1)) && (p <= cdist(l)))
fprintf(fileID,'%s\n',num2str(l-1));
q=rand;
for m=2:cols%2 to 28
if ((q >= CTRANS(l,m-1)) && (q <= CTRANS(l,m)))
fprintf(fileID,'%s\n',num2str(m-1));
end
end
end
end
end
fclose(fileID);
I am struggling with the second order case. I can provide more details if required. My input data from where I extract the statistics is english text of length around 4000 characters. I have removed the punctuations etc and converted capital letters to small letters, so now there are 27 symbols where number 1 represents 'a' till 26 represents 'z' and 27 for space. Also I have created the bi-gram distribution vector for the second order case.
I have a large file of 3D point cloud each line in the form of
x(1) y(1) z(1) g(1)
...
...
x(n) y(n) z(n) g(n)
now due to cpu power limitation I can not display all of the 3D points and would like to only select a sub set of it. say only one fifth of the points.
If I do the following
while (){
if x(i) % 5 == 0 keep the 3d point
}
the result gets zibera pattern, so it does not look nice. What algorithm do you suggest to select best candidates to form a subset of points to form a sub 3D point cloud which is most similar to the original dense point cloud?
Thank you
The language does not matter ( matlab, java c, etc) what matters is how we make a sparser version of the original one.
As an alternative to random sub-sampling mentioned in the first answer, you could try this:
Compute the bounding box the point cloud (axis-aligned or oriented bounding box),
Choose a cell size (the bounding box now contains W x H x D cells of this size),
Hash all the points of the point cloud to their respective cell grid and keep only N point(s) maximum per cell (N >= 1), or simpler, just drop or keep every Nth point.
Anything wrong with random subsampling?
f = fractionOfDataToKeep(); // between 0 (0%) and 1 (100%)
while() {
r = rng(1.0); // pseudorandom number between 0 and 1
if (r < f) keepThe3DPoint()
}
I have 3 vectors of variable lengths but bounded between 1 and 5 (both inclusive). I need to print them out (in a "nice" way) while the code runs.
Nice := I want to let all the vectors be printed in such a way that the starting value of each vector in each iteration is aligned.
What I have tried:
Current Bad Version
for it=1:length(a)
fprintf(' %4.4f ',a(it))
end
and similar for other two.
This makes them misaligned. If the first vector is only length 1, everything gets messed up.
Sloppy Output Version
I filled up the empty locations with 0 and printed
for it=1:5
fprintf(' %4.4f ',a(it))
end
but this is sloppy since it gives the reader the wrong impression. The reader will believe that the vector is full length with values 0.
However, this prints it out correctly. All the vectors are appropriately aligned.
Sample
In my code a,b,c are numbers but suppose a,b,c were list of strings. a is the animals I saw today, b is what i ate for lunch and c is where i went today. They vary from day to day.
EDIT : On the last line, Elephant should be RED (in the correct version).
Modifying your "sloppy version", you can just print spaces rather than zeros:
for it=1:5
if a(it) == 0
% print 11 spaces
fprintf(' ')
else
fprintf(' %4.4f ',a(it))
end
end
i am having problem with writing equations.
r = 25, k= 2, R = 50:25:600, DR = 0.5:0.5:4.0
h= r*[1-cos(asin((sqrt(2*R*DR+DR^2))+r*sin(acos(r-k)/r)/r))]-k
but as a resault i get this: h = 1.9118e+001 +1.7545e+002i.
I just start with Matlab. Thanks
What I get from what you've written is actually
??? Error using ==> mtimes
Inner matrix dimensions must agree.
which is correct because you're trying to multiply two row vectors by one another. Could you please show us the actual code you used?
Anyway, supposing that's dealt with somehow, it looks to me as if you're feeding something to asin that's much bigger than 1. That'll give you complex results. Is the thing you're passing to asin perhaps meant to be divided by R^2 or DR^2 or something of the kind? You have a similar issue a bit later with the argument to acos.
I also suspect that some of your * and ^ and / operators should actually be elementwise ones .*, .^, ./.
If you're trying to do as you said:
so in first equation i used R= 50, DR
= 0.5, r= 25, k=2 and i need to get h. In second equation i used R=75,
DR=1.0, r=25, k=2...for a last
equation i used
R=600,DR=4.0,r=25,k=2.
DR and R need to be the same length... so if R goes between 50 and 600 in increments of 25, DR should go from 0.5 to 12.5 in increments of 0.5, or 0.5 to 4.0 in increments of 0.1522...
once you figure that out, be sure the add a period before every matrix multiplication operation (e.g. * or ^)
EDIT: formula adjusted slightly (bracketing) to reflect success in comment.
When you say you want a table, I guess it is to be an R by DR table (since you have to vectors of different length). To do that you need to use R as a column vector (R' below) and multiply with * (not .*). When R doesn't appear in a term multiply by ones(size(R)) (or use repmat) to get DR into the right shape. To square DR by element, you need DR.^2. There seems to be a misplaced bracket for the acos, surely you divide by r before taking the acos. There must be a division by something like r in the asin (not r^2 because you've taken the sqrt). Finally, the last division by r is redundant as written, since you multiply by r at the same level just before. Anyway, if I do the following:
h= r*(1-cos(asin((sqrt(2*R'*DR+ones(size(R))'*DR.^2)/r)+sin(acos((r-k)/r)))))-k
I get an R by DR table. Results for small R,DR are real; higher R,DR are complex due to the argument of the first asin being >1. The first entry in the table is 4.56, as you require.