home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_25_1988_Transactor_Publishing.d64
/
baspix
< prev
next >
Wrap
Text File
|
2023-02-26
|
3KB
|
104 lines
; BASPIX
;
; This ML subroutine is a very literal translation
;of the pixel plotting routine found on pages 123-124
;of the CBM Programmers Reference Guide.
;Very little optimization has been done.
;
; min cycles to execute: about 829
; max cycles to execute: about 998
;
; includes 6 cycles for a JSR to get us here
;
;=================================
;= register usage on entry =
;=================================
;
; a = 0 if x<255, 1 if x>255
; x = 0 - 255
; y = 0 - 199
;
pntr = $fb ;a zero page pointer
;
* = $8000
;
baspix sta pntr+1 ;add in a right away
txa ;put x into a
pha ;save x for later
tya ;save y for later use
pha ;push y on stack
;
; here, we will calculate the
; (8 * (int (x / 8)))
; note that this is the same as
; (x and 248)
txa ;now a = x
and #$f8 ;now a = x and 248
sta pntr ;save it
;
; now we are going to perform the
;calculation of
; int (y / 8) * 320
; note we can do this as
; (y and 248) * 40
nxtlp2 tya ;move y into a
and #$f8 ;mask off lower bits
tay ;use this value to add
ldx #40 ;prepare to add in 40 times
loop1 tya ;move value to add in 39 times into acc.
clc ;ready to add now...
adc pntr ;adding in y 40 times is same as y * 40
sta pntr ;hold onto the new value!
bcc nxtlp1 ;if no carry, skip next instruction
inc pntr+1 ;add 1 to hi byte of pointer
nxtlp1 dex ;are we done yet?
bne loop1 ;no! keep going!
;
pla ;get back value of y from stack
and #$07 ;this gives us y and 7
clc ;add this in, as well!
adc pntr ;add it
sta pntr ;save it
bcc nxtlp3 ;skip it, if no carry...
inc pntr+1 ;add 1 to hi byte
;
; now we add in the base address of
;our hi-res screen. we only need the
;high byte, since it must start on
;on the beginning of a page
nxtlp3 clc ;prep for add
lda #$20 ;screen located at $2000
adc pntr+1 ;add it in
sta pntr+1 ;and save it
;
; now, pntr and pntr+1 point to
;the byte we want in screen memory
;here, we calculate which bit we
;are going to turn on.
pla ;get x from stack
and #$07 ;gives us x and 7
sta bitlit ;save for our subtraction
lda #$07 ;we'll subtract bit from 7
sec ;prep for subtraction
sbc bitlit ;gives us a = 7 - (x and 7)
tay ;we'll use this value as a counter
;
; we now use (x and 7) as a counter
;for shifting a single bit to the
;left.
sec ;first time thru, carry gets pushed into acc.
lda #$00 ;start out with 0 in acc.
;
loop2 rol a ;shift single bit to left
dey ;are we done yet?
bpl loop2 ;not yet, keep going!
; finally, we can access our byte
;and turn our bit on
ldy #$00 ;make our index = 0
ora (pntr),y ;turn on our bit
sta (pntr),y ;and save the change
rts ;all done..
;
bitlit .byte 0 ;a variable
.end