Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PORTB = $6000
- PORTA = $6001
- DDRB = $6002
- DDRA = $6003
- PCR = $600c
- IFR = $600d
- IER = $600e
- value = $0200 ;4 bytes
- mod10 = $0204 ;4 bytes
- message = $0208 ;16 bytes
- counter = $0218 ;4 bytes
- inshop = $021c ;1 byte
- countby = $021d ; 4 bytes
- shopselect = $021e ; 1 byte
- E = %10000000
- RW = %01000000
- RS = %00100000
- .org $8000
- reset:
- ldx #$ff
- txs
- cli
- lda #$82
- sta IER
- lda #$00
- sta PCR
- lda #%11111111 ; Set all pins on port B to output
- sta DDRB
- lda #%11100000 ; Set top 3 pins on port A to output
- sta DDRA
- lda #%00111000 ; Set 8-bit mode; 2-line display; 5x8 font
- jsr lcd_instruction
- lda #%00001110 ; Display on; cursor on; blink off
- jsr lcd_instruction
- lda #%00000110 ; Increment and shift cursor; don't shift display
- jsr lcd_instruction
- lda #$00000001 ; Clear display
- jsr lcd_instruction
- lda #%00000010 ; home LCD
- jsr lcd_instruction
- lda #0
- sta counter
- sta counter + 1
- lda #1
- sta inshop
- sta countby
- sta shopselect
- ;
- ;
- ;/out of shop
- ;
- ;
- out_shop:
- lda #%00000010 ; home LCD
- jsr lcd_instruction
- ldx #0
- print_bit:
- lda bitdsp,x
- beq bit_loop
- jsr print_char
- inx
- jmp print_bit
- ;loop for out of shop
- bit_loop:
- lda #%00000010 ; home LCD
- jsr lcd_instruction
- lda inshop
- cmp #%00000001 ; check if were in shop, 1= yes 0= no
- bne in_shop
- jmp displayBitValue
- jmp bit_loop
- ;
- ;
- ;in the shop
- ;
- ;
- in_shop:
- ldx #0
- shop_print:
- lda shoptextpos1,x
- beq shop_loop
- jsr print_char
- inx
- jmp shop_print
- ;loop for out of shop
- shop_loop:
- lda inshop
- cmp #%00000001 ; check if were in shop, 1= yes 0= no
- beq out_shop
- lda shopselect
- and #%00000111
- tax
- cpx #%00000001
- beq shoppos1
- cpx #%00000010
- beq shoppos2
- cpx #%00000011
- beq shoppos3
- cpx #%00000100
- beq shoppos4
- jmp shop_loop
- shoppos1:
- lda #%00000010 ; home LCD
- jsr lcd_instruction
- ldx #0
- shop_print1:
- lda shoptextpos1,x
- beq shop_loop
- jsr print_char
- inx
- jmp shop_print1
- shoppos2:
- lda #%00000010 ; home LCD
- jsr lcd_instruction
- ldx #0
- shop_print2:
- lda shoptextpos2,x
- beq shop_loop
- jsr print_char
- inx
- jmp shop_print2
- shoppos3:
- lda #%00000010 ; home LCD
- jsr lcd_instruction
- ldx #0
- shop_print3:
- lda shoptextpos3,x
- beq shop_loop
- jsr print_char
- inx
- jmp shop_print3
- shoppos4:
- lda #%00000010 ; home LCD
- jsr lcd_instruction
- ldx #0
- shop_print4:
- lda shoptextpos4,x
- beq shop_loop
- jsr print_char
- inx
- jmp shop_print4
- shoptextpos1: .asciiz " shop 1bc-2bc 4bc 8bc "
- shoptextpos2: .asciiz " shop 1bc 2bc-4bc 8bc "
- shoptextpos3: .asciiz " shop 1bc 2bc 4bc-8bc "
- shoptextpos4: .asciiz " shop 1bc 2bc 4bc 8bc- "
- bitdsp: .asciiz " bits "
- displayBitValue:
- lda #0
- sta message
- ; making value the number we wanna convert to binary
- lda counter
- sta value
- lda counter + 1
- sta value + 1
- divide:
- ; make remainder 0
- lda #0
- sta mod10
- sta mod10 + 1
- clc
- ldx #16
- divloop:
- ; rotate quotent and remainder
- rol value
- rol value + 1
- rol mod10
- rol mod10 + 1
- ; a,y = divident - divisor
- sec
- lda mod10
- sbc #10
- tay ; save low byte of the subtraction into Y
- lda mod10 + 1
- sbc #0
- bcc ignore_result ; branching if dividend is less than divisor
- sty mod10
- sta mod10 + 1
- ignore_result:
- dex
- bne divloop
- rol value ;shift the ast bit in the quotient
- rol value + 1
- lda mod10
- clc
- adc #"0"
- jsr push_char
- ; if value != 0 then continue dividing
- lda value
- ora value + 1
- bne divide ; branch if value != 0
- ldx #0
- print:
- lda message,x
- beq bit_looprs
- jsr print_char
- inx
- jmp print
- bit_looprs:
- jmp bit_loop
- ; add the character in the a register to the
- ; null-terminated string 'message'
- push_char:
- pha ; push new first char onto stack
- ldy #0
- char_loop
- lda message,y ; get char on string and put into x register
- tax
- pla
- sta message,y ; Pull char off stack and add it to the string
- iny
- txa
- pha ; Push char from string onto stack
- bne char_loop
- pla
- sta message,y ; pull the null of the stack and add to the end of the string
- rts
- lcd_wait:
- pha
- lda #%00000000 ; Port B is input
- sta DDRB
- lcdbusy:
- lda #RW
- sta PORTA
- lda #(RW | E)
- sta PORTA
- lda PORTB
- and #%10000000
- bne lcdbusy
- lda #RW
- sta PORTA
- lda #%11111111 ; Port B is output
- sta DDRB
- pla
- rts
- lcd_instruction:
- jsr lcd_wait
- sta PORTB
- lda #0 ; Clear RS/RW/E bits
- sta PORTA
- lda #E ; Set E bit to send instruction
- sta PORTA
- lda #0 ; Clear RS/RW/E bits
- sta PORTA
- rts
- print_char:
- jsr lcd_wait
- sta PORTB
- lda #RS ; Set RS; Clear RW/E bits
- sta PORTA
- lda #(RS | E) ; Set E bit to send instruction
- sta PORTA
- lda #RS ; Clear E bits
- sta PORTA
- rts
- decshoppos:
- dec shopselect
- jmp exit_irq
- incshoppos:
- inc shopselect
- jmp exit_irq
- ;
- ;
- ;intterupts!
- ;
- ;
- exit_irq
- pla
- tax
- pla
- bit PORTA
- rti
- irq:
- pha
- txa
- pha
- lda PORTA
- and #%00011111
- tax
- cpx #%00010000
- beq top_button
- cpx #%00001000
- beq right_button
- cpx #%00000100
- beq bottom_button
- cpx #%00000010
- beq left_button
- cpx #%00000001
- beq extra_button
- jmp exit_irq
- bottom_button: ;PA2 select and buy
- lda counter
- clc
- adc #3
- sta counter
- bcc exit_irq
- inc counter + 1
- jmp exit_irq
- left_button: ;PA1 move select left
- lda shopselect
- and #%00000111
- tax
- cpx #%00000001
- beq incshoppos
- cpx #%00000010
- beq incshoppos
- cpx #%00000011
- beq incshoppos
- cpx #%00000100
- beq exit_irq
- jmp exit_irq
- right_button: ;PA3 move select right
- lda shopselect
- and #%00000111
- tax
- cpx #%00000001
- beq exit_irq
- cpx #%00000010
- beq decshoppos
- cpx #%00000011
- beq decshoppos
- cpx #%00000100
- beq decshoppos
- jmp exit_irq
- top_button: ;PA4 clicker
- lda counter
- clc
- adc countby
- sta counter
- bcc exit_irq
- inc counter + 1
- bcc exit_irq
- inc counter + 2
- bcc exit_irq
- inc counter + 3
- jmp exit_irq
- extra_button: ;PA0 open/close shop
- ldx inshop
- cpx #%00000001
- beq exit_shop
- inc inshop
- jmp exit_irq
- exit_shop:
- ldx #$00
- stx inshop
- jmp exit_irq
- nmi:
- .org $fffa
- .word nmi
- .word reset
- .word irq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement