Mercurial > hg > dmlib
comparison tools/ppl.c @ 2530:aacf3bd1cceb
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 16 May 2020 06:38:52 +0300 |
parents | 0ab24caf7fdf |
children | d56a0e86067a |
comparison
equal
deleted
inserted
replaced
2529:fddee4b6a427 | 2530:aacf3bd1cceb |
---|---|
548 | 548 |
549 int main(int argc, char *argv[]) | 549 int main(int argc, char *argv[]) |
550 { | 550 { |
551 BOOL initSDL = FALSE, audioInit = FALSE; | 551 BOOL initSDL = FALSE, audioInit = FALSE; |
552 DMResource *file = NULL; | 552 DMResource *file = NULL; |
553 int result = -1; | 553 int res = -1; |
554 BOOL muteState = FALSE; | 554 BOOL muteState = FALSE; |
555 | 555 |
556 memset(&eng, 0, sizeof(eng)); | 556 memset(&eng, 0, sizeof(eng)); |
557 | 557 |
558 eng.optScrWidth = 640; | 558 eng.optScrWidth = 640; |
571 { | 571 { |
572 argShowHelp(); | 572 argShowHelp(); |
573 return 1; | 573 return 1; |
574 } | 574 } |
575 | 575 |
576 if ((result = dmf_open_stdio(optFilename, "rb", &file)) != DMERR_OK) | 576 if ((res = dmf_open_stdio(optFilename, "rb", &file)) != DMERR_OK) |
577 { | 577 { |
578 dmErrorMsg("Error opening file '%s': %s\n", | 578 dmErrorMsg("Error opening file '%s': %s\n", |
579 optFilename, dmErrorStr(result)); | 579 optFilename, dmErrorStr(res)); |
580 return 1; | 580 return 1; |
581 } | 581 } |
582 | 582 |
583 // Initialize miniJSS | 583 // Initialize miniJSS |
584 jssInit(); | 584 jssInit(); |
585 | 585 |
586 // Read module file | 586 // Read module file |
587 dmMsg(1, "Reading file: %s\n", optFilename); | 587 dmMsg(1, "Reading file: %s\n", optFilename); |
588 #ifdef JSS_SUP_XM | 588 #ifdef JSS_SUP_XM |
589 result = jssLoadXM(file, &eng.mod, TRUE); | 589 if (eng.mod == NULL) |
590 { | |
591 dmMsg(2, "* Trying XM...\n"); | |
592 dmfreset(file); | |
593 if ((res = jssLoadXM(file, &eng.mod, TRUE)) == DMERR_OK) | |
594 { | |
595 dmfreset(file); | |
596 res = jssLoadXM(file, &eng.mod, FALSE); | |
597 } | |
598 } | |
590 #endif | 599 #endif |
591 #ifdef JSS_SUP_JSSMOD | 600 #ifdef JSS_SUP_JSSMOD |
592 dmfreset(file); | 601 if (eng.mod == NULL) |
593 if (result != DMERR_OK) | |
594 { | 602 { |
595 dmMsg(1, "* Trying JSSMOD ...\n"); | 603 dmMsg(1, "* Trying JSSMOD ...\n"); |
596 result = jssLoadJSSMOD(file, &eng.mod, TRUE); | |
597 dmfreset(file); | 604 dmfreset(file); |
598 if (result == DMERR_OK) | 605 if ((res = jssLoadJSSMOD(file, &eng.mod, TRUE)) == DMERR_OK) |
599 result = jssLoadJSSMOD(file, &eng.mod, FALSE); | 606 { |
600 } | 607 dmfreset(file); |
601 else | 608 res = jssLoadJSSMOD(file, &eng.mod, FALSE); |
602 { | 609 } |
603 dmMsg(2, "* Trying XM...\n"); | |
604 result = jssLoadXM(file, &eng.mod, FALSE); | |
605 } | 610 } |
606 #endif | 611 #endif |
607 dmf_close(file); | 612 dmf_close(file); |
608 | 613 |
609 if (result != DMERR_OK) | 614 // Check for errors, we still might have some data tho |
615 if (res != DMERR_OK) | |
610 { | 616 { |
611 dmErrorMsg("Error loading module file: %s\n", | 617 dmErrorMsg("Error loading module file: %s\n", |
612 dmErrorStr(result)); | 618 dmErrorStr(res)); |
613 goto exit; | 619 goto exit; |
614 } | 620 } |
615 | 621 |
622 // Check if we have anything | |
623 if (eng.mod == NULL) | |
624 { | |
625 res = dmError(DMERR_INIT_FAIL, | |
626 "Could not load module file.\n"); | |
627 goto exit; | |
628 } | |
629 | |
616 // Try to convert it | 630 // Try to convert it |
617 if ((result = jssConvertModuleForPlaying(eng.mod)) != DMERR_OK) | 631 if ((res = jssConvertModuleForPlaying(eng.mod)) != DMERR_OK) |
618 { | 632 { |
619 dmErrorMsg("Could not convert module for playing: %s\n", | 633 dmErrorMsg("Could not convert module for playing: %s\n", |
620 dmErrorStr(result)); | 634 dmErrorStr(res)); |
621 goto exit; | 635 goto exit; |
622 } | 636 } |
623 | 637 |
624 | 638 |
625 // Initialize SDL components | 639 // Initialize SDL components |
626 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) | 640 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) |
627 { | 641 { |
628 dmErrorMsg("Could not initialize SDL: %s\n", | 642 res = dmError(DMERR_INIT_FAIL, |
643 "Could not initialize SDL: %s\n", | |
629 SDL_GetError()); | 644 SDL_GetError()); |
630 goto exit; | 645 goto exit; |
631 } | 646 } |
632 initSDL = TRUE; | 647 initSDL = TRUE; |
633 | 648 |
637 optOutFormat, optOutChannels, optOutFreq); | 652 optOutFormat, optOutChannels, optOutFreq); |
638 | 653 |
639 eng.dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO); | 654 eng.dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO); |
640 if (eng.dev == NULL) | 655 if (eng.dev == NULL) |
641 { | 656 { |
642 dmErrorMsg("jvmInit() returned NULL\n"); | 657 res = dmError(DMERR_INIT_FAIL, |
658 "jvmInit() returned NULL\n"); | |
643 goto exit; | 659 goto exit; |
644 } | 660 } |
645 | 661 |
646 switch (optOutFormat) | 662 switch (optOutFormat) |
647 { | 663 { |
648 case JSS_AUDIO_S16: eng.afmt.format = AUDIO_S16SYS; break; | 664 case JSS_AUDIO_S16: eng.afmt.format = AUDIO_S16SYS; break; |
649 case JSS_AUDIO_U16: eng.afmt.format = AUDIO_U16SYS; break; | 665 case JSS_AUDIO_U16: eng.afmt.format = AUDIO_U16SYS; break; |
650 case JSS_AUDIO_S8: eng.afmt.format = AUDIO_S8; break; | 666 case JSS_AUDIO_S8: eng.afmt.format = AUDIO_S8; break; |
651 case JSS_AUDIO_U8: eng.afmt.format = AUDIO_U8; break; | 667 case JSS_AUDIO_U8: eng.afmt.format = AUDIO_U8; break; |
652 default: | 668 default: |
653 dmErrorMsg("Unsupported audio format %d (could not set matching SDL format)\n", | 669 res = dmError(DMERR_NOT_SUPPORTED, |
670 "Unsupported audio format %d (could not set matching SDL format)\n", | |
654 optOutFormat); | 671 optOutFormat); |
655 goto exit; | 672 goto exit; |
656 } | 673 } |
657 | 674 |
658 eng.afmt.freq = optOutFreq; | 675 eng.afmt.freq = optOutFreq; |
662 eng.afmt.userdata = (void *) eng.dev; | 679 eng.afmt.userdata = (void *) eng.dev; |
663 | 680 |
664 // Open the audio device | 681 // Open the audio device |
665 if (SDL_OpenAudio(&eng.afmt, NULL) < 0) | 682 if (SDL_OpenAudio(&eng.afmt, NULL) < 0) |
666 { | 683 { |
667 dmErrorMsg("Couldn't open SDL audio: %s\n", | 684 res = dmError(DMERR_INIT_FAIL, |
685 "Couldn't open SDL audio: %s\n", | |
668 SDL_GetError()); | 686 SDL_GetError()); |
669 goto exit; | 687 goto exit; |
670 } | 688 } |
671 audioInit = TRUE; | 689 audioInit = TRUE; |
672 | 690 |
673 // Initialize player | 691 // Initialize player |
674 if ((eng.plr = jmpInit(eng.dev)) == NULL) | 692 if ((eng.plr = jmpInit(eng.dev)) == NULL) |
675 { | 693 { |
676 dmErrorMsg("jmpInit() returned NULL\n"); | 694 res = dmError(DMERR_INIT_FAIL, |
695 "jmpInit() returned NULL\n"); | |
677 goto exit; | 696 goto exit; |
678 } | 697 } |
679 | 698 |
680 jvmSetCallback(eng.dev, jmpExec, eng.plr); | 699 jvmSetCallback(eng.dev, jmpExec, eng.plr); |
681 jmpSetModule(eng.plr, eng.mod); | 700 jmpSetModule(eng.plr, eng.mod); |
692 | 711 |
693 if (optUseGUI) | 712 if (optUseGUI) |
694 { | 713 { |
695 // Get font | 714 // Get font |
696 static const char *engineFontName = "pplfont.fnt"; | 715 static const char *engineFontName = "pplfont.fnt"; |
697 result = dmf_open_memio(NULL, engineFontName, engineSetupFont, sizeof(engineSetupFont), &file); | 716 res = dmf_open_memio(NULL, engineFontName, engineSetupFont, sizeof(engineSetupFont), &file); |
698 if (result != DMERR_OK) | 717 if (res != DMERR_OK) |
699 { | 718 { |
700 dmErrorMsg("Error opening font file '%s': %s\n", | 719 dmErrorMsg("Error opening font file '%s': %s\n", |
701 engineFontName, dmErrorStr(result)); | 720 engineFontName, dmErrorStr(res)); |
702 goto exit; | 721 goto exit; |
703 } | 722 } |
704 result = dmLoadBitmapFont(file, &font); | 723 res = dmLoadBitmapFont(file, &font); |
705 dmf_close(file); | 724 dmf_close(file); |
706 if (result != DMERR_OK) | 725 if (res != DMERR_OK) |
707 { | 726 { |
708 dmErrorMsg("Could not load font data from '%s': %s\n", | 727 dmErrorMsg("Could not load font data from '%s': %s\n", |
709 engineFontName, dmErrorStr(result)); | 728 engineFontName, dmErrorStr(res)); |
710 goto exit; | 729 goto exit; |
711 } | 730 } |
712 | 731 |
713 SDL_Color pal[DMFONT_NPALETTE]; | 732 SDL_Color pal[DMFONT_NPALETTE]; |
714 for (int n = 0; n < DMFONT_NPALETTE; n++) | 733 for (int n = 0; n < DMFONT_NPALETTE; n++) |
724 eng.optScrWidth, eng.optScrHeight, | 743 eng.optScrWidth, eng.optScrHeight, |
725 eng.optVFlags | SDL_WINDOW_RESIZABLE | 744 eng.optVFlags | SDL_WINDOW_RESIZABLE |
726 //| SDL_WINDOW_HIDDEN | 745 //| SDL_WINDOW_HIDDEN |
727 )) == NULL) | 746 )) == NULL) |
728 { | 747 { |
729 dmErrorMsg("Can't create an SDL window: %s\n", SDL_GetError()); | 748 res = dmError(DMERR_INIT_FAIL, |
749 "Can't create an SDL window: %s\n", | |
750 SDL_GetError()); | |
730 goto exit; | 751 goto exit; |
731 } | 752 } |
732 | 753 |
733 SDL_SetWindowTitle(eng.window, dmProgDesc); | 754 SDL_SetWindowTitle(eng.window, dmProgDesc); |
734 | 755 |
735 if ((eng.renderer = SDL_CreateRenderer(eng.window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL) | 756 if ((eng.renderer = SDL_CreateRenderer(eng.window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL) |
736 { | 757 { |
737 dmErrorMsg("Can't create an SDL renderer: %s\n", SDL_GetError()); | 758 res = dmError(DMERR_INIT_FAIL, |
759 "Can't create an SDL renderer: %s\n", | |
760 SDL_GetError()); | |
738 goto exit; | 761 goto exit; |
739 } | 762 } |
740 | 763 |
741 if (!dmInitializeVideo()) | 764 if (!dmInitializeVideo()) |
765 { | |
766 res = DMERR_INIT_FAIL; | |
742 goto exit; | 767 goto exit; |
768 } | |
743 | 769 |
744 //SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best"); | 770 //SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best"); |
745 //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); | 771 //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
746 } | 772 } |
747 | 773 |
981 if (initSDL) | 1007 if (initSDL) |
982 SDL_Quit(); | 1008 SDL_Quit(); |
983 | 1009 |
984 jssClose(); | 1010 jssClose(); |
985 | 1011 |
986 return 0; | 1012 return res; |
987 } | 1013 } |