Add bouncing sprite. First experiment.

This commit is contained in:
giomba 2022-11-03 20:51:18 +01:00
parent aed259522b
commit 51fdaab28d
5 changed files with 87 additions and 43 deletions

View File

@ -1,7 +1,7 @@
#pragma once
#define VERTICAL_OFFSET 30
#define HORIZONTAL_OFFSET 192
#define HORIZONTAL_OFFSET 168
#define LINE_BUFFER_SIZE 160
#define BLACK 0x00

49
main.S
View File

@ -36,29 +36,14 @@ main_asm:
1:
rjmp 1b
.global int_horizontal_sync
int_horizontal_sync: ; +3
push r31 ; +5
in r31, IO(SREG) ; +6, status register
push r31 ; +8
push r30 ; +10
.global int_horizontal_sync_s
int_horizontal_sync_s:
push r31
; if (0 <= line < 256), then enter
lds r30, line ; +12
lds r31, line + 1 ; +14
adiw z, 1 ; +16
sts line, r30 ; +18
sts line + 1, r31 ; +20
cpi r31, 0 ; +21
breq enter ; +23
jmp int_horizontal_sync_end
enter:
; here, +23 cycles have passed since horizontal sync
; so, there are still ~168 cycles before first useful data
; load timer to trigger isr at the beginning of the visible scanline
ldi r31, 0
sts TCNT0, r31
ldi r31, HORIZONTAL_OFFSET ; set counter TOP
lds r31, hpos ; set counter TOP
sts OCR0A, r31
ldi r31, 0x7 ; clear any pending interrupt
@ -68,12 +53,8 @@ enter:
ori r31, 0x02 ; mask enable interrupt timer A
sts TIMSK0, r31
int_horizontal_sync_end:
pop r30
pop r31
out IO(SREG), r31
pop r31
reti
ret
.global int_timer_0
int_timer_0:
@ -83,6 +64,7 @@ int_timer_0:
push r31
push r30
push r29
push r25
; turn off interrupt
lds r31, TIMSK0
@ -96,11 +78,11 @@ int_timer_0:
lds zl, current_jump_table
lds zh, current_jump_table + 1
; ldi zl, pm_lo8(line_jump_table_0)
; ldi zh, pm_hi8(line_jump_table_0)
clr r0
lds r29, line
lds r25, vpos
sub r29, r25
add zl, r29
adc zh, r0
add zl, r29
@ -110,6 +92,7 @@ int_timer_0:
.global jump_table_return_address
jump_table_return_address:
pop r25
pop r29
pop r30
pop r31
@ -117,8 +100,8 @@ jump_table_return_address:
pop r31
reti
.global int_vertical_sync
int_vertical_sync:
.global int_vertical_sync_s
int_vertical_sync_s:
push r31
in r31, IO(SREG)
push zl
@ -126,12 +109,6 @@ int_vertical_sync:
push yl
push yh
lds r31, frame + 1
lds r30, frame
adiw z, 1
sts frame + 1, r31
sts frame, r30
ldi r30, 1
ldi r31, 0
sts line, r30

39
main.c
View File

@ -18,14 +18,41 @@ volatile uint16_t frame = 0;
volatile uint16_t line = 0xfe;
volatile uint8_t image = 0xff;
ISR(INT0_vect, ISR_NAKED) {
// vertical sync interrupt
asm("jmp int_vertical_sync");
// horizontal and vertical position of bouncing logo
volatile uint8_t vpos = 0;
volatile uint8_t hpos = 0;
volatile int8_t vinc = +1;
volatile int8_t hinc = +1;
void int_vertical_sync_s(void);
ISR(INT0_vect) {
frame += 1;
vpos += vinc;
hpos += hinc;
if (vpos == 0)
vinc = +1;
if (vpos == 256 - 64)
vinc = -1;
if (hpos == HORIZONTAL_OFFSET)
hinc = +1;
if (hpos == 255 - 40)
hinc = -1;
int_vertical_sync_s();
}
ISR(INT1_vect, ISR_NAKED) {
// horizontal sync interrupt
asm("jmp int_horizontal_sync");
void int_horizontal_sync_s(void);
ISR(INT1_vect) {
line += 1;
// if (line >= 256)
if (line >= vpos + 64)
return;
if (line >= vpos)
int_horizontal_sync_s();
}
ISR(TIMER0_COMPA_vect, ISR_NAKED) {
// back porch timer interrupt
asm("jmp int_timer_0");

40
samples/bouncing-logo.pbm Normal file
View File

@ -0,0 +1,40 @@
P1
# Created by GIMP version 2.10.32 PNM plug-in
40 64
1110011101110111000110000011111111111111100101000010010010100100000000
0000000001100101000010010010100100000000000000000111100110001001110010
0100000000000000000110010100001001001010010000000000000000011001010000
1001001010010000000000000000011001010000100100101001000000000000000001
1001011100100100100110000000000000000001000000000000000000000000000000
0000000001000000000000000000000000000000000000000100000000000000000000
0000000000000000000100000000000000000000000000000000000000010000000000
0000000000000000000000000000010000000000000000000000000000000000000001
0000000000000000000000000000000000000001000000000000000000000000000000
0000000001100000000000000000000000000000000000000110000000000000000000
0000000000000000000110000000000000000000000000000000000000011000000000
0000000000000000000000000000011000000000000000000000000000000000000001
1000000000000000000000000000000000000001100000000000000000000000000000
0000000001100000000000000000000000000000000000000110000000000000000000
0000000000000000000110000000000000000000000000000000000000001000000000
0000000000000000000000000000001000000000000000000000000000000000000000
1000000000000000000000000000000000000000100000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000010000000000000000000000000000000000000001000000000
0000000000000000000000000000001000000000000000000000000000000000000000
1000000000000000000000000000000000000001100000000000000000000000000000
0000000001100000000000000000000000000000000000000110000000000000000000
0000000000000000000110000000000000000000000000000000000000011000000000
0000000000000000000000000000011000000000000000000000000000000000000001
1111110000000000000000000000000000011111

BIN
samples/bouncing-logo.xcf Normal file

Binary file not shown.