0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-28 00:33:02 +00:00

Minor cleanup

This commit is contained in:
neauoire 2021-04-08 16:30:44 -07:00
parent 9df5bb924b
commit 169e659ab8
3 changed files with 20 additions and 30 deletions

View file

@ -1,14 +1,15 @@
#!/bin/bash #!/bin/bash
echo "Formatting.." echo "Formatting.."
clang-format -i src/assembler.c
clang-format -i src/uxn.h clang-format -i src/uxn.h
clang-format -i src/uxn.c clang-format -i src/uxn.c
clang-format -i src/ppu.h
clang-format -i src/ppu.c
clang-format -i src/apu.h
clang-format -i src/apu.c
clang-format -i src/assembler.c
clang-format -i src/emulator.c clang-format -i src/emulator.c
clang-format -i src/debugger.c clang-format -i src/debugger.c
clang-format -i src/ppu.c
clang-format -i src/apu.c
clang-format -i src/apu.h
echo "Cleaning.." echo "Cleaning.."
rm -f ./bin/assembler rm -f ./bin/assembler
@ -31,7 +32,7 @@ else
fi fi
echo "Assembling.." echo "Assembling.."
./bin/assembler projects/software/noodle.usm bin/boot.rom ./bin/assembler projects/software/nasu.usm bin/boot.rom
echo "Running.." echo "Running.."
if [ "${2}" = '--cli' ]; if [ "${2}" = '--cli' ];

View file

@ -83,6 +83,7 @@ quit(void)
free(ppu.output); free(ppu.output);
free(ppu.fg); free(ppu.fg);
free(ppu.bg); free(ppu.bg);
SDL_UnlockAudioDevice(audio_id);
SDL_DestroyTexture(gTexture); SDL_DestroyTexture(gTexture);
gTexture = NULL; gTexture = NULL;
SDL_DestroyRenderer(gRenderer); SDL_DestroyRenderer(gRenderer);
@ -136,21 +137,18 @@ domouse(Uxn *u, SDL_Event *event)
mempoke16(u, addr + 0, x); mempoke16(u, addr + 0, x);
mempoke16(u, addr + 2, y); mempoke16(u, addr + 2, y);
u->ram.dat[addr + 5] = 0x00; u->ram.dat[addr + 5] = 0x00;
switch(event->button.button) { flag = event->button.button == SDL_BUTTON_LEFT ? 0x01 : 0x10;
case SDL_BUTTON_LEFT: flag = 0x01; break;
case SDL_BUTTON_RIGHT: flag = 0x10; break;
}
switch(event->type) { switch(event->type) {
case SDL_MOUSEBUTTONUP:
setflag(&u->ram.dat[addr + 4], flag, 0);
break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
setflag(&u->ram.dat[addr + 4], flag, 1); u->ram.dat[addr + 4] |= flag;
if(flag == 0x10 && (u->ram.dat[addr + 4] & 0x01)) if(flag == 0x10 && (u->ram.dat[addr + 4] & 0x01))
u->ram.dat[addr + 5] = 0x01; u->ram.dat[addr + 5] = 0x01;
if(flag == 0x01 && (u->ram.dat[addr + 4] & 0x10)) if(flag == 0x01 && (u->ram.dat[addr + 4] & 0x10))
u->ram.dat[addr + 5] = 0x10; u->ram.dat[addr + 5] = 0x10;
break; break;
case SDL_MOUSEBUTTONUP:
u->ram.dat[addr + 4] &= (~flag);
break;
} }
} }
@ -183,14 +181,8 @@ doctrl(Uxn *u, SDL_Event *event, int z)
switch(event->key.keysym.sym) { switch(event->key.keysym.sym) {
case SDLK_LCTRL: flag = 0x01; break; case SDLK_LCTRL: flag = 0x01; break;
case SDLK_LALT: flag = 0x02; break; case SDLK_LALT: flag = 0x02; break;
case SDLK_BACKSPACE: case SDLK_BACKSPACE: flag = 0x04; break;
flag = 0x04; case SDLK_RETURN: flag = 0x08; break;
if(z) u->ram.dat[devkey->addr + 2] = 0x08;
break;
case SDLK_RETURN:
flag = 0x08;
if(z) u->ram.dat[devkey->addr + 2] = 0x0d;
break;
case SDLK_UP: flag = 0x10; break; case SDLK_UP: flag = 0x10; break;
case SDLK_DOWN: flag = 0x20; break; case SDLK_DOWN: flag = 0x20; break;
case SDLK_LEFT: flag = 0x40; break; case SDLK_LEFT: flag = 0x40; break;
@ -293,9 +285,8 @@ audio_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
} }
apu.queue->dat[apu.queue->n++] = (m[0xb] << 8) + m[0xc]; apu.queue->dat[apu.queue->n++] = (m[0xb] << 8) + m[0xc];
apu.queue->dat[apu.queue->n++] = (m[0xd] << 8) + b1; apu.queue->dat[apu.queue->n++] = (m[0xd] << 8) + b1;
} else if(b0 == 0xf && apu.queue != NULL) { } else if(b0 == 0xf && apu.queue != NULL)
apu.queue->finishes = 1; apu.queue->finishes = 1;
}
return b1; return b1;
} }
@ -362,20 +353,19 @@ start(Uxn *u)
while(SDL_PollEvent(&event) != 0) { while(SDL_PollEvent(&event) != 0) {
switch(event.type) { switch(event.type) {
case SDL_QUIT: case SDL_QUIT:
SDL_UnlockAudioDevice(audio_id);
quit(); quit();
break; break;
case SDL_KEYDOWN:
case SDL_KEYUP:
doctrl(u, &event, event.type == SDL_KEYDOWN);
evaluxn(u, devctrl->vector);
break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
domouse(u, &event); domouse(u, &event);
evaluxn(u, devmouse->vector); evaluxn(u, devmouse->vector);
break; break;
case SDL_KEYDOWN:
case SDL_KEYUP:
doctrl(u, &event, event.type == SDL_KEYDOWN);
evaluxn(u, devctrl->vector);
break;
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
dotext(u, &event); dotext(u, &event);
evaluxn(u, devkey->vector); evaluxn(u, devkey->vector);

View file

@ -143,7 +143,6 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad)
p->pad = pad; p->pad = pad;
p->width = (8 * p->hor + p->pad * 2); p->width = (8 * p->hor + p->pad * 2);
p->height = (8 * p->ver + p->pad * 2); p->height = (8 * p->ver + p->pad * 2);
if(!(p->output = malloc(p->width * p->height * sizeof(Uint32)))) if(!(p->output = malloc(p->width * p->height * sizeof(Uint32))))
return 0; return 0;
if(!(p->bg = malloc(p->width * p->height * sizeof(Uint8) * 2))) if(!(p->bg = malloc(p->width * p->height * sizeof(Uint8) * 2)))