amiga_imgv
view src/main.c @ 0:a4788c959918
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 25 Oct 2017 19:34:53 +0300 |
parents | |
children | 663471a80c21 |
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <assert.h>
5 #include "gfx.h"
6 #include "image.h"
7 #include "logger.h"
9 #include "hwregs.h"
10 #include "copper.h"
13 static int proc_event(union gfx_event *ev);
14 static void show_ham_image(struct ham_image *img);
16 static int win_width, win_height;
18 int main(int argc, char **argv)
19 {
20 struct ham_image *img;
22 if(argv[1]) {
23 if(!(img = load_ham_image(argv[1]))) {
24 fprintf(stderr, "failed to load image: %s\n", argv[1]);
25 return 1;
26 }
27 } else {
28 printf("generating test image ...\n");
29 if(!(img = gen_ham_image(320, 256, 6))) {
30 fprintf(stderr, "failed to generate image\n");
31 return 1;
32 }
33 }
35 if(gfx_init(6, GFX_HAM) == -1) {
36 return 1;
37 }
38 gfx_wait_vblank();
39 show_ham_image(img);
41 for(;;) {
42 union gfx_event ev;
43 if(gfx_next_event(&ev, GFX_EVLOOP_BLOCK)) {
44 if(proc_event(&ev) == -1) {
45 break;
46 }
47 }
48 }
50 gfx_shutdown();
51 return 0;
52 }
54 static int proc_event(union gfx_event *ev)
55 {
56 switch(ev->type) {
57 case GFX_EV_QUIT:
58 return -1;
60 case GFX_EV_KEY:
61 switch(ev->key.key) {
62 case 27:
63 return -1;
64 default:
65 break;
66 }
67 break;
69 default:
70 break;
71 }
72 return 0;
73 }
75 #define NUM_BPL 6
76 static void show_ham_image(struct ham_image *img)
77 {
78 int i, j, k, fbwidth, fbheight, ncolors, prev_line;
79 unsigned char *fbptr = gfx_get_framebuffer();
80 struct palchange *chg = img->chglist;
82 fbwidth = gfx_framebuffer_width();
83 fbheight = gfx_framebuffer_height();
85 memcpy(fbptr, img->pixels, fbwidth * fbheight / 8 * NUM_BPL);
87 /* create copper list that handles the palette */
88 clear_copper();
89 gfx_begin_copperlist();
90 /* initial palette at the start of frame */
91 for(i=0; i<16; i++) {
92 add_copper(COPPER_MOVE(REGN_COLOR(i), img->palette[i]));
93 logmsg("copper palette[%d]: %x\n", i, (unsigned int)img->palette[i]);
94 }
95 /* add copper instructions for palette changes according to the image changelist */
96 prev_line = -1;
97 while(chg) {
98 assert(chg->line >= prev_line);
99 if(chg->line != prev_line) {
100 prev_line = chg->line;
101 add_copper(COPPER_VWAIT(chg->line));
102 }
103 add_copper(COPPER_MOVE(REGN_COLOR(chg->entry >> 12), chg->entry & 0xfff));
104 }
105 add_copper(COPPER_END);
106 }