src/mess/machine/iq151_minigraf.c
| r13226 | r13227 | |
| 7 | 7 | #include "emu.h" |
| 8 | 8 | #include "iq151_minigraf.h" |
| 9 | 9 | |
| 10 | #include "emuopts.h" |
| 11 | #include "png.h" |
| 10 | 12 | |
| 13 | // paper is A4 (297x210mm) |
| 14 | #define PAPER_HEIGHT (210*8) |
| 15 | #define PAPER_WIDTH (297*8) |
| 16 | |
| 17 | // usable area is 187.5x262.5mm step is 0.125mm |
| 18 | #define PAPER_MAX_X 2100 |
| 19 | #define PAPER_MAX_Y 1500 |
| 20 | |
| 21 | // dump the m_paper bitmap into a png |
| 22 | #define DUMP_PAPER_INTO_PNG 0 |
| 23 | |
| 11 | 24 | /*************************************************************************** |
| 12 | 25 | IMPLEMENTATION |
| 13 | 26 | ***************************************************************************/ |
| r13226 | r13227 | |
| 45 | 58 | void iq151_minigraf_device::device_start() |
| 46 | 59 | { |
| 47 | 60 | m_rom = (UINT8*)subregion("minigraf")->base(); |
| 61 | |
| 62 | // allocate a bitmap for represent the paper |
| 63 | m_paper = auto_bitmap_alloc(machine(), PAPER_WIDTH, PAPER_HEIGHT, BITMAP_FORMAT_INDEXED16); |
| 64 | bitmap_fill(m_paper, NULL , 0); |
| 65 | |
| 66 | m_pen = 0; |
| 67 | m_posx = m_posy = 0; |
| 48 | 68 | } |
| 49 | 69 | |
| 50 | 70 | //------------------------------------------------- |
| 71 | // device_stop - clean up anything that needs to |
| 72 | // happen before the running_machine goes away |
| 73 | //------------------------------------------------- |
| 74 | |
| 75 | void iq151_minigraf_device::device_stop() |
| 76 | { |
| 77 | #if DUMP_PAPER_INTO_PNG |
| 78 | emu_file file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); |
| 79 | file_error filerr = file.open("iq151_minigraf.png"); |
| 80 | |
| 81 | if (filerr == FILERR_NONE) |
| 82 | { |
| 83 | static const rgb_t png_palette[] = { RGB_WHITE, RGB_BLACK }; |
| 84 | |
| 85 | // save the paper into a png |
| 86 | png_write_bitmap(file, NULL, m_paper, 2, png_palette); |
| 87 | } |
| 88 | #endif |
| 89 | } |
| 90 | |
| 91 | //------------------------------------------------- |
| 51 | 92 | // rom_region - device-specific ROM region |
| 52 | 93 | //------------------------------------------------- |
| 53 | 94 | |
| r13226 | r13227 | |
| 75 | 116 | { |
| 76 | 117 | if (offset >= 0xf0 && offset < 0xf4) |
| 77 | 118 | { |
| 78 | | // Plotter control lines |
| 119 | /* |
| 120 | Plotter control lines |
| 121 | |
| 122 | ---- -xxx horizontal step |
| 123 | --xx x--- vertical step |
| 124 | -x-- ---- ??? |
| 125 | x--- ---- pen up/down |
| 126 | */ |
| 127 | |
| 128 | plotter_update(data); |
| 79 | 129 | } |
| 80 | 130 | } |
| 131 | |
| 132 | |
| 133 | //************************************************************************** |
| 134 | // Aritma MINIGRAF 0507 |
| 135 | //************************************************************************** |
| 136 | |
| 137 | inline int iq151_minigraf_device::get_direction(UINT8 old_val, UINT8 new_val) |
| 138 | { |
| 139 | if (new_val == 0 && old_val == 7) return +1; |
| 140 | if (new_val == 7 && old_val == 0) return -1; |
| 141 | |
| 142 | return (new_val - old_val); |
| 143 | } |
| 144 | |
| 145 | void iq151_minigraf_device::plotter_update(UINT8 control) |
| 146 | { |
| 147 | // update pen and paper positions |
| 148 | m_posx += get_direction(m_control & 7, control & 7); |
| 149 | m_posy += get_direction((m_control>>3) & 7, (control>>3) & 7); |
| 150 | |
| 151 | // bit 7 is pen up/down |
| 152 | m_pen = BIT(control, 7); |
| 153 | |
| 154 | // clamp within range |
| 155 | m_posx = MAX(m_posx, 0); |
| 156 | m_posx = MIN(m_posx, PAPER_MAX_X); |
| 157 | m_posy = MAX(m_posy, 0); |
| 158 | m_posy = MIN(m_posy, PAPER_MAX_Y); |
| 159 | |
| 160 | // if pen is down draws a point |
| 161 | if (m_pen) |
| 162 | *BITMAP_ADDR16(m_paper, ((PAPER_HEIGHT-PAPER_MAX_Y)/2) + PAPER_MAX_Y - m_posy, ((PAPER_WIDTH-PAPER_MAX_X)/2) + m_posx) = 1; |
| 163 | |
| 164 | m_control = control; |
| 165 | } |
src/mess/machine/iq151_minigraf.h
| r13226 | r13227 | |
| 23 | 23 | // optional information overrides |
| 24 | 24 | virtual const rom_entry *device_rom_region() const; |
| 25 | 25 | |
| 26 | | |
| 27 | 26 | protected: |
| 28 | 27 | // device-level overrides |
| 29 | 28 | virtual void device_start(); |
| 29 | virtual void device_stop(); |
| 30 | 30 | virtual void device_config_complete() { m_shortname = "iq151_minigraf"; } |
| 31 | 31 | |
| 32 | 32 | // iq151cart_interface overrides |
| 33 | 33 | virtual void read(offs_t offset, UINT8 &data); |
| 34 | 34 | virtual void io_write(offs_t offset, UINT8 data); |
| 35 | 35 | |
| 36 | // Aritma MINIGRAF 0507 |
| 37 | void plotter_update(UINT8 control); |
| 38 | int get_direction(UINT8 old_val, UINT8 new_val); |
| 39 | |
| 36 | 40 | private: |
| 37 | 41 | |
| 38 | 42 | UINT8 * m_rom; |
| 43 | INT16 m_posx; |
| 44 | INT16 m_posy; |
| 45 | UINT8 m_pen; |
| 46 | UINT8 m_control; |
| 47 | |
| 48 | bitmap_t * m_paper; |
| 39 | 49 | }; |
| 40 | 50 | |
| 41 | 51 | |
src/mess/machine/iq151_ms151a.c
| r13226 | r13227 | |
| 7 | 7 | #include "emu.h" |
| 8 | 8 | #include "iq151_ms151a.h" |
| 9 | 9 | |
| 10 | #include "emuopts.h" |
| 11 | #include "png.h" |
| 10 | 12 | |
| 13 | // paper is A4 (210x297mm) |
| 14 | #define PAPER_HEIGHT (210*10) |
| 15 | #define PAPER_WIDTH (297*10) |
| 16 | |
| 17 | // usable area is 175x250mm step is 0.1mm |
| 18 | #define PAPER_MAX_X (250*10) |
| 19 | #define PAPER_MAX_Y (175*10) |
| 20 | |
| 21 | // dump the m_paper bitmap into a png |
| 22 | #define DUMP_PAPER_INTO_PNG 0 |
| 23 | |
| 11 | 24 | /*************************************************************************** |
| 12 | 25 | IMPLEMENTATION |
| 13 | 26 | ***************************************************************************/ |
| r13226 | r13227 | |
| 44 | 57 | void iq151_ms151a_device::device_start() |
| 45 | 58 | { |
| 46 | 59 | m_rom = (UINT8*)subregion("ms151a")->base(); |
| 60 | |
| 61 | // allocate a bitmap for represent the paper |
| 62 | m_paper = auto_bitmap_alloc(machine(), PAPER_WIDTH, PAPER_HEIGHT, BITMAP_FORMAT_INDEXED16); |
| 63 | bitmap_fill(m_paper, NULL , 0); |
| 64 | |
| 65 | m_pen = 0; |
| 66 | m_posx = m_posy = 0; |
| 47 | 67 | } |
| 48 | 68 | |
| 49 | 69 | //------------------------------------------------- |
| 70 | // device_stop - clean up anything that needs to |
| 71 | // happen before the running_machine goes away |
| 72 | //------------------------------------------------- |
| 73 | |
| 74 | void iq151_ms151a_device::device_stop() |
| 75 | { |
| 76 | #if DUMP_PAPER_INTO_PNG |
| 77 | emu_file file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); |
| 78 | file_error filerr = file.open("iq151_ms151a.png"); |
| 79 | |
| 80 | if (filerr == FILERR_NONE) |
| 81 | { |
| 82 | static const rgb_t png_palette[] = { RGB_WHITE, RGB_BLACK }; |
| 83 | |
| 84 | // save the paper into a png |
| 85 | png_write_bitmap(file, NULL, m_paper, 2, png_palette); |
| 86 | } |
| 87 | #endif |
| 88 | } |
| 89 | |
| 90 | //------------------------------------------------- |
| 50 | 91 | // rom_region - device-specific ROM region |
| 51 | 92 | //------------------------------------------------- |
| 52 | 93 | |
| r13226 | r13227 | |
| 72 | 113 | |
| 73 | 114 | void iq151_ms151a_device::io_read(offs_t offset, UINT8 &data) |
| 74 | 115 | { |
| 75 | | |
| 116 | if (offset == 0xc4) |
| 117 | data = plotter_status(); |
| 76 | 118 | } |
| 77 | 119 | |
| 78 | 120 | //------------------------------------------------- |
| r13226 | r13227 | |
| 81 | 123 | |
| 82 | 124 | void iq151_ms151a_device::io_write(offs_t offset, UINT8 data) |
| 83 | 125 | { |
| 126 | if (offset >= 0xc0 && offset <= 0xc4) |
| 127 | plotter_update(offset - 0xc0, data); |
| 128 | } |
| 84 | 129 | |
| 130 | |
| 131 | //************************************************************************** |
| 132 | // XY 4130/4131 |
| 133 | //************************************************************************** |
| 134 | |
| 135 | UINT8 iq151_ms151a_device::plotter_status() |
| 136 | { |
| 137 | /* |
| 138 | bit 7 - plotter READY line |
| 139 | */ |
| 140 | |
| 141 | return 0x80; |
| 85 | 142 | } |
| 143 | |
| 144 | void iq151_ms151a_device::plotter_update(UINT8 offset, UINT8 data) |
| 145 | { |
| 146 | // update pen and paper positions |
| 147 | switch (offset) |
| 148 | { |
| 149 | case 0: m_posx++; break; |
| 150 | case 1: m_posx--; break; |
| 151 | case 2: m_posy++; break; |
| 152 | case 3: m_posy--; break; |
| 153 | case 4: m_pen = data & 0x01; break; |
| 154 | } |
| 155 | |
| 156 | // clamp within range |
| 157 | m_posx = MAX(m_posx, 0); |
| 158 | m_posx = MIN(m_posx, PAPER_MAX_X); |
| 159 | m_posy = MAX(m_posy, 0); |
| 160 | m_posy = MIN(m_posy, PAPER_MAX_Y); |
| 161 | |
| 162 | // if pen is down draws a point |
| 163 | if (m_pen) |
| 164 | *BITMAP_ADDR16(m_paper, ((PAPER_HEIGHT-PAPER_MAX_Y)/2) + PAPER_MAX_Y - m_posy, ((PAPER_WIDTH-PAPER_MAX_X)/2) + m_posx) = 1; |
| 165 | } |