Advertisement
Phaze101

C64BC_Printing10_01

May 14th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;============================================================================
  2. ; C64 Bedtime Coding
  3. ; By Phaze 101
  4. ;
  5. ; Article 10 - Example 01
  6. ;============================================================================
  7.  
  8. ; I wish to thank all those that sent me emails or get in touch with me
  9. ; regarding this serious or articles.
  10. ;
  11. ; Also I would like to thank my team for their help in making these articles
  12. ; possible and for their help in translating these articles to Italian.
  13. ;
  14. ; If you find any bugs (I am not not perfect)or issues please get in touch.
  15. ; I will do my best to help out where possible however do allow sometime
  16. ; since I also have a day job to deal with.
  17.  
  18. ;==============================================================================
  19. ; Where to assemble in memory
  20. ;==============================================================================
  21.  
  22. *               =       $c000
  23.  
  24. ;==============================================================================
  25. ; Constants
  26. ;==============================================================================
  27.  
  28. ScrBase         =       $0400
  29.  
  30. ;==============================================================================
  31. ; Main Entry
  32. ;==============================================================================
  33.  
  34. Main
  35.         ldx     #$0
  36.         ldy     #$0
  37.         jsr     SetBgBorder
  38.  
  39.         lda     #$20
  40.         jsr     ClearScreen
  41.  
  42.         jsr     DisplayScreen
  43.  
  44.         jsr     WaitForSpace
  45.  
  46.         lda     #$20
  47.         jsr     ClearScreen
  48.  
  49.         rts
  50.  
  51. ;==============================================================================
  52. ; Set Baground and Border
  53. ;
  54. ; Input
  55. ; X Register - Value for Background
  56. ; Y Register - Valeu for Border
  57. ;==============================================================================
  58.  
  59. SetBgBorder
  60.         stx     $d021
  61.         sty     $d020
  62.         rts
  63.  
  64. ;==============================================================================
  65. ; Clean / Fill Screen
  66. ;
  67. ; Input
  68. ; A register = Fill Value
  69. ;==============================================================================
  70.  
  71. ClearScreen
  72.         ldx     #$00
  73.  
  74. ClrLoop
  75.         sta     ScrBase,x         ; 1024
  76.         sta     ScrBase+250,x     ; 1024 + 250
  77.         sta     ScrBase+500,x     ; 1024 + 500
  78.         sta     ScrBase+750,x     ; 1024 + 750
  79.  
  80.         inx
  81.         cpx     #$fa
  82.         bne     ClrLoop
  83.         rts
  84.  
  85. ;==============================================================================
  86. ; Wait for Space bar to be pressed
  87. ;==============================================================================
  88.  
  89. WaitForSpace
  90.         lda     #$7f    ;%01111111 - only row 7 KB matrix
  91.         sta     $dc00
  92.         lda     $dc01
  93.         and     #$10    ;mask %00010000
  94.         bne     WaitForSpace
  95.  
  96.         rts            
  97.  
  98. ;==============================================================================
  99. ; Set Cursor Position on Screen
  100. ;==============================================================================
  101.  
  102. SetCurs
  103.         cld
  104.  
  105. ;Use an addition to calculate rows
  106.  
  107.         clc
  108. CalcRow                        
  109.         lda     #$28
  110.         adc     Buf2
  111.         sta     Buf2
  112.         lda     #$0
  113.         adc     Buf2+1
  114.         sta     Buf2+1
  115.         dey
  116.         bne     CalcRow
  117.  
  118. ;Add Column
  119.  
  120.         clc
  121. AddColumn
  122.         txa    
  123.         adc     Buf2
  124.         sta     Buf2
  125.         lda     #$0
  126.         adc     Buf2+1
  127.         sta     Buf2+1
  128.  
  129. ;Add poistion to base address
  130.  
  131.         clc
  132. AddScrBase
  133.         lda     Buf1
  134.         adc     Buf2
  135.         sta     Buf3
  136.  
  137.         lda     Buf1+1
  138.         adc     Buf2+1
  139.         sta     Buf3+1
  140.  
  141.         rts
  142.  
  143. Buf1  
  144.         word     ScrBase
  145. Buf2  
  146.         word     $0000          ;Holds offset from Screen Base Address
  147. Buf3  
  148.         word     $0000          ;Holds Screen Address where to write first char
  149.  
  150. ;==============================================================================
  151. ; Print At
  152. ;==============================================================================
  153.  
  154. PrintAt
  155.         sta     $fb             ;source
  156.         sty     $fc
  157.  
  158.         lda     Buf3           ;destination
  159.         sta     $fd
  160.         lda     Buf3+1
  161.         sta     $fe
  162.        
  163.         ldy     #$0
  164.         lda     ($fb),y
  165.  
  166. PrtLoop
  167.         beq     EndPrint
  168.         sta     ($fd),y
  169.         iny
  170.         lda     ($fb),y
  171.         bne     PrtLoop
  172.  
  173. EndPrint
  174.         rts
  175.  
  176. ;==============================================================================
  177. ; Display Screen with Text
  178. ;==============================================================================
  179.  
  180. DisplayScreen
  181.  
  182.         jsr     ClearBuffers
  183.  
  184.         ldy     #$06
  185.         ldx     #$09
  186.         jsr     SetCurs
  187.  
  188.         lda     #<Text1
  189.         ldy     #>Text1
  190.         jsr     PrintAt
  191.  
  192.         jsr     ClearBuffers
  193.  
  194.         ldy     #$08
  195.         ldx     #$0A
  196.         jsr     SetCurs
  197.  
  198.         lda     #<Text2
  199.         ldy     #>Text2
  200.         jsr     PrintAt
  201.  
  202.         jsr     ClearBuffers
  203.  
  204.         ldy     #$0a
  205.         ldx     #$11
  206.         jsr     SetCurs
  207.  
  208.         lda     #<Text3
  209.         ldy     #>Text3
  210.         jsr     PrintAt
  211.  
  212.         jsr     ClearBuffers
  213.  
  214.         ldy     #$0c
  215.         ldx     #$11
  216.         jsr     SetCurs
  217.  
  218.         lda     #<Text4
  219.         ldy     #>Text4
  220.         jsr     PrintAt
  221.  
  222.         jsr     ClearBuffers
  223.  
  224.         ldy     #$0e
  225.         ldx     #$0d
  226.         jsr     SetCurs
  227.  
  228.         lda     #<Text5
  229.         ldy     #>Text5
  230.         jsr     PrintAt
  231.  
  232.         rts
  233.  
  234. ;==============================================================================
  235. ; Clear Memory Buffers
  236. ;==============================================================================
  237.  
  238. ClearBuffers
  239.         ldy     #$4
  240.         lda     #$0
  241. ClrBufLoop
  242.         dey
  243.         sta     Buf2,y
  244.         bne     ClrBufLoop
  245.         rts
  246.  
  247. ;==============================================================================
  248. ; Our Text
  249. ;==============================================================================
  250.  
  251. Text1
  252.         text 'retroprogramming italia',0
  253. Text2
  254.         text 'in collaboration with',0
  255. Text3
  256.         text 'phaze101',0
  257. Text4
  258.         text 'presents',0
  259. Text5
  260.         text 'c64bc example 01',0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement