Advertisement
Phaze101

C64BC_Printing10_02

May 15th, 2019
229
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 02
  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. ColMem          =       $d800
  30.  
  31. TempMem         =       $02
  32.  
  33. ;==============================================================================
  34. ; Main Entry
  35. ;==============================================================================
  36.  
  37. Main
  38.         ldx     #$05
  39.         ldy     #$0d
  40.         jsr     SetBgBorder
  41.  
  42.         lda     #$20            ;Fill value
  43.         ldy     #$00            ;Colour Value
  44.         jsr     ScrFill
  45.  
  46.         jsr     DisplayScreen
  47.  
  48.         jsr     WaitForSpace
  49.  
  50.         ldx     #$06
  51.         ldy     #$0e
  52.         jsr     SetBgBorder
  53.  
  54.         lda     #$20            ;Fill value
  55.         ldy     #$0e            ;Colour Value
  56.         jsr     ScrFill
  57.  
  58.         rts
  59.  
  60. ;==============================================================================
  61. ; Set Baground and Border
  62. ;
  63. ; Input
  64. ; X Register - Value for Background
  65. ; Y Register - Valeu for Border
  66. ;==============================================================================
  67.  
  68. SetBgBorder
  69.         stx     $d021
  70.         sty     $d020
  71.         rts
  72.  
  73. ;==============================================================================
  74. ; Screen Fill
  75. ; Set the screen text to a colour
  76. ;
  77. ; Input
  78. ; A register = Fill Value
  79. ; Y register = Colour Value
  80. ;==============================================================================
  81.  
  82. ScrFill
  83.         sta     $fb     ;Fill Character
  84.         ldx     #$00
  85.  
  86. ScrLoop
  87.         lda     $fb
  88.         sta     ScrBase,x         ; Screen 1024
  89.         sta     ScrBase+250,x     ; Screen 1024 + 250
  90.         sta     ScrBase+500,x     ; Screen 1024 + 500
  91.         sta     ScrBase+750,x     ; Screen 1024 + 750
  92.  
  93.         tya                       ; Colour Value is in Y register
  94.         sta     ColMem,x          ; Colour Mem 55296
  95.         sta     ColMem+250,x      ; Colour Mem 55296 + 250
  96.         sta     ColMem+500,x      ; Colour Mem 55296 + 500
  97.         sta     ColMem+750,x      ; Colour Mem 55296 + 750
  98.  
  99.         inx
  100.         cpx     #$fa
  101.         bne     ScrLoop
  102.  
  103.         rts
  104.  
  105. ;==============================================================================
  106. ; Wait for Space bar to be pressed
  107. ;==============================================================================
  108.  
  109. WaitForSpace
  110.         lda     #$7f    ;%01111111 - only row 7 KB matrix
  111.         sta     $dc00
  112.         lda     $dc01
  113.         and     #$10    ;mask %00010000
  114.         bne     WaitForSpace
  115.  
  116.         rts            
  117.  
  118. ;==============================================================================
  119. ; Set Cursor Position on Screen
  120. ;
  121. ; Input
  122. ; X register - number of Colums
  123. ; Y register - number of rows
  124. ;==============================================================================
  125.  
  126. SetCurs
  127.         cld
  128.  
  129.         cpy     #$0
  130.         beq     AddColumn
  131.  
  132. ;Use an addition to calculate rows
  133. CalcRow                        
  134.         clc
  135.         lda     #$28
  136.         adc     Buf2
  137.         sta     Buf2
  138.         lda     #$0
  139.         adc     Buf2+1
  140.         sta     Buf2+1
  141.         dey
  142.         bne     CalcRow
  143.  
  144. ;Add Column
  145. AddColumn
  146.         cpx     #$0
  147.         beq     AddScrBase
  148.      
  149.         clc
  150.         txa    
  151.         adc     Buf2
  152.         sta     Buf2
  153.         lda     #$0
  154.         adc     Buf2+1
  155.         sta     Buf2+1
  156.  
  157. ;Add position to base address
  158. AddScrBase
  159.         clc
  160.         lda     Buf1
  161.         adc     Buf2
  162.         sta     Buf3
  163.  
  164.         lda     Buf1+1
  165.         adc     Buf2+1
  166.         sta     Buf3+1
  167.  
  168.         rts
  169.  
  170. Buf1  
  171.         word     ScrBase
  172. Buf2  
  173.         word     $0000          ;Holds offset from Screen Base Address
  174. Buf3  
  175.         word     $0000          ;Holds Screen Address where to write first char
  176.  
  177. ;==============================================================================
  178. ; Print At - No colour
  179. ; 1. Handles number Strings in one Pass
  180. ; 2. Read X and Y values from first 2 bytes before each string
  181. ;
  182. ; Source Address of string stored at $fb & $fc
  183. ; Destination Address to Screem Memory sored at $fd & $fe
  184. ;==============================================================================
  185.  
  186. PrintAt
  187.  
  188. ;Init Part
  189.         sta     $fb             ;source - Pointing to first byte X value
  190.         sty     $fc
  191.  
  192.         lda     NoStrs          ;load the number of strings we have
  193.         sta     TempMem         ;store it in out temp location
  194.  
  195. ;Set Postion on Display
  196. SetPos
  197.         jsr     ClearBuffers    ;make sure buffers are clear
  198.  
  199.         ldy     #$0
  200.         lda     ($fb),y         ;Get No of Columns
  201.         tax
  202.         iny
  203.         lda     ($fb),y         ;Get No of Row
  204.         tay
  205.         jsr     SetCurs
  206.  
  207. ;Set Source to the String that will be Printed - skip 2 Bytes
  208.         clc
  209.         lda     #$02    
  210.         adc     $fb
  211.         sta     $fb
  212.         lda     #$0
  213.         adc     $fc
  214.         sta     $fc
  215.  
  216. ;Set Destination on the Screen
  217.         lda     Buf3            ;destination
  218.         sta     $fd
  219.         lda     Buf3+1
  220.         sta     $fe
  221.        
  222. ;Read String and Display it
  223.         ldy     #$0
  224.         lda     ($fb),y         ;check if string is empty
  225. PrtLoop
  226.         beq     PrintNextString
  227.         sta     ($fd),y
  228.         iny
  229.         lda     ($fb),y
  230.         bne     PrtLoop
  231.  
  232. ;Are there more strings to print?
  233. PrintNextString
  234.         dec     TempMem         ;we could have used DEC NoStrs but in doing so
  235.                                 ;the next time we run the program NoStrs will
  236.                                 ;be a zero and we will not know how many
  237.                                 ;strings there are to read
  238.  
  239. ;        cmp     NoStrs       ;this is not needed but for clarity is commented
  240.  
  241.         beq     PrintExit
  242.  
  243. ;If there is then Point to the next String
  244.         iny
  245.  
  246. ;AddrNextString
  247.         clc
  248.         tya    
  249.         adc     $fb
  250.         sta     $fb
  251.         lda     #$0
  252.         adc     $fc
  253.         sta     $fc
  254.         jmp     SetPos
  255.  
  256. PrintExit
  257.         rts
  258.  
  259. ;==============================================================================
  260. ; Display Screen with Text
  261. ;==============================================================================
  262.  
  263. DisplayScreen
  264.  
  265.         lda     #<Strings
  266.         ldy     #>Strings
  267.         jsr     PrintAt
  268.  
  269.  
  270.         rts
  271.  
  272. ;==============================================================================
  273. ; Clear Memory Buffers
  274. ;==============================================================================
  275.  
  276. ClearBuffers
  277.         ldy     #$4
  278.         lda     #$0
  279. ClrBufLoop
  280.         dey
  281.         sta     Buf2,y
  282.         bne     ClrBufLoop
  283.         rts
  284.  
  285. ;==============================================================================
  286. ; Our Text
  287. ;
  288. ; First byte is number of strings to Read
  289. ; First 2 bytes of each string are the X and Y position on the screen
  290. ; Each String ternimantes with a value of 0
  291. ;==============================================================================
  292.  
  293. NoStrs
  294.         byte    $06    
  295.  
  296. Strings
  297.         byte    $01,$01                                 ;X,Y Position
  298.         text    'retroprogramming italia',0
  299.         byte    $04,$05    
  300.         text    'in collaboration with',0
  301.         byte    $07,$09    
  302.         text    'phaze101',0
  303.         byte    $0a,$0d    
  304.         text    'presents',0
  305.         byte    $0d,$11    
  306.         text    'c64 bedtime coding',0
  307.         byte    $10,$15  
  308.         text    'article 10 - example 02',0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement