Advertisement
verz

SuBloku.asm

Dec 8th, 2019
1,192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; 10 SYS2064
  2.  
  3. *=$0801
  4.         BYTE    $0B, $08, $0A, $00, $9E, $32, $30, $36, $34, $00, $00, $00
  5. *=2064
  6.         jmp Main
  7.  
  8. scrline byte 0,0,0,0,0,0,0,0,0,0
  9. linnum  byte 0
  10. mystring byte 0,0,0,0,0,0,0,0
  11.  
  12. ScrnBase = $0400
  13. ScrnCol  = $d800
  14. _pnt1 = $3
  15. _pnt2 = $5
  16. _pnt3 = $b7
  17. _pnt4 = $b9
  18. _pnt5 = $bb
  19.  
  20. _Snot  = $8000
  21. _Snot1 = _Snot + $100
  22. _Snot2 = _Snot + $200
  23. _Snot3 = _Snot + $300
  24. _Snot4 = _Snot + $400
  25. _Snot5 = _Snot + $500
  26. _Snot6 = _Snot + $600
  27. _Snot7 = _Snot + $700
  28. _Snot8 = _Snot + $800
  29. _Snot9 = _Snot + $900
  30. _Sblk  = _Snot + $A00
  31. _Smat  = _Snot + $B00
  32. _Sgblk = _Snot + $C00
  33. _SXY   = _Snot + $80
  34.  
  35. fmod    =$60
  36. _rnVal  =$2
  37. _rnDsp  byte 0
  38. _rnY    =$61
  39. _rnX    =$62
  40. _strcell byte 0, 0
  41. _fsaN   =$a3
  42. _fsaF   =$a4
  43. _fsaC   =$a5
  44. _frcF   =$a6
  45. _fsY    =$a7
  46. _rnEF   =$a8
  47.  
  48. sIndic byte '-->',0
  49. sClear byte '   ',0
  50. kSel   byte 0
  51. kSelp  byte 0
  52. kDown   = 17
  53. kUp     = 145
  54. kRet    = 13
  55.  
  56. _mnu1 byte  6,6,'1. subloku facile',0
  57. _mnu2 byte  7,6,'2. subloku medio',0
  58. _mnu3 byte  8,6,'3. subloku difficile 1',0
  59. _mnu4 byte  9,6,'4. subloku difficile 2',0
  60. _mnu5 byte 10,6,'5. sudoku facile',0
  61. _mnu6 byte 11,6,'6. sudoku difficile',0
  62. _mnu7 byte 12,6,'7. esci',0
  63.  
  64. StrTable
  65.         byte <_mnu1, >_mnu1
  66.         byte <_mnu2, >_mnu2
  67.         byte <_mnu3, >_mnu3
  68.         byte <_mnu4, >_mnu4
  69.         byte <_mnu5, >_mnu5
  70.         byte <_mnu6, >_mnu6
  71.         byte <_mnu7, >_mnu7
  72.  
  73. _tim byte 0,0,0
  74. _tem  byte "tempo: ",0
  75. _sec  byte " sec",0
  76.  
  77.  
  78. ; ------------------------------------------------------
  79. Main
  80.         ldy #>_SXY      ; calcolo della matrice delle coordinate XY
  81.         sty _pnt1+1     ; utile in alcune elaborazioni
  82.         iny
  83.         sty _pnt2+1
  84.         lda #<_SXY
  85.         sta _pnt1
  86.         sta _pnt2
  87.         ldy #0
  88.         ldx #1
  89.         txa
  90. _plp    sta _rnY
  91.         sta (_pnt2),y
  92.         txa
  93.         sta (_pnt1),y
  94.         lda _rnY
  95.         iny
  96.         inx
  97.         cpx #10
  98.         bne _plp
  99.         ldx #1
  100.         clc
  101.         adc #1
  102.         cmp #10
  103.         bne _plp
  104.  
  105.         lda #1
  106.         sta kSel
  107.         sta kSelp
  108. Main2
  109.         lda #32
  110.         ldy #8
  111.  
  112.         jsr ClearScreen
  113.         jsr WriteMenu
  114.  
  115. _RK     clc             ; legge un tasto
  116.         lda kSelp
  117.         adc #5
  118.         tay
  119.         ldx #3
  120.         jsr SetCurs
  121.         lda #<sClear
  122.         ldx #>sClear
  123.         jsr PrintAt
  124.  
  125.         clc             ; disegna la freccia di indicazione
  126.         lda kSel
  127.         adc #5
  128.         tay
  129.         ldx #3
  130.         jsr SetCurs
  131.         lda #<sIndic
  132.         ldx #>sIndic
  133.         jsr PrintAt
  134.  
  135. _read   jsr $F142
  136.         beq _read
  137.         tax
  138.         CLC
  139.         ADC #$c8  ; make m = $FF
  140.         ADC #7    ; carry set if in range n to m
  141.         bcs KeyNum
  142.         cpx #kDown
  143.         beq KeyDwn
  144.         cpx #kUp
  145.         beq KeyUp
  146.         cpx #kRet       ; la scelta è <Return>
  147.         bne _RK
  148.         jmp Prep
  149. KeyNum                  ; la scelta è un numero
  150.         lda kSel
  151.         sta kSelp
  152.         txa
  153.         sec
  154.         sbc #"0"
  155.         sta kSel
  156.         jmp _RK
  157. KeyDwn  lda kSel        ; la scelta è CrsrDown
  158.         sta kSelp
  159.         cmp #7
  160.         beq _RK
  161.         inc kSel
  162.         bne _RK
  163. KeyUp   lda kSel        ; la scelta è CrsrUp
  164.         sta kSelp
  165.         cmp #1
  166.         beq _RK
  167.         dec kSel
  168.         bne _RK
  169.  
  170. ; ------------------------------------------------------
  171. ; scrive il menù
  172. ; ------------------------------------------------------
  173. WriteMenu
  174.         lda #0
  175.         sta 53281
  176.         lda #12
  177.         tax
  178. _wmlp  
  179.         pha
  180.         lda strtable,x
  181.         sta _pnt1
  182.         pha
  183.         lda strtable+1,x
  184.         sta _pnt1+1
  185.         pha
  186.         ldy #1
  187.         lda (_pnt1),y
  188.         tax
  189.         dey
  190.         lda (_pnt1),y
  191.         tay
  192.         jsr SetCurs
  193.        
  194.         pla
  195.         tax
  196.         pla
  197.         ldy #2
  198.         jsr PrintAt+2
  199.         pla
  200.         tax
  201.         dex
  202.         dex
  203.         txa
  204.         bpl _wmlp
  205.         rts
  206.  
  207. ; ------------------------------------------------------
  208. ; prepara la schermata di gioco, in base alla selezione
  209. ; ------------------------------------------------------
  210. Prep
  211.         lda #32
  212.         jsr ClearScreen
  213.         lda kSel
  214.         cmp #7
  215.         bne _pchk1
  216.         lda #6
  217.         sta 53281
  218.         rts
  219. _pchk1  cmp #1
  220.         bne _pchk2
  221.                 lda #<_1num
  222.                 sta _pnt4
  223.                 lda #>_1num
  224.                 sta _pnt4+1
  225.                 lda #<_1blk
  226.                 sta _pnt5
  227.                 lda #>_1blk
  228.                 sta _pnt5+1
  229.                 jmp _pnxt
  230. _pchk2  cmp #2
  231.         bne _pchk3
  232.                 lda #<_2num
  233.                 sta _pnt4
  234.                 lda #>_2num
  235.                 sta _pnt4+1
  236.                 lda #<_2blk
  237.                 sta _pnt5
  238.                 lda #>_2blk
  239.                 sta _pnt5+1
  240.                 jmp _pnxt
  241. _pchk3  cmp #3
  242.         bne _pchk4
  243.                 lda #<_3num
  244.                 sta _pnt4
  245.                 lda #>_3num
  246.                 sta _pnt4+1
  247.                 lda #<_3blk
  248.                 sta _pnt5
  249.                 lda #>_3blk
  250.                 sta _pnt5+1
  251.                 jmp _pnxt
  252. _pchk4  cmp #4
  253.         bne _pchk5
  254.                 lda #<_4num
  255.                 sta _pnt4
  256.                 lda #>_4num
  257.                 sta _pnt4+1
  258.                 lda #<_3blk
  259.                 sta _pnt5
  260.                 lda #>_3blk
  261.                 sta _pnt5+1
  262.                 jmp _pnxt
  263. _pchk5  cmp #5
  264.         bne _pchk6
  265.                 lda #<_5num
  266.                 sta _pnt4
  267.                 lda #>_5num
  268.                 sta _pnt4+1
  269.                 lda #<_5blk
  270.                 sta _pnt5
  271.                 lda #>_5blk
  272.                 sta _pnt5+1
  273.                 jmp _pnxt
  274. _pchk6  cmp #6
  275.                 lda #<_6num
  276.                 sta _pnt4
  277.                 lda #>_6num
  278.                 sta _pnt4+1
  279.                 lda #<_5blk
  280.                 sta _pnt5
  281.                 lda #>_5blk
  282.                 sta _pnt5+1
  283. _pnxt
  284.         lda #9
  285.         sta linnum
  286.  
  287.         jsr ResetBoard
  288.         jsr GetTime
  289.         jsr ReduceNotes
  290.  
  291. _lpcop  clc             ; prepara una linea dello Schema per disegnarla a video
  292.         ldy #8
  293. _lplin  lda (_pnt4),y
  294.         beq _revon
  295.         adc #$10        ; aggiunge $30 per un numero, $20 per spazio
  296. _revon  adc #$20
  297.         ora #$80        ; attiva reverse
  298.         sta scrline,y
  299.         dey
  300.         bpl _lplin
  301.  
  302.         ldx #5          ; disegna i numeri
  303.         lda #5
  304.         adc #8
  305.         sbc linnum
  306.         tay
  307.         jsr SetCurs
  308.         lda _pnt2
  309.         sta _pnt3
  310.         lda #$d4
  311.         adc _pnt2+1
  312.         sta _pnt3+1
  313.         lda #<scrline
  314.         ldx #>scrline
  315.         jsr PrintAt
  316.        
  317.         ldy #9          ; disegna (assegna) i colori
  318. _lpcol  lda (_pnt5),y
  319.         sta (_pnt3),y
  320.         dey
  321.         bpl _lpcol
  322.  
  323.         lda #9
  324.         adc _pnt4
  325.         sta _pnt4
  326.         lda #0
  327.         adc _pnt4+1
  328.         sta _pnt4+1
  329.         lda #9
  330.         adc _pnt5
  331.         sta _pnt5
  332.         lda #0
  333.         adc _pnt5+1
  334.         sta _pnt5+1
  335.  
  336.         dec linnum
  337.         bne _lpcop
  338.  
  339.         jsr MainLoop
  340.  
  341. _read1  jsr $F142       ; attende <Return>
  342.         beq _read1
  343.         cmp #13
  344.         bne _read1
  345.         jmp Main2
  346.  
  347.  
  348. ; ------------------------------------------------------
  349. MainLoop
  350.         jsr RecalcNotes
  351.         lda #0
  352.         sta fmod
  353.         jsr FindSingleInCell
  354.         lda _rnEF
  355.         beq _endmainloop
  356.         lda fmod
  357.         bne MainLoop
  358.         jsr FindSingleInArea
  359.         lda _rnEF
  360.         beq _endmainloop
  361.         lda fmod
  362.         bne MainLoop
  363.         jsr FindRowColToBlock
  364.         lda fmod
  365.         bne MainLoop
  366.  
  367. _endmainloop
  368.         sei             ; time
  369.         sec
  370.         lda $a2
  371.         sbc _tim+2
  372.         sta _tim+2
  373.         lda $a1
  374.         sbc _tim+1
  375.         sta _tim+1
  376.         lda $a0
  377.         sbc _tim
  378.         sta _tim
  379.         cli
  380.         jsr PrintTime
  381.         rts
  382.  
  383.  
  384. ; ------------------------------------------------------
  385. ; cerca una cella che abbia un solo candidato
  386. ; ------------------------------------------------------
  387. FindSingleInCell
  388.         ldy #81-1       ; scorre tutta la matrice
  389.         lda #>_Snot
  390.         sta _pnt1+1
  391.         sta _pnt2+1
  392.         ldx #0
  393.         stx _pnt1
  394.         stx _pnt2
  395.        
  396. _fsslp2 lda (_pnt1),y
  397.         cmp #1
  398.         beq _fsslp4
  399. _fsslp3 dey
  400.         bpl _fsslp2
  401.         rts
  402.  
  403. _fsslp4 sta fmod
  404. _fsslp5 inx
  405.         inc _pnt2+1
  406.         lda (_pnt2),y
  407.         beq _fsslp5
  408.         txa
  409.         sta _rnVal
  410.         sta _Smat,y
  411.         jsr DisplayCell
  412.         jsr SetCellAndNotes
  413.         jmp RecalcNotes
  414.  
  415.  
  416. ; ------------------------------------------------------
  417. ; cerca riga/colonna/blocco che abbia il candidato per
  418. ; un valore in una sola cella
  419. ; ------------------------------------------------------
  420. FindSingleInArea
  421. ; FindSingleInRow
  422. ; cerca per riga
  423.         lda #9
  424.         sta _fsaN
  425.        
  426. _fsalp1 ldx #0
  427.         ldy #0
  428.         stx _pnt1
  429.         lda #>_Snot
  430.         clc
  431.         adc _fsaN
  432.         sta _pnt1+1
  433. _fsalp7         lda #2
  434.                 sta _fsaF
  435.                 jmp _fsalp3
  436. _fsalp2                 iny
  437.                         cpy #81
  438.                         bcs _fsalp6
  439.                         inx
  440.                         cpx #9
  441.                         bne _fsalp3 ; end loop
  442.                         lda _fsaF
  443.                         cmp #1
  444.                         bne _fsalp4
  445.                         ;found!
  446.                         jmp Found
  447.  
  448. _fsalp3                 lda (_pnt1),y
  449.                         beq _fsalp2
  450.                         sty _fsY
  451.                         dec _fsaF
  452.                         bne _fsalp2        
  453. _fsalp4 ;not found
  454.                 sty _fsY
  455.                 txa
  456.                 sec
  457.                 sbc #9
  458.                 eor #$ff
  459.                 sec
  460.                 adc _fsY
  461.                 tay
  462.                 ldx #0        
  463.                 jmp _fsalp7
  464. _fsalp6 dec _fsaN
  465.         bne _fsalp1
  466.         ;jmp FindSingleInCol
  467.  
  468. ; FindSingleInCol
  469. ; cerca per colonna
  470.         lda #9          ; cerca la tabella di un certo valore
  471.         sta _fsaN
  472.        
  473. _fsclp1 ldy #8
  474.         sty _fsaC       ; loop varie note
  475.         lda _fsaN       ; punta alla tabella
  476.         clc             ; .
  477.         adc #>_Snot1-1  ; .
  478.         sta _pnt1+1     ; .
  479.         lda #0          ; .
  480.         sta _pnt1       ; .
  481. _fsclp2         lda #2          ; loop colonne per ogni nota
  482.                 sta _fsaF       ; non più di un elemento da trovare
  483.                 ldx #9          ; 9 elementi da controllare
  484.                 ldy _fsaC
  485.                         jmp _fsclp5
  486. _fsclp3                 dex     ; loop di controllo colonna
  487.                         bne _fsclp4
  488.                         lda _fsaF
  489.                         cmp #1
  490.                         bne _fsclp6
  491.                         ;found!
  492.                         jmp Found
  493. _fsclp4                 tya
  494.                         clc
  495.                         adc #9
  496.                         tay
  497. _fsclp5                 lda (_pnt1),y
  498.                         beq _fsclp3
  499.                         sty _fsY
  500.                         dec _fsaF
  501.                         bne _fsclp3
  502. _fsclp6         dec _fsaC
  503.                 bne _fsclp2
  504.         dec _fsaN
  505.         bne _fsclp1
  506.  
  507. ; FindSingleInBlock
  508. ; cerca nei blocchi
  509.         lda #0
  510.         sta _pnt1
  511.         lda #$90
  512. _fsblp3 sta _fsbdst+1              ; ciclo sui valori
  513.         lda #9
  514.         sta _fsaN
  515. _fsblp5         lda _fsaN
  516.                 clc
  517.                 adc #>_Snot1-1
  518.                 sta _pnt1+1
  519.                 lda #2
  520.                 sta _fsaF
  521.                 ldx #9
  522.                         jmp _fsbdst
  523. _fsblp1                 dex
  524.                         bne _fsbdst
  525.                         lda _fsaF
  526.                         cmp #1
  527.                         bne _fsblp6
  528.                         ;found!
  529.                         jmp Found
  530. _fsbdst                 lda _Sgblk,x
  531.                         tay
  532.                         lda (_pnt1),y
  533.                         beq _fsblp1
  534.                         sty _fsY
  535.                         dec _fsaF
  536.                         bne _fsblp1
  537. _fsblp6         dec _fsaN
  538.                 bne _fsblp5
  539. _fsblp4 lda _fsbdst+1
  540.         sec
  541.         sbc #$10
  542.         bne _fsblp3
  543.         rts
  544.  
  545.  
  546.  
  547. ; ------------------------------------------------------
  548. Found
  549.         sta fmod
  550.         ldy _fsY
  551.         lda _fsaN
  552.         sta _rnVal
  553.         sta _Smat,y
  554.         jsr DisplayCell
  555.         jsr SetCellAndNotes
  556.         jmp RecalcNotes
  557.  
  558.        
  559.  
  560. ; ------------------------------------------------------
  561. ; cerca blocchi in cui le note siano tutte in una riga/colonna
  562. ; ------------------------------------------------------
  563. FindRowColToBlock
  564.         lda #0
  565.         sta _pnt1
  566.         lda #$90
  567. _frclp3 sta _frcdst+1              ; ciclo sui gruppi
  568.         lda #9
  569.         sta _fsaN
  570. _frclp5         lda _fsaN          ; ciclo sui valori
  571.                 clc
  572.                 adc #>_Snot1-1
  573.                 sta _pnt1+1
  574.                 ldx #$ff
  575.                 stx _rnX
  576.                 stx _rnY
  577.                 lda #0
  578.                 sta _frcF
  579.                 ldx #9
  580.                         jmp _frcdst
  581. _frclp1                 dex
  582.                         beq _frclp2
  583. _frcdst                 lda _Sgblk,x
  584.                         tay
  585.                         lda (_pnt1),y
  586.                         beq _frclp1
  587.                         lda _frcF
  588.                         bne _nxtctrl
  589.                         inc _frcF
  590.                         lda _SXY,y
  591.                         sta _rnX
  592.                         lda _SXY+$100,y
  593.                         sta _rnY
  594.                         jmp _frclp1
  595. _nxtctrl                lda _SXY,y    
  596.                         cmp _rnX
  597.                         beq _checkY
  598.                         lda #$ff
  599.                         sta _rnX
  600.                         cmp _rnY
  601.                         beq _frclp6
  602. _checkY                 lda _SXY+$100,y
  603.                         cmp _rnY
  604.                         beq _frclp1
  605.                         lda #$ff
  606.                         sta _rnY
  607.                         cmp _rnX
  608.                         bne _frclp1
  609.  
  610. _frclp6         dec _fsaN
  611.                 bne _frclp5
  612. _frclp4 lda _frcdst+1
  613.         sec
  614.         sbc #$10
  615.         bne _frclp3
  616.         rts
  617. _frclp2                 lda _rnX
  618.                         bmi _frcY
  619.                         ldx #9
  620.                         tay            ; Xpos -> .Y
  621.                         dey
  622.                         lda _frcdst+1
  623.                         lsr
  624.                         lsr
  625.                         lsr
  626.                         lsr
  627.                         sta _pnt4+1
  628. _frclp7                 lda _pnt4+1
  629.                         cmp _Sblk,y
  630.                         beq _nxtrc1
  631.                         lda #0
  632.                         sta (_pnt1),y
  633. _nxtrc1                 tya
  634.                         clc
  635.                         adc #9
  636.                         tay
  637.                         dex
  638.                         bne _frclp7
  639.                         lda #1
  640.                         sta fmod
  641.                         jmp _frclp6
  642.  
  643. _frcY                   ldx _rnY
  644.                         bmi _frclp6
  645.                         clc            ; Ypos -> .Y
  646.                         lda #0
  647.                         jmp _el
  648. _il                     adc #9
  649. _el                     dex
  650.                         bne _il
  651.                         ldx #9
  652.                         tay
  653.                         lda _frcdst+1
  654.                         lsr
  655.                         lsr
  656.                         lsr
  657.                         lsr
  658.                         sta _pnt4+1
  659. _frclp8                 lda _pnt4+1
  660.                         cmp _Sblk,y
  661.                         beq _nxtrc2
  662.                         lda #0
  663.                         sta (_pnt1),y
  664. _nxtrc2                 iny
  665.                         dex
  666.                         bne _frclp8
  667.                         lda #1
  668.                         sta fmod
  669.                         jmp _frclp6
  670.  
  671.  
  672. ; ------------------------------------------------------
  673. ; ripristina le matrici allo stato iniziale;
  674. ; carica lo schema scelto
  675. ; ------------------------------------------------------
  676. ResetBoard
  677.         lda #>_Sgblk
  678.         sta _pnt3+1
  679.         lda #0
  680.         sta _pnt3
  681.         ldy #9
  682. _rblp1  sta (_pnt3),y
  683.         dey
  684.         bne _rblp1
  685.  
  686.         ldy #81-1
  687.  
  688. _rblp2  lda (_pnt4),y   ; carica lo schema
  689.         sta _Smat,y
  690.         lda (_pnt5),y   ; carica la struttura
  691.         sta _Sblk,y
  692.  
  693.         tax             ; crea tabella array dei blocchi
  694.         asl
  695.         asl
  696.         asl
  697.         asl
  698.         sta _rbdst1+1   ; codice automodificante
  699.         inc _Sgblk,x
  700.         lda _Sgblk,x
  701.         tax
  702.         tya
  703. _rbdst1 sta _Sgblk,x    ; destinazione automodificata
  704.  
  705.         lda #1          ; azzera i candidati delle celle
  706.         sta _Snot1,y
  707.         sta _Snot2,y
  708.         sta _Snot3,y
  709.         sta _Snot4,y
  710.         sta _Snot5,y
  711.         sta _Snot6,y
  712.         sta _Snot7,y
  713.         sta _Snot8,y
  714.         sta _Snot9,y
  715.         dey
  716.         bpl _rblp2
  717.         rts
  718.  
  719.  
  720. ; ------------------------------------------------------
  721. ; cerca le celle valorizzate per annullare le note
  722. ; corrispondenti
  723. ; ------------------------------------------------------
  724. ReduceNotes
  725.         ldy #81-1
  726. _rnlp   lda _Smat,y
  727.         beq _rnend
  728.  
  729.         jsr SetCellAndNotes
  730.  
  731.         ldy _rnY
  732. _rnend  dey
  733.         bpl _rnlp
  734. ; ------------------------------------------------------
  735. RecalcNotes
  736.         ;calcola le note per casella
  737.         lda #0
  738.         sta _rnEF
  739.         ldy #81-1
  740. _rnslp1 lda #>_Snot1
  741.         sta _pnt1+1
  742.         lda #9
  743.         sta _pnt2
  744.         ldx #0
  745.         stx _pnt1
  746.        
  747. _rnslp2 lda (_pnt1),y
  748.         beq _rnslp3
  749.         inx
  750.         stx _rnEF
  751. _rnslp3 inc _pnt1+1
  752.         dec _pnt2
  753.         bne _rnslp2
  754.         txa    
  755.         sta _Snot,y
  756.        
  757.         dey
  758.         bpl _rnslp1
  759.         rts
  760.  
  761.  
  762. ; ------------------------------------------------------
  763. ; data una cella valorizzata, annulla le note per quella
  764. ; cella e le note di quel valore per le celle degli
  765. ; stessi riga/colonna/blocco
  766. ; ------------------------------------------------------
  767. ; richiede A=valore, Y=posizione
  768. ; ------------------------------------------------------
  769. SetCellAndNotes
  770.         sta _rnVal
  771.         sty _rnY
  772.  
  773.         ;azzera note per quella cella
  774.         ldx #9
  775.         lda #>_Snot1
  776.         sta _pnt1+1
  777.         lda #0
  778.         sta _pnt1
  779. _rnzlop sta (_pnt1),y
  780.         inc _pnt1+1
  781.         dex
  782.         bne _rnzlop
  783.  
  784.         ;azzera note di quel valore per quella colonna
  785.         clc
  786.         lda #>_Snot1-1
  787.         adc _rnVal
  788.         sta _pnt2+1
  789.         lda #0
  790.         sta _pnt2
  791.  
  792.         lda _SXY,y
  793.         sec
  794.         sbc #1
  795.         sta _rnX
  796.        
  797.         tay             ;azzera le note della stessa colonna
  798.         ldx #9
  799.         clc
  800. _rnclp0 lda #0
  801.         sta (_pnt2),y
  802.         tya
  803.         adc #9
  804.         tay
  805.         dex
  806.         bne _rnclp0
  807.  
  808.         lda _rnY        ;azzera le note della stessa riga
  809.         sec
  810.         sbc _rnX
  811.         tay
  812.         ldx #9
  813.         lda #0
  814. _rnclp1 sta (_pnt2),y
  815.         iny
  816.         dex
  817.         bne _rnclp1
  818.  
  819. _rncblk
  820.         clc             ;azzera le note per quel blocco
  821.         lda _rnVal
  822.         adc #>_Snot1-1
  823.         sta _pnt1+1
  824.         lda #0
  825.         sta _pnt1
  826.         ldy _rnY
  827.         lda _Sblk,y
  828.         ldy #81-1
  829.        
  830. _rnblp1 cmp _Sblk,y
  831.         bne _rnblp2
  832.         lda #0
  833.         sta (_pnt1),y
  834.         lda _Sblk,y
  835. _rnblp2 dey
  836.         bpl _rnblp1
  837.  
  838.         rts
  839.  
  840.  
  841. ; ------------------------------------------------------
  842. DisplayCell
  843.         ora #$80+$30
  844.         sta _strcell
  845.  
  846.         tya
  847.         sty _rnY
  848.         ldy #$2
  849. _dclp   iny
  850.         sec
  851.         sbc #9
  852.         bpl _dclp
  853.         adc #14
  854.         tax
  855.         jsr SetCurs
  856.         lda #<_strcell
  857.         ldx #>_strcell
  858.         jsr PrintAt
  859.         ldy _rnY
  860.         lda _rnVal
  861.         rts
  862.  
  863.  
  864. ; ------------------------------------------------------
  865. GetTime
  866.         lda $a0
  867.         sta _tim
  868.         lda $a1
  869.         sta _tim+1
  870.         lda $a2
  871.         sta _tim+2
  872.         rts
  873.  
  874. ; ------------------------------------------------------
  875. PrintTime
  876.         clc
  877.         ldx #15
  878.         ldy #10
  879.         jsr $E50A       ; Set Pos:  c 10, r 15
  880.         lda #<_tem
  881.         ldy #>_tem
  882.         jsr $ab1e
  883.  
  884.         lda _tim+2
  885.         ldx _tim+1
  886.         ldy _tim+0
  887.         jsr $af87  ; sets mantissa to 00yyxxaa
  888.         jsr $af7e  ; set rest of FAC1 and JMP to $b8d2
  889.  
  890.         jsr Fac2Arg
  891.         lda #0
  892.         ldy #+60
  893.         jsr $b391       ; convert Y/A (lo/hi) to Fac1
  894.         jsr $bb12       ; FDIVT division   ARG/FAC
  895.         jsr Fac2Arg
  896.         lda #0
  897.         ldy #100
  898.         jsr $b391       ; convert Y/A (lo/hi) to Fac1
  899.         jsr $ba30       ; Fac=Arg*Fac
  900.         jsr $bddd       ; convert Fac1 to string
  901.  
  902.         sta _pnt1
  903.         sty _pnt1+1
  904.         ldy #0
  905. _ptlp   lda (_pnt1),y
  906.         sta mystring,y
  907.         iny
  908.         cmp #0
  909.         beq _ptel
  910.         cmp #'.'
  911.         bne _ptlp
  912.         lda #0
  913. _ptel   sta mystring,y
  914.         lda mystring-2,y
  915.         sta mystring-1,y
  916.         lda mystring-3,y
  917.         sta mystring-2,y
  918.         lda #'.'
  919.         sta mystring-3,y
  920.         lda #<mystring
  921.         ldy #>mystring
  922.         jsr $ab1e       ; print string pointed by Y/A
  923.         lda #<_sec
  924.         ldy #>_sec
  925.         jsr $ab1e
  926.         rts
  927.  
  928. Fac2Arg
  929.         ldx #6
  930. _l5     lda $61,x       ; FAC -> ARG
  931.         sta $69,x
  932.         dex
  933.         bpl _l5
  934.         rts
  935.  
  936. _1num
  937.         byte 9, 2, 1, 5, 6, 0, 0, 0, 0
  938.         byte 0, 0, 0, 0, 0, 9, 6, 0, 2
  939.         byte 0, 6, 0, 0, 0, 0, 0, 2, 4
  940.         byte 0, 1, 0, 0, 4, 0, 0, 0, 9
  941.         byte 0, 0, 5, 8, 0, 1, 2, 0, 0
  942.         byte 3, 0, 0, 0, 7, 0, 0, 9, 0
  943.         byte 1, 9, 0, 0, 0, 0, 0, 4, 0
  944.         byte 2, 0, 9, 6, 0, 0, 0, 0, 0
  945.         byte 0, 0, 0, 0, 2, 3, 9, 8, 6
  946. _1blk
  947.         byte 1, 1, 1, 1, 1, 2, 2, 2, 2
  948.         byte 1, 1, 1, 3, 3, 2, 2, 4, 2
  949.         byte 1, 3, 3, 3, 2, 2, 4, 4, 4
  950.         byte 5, 3, 3, 3, 3, 6, 6, 4, 4
  951.         byte 5, 5, 6, 6, 6, 6, 6, 4, 4
  952.         byte 5, 5, 6, 6, 7, 7, 7, 7, 4
  953.         byte 5, 5, 5, 8, 8, 7, 7, 7, 9
  954.         byte 8, 5, 8, 8, 7, 7, 9, 9, 9
  955.         byte 8, 8, 8, 8, 9, 9, 9, 9, 9
  956. _2num
  957.         byte 0, 0, 0, 0, 2, 0, 7, 3, 0
  958.         byte 1, 0, 0, 0, 0, 9, 5, 0, 0
  959.         byte 2, 4, 0, 0, 1, 0, 0, 0, 0
  960.         byte 0, 6, 0, 4, 0, 2, 0, 0, 0
  961.         byte 9, 0, 1, 0, 0, 0, 3, 0, 2
  962.         byte 0, 0, 0, 6, 0, 5, 0, 4, 0
  963.         byte 0, 0, 0, 0, 5, 0, 0, 7, 3
  964.         byte 0, 0, 8, 3, 0, 0, 0, 0, 5
  965.         byte 0, 1, 7, 0, 3, 0, 0, 0, 0
  966. _2blk
  967.         byte 1, 1, 1, 2, 2, 2, 2, 2, 2
  968.         byte 3, 3, 1, 1, 1, 1, 4, 2, 2
  969.         byte 3, 3, 3, 1, 1, 5, 4, 2, 4
  970.         byte 3, 3, 3, 5, 5, 5, 4, 4, 4
  971.         byte 6, 3, 6, 6, 5, 4, 4, 7, 4
  972.         byte 6, 6, 6, 5, 5, 5, 7, 7, 7
  973.         byte 6, 8, 6, 5, 9, 9, 7, 7, 7
  974.         byte 8, 8, 6, 9, 9, 9, 9, 7, 7
  975.         byte 8, 8, 8, 8, 8, 8, 9, 9, 9
  976. _3num
  977.         byte 0, 0, 0, 2, 0, 1, 7, 0, 0
  978.         byte 0, 1, 4, 0, 0, 0, 0, 0, 0
  979.         byte 0, 7, 0, 0, 4, 0, 0, 0, 1
  980.         byte 3, 0, 0, 0, 2, 0, 0, 0, 6
  981.         byte 0, 0, 8, 1, 0, 3, 5, 0, 0
  982.         byte 8, 0, 0, 0, 9, 0, 0, 0, 3
  983.         byte 1, 0, 0, 0, 3, 0, 0, 7, 0
  984.         byte 0, 0, 0, 0, 0, 0, 9, 4, 0
  985.         byte 0, 0, 1, 9, 0, 7, 0, 0, 0
  986. _3blk
  987.         byte 1, 1, 1, 2, 2, 2, 2, 2, 2
  988.         byte 1, 1, 1, 2, 3, 3, 3, 3, 2
  989.         byte 1, 1, 1, 2, 3, 3, 4, 3, 3
  990.         byte 5, 5, 5, 6, 6, 4, 4, 3, 4
  991.         byte 5, 7, 7, 6, 6, 6, 4, 4, 4
  992.         byte 5, 7, 7, 8, 6, 6, 6, 9, 4
  993.         byte 5, 7, 8, 8, 8, 6, 9, 9, 4
  994.         byte 5, 7, 7, 7, 8, 9, 9, 9, 9
  995.         byte 5, 5, 7, 8, 8, 8, 8, 9, 9
  996. _4num
  997.         byte 0, 0, 0, 2, 0, 1, 7, 0, 0
  998.         byte 0, 0, 4, 0, 0, 0, 0, 0, 0
  999.         byte 0, 7, 0, 0, 4, 0, 0, 0, 1
  1000.         byte 3, 0, 0, 0, 2, 0, 0, 0, 6
  1001.         byte 0, 0, 8, 0, 0, 0, 5, 0, 0
  1002.         byte 8, 0, 0, 0, 9, 0, 0, 0, 3
  1003.         byte 1, 0, 0, 0, 3, 0, 0, 7, 0
  1004.         byte 0, 0, 0, 0, 0, 0, 0, 4, 0
  1005.         byte 0, 0, 1, 9, 0, 7, 0, 0, 0
  1006. _4blk
  1007. _5num
  1008.         byte 0, 0, 7, 0, 0, 3, 9, 0, 2
  1009.         byte 0, 0, 0, 8, 0, 0, 0, 0, 0
  1010.         byte 9, 4, 3, 0, 0, 0, 0, 0, 7
  1011.         byte 6, 9, 0, 0, 0, 0, 0, 0, 0
  1012.         byte 3, 0, 0, 5, 2, 7, 0, 0, 0
  1013.         byte 0, 0, 0, 0, 0, 0, 8, 4, 0
  1014.         byte 0, 0, 0, 0, 4, 8, 0, 0, 0
  1015.         byte 2, 6, 0, 0, 0, 0, 0, 0, 0
  1016.         byte 0, 0, 0, 0, 0, 0, 1, 2, 9
  1017. _5blk
  1018.         byte 1, 1, 1, 2, 2, 2, 3, 3, 3
  1019.         byte 1, 1, 1, 2, 2, 2, 3, 3, 3
  1020.         byte 1, 1, 1, 2, 2, 2, 3, 3, 3
  1021.         byte 4, 4, 4, 5, 5, 5, 6, 6, 6
  1022.         byte 4, 4, 4, 5, 5, 5, 6, 6, 6
  1023.         byte 4, 4, 4, 5, 5, 5, 6, 6, 6
  1024.         byte 7, 7, 7, 8, 8, 8, 9, 9, 9
  1025.         byte 7, 7, 7, 8, 8, 8, 9, 9, 9
  1026.         byte 7, 7, 7, 8, 8, 8, 9, 9, 9
  1027. _6num
  1028.         byte 0, 2, 0, 0, 0, 0, 0, 8, 6
  1029.         byte 8, 0, 7, 0, 0, 5, 0, 0, 0
  1030.         byte 0, 0, 3, 0, 4, 0, 0, 0, 2
  1031.         byte 0, 5, 0, 7, 9, 0, 0, 0, 0
  1032.         byte 0, 0, 1, 0, 5, 0, 2, 0, 0
  1033.         byte 0, 0, 0, 0, 2, 6, 0, 7, 0
  1034.         byte 5, 0, 0, 0, 3, 0, 1, 4, 0
  1035.         byte 0, 0, 0, 4, 0, 0, 0, 0, 5
  1036.         byte 9, 1, 0, 0, 0, 0, 0, 2, 0
  1037. _6blk
  1038.  
  1039.  
  1040.  
  1041. ;--------------------------------------
  1042. ; Call with
  1043. ; .X = value of horizontal pos
  1044. ; .Y = value of vertical pos
  1045. ;
  1046. ; thanx to Phaze101
  1047. ;--------------------------------------
  1048.  
  1049. SetCurs
  1050.         lda #0
  1051.         sta _pnt1
  1052.         sta _pnt1+1
  1053.         cpy #0                 ;first line: no need to add rows
  1054.         beq AddColumn-1
  1055.  
  1056.         ;clc
  1057. CalcRow                        ;Use an addition to calculate rows
  1058.         tya             ;2                max(Y)=25
  1059.         asl             ;2   A= Y x 2
  1060.         asl             ;2   A= Y x 4
  1061.         sty _pnt1     ;3      
  1062.         adc _pnt1     ;3   A= Y x 5
  1063.         asl             ;2   A= Y x 10 (still contained in one byte)
  1064.         asl             ;2   A= Y x 20 (now needs two bytes)
  1065.         rol _pnt1+1     ;5    flows on high byte
  1066.         asl             ;2   A= Y x 40
  1067.         rol _pnt1+1     ;5    flows on high byte
  1068.         sta _pnt1       ;3   stores on low byte
  1069.  
  1070.         clc
  1071. AddColumn
  1072.         txa    
  1073.         adc     _pnt1
  1074.         sta     _pnt1
  1075.         bcc AddScrBase
  1076.         inc     _pnt1+1
  1077.  
  1078.         clc                     ;Add position to base address
  1079. AddScrBase
  1080.         ;lda     _pnt1
  1081.         adc     #<ScrnBase
  1082.         sta     _pnt2
  1083.         lda     #>ScrnBase
  1084.         adc     _pnt1+1
  1085.         sta     _pnt2+1
  1086.  
  1087.         rts
  1088.  
  1089.  
  1090. ;--------------------------------------
  1091. ; PrintAt, ChainPrint
  1092. ; Call with
  1093. ; .A = low  byte of the string
  1094. ; .X = high byte of the string
  1095. ;
  1096. ; thanx to Phaze101
  1097. ;--------------------------------------
  1098.  
  1099. PrintAt
  1100.         ldy #$0
  1101.         sta _pnt1
  1102.         stx _pnt1+1
  1103.         jmp _ln
  1104. _PrtLoop
  1105.         sta (_pnt2),y          
  1106.         iny
  1107. _ln     lda (_pnt1),y
  1108.         bne _PrtLoop
  1109.  
  1110.         rts
  1111.  
  1112. ChainPrint
  1113.         sta _pnt1
  1114.         stx _pnt1+1
  1115.         tya
  1116.         ldy #0
  1117.         clc
  1118.         adc _pnt2
  1119.         sta _pnt2
  1120.         bcc _ln
  1121.         inc _pnt2+1
  1122.         bcs _ln
  1123.  
  1124. ;--------------------------------------
  1125. ; Call with
  1126. ; .A = value of the character to use to fill the screen
  1127. ;
  1128. ; thanx to Phaze101
  1129. ;--------------------------------------
  1130.  
  1131. ClearScreen    ldx #+200 ; init index
  1132.                sta $2
  1133. ClrLoop        lda $2
  1134.                sta ScrnBase-1,x ; 1023
  1135.                sta ScrnBase+199,x ; 1023 + 200
  1136.                sta ScrnBase+399,x ; 1023 + 400
  1137.                sta ScrnBase+599,x ; 1023 + 600
  1138.                sta ScrnBase+799,x ; 1023 + 800
  1139.                 tya
  1140.                 sta ScrnCol-1,x
  1141.                 sta ScrnCol+199,x
  1142.                 sta ScrnCol+399,x
  1143.                 sta ScrnCol+599,x
  1144.                 sta ScrnCol+799,x
  1145.                dex
  1146.                bne ClrLoop
  1147.                rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement