summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/SDL2/test/testdisplayinfo.c
blob: f06722e88bc7bb4ce18389310225a76d4d761e3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely.
*/

/* Program to test querying of display info */

#include "SDL.h"

#include <stdio.h>
#include <stdlib.h>

static void
print_mode(const char *prefix, const SDL_DisplayMode *mode)
{
    if (!mode)
        return;

    SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
            prefix, SDL_GetPixelFormatName(mode->format),
            mode->w, mode->h, mode->refresh_rate);
}

int
main(int argc, char *argv[])
{
    SDL_DisplayMode mode;
    int num_displays, dpy;

    /* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    /* Load the SDL library */
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
        return 1;
    }

    SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
    num_displays = SDL_GetNumVideoDisplays();

    SDL_Log("See %d displays.\n", num_displays);

    for (dpy = 0; dpy < num_displays; dpy++) {
        const int num_modes = SDL_GetNumDisplayModes(dpy);
        SDL_Rect rect = { 0, 0, 0, 0 };
        float ddpi, hdpi, vdpi;
        int m;

        SDL_GetDisplayBounds(dpy, &rect);
        SDL_Log("%d: \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);

        if (SDL_GetDisplayDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    DPI: failed to query (%s)\n", SDL_GetError());
        } else {
            SDL_Log("    DPI: ddpi=%f; hdpi=%f; vdpi=%f\n", ddpi, hdpi, vdpi);
        }

        if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    CURRENT: failed to query (%s)\n", SDL_GetError());
        } else {
            print_mode("CURRENT", &mode);
        }

        if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    DESKTOP: failed to query (%s)\n", SDL_GetError());
        } else {
            print_mode("DESKTOP", &mode);
        }

        for (m = 0; m < num_modes; m++) {
            if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    MODE %d: failed to query (%s)\n", m, SDL_GetError());
            } else {
                char prefix[64];
                SDL_snprintf(prefix, sizeof (prefix), "    MODE %d", m);
                print_mode(prefix, &mode);
            }
        }

        SDL_Log("\n");
    }

    SDL_Quit();
    return 0;
}

/* vi: set ts=4 sw=4 expandtab: */
count; int addr = (WP+(reg<<1)) & 0xfffe & m_prgaddr_mask; m_prgspace->write_byte(addr, data>>8); m_prgspace->write_byte(addr+1, data & 0xff); m_icount = temp; } /* Interrupt input. Keep in mind that the TMS9980A does not have any INTREQ line but signals interrupts via IC0-IC2 only. Thus we cannot take down any single interrupt; only all interrupts can be cleared at once using level 7. The state parameter is actually not needed. */ void tms9980a_device::execute_set_input(int irqline, int state) { // We model the three lines IC0-IC2 as 8 separate input lines, although we // cannot assert more than one at a time. The state value is not needed, // as level 7 means to clean all interrupts, but we consider it for the // sake of consistency. int level = irqline; // Just to stay consistent. if (state==CLEAR_LINE) level = INT_9980A_CLEAR; switch (level) { case INT_9980A_RESET: case 1: level = RESET_INT; m_reset = true; break; case INT_9980A_LOAD: level = LOAD_INT; break; case INT_9980A_LEVEL1: case INT_9980A_LEVEL2: case INT_9980A_LEVEL3: case INT_9980A_LEVEL4: level = level - 2; break; case INT_9980A_CLEAR: // Clear all interrupts m_load_state = false; m_irq_state = false; if (TRACE_INT) logerror("tms9980a: clear interrupts\n"); break; } m_irq_level = level; if (m_irq_level != INT_9980A_CLEAR) { if (m_irq_level == LOAD_INT) { // Some boards start up with LOAD interrupt, so we clear the reset flag m_reset = false; m_load_state = true; } else m_irq_state = true; if (TRACE_INT) logerror("tms9980a: interrupt level=%d, ST=%04x\n", m_irq_level, ST); } } /*****************************************************************************/ /* Memory read: Clock cycles: 4 + 2W, W = number of wait states */ void tms9980a_device::mem_read() { uint8_t value; switch (m_mem_phase) { case 1: m_pass = 4; // make the CPU visit this method more than once if (!m_dbin_line.isnull()) m_dbin_line(ASSERT_LINE); m_prgspace->set_address(m_address & m_prgaddr_mask & ~1); if (TRACE_ADDRESSBUS) logerror("tms9980a: set address bus %04x\n", m_address & m_prgaddr_mask & ~1); m_check_ready = true; break; case 2: // Sample the value on the data bus (high byte) value = m_prgspace->read_byte(m_address & m_prgaddr_mask & ~1); if (TRACE_MEM) logerror("tms9980a: memory read high byte %04x -> %02x\n", m_address & m_prgaddr_mask & ~1, value); m_current_value = (value << 8) & 0xff00; break; case 3: m_prgspace->set_address((m_address & m_prgaddr_mask) | 1); if (TRACE_ADDRESSBUS) logerror("tms9980a: set address bus %04x\n", (m_address & m_prgaddr_mask) | 1); break; case 4: // Sample the value on the data bus (low byte) value = m_prgspace->read_byte((m_address & m_prgaddr_mask) | 1); m_current_value = m_current_value | (value & 0x00ff); if (TRACE_MEM) logerror("tms9980a: memory read low byte %04x -> %02x -> complete word %04x\n", (m_address & m_prgaddr_mask) | 1, value, m_current_value); break; } pulse_clock(1); m_mem_phase = (m_mem_phase % 4) +1; } void tms9980a_device::mem_write() { switch (m_mem_phase) { case 1: m_pass = 4; // make the CPU visit this method once more if (!m_dbin_line.isnull()) m_dbin_line(CLEAR_LINE); m_prgspace->set_address(m_address & m_prgaddr_mask & ~1); if (TRACE_ADDRESSBUS) logerror("tms9980a: set address bus %04x\n", m_address & m_prgaddr_mask & ~1); m_prgspace->write_byte(m_address & 0x3ffe & ~1, (m_current_value >> 8)&0xff); if (TRACE_MEM) logerror("tms9980a: memory write high byte %04x <- %02x\n", m_address & m_prgaddr_mask & ~1, (m_current_value >> 8)&0xff); m_check_ready = true; break; case 2: // no action here, just wait for READY break; case 3: m_prgspace->set_address((m_address & m_prgaddr_mask) | 1); if (TRACE_ADDRESSBUS) logerror("tms9980a: set address bus %04x\n", (m_address & m_prgaddr_mask) | 1); m_prgspace->write_byte((m_address & m_prgaddr_mask) | 1, m_current_value & 0xff); if (TRACE_MEM) logerror("tms9980a: memory write low byte %04x <- %02x\n", (m_address & m_prgaddr_mask) | 1, m_current_value & 0xff); break; case 4: // no action here, just wait for READY break; } pulse_clock(1); m_mem_phase = (m_mem_phase % 4) +1; } void tms9980a_device::acquire_instruction() { if (m_mem_phase == 1) { if (!m_iaq_line.isnull()) m_iaq_line(ASSERT_LINE); m_address = PC; m_first_cycle = m_icount; } mem_read(); if (m_mem_phase == 1) // changed by mem_read and wrapped { decode(m_current_value); if (TRACE_OP) logerror("tms9980a: ===== Next operation %04x (%s) at %04x =====\n", IR, opname[m_command], PC); debugger_instruction_hook(this, PC); PC = (PC + 2) & 0xfffe & m_prgaddr_mask; } // IAQ will be cleared in the main loop } /**************************************************************************/ uint32_t tms9980a_device::execute_min_cycles() const { return 2; } // TODO: Compute this value, just a wild guess for the average uint32_t tms9980a_device::execute_max_cycles() const { return 10; } uint32_t tms9980a_device::execute_input_lines() const { return 8; } // clocks to cycles, cycles to clocks = id // execute_default_irq_vector = 0 // execute_burn = nop // device_disasm_interface overrides util::disasm_interface *tms9980a_device::create_disassembler() { return new tms9900_disassembler(TMS9980_ID); } DEFINE_DEVICE_TYPE(TMS9980A, tms9980a_device, "tms9980a", "TMS9980A")