.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   An odd question... (http://forums.bots-united.com/showthread.php?t=4343)

Lazy 14-08-2005 11:14

An odd question...
 
A stupid late-night idea has me trying to create a dot matrix display using '.' and 'o' characters...
I have it set up so that there are 160 bits/dots, 32 bits wide by 5 bits high.
So, each line is made up of 4 bytes ( ie. byte 2 is 16,0 to 23, 0 ).

I just can't figure out how to convert an X,Y coordinate ( say, 5,2 ) to an individual byte and bit.
There must be some kind of math to do it but I can't figure it out - unless more coffee will help.

I could post the code I have now if needed, but its not commented and only rotates the bits in every byte of the first line.
Btw, is there a standard C/C++ way to rotate bits?
I can't remember off hand so I used some x86 asm to do the rotation.

Pierre-Marie Baty 15-08-2005 23:59

Re: An odd question...
 
If you have lines of 32 bits you have 4 bytes per line. So the bit A on line B will be the 32*B+A bit of your flattened array. To find which byte it is from, divide that by eight and round it down.

rotate bits in C ? Use the << and >> operators. But be aware that the leftmost and rightmost bits are lost, so if you want them to reappear at the other side of the word, you have to put them there manually.

I really think you should sleep more, maths look much simpler when looked at through wide open eyes and with a fully operational brain :)

Lazy 16-08-2005 03:29

Re: An odd question...
 
Thanks, I'll try that out in a bit.
I'm starting to learn 6502 assembly and the book I'm reading assumes the computer has display memory that can be written to inorder to put things on the display.
Unfortunately, the simulator I'm using works by writing a character value to a memory address to put something on the screen.
So with my limited 6502 assembly I'm setting aside 440 bytes to use as emulated display memory then iterating through the bytes and writing them to the display character address every time it's needed.
Horribly inefficient but no 6502 simulators I found supported display memory.

So while this vvvvv works for temporary purposes, the book requires the emulated display memory.
Code:

                .ORG $200
HelloString:        .ASCII "Hello from 6502 ASM!", $00
                .START .Main

.Main        LDY #$00
.Getch        LDA HelloString, Y
        BEQ .Fin
       
        STA $E001
        INY
        JMP .Getch

.Fin        BRK

As for sleep, I wish I could...
I just end up lying in bed for hours until I come to realize sleep is not going to happen, so I just go back and code some more. :(


All times are GMT +2. The time now is 10:44.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.