Skip to content

Instantly share code, notes, and snippets.

@BalorPrice
Created October 3, 2018 20:38
Show Gist options
  • Save BalorPrice/067fa7c704cb1068ba05e33f6fb6d251 to your computer and use it in GitHub Desktop.
Save BalorPrice/067fa7c704cb1068ba05e33f6fb6d251 to your computer and use it in GitHub Desktop.
; Example of rotation in Mode 4 for the SAM Coupé
inc_d: equ &14
inc_e: equ &1c
dec_d: equ &15
dec_e: equ &1d
;----------------------------------------------
gfx.print_rotatedHLDEBCA:
; Print bitmap rotated.
; A = rotation value, 0=0 degrees, 1=90 degrees clockwise, 2=180 degrees, 3=270 degrees
; B = Depth
; C = Width in pixels
; (E,D) = coordinates to print to screen - hotspot is top-left, rotation turns graphic around this value
; HL = source data
@test_rotation:
cp 3
call z,@+set_270
cp 2
call z,@+set_180
cp 1
call z,@+set_90
or a
call z,@+set_0
@print_rot:
@reset_flip_flop: ; Reset the collect_pixel internal flip_flip bit
ld a,1
ld (@+flip + 1),a
@y_loop:
push bc
push de
@x_loop:
push bc
call @+collect_pixelHL
or a
call nz,@+plotDEA
@x_upd: inc e
pop bc
dec c
jr nz,@-x_loop
pop de
@y_upd: inc d
pop bc
djnz @-y_loop
ret
;----------------------------------------------
@set_0:
; Print door for top of screen ie right-way-up
push af
ld a,inc_e ; Set inner loop to move to the right
ld (@-x_upd),a
ld a,inc_d ; Set outer loop to move down
ld (@-y_upd),a
pop af
ret
;----------------------------------------------
@set_90:
; Print door for right of screen, rotated clockwise 90 degrees.
push af
ld a,inc_d ; Now rotated, inner loop (source x) moves down
ld (@-x_upd),a
ld a,dec_e ; outer loop moves left
ld (@-y_upd),a
pop af
ret
;----------------------------------------------
@set_180:
push af
ld a,dec_e
ld (@-x_upd),a
ld a,dec_d
ld (@-y_upd),a
pop af
ret
;----------------------------------------------
@set_270:
push af
ld a,dec_d
ld (@-x_upd),a
ld a,inc_e
ld (@-y_upd),a
pop af
ret
;----------------------------------------------
@collect_pixelHL:
; Collect next pixel from source
@flip: ld a,1 ; Flip-flop entry widget: swaps between left- and right-nibbles each time
xor 1
ld (@-flip + 1),a
ld a,(hl)
jr z,@+collect_right_nibble
@collect_left_nibble:
and &0f
inc hl ; If right nibble, also move source onto new byte
ret
@collect_right_nibble:
for 4,rra
and &0f
ret
;----------------------------------------------
@plotDEA:
; Plot (E,D) with colour A in bottom nibble
push de
srl d
rr e
jr nc,@+left
@right:
ld c,a
ld a,(de)
and &f0
or c
ld (de),a
pop de
ret
@left:
for 4,add a
ld c,a
ld a,(de)
and &0f
or c
ld (de),a
pop de
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment