Advertisement
verz

C64 bitmap Plot

Apr 9th, 2020
1,442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ________________________________________
  2. ;
  3. ;       Plot function
  4. ;
  5. ;       draws a pixel on bitmap screen
  6. ;
  7. ;
  8. ;       92cycl, without tables
  9. ;_________________________________________
  10.  
  11.  
  12. ; 10 SYS2064
  13.  
  14. *=$0801
  15.         BYTE    $0B, $08, $0A, $00, $9E, $32, $30, $36, $34, $00, $00, $00
  16.  
  17. *=$810
  18.  
  19.         jmp _main
  20.  
  21. _Vic = $d000
  22. _Vmem= $2000
  23. _Cmem= $0400
  24. _V17 byte 0
  25. _V24 byte 0
  26. _Y = $2
  27. _X = $3
  28. wOffs = $fd
  29.  
  30.  
  31. ; ************************************************
  32. ;
  33. ;       Plot
  34. ;
  35. ;       input: _X* (word 0-319**)
  36. ;              _Y* (byte 0-200**)
  37. ;       *_X, _Y are variables in memory, not the registers
  38. ;       **no boundary check
  39. ;
  40. ; offset = BaseAddr + 320*int(Y/8)+(Y and 7) + 8*int(X/8)
  41. ; pixel  = 2^(7-(X and 7))
  42. ;
  43. ; ************************************************
  44. _Plot
  45.         ldy #0          ; 2     ; comput. dY
  46.         sty wOffs       ; 3     ; reset lobyte
  47.         lda _Y          ; 3
  48.         lsr             ; 2
  49.         lsr             ; 2
  50.         lsr             ; 2     ; int(Y/8)
  51.         sta wOffs+1     ; 3     ; 256*int(Y/8) hibyte (lobyte=0)
  52.         lsr             ; 2
  53.         ror wOffs       ; 5
  54.         lsr             ; 2     ; 64*int(Y/8)  hibyte
  55.         ror wOffs       ; 5     ; 64*int(Y/8)  lobyte  (= 320*int(Y/8) lobyte)
  56.         adc wOffs+1     ; 3     ; 256*int(Y/8) + 64*int(Y/8)  hibyte
  57.         sta wOffs+1     ; 3     ; =320*int(Y/8) hibyte
  58.         lda _Y          ; 3     ; add (Y and 7)
  59.         and #7          ; 2
  60.         ora wOffs       ; 3     ; lobyte [xx000xxx]
  61.         sta wOffs       ; 3  48  
  62.  
  63.         lda _X          ; 3     ; dX + dY + BaseAddr
  64.         and #248        ; 2
  65.         adc wOffs       ; 3
  66.         sta wOffs       ; 3
  67.         lda wOffs+1     ; 3
  68.         adc _X+1        ; 3
  69.         adc #>_Vmem     ; 2
  70.         sta wOffs+1     ; 3  22
  71.        
  72.         lda _X          ; 3     ; set pixel-bit
  73.         and #7          ; 2
  74.         tax             ; 2
  75.         lda (wOffs),y   ; 5     ; draws the pixel
  76.         ora ortab,x     ; 4
  77.         sta (wOffs),y   ; 6  22
  78.  
  79.         rts
  80.  
  81. ortab
  82.         byte 128, 64, 32, 16, 8, 4, 2, 1
  83.        
  84.  
  85.  
  86. ; ***************************************************
  87. _main
  88.         ; set bitmap mode and bitmap window
  89.         lda _Vic+17        ;bitmap mode
  90.         sta _V17
  91.         ora #32
  92.         sta _Vic+17
  93.  
  94.         lda _Vic+24        ;videomem => 8192 ($2000)
  95.         sta _V24
  96.         ora #8
  97.         sta _Vic+24
  98.  
  99.  
  100.         ; clear video bitmap
  101.         lda #01  ; black pen, white background
  102.         jsr _ClearCol
  103.         jsr _ClearBmap
  104.  
  105.  
  106.         ; fillscreen loop
  107.         lda #199
  108.         sta _Y
  109. _rep    lda #>319
  110.         sta _X+1
  111.         lda #<319
  112.         sta _X
  113. _toPlot jsr _Plot
  114.         dec _X
  115.         bne _toPlot
  116.         jsr _Plot
  117.         dec _X
  118.         dec _X+1
  119.         bpl _toPlot
  120.         dec _Y
  121.         bne _rep
  122.  
  123.  
  124.         ; restore char video
  125.         jsr WaitForSpace            
  126.         lda _V17
  127.         sta _Vic+17
  128.         lda _V24        
  129.         sta _Vic+24
  130.         lda #32 ;space
  131.         jsr _ClearCol
  132.  
  133.         rts
  134.  
  135. WaitForSpace            ;thanx to Phaze101
  136.         lda     #$7f    ;%01111111 - only row 7 KB matrix
  137.         sta     $dc00
  138.         lda     $dc01
  139.         and     #$10    ;mask %00010000
  140.         bne     WaitForSpace
  141.  
  142.         rts
  143.  
  144.  
  145.  
  146.  
  147. ; ***************************************************
  148. ;       ClearCol
  149. ;
  150. ;  clear screen/color memory
  151. ;
  152. ;       input: .A = fill value
  153. ;
  154. _ClearCol
  155.         ldx #200
  156. _ccl    sta _Cmem-1  ,x
  157.         sta _Cmem+199,x
  158.         sta _Cmem+399,x
  159.         sta _Cmem+599,x
  160.         sta _Cmem+799,x
  161.         dex
  162.         bne _ccl
  163.         rts
  164.  
  165. ; ***************************************************
  166. ;       ClearBmap
  167. ;
  168. ;  clear bitmap screen
  169. ;
  170. align 256
  171.  
  172. _ClearBmap
  173.         ldx #200
  174.         lda #0
  175. _cbl    sta _Vmem-1  ,x
  176.         sta _Vmem+199,x
  177.         sta _Vmem+399,x
  178.         sta _Vmem+599,x
  179.         sta _Vmem+799,x
  180.        
  181.         sta _Vmem+ 999,x
  182.         sta _Vmem+1199,x
  183.         sta _Vmem+1399,x
  184.         sta _Vmem+1599,x
  185.         sta _Vmem+1799,x
  186.  
  187.         sta _Vmem+1999,x
  188.         sta _Vmem+2199,x
  189.         sta _Vmem+2399,x
  190.         sta _Vmem+2599,x
  191.         sta _Vmem+2799,x
  192.  
  193.         sta _Vmem+2999,x
  194.         sta _Vmem+3199,x
  195.         sta _Vmem+3399,x
  196.         sta _Vmem+3599,x
  197.         sta _Vmem+3799,x
  198.  
  199.         sta _Vmem+3999,x
  200.         sta _Vmem+4199,x
  201.         sta _Vmem+4399,x
  202.         sta _Vmem+4599,x
  203.         sta _Vmem+4799,x
  204.  
  205.         sta _Vmem+4999,x
  206.         sta _Vmem+5199,x
  207.         sta _Vmem+5399,x
  208.         sta _Vmem+5599,x
  209.         sta _Vmem+5799,x
  210.  
  211.         sta _Vmem+5999,x
  212.         sta _Vmem+6199,x
  213.         sta _Vmem+6399,x
  214.         sta _Vmem+6599,x
  215.         sta _Vmem+6799,x
  216.  
  217.         sta _Vmem+6999,x
  218.         sta _Vmem+7199,x
  219.         sta _Vmem+7399,x
  220.         sta _Vmem+7599,x
  221.         sta _Vmem+7799,x
  222.  
  223.         dex
  224.         bne _cbl
  225.         rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement