Screen Manipulation

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Screen Manipulation

advaith_dm
Is it possible to draw a circle of an arbitrary radius purely using Hack Assembly Language on CPEU Emulator, if so please provide an insight on how you can solve this problem?
Reply | Threaded
Open this post in threaded view
|

Re: Screen Manipulation

WBahn
Administrator
Sure, you just need to develop a circle-drawing algorithm in assembly language.

Just like any other programming problem, break the problem down into smaller pieces. Ask which of those pieces you could implement in assembly language and set those aside for the time being. For each of the remaining pieces, break it down into smaller pieces. Keep repeating this process until you have gotten everything down to a point where you can do it in assembly language. Then start coding. Do it incrementally so that you can implement and test smaller pieces and put the pieces together to make larger testable pieces until you have it all done.

A circle drawing algorithm in assembly is not a trivial undertaking, but it is very doable. In the end, you will likely have an algorithm that will considerably outperform the one in the Screen library, if for no other reason that it doesn't suffer the calling overhead and restrictions imposed by the VM language acting as an intermediary.
Reply | Threaded
Open this post in threaded view
|

Re: Screen Manipulation

advaith_dm
Thank you for the response, I understand the fact we have to break down a circle algorithm written in a higher language to a Hack Assembly, Doesn't it mean that we have to develop a coordinate system for the screen and handle the pointer according to it, to reach my goal, Essentially speaking, I 'll have to come up with a user-defined screen library to suit my needs?
Reply | Threaded
Open this post in threaded view
|

Re: Screen Manipulation

WBahn
Administrator
ayush_shyam wrote
Thank you for the response, I understand the fact we have to break down a circle algorithm written in a higher language to a Hack Assembly, Doesn't it mean that we have to develop a coordinate system for the screen and handle the pointer according to it, to reach my goal, Essentially speaking, I 'll have to come up with a user-defined screen library to suit my needs?
Of course you have to develop a coordinate system for the screen. When someone calls your assembly language routine they are going to need to provide it with values that somehow convey the location and size of the circle, aren't they? Well, that requires that the person using your assembly language routine know how that routine is going to interpret those numbers, which means you have to specify a coordinate system. You also need to do that in order to map the pixels that you want to change the color of to the memory addresses and bits within those addresses that control those pixels. That has nothing to do with assembly versus high level or whether you are using a completely self-contained function or calling on other library functions.

I don't know what pointer you are referring to or what it means to handle it.

I don't know whether you will need to come up with a user-defined screen library to suit your needs because I have no idea what your needs are. You asked if it's possible to draw a circuit of arbitrary radius (though you didn't say anything about the location of that circle) using purely Hack Assembly Language. The answer is Yes, it is. You then asked for insight into how to solve that problem. That implies that you are at a loss how to figure out an algorithm to draw a circle using assembly language. That's all I had to go on, so I tried to explain how you would go about accomplishing that.

If you want advice that is more appropriate to what you are struggling with, then you are going to need to convey what it is you are struggling with.

What is it, precisely, that you are trying to achieve?
Reply | Threaded
Open this post in threaded view
|

Re: Screen Manipulation

advaith_dm
I have been trying to implementing mid point algorithm for drawing circles, breaking the algorithm/code down i realized the problem of coordinate systems, which is handled in high level languages.

By pointers i mean trying to set the M values of the corresponding pixel to 1 to change it to a dark colour. So basically i was implying the mapping to each pixel when i told that.

What i m trying to achieve is to draw a circle of arbitrary radius
Around center of the cpeu emulator screen. To which i m facing the issue of implementation stumbling on coordinate system definition and pixel mapping according to the developed coordinate system.
Reply | Threaded
Open this post in threaded view
|

Re: Screen Manipulation

WBahn
Administrator
ayush_shyam wrote
I have been trying to implementing mid point algorithm for circles, breaking the algorithm/code down i realized the problem of coordinate systems.

By pointers i mean trying to set the M values of the corresponding pixel to 1 to change it to a dark colour. So basically i was implying the mapping to each pixel when i told that.

What i m trying to achieve is to draw a circle of arbitrary radius
Around center of the cpeu emulator screen. To which i m facing the issue of implementation stumbling on coordinate system defenitions and pixel mappin according to the developed coordinate system.
So, if I understand you correctly, your assembly language program will be limited to drawing a circle of a user-specified radius centered in the middle of the screen.

Are you wanting to draw a filled circle, or just the circle outline?

Are you only drawing a black circle, or does the user get to specify color?

How does the radius get passed to your code?

Are you assuming that the radius is small enough so that the entire circle fits on the screen?

What do you want to have happen if part of the circle goes off the screen?

These are all interface specification issues that should be thought of ahead of time. They don't all have to be addressed in their final form all at once, however. For instance, you can say that, for now, you will assume that the requested radius is small enough so that the entire circle is on the screen and then go back later and decide how to handle situations in which it isn't.

The mapping between the RAM and the screen is explicitly spelled out in Section 4.2.5.

You have to decide what "the center" of the screen is. Since the screen dimensions are an even number, the center is located between two rows and two columns. Since you probably don't want to get into fractional pixel locations, you have to decide which of the slightly-off-center pixels you want to declare as the center of your circle.

The screen dimensions are 512x256, so I let's say that you want <256,128> to be the center.

So that's row 256 (with Row 0 at the top) and column 256 (with Col 0 at the left).
 
The RAM cell that controls this pixel is:
RAM[16384 + r*32 + c/16] = RAM[16384+4096+16] = RAM[20496].

The bit within that memory cell that controls that pixel is c%16 = 0 (or the lsb).

Do you understand how to set/clear individual bits within a word without affecting the others?
Reply | Threaded
Open this post in threaded view
|

Re: Screen Manipulation

advaith_dm
I think i have a somewhat idea on what to do now, thank you very much for the advice. It really helped sorting things out.
I ll reproach if i face any logical or technical issues.
Reply | Threaded
Open this post in threaded view
|

Re: Screen Manipulation

WBahn
Administrator
Sounds good and good luck to you. Again, this is not a trivial assembly language program, but it is very doable. You will almost certainly struggle with some things, but will end up justifiably proud after you succeed.