Hello all, sorry for the lack of updates, school assignments have been keeping me very busy which is why I have been quiet up till now.
That said, I have some more 6502 assembler goodness to report. Earlier this month the group I was assigned to was tasked with completing two of four assembler coding tasks. We chose to tackle the code that would fill the graphical display depending on the color selected in the text display, and the calculator challenge that required us to write code so that a user could add two number, where each could be a maximum value of 99.
Now I’ll be frank and say that I probably will not get around to finishing the second coding task. That will be something I’ll try to tackle on my own time, as well as figuring out how to make a two player pong game… What I can talk about though is the work I did on the color display. For this particular lab, our professor provided “Rom Routines” for the 6502 emulator we are working with, and they mainly relate to displaying text on the screen. Now you may be asking,
“What the heck is a Rom Routine?”
Well in simple terms, it is per-programmed code which is stored in memory chip, and can be used to complete various operations, as well as add extra functionality to the computer chip’s set of instructions.
That out of the way, what did I do for my program? Well, the main ones I used helped in outputting text to the screen (“CHROUT” aka character output), while using another (PLOT) to get, and set the horizontal / vertical position of the text cursor. You can learn more about all the routines that were available to us here, however I will be focusing on the two I mentioned above.
Now CHAROUT is pretty straightforward, it outputs one character of text. If you iterate through a sequence of characters, and then call this routine, it will output the sequence.
loop:
lda text,y ;load memory with a text sequence and add 1 via an index (y) to shift to the next character
beq done ;finish when the index equals the end of the sequence
jsr CHROUT ;the rom routine that will output the character loaded into memory
iny ;increment the index/ basically it's like inputting 1+ in a calculator to count upward
bne loop ;keep looping if the index is not equal to the end of the sequence
Above you see a basic loop using the CHROUT rom routine. Now try to assume that “text” in the code above is pointing to as sequence of characters stored in an area of memory, in this format:
“h”,”e”,”l”,”l”,”o”,00
Each character is a position in this comma separated sequence and so you need to count through this sequence to print the word “hello.” If you’re wondering about the two zeroes at the end, that is to indicate the end of the sequence.
Ok what about PLOT? Well this can be complicated so I’ll try to keep it simple. The PLOT routine requires a bit of setup to get or set the cursor information. You have to do things like manipulating the carry flag in the processor, which will dictate what operation PLOT should carry out… No pun intended. If you are not sure what I mean by carry, basically it’s how we carry over powers of 10 other digits in a number when doing addition. You know right? In addition you sometimes have to write a “1” over a number to show that the value has been passed on to the next power.
1 <— this is a carry since 3 + 9 = 12
23
+ 29
5 2
Ok math lesson over. When you make that carry disappear for the processor, the PLOT routine will set the horizontal and vertical position of the cursor. Once the position has been set, we as programmers can then modify what is outputted at that position. In regards to my program, I wanted to invert the color of the character where the cursor was located. To do this I have to invoke reverse mode to create the desired effect. How I go about this requires that you understand hexadecimal values, and that anything above a value of 127 will result in reverse mode. As long as you understand this you can then create the desired effect by using mathematical operations like Bitwise Or to modify the value. In my code, if you look at the inc_color section, you will see ORA opcode with the hex value of 80. That value in hex is 128, essentially forcing a characters value to be above 127, and reversing the display. In this case I changed the “-” or hex 2d (represents the value of 45) character’s value to hex ad (45 + 128 = 173) to make it display in reverse.
Well that is all for this month, next week I should be able to update you on my next lab assignment using the AArch64 architecture. Please look forward to it!