Code finalization for bouncing sprite.
This commit is contained in:
parent
b76ec5e498
commit
a5b5fb17c6
17
const.h
17
const.h
@ -1,8 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define VERTICAL_OFFSET 30
|
#define FRAME_PIXEL_WIDTH 1024 // [system clock]
|
||||||
#define HORIZONTAL_OFFSET 168
|
#define FRAME_PIXEL_HEIGHT 256 // [line]
|
||||||
#define LINE_BUFFER_SIZE 160
|
|
||||||
|
|
||||||
#define BLACK 0x00
|
#define BACK_PORCH_OFFSET 100 // [system clock]
|
||||||
#define WHITE 0xff
|
#define FRONT_PORCH_OFFSET 40 // [system clock]
|
||||||
|
|
||||||
|
#define SPRITE_WIDTH 80 // [system clock]
|
||||||
|
#define SPRITE_HEIGHT 64 // [line]
|
||||||
|
|
||||||
|
// Time spent from the horizontal sync pulse,
|
||||||
|
// to the first displayed dot.
|
||||||
|
// This is given as HSYNC_INT_TUNE + HSYNC_TIMER_TUNE + C part
|
||||||
|
#define HSYNC_TUNE 70
|
87
main.S
87
main.S
@ -38,67 +38,76 @@ main_asm:
|
|||||||
|
|
||||||
.global int_horizontal_sync_s
|
.global int_horizontal_sync_s
|
||||||
int_horizontal_sync_s:
|
int_horizontal_sync_s:
|
||||||
push r31
|
push r31 ; +2
|
||||||
push r30
|
push r30 ; +2
|
||||||
|
|
||||||
; load timer to trigger isr at the beginning of the visible scanline
|
; load timer to trigger isr at the beginning of the visible scanline
|
||||||
; reset counter to 0
|
; reset counter to 0
|
||||||
ldi r31, 0
|
ldi r31, 0 ; +1
|
||||||
sts TCNT1H, r31
|
sts TCNT1H, r31 ; +2
|
||||||
sts TCNT1L, r31
|
sts TCNT1L, r31 ; +2
|
||||||
|
|
||||||
; set counter TOP (MSB first!)
|
; set counter TOP (MSB first!)
|
||||||
lds r31, hpos + 1
|
lds r31, hpos + 1 ; +2
|
||||||
lds r30, hpos
|
lds r30, hpos ; +2
|
||||||
sts OCR1AH, r31
|
sts OCR1AH, r31 ; +2
|
||||||
sts OCR1AL, r30
|
sts OCR1AL, r30 ; +2
|
||||||
|
|
||||||
; clear any pending interrupt
|
; clear any pending interrupt
|
||||||
ldi r31, 0x7
|
ldi r31, 0x7 ; +1
|
||||||
sts TIFR1, r31
|
sts TIFR1, r31 ; +2
|
||||||
|
|
||||||
; enable interrupt timer A
|
; enable interrupt timer A
|
||||||
lds r31, TIMSK1
|
lds r31, TIMSK1 ; +2
|
||||||
ori r31, 0x02
|
ori r31, 0x02 ; +1
|
||||||
sts TIMSK1, r31
|
sts TIMSK1, r31 ; +2
|
||||||
|
|
||||||
|
; total: 25
|
||||||
|
; HSYNC_INT_TUNE = 25
|
||||||
|
; this adds up for HSYNC_TUNE
|
||||||
|
|
||||||
pop r30
|
pop r30
|
||||||
pop r31
|
pop r31
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.global int_timer_0
|
.global int_timer_1
|
||||||
int_timer_0:
|
int_timer_1:
|
||||||
; here we are at the beginning of the visible line
|
; here we are at the beginning of the visible line
|
||||||
push r31
|
; jmp (from C) ; +3
|
||||||
in r31, IO(SREG)
|
push r31 ; +2
|
||||||
push r31
|
in r31, IO(SREG) ; +1
|
||||||
push r30
|
push r31 ; +2
|
||||||
push r29
|
push r30 ; +2
|
||||||
push r25
|
push r29 ; +2
|
||||||
|
push r25 ; +2
|
||||||
|
|
||||||
; turn off interrupt
|
; turn off interrupt
|
||||||
lds r31, TIMSK1
|
lds r31, TIMSK1 ; +2
|
||||||
andi r31, 0xfd ; mask disable interrupt timer A
|
andi r31, 0xfd ; mask disable interrupt timer A, +1
|
||||||
sts TIMSK1, r31
|
sts TIMSK1, r31 ; +2
|
||||||
|
|
||||||
lds r31, show_image
|
lds r31, show_image ; +2
|
||||||
cpi r31, 0x1
|
cpi r31, 0x1 ; +1
|
||||||
brne jump_table_return_address
|
brne jump_table_return_address ; +1 (not taken)
|
||||||
|
|
||||||
lds zl, current_jump_table
|
lds zl, current_jump_table ; +2
|
||||||
lds zh, current_jump_table + 1
|
lds zh, current_jump_table + 1 ; +2
|
||||||
|
|
||||||
clr r0
|
clr r0 ; +1
|
||||||
lds r29, line
|
lds r29, line ; +2
|
||||||
lds r25, vpos
|
lds r25, vpos ; +2
|
||||||
sub r29, r25
|
sub r29, r25 ; +1
|
||||||
|
|
||||||
add zl, r29
|
add zl, r29 ; +1
|
||||||
adc zh, r0
|
adc zh, r0 ; +1
|
||||||
add zl, r29
|
add zl, r29 ; +1
|
||||||
adc zh, r0
|
adc zh, r0 ; +1
|
||||||
|
|
||||||
ijmp
|
ijmp ; +2
|
||||||
|
|
||||||
|
; total: 39
|
||||||
|
; HSYNC_TIMER_TUNE = 39
|
||||||
|
; this adds up for HSYNC_TUNE
|
||||||
|
|
||||||
.global jump_table_return_address
|
.global jump_table_return_address
|
||||||
jump_table_return_address:
|
jump_table_return_address:
|
||||||
|
32
main.c
32
main.c
@ -18,35 +18,46 @@ volatile uint16_t frame = 0;
|
|||||||
volatile uint16_t line = 0xfe;
|
volatile uint16_t line = 0xfe;
|
||||||
volatile uint8_t image = 0xff;
|
volatile uint8_t image = 0xff;
|
||||||
|
|
||||||
// horizontal and vertical position of bouncing logo
|
// horizontal and vertical position
|
||||||
|
// (and current increments)
|
||||||
|
// of bouncing sprite
|
||||||
volatile uint8_t vpos = 0;
|
volatile uint8_t vpos = 0;
|
||||||
volatile uint16_t hpos = 0;
|
volatile uint16_t hpos = 0;
|
||||||
volatile int8_t vinc = +1;
|
volatile int8_t vinc = +1;
|
||||||
volatile int8_t hinc = +1;
|
volatile int8_t hinc = +1;
|
||||||
|
|
||||||
|
// vertical sync interrupt
|
||||||
void int_vertical_sync_s(void);
|
void int_vertical_sync_s(void);
|
||||||
ISR(INT0_vect) {
|
ISR(INT0_vect) {
|
||||||
|
// count frames
|
||||||
frame += 1;
|
frame += 1;
|
||||||
|
|
||||||
|
// move sprite
|
||||||
vpos += vinc;
|
vpos += vinc;
|
||||||
hpos += hinc;
|
hpos += hinc;
|
||||||
|
|
||||||
|
// invert bouncing direction
|
||||||
if (vpos == 0)
|
if (vpos == 0)
|
||||||
vinc = +1;
|
vinc = +1;
|
||||||
if (vpos == 256 - 64)
|
if (vpos == FRAME_PIXEL_HEIGHT - SPRITE_HEIGHT)
|
||||||
vinc = -1;
|
vinc = -1;
|
||||||
if (hpos == HORIZONTAL_OFFSET)
|
if (hpos == BACK_PORCH_OFFSET)
|
||||||
hinc = +1;
|
hinc = +1;
|
||||||
if (hpos == 1024 - 80)
|
if (hpos ==
|
||||||
|
FRAME_PIXEL_WIDTH - SPRITE_WIDTH - FRONT_PORCH_OFFSET - HSYNC_TUNE)
|
||||||
hinc = -1;
|
hinc = -1;
|
||||||
|
|
||||||
int_vertical_sync_s();
|
int_vertical_sync_s();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// horizontal sync interrupt
|
||||||
void int_horizontal_sync_s(void);
|
void int_horizontal_sync_s(void);
|
||||||
ISR(INT1_vect) {
|
ISR(INT1_vect) {
|
||||||
|
// count lines
|
||||||
line += 1;
|
line += 1;
|
||||||
// if (line >= 256)
|
|
||||||
if (line >= vpos + 64)
|
// we are past the last line of the sprite
|
||||||
|
if (line >= vpos + SPRITE_HEIGHT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (line >= vpos)
|
if (line >= vpos)
|
||||||
@ -54,8 +65,8 @@ ISR(INT1_vect) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ISR(TIMER1_COMPA_vect, ISR_NAKED) {
|
ISR(TIMER1_COMPA_vect, ISR_NAKED) {
|
||||||
// back porch timer interrupt
|
// end-of back porch timer interrupt
|
||||||
asm("jmp int_timer_0");
|
asm("jmp int_timer_1");
|
||||||
}
|
}
|
||||||
|
|
||||||
// external assembly main loop
|
// external assembly main loop
|
||||||
@ -76,10 +87,5 @@ int main() {
|
|||||||
TCCR1A = 0x00; // don't connect output pins to timer, CTC[1:0] mode
|
TCCR1A = 0x00; // don't connect output pins to timer, CTC[1:0] mode
|
||||||
TCCR1B = 0x09; // CTC[3:2] mode, no prescaler
|
TCCR1B = 0x09; // CTC[3:2] mode, no prescaler
|
||||||
|
|
||||||
#if 0
|
|
||||||
TCCR0A = 0x02; // don't connect output pins to timer, CTC[1:0] mode
|
|
||||||
TCCR0B = 0x01; // CTC[2] mode, no prescaler
|
|
||||||
#endif
|
|
||||||
|
|
||||||
main_asm();
|
main_asm();
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,6 @@
|
|||||||
P1
|
P1
|
||||||
# Created by GIMP version 2.10.32 PNM plug-in
|
# Created by GIMP version 2.10.32 PNM plug-in
|
||||||
40 64
|
80 64
|
||||||
1110011101110111000110000011111111111111100101000010010010100100000000
|
|
||||||
0000000001100101000010010010100100000000000000000111100110001001110010
|
|
||||||
0100000000000000000110010100001001001010010000000000000000011001010000
|
|
||||||
1001001010010000000000000000011001010000100100101001000000000000000001
|
|
||||||
1001011100100100100110000000000000000001000000000000000000000000000000
|
|
||||||
0000000001000000000000000000000000000000000000000100000000000000000000
|
|
||||||
0000000000000000000100000000000000000000000000000000000000010000000000
|
|
||||||
0000000000000000000000000000010000000000000000000000000000000000000001
|
|
||||||
0000000000000000000000000000000000000001000000000000000000000000000000
|
|
||||||
0000000001100000000000000000000000000000000000000110000000000000000000
|
|
||||||
0000000000000000000110000000000000000000000000000000000000011000000000
|
|
||||||
0000000000000000000000000000011000000000000000000000000000000000000001
|
|
||||||
1000000000000000000000000000000000000001100000000000000000000000000000
|
|
||||||
0000000001100000000000000000000000000000000000000110000000000000000000
|
|
||||||
0000000000000000000110000000000000000000000000000000000000001000000000
|
|
||||||
0000000000000000000000000000001000000000000000000000000000000000000000
|
|
||||||
1000000000000000000000000000000000000000100000000000000000000000000000
|
|
||||||
0000000000000000000000000000000000000000000000000000000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000000000000000000000000000000000000000000000000000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000000000000000000000000000000000000000000000000000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
@ -31,10 +14,64 @@ P1
|
|||||||
0000000000000000000000000000000000000000000000000000000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000000000000000000000000000000000000000000000000000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000000000000000000000000000000000000000000000000000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000000000000000010000000000000000000000000000000000000001000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000000000000000000000000001000000000000000000000000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
1000000000000000000000000000000000000001100000000000000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000001100000000000000000000000000000000000000110000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000000000000000110000000000000000000000000000000000000011000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000000000000000000000000011000000000000000000000000000000000000001
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
1111110000000000000000000000000000011111
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0000000000000000000000000000000000000000111001110111011100011001110111
|
||||||
|
0100111010100010011000000000000000000000000000000010010100001001001010
|
||||||
|
0101000100010100001011001010010000000000000000000000000000001001010000
|
||||||
|
1001001010010100010001010000101010101001000000000000000000000000000000
|
||||||
|
1110011000100111001001011001100101000010100110111100000000000000000000
|
||||||
|
0000000000100101000010010010100101000100010100001010001010010000000000
|
||||||
|
0000000000000000000010010100001001001010010100010001010000101000101001
|
||||||
|
0000000000000000000000000000001001010000100100101001010001000101000010
|
||||||
|
1000101001000000000000000000000000000000100101110010010010011001000100
|
||||||
|
0100111010100010100101000000000000000000000000000000000000000000000000
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0000011001000011001110011100011000110011100011001000100111000101110000
|
||||||
|
0000000000000010000100010000100101001010010100001001010010110110100000
|
||||||
|
0100100000000000000000001000010001000010010100101001010000100101001010
|
||||||
|
1010100000010010000000000000000000101101000101101110011100100101011011
|
||||||
|
1001111010101001100001001000000000000000000010010100010010100001001010
|
||||||
|
0101001010010100101000100001000100100000000000000000001001010001001010
|
||||||
|
0001001010010100101001010010100010000100010010000000000000000000100101
|
||||||
|
0001001010000100101001010010100101001010001000010001001000000000000000
|
||||||
|
0000011001110011001000010010011000110010010100101000101110010100100000
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0000000000000000000000000000000000000000000000000100000000000000000000
|
||||||
|
0000000000000000000000000000000000000000000000000000000000001000000000
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0100000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0000000000001000000000000000000000000000000000000000000000000000000000
|
||||||
|
0000000000000000000000010000000000000000000000000000000000000000000000
|
||||||
|
0000000000000000000000000000000000100000000000000000000000000000000000
|
||||||
|
0000000000000000000000000000000000000000000001000000111000000000000000
|
||||||
|
0000000000000000000000000000000000000000000000000000000010001110000000
|
||||||
|
0010000000000000000000000000000000000000000000000000000000000000000111
|
||||||
|
1000000000010000000000000000000000000000000000000000000000000000000000
|
||||||
|
0000000110000000000010000000000000000000000000000000000000000000000000
|
||||||
|
0000000000000000010100000000010000000000000000000000000000000000000000
|
||||||
|
0000000000000000000000000011001000000010000000000000000000000000000000
|
||||||
|
0000000000000000000000000000000000001000010000010000000000000000000000
|
||||||
|
0000000000000000000000000000000000000000000001100000100010000000000000
|
||||||
|
0000000000000000000000000000000000000000000000000000000100000001010000
|
||||||
|
0000000000000000000000000000000000000000000000000000000000000000010000
|
||||||
|
0000100000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
0000010000000000000000001000000000000000000000000000000000000000000000
|
||||||
|
0000000000000001000000000000000000100000000000000000000000000000000000
|
||||||
|
0000000000000000000000000110000000000000000110000000000000000000000000
|
||||||
|
0000000000000000000000000000000000001000000000000000010000000000000000
|
||||||
|
0000000000000000000000000000000000000000000000110000000000000011000000
|
||||||
|
0000000000000000000000000000000000000000000000000000000001000000000000
|
||||||
|
0010000000000000000000000000000000000000000000000000000000000000000110
|
||||||
|
0000000000011000000000000000000000000000000000000000000000000000000000
|
||||||
|
0000000011100000000111000000000000000000000000000000000000000000000000
|
||||||
|
0000000000000000000011100001110000000000000000000000000000000000000000
|
||||||
|
0000000000000000000000000000000011111100000000000000000000000000000000
|
||||||
|
0000000000
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user