Advertisement
flip_floopOG

Clicker game version 0.04

Sep 12th, 2024 (edited)
177
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. ;
  13. counter = $0218 ;4 bytes
  14. inshop = $021c ;1 byte
  15. ;
  16. countby = $021d ; 4 bytes
  17. ;
  18. shopselect = $021e ; 1 byte
  19. ;
  20. onebcTotAmm = $021f ; 2 bytes
  21. twobcTotAmm = $0221 ; 2 bytes
  22. threebcTotAmm = $0223 ; 2 bytes
  23. fourbcTotAmm = $0225 ; 2 bytes
  24. ;
  25. onebkTotAmm = $0227 ; 2 bytes
  26. twobkTotAmm = $0229 ; 2 bytes
  27. threebkTotAmm = $022b ; 2 bytes
  28. fourbkTotAmm = $022d ; 2 bytes
  29. ;
  30. bitinctotal = $022f ; 4 bytes
  31. ;
  32. onebccost = $0233 ; 3 bytes
  33. twobccost = $0236 ; 3 bytes
  34. threebccost = $0239 ; 3 bytes
  35. fourbccost = $023b ; 3 bytes
  36.  
  37. onebkcost = $023e ; 3 bytes
  38. twobkcost = $0242 ; 3 bytes
  39. threebkcost = $0245 ; 3 bytes
  40. fourbkcost = $0248 ; 3 bytes
  41.  
  42. E  = %10000000
  43. RW = %01000000
  44. RS = %00100000
  45.  
  46.   .org $8000
  47.  
  48. reset:
  49.   ldx #$ff
  50.   txs
  51.   cli
  52.  
  53.   lda #$82
  54.   sta IER
  55.   lda #$00
  56.   sta PCR
  57.  
  58.  
  59.   lda #%11111111 ; Set all pins on port B to output
  60.   sta DDRB
  61.   lda #%11100000 ; Set top 3 pins on port A to output
  62.   sta DDRA
  63.  
  64.   lda #%00111000 ; Set 8-bit mode; 2-line display; 5x8 font
  65.   jsr lcd_instruction
  66.   lda #%00001110 ; Display on; cursor on; blink off
  67.   jsr lcd_instruction
  68.   lda #%00000110 ; Increment and shift cursor; don't shift display
  69.   jsr lcd_instruction
  70.   lda #$00000001 ; Clear display
  71.   jsr lcd_instruction
  72.   lda #%00000010 ; home LCD
  73.   jsr lcd_instruction
  74.  
  75.   lda #0
  76.   sta counter
  77.   sta counter + 1
  78.   sta bitinctotal
  79.   sta bitinctotal + 1
  80.   sta bitinctotal + 2
  81.   sta bitinctotal + 3
  82.  
  83.   sta onebcTotAmm
  84.   sta onebcTotAmm + 1
  85.   sta twobcTotAmm
  86.   sta twobcTotAmm + 1
  87.   sta threebcTotAmm
  88.   sta threebcTotAmm + 1
  89.   sta fourbcTotAmm
  90.   sta fourbcTotAmm + 1
  91.  
  92.   sta onebkTotAmm
  93.   sta onebkTotAmm + 1
  94.   sta twobkTotAmm
  95.   sta twobkTotAmm + 1
  96.   sta threebkTotAmm
  97.   sta threebkTotAmm + 1
  98.   sta fourbkTotAmm
  99.   sta fourbkTotAmm + 1
  100.  
  101.   lda #1
  102.   sta inshop
  103.   sta countby
  104.   sta countby + 1
  105.   sta countby + 2
  106.   sta countby + 3
  107.   sta shopselect
  108.  
  109.  
  110. onebccost = $0233 ; 3 bytes
  111. twobccost = $0236 ; 3 bytes
  112. threebccost = $0239 ; 3 bytes
  113. fourbccost = $023b ; 3 bytes
  114.  
  115. onebkcost = $023e ; 3 bytes
  116. twobkcost = $0242 ; 3 bytes
  117. threebkcost = $0245 ; 3 bytes
  118. fourbkcost = $0248 ; 3 bytes
  119.   lda #64
  120.   sta onebccost
  121.   sta onebccost + 1
  122.   sta onebccost + 2
  123.   lda #256
  124.   sta twobccost
  125.   sta twobccost + 1
  126.   sta twobccost + 2
  127.   lda #256
  128.   sta threebccost
  129.   sta threebccost + 1
  130.   sta threebccost + 2
  131.   lda #4096
  132.   sta fourbccost
  133.   sta fourbccost + 1
  134.   sta fourbccost + 2
  135.  
  136.  
  137.  
  138.  
  139.  
  140. ;
  141. ;
  142. ;/out of shop
  143. ;
  144. ;
  145.  
  146. out_shop:
  147.  
  148.   lda #%00000010 ; home LCD
  149.   jsr lcd_instruction
  150.  
  151.   ldx #0
  152. print_bit:
  153.   lda bitdsp,x
  154.   beq bit_loop
  155.   jsr print_char
  156.   inx
  157.   jmp print_bit
  158.  
  159.  
  160. ;loop for out of shop
  161.  
  162. bit_loop:
  163.   lda #%00000010 ; home LCD
  164.   jsr lcd_instruction
  165.  
  166.   lda inshop
  167.   cmp #%00000001 ; check if were in shop, 1= yes 0= no
  168.   bne in_shop
  169.  
  170.   jmp displayBitValue
  171.  
  172.   jmp bit_loop
  173.  
  174. ;
  175. ;
  176. ;in the shop
  177. ;
  178. ;
  179.  
  180. in_shop:
  181.   ldx #0
  182. shop_print:
  183.   lda shoptextpos1,x
  184.   beq shop_loop
  185.   jsr print_char
  186.   inx
  187.   jmp shop_print
  188.  
  189. ;loop for out of shop
  190.  
  191. shop_loop:
  192.   lda inshop
  193.   cmp #%00000001 ; check if were in shop, 1= yes 0= no
  194.   beq out_shop
  195.   jmp shop_loopb
  196.  
  197.  
  198. shoppos1:
  199.   lda #%00000010 ; home LCD
  200.   jsr lcd_instruction
  201.   ldx #0
  202. shop_print1:
  203.   lda shoptextpos1,x
  204.   beq shop_loopa
  205.   jsr print_char
  206.   inx
  207.   jmp shop_print1
  208. shoppos2:
  209.   lda #%00000010 ; home LCD
  210.   jsr lcd_instruction
  211.   ldx #0
  212. shop_print2:
  213.   lda shoptextpos2,x
  214.   beq shop_loopa
  215.   jsr print_char
  216.   inx
  217.   jmp shop_print2
  218. shoppos3:
  219.   lda #%00000010 ; home LCD
  220.   jsr lcd_instruction
  221.   ldx #0
  222. shop_print3:
  223.   lda shoptextpos3,x
  224.   beq shop_loopa
  225.   jsr print_char
  226.   inx
  227.   jmp shop_print3
  228. shoppos4:
  229.   lda #%00000010 ; home LCD
  230.   jsr lcd_instruction
  231.   ldx #0
  232. shop_print4:
  233.   lda shoptextpos4,x
  234.   beq shop_loopa
  235.   jsr print_char
  236.   inx
  237.   jmp shop_print4
  238. ;
  239.  
  240. shop_loopb:
  241.   lda shopselect
  242.   and #%00001111
  243.   tax
  244.   cpx #%00000001
  245.   beq shoppos1
  246.   cpx #%00000010
  247.   beq shoppos2
  248.   cpx #%00000011
  249.   beq shoppos3
  250.   cpx #%00000100
  251.   beq shoppos4
  252.   cpx #%00000101
  253.   beq shoppos1a
  254.   cpx #%00000110
  255.   beq shoppos2a
  256.   cpx #%00000111
  257.   beq shoppos3a
  258.   cpx #%00001000
  259.   beq shoppos4a
  260.   jmp shop_loop
  261. ;
  262. shop_loopa:
  263.   jmp shop_loop
  264. ;
  265. shoppos1a:
  266.   lda #%00000010 ; home LCD
  267.   jsr lcd_instruction
  268.   ldx #0
  269. shop_print1a:
  270.   lda shoptextpos1a,x
  271.   beq shop_loopa
  272.   jsr print_char
  273.   inx
  274.   jmp shop_print1a
  275. shoppos2a:
  276.   lda #%00000010 ; home LCD
  277.   jsr lcd_instruction
  278.   ldx #0
  279. shop_print2a:
  280.   lda shoptextpos2a,x
  281.   beq shop_loopa
  282.   jsr print_char
  283.   inx
  284.   jmp shop_print2a
  285. shoppos3a:
  286.   lda #%00000010 ; home LCD
  287.   jsr lcd_instruction
  288.   ldx #0
  289. shop_print3a:
  290.   lda shoptextpos3a,x
  291.   beq shop_loopa
  292.   jsr print_char
  293.   inx
  294.   jmp shop_print3a
  295. shoppos4a:
  296.   lda #%00000010 ; home LCD
  297.   jsr lcd_instruction
  298.   ldx #0
  299. shop_print4a:
  300.   lda shoptextpos4a,x
  301.   beq shop_loopa
  302.   jsr print_char
  303.   inx
  304.   jmp shop_print4a
  305.  
  306.  
  307.  
  308. shoptextpos1: .asciiz "      shop     >                        1bc-2bc 4bc 8bc   "
  309. shoptextpos2: .asciiz "      shop     >                        1bc 2bc-4bc 8bc   "
  310. shoptextpos3: .asciiz "      shop     >                        1bc 2bc 4bc-8bc   "
  311. shoptextpos4: .asciiz "      shop     >                        1bc 2bc 4bc 8bc-  "
  312.  
  313. shoptextpos1a: .asciiz "<     shop                              1bk-2bk 4bk 8bk   "
  314. shoptextpos2a: .asciiz "<     shop                              1bk 2bk-4bk 8bk   "
  315. shoptextpos3a: .asciiz "<     shop                              1bk 2bk 4bk-8bk   "
  316. shoptextpos4a: .asciiz "<     shop                              1bk 2bk 4bk 8bk-  "
  317.  
  318. bitdsp: .asciiz "                                        bits                    "
  319.  
  320.  
  321.  
  322. displayBitValue:
  323.   lda #0
  324.   sta message
  325.  
  326.   ; making value the number we wanna convert to binary
  327.   lda counter
  328.   sta value
  329.   lda counter + 1
  330.   sta value + 1
  331.  
  332. divide:
  333.   ; make remainder 0
  334.   lda #0
  335.   sta mod10
  336.   sta mod10 + 1
  337.   clc
  338.  
  339.   ldx #16
  340. divloop:
  341.   ; rotate quotent and remainder
  342.   rol value
  343.   rol value + 1
  344.   rol mod10
  345.   rol mod10 + 1
  346.  
  347.   ; a,y = divident - divisor
  348.   sec
  349.   lda mod10
  350.   sbc #10
  351.   tay               ; save low byte of the subtraction into Y
  352.   lda mod10 + 1
  353.   sbc #0
  354.   bcc ignore_result ; branching if dividend is less than divisor
  355.   sty mod10
  356.   sta mod10 + 1
  357.  
  358. ignore_result:
  359.   dex
  360.   bne divloop
  361.   rol value ;shift the ast bit in the quotient
  362.   rol value + 1
  363.  
  364.   lda mod10
  365.   clc
  366.   adc #"0"
  367.   jsr push_char
  368.  
  369.   ; if value != 0 then continue dividing
  370.   lda value
  371.   ora value + 1
  372.   bne divide ; branch if value != 0
  373.  
  374.   ldx #0
  375. print:
  376.   lda message,x
  377.   beq bit_looprs
  378.   jsr print_char
  379.   inx
  380.   jmp print
  381.  
  382. bit_looprs:
  383.   jmp bit_loop
  384.  
  385.  
  386.  
  387.  
  388. ; add the character in the a register to the
  389. ; null-terminated string 'message'
  390. push_char:
  391.   pha  ; push new first char onto stack
  392.   ldy #0
  393.  
  394. char_loop
  395.   lda message,y  ; get char on string and put into x register
  396.   tax
  397.   pla
  398.   sta message,y  ; Pull char off stack and add it to the string
  399.   iny
  400.   txa
  401.   pha            ; Push char from string onto stack
  402.   bne char_loop
  403.  
  404.   pla
  405.   sta message,y  ; pull the null of the stack and add to the end of the string
  406.  
  407.   rts
  408.  
  409.  
  410. lcd_wait:
  411.   pha
  412.   lda #%00000000  ; Port B is input
  413.   sta DDRB
  414. lcdbusy:
  415.   lda #RW
  416.   sta PORTA
  417.   lda #(RW | E)
  418.   sta PORTA
  419.   lda PORTB
  420.   and #%10000000
  421.   bne lcdbusy
  422.  
  423.   lda #RW
  424.   sta PORTA
  425.   lda #%11111111  ; Port B is output
  426.   sta DDRB
  427.   pla
  428.   rts
  429.  
  430. lcd_instruction:
  431.   jsr lcd_wait
  432.   sta PORTB
  433.   lda #0         ; Clear RS/RW/E bits
  434.   sta PORTA
  435.   lda #E         ; Set E bit to send instruction
  436.   sta PORTA
  437.   lda #0         ; Clear RS/RW/E bits
  438.   sta PORTA
  439.   rts
  440.  
  441. print_char:
  442.  
  443.   jsr lcd_wait
  444.   sta PORTB
  445.   lda #RS         ; Set RS; Clear RW/E bits
  446.   sta PORTA
  447.   lda #(RS | E)   ; Set E bit to send instruction
  448.   sta PORTA
  449.   lda #RS         ; Clear E bits
  450.   sta PORTA
  451.   rts
  452.  
  453.  
  454.  
  455.  
  456. exit_shoap:
  457.   ldx #$00
  458.   stx inshop
  459.   jmp exit_irq
  460. ;
  461. ;
  462. ;intterupts!
  463. ;
  464. ;
  465.  
  466. decshoppos:
  467.   dec shopselect
  468.   jmp exit_irq
  469.  
  470. exit_shopa:
  471.   ldx #$00
  472.   stx inshop
  473.   jmp exit_irq
  474.  
  475. extra_button: ;PA0 open/close shop
  476.   ldx inshop
  477.   cpx #%00000001
  478.   beq exit_shopa
  479.   inc inshop
  480.   jmp exit_irq
  481.  
  482.  
  483.  
  484. bottom_button: ;PA2 select and buy
  485.   lda counter
  486.   clc
  487.   adc #3
  488.   sta counter
  489.   bcc exit_irq
  490.   inc counter + 1
  491.   jmp exit_irq
  492.  
  493. irq:
  494.   pha
  495.   txa
  496.   pha
  497.   lda PORTA
  498.   and #%00011111
  499.   tax
  500.   cpx #%00010000
  501.   beq top_button
  502.   cpx #%00001000
  503.   beq right_button
  504.   cpx #%00000100
  505.   beq bottom_button
  506.   cpx #%00000010
  507.   beq left_button
  508.   cpx #%00000001
  509.   beq extra_button
  510.  
  511.   jmp exit_irq
  512.  
  513. exit_irq
  514.   pla
  515.   tax
  516.   pla
  517.   bit PORTA
  518.   rti
  519.  
  520. left_button: ;PA1 move select left
  521.   lda shopselect
  522.   and #%00001111
  523.   tax
  524.   cpx #%00000001
  525.   beq exit_irq
  526.   cpx #%00000010
  527.   beq decshoppos
  528.   cpx #%00000011
  529.   beq decshoppos
  530.   cpx #%00000100
  531.   beq decshoppos
  532.   cpx #%00000101
  533.   beq decshoppos
  534.   cpx #%00000110
  535.   beq decshoppos
  536.   cpx #%00000111
  537.   beq decshoppos
  538.   cpx #%00001000
  539.   beq decshoppos
  540.   jmp exit_irq
  541. right_button: ;PA3 move select right
  542.   lda shopselect
  543.   and #%00001111
  544.   tax
  545.   cpx #%00000001
  546.   beq incshoppos
  547.   cpx #%00000010
  548.   beq incshoppos
  549.   cpx #%00000011
  550.   beq incshoppos
  551.   cpx #%00000100
  552.   beq incshoppos
  553.   cpx #%00000101
  554.   beq incshoppos
  555.   cpx #%00000110
  556.   beq incshoppos
  557.   cpx #%00000111
  558.   beq incshoppos
  559.   cpx #%00001000
  560.   beq exit_irq
  561.   jmp exit_irq
  562.  
  563. incshoppos:
  564.   inc shopselect
  565.   jmp exit_irq
  566.  
  567. exit_shop:
  568.   ldx #$00
  569.   stx inshop
  570.   jmp exit_irq
  571.  
  572.  
  573. top_button: ;PA4 clicker
  574.   lda counter
  575.   clc
  576.   adc countby
  577.   sta counter
  578.   bcc exit_irq
  579.   inc counter + 1
  580.   bcc exit_irq
  581.   inc counter + 2
  582.   bcc exit_irq
  583.   inc counter + 3
  584.   jmp exit_irq
  585.  
  586.  
  587.  
  588.  
  589. nmi:
  590.  
  591.  
  592.  
  593.  
  594.   .org $fffa
  595.   .word nmi
  596.   .word reset
  597.   .word irq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement