Advertisement
flip_floopOG

Clicker game version 0.02

Sep 11th, 2024
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PORTB = $6000
  2. PORTA = $6001
  3. DDRB = $6002
  4. DDRA = $6003
  5. PCR = $600c
  6. IFR = $600d
  7. IER = $600e
  8.  
  9. value = $0200 ;4 bytes
  10. mod10 = $0204 ;4 bytes
  11. message = $0208 ;16 bytes
  12. counter = $0218 ;4 bytes
  13. inshop = $021c ;1 byte
  14. countby = $021d ; 4 bytes
  15. shopselect = $021e ; 1 byte
  16.  
  17. E  = %10000000
  18. RW = %01000000
  19. RS = %00100000
  20.  
  21.   .org $8000
  22.  
  23. reset:
  24.   ldx #$ff
  25.   txs
  26.   cli
  27.  
  28.   lda #$82
  29.   sta IER
  30.   lda #$00
  31.   sta PCR
  32.  
  33.  
  34.   lda #%11111111 ; Set all pins on port B to output
  35.   sta DDRB
  36.   lda #%11100000 ; Set top 3 pins on port A to output
  37.   sta DDRA
  38.  
  39.   lda #%00111000 ; Set 8-bit mode; 2-line display; 5x8 font
  40.   jsr lcd_instruction
  41.   lda #%00001110 ; Display on; cursor on; blink off
  42.   jsr lcd_instruction
  43.   lda #%00000110 ; Increment and shift cursor; don't shift display
  44.   jsr lcd_instruction
  45.   lda #$00000001 ; Clear display
  46.   jsr lcd_instruction
  47.   lda #%00000010 ; home LCD
  48.   jsr lcd_instruction
  49.  
  50.   lda #0
  51.   sta counter
  52.   sta counter + 1
  53.   lda #1
  54.   sta inshop
  55.   sta countby
  56.   sta shopselect
  57.  
  58. ;
  59. ;
  60. ;/out of shop
  61. ;
  62. ;
  63.  
  64. out_shop:
  65.  
  66.   lda #%00000010 ; home LCD
  67.   jsr lcd_instruction
  68.  
  69.   ldx #0
  70. print_bit:
  71.   lda bitdsp,x
  72.   beq bit_loop
  73.   jsr print_char
  74.   inx
  75.   jmp print_bit
  76.  
  77.  
  78. ;loop for out of shop
  79.  
  80. bit_loop:
  81.   lda #%00000010 ; home LCD
  82.   jsr lcd_instruction
  83.  
  84.   lda inshop
  85.   cmp #%00000001 ; check if were in shop, 1= yes 0= no
  86.   bne in_shop
  87.  
  88.   jmp displayBitValue
  89.  
  90.   jmp bit_loop
  91.  
  92. ;
  93. ;
  94. ;in the shop
  95. ;
  96. ;
  97.  
  98. in_shop:
  99.   ldx #0
  100. shop_print:
  101.   lda shoptextpos1,x
  102.   beq shop_loop
  103.   jsr print_char
  104.   inx
  105.   jmp shop_print
  106.  
  107. ;loop for out of shop
  108.  
  109. shop_loop:
  110.   lda inshop
  111.   cmp #%00000001 ; check if were in shop, 1= yes 0= no
  112.   beq out_shop
  113.  
  114.   lda shopselect
  115.   and #%00000111
  116.   tax
  117.   cpx #%00000001
  118.   beq shoppos1
  119.   cpx #%00000010
  120.   beq shoppos2
  121.   cpx #%00000011
  122.   beq shoppos3
  123.   cpx #%00000100
  124.   beq shoppos4
  125.  
  126.   jmp shop_loop
  127.  
  128. shoppos1:
  129.   lda #%00000010 ; home LCD
  130.   jsr lcd_instruction
  131.   ldx #0
  132. shop_print1:
  133.   lda shoptextpos1,x
  134.   beq shop_loop
  135.   jsr print_char
  136.   inx
  137.   jmp shop_print1
  138. shoppos2:
  139.   lda #%00000010 ; home LCD
  140.   jsr lcd_instruction
  141.   ldx #0
  142. shop_print2:
  143.   lda shoptextpos2,x
  144.   beq shop_loop
  145.   jsr print_char
  146.   inx
  147.   jmp shop_print2
  148. shoppos3:
  149.   lda #%00000010 ; home LCD
  150.   jsr lcd_instruction
  151.   ldx #0
  152. shop_print3:
  153.   lda shoptextpos3,x
  154.   beq shop_loop
  155.   jsr print_char
  156.   inx
  157.   jmp shop_print3
  158. shoppos4:
  159.   lda #%00000010 ; home LCD
  160.   jsr lcd_instruction
  161.   ldx #0
  162. shop_print4:
  163.   lda shoptextpos4,x
  164.   beq shop_loop
  165.   jsr print_char
  166.   inx
  167.   jmp shop_print4
  168.  
  169.  
  170.  
  171.  
  172.  
  173. shoptextpos1: .asciiz "      shop                              1bc-2bc 4bc 8bc   "
  174. shoptextpos2: .asciiz "      shop                              1bc 2bc-4bc 8bc   "
  175. shoptextpos3: .asciiz "      shop                              1bc 2bc 4bc-8bc   "
  176. shoptextpos4: .asciiz "      shop                              1bc 2bc 4bc 8bc-  "
  177. bitdsp: .asciiz "                                        bits                    "
  178.  
  179.  
  180.  
  181. displayBitValue:
  182.   lda #0
  183.   sta message
  184.  
  185.   ; making value the number we wanna convert to binary
  186.   lda counter
  187.   sta value
  188.   lda counter + 1
  189.   sta value + 1
  190.  
  191. divide:
  192.   ; make remainder 0
  193.   lda #0
  194.   sta mod10
  195.   sta mod10 + 1
  196.   clc
  197.  
  198.   ldx #16
  199. divloop:
  200.   ; rotate quotent and remainder
  201.   rol value
  202.   rol value + 1
  203.   rol mod10
  204.   rol mod10 + 1
  205.  
  206.   ; a,y = divident - divisor
  207.   sec
  208.   lda mod10
  209.   sbc #10
  210.   tay               ; save low byte of the subtraction into Y
  211.   lda mod10 + 1
  212.   sbc #0
  213.   bcc ignore_result ; branching if dividend is less than divisor
  214.   sty mod10
  215.   sta mod10 + 1
  216.  
  217. ignore_result:
  218.   dex
  219.   bne divloop
  220.   rol value ;shift the ast bit in the quotient
  221.   rol value + 1
  222.  
  223.   lda mod10
  224.   clc
  225.   adc #"0"
  226.   jsr push_char
  227.  
  228.   ; if value != 0 then continue dividing
  229.   lda value
  230.   ora value + 1
  231.   bne divide ; branch if value != 0
  232.  
  233.   ldx #0
  234. print:
  235.   lda message,x
  236.   beq bit_looprs
  237.   jsr print_char
  238.   inx
  239.   jmp print
  240.  
  241. bit_looprs:
  242.   jmp bit_loop
  243.  
  244.  
  245.  
  246.  
  247. ; add the character in the a register to the
  248. ; null-terminated string 'message'
  249. push_char:
  250.   pha  ; push new first char onto stack
  251.   ldy #0
  252.  
  253. char_loop
  254.   lda message,y  ; get char on string and put into x register
  255.   tax
  256.   pla
  257.   sta message,y  ; Pull char off stack and add it to the string
  258.   iny
  259.   txa
  260.   pha            ; Push char from string onto stack
  261.   bne char_loop
  262.  
  263.   pla
  264.   sta message,y  ; pull the null of the stack and add to the end of the string
  265.  
  266.   rts
  267.  
  268.  
  269. lcd_wait:
  270.   pha
  271.   lda #%00000000  ; Port B is input
  272.   sta DDRB
  273. lcdbusy:
  274.   lda #RW
  275.   sta PORTA
  276.   lda #(RW | E)
  277.   sta PORTA
  278.   lda PORTB
  279.   and #%10000000
  280.   bne lcdbusy
  281.  
  282.   lda #RW
  283.   sta PORTA
  284.   lda #%11111111  ; Port B is output
  285.   sta DDRB
  286.   pla
  287.   rts
  288.  
  289. lcd_instruction:
  290.   jsr lcd_wait
  291.   sta PORTB
  292.   lda #0         ; Clear RS/RW/E bits
  293.   sta PORTA
  294.   lda #E         ; Set E bit to send instruction
  295.   sta PORTA
  296.   lda #0         ; Clear RS/RW/E bits
  297.   sta PORTA
  298.   rts
  299.  
  300. print_char:
  301.  
  302.   jsr lcd_wait
  303.   sta PORTB
  304.   lda #RS         ; Set RS; Clear RW/E bits
  305.   sta PORTA
  306.   lda #(RS | E)   ; Set E bit to send instruction
  307.   sta PORTA
  308.   lda #RS         ; Clear E bits
  309.   sta PORTA
  310.   rts
  311.  
  312. decshoppos:
  313.   dec shopselect
  314.   jmp exit_irq
  315. incshoppos:
  316.   inc shopselect
  317.   jmp exit_irq
  318.  
  319. ;
  320. ;
  321. ;intterupts!
  322. ;
  323. ;
  324. exit_irq
  325.   pla
  326.   tax
  327.   pla
  328.   bit PORTA
  329.   rti
  330.  
  331. irq:
  332.   pha
  333.   txa
  334.   pha
  335.   lda PORTA
  336.   and #%00011111
  337.   tax
  338.   cpx #%00010000
  339.   beq top_button
  340.   cpx #%00001000
  341.   beq right_button
  342.   cpx #%00000100
  343.   beq bottom_button
  344.   cpx #%00000010
  345.   beq left_button
  346.   cpx #%00000001
  347.   beq extra_button
  348.  
  349.   jmp exit_irq
  350.  
  351. bottom_button: ;PA2 select and buy
  352.   lda counter
  353.   clc
  354.   adc #3
  355.   sta counter
  356.   bcc exit_irq
  357.   inc counter + 1
  358.   jmp exit_irq
  359.  
  360. left_button: ;PA1 move select left
  361.   lda shopselect
  362.   and #%00000111
  363.   tax
  364.   cpx #%00000001
  365.   beq incshoppos
  366.   cpx #%00000010
  367.   beq incshoppos
  368.   cpx #%00000011
  369.   beq incshoppos
  370.   cpx #%00000100
  371.   beq exit_irq
  372.   jmp exit_irq
  373.  
  374. right_button: ;PA3 move select right
  375.   lda shopselect
  376.   and #%00000111
  377.   tax
  378.   cpx #%00000001
  379.   beq exit_irq
  380.   cpx #%00000010
  381.   beq decshoppos
  382.   cpx #%00000011
  383.   beq decshoppos
  384.   cpx #%00000100
  385.   beq decshoppos
  386.   jmp exit_irq
  387.  
  388. top_button: ;PA4 clicker
  389.   lda counter
  390.   clc
  391.   adc countby
  392.   sta counter
  393.   bcc exit_irq
  394.   inc counter + 1
  395.   bcc exit_irq
  396.   inc counter + 2
  397.   bcc exit_irq
  398.   inc counter + 3
  399.   jmp exit_irq
  400.  
  401. extra_button: ;PA0 open/close shop
  402.   ldx inshop
  403.   cpx #%00000001
  404.   beq exit_shop
  405.   inc inshop
  406.   jmp exit_irq
  407.  
  408. exit_shop:
  409.   ldx #$00
  410.   stx inshop
  411.   jmp exit_irq
  412.  
  413. nmi:
  414.  
  415.  
  416.  
  417.  
  418.   .org $fffa
  419.   .word nmi
  420.   .word reset
  421.   .word irq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement