Skip to main content

Colour Selection

Photo by Scott Webb on Unsplash


Today I'll talk about Lab 4. We had to pick two tasks out of four and develop the solution using my least favour language: assembly. Our group chose the options 2 (data input form) and 4 (screen colour selector) thinking that would be the easiest ones. The other options were adding calculator and hexdump. This post will talk about the colour selector, and my next will be the input form.

The colour selector project was quite easy to do relatively. There are only 16 colours available (0 to F in hex). We have to list them in the text area and allow the selection using the cursor (up and down). Once the colour is selected, we have to paint the graph area.

The graph area we did before. Basically, we have to store the colour code for every pixel in the display using the memory location between $0200 and $05FF. In the last post, we deal with up and down keys to change the numeric display. However, we never dealt with character display before.

The character display works the same way as the graph. Its memory locations range from $F000 to $F7CF and have 25 lines of 80 characters (80x25). The complication here is the navigation between rows. It is not a matter of just increment the high bite – meaning more code and more working hours. Fortunately, we have ROM routines to help us to navigate, get and set the characters. Just like calling a function.

To know more about the ROM routines, access the 6502 simulator notes and take a look at "ROM Routines."

I tried to put as many comments in the code that I could. Also, that was my first time using the stack (instructions pha and pla) that saved my code! The stack is a handy area to save data when you need to free registers to do something and then restore that data.

I'm proud of myself finishing this code. I know that is room for improvement, but I can see my progress using assembly. See you in the next post.

; ROM routines
define SCINIT $ff81 ; initialize/clear screen
define CHRIN $ffcf ; input character from keyboard
define CHROUT $ffd2 ; output character to screen
define SCREEN $ffed ; get screen size
define PLOT $fff0 ; get/set cursor coordinates
define cur_pos $10
jsr SCINIT
ldy #$00
ldx #$00
stx cur_pos
char: lda color_list,y
beq main
jsr CHROUT
iny
bne char
main:
lda $ff ; get a keystroke
beq main ; fix freezing on max speed
ldx #$00 ; clear out the key buffer
stx $ff
cmp #$71 ; handle q -> increment
beq incr
cmp #$77 ; handle w -> decrement
beq decr
jmp main ; if no key pressed loop forever
clear_cursor:
lda #$2d ; character -
jsr print_cursor
rts
incr:
jsr clear_cursor
inc cur_pos
lda cur_pos
cmp #$10
beq incr_reset
bne incr_decr
incr_reset:
lda #$00
sta cur_pos
jmp incr_decr
decr:
jsr clear_cursor
dec cur_pos
lda cur_pos
cmp #$FF
beq decr_reset
bne incr_decr
decr_reset:
lda #$0F
sta cur_pos
jmp incr_decr
incr_decr:
lda #$93 ; character black box
jsr print_cursor
jmp paint
print_cursor:
clc ; select the SET function for PLOT
ldx #$00
ldy cur_pos ; increment this one
pha ; save the value of A into the stack
jsr PLOT ; set the cursor position
pla ; restore the value of A from the stack
jsr CHROUT ; print the char
rts
paint:
ldx #$06 ; max value for $11
ldy #$00 ; index
lda #$00 ; set pointer at $10 to $0200
sta $11
lda #$02
sta $12
lda cur_pos ; set the color
jmp paint_loop
paint_loop:
sta ($11),y ; store colour
iny ; increment index
bne paint_loop ; branch until page done
inc $12 ; increment high byte of pointer
cpx $12 ; compare with max value
bne paint_loop ; continue if not done
jmp main ; done - return to main
color_list:
dcb $93,"B","l","a","c","k",13
dcb "-","W","h","i","t","e",13
dcb "-","R","e","d",13
dcb "-","C","y","a","n",13
dcb "-","P","u","r","p","l","e",13
dcb "-","G","r","e","e","n",13
dcb "-","B","l","u","e",13
dcb "-","Y","e","l","l","o","w",13
dcb "-","O","r","a","n","g","e",13
dcb "-","B","r","o","w","n",13
dcb "-","L","i","g","h","t",32,"r","e","d",13
dcb "-","D","a","r","k",32,"g","r","e","y",13
dcb "-","G","r","e","y",13
dcb "-","L","i","g","h","t",32,"g","r","e","e","n",13
dcb "-","L","i","g","h","t",32,"b","l","u","e",13
dcb "-","L","i","g","h","t",32,"g","r","e","y",00
view raw spo-lab4a.s hosted with ❤ by GitHub

Comments

Popular posts from this blog

Going Faster

Photo by  Anders Jildén  on  Unsplash Today’s topic is compiler optimizations. Besides translating our source code into machine binary executable, the compiler, based on optimization parameters, can also produce faster executables. Just by adding some parameters to the compiler, we can get a better performance or a smaller executable, for example. There are hundreds of those parameters which we can turn on or off using the prefix -f and -fno. However, instead of doing one by one, we can use the features mode using the -O param. It ranges from 0 (no optimization – the default) to 3 (the highest). Using those parameters has a cost —usually, the faster, the larger executable. How does the compiler make it faster if my code is perfect? I’m going to put some methods here, but if you want, here is more detail . Also, bear in mind that most of the optimizations are done in the intermediate representation of the program. So, the examples below are rewritten just to...

Data Input Form

Photo by  Marvin Meyer  on  Unsplash Continuing the Lab 4, we are going to develop the option 2, data input form. The goal is to prompt the user to enter its name, address, city, province and postal code. Also, letting the user use up, down, left, and right arrows to navigate throughout the fields. After finishing the data input, a summary is presented at the end. Using the ROM routines, wasn’t too hard to allow users to type data into the character display. Then, I decided to make the filed names with the same width, 14 characters, limiting the input to 40 characters. So, the user is not allowed to type in the first 14 and after 54 characters. When the user presses enter at the last field, the summary is shown. I could display the fixed message, but I couldn’t copy the inserted data. I’m still working on that, and I’ll update this post as soon I figure it out. It is frustrating for me to spend days in basic problems that could be solved quickly using other langu...

Two-digit Numeric Display - Final

Photo by  Nick Hillier  on  Unsplash In this post, I’ll continue the two-digit numeric display. If you miss it, click here and check it out . To finish this project, we just need to show the numbers in the matrix-pixel (the black-box in the 6502 emulator ). To kickstart, our instructor gave us one example of how to display graphs, which was a lot helpful. The first thing that I’ve noticed was the bitmap table at the bottom. So, I mimic it and made ten tables like that to represent each number (zero to nine). So far, so good! Then I grabbed the logic to display one digit, and then my nightmares just started. How to place two graphs (one for each digit)? How to switch from one number to another? How to reuse code? Where is my coffee?! To emulate some if-elseif-else statements, I used jmp (jump). They are all over the place! However, the 6502 limits the jump range from -127 to 128. That means moving the code-blocks to satisfy all jumps limit. For e...