multiple frames

This commit is contained in:
giomba 2021-08-12 18:26:03 +02:00
parent a4854efd4a
commit 826234a93d
2 changed files with 176 additions and 95 deletions

View File

@ -13,16 +13,10 @@ enum ExitStatus {
}; };
int main(int argc, char** argv) { int main(int argc, char** argv) {
if (argc != 2) { if (argc < 2) {
return BAD_ARGUMENT; return BAD_ARGUMENT;
} }
std::fstream infile;
infile.open(argv[1], std::ios::in);
if (! infile) {
return FILE_NOT_OPEN;
}
std::fstream outfile; std::fstream outfile;
outfile.open("frame.S", std::ios::out); outfile.open("frame.S", std::ios::out);
if (! outfile) { if (! outfile) {
@ -32,10 +26,19 @@ int main(int argc, char** argv) {
outfile << "#include \"macro.h\"" << std::endl; outfile << "#include \"macro.h\"" << std::endl;
outfile << "#include <avr/io.h>" << std::endl; outfile << "#include <avr/io.h>" << std::endl;
outfile << ".global line_jump_table" << std::endl; for (int current_image = 0; current_image < argc - 1; ++current_image) {
outfile << "line_jump_table:" << std::endl; outfile << ".global line_jump_table_" << current_image << std::endl;
outfile << "line_jump_table_" << current_image << ":" << std::endl;
for (int i = 0; i < 256; ++i) { for (int i = 0; i < 256; ++i) {
outfile << '\t' << "jmp line_" << i << std::endl; outfile << '\t' << "jmp line_" << current_image << "_" << i << std::endl;
}
}
for (int current_image = 0; current_image < argc - 1; ++current_image) {
std::fstream infile;
infile.open(argv[1 + current_image], std::ios::in);
if (! infile) {
return FILE_NOT_OPEN;
} }
int width, height; int width, height;
@ -77,7 +80,7 @@ int main(int argc, char** argv) {
infile.close(); infile.close();
for (int y = 0; y < height; ++y) { for (int y = 0; y < height; ++y) {
outfile << "line_" << y << ":" << std::endl; outfile << "line_" << current_image << "_" << y << ":" << std::endl;
int count = 0; int count = 0;
char last = image[y * width + 0]; char last = image[y * width + 0];
@ -111,14 +114,14 @@ int main(int argc, char** argv) {
last = current; last = current;
count = 1; count = 1;
} }
} }
outfile << '\t' << "cbi IO(PORTB), 4" << std::endl; outfile << '\t' << "cbi IO(PORTB), 4" << std::endl;
outfile << '\t' << "jmp jump_table_return_address" << std::endl; outfile << '\t' << "jmp jump_table_return_address" << std::endl;
} }
delete[] image;
}
outfile.close(); outfile.close();
} }

94
main.S
View File

@ -2,11 +2,25 @@
#include "macro.h" #include "macro.h"
#include "const.h" #include "const.h"
.data
image:
.byte 0xff
show_image:
.byte 0x00
button_next_image:
.byte 0x0
current_jump_table:
.word 0x0
.text .text
.global main .global main
main: main:
ldi r16, 0x30 ; port B, pin 4 and 5 as output ldi r16, 0x30 ; port B, pin 4 and 5 as output, others as input
sts DDRB, r16 sts DDRB, r16
; set interrupt vectors at address 0x0, not bootloader ; set interrupt vectors at address 0x0, not bootloader
@ -34,6 +48,10 @@ main:
sts line, r16 sts line, r16
ldi r16, 0xfe ldi r16, 0xfe
sts line + 1, r16 sts line + 1, r16
ldi r16, 0xff
sts image, r16
ldi r16, 0
sts show_image, r16
; r0 always holds 0 ; r0 always holds 0
clr r0 clr r0
@ -98,10 +116,17 @@ int_timer_0:
andi r31, 0xfd ; mask disable interrupt timer A andi r31, 0xfd ; mask disable interrupt timer A
sts TIMSK0, r31 sts TIMSK0, r31
clr r0 lds r31, show_image
ldi zl, pm_lo8(line_jump_table) cpi r31, 0x1
ldi zh, pm_hi8(line_jump_table) brne jump_table_return_address
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 r29, line
add zl, r29 add zl, r29
adc zh, r0 adc zh, r0
@ -123,8 +148,10 @@ jump_table_return_address:
int_vertical_sync: int_vertical_sync:
push r31 push r31
in r31, IO(SREG) in r31, IO(SREG)
push r31 push zl
push r30 push zh
push yl
push yh
lds r31, frame + 1 lds r31, frame + 1
lds r30, frame lds r30, frame
@ -137,9 +164,60 @@ int_vertical_sync:
sts line, r30 sts line, r30
sts line + 1, r31 sts line + 1, r31
; check button
in r31, IO(PINB)
andi r31, 0x08
breq check_if_released
ldi r31, 1
sts button_next_image, r31
jmp int_vertical_sync_end
check_if_released:
lds r31, button_next_image
cpi r31, 1
brne int_vertical_sync_end
; here button is released
lds r31, show_image
cpi r31, 1
breq 1f
ldi r31, 1
sts show_image, r31
rjmp 2f
1:
ldi r31, 0
sts show_image, r31
rjmp end_button_release
2:
; show image
ldi zl, pm_lo8(line_jump_table_0)
ldi zh, pm_hi8(line_jump_table_0)
clr yl
lds yh, image
inc yh
sts image, yh
add zh, yh
add zh, yh
sts current_jump_table, zl
sts current_jump_table + 1, zh
ldi r31, 0x01
sts show_image, r31
end_button_release:
clr yl
sts button_next_image, yl
int_vertical_sync_end: int_vertical_sync_end:
pop r30 pop yh
pop r31 pop yl
pop zh
pop zl
out IO(SREG), r31 out IO(SREG), r31
pop r31 pop r31
reti reti