c64-livecoding/wip-hugo/routines/memory/pixel_draw.s

95 lines
1.9 KiB
ArmAsm
Executable file

;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
;;Screen print. Draws a pixel at a specified position.
;; Destroys A X Y
.proc pixel_draw; Draws a pixel at [Y = FB , X = FC, FD]. Y = 0 - 320, X= 0 - 200
Y_pos = $FB
X_pos = $FCFD
byte_to_paint = $FE
btp_mem_pos =$494A; byte to paint memory position
C = $7071
B =$7273
;; X = X_pos (mod 8)
LDA >X_pos ; X (mod 8)
AND #%00000111
TAX
;;Store pixel in byte_to_paint
LDA #%10000000
INX
@shift_btp: ;; check out SMB instruction here! //Hugo
DEX
BEQ end__;X=0 end this
CLC
ROR A
jmp @shift_btp
end__:
STA byte_to_paint
;;FIND THE POSITION IN MEMORY TO WRITE PIXEL
;; + + + + + > X
;; +
;; +
;;\/
;; Y
;;
;;pos = x_offset
LDA #%11111000
AND >X_pos
STA >btp_mem_pos
LDA <X_pos
STA <btp_mem_pos
;;The y_pos adds offset because chunk offsets + inside chunk offset.
;; Adding inside chunk offset
LDA #%00000111 ; A = y (mod 8)
AND Y_pos ;; offset to add
;;ading offset, same as psudocode bellow
;;Add_16 >btp_mem_pos, <btp_mem_pos, A, #$00
CLC ; Y = b_low
ADC >btp_mem_pos
STA >btp_mem_pos
LDA #$00
ADC <btp_mem_pos ; C =0
STA <btp_mem_pos
LDA #$00
STA $4B
;;y =8 translates to 320 bytes.
LDA #%11111000 ; A = y - [y (mod 8)]
AND Y_pos
STA >C
STA >B
LDA #$00
STA <C
STA <B
;;We need to calculate C*40. 40 = 2*2*2*(2^2 +1)
;; _*2^2
mult_16 >C, <C, !
mult_16 >C, <C, !
;; + _*1
Add_16 >C, <C, >B, <B, !
;; *2*2*2
mult_16 >C, <C, !
mult_16 >C, <C, !
mult_16 >C, <C, !
Add_16 >btp_mem_pos, <btp_mem_pos, >C, <C, !
;;add offset for where bitmap is
Add_16 >btp_mem_pos, <btp_mem_pos, #<Bitmap, #>Bitmap, !
;;Let draw some stuff
LDX #$00
LDA byte_to_paint ;; note that both bytes are used!
ORA (>btp_mem_pos, X)
STA (>btp_mem_pos, X)
RTS
.endproc