home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / genie-commodore-file-library / C128Graphics / VIEW-BM.ARC / VBMLIB.S < prev   
Encoding:
Text File  |  2019-04-13  |  4.2 KB  |  229 lines

  1. ;*** vbmlib 1.10 package - by Craig Bruce - 13-Nov-93
  2.  
  3. ;vdc register values courtesy of Fred Bowen of Commodore
  4.  
  5. ;vdc memory: 00000-21359=even frame, 21360-42719=odd frame
  6. ;bm file: 0-3=format ('b,'m,$cb,$02), 4-5=widthLH, 6-7=heightLH, 8-end=bmData
  7.  
  8. .org $1300
  9. .obj "@0:vbmlib.bin"
  10.  
  11. vdcStat    = $d600
  12. vdcData    = $d601
  13. evenFrame  = 0
  14. oddFrame   = 21360
  15.  
  16. chkin  = $ffc6
  17. chrin  = $ffcf
  18. clrchn = $ffcc
  19.  
  20.         jmp vbmInit     ;()
  21.         jmp vbmFinish   ;()
  22.         jmp vbmFill     ;( .A=fillValue )
  23.         jmp vbmRead     ;( .A=width8, .X=leftMargin8, ($fa)=dispHeight,
  24.                         ;  ($fc)=topMargin )
  25.  
  26.         .byte $cb,$06,11
  27.  
  28. vdcWrite = *
  29.         stx vdcStat
  30. -       bit vdcStat
  31.         bpl -
  32.         sta vdcData
  33.         rts
  34.  
  35. vdcRead = *
  36.         stx vdcStat
  37. -       bit vdcStat
  38.         bpl -
  39.         lda vdcData
  40.         rts
  41.  
  42. vbmInit = *
  43.         cld
  44.         cli
  45.         ldy #0
  46. -       ldx initRegs,y
  47.         lda initVals,y
  48.         cpx #25
  49.         bne +
  50.         jsr vdcRead
  51.         and #$0f
  52.         ora initVals,y
  53. +       jsr vdcWrite
  54.         iny
  55.         cpy #initVals-initRegs
  56.         bcc -
  57.         lda #$aa
  58.         jmp vbmFill
  59.  
  60. initRegs = *
  61.         .byte 000,001,002,004,005,006,007,008,009,024,025,027,028,020,021
  62.         .byte 012,013,026,012,013
  63. initVals = *            
  64.         .byte $7e,$50,$66,$4c,006,$4c,$47,003,006,000,$80,000,016,166,224
  65.         .byte 000,000,224,0,0    ;last two = >evenFrame,<evenFrame
  66.  
  67. vbmFill = *  ;( .A=fillValue )
  68.         pha
  69.         ldx #18
  70.         lda #>evenFrame
  71.         jsr vdcWrite
  72.         ldx #19
  73.         lda #<evenFrame
  74.         jsr vdcWrite
  75.         ldx #31
  76.         pla
  77.         jsr vdcWrite
  78.         ldy #161
  79. -       ldx #30
  80.         lda #$00
  81.         jsr vdcWrite
  82.         dey
  83.         bne -
  84.         rts
  85.  
  86. vbmFinish = *
  87.         jsr $e179
  88.         jsr $ff62
  89.         lda #147
  90.         jsr $ffd2
  91.         rts
  92.  
  93. height    = $fa ;(2)
  94. topMargin = $fc ;(2)
  95. lmargin   = $fe ;(1)
  96. rmargin   = $ff ;(1)
  97. dispwidth .buf 1
  98. baseaddr  = $fc ;(2)
  99. evenodd   .buf 1
  100. width     .buf 1
  101.  
  102. vbmRead = *  ;( .A=width8, .X=leftMargin8, ($fa)=height, ($fc)=topMargin )
  103.         ;** adjust width
  104.         sta width
  105.         stx lmargin
  106.         sec
  107.         sbc lmargin
  108.         cmp #80
  109.         bcs +
  110.         sta dispwidth
  111.         lda #0
  112.         sta rmargin
  113.         jmp adjustHeight
  114. +       sbc #80
  115.         sta rmargin
  116.         lda #80
  117.         sta dispwidth
  118.  
  119.         ;** adjust height
  120.         adjustHeight = *
  121.         sec
  122.         lda height+0
  123.         sbc topMargin+0
  124.         sta height+0
  125.         lda height+1
  126.         sbc topMargin+1
  127.         sta height+1
  128.         lda height+0
  129.         cmp #<492
  130.         lda height+1
  131.         sbc #>492
  132.         bcc setInput
  133.         lda #<492
  134.         ldy #>492
  135.         sta height+0
  136.         sty height+1
  137.  
  138.         ;** set input
  139.         setInput = *
  140.         ldx #1
  141.         jsr chkin
  142.         bcc +
  143.         rts
  144. +       nop
  145.  
  146.         ;** skip top margin
  147. -       lda topMargin+0
  148.         ora topMargin+1
  149.         beq ++
  150.         ldy width
  151. -       jsr chrin
  152.         dey
  153.         bne -
  154.         lda topMargin+0
  155.         bne +
  156.         dec topMargin+1
  157. +       dec topMargin+0
  158.         jmp --
  159. +       nop
  160.  
  161.         ;** read the lines
  162.         lda #0
  163.         sta baseaddr+0
  164.         sta baseaddr+1
  165.         sta evenodd
  166. -       lda height+0
  167.         ora height+1
  168.         bne +
  169.         jsr clrchn
  170.         rts
  171. +       jsr displayLine
  172.         lda evenodd
  173.         and #$01
  174.         beq +
  175.         clc
  176.         lda baseaddr+0
  177.         adc #80
  178.         sta baseaddr+0
  179.         bcc +
  180.         inc baseaddr+1
  181. +       inc evenodd
  182.         lda height+0
  183.         bne +
  184.         dec height+1
  185. +       dec height+0
  186.         jmp -
  187.  
  188. displayLine = *
  189.         ;** set line address
  190.         lda evenodd
  191.         and #$01
  192.         bne +
  193.         lda baseaddr+0
  194.         pha
  195.         lda baseaddr+1
  196.         jmp ++
  197. +       clc
  198.         lda baseaddr+0
  199.         adc #<oddFrame
  200.         pha
  201.         lda baseaddr+1
  202.         adc #>oddFrame
  203. +       ldx #18
  204.         jsr vdcWrite
  205.         ldx #19
  206.         pla
  207.         jsr vdcWrite
  208.  
  209.         ;** poke line
  210.         ldy lmargin
  211.         beq +
  212. -       jsr chrin
  213.         dey
  214.         bne -
  215. +       ldy dispwidth
  216.         beq +
  217. -       jsr chrin
  218.         eor #$ff
  219.         ldx #31
  220.         jsr vdcWrite
  221.         dey
  222.         bne -
  223. +       ldy rmargin
  224.         beq +
  225. -       jsr chrin
  226.         dey
  227.         bne -
  228. +       rts
  229.