Advertisement
paul_nicholls

Untitled

Jun 11th, 2019
2,334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .const COLOR_ADDRESS    = $d800
  2.  
  3. // change these zero-page addresses to your specifications :)
  4. .const addressPntr1     = $f0
  5. .const addressPntr2     = $f2
  6. .const addressPntr3     = $f4
  7.  
  8. // change these to your specifications :)
  9. .const SCREEN0_ADDRESS  = 1024
  10. .const TITLE_CHARSET    = $4800
  11.  
  12. .const SCREEN_WIDTH     = 40
  13. .const SCREEN_HEIGHT    = 25
  14.  
  15. .macro drawLargeText(x,y,s) {
  16.   .for (var i = 0; i < s.size(); i++) {
  17.     lda #s.charAt(i)
  18.     ldx #[x+i*8]
  19.     ldy #y
  20.  
  21.     jsr drawBigChar
  22.   }
  23. }
  24.  
  25. .pseudocommand copy8 src : dst {
  26.   lda src
  27.   sta dst
  28. }
  29.  
  30. .macro add16im(value,src,dst) {
  31.     clc
  32.     lda #<value
  33.     adc src + 0
  34.     sta dst + 0
  35.     lda #>value
  36.     adc src + 1
  37.     sta dst + 1
  38. }
  39.  
  40. screen0_row_lo:
  41.   .for (var y = 0; y < SCREEN_HEIGHT; y++) {
  42.     .byte <(SCREEN0_ADDRESS + y * SCREEN_WIDTH)
  43.   }
  44.  
  45. screen0_row_hi:
  46.   .for (var y = 0; y < SCREEN_HEIGHT; y++) {
  47.     .byte >(SCREEN0_ADDRESS + y * SCREEN_WIDTH)
  48.   }
  49.  
  50. color_row_lo:
  51.   .for (var y = 0; y < SCREEN_HEIGHT; y++) {
  52.     .byte <(COLOR_ADDRESS + y * SCREEN_WIDTH)
  53.   }
  54.  
  55. color_row_hi:
  56.   .for (var y = 0; y < SCREEN_HEIGHT; y++) {
  57.     .byte >(COLOR_ADDRESS + y * SCREEN_WIDTH)
  58.   }
  59.  
  60. .namespace c64color {
  61.   .label BLACK       = $0
  62.   .label WHITE       = $1
  63.   .label RED         = $2
  64.   .label CYAN        = $3
  65.   .label PURPLE      = $4
  66.   .label GREEN       = $5
  67.   .label BLUE        = $6
  68.   .label YELLOW      = $7
  69.   .label ORANGE      = $8
  70.   .label BROWN       = $9
  71.   .label LIGHT_RED   = $A //10
  72.   .label DARK_GREY   = $B //11
  73.   .label GREY        = $C //12
  74.   .label LIGHT_GREEN = $D //13
  75.   .label LIGHT_BLUE  = $E //14
  76.   .label LIGHT_GREY  = $F //15
  77. }
  78.  
  79. //----------------------------------------------------------------------------------
  80. //                             drawBigChar
  81. // input: a   = character value to draw (screen code)
  82. // input: x,y = x,y location for character
  83. //----------------------------------------------------------------------------------
  84. drawBigChar: {
  85.   // save char code
  86.   pha
  87.   // setup screen pointer
  88.   :copy8 screen0_row_lo,y : addressPntr2 + 0
  89.   :copy8 screen0_row_hi,y : addressPntr2 + 1
  90.  
  91.   // setup color pointer
  92.   :copy8 color_row_lo,y : addressPntr3 + 0
  93.   :copy8 color_row_hi,y : addressPntr3 + 1
  94.  
  95.   txa
  96.   pha
  97.  
  98.   // add x to pointers
  99.   clc
  100.   adc addressPntr2 + 0
  101.   sta addressPntr2 + 0
  102.  
  103.   pla
  104.   clc
  105.   adc addressPntr3 + 0
  106.   sta addressPntr3 + 0
  107.  
  108.   pla
  109.   // convert a reg to character address in memory
  110.   sta addressPntr1 + 0
  111.   lda #0
  112.   sta addressPntr1 + 1
  113.  
  114.   // x 8
  115.   asl addressPntr1 + 0
  116.   rol addressPntr1 + 1
  117.   asl addressPntr1 + 0
  118.   rol addressPntr1 + 1
  119.   asl addressPntr1 + 0
  120.   rol addressPntr1 + 1
  121.  
  122.   :add16im(TITLE_CHARSET,addressPntr1,addressPntr1)
  123.  
  124.   // copy char data to buffer
  125.   ldy #7
  126. !:
  127.   lda (addressPntr1),y
  128.   sta charData,y
  129.   dey
  130.   bpl !-
  131.  
  132.   ldx #0
  133. copyCharLine:
  134.   // copy char row to screen
  135.   ldy #0
  136. copyCharRow:
  137.   rol charData,x
  138.   bcc noPixel
  139.  
  140.   // pixel char
  141.   lda #32+128
  142.   sta (addressPntr2),y
  143.  
  144.   // pixel color
  145.   lda charColor0,x
  146.   sta (addressPntr3),y
  147.  
  148. noPixel:
  149.   iny
  150.   cpy #8
  151.   bne copyCharRow
  152.   // next line
  153.   :add16im(SCREEN_WIDTH,addressPntr2,addressPntr2)
  154.   :add16im(SCREEN_WIDTH,addressPntr3,addressPntr3)
  155.   inx
  156.   cpx #8
  157.   bne copyCharLine
  158.   rts
  159. charData:
  160.   .byte 0,0,0,0,0,0,0,0
  161. // change these to match your big char row colors!!
  162. charColor0: .byte c64color.WHITE
  163. charColor1: .byte c64color.WHITE
  164. charColor2: .byte c64color.WHITE
  165. charColor3: .byte c64color.YELLOW
  166. charColor4: .byte c64color.YELLOW
  167. charColor5: .byte c64color.ORANGE
  168. charColor6: .byte c64color.LIGHT_RED
  169. charColor7: .byte c64color.LIGHT_RED
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement