SPO600 Lab3 - decide what to write
Hamburger application
In this Lab, we are allowed to decide what program to write as long as the program meet the below criteria:-
1. The program have to work in the 6520 Emulator
2. Output to the character screen and the graphic screen
3. get input from the keyboard
4. use some math instruction, e.g. add/ subtract
On this long night of assignments, I was so hungry that I decided to create a Hamburger application to design my own burger!
Remark: This program is original.
Specification:
1. The user will be able to choose the filling of the hamburger, e.g. egg, meat and vegetables, by pressing number key on keyboard.
2. Instruction of the program, filling options and respective cost will be printed on the character screen.
3. The graphic screen will show the hamburger. When filling is choose by the user, the filling will be added to the graphic screen.
4. After four filling are added, the burger on the graphic display will be completed.
5. Total cost will be calculated and displayed on the character display.
code:
define SCINIT $ff81 ; Initialize and clear the character display
define CHROUT $ffd2 ; print accumulator's value to screen
define CCOUNT $0010
define STPT_L $11
define STPT_H $12
define COLOR $13
define COST_L $14
define COST_H $15
jsr SCINIT
ldy #$02
sty COST_H
ldy #$00
sty COST_L
lda #$04
sta CCOUNT
lda #$02
sta STPT_H
lda #$A0
sta STPT_L
menu: lda instruc,y
beq ini
jsr CHROUT
iny
bne menu
ini:
lda #$08
ldy #$00
layer1:
sta $0266, y
iny
cpy #$14
bne layer1
ldy #$00
layer2:
sta $0284, y
iny
cpy #$18
bne layer2
ldy #$00
;draw bread
lda #$08
sta COLOR
jsr food
loop:
jsr getkey
cmp #$31
beq lettuce
cmp #$32
bne getegg
jmp meat
getegg: jmp egg
add: jsr food
dec CCOUNT
bne loop
;draw bread
lda #$08
sta COLOR
jsr food
lda #$08
ldy #$00
layer4:
sta $0506, y
iny
cpy #$14
bne layer4
ldy #$00
layer3:
sta $04e4, y
iny
cpy #$18
bne layer3
ldy #$00
;print cost
ldy #$00
cost: lda price,y
beq cashier
jsr CHROUT
iny
bne cost
cashier:
lda COST_H
clc
adc #$30
jsr CHROUT
ldy COST_L
beq done; 00 cents
lda #$2e
jsr CHROUT
cpy #$40 ; check if 25 cents
bne check50
lda #$32
JSR CHROUT
lda #$35
jsr CHROUT
jmp done
check50: cpy #$80 ; check if 50 cents
bne print75
lda #$35
JSR CHROUT
jmp done
print75:
lda #$37
JSR CHROUT
lda #$35
JSR CHROUT
jmp done
;=========================================
done:
brk
lettuce:
lda #$05
sta COLOR
lda COST_L
SEC
SBC #$40
STA COST_L
lda COST_H
SBC #$00
STA COST_H
jmp add
meat:
lda #$09
sta COLOR
lda #$80
clc
adc COST_L
sta COST_L
lda #$01
adc COST_H
sta COST_H
jmp add
egg:
lda #$01
sta COLOR
lda #$c0
clc
adc COST_L
sta COST_L
lda #$00
adc COST_H
sta COST_H
jmp add
food:
ldx #$00
lda COLOR
food_i:
ldy #$03
lda COLOR
jsr draw
lda #$20
clc
adc STPT_L
sta STPT_L
bne next
inc STPT_H
next: inx
cpx #$03 ; draw 2 layer
bne food_i
rts
;a: color code, STPL_L: start position; y:offset
draw:
sta (STPT_L), y
iny
cpy #$1d
bne draw
rts
getkey: ;to get the input 1/2/3 to accumulator
lda $ff
beq getkey
cmp #$31
bmi getkey
cmp #$34
bpl getkey
ldx #$00
stx $ff
rts
instruc:
dcb "S","e","l","e","c","t",32,"4",32,"B","u","r","g","e"
dcb "r",32,"f","i","l","l","i","n","g",32,"b","y",32
dcb "p","r","e","s","s","i","n","g",32,"1",$2c,32,"2",32
dcb "o","r",32,"3",$0d,"(","b","a","s","e",32,"c","o","s"
dcb "t",":",32,"$","2",")",$0d
dcb "O","p","t","i","o","n","s",":",$0d
dcb "1",":","l","e","t","t"
dcb "u","c","e",32,"-","$","0",".","2","5",$0d
dcb "2",":","m","e","a","t",32,"$","1",".","5",$0d
dcb "3",".","e","g","g",32,"$","0",".","7","5",$0d,00
price:
dcb "y","o","u","r",32,"c","o","s","t",32,"i","s",":",32
dcb "$",00
Reflection:
Designing a new program that utilizes the graphics screen, character screen, keyboard input, and mathematical operations, while keeping it simple enough to implement in assembly was not easy. I spent a significant amount of time refining the design.
In this lab, I applied what I recently learned in the SPO600 course. I used the character screen to display content, with the dcb keyword proving especially useful for storing messages and text. Meanwhile, the graphics screen enhances the user experience, though it presents challenges for the programmer. I had to rely on trial and error to complete the image pixel by pixel. Additionally, I practiced performing addition and subtraction on two-byte values, utilizing the carry flag. I particularly enjoyed making my application interactive by allowing the user to provide input.
Comments
Post a Comment