home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_25_1988_Transactor_Publishing.d64 / baspix < prev    next >
Text File  |  2023-02-26  |  3KB  |  104 lines

  1. ;             BASPIX
  2. ;
  3. ;  This ML subroutine is a very literal translation
  4. ;of the pixel plotting routine found on pages 123-124
  5. ;of the CBM Programmers Reference Guide.
  6. ;Very little optimization has been done.
  7. ;
  8. ; min cycles to execute: about 829
  9. ; max cycles to execute: about 998
  10. ;
  11. ; includes 6 cycles for a JSR to get us here
  12. ;
  13. ;=================================
  14. ;=    register usage on entry    =
  15. ;=================================
  16. ;
  17. ; a = 0 if x<255, 1 if x>255
  18. ; x = 0 - 255
  19. ; y = 0 - 199
  20. ;
  21. pntr = $fb          ;a zero page pointer
  22. ;
  23.        * = $8000
  24. ;
  25. baspix sta pntr+1   ;add in a right away
  26.        txa          ;put x into a
  27.        pha          ;save x for later
  28.        tya          ;save y for later use
  29.        pha          ;push y on stack
  30. ;
  31. ; here, we will calculate the
  32. ;   (8 * (int (x / 8)))
  33. ; note that this is the same as
  34. ;   (x and 248)
  35.        txa          ;now a = x
  36.        and #$f8     ;now a = x and 248
  37.        sta pntr     ;save it
  38. ;
  39. ; now we are going to perform the
  40. ;calculation of
  41. ;     int (y / 8) * 320
  42. ; note we can do this as
  43. ;     (y and 248) * 40
  44. nxtlp2 tya          ;move y into a
  45.        and #$f8     ;mask off lower bits
  46.        tay          ;use this value to add
  47.        ldx #40      ;prepare to add in 40 times
  48. loop1  tya          ;move value to add in 39 times into acc.
  49.        clc          ;ready to add now...
  50.        adc pntr     ;adding in y 40 times is same as y * 40
  51.        sta pntr     ;hold onto the new value!
  52.        bcc nxtlp1   ;if no carry, skip next instruction
  53.        inc pntr+1   ;add 1 to hi byte of pointer
  54. nxtlp1 dex          ;are we done yet?
  55.        bne loop1    ;no! keep going!
  56. ;
  57.        pla          ;get back value of y from stack
  58.        and #$07     ;this gives us y and 7
  59.        clc          ;add this in, as well!
  60.        adc pntr     ;add it
  61.        sta pntr     ;save it
  62.        bcc nxtlp3   ;skip it, if no carry...
  63.        inc pntr+1   ;add 1 to hi byte
  64. ;
  65. ; now we add in the base address of
  66. ;our hi-res screen. we only need the
  67. ;high byte, since it must start on
  68. ;on the beginning of a page
  69. nxtlp3 clc          ;prep for add
  70.        lda #$20     ;screen located at $2000
  71.        adc pntr+1   ;add it in
  72.        sta pntr+1   ;and save it
  73. ;
  74. ; now, pntr and pntr+1 point to
  75. ;the byte we want in screen memory
  76. ;here, we calculate which bit we
  77. ;are going to turn on.
  78.        pla          ;get x from stack
  79.        and #$07     ;gives us x and 7
  80.        sta bitlit   ;save for our subtraction
  81.        lda #$07     ;we'll subtract bit from 7
  82.        sec          ;prep for subtraction
  83.        sbc bitlit   ;gives us a = 7 - (x and 7)
  84.        tay          ;we'll use this value as a counter
  85. ;
  86. ; we now use (x and 7) as a counter
  87. ;for shifting a single bit to the
  88. ;left.
  89.        sec          ;first time thru, carry gets pushed into acc.
  90.        lda #$00     ;start out with 0 in acc.
  91. ;
  92. loop2  rol a        ;shift single bit to left
  93.        dey          ;are we done yet?
  94.        bpl loop2    ;not yet, keep going!
  95. ; finally, we can access our byte
  96. ;and turn our bit on
  97.        ldy #$00     ;make our index = 0
  98.        ora (pntr),y ;turn on our bit
  99.        sta (pntr),y ;and save the change
  100.        rts          ;all done..
  101. ;
  102. bitlit .byte 0      ;a variable
  103.        .end
  104.